Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CgFx.h

Go to the documentation of this file.
00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
00011 
00012 #pragma once
00013 
00015 #include "nvsgcommon.h"
00016 
00017 #include "CgFX/ICgFXEffect.h"
00018 #include "nvsg/StateAttribute.h"
00019 #include <string>
00020 #include <vector>
00021 
00022 namespace nvsg
00023 {
00024   class  CgFx;
00025   class  CgFxEntity;
00026   class  CgFxParameter;
00027   class  CgFxAnnotation;
00028   class  CgFxPass;
00029   class  CgFxTechnique;
00030 
00031   typedef const CgFxEntity     * CgFxEntityHandle;      
00032   typedef const CgFxAnnotation * CgFxAnnotationHandle;  
00033   typedef const CgFxParameter  * CgFxParameterHandle;   
00034   typedef const CgFxTechnique  * CgFxTechniqueHandle;   
00035   typedef const CgFxPass       * CgFxPassHandle;        
00036 
00037   typedef enum
00038   { // known semantics
00039     CGFX_SEMANTIC_UNKNOWN = 0,
00040     CGFX_SEMANTIC_WORLD,                       
00041     CGFX_SEMANTIC_FIRST_TRANSFORM = CGFX_SEMANTIC_WORLD,
00042     CGFX_SEMANTIC_VIEW,                        
00043     CGFX_SEMANTIC_PROJECTION,                  
00044     CGFX_SEMANTIC_WORLDT,                      
00045     CGFX_SEMANTIC_VIEWT,                       
00046     CGFX_SEMANTIC_PROJECTIONT,                 
00047     CGFX_SEMANTIC_WORLDI,                      
00048     CGFX_SEMANTIC_VIEWI,                       
00049     CGFX_SEMANTIC_PROJECTIONI,                 
00050     CGFX_SEMANTIC_WORLDIT,                     
00051     CGFX_SEMANTIC_VIEWIT,                      
00052     CGFX_SEMANTIC_PROJECTIONIT,                
00053     CGFX_SEMANTIC_WORLDVIEW,                   
00054     CGFX_SEMANTIC_WORLDVIEWPROJECTION,         
00055     CGFX_SEMANTIC_WORLDVIEWT,                  
00056     CGFX_SEMANTIC_WORLDVIEWPROJECTIONT,        
00057     CGFX_SEMANTIC_WORLDVIEWI,                  
00058     CGFX_SEMANTIC_WORLDVIEWPROJECTIONI,        
00059     CGFX_SEMANTIC_WORLDVIEWIT,                 
00060     CGFX_SEMANTIC_WORLDVIEWPROJECTIONIT,       
00061     CGFX_SEMANTIC_LAST_TRANSFORM = CGFX_SEMANTIC_WORLDVIEWPROJECTIONIT 
00062   } eCgFxSemantic;
00063 
00065   typedef std::pair<eCgFxSemantic, CgFxParameterHandle> CgFxTransform;
00066 
00067 #if !defined(DOXYGEN_IGNORE) // The following are implementation details and need no public documentation.
00068                              // Exclude them from doxygen build
00069 
00070   // holds data common to all 'CgFx entities' like CgFxParameter, CgFxAnnotation, CgFxTechnique, and CgFxPass
00071   // note: this cannot be instantiated by general clients
00072   class CgFxEntity : public nvutil::RCObject
00073   {
00074     friend class CgFx; // private to CgFx implementation!
00075   protected:
00076     CgFxEntity();
00077     virtual ~CgFxEntity();
00078     CGFXHANDLE hdl;                     // opaque handle to talk to the corresponding effect
00079     std::vector<CgFxAnnotation*> annos; // collection of optional annotations 
00080   };
00081 
00082   // represents a CgFx parameter in general and acts as a helper used with the CgFx implementation
00083   // note: this cannot be instantiated by general clients
00084   class CgFxParameter : public CgFxEntity
00085   {
00086     friend class CgFx; // private to CgFx implementation ...
00087     
00088     // ... and the following queries
00089     friend const char *      getParameterName          (CgFxParameterHandle hdl);
00090     friend const char *      getParameterSemantic      (CgFxParameterHandle hdl);
00091     friend CgFXPARAMETERTYPE getParameterType          (CgFxParameterHandle hdl);
00092     friend bool              isParameterScalarType     (CgFxParameterHandle hdl);
00093     friend bool              isParameterVector2Type    (CgFxParameterHandle hdl);
00094     friend bool              isParameterVector3Type    (CgFxParameterHandle hdl);
00095     friend bool              isParameterVector4Type    (CgFxParameterHandle hdl);
00096     friend bool              isParameterMatrix33Type   (CgFxParameterHandle hdl);
00097     friend bool              isParameterMatrix34Type   (CgFxParameterHandle hdl);
00098     friend bool              isParameterMatrix43Type   (CgFxParameterHandle hdl);
00099     friend bool              isParameterMatrix44Type   (CgFxParameterHandle hdl);
00100     friend bool              isParameterTextureType    (CgFxParameterHandle hdl);
00101     friend bool              isParameterSamplerType    (CgFxParameterHandle hdl);
00102 
00103   protected:
00104     CgFxParameter() {}
00105     virtual ~CgFxParameter() {}
00106     CgFXPARAMETER_DESC desc;        // detailed description for this parameter
00107   };
00108 
00109   // represents an annotation for a general entity
00110   // note: as defined by the CgFX spec, an annotation itself is a parameter
00111   // note: this cannot be instantiated by general clients
00112   class CgFxAnnotation : public CgFxParameter
00113   {
00114     friend class CgFx; // private to CgFx implementation
00115   protected:
00116     CgFxAnnotation() {}
00117     ~CgFxAnnotation() {}
00118   };
00119 
00120   // represents a CgFx pass description and acts as a helper used with the CgFx implementation
00121   // note: this cannot be instantiated by general clients
00122   class CgFxPass : public CgFxEntity
00123   {
00124     friend class CgFx; // private to CgFx implementation ... 
00125     friend const char * getPassName (CgFxPassHandle hdl); // ... and this query
00126   protected:
00127     CgFxPass() {}
00128     ~CgFxPass() {}
00129     CgFXPASS_DESC desc;             
00130   };
00131 
00132   // represents a CgFx technique description and acts as a helper used with the CgFx implementation
00133   // note: this cannot be instantiated by general clients
00134   class CgFxTechnique : public CgFxEntity
00135   {
00136     friend class CgFx; // private to CgFx implementation ...
00137     // ... and the following queries
00138     friend const char * getTechniqueName (CgFxTechniqueHandle hdl);
00139     friend bool         isTechniqueValid (CgFxTechniqueHandle hdl);
00140   protected:
00141     CgFxTechnique();                // initialization
00142     ~CgFxTechnique();               // termination
00143     CgFXTECHNIQUE_DESC desc;        // detailed technique description
00144     std::vector<CgFxPass*> passes;  // required render passes for this technique
00145     bool valid;                     // assigns whether this is a valid technique for the current environment
00146   };
00147 
00148 #endif // DOXYGEN_IGNORE
00149 
00151 
00153   class CgFx : public StateAttribute
00154   {
00155     public: // public interface
00156 
00158 
00159       NVSG_API static const CgFx * create( void );
00160 
00162 
00163       NVSG_API static const CgFx * createFromBase( const StateAttribute &rhs    
00164                                                  );
00165 
00167 
00168       NVSG_API virtual const CgFx * clone( void ) const;
00169 
00171 
00173       NVSG_API bool createEffectFromFile( const std::string& file    
00174                                         );
00175 
00177 
00178       NVSG_API bool isEffectValid( void ) const;
00179 
00181 
00182       NVSG_API const std::string& getEffectFile( void ) const;
00183 
00185 
00186       NVSG_API size_t getNumberOfTransforms( void ) const;
00187 
00189 
00190       NVSG_API const CgFxTransform& getTransform( size_t index    
00191                                                 ) const;
00192 
00194 
00195       NVSG_API size_t getNumberOfTweakables( void ) const;
00196       
00198 
00199       NVSG_API CgFxParameterHandle getTweakable( size_t index   
00200                                                ) const;
00201 
00203 
00204       NVSG_API CgFxParameterHandle getTweakable( const std::string& name   
00205                                                ) const;
00206 
00208 
00209       NVSG_API size_t getNumberOfAnnotations( CgFxEntityHandle hdl    
00210                                             ) const;
00211 
00213 
00214       NVSG_API CgFxAnnotationHandle getAnnotation( CgFxEntityHandle hdl   
00215                                                  , size_t index           
00216                                                  ) const;
00217 
00219 
00220       NVSG_API CgFxAnnotationHandle getAnnotation( CgFxEntityHandle hdl   
00221                                                  , const std::string& name     
00222                                                  ) const;
00223 
00225 
00228       template<typename ValueType>
00229       void getValue( CgFxParameterHandle hdl    
00230                   , ValueType& value            
00231                   ) const;
00232 
00234       template<typename ValueType>
00235       void getValue( CgFxParameterHandle hdl    
00236                   , ValueType * value           
00237                   ) const;
00238 
00240       NVSG_API void getValue( CgFxParameterHandle hdl   
00241                             , const char ** value       
00242                             ) const;
00243 
00245       NVSG_API void getValue( CgFxParameterHandle hdl   
00246                             , std::string& value             
00247                             ) const;
00248 
00250 
00253       template<typename ValueType>
00254       void setValue( CgFxParameterHandle hdl    
00255                   , const ValueType& value      
00256                   );
00257 
00258       template<typename ValueType>
00259       void setValue( CgFxParameterHandle hdl    
00260                   , const ValueType& value      
00261                   ) const ;
00262 
00264       template<typename ValueType>
00265       void setValue( CgFxParameterHandle hdl    
00266                   , const ValueType * value     
00267                   );
00268 
00269       template<typename ValueType>
00270       void setValue( CgFxParameterHandle hdl    
00271                   , const ValueType * value     
00272                   ) const;
00273 
00275       NVSG_API void setValue( CgFxParameterHandle hdl   
00276                             , const char * value        
00277                             );
00278       
00279       NVSG_API void setValue( CgFxParameterHandle hdl   
00280                             , const char * value        
00281                             ) const;
00282 
00284       NVSG_API void setValue( CgFxParameterHandle hdl   
00285                             , const std::string& value       
00286                             );
00287       
00288       NVSG_API void setValue( CgFxParameterHandle hdl   
00289                             , const std::string& value       
00290                             ) const;
00291 
00293 
00294       NVSG_API size_t getNumberOfTechniques( void ) const;
00295 
00297 
00298       NVSG_API CgFxTechniqueHandle getTechnique( size_t index   
00299                                                ) const;
00300 
00301       // Get the current technique.
00303       NVSG_API size_t getCurrentTechnique( void ) const;
00304 
00305       // Set the current technique.
00307       NVSG_API void setCurrentTechnique( size_t index   
00308                                        );
00309       
00311 
00313       NVSG_API bool validateCurrentTechnique( void ) const;
00314       
00316 
00317       NVSG_API bool isCurrentTechniqueValid( void ) const;
00318 
00320 
00321       NVSG_API bool isCurrentTechniqueValidationPending( void ) const;
00322 
00324 
00325       NVSG_API size_t getNumberOfPasses( CgFxTechniqueHandle hdl    
00326                                        ) const;
00327 
00329 
00330       NVSG_API CgFxPassHandle getPass( CgFxTechniqueHandle hdl    
00331                                      , size_t index               
00332                                      ) const;
00333 
00335 
00339       NVSG_API bool passFirstPass( void ) const;
00340 
00342 
00345       NVSG_API bool passNextPass( void ) const;
00346 
00347       //--  Functions reimplemented from Object  --
00349 
00351       NVSG_API virtual DataID getDataID( void ) const;
00352       
00354 
00356       NVSG_API virtual bool isDataShared( void ) const;
00357 
00358     protected:
00360       NVSG_API CgFx( void );
00361 
00363       NVSG_API CgFx( const StateAttribute &rhs );
00364 
00366       NVSG_API CgFx( const CgFx& rhs );
00367       
00368       /* prohibit explicit creation on stack by making the destructor protected */
00369       NVSG_API virtual ~CgFx(void);
00370 
00371     private: // private interface
00372       bool initEffect( void );
00373       void initAnnotations( CgFxEntity * p, size_t count );
00374 
00375     private: // private data
00376       ICgFXEffect            * m_effect;    
00377       // 
00378       std::string                   m_file;      
00379       //
00380       std::vector<CgFxTransform>    m_trafos;    
00381       std::vector<CgFxParameter*>   m_tweaks;    
00382       //
00383       std::vector<CgFxTechnique*>   m_techs;     
00384       mutable size_t           m_currTech;  
00385       mutable size_t           m_lastCurrTech; 
00386       mutable size_t           m_currPass;  
00387       mutable size_t           m_numPasses; 
00388   };
00389 
00390 
00391   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00392   // inline implementations can go here
00393   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00394 
00396 
00401   NVSG_API bool CgFx_getTextureFileName( const CgFx * cgfx, CgFxParameterHandle hdl, std::string& file );
00402 
00404 
00407   NVSG_API void CgFx_setTextureFileName( CgFx * cgfx, CgFxParameterHandle hdl, const std::string& file );
00408 
00410 
00411   inline const char * getParameterName( CgFxParameterHandle hdl )
00412   {
00413     __ASSERT(hdl);
00414     return hdl->desc.Name;
00415   }
00416 
00418 
00419   inline const char * getPassName( CgFxPassHandle hdl )
00420   {
00421     __ASSERT(hdl);
00422     return hdl->desc.Name;
00423   }
00424 
00426 
00427   inline const char * getTechniqueName( CgFxTechniqueHandle hdl )
00428   {
00429     __ASSERT(hdl);
00430     return hdl->desc.Name;
00431   }
00432 
00434 
00435   inline const char * getParameterSemantic( CgFxParameterHandle hdl )
00436   {
00437     __ASSERT(hdl);
00438     return hdl->desc.Semantic;
00439   }
00440 
00442 
00443   inline CgFXPARAMETERTYPE getParameterType( CgFxParameterHandle hdl )
00444   {
00445     __ASSERT(hdl);
00446     return hdl->desc.Type;
00447   }
00448 
00450 
00451   inline bool isParameterScalarType( CgFxParameterHandle hdl )
00452   {
00453     __ASSERT(hdl);
00454     return hdl->desc.Dimension[1]==0 && hdl->desc.Dimension[0]==1; 
00455   }
00456 
00458 
00459   inline bool isParameterVector2Type( CgFxParameterHandle hdl )
00460   {
00461     __ASSERT(hdl);
00462     return hdl->desc.Dimension[1]==0 && hdl->desc.Dimension[0]==2;
00463   }
00464 
00466 
00467   inline bool isParameterVector3Type( CgFxParameterHandle hdl )
00468   {
00469     __ASSERT(hdl);
00470     return hdl->desc.Dimension[1]==0 && hdl->desc.Dimension[0]==3;
00471   }
00472 
00474 
00475   inline bool isParameterVector4Type( CgFxParameterHandle hdl )
00476   {
00477     __ASSERT(hdl);
00478     return hdl->desc.Dimension[1]==0 && hdl->desc.Dimension[0]==4;
00479   }
00480 
00482 
00483   inline bool isParameterMatrix33Type( CgFxParameterHandle hdl )
00484   {
00485     __ASSERT(hdl);
00486     return hdl->desc.Dimension[1]==3 && hdl->desc.Dimension[0]==3; 
00487   }
00488 
00490 
00491   inline bool isParameterMatrix34Type( CgFxParameterHandle hdl )
00492   {
00493     __ASSERT(hdl);
00494     return hdl->desc.Dimension[1]==4 && hdl->desc.Dimension[0]==3; 
00495   }
00496 
00498 
00499   inline bool isParameterMatrix43Type( CgFxParameterHandle hdl )
00500   {
00501     __ASSERT(hdl);
00502     return hdl->desc.Dimension[1]==3 && hdl->desc.Dimension[0]==4; 
00503   }
00504 
00506 
00507   inline bool isParameterMatrix44Type( CgFxParameterHandle hdl )
00508   {
00509     __ASSERT(hdl);
00510     return hdl->desc.Dimension[1]==4 && hdl->desc.Dimension[0]==4; 
00511   }
00512 
00514 
00515   inline bool isParameterTextureType( CgFxParameterHandle hdl )
00516   {
00517     __ASSERT(hdl);
00518     return hdl->desc.Type>=CgFXPT_TEXTURE1D && hdl->desc.Type<=CgFXPT_TEXTURE3D; 
00519   }
00520 
00522 
00523   inline bool isParameterSamplerType( CgFxParameterHandle hdl )
00524   {
00525     __ASSERT(hdl);
00526     return hdl->desc.Type>=CgFXPT_SAMPLER1D && hdl->desc.Type<=CgFXPT_SAMPLER3D; 
00527   }
00528 
00530 
00531   inline bool isTechniqueValid( CgFxTechniqueHandle hdl )
00532   {
00533     __ASSERT(hdl);
00534     return hdl->valid;
00535   }
00536 
00537   inline bool CgFx::isEffectValid( void ) const
00538   {
00539     __TRACE();
00540     return m_effect!=NULL;
00541   }
00542 
00543   inline const std::string& CgFx::getEffectFile( void ) const 
00544   { 
00545     __TRACE();
00546     return m_file; 
00547   }
00548 
00549   inline size_t CgFx::getNumberOfTransforms( void ) const
00550   {
00551     __TRACE();
00552     return m_trafos.size();
00553   }
00554 
00555   inline const CgFxTransform& CgFx::getTransform( size_t index ) const
00556   {
00557     __TRACE();
00558     __ASSERT(index<m_trafos.size());
00559     return m_trafos[index];
00560   }
00561 
00562   inline size_t CgFx::getNumberOfTweakables( void ) const
00563   {
00564     __TRACE();
00565     return m_tweaks.size();
00566   }
00567       
00568   inline CgFxParameterHandle CgFx::getTweakable( size_t index ) const
00569   {
00570     __TRACE();
00571     __ASSERT(index<m_tweaks.size());
00572     return m_tweaks[index];
00573   }
00574 
00575   inline size_t CgFx::getNumberOfAnnotations( CgFxEntityHandle hdl ) const
00576   {
00577     __TRACE();
00578     __ASSERT(hdl);
00579     return hdl->annos.size();
00580   }
00581 
00582   inline CgFxAnnotationHandle CgFx::getAnnotation( CgFxEntityHandle hdl, size_t index ) const
00583   {
00584     __TRACE();
00585     __ASSERT(hdl && index<hdl->annos.size());
00586     return hdl->annos[index];
00587   }
00588 
00589   template<typename ValueType>
00590   inline void CgFx::getValue( CgFxParameterHandle hdl, ValueType& value ) const
00591   {
00592     //  __TRACE();  produces an internal compiler error
00593 #if !defined(CGFX_NOT_SUPPORTED)
00594     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00595     __ASSERT(hdl->desc.Type!=CgFXPT_STRING); // must not use this for string parameters
00596     __ASSERT(hdl->desc.Bytes==sizeof(ValueType)); // sizes must match
00597     __VERIFY(SUCCEEDED(m_effect->GetValue(hdl->hdl, &value, hdl->desc.Bytes)));
00598 #endif
00599   }
00600 
00601   template<typename ValueType>
00602   inline void CgFx::getValue( CgFxParameterHandle hdl, ValueType * value ) const
00603   {
00604     //  __TRACE();  produces an internal compiler error
00605 #if !defined(CGFX_NOT_SUPPORTED)
00606     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00607     __ASSERT(hdl->desc.Type!=CgFXPT_STRING); // must not use this for string parameters
00608     __ASSERT(!(hdl->desc.Bytes%sizeof(ValueType))); // sizes must match
00609     __VERIFY(SUCCEEDED(m_effect->GetValue(hdl->hdl, value, hdl->desc.Bytes)));
00610 #endif
00611   }
00612 
00613   inline void CgFx::getValue( CgFxParameterHandle hdl, const char ** value ) const
00614   {
00615     __TRACE();
00616 #if !defined(CGFX_NOT_SUPPORTED)
00617     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00618     __ASSERT(hdl->desc.Type==CgFXPT_STRING); // must not use this for other than string parameters
00619     __VERIFY(SUCCEEDED(m_effect->GetString(hdl->hdl, (LPCSTR*)value)));
00620 #endif
00621   }
00622 
00623   inline void CgFx::getValue( CgFxParameterHandle hdl, std::string& value ) const
00624   {
00625     __TRACE();
00626 #if !defined(CGFX_NOT_SUPPORTED)
00627     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00628     __ASSERT(hdl->desc.Type==CgFXPT_STRING); // must not use this for other than string parameters
00629     LPCSTR s;
00630     __VERIFY(SUCCEEDED(m_effect->GetString(hdl->hdl, &s)));
00631     value=s;
00632 #endif
00633   }
00634 
00635   template<typename ValueType>
00636   inline void CgFx::setValue( CgFxParameterHandle hdl, const ValueType& value )
00637   {
00638     //  __TRACE();  produces an internal compiler error
00639 #if !defined(CGFX_NOT_SUPPORTED)
00640     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00641     __ASSERT(hdl->desc.Type!=CgFXPT_STRING); // must not use this for string parameters
00642     __ASSERT(hdl->desc.Bytes==sizeof(ValueType)); // sizes must match
00643     __VERIFY(SUCCEEDED(m_effect->SetValue(hdl->hdl, &value, hdl->desc.Bytes)));
00644     ++m_incarnation; // force new validation 
00645 #endif
00646   }
00647 
00648   template<typename ValueType>
00649   inline void CgFx::setValue( CgFxParameterHandle hdl, const ValueType * value )
00650   {
00651     //  __TRACE();  produces an internal compiler error
00652 #if !defined(CGFX_NOT_SUPPORTED)
00653     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00654     __ASSERT(hdl->desc.Type!=CgFXPT_STRING); // must not use this for string parameters
00655     __ASSERT(!(hdl->desc.Bytes%sizeof(ValueType))); // sizes must match
00656     __VERIFY(SUCCEEDED(m_effect->SetValue(hdl->hdl, value, hdl->desc.Bytes)));
00657     ++m_incarnation; // force new validation 
00658 #endif
00659   }
00660 
00661   inline void CgFx::setValue( CgFxParameterHandle hdl, const char * value )
00662   {
00663     __TRACE();
00664 #if !defined(CGFX_NOT_SUPPORTED)
00665     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00666     __ASSERT(hdl->desc.Type==CgFXPT_STRING); // must not use this for other than string parameters
00667     __VERIFY(SUCCEEDED(m_effect->SetString(hdl->hdl, (LPCSTR)value)));
00668     ++m_incarnation; // force new validation 
00669 #endif
00670   }
00671 
00672   inline void CgFx::setValue( CgFxParameterHandle hdl, const std::string& value )
00673   {
00674     __TRACE();
00675 #if !defined(CGFX_NOT_SUPPORTED)
00676     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00677     __ASSERT(hdl->desc.Type==CgFXPT_STRING); // must not use this for other than string parameters
00678     __VERIFY(SUCCEEDED(m_effect->SetString(hdl->hdl, value.c_str())));
00679     ++m_incarnation; // force new validation 
00680 #endif
00681   }
00682 
00683   template<typename ValueType>
00684   inline void CgFx::setValue( CgFxParameterHandle hdl, const ValueType& value ) const
00685   {
00686     __TRACE();
00687 #if !defined(CGFX_NOT_SUPPORTED)
00688     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00689     __ASSERT(hdl->desc.Type!=CgFXPT_STRING); // must not use this for string parameters
00690     __ASSERT(hdl->desc.Bytes==sizeof(ValueType)); // sizes must match
00691     __VERIFY(SUCCEEDED(m_effect->SetValue(hdl->hdl, &value, hdl->desc.Bytes)));
00692 #endif
00693   }
00694 
00695   template<typename ValueType>
00696   inline void CgFx::setValue( CgFxParameterHandle hdl, const ValueType * value ) const
00697   {
00698     __TRACE();
00699 #if !defined(CGFX_NOT_SUPPORTED)
00700     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00701     __ASSERT(hdl->desc.Type!=CgFXPT_STRING); // must not use this for string parameters
00702     __ASSERT(!(hdl->desc.Bytes%sizeof(ValueType))); // sizes must match
00703     __VERIFY(SUCCEEDED(m_effect->SetValue(hdl->hdl, value, hdl->desc.Bytes)));
00704 #endif
00705   }
00706 
00707   inline void CgFx::setValue( CgFxParameterHandle hdl, const char * value ) const
00708   {
00709     __TRACE();
00710 #if !defined(CGFX_NOT_SUPPORTED)
00711     __ASSERT(m_effect); // need the embedded effect successfully created beforehand
00712     __ASSERT(hdl->desc.Type==CgFXPT_STRING); // must not use this for other than string parameters
00713     __VERIFY(SUCCEEDED(m_effect->SetString(hdl->hdl, (LPCSTR)value)));
00714 #endif
00715   }
00716 
00717   inline void CgFx::setValue( CgFxParameterHandle hdl, const std::string& value ) const
00718   {
00719 #if !defined(CGFX_NOT_SUPPORTED)
00720     __TRACE();
00721     __ASSERT(m_effect); // need the embedded effect created beforehand
00722     __ASSERT(hdl->desc.Type==CgFXPT_STRING); // must not use this for other than string parameters
00723     __VERIFY(SUCCEEDED(m_effect->SetString(hdl->hdl, value.c_str())));
00724 #endif
00725   }
00726 
00727   inline size_t CgFx::getNumberOfTechniques( void ) const
00728   {
00729     __TRACE();
00730     return m_techs.size();
00731   }
00732 
00733   inline CgFxTechniqueHandle CgFx::getTechnique( size_t index ) const
00734   {
00735     __TRACE();
00736     __ASSERT(index<m_techs.size());
00737     return m_techs[index];
00738   }
00739 
00740   inline size_t CgFx::getCurrentTechnique( void ) const
00741   {
00742     __TRACE();
00743     return m_currTech;
00744   }
00745 
00746   inline void CgFx::setCurrentTechnique( size_t index )
00747   {
00748     __TRACE();
00749     __ASSERT(index<m_techs.size());
00750     m_currTech = index;
00751     ++m_incarnation; // force new validation 
00752   }
00753       
00754   inline bool CgFx::isCurrentTechniqueValid( void ) const
00755   {
00756     __TRACE();
00757     return (m_currTech<m_techs.size()) ? m_techs[m_currTech]->valid : false;
00758   }
00759 
00760   inline bool CgFx::isCurrentTechniqueValidationPending( void ) const
00761   {
00762     __TRACE();
00763     return m_lastCurrTech != m_currTech;
00764   }
00765 
00766   inline size_t CgFx::getNumberOfPasses( CgFxTechniqueHandle hdl ) const
00767   {
00768     __TRACE();
00769     __ASSERT(hdl);
00770     return hdl->passes.size();
00771   }
00772 
00773   inline CgFxPassHandle CgFx::getPass( CgFxTechniqueHandle hdl, size_t index ) const
00774   {
00775     __TRACE();
00776     __ASSERT(hdl);
00777     __ASSERT(index<hdl->passes.size());
00778     return hdl->passes[index];
00779   }
00780 
00781 } // namespace nvsg

Generated on Tue Mar 1 13:19:19 2005 for NVSGSDK by NVIDIA