00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_CONTEXT_H
00024 #define LUX_CONTEXT_H
00025
00026 #include <boost/thread/mutex.hpp>
00027
00028 #include "lux.h"
00029 #include "renderfarm.h"
00030
00031
00032 #define STATE_UNINITIALIZED 0
00033 #define STATE_OPTIONS_BLOCK 1
00034 #define STATE_WORLD_BLOCK 2
00035
00036 namespace lux {
00037
00038 class Context {
00039 public:
00040
00041 Context(std::string n="Lux default context") : name(n) {
00042 init();
00043 }
00044
00045 ~Context() {
00046 free();
00047 }
00048
00049
00050
00051
00052
00053
00054 static Context* getActive() {
00055 return activeContext;
00056 }
00057 static void setActive(Context *c) {
00058 activeContext=c;
00059 }
00060
00061
00062
00063 static void luxIdentity() { activeContext->identity(); }
00064 static void luxTranslate(float dx, float dy, float dz) { activeContext->translate(dx, dy, dz); }
00065 static void luxRotate(float angle, float ax, float ay, float az) { activeContext->rotate(angle, ax, ay, az); }
00066 static void luxScale(float sx, float sy, float sz) { activeContext->scale(sx, sy, sz); }
00067 static void luxLookAt(float ex, float ey, float ez, float lx, float ly, float lz, float ux, float uy, float uz) { activeContext->lookAt(ex, ey, ez, lx, ly, lz, ux, uy, uz) ; }
00068 static void luxConcatTransform(float transform[16]) { activeContext->concatTransform(transform); }
00069 static void luxTransform(float transform[16]) { activeContext->transform(transform); }
00070 static void luxCoordinateSystem(const string &s) { activeContext->coordinateSystem(s) ; }
00071 static void luxCoordSysTransform(const string &s) { activeContext->coordSysTransform(s); }
00072 static void luxPixelFilter(const string &name, const ParamSet ¶ms) { activeContext->pixelFilter(name, params); }
00073 static void luxFilm(const string &type, const ParamSet ¶ms) { activeContext->film(type, params); }
00074 static void luxSampler(const string &name, const ParamSet ¶ms) { activeContext->sampler(name, params); }
00075 static void luxAccelerator(const string &name, const ParamSet ¶ms) { activeContext->accelerator(name, params); }
00076 static void luxSurfaceIntegrator(const string &name, const ParamSet ¶ms) { activeContext->surfaceIntegrator(name, params); }
00077 static void luxVolumeIntegrator(const string &name, const ParamSet ¶ms) { activeContext->volumeIntegrator(name, params); }
00078 static void luxCamera(const string &s, const ParamSet &cameraParams) { activeContext->camera(s, cameraParams); }
00079 static void luxWorldBegin() { activeContext->worldBegin(); }
00080 static void luxAttributeBegin() { activeContext->attributeBegin(); }
00081 static void luxAttributeEnd() { activeContext->attributeEnd(); }
00082 static void luxTransformBegin() { activeContext->transformBegin(); }
00083 static void luxTransformEnd() { activeContext->transformEnd(); }
00084 static void luxTexture(const string &name, const string &type, const string &texname, const ParamSet ¶ms) { activeContext->texture(name, type, texname, params); }
00085 static void luxMaterial(const string &name, const ParamSet ¶ms) { activeContext->material(name, params); }
00086 static void luxMakeNamedMaterial(const string &name, const ParamSet ¶ms) { activeContext->makenamedmaterial(name, params); }
00087 static void luxNamedMaterial(const string &name, const ParamSet ¶ms) { activeContext->namedmaterial(name, params); }
00088 static void luxLightSource(const string &name, const ParamSet ¶ms) { activeContext->lightSource(name, params); }
00089 static void luxAreaLightSource(const string &name, const ParamSet ¶ms) { activeContext->areaLightSource(name, params); }
00090 static void luxPortalShape(const string &name, const ParamSet ¶ms) { activeContext->portalShape(name, params); }
00091 static void luxShape(const string &name, const ParamSet ¶ms) { activeContext->shape(name, params); }
00092 static void luxReverseOrientation() { activeContext->reverseOrientation(); }
00093 static void luxVolume(const string &name, const ParamSet ¶ms) { activeContext->volume(name, params); }
00094 static void luxObjectBegin(const string &name) { activeContext->objectBegin(name); }
00095 static void luxObjectEnd() { activeContext->objectEnd(); }
00096 static void luxObjectInstance(const string &name) { activeContext->objectInstance(name); }
00097 static void luxWorldEnd() { activeContext->worldEnd(); }
00098
00099
00100 void makemixmaterial(const ParamSet shapeparams, const ParamSet materialparams, boost::shared_ptr<Material> mtl);
00101
00102
00103 static void luxCleanup() { activeContext->cleanup(); }
00104
00105
00106
00107 static void luxStart() { activeContext->start(); }
00108 static void luxPause() { activeContext->pause(); }
00109 static void luxExit() { activeContext->exit(); }
00110
00111 static void luxWait() { activeContext->wait(); }
00112
00113
00114 static int luxAddThread() { return activeContext->addThread(); }
00115 static void luxRemoveThread() { activeContext->removeThread(); }
00116
00117
00118 static void luxUpdateFramebuffer() { activeContext->updateFramebuffer(); }
00119 static unsigned char* luxFramebuffer() { return activeContext->framebuffer(); }
00120
00121
00122
00123
00124
00125 static void luxUpdateFilmFromNetwork() { activeContext->updateFilmFromNetwork(); }
00126 static void luxSetNetworkServerUpdateInterval(int updateInterval) { activeContext->renderFarm->serverUpdateInterval = updateInterval; }
00127 static int luxGetNetworkServerUpdateInterval() { return activeContext->renderFarm->serverUpdateInterval; }
00128 static void luxAddServer(const string &name) { activeContext->addServer(name); }
00129
00130
00131 static double luxStatistics(const string &statName) { return activeContext->statistics(statName); }
00132
00133
00134 static void luxTransmitFilm(std::basic_ostream<char> &stream) { activeContext->transmitFilm(stream); }
00135
00136
00137 static void luxEnableDebugMode() { activeContext->enableDebugMode(); }
00138
00139 private:
00140 static Context *activeContext;
00141 string name;
00142 Scene *luxCurrentScene;
00143
00144 void init();
00145 void free();
00146
00147
00148 void identity();
00149 void translate(float dx, float dy, float dz);
00150 void rotate(float angle, float ax, float ay, float az);
00151 void scale(float sx, float sy, float sz);
00152 void lookAt(float ex, float ey, float ez, float lx, float ly, float lz,
00153 float ux, float uy, float uz);
00154 void concatTransform(float transform[16]);
00155 void transform(float transform[16]);
00156 void coordinateSystem(const string &);
00157 void coordSysTransform(const string &);
00158 void pixelFilter(const string &name, const ParamSet ¶ms);
00159 void film(const string &type, const ParamSet ¶ms);
00160 void sampler(const string &name, const ParamSet ¶ms);
00161 void accelerator(const string &name, const ParamSet ¶ms);
00162 void surfaceIntegrator(const string &name, const ParamSet ¶ms);
00163 void volumeIntegrator(const string &name, const ParamSet ¶ms);
00164 void camera(const string &, const ParamSet &cameraParams);
00165 void worldBegin();
00166 void attributeBegin();
00167 void attributeEnd();
00168 void transformBegin();
00169 void transformEnd();
00170 void texture(const string &name, const string &type, const string &texname,
00171 const ParamSet ¶ms);
00172 void material(const string &name, const ParamSet ¶ms);
00173 void makenamedmaterial(const string &name, const ParamSet ¶ms);
00174 void namedmaterial(const string &name, const ParamSet ¶ms);
00175 void lightSource(const string &name, const ParamSet ¶ms);
00176 void areaLightSource(const string &name, const ParamSet ¶ms);
00177 void portalShape(const string &name, const ParamSet ¶ms);
00178 void shape(const string &name, const ParamSet ¶ms);
00179 void reverseOrientation();
00180 void volume(const string &name, const ParamSet ¶ms);
00181 void objectBegin(const string &name);
00182 void objectEnd();
00183 void objectInstance(const string &name);
00184 void worldEnd();
00185
00186
00187 void cleanup();
00188
00189
00190
00191 void start();
00192 void pause();
00193 void exit();
00194 void wait();
00195
00196
00197 int addThread();
00198 void removeThread();
00199
00200
00201 void updateFramebuffer();
00202 unsigned char* framebuffer();
00203
00204
00205
00206
00207
00208
00209 void updateFilmFromNetwork();
00210 void transmitFilm(std::basic_ostream<char> &stream);
00211
00212
00213 double statistics(const string &statName);
00214 void addServer(const string &name);
00215
00216 void enableDebugMode();
00217
00218
00219 struct RenderOptions {
00220
00221 RenderOptions() {
00222
00223 FilterName = "mitchell";
00224 FilmName = "multiimage";
00225 SamplerName = "random";
00226 AcceleratorName = "kdtree";
00227 SurfIntegratorName = "path";
00228 VolIntegratorName = "emission";
00229 CameraName = "perspective";
00230 currentInstance = NULL;
00231 debugMode = false;
00232 }
00233
00234 Scene *MakeScene() const;
00235
00236 string FilterName;
00237 ParamSet FilterParams;
00238 string FilmName;
00239 ParamSet FilmParams;
00240 string SamplerName;
00241 ParamSet SamplerParams;
00242 string AcceleratorName;
00243 ParamSet AcceleratorParams;
00244 string SurfIntegratorName, VolIntegratorName;
00245 ParamSet SurfIntegratorParams, VolIntegratorParams;
00246 string CameraName;
00247 ParamSet CameraParams;
00248 Transform WorldToCamera;
00249 bool gotSearchPath;
00250 mutable vector<Light *> lights;
00251 mutable vector<Primitive* > primitives;
00252 mutable vector<VolumeRegion *> volumeRegions;
00253 map<string, vector<Primitive* > > instances;
00254 vector<Primitive* > *currentInstance;
00255 bool debugMode;
00256 };
00257
00258 struct NamedMaterial {
00259 NamedMaterial() {};
00260
00261 ParamSet materialParams;
00262 string material;
00263 };
00264
00265 struct GraphicsState {
00266
00267 GraphicsState() {
00268
00269 material = "matte";
00270 reverseOrientation = false;
00271 }
00272
00273 map<string, boost::shared_ptr<Texture<float> > > floatTextures;
00274 map<string, boost::shared_ptr<Texture<Spectrum> > > spectrumTextures;
00275 ParamSet materialParams;
00276 string material;
00277 ParamSet areaLightParams;
00278 string areaLight;
00279 string currentLight;
00280 Light* currentLightPtr;
00281 bool reverseOrientation;
00282 };
00283
00284 int currentApiState;
00285 Transform curTransform;
00286 map<string, Transform> namedCoordinateSystems;
00287 RenderOptions *renderOptions;
00288 GraphicsState *graphicsState;
00289 vector<NamedMaterial> namedmaterials;
00290 vector<GraphicsState> pushedGraphicsStates;
00291 vector<Transform> pushedTransforms;
00292 RenderFarm *renderFarm;
00293
00294
00295 mutable boost::mutex renderingMutex;
00296 };
00297
00298 }
00299
00300 #endif //LUX_CONTEXT_H