Skip to main content
gamedev.net
🔒 Locked

loading shader variables without knowing variable types or names

Started by Stellar Developer Mar 11, 2008 at 5:14 PM 2 replies 800+ views
Original Post
Stellar Developer
Stellar Developer
i need to load any number of shaders for a mesh, but given that I want to code the correct way, I want to iterate over the variables list and load them into a map. I can see how to determine the number of variables to loop over, in order to load them, but i dont see how to determine type. so i dont know whether to call AsMatrix, AsShaderResource, ect.. is there any way to get the type at runtime?
ankhd
ankhd
Hi, I think may be some thing like this may be ok

parseParameters(){    // Look at parameters for semantics and annotations that we know how to interpret    D3DXPARAMETER_DESC ParamDesc;    D3DXHANDLE hParam;    static char numerals[] = {'0','1','2','3','4','5','6','7','8','9'};	    for( UINT iParam = 0; iParam < m_EffectDesc.Parameters; iParam++ )    {        hParam = m_pEffect->GetParameter ( NULL, iParam );        m_pEffect->GetParameterDesc( hParam, &ParamDesc );        if( ParamDesc.Semantic != NULL &&             ( ParamDesc.Class == D3DXPC_MATRIX_ROWS || ParamDesc.Class == D3DXPC_MATRIX_COLUMNS ) )        {            if( strcmpi( ParamDesc.Semantic, "world" ) == 0 )                m_matrixHandle[worldMatrix] = hParam;            else if( strcmpi( ParamDesc.Semantic, "view" ) == 0 )                m_matrixHandle[viewMatrix] = hParam;            else if( strcmpi( ParamDesc.Semantic, "projection" ) == 0 )                m_matrixHandle[projMatrix] = hParam;            	   // look for texture matrices which are named texMatX	   if (strnicmp( ParamDesc.Semantic, "texmat", 6) ==0)	   {		cString name(ParamDesc.Name);		int iPos = name.find_first_of(numerals, 0, sizeof(numerals));				if (iPos != cString::npos)				{					int iTexture = atoi(&ParamDesc.Name[iPos]);					if (iTexture>=0 && iTexture<k_max_texture_handles)					{						m_textureMatrixHandle[iTexture] = hParam;					}				}			}        }        if( ParamDesc.Semantic != NULL &&             ( ParamDesc.Class == D3DXPC_VECTOR ))        {            			       }        if(ParamDesc.Class == D3DXPC_SCALAR)        {			if( ParamDesc.Semantic == NULL)			{				if( strcmpi( ParamDesc.Name, "curnumbones" ) == 0 )				{					m_paramHandle[boneInfluenceCount] = hParam;				}			}			else			{			    if( strcmpi( ParamDesc.Semantic, "materialpower" ) == 0 )					m_paramHandle[specularMaterialPower] = hParam;			}		}        if( ParamDesc.Class == D3DXPC_OBJECT )        {			cString name(ParamDesc.Name);						if (ParamDesc.Type == D3DXPT_TEXTURE				&& name == "shadow")			{				m_shadowTextureHandle = hParam;			}			else if (ParamDesc.Type == D3DXPT_TEXTURE				|| ParamDesc.Type == D3DXPT_TEXTURE2D				|| ParamDesc.Type == D3DXPT_TEXTURE3D				|| ParamDesc.Type == D3DXPT_TEXTURECUBE)			{				int iPos = name.find_first_of (numerals, 0, sizeof(numerals));			   if (iPos != cString::npos)			   {			       int iTexture = atoi(&ParamDesc.Name[iPos]);			       if (iTexture>=0 && iTexture<k_max_texture_handles)			       {				   m_textureHandle[iTexture] = hParam;			       }			   }			}        }		if ( ParamDesc.Class == D3DXPC_STRUCT)		{			if( strcmpi( ParamDesc.Semantic, "AtmosphericLighting" ) == 0 )				m_paramHandle[k_atmosphericLighting] = hParam;			else if ( strcmpi( ParamDesc.Semantic, "patchCorners") == 0 )				m_paramHandle[patchCorners] = hParam;		}	}}


jpetrie
jpetrie
Given the function names you mention, are you using D3D10?

If so, you can call AsWhatever() and followed by IsValid(). This is inefficient but will work. Alternatively you can use the EffectVariable::GetType() method can get the description of the resulting ID3D10EffectType. You should cache this result.
Stellar Developer
Stellar Developer
ankhd, I will use GetDesc at the various levels to attain the data I need. Guess I wasnt looking very hard at the data structures to have missed it.

jpetrie, I'll probably use a more efficient way, but I'll use isvalid for runtime validation and I'll check out the type function.

thanks for the replies, everything I needed to know. Im back on track again! :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.