• Create Account

Banner advertising on our site currently available from just \$5!

# How do I create more than one constant buffer ?

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1Danisflying  Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 March 2012 - 06:46 PM

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 .

### #2Asesh  Members   -  Reputation: 268

Like
0Likes
Like

Posted 25 March 2012 - 07:55 PM

solution: instancing

### #3Hornsj3  Members   -  Reputation: 191

Like
0Likes
Like

Posted 25 March 2012 - 08:00 PM

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.

### #4Danisflying  Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 March 2012 - 08:15 PM

How would I create that register ?

### #5Bacterius  Crossbones+   -  Reputation: 10239

Like
0Likes
Like

Posted 26 March 2012 - 12:54 AM

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.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- Pessimal Algorithms and Simplexity Analysis

### #6kauna  Crossbones+   -  Reputation: 2888

Like
0Likes
Like

Posted 26 March 2012 - 01:12 AM

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!

### #7Danisflying  Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 March 2012 - 07:59 AM

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

### #8TiagoCosta  Crossbones+   -  Reputation: 2722

Like
0Likes
Like

Posted 26 March 2012 - 09:22 AM

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


### #9Hornsj3  Members   -  Reputation: 191

Like
0Likes
Like

Posted 26 March 2012 - 09:50 AM

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

Oh... I always assume 11

### #10Danisflying  Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 March 2012 - 09:58 AM

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

### #11kauna  Crossbones+   -  Reputation: 2888

Like
0Likes
Like

Posted 29 March 2012 - 01:00 AM

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!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS