Obtaining Shader Parameters

The IParameterManager provides access to the data acquired by the parsers. The following code snippet shows how to access an IParameterManager from an IDxMaterial3 pointer obtained from an Mtl object.

Mtl * l_pMtl = l_pINode->GetMtl();
IDxMaterial3 *l_pIDxMaterial3 = (IDxMaterial*)l_pMtl->GetInterface(IDXMATERIAL3_INTERFACE);
IParameterManager *l_pIParameterManager = l_pIDxMaterial3->GetCurrentParameterManager();
 

A specific parameter value can be accessed using the method IParameterName::GetParameterByName() :

texHandle = pEffect->GetParameterByName(NULL, paramName);

The following code sample shows how to access data either by name or iteratively. The choice of approach depends on how the parser holds its internal data.

switch(pm->GetParamType(i))
{
    case  IParameterManager::kPType_Float:
    {
        float fval;
        pm->GetParamData((void*)&fval,i);
        pEffect->SetFloat(pm->GetParamName(i), fval);
    }
    break;
 
    case  IParameterManager::kPType_Color:
    case  IParameterManager::kPType_Point4:
    {
        D3DCOLORVALUE cval;
        pm->GetParamData((void*)&cval,i);
        pEffect->SetVector(pm->GetParamName(i), (D3DXVECTOR4*)&cval);
    }
    break;
 
    case  IParameterManager::kPType_Bool:
    {
        BOOL bval;
        pm->GetParamData((void*)&bval,i);
        pEffect->SetBool(pm->GetParamName(i), bval);
    }
    break;
 
    case  IParameterManager::kPType_Int:
    {
        int ival;
        pm->GetParamData((void*)&ival,i);
        pEffect->SetInt(pm->GetParamName(i), ival);
    }
    break;
}

As more shader types become available, materials must be able to display these in the File Open dialog. To accommodate this, new methods have been added to the EffectDescriptor class. The parser defines supported file extensions in the descriptor since the actual parser has not been loaded until the file has been accessed to determine which parser to load. File extensions are supplied as a localizable strings.

The material is responsible for displaying any errors generated, so additional parser methods need to provide access to error buffers.