# How do I create more than one constant buffer ?

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

## Recommended Posts

The reason why I want to create a second constant buffer is to render a second cube, Is there another way to create a duplicate of a cube .

##### Share on other sites
solution: instancing

##### Share on other sites
I believe there are more than one constant buffer register. If you want 2 distinct constant buffers you can create an array of constant buffers and pass that to your shader SetConstantBuffers(...) function.

##### Share on other sites
How would I create that register ?

##### Share on other sites
How are you creating your first constant buffer? That said you don't normally create a new constant buffer just to store a cube. Constant buffers are for stuff like camera position, world/view/projection matrices, shader parameters, etc... vertex and mesh data usually goes within the vertex declarations.

##### Share on other sites
You create a second constant buffer in the same way as you create the first constant buffer.

Also, you may reuse a single constant buffer for different drawing calls. ie. fill constant buffer for the first cube, draw, re-fill the same constant buffer for the second cube (like with different world matrix and color etc), draw the second cube and so on.

Cheers!

##### Share on other sites
I understand creating the second constant buffer, It how do I run both constant buffers at the same time using VSSetConstantBuffers function

##### Share on other sites

I understand creating the second constant buffer, It how do I run both constant buffers at the same time using VSSetConstantBuffers function

Assuming you're using DirectX 11, you can declare two constant buffers in HLSL like this:

 cbuffer cbuffer0 : register(b0) { //.. } cbuffer cbuffer1 : register(b1) { //... } 

Then use:

 ID3D11Buffer** ppCBuffers = {pCBuffer0, pCBuffer1}; VSSetConstantBuffers(0, 2, ppCBuffers); 

##### Share on other sites

Assuming you're using DirectX 11, you can declare two constant buffers in HLSL like this:

Oh... I always assume 11

##### Share on other sites
I'm getting an error when it comes to CreateVertexShader function

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 9
• ### Forum Statistics

• Total Topics
634085
• Total Posts
3015407
×