Specializing Interfaces (Direct3D 10)

ID3D10EffectVariable Interface has a number of methods for casting the interface into the particular type of interface you need. The methods are of the form AsType and include a method for each type of effect variable (such as AsBlend, AsConstantBuffer etc..)

For example, suppose you have an effect with two global variables: time and a world transform.

float    g_fTime;
float4x4 g_mWorld;

Here is an example (from SimpleSample10 Sample) that gets these variables:

ID3D10EffectVariable* g_pVariable;
ID3D10EffectMatrixVariable* g_pmWorld;
ID3D10EffectScalarVariable* g_pfTime;

g_pVariable = g_pEffect10->GetVariableByName("g_mWorld");
g_pmWorld = g_pVariable->AsMatrix();
g_pfTime = g_pEffect10->GetVariableByName("g_fTime");
g_pfTime = g_pVariable->AsScalar();

By specializing the interfaces, you could reduce the code to a single call.

g_pmWorld = (g_pEffect10->GetVariableByName("g_mWorld"))->AsMatrix();
g_pfTime = (g_pEffect10->GetVariableByName("g_fTime"))->AsScalar();

Interfaces that inherit from ID3D10EffectVariable Interface also have these methods, but they have been designed to return invalid objects; only calls from ID3D10EffectVariable Interface return valid objects. Applications can test the returned object to see if it is valid by calling ID3D10EffectVariable::IsValid.

Effects