However, then I see the book using it like this:
Quote
The C++ application code typically needs to communicate with the effect; in particular, the C++ application usually needs to update variables in the constant buffers. For example, suppose that we had the following constant buffer defined in an effect file:
Through the ID3D10Effect interface, we can obtain pointers to the variables in the constant buffer:
The ID3D10Effect::GetVariableByName method returns a pointer of type ID3D10EffectVariable. This is a generic effect variable type; to obtain a pointer to the specialized type (e.g., matrix, vector, scalar), you must use the appropriate As***** method (e.g., AsMatrix, AsVector, AsScalar).
Once we have pointers to the variables, we can update them through the C++ interface. Here are some examples:
cbuffer cbPerObject
{
float4x4 gWVP;
float4 gColor;
float gSize;
int gIndex;
bool gOptionOn;
};Through the ID3D10Effect interface, we can obtain pointers to the variables in the constant buffer:
ID3D10EffectMatrixVariable* fxWVPVar;
ID3D10EffectVectorVariable* fxColorVar;
ID3D10EffectScalarVariable* fxSizeVar;
ID3D10EffectScalarVariable* fxIndexVar;
ID3D10EffectScalarVariable* fxOptionOnVar;
fxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix();
fxColorVar = mFX->GetVariableByName("gColor")->AsVector();
fxSizeVar = mFX->GetVariableByName("gSize")->AsScalar();
fxIndexVar = mFX->GetVariableByName("gIndex")->AsScalar();
fxOptionOnVar = mFX->GetVariableByName("gOptionOn")->AsScalar();The ID3D10Effect::GetVariableByName method returns a pointer of type ID3D10EffectVariable. This is a generic effect variable type; to obtain a pointer to the specialized type (e.g., matrix, vector, scalar), you must use the appropriate As***** method (e.g., AsMatrix, AsVector, AsScalar).
Once we have pointers to the variables, we can update them through the C++ interface. Here are some examples:
fxWVPVar->SetMatrix( (float*)&M ); // assume M is of type D3DXMATRIX fxColorVar->SetFloatVector( (float*)&v ); // assume v is of type // D3DXVECTOR4 fxSizeVar->>SetFloat( 5.0f ); fxIndexVar->SetInt( 77 ); fxOptionOnVar->SetBool( true );
But now they make separate calls, is this not beating the purpose of constant buffers?
If it isn't, then why not?
If it is, then how do I set it correctly? (I assume this has something to do with "ID3D10EffectConstantBuffer::SetConstantBuffer()" but it seems to be poorly documented)












