# will DX10 automatically handles Constant Buffer?

This topic is 3613 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am a bit lost in my understanding of constant buffer usage in DX10 HLSL. From the SDK examples, e.g Skinning10, I don't see the sample code manually maintaining a Constant Buffer and updating it. Is there any gains in manually handling the constant buffer? By manually handling I meant:
//Effect file:
cbuffer PerFrame
{
float4x4 World;
float4x4 View;
float4x4 Projection;
};

//CPP code
BYTE *pData = new BYTE[1000] //assume the constant buffer use 1000 bytes;
ID3D10Buffer *pBuffer //assume already created to bind as constant buffer
...

//Fills the CPU copy of the constant buffer
//assume the location to be filled is obtained through the
memcpy(&pData[0], &WorldMat, sizeof(D3DXMATRIX));
memcpy(&pData[16], &ViewMat, sizeof(D3DXMATRIX));
memcpy(&pData[32], &FooMat, sizeof(D3DXMATRIX));

//Update the Constant Buffer
D3DDevice->UpdateSubresource(pBuffer, 0, 0, pData, 0, 0);
...

//Set the constant buffer
pEffectConstantBuffer->SetConstantBuffer(pBuffer);


Is it better to handle such things manually? The skinning SDK sample just used: pMatrixVariable->SetMatrix(&WorldMat) etc to update the constants in the constant buffer. Which is a more prefered way?

##### Share on other sites
The samples tend to keep things simple thus they put everything into the default/global CB.

It is definitely good practice to partition constants into CB's yourself - you're adding valuable domain knowledge that the compiler/runtime cannot easily figure out itself. For a trivial app like a sample it probably won't matter, but for a more heavyweight application you could notice it...

hth
Jack

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009410
• ### Who's Online (See full list)

There are no registered users currently online

×