Skip to main content
GameDev.net gamedev.net
🔒 Locked

How do I create more than one constant buffer ?

Started by Danisflying Mar 26, 2012 at 12:46 AM 9 replies 2.1k views
Original Post
Danisflying
Danisflying
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 .
Asesh
Asesh
solution: instancing
Hornsj3
Hornsj3
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.
Danisflying
Danisflying
How would I create that register ?
Bacterius
Bacterius
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.
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
kauna
kauna
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!
Danisflying
Danisflying
I understand creating the second constant buffer, It how do I run both constant buffers at the same time using VSSetConstantBuffers function
Aqua Costa
Aqua Costa

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);
Hornsj3
Hornsj3

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



Oh... I always assume 11 smile.png
Danisflying
Danisflying
I'm getting an error when it comes to CreateVertexShader function
kauna
kauna

I'm getting an error when it comes to CreateVertexShader function


Which error do you get?

I am not following exactly what you are trying to accomplish since all the techniques to draw any object multiple times have been presented and you don't give a clue which option you are following. Read my previous post. It is the simplest way to draw the same cube as many times as you wish and you'll only need a single constant buffer for it.

Best regards!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.