00001 /*************************************************************************** 00002 * Copyright (C) 1998-2010 by authors (see AUTHORS.txt ) * 00003 * * 00004 * This file is part of LuxRays. * 00005 * * 00006 * LuxRays is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 3 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 * LuxRays is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00018 * * 00019 * LuxRays website: http://www.luxrender.net * 00020 ***************************************************************************/ 00021 00037 #ifndef _LUXRAYS_CONTEXT_H 00038 #define _LUXRAYS_CONTEXT_H 00039 00040 #include <cstdlib> 00041 #include <sstream> 00042 #include <ostream> 00043 00044 #include "luxrays/luxrays.h" 00045 #include "luxrays/core/dataset.h" 00046 00047 namespace luxrays { 00048 00049 typedef void (*LuxRaysDebugHandler)(const char *msg); 00050 00051 #define LR_LOG(c, a) { if (c->HasDebugHandler()) { std::stringstream _LR_LOG_LOCAL_SS; _LR_LOG_LOCAL_SS << a; c->PrintDebugMsg(_LR_LOG_LOCAL_SS.str().c_str()); } } 00052 00053 class DeviceDescription; 00054 class OpenCLDeviceDescription; 00055 class OpenCLIntersectionDevice; 00056 00063 class Context { 00064 public: 00072 Context(LuxRaysDebugHandler handler = NULL, const int openclPlatformIndex = -1); 00073 00076 ~Context(); 00077 00078 //-------------------------------------------------------------------------- 00079 // Methods dedicated to device listing and creation 00080 //-------------------------------------------------------------------------- 00081 00086 const std::vector<DeviceDescription *> &GetAvailableDeviceDescriptions() const; 00087 00092 const std::vector<IntersectionDevice *> &GetIntersectionDevices() const; 00093 00098 const std::vector<PixelDevice *> &GetPixelDevices() const; 00099 00106 std::vector<IntersectionDevice *> AddIntersectionDevices(std::vector<DeviceDescription *> &deviceDescs); 00107 00119 std::vector<IntersectionDevice *> AddVirtualM2MIntersectionDevices(const unsigned int count, 00120 std::vector<DeviceDescription *> &deviceDescs); 00121 00133 std::vector<IntersectionDevice *> AddVirtualM2OIntersectionDevices(const unsigned int count, 00134 std::vector<DeviceDescription *> &deviceDescs); 00135 00142 std::vector<PixelDevice *> AddPixelDevices(std::vector<DeviceDescription *> &deviceDescs); 00143 00144 //-------------------------------------------------------------------------- 00145 // Methods dedicated to DataSet definition 00146 //-------------------------------------------------------------------------- 00147 00148 void SetDataSet(DataSet *dataSet); 00149 void UpdateDataSet(); 00150 00151 //-------------------------------------------------------------------------- 00152 // Methods dedicated to Context mangement (i.e. start/stop, etc.) 00153 //-------------------------------------------------------------------------- 00154 00155 void Start(); 00156 void Interrupt(); 00157 void Stop(); 00158 bool IsRunning() const { return started; } 00159 00160 //-------------------------------------------------------------------------- 00161 // Methods dedicated to message debug handling 00162 //-------------------------------------------------------------------------- 00163 00164 bool HasDebugHandler() const { return debugHandler != NULL; } 00165 void PrintDebugMsg(const char *msg) const { 00166 if (debugHandler) 00167 debugHandler(msg); 00168 } 00169 00170 friend class OpenCLIntersectionDevice; 00171 00172 private: 00173 std::vector<IntersectionDevice *> CreateIntersectionDevices(std::vector<DeviceDescription *> &deviceDesc); 00174 std::vector<PixelDevice *> CreatePixelDevices(std::vector<DeviceDescription *> &deviceDesc); 00175 00176 LuxRaysDebugHandler debugHandler; 00177 00178 DataSet *currentDataSet; 00179 std::vector<DeviceDescription *> deviceDescriptions; 00180 00181 // All intersection devices (including virtual) 00182 std::vector<IntersectionDevice *> idevices; 00183 // All OpenCL devices 00184 std::vector<OpenCLIntersectionDevice *> oclDevices; 00185 // Virtual intersection devices 00186 std::vector<VirtualM2MHardwareIntersectionDevice *> m2mDevices; 00187 std::vector<VirtualM2OHardwareIntersectionDevice *> m2oDevices; 00188 00189 // All pixel devices 00190 std::vector<PixelDevice *> pdevices; 00191 00192 bool started; 00193 }; 00194 00195 } 00196 00197 #endif /* _LUXRAYS_CONTEXT_H */
1.6.3