home | up | contents |
00001 00002 // Copyright 1986-2006 by mental images GmbH, Fasanenstr. 81, D-10623 Berlin, 00003 // Germany. All rights reserved. 00005 // Author: kjs 00006 // Created: 09.01.06 00007 // Module: api 00008 // Purpose: mental ray C++ shader interface extensions 00010 00026 00027 #ifndef MI_SHADER_IF_H 00028 #define MI_SHADER_IF_H 00029 00030 #if !defined(SHADER_H) 00031 #include <mi_raylib.h> 00032 #include <mi_lib.h> 00033 #endif 00034 00035 #ifndef __cplusplus 00036 #error mi_shader_if.h requires C++ compilation 00037 #endif 00038 00039 00041 static const int mi_ray_interface_version = 1; 00042 00043 00044 // forward declarations 00045 namespace mi { 00046 namespace shader { 00047 class Interface; 00048 } 00049 } 00050 00051 00068 00069 extern "C" mi::shader::Interface *mi_get_shader_interface(int version = mi_ray_interface_version); 00070 00071 00073 namespace mi { 00074 00075 00081 namespace shader { 00082 00083 00085 struct Options; 00086 class LightList; 00087 00088 00108 00109 class Interface { 00110 public: 00111 00128 static inline Interface* get(int version = mi_ray_interface_version) 00129 { return mi_get_shader_interface(version); } 00130 00139 virtual Options* getOptions(miTag options_tag); 00140 00144 virtual LightList* createLightList(miState* state, miTag* slist=0, int n=0); 00145 00151 virtual void release(); 00152 }; 00153 00154 00193 00194 struct Options { 00196 00200 virtual void set(const char *name, bool value) = 0; 00201 00207 virtual void set(const char *name, const char *value) = 0; 00208 00213 virtual void set(const char *name, int value) = 0; 00214 00218 virtual void set(const char *name, float value) = 0; 00219 00225 virtual void set(const char *name, float value1, float value2, float value3) = 0; 00226 00233 virtual void set(const char *name, float value1, float value2, float value3, float value4) = 0; 00234 00240 virtual bool get(const char *name, bool *value) = 0; 00241 00249 virtual bool get(const char *name, const char **value) = 0; 00250 00256 virtual bool get(const char *name, int *value) = 0; 00257 00266 virtual bool get(const char *name, float *value) = 0; 00267 00280 virtual bool get(const char *name, float *value1, float *value2, float *value3) = 0; 00281 00296 virtual bool get(const char *name, float *value1, float *value2, float *value3, float *value4) = 0; 00297 00301 virtual void release() = 0; 00302 }; 00303 00304 00306 class LightIterator { 00307 public: 00308 LightIterator( 00309 miState* state, // the state 00310 miTag* shader_light_list = 0, // optional array of light tags 00311 int n_shader_lights = 0); // number of lights in above array 00312 00313 LightIterator(const LightIterator& liter); 00314 ~LightIterator(); 00315 00316 miTag operator*() const; 00317 LightList* operator->() const; 00318 const LightIterator& operator++(); 00319 LightIterator operator++(int); 00320 00321 bool at_end() const; 00322 00323 const LightIterator& operator=(const LightIterator& iter); 00324 00325 bool operator==(const LightIterator& iter) const; 00326 00327 private: 00328 LightList* m_list; 00329 size_t m_current; 00330 }; 00331 00333 class LightList { 00334 public: 00335 virtual size_t set_current(size_t current) = 0; 00336 virtual size_t get_current() const = 0; 00337 virtual bool sample() = 0; 00338 virtual miScalar get_dot_nl() const = 0; 00339 virtual const miVector& get_direction() const = 0; 00340 virtual void get_contribution(miColor* c) const = 0; 00341 virtual void get_contribution(miSpectrum* s) const = 0; 00342 virtual int get_number_of_samples() const = 0; 00343 virtual miTag get_light_tag(size_t current) const = 0; 00344 virtual size_t get_number_of_lights() const = 0; 00345 virtual void connect() = 0; 00346 virtual void release() = 0; 00347 }; 00348 00349 //----------------------------------------------------------------------------- 00350 // inline implementation for LightIterator methods 00351 //----------------------------------------------------------------------------- 00352 00354 inline LightIterator::LightIterator( 00355 miState* state, 00356 miTag* shader_light_list, 00357 int n_shader_lights) 00358 : m_list(0) 00359 , m_current(0) 00360 { 00361 Interface* iface; 00362 mi_query(miQ_RAY_INTERFACE, state, 0, &iface); 00363 m_list = iface->createLightList(state, shader_light_list, n_shader_lights); 00364 } 00365 00367 inline LightIterator::LightIterator(const LightIterator& iter) 00368 : m_list(iter.m_list) 00369 , m_current(iter.m_current) 00370 { 00371 if(m_list) m_list->connect(); 00372 } 00373 00375 inline LightIterator::~LightIterator() 00376 { 00377 if(m_list) m_list->release(); 00378 } 00379 00381 inline const LightIterator& LightIterator::operator=(const LightIterator& iter) 00382 { 00383 m_list = iter.m_list; 00384 m_current = iter.m_current; 00385 if(m_list) m_list->connect(); 00386 return *this; 00387 } 00388 00390 inline miTag LightIterator::operator*() const 00391 { 00392 return m_list->get_light_tag(m_current); 00393 } 00394 00396 inline LightList* LightIterator::operator->() const 00397 { 00398 m_list->set_current(m_current); 00399 return m_list; 00400 } 00401 00403 inline const LightIterator& LightIterator::operator++() 00404 { 00405 ++m_current; 00406 return *this; 00407 } 00408 00410 inline LightIterator LightIterator::operator++(int) 00411 { 00412 LightIterator res(*this); 00413 ++m_current; 00414 return res; 00415 } 00416 00418 inline bool LightIterator::at_end() const 00419 { 00420 return m_current == m_list->get_number_of_lights(); 00421 } 00422 00424 inline bool LightIterator::operator==(const LightIterator& iter) const 00425 { 00426 return m_list == iter.m_list && m_current == iter.m_current; 00427 } 00428 00430 inline bool operator!=(const LightIterator& i1, const LightIterator& i2) 00431 { 00432 return !(i1 == i2); 00433 } 00434 00436 LightList* LightListFactory( 00437 miState* state, 00438 miTag* shader_light_list = 0, 00439 int n_shader_lights = 0); 00440 00441 } // namespace shader 00442 } // namespace mi 00443 00444 00445 #endif // MI_SHADER_IF_H
home | up | contents |
Copyright © 1986-2006 by mental images GmbH