/////////////////////////////////////////////////////////////////////////// // File : RCKShaderCG.h // // Author : Florian Delizy // // // // Virtools SDK : Implementation of CG shaders // // Provides backward compatibility from the CgFX 1.2.1 to CgFX 1.1 // // // // Copyright (c) Virtools 2003, All Rights Reserved. // /////////////////////////////////////////////////////////////////////////// #include "CgFXCompat.h" // // CgFXEffectHelper : used to manage parameters using CgFX 1.1 (useless in 1.2) // // Constructor parse the params of the effect, should be recreated after // every compilation of the shader // iEffect : the CgFX object to use CgFXEffectHelper::CgFXEffectHelper(ICgFXEffect * iEffect) { XASSERT(iEffect); m_Effect = iEffect; #ifndef USE_CGFX_121 _ParseParams(); #endif } // // Destroy the data of the object // CgFXEffectHelper::~CgFXEffectHelper(void) { m_Effect = NULL; #ifndef USE_CGFX_121 m_names.Clear(); m_semantics.Clear(); #endif } #ifndef USE_CGFX_121 // This part is useless with CgFX 1.2.1 // // Parse the parameters from the m_Effect var // void CgFXEffectHelper::_ParseParams(void) { CgFXEFFECT_DESC desc; HRESULT hr; XASSERT(m_Effect); hr = m_Effect->GetDesc(&desc); XASSERT(hr); for (UINT i = 0; i < desc.Parameters; i++) { CgFXPARAMETER_DESC pdesc; hr = m_Effect->GetParameterDesc( (CGFXHANDLE) i, &pdesc); m_names.PushBack(Pair(XString(pdesc.Name), (CGFXHANDLE) i)); if (pdesc.Semantic) m_semantics.PushBack(Pair(XString(pdesc.Semantic), (CGFXHANDLE) i)); } } // // Get the parameter by looking in the table // CGFXHANDLE CgFXEffectHelper::GetParameterBySemantic(const XString & semantic) { int nbs = m_semantics.Size(); for (int i = 0; i < nbs; i++) { if (m_semantics[i].string == semantic) return m_semantics[i].handle; } return NULL; } // Get the parameter given its name (table lookup) CGFXHANDLE CgFXEffectHelper::GetParameterByName( const XString name) { int nbs = m_names.Size(); for (int i = 0; i < nbs; i++) { if (m_names[i].string == name) return m_names[i].handle; } return NULL; } #endif // #ifndef USE_CGFX_121