RslPlugin.h

Go to the documentation of this file.
00001 /* $Id: //depot/main/rmanprod/rman/include/shadeop.h#18 $  (Pixar - RenderMan Division) $Date: 2005/06/02 $ */
00002 /*
00003 ** Copyright (c) 2004 PIXAR.  All rights reserved.  This program or
00004 ** documentation contains proprietary confidential information and trade
00005 ** secrets of PIXAR.  Reverse engineering of object code is prohibited.
00006 ** Use of copyright notice is precautionary and does not imply
00007 ** publication.
00008 **
00009 **                      RESTRICTED RIGHTS NOTICE
00010 **
00011 ** Use, duplication, or disclosure by the Government is subject to the
00012 ** following restrictions:  For civilian agencies, subparagraphs (a) through
00013 ** (d) of the Commercial Computer Software--Restricted Rights clause at
00014 ** 52.227-19 of the FAR; and, for units of the Department of Defense, DoD
00015 ** Supplement to the FAR, clause 52.227-7013 (c)(1)(ii), Rights in
00016 ** Technical Data and Computer Software.
00017 **
00018 ** Pixar
00019 ** 1200 Park Ave.
00020 ** Emeryville, CA  94608
00021 */
00022 
00023 #ifndef RSLPLUGIN_H
00024 #define RSLPLUGIN_H
00025 
00026 // Use of typedefs like RtColor is recommended for new grid-based shadeops.
00027 // For backwards compatibility, they are not automatically included for older
00028 // pointwise shadeops.
00029 #include "ri.h"
00030 #include "RixInterfaces.h"      // RslContext inherits from RixContext
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     // Need to call private methods from iterator constructors.
00228     template<typename T> friend class RslIter;
00229     template<typename T> friend class RslArrayIter;
00230 
00231     // Get acceleration info for an iterator with "packed" user data.
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     // Need to call private methods from iterator constructors.
00298     template<typename T> friend class RslIter;
00299     template<typename T> friend class RslArrayIter;
00300 
00301     // Returns (in result parameters) the data pointer and increment list.
00302     virtual void getInfo(float** data, RslIncrType** incrList,
00303                  bool* isVarying) const = 0;
00304 
00305     // Returns (in result parameters) the data pointer, increment list, and
00306     // array length.
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;                // Copy before increment.
00374         ++*this;                        // Increment.
00375         return temp;                    // Return old value.
00376     };
00377 
00380     bool IsVarying() const { return m_isVarying; }
00381 
00382 private:
00383     // Current data pointer.
00384     float* m_data;
00385 
00386     // Current increment list, which gives fast access to next active point.
00387     RslIncrType* m_incrList;
00388 
00389     // True if the iterator is varying.
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;   // Copy before increment.
00442         ++*this;                        // Increment.
00443         return temp;                    // Return old value.
00444     };
00445         
00448     bool IsVarying() const { return m_isVarying; }
00449 
00451     int GetLength() const { return m_length; }
00452         
00453 private:
00454     // Current data pointer.
00455     float* m_data;
00456 
00457     // Current increment list, which gives fast access to next active point.
00458     RslIncrType* m_incrList;
00459 
00460     // Array length.
00461     int m_length;
00462 
00463     // True if the iterator is varying.
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 /* defined RSLPLUGIN_H */

Generated on Wed May 10 15:56:09 2006 for PRManHeaders by  doxygen 1.4.6