00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef RSLPLUGIN_H
00024 #define RSLPLUGIN_H
00025 
00026 
00027 
00028 
00029 #include "ri.h"
00030 #include "RixInterfaces.h"      
00031 
00033 #define RSL_PLUGIN_VERSION 2
00034 
00106 
00107 
00108 typedef unsigned int RslRunFlag;
00109 
00111 typedef unsigned int RslIncrType;
00112 
00115 typedef int (*RslEntryFunc)(class RslContext* ctx,
00116                             int argc, const class RslArg** argv);
00117 
00121 class RslContext : public RixContext {
00122 public:
00124     virtual ~RslContext() {}
00125 
00128     virtual const RslRunFlag* GetRunFlags(unsigned int* length) const = 0;
00129 
00133     virtual RixInterface* GetRixInterface(RixInterfaceId id) const = 0;
00134 
00155     RixStorage* GetGlobalStorage() const
00156     {
00157         return (RixStorage*) GetRixInterface(k_RixGlobalData);
00158     }
00159 
00176     RixStorage* GetThreadStorage() const
00177     {
00178         return (RixStorage*) GetRixInterface(k_RixThreadData);
00179     }
00180 
00185     RixStorage* GetLocalStorage() const
00186     {
00187         return (RixStorage*) GetRixInterface(k_RixLocalData);
00188     }
00189 
00193     void SetThreadData(void* data, RixCleanupFunc cleanup = 0L)
00194     {
00195         RixStorage* storage = (RixStorage*) GetRixInterface(k_RixThreadData);
00196         storage->Set(GetPluginName(), data, cleanup);
00197     }
00198 
00200     void* GetThreadData() const
00201     {
00202         RixStorage* storage = (RixStorage*) GetRixInterface(k_RixThreadData);
00203         return storage->Get(GetPluginName());
00204     }
00205 
00210     void SetLocalData(void* data, RixCleanupFunc cleanup = 0L)
00211     {
00212         RixStorage* storage = (RixStorage*) GetRixInterface(k_RixLocalData);
00213         storage->Set(GetPluginName(), data, cleanup);
00214     }
00215 
00217     void* GetLocalData() const
00218     {
00219         RixStorage* storage = (RixStorage*) GetRixInterface(k_RixLocalData);
00220         return storage->Get(GetPluginName());
00221     }
00222 
00224     virtual const char* GetPluginName() const = 0;
00225 
00226 private:
00227     
00228     template<typename T> friend class RslIter;
00229     template<typename T> friend class RslArrayIter;
00230 
00231     
00232     virtual RslIncrType* getIncrList(unsigned int stride) const = 0;
00233 };
00234 
00237 class RslArg {
00238 public:
00240     virtual ~RslArg() {};
00241 
00243     virtual bool IsFloat() const = 0;
00244 
00246     virtual bool IsPoint() const = 0;
00247 
00249     virtual bool IsVector() const = 0;
00250 
00252     virtual bool IsColor() const = 0;
00253 
00255     virtual bool IsString() const = 0;
00256 
00258     virtual bool IsMatrix() const = 0;
00259 
00261     virtual bool IsArray() const = 0;
00262 
00264     virtual bool IsVarying() const = 0;
00265 
00268     virtual int GetArrayLength() const = 0;
00269 
00273     virtual unsigned int NumValues() const = 0;
00274 
00278     static unsigned int NumValues(int argc, const RslArg** argv) {
00279         int m = 1;
00280         for (int i = 0; i < argc; ++i) {
00281             int n = argv[i]->NumValues();
00282             if (n > m)
00283                 m = n;
00284         }
00285         return m;
00286     }
00287 
00294     virtual void GetData(float** data, int* stride) const = 0;
00295 
00296 private:
00297     
00298     template<typename T> friend class RslIter;
00299     template<typename T> friend class RslArrayIter;
00300 
00301     
00302     virtual void getInfo(float** data, RslIncrType** incrList,
00303                  bool* isVarying) const = 0;
00304 
00305     
00306     
00307     virtual void getArrayInfo(float** data,
00308                       RslIncrType** incrList, int* arrayLength,
00309                       bool* isVarying) const = 0;
00310 };
00311 
00312 
00329 template<typename T>
00330 class RslIter {
00331 public:
00333     RslIter(const RslArg* arg)
00334     {
00335         arg->getInfo(&m_data, &m_incrList, &m_isVarying);
00336     }
00337 
00340     RslIter(const T* data, const RslContext* ctx) :
00341         m_data((float*) data),
00342         m_incrList(ctx->getIncrList(0)),
00343         m_isVarying(false)
00344     {
00345     }
00346 
00350     T& operator*() { return *((T*) m_data); }
00351 
00355     const T& operator*() const { return *((T*) m_data); }
00356 
00360     RslIter<T>& operator++() 
00361     {
00362         m_data += *m_incrList;
00363         ++m_incrList;
00364         return *this;
00365     };
00366 
00371     RslIter<T> operator++(int) 
00372     {
00373         RslIter<T> temp = *this;                
00374         ++*this;                        
00375         return temp;                    
00376     };
00377 
00380     bool IsVarying() const { return m_isVarying; }
00381 
00382 private:
00383     
00384     float* m_data;
00385 
00386     
00387     RslIncrType* m_incrList;
00388 
00389     
00390     bool m_isVarying;
00391 };
00392     
00393 
00399 template<typename T>
00400 class RslArrayIter {
00401 public:
00403     RslArrayIter(const RslArg* arg)
00404     {
00405         arg->getArrayInfo(&m_data, &m_incrList, &m_length, &m_isVarying);
00406     }
00407 
00410     RslArrayIter(const T* data, int length, const RslContext* ctx) :
00411         m_data((float*) data),
00412         m_incrList(ctx->getIncrList(0)),
00413         m_length(length),
00414         m_isVarying(false)
00415     {
00416     }
00419     T* operator*() { return (T*) m_data; }
00420 
00423     T&  operator[](int x) { return ((T*)m_data)[x]; }
00424 
00428     RslArrayIter<T>& operator++() 
00429     {
00430         m_data += *m_incrList * m_length;
00431         ++m_incrList;
00432         return *this;
00433     };
00434 
00439     RslArrayIter<T> operator++(int) 
00440     {
00441         RslArrayIter<T> temp = *this;   
00442         ++*this;                        
00443         return temp;                    
00444     };
00445         
00448     bool IsVarying() const { return m_isVarying; }
00449 
00451     int GetLength() const { return m_length; }
00452         
00453 private:
00454     
00455     float* m_data;
00456 
00457     
00458     RslIncrType* m_incrList;
00459 
00460     
00461     int m_length;
00462 
00463     
00464     bool m_isVarying;
00465 };
00466 
00467 
00468 typedef RslIter<RtFloat>        RslFloatIter;        
00469 typedef RslIter<RtString>       RslStringIter;       
00470 typedef RslIter<RtColor>        RslColorIter;        
00471 typedef RslIter<RtVector>       RslVectorIter;       
00472 typedef RslIter<RtNormal>       RslNormalIter;       
00473 typedef RslIter<RtPoint>        RslPointIter;        
00474 typedef RslIter<RtMatrix>       RslMatrixIter;       
00475 
00476 typedef RslArrayIter<RtFloat>   RslFloatArrayIter;   
00477 typedef RslArrayIter<RtString>  RslStringArrayIter;  
00478 typedef RslArrayIter<RtColor>   RslColorArrayIter;   
00479 typedef RslArrayIter<RtVector>  RslVectorArrayIter;  
00480 typedef RslArrayIter<RtNormal>  RslNormalArrayIter;  
00481 typedef RslArrayIter<RtPoint>   RslPointArrayIter;    
00482 typedef RslArrayIter<RtMatrix>  RslMatrixArrayIter;   
00483     
00484 
00487 typedef void (*RslVoidFunc)(RixContext* context);
00488 
00528 struct RslFunction {
00530     const char *m_prototype;
00531 
00533     RslEntryFunc m_entry;
00534 
00536     RslVoidFunc m_initFunc;
00537 
00539     RslVoidFunc m_cleanupFunc;
00540 };
00541 
00544 struct RslFunctionTable {
00546     const RslFunction* m_functions;
00547 
00549     const char m_version;
00550 
00552     RslVoidFunc m_initFunc;
00553 
00555     RslVoidFunc m_cleanupFunc;
00556 
00558     RslFunctionTable(const RslFunction* functions,
00559                      RslVoidFunc init = NULL, RslVoidFunc cleanup = NULL) :
00560         m_functions(functions),
00561         m_version(RSL_PLUGIN_VERSION),
00562         m_initFunc(init),
00563         m_cleanupFunc(cleanup)
00564     {
00565     }
00566 };
00567 
00577 #ifdef _MSC_VER
00578 #define RSLEXPORT __declspec(dllexport)
00579 #else
00580 #define RSLEXPORT
00581 #endif
00582 
00583 #endif