00001 00002 // Copyright 1986-2008 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 #include <mi_shader.h> 00034 #endif 00035 00036 #ifndef __cplusplus 00037 #error mi_shader_if.h requires C++ compilation 00038 #endif 00039 00040 00042 static const int mi_ray_interface_version = 2; 00043 00044 00045 // forward declarations 00046 namespace mi { 00047 namespace shader { 00048 struct Interface; 00049 } 00050 } 00051 00052 00070 00071 extern "C" mi::shader::Interface *mi_get_shader_interface( 00072 int version = mi_ray_interface_version); 00073 00075 namespace mi { 00076 00077 00083 namespace shader { 00084 00085 00087 struct Options; 00088 class LightList; 00089 00101 struct Framebuffer { 00102 public: 00107 virtual bool set( 00108 const char *buffer, 00109 const char *param, 00110 const bool value) = 0; 00111 00116 virtual bool set( 00117 const char *buffer, 00118 const char *param, 00119 const float value) = 0; 00120 00125 virtual bool set( 00126 const char *buffer, 00127 const char *param, 00128 const int value) = 0; 00129 00134 virtual bool set( 00135 const char *buffer, 00136 const char *param, 00137 const char *value) = 0; 00138 00145 virtual bool get( 00146 const char *buffer, 00147 const char *param, 00148 bool &value) const = 0; 00149 00156 virtual bool get( 00157 const char *buffer, 00158 const char *param, 00159 float &value) const = 0; 00160 00167 virtual bool get( 00168 const char *buffer, 00169 const char *param, 00170 int &value) const = 0; 00171 00178 virtual bool get( 00179 const char *buffer, 00180 const char *param, 00181 const char *&value) const = 0; 00182 00189 virtual bool get_index(const char *buffer, size_t &index) const = 0; 00190 00194 virtual bool reset() = 0; 00195 00197 virtual void echo(FILE *) const = 0; 00198 00202 virtual bool get_buffercount(size_t &buffercount) const = 0; 00203 00210 virtual bool get_buffername(size_t num, const char *&name) const = 0; 00211 00215 virtual bool remove(const char *buffer) = 0; 00216 }; 00217 00219 00223 class Access_fb_prim { 00224 public: 00225 virtual const Framebuffer * operator->() = 0; 00226 virtual void release() = 0; 00227 }; 00228 00230 00235 class Access_fb { 00236 public: 00239 Access_fb( 00240 miTag tag); 00241 00243 ~Access_fb(); 00244 00246 const Framebuffer * operator->(); 00247 private: 00248 Access_fb(); 00249 Access_fb(const Access_fb &); 00250 const Access_fb & operator=(const Access_fb &); 00251 Access_fb_prim *m_afb; 00252 }; 00253 00255 00259 00260 class Edit_fb_prim { 00261 public: 00262 virtual Framebuffer * operator->() = 0; 00263 virtual void release() = 0; 00264 }; 00265 00267 00271 00272 class Edit_fb { 00273 public: 00276 Edit_fb( 00277 miTag tag); 00278 00280 ~Edit_fb(); 00281 00283 Framebuffer * operator->(); 00284 private: 00285 Edit_fb(); 00286 Edit_fb(const Edit_fb &); 00287 const Edit_fb & operator=(const Edit_fb &); 00288 Edit_fb_prim *m_efb; 00289 }; 00290 00310 00311 struct Interface { 00328 static inline Interface* get( 00329 int version = mi_ray_interface_version) 00330 { 00331 return mi_get_shader_interface(version); 00332 } 00333 00347 virtual Options *getOptions( 00348 miTag string_options); 00349 00353 virtual miTag createFramebuffer(); 00354 00359 virtual miTag copyFramebuffer( 00360 miTag old_buffer_tag); 00361 00363 00370 virtual Access_fb_prim *accessFramebuffer( 00371 miTag buffer_tag); 00372 00379 virtual Edit_fb_prim *editFramebuffer( 00380 miTag buffer_tag); 00381 00383 00395 virtual LightList *createLightList( 00396 miState *state, 00397 miTag *slist = 0, 00398 int n = 0); 00399 00406 virtual void release(); 00407 00408 00422 virtual LightList *createLightList( 00423 miState *state, 00424 const miVector &axis, 00425 miScalar spread_cos, 00426 miTag *slist = 0, 00427 int n = 0); 00428 }; 00429 00430 00469 00470 struct Options { 00472 00476 virtual void set( 00477 const char *name, 00478 bool value) = 0; 00479 00485 virtual void set( 00486 const char *name, 00487 const char * value) = 0; 00488 00493 virtual void set( 00494 const char *name, 00495 int value) = 0; 00496 00500 virtual void set( 00501 const char *name, 00502 float value) = 0; 00503 00509 virtual void set( 00510 const char *name, 00511 float value1, 00512 float value2, 00513 float value3) = 0; 00514 00521 virtual void set( 00522 const char *name, 00523 float value1, 00524 float value2, 00525 float value3, 00526 float value4) = 0; 00527 00533 virtual bool get( 00534 const char *name, 00535 bool *value) const = 0; 00536 00544 virtual bool get( 00545 const char *name, 00546 const char **value) const = 0; 00547 00553 virtual bool get( 00554 const char *name, 00555 int *value) const = 0; 00556 00565 virtual bool get( 00566 const char *name, 00567 float *value) const = 0; 00568 00581 virtual bool get( 00582 const char *name, 00583 float *value1, 00584 float *value2, 00585 float *value3) const = 0; 00586 00601 virtual bool get( 00602 const char *name, 00603 float *value1, 00604 float *value2, 00605 float *value3, 00606 float *value4) const = 0; 00607 00613 virtual bool remove( 00614 const char *name) = 0; 00615 00619 virtual void release() = 0; 00620 }; 00621 00622 00648 class LightIterator { 00649 public: 00666 LightIterator( 00667 miState* state, 00668 miTag* shader_light_list = 0, 00669 int n_shader_lights = 0, 00670 int version = mi_ray_interface_version); 00671 00685 LightIterator( 00686 miState* state, 00687 const miVector &axis, 00688 miScalar spread_cos, 00689 miTag* shader_light_list = 0, 00690 int n_shader_lights = 0, 00691 int version = mi_ray_interface_version); 00692 00693 00699 LightIterator(const LightIterator &liter); 00700 00705 ~LightIterator(); 00706 00713 miTag operator*() const; 00714 00727 LightList* operator->() const; 00728 00737 const LightIterator& operator++(); 00738 00748 LightIterator operator++(int); 00749 00754 bool at_end() const; 00755 00759 const LightIterator &operator=(const LightIterator &iter); 00760 00766 bool operator==(const LightIterator &iter) const; 00767 00773 bool operator!=(const LightIterator &iter) const; 00774 00775 private: 00779 LightList* m_list; 00780 00784 size_t m_current; 00785 }; 00786 00796 class LightList { 00797 public: 00798 00806 virtual size_t set_current(size_t current) = 0; 00807 00812 virtual size_t get_current() const = 0; 00813 00819 virtual bool sample() = 0; 00820 00825 virtual miScalar get_dot_nl() const = 0; 00826 00831 virtual const miVector& get_direction() const = 0; 00832 00839 virtual void get_contribution(miColor *c) const = 0; 00840 00847 virtual void get_contribution(miSpectrum *s) const = 0; 00848 00855 virtual int get_number_of_samples() const = 0; 00856 00863 virtual miTag get_light_tag(size_t current) const = 0; 00864 00868 virtual size_t get_number_of_lights() const = 0; 00869 00875 virtual void connect() = 0; 00876 00882 virtual void release() = 0; 00883 }; 00884 00885 //----------------------------------------------------------------------------- 00886 // inline implementation for LightIterator methods 00887 //----------------------------------------------------------------------------- 00888 00902 inline LightIterator::LightIterator( 00903 miState *state, 00904 const miVector &axis, 00905 miScalar spread_cos, 00906 miTag *shader_light_list, 00907 int n_shader_lights, 00908 int version) 00909 : m_list(0) 00910 , m_current(0) 00911 { 00912 Interface* iface = Interface::get(version); 00913 m_list = iface->createLightList(state, axis, spread_cos, shader_light_list, n_shader_lights); 00914 iface->release(); 00915 } 00916 00917 00928 inline LightIterator::LightIterator( 00929 miState *state, 00930 miTag *shader_light_list, 00931 int n_shader_lights, 00932 int version) 00933 : m_list(0) 00934 , m_current(0) 00935 { 00936 Interface* iface = Interface::get(version); 00937 m_list = iface->createLightList(state, state->normal, 0, shader_light_list, n_shader_lights); 00938 iface->release(); 00939 } 00940 00945 inline LightIterator::LightIterator(const LightIterator &iter) 00946 : m_list(iter.m_list) 00947 , m_current(iter.m_current) 00948 { 00949 if(m_list) m_list->connect(); 00950 } 00951 00955 inline LightIterator::~LightIterator() 00956 { 00957 if(m_list) m_list->release(); 00958 } 00959 00968 inline const LightIterator& LightIterator::operator=(const LightIterator &iter) 00969 { 00970 if(m_list != iter.m_list) { 00971 // need the compare above, otherwise the release might delete the list 00972 // and the connect below would be invalid. 00973 m_list->release(); 00974 m_list = iter.m_list; 00975 m_list->connect(); 00976 } 00977 m_current = iter.m_current; 00978 return *this; 00979 } 00980 00986 inline miTag LightIterator::operator*() const 00987 { 00988 return m_list->get_light_tag(m_current); 00989 } 00990 00996 inline LightList* LightIterator::operator->() const 00997 { 00998 m_list->set_current(m_current); 00999 return m_list; 01000 } 01001 01006 inline const LightIterator& LightIterator::operator++() 01007 { 01008 ++m_current; 01009 return *this; 01010 } 01011 01016 inline LightIterator LightIterator::operator++(int) 01017 { 01018 LightIterator res(*this); 01019 ++m_current; 01020 return res; 01021 } 01022 01026 inline bool LightIterator::at_end() const 01027 { 01028 return m_current == m_list->get_number_of_lights(); 01029 } 01030 01034 inline bool LightIterator::operator==(const LightIterator &iter) const 01035 { 01036 return m_list == iter.m_list && m_current == iter.m_current; 01037 } 01038 01042 inline bool LightIterator::operator!=(const LightIterator &iter) const 01043 { 01044 return !this->operator==(iter); 01045 } 01046 01049 inline Access_fb::Access_fb( 01050 miTag tag) 01051 : m_afb(0) 01052 { 01053 mi::shader::Interface *iface = mi_get_shader_interface(); 01054 m_afb = iface->accessFramebuffer(tag); 01055 iface->release(); 01056 iface = 0; 01057 } 01058 01059 inline Access_fb::~Access_fb() 01060 { 01061 if(m_afb != 0){ 01062 m_afb->release(); 01063 } 01064 } 01065 01066 inline const Framebuffer * Access_fb::operator->() 01067 { 01068 if(m_afb != 0){ 01069 return (*m_afb).operator->(); 01070 } 01071 return 0; 01072 } 01073 01076 inline Edit_fb::Edit_fb( 01077 miTag tag) 01078 : m_efb(0) 01079 { 01080 mi::shader::Interface *iface = mi_get_shader_interface(); 01081 m_efb = iface->editFramebuffer(tag); 01082 iface->release(); 01083 iface = 0; 01084 } 01085 01086 inline Edit_fb::~Edit_fb() 01087 { 01088 if(m_efb != 0){ 01089 m_efb->release(); 01090 } 01091 } 01092 01093 inline Framebuffer * Edit_fb::operator->() 01094 { 01095 if(m_efb != 0){ 01096 return (*m_efb).operator->(); 01097 } 01098 return 0; 01099 } 01100 01101 } // namespace shader 01102 } // namespace mi 01103 01104 #endif // MI_SHADER_IF_H
Copyright © 1986-2008 by
mental images GmbH