Managing constant buffers without FX interface
- by xcrypt
I am aware that there is a sample on working without FX in the samplebrowser, and I already checked that one.
However, some questions arise:
In the sample:
D3DXMATRIXA16 mWorldViewProj;
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mView;
D3DXMATRIXA16 mProj;
mWorld = g_World;
mView = g_View;
mProj = g_Projection;
mWorldViewProj = mWorld * mView * mProj;
VS_CONSTANT_BUFFER* pConstData;
g_pConstantBuffer10->Map( D3D10_MAP_WRITE_DISCARD, NULL, ( void** )&pConstData );
pConstData->mWorldViewProj = mWorldViewProj;
pConstData->fTime = fBoundedTime;
g_pConstantBuffer10->Unmap();
They are copying their D3DXMATRIX'es to D3DXMATRIXA16. Checked on msdn, these new matrices are 16 byte aligned and optimised for intel pentium 4.
So as my first question:
1) Is it necessary to copy matrices to D3DXMATRIXA16 before sending
them to the constant buffer? And if no, why don't we just use
D3DXMATRIXA16 all the time?
I have another question about managing multiple constant buffers within one shader.
Suppose that, within your shader, you have multiple constant buffers that need to be updated at different times:
cbuffer cbNeverChanges
{
matrix View;
};
cbuffer cbChangeOnResize
{
matrix Projection;
};
cbuffer cbChangesEveryFrame
{
matrix World;
float4 vMeshColor;
};
Then how would I set these buffers all at different times?
g_pd3dDevice->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer10 );
gives me the possibility to set multiple buffers, but that is within one call.
2) Is that okay even if my constant buffers are updated at different
times? And do I suppose I have to make sure the constantbuffers are in
the same position in the array as the order they appear in the shader?