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

Multiple vertex buffers [DirectX 10]

Started by Calin Feb 12 at 1:27 PM 5 replies 650+ views
Original Post
Calin
Calin

How do you create a more than one vertex buffer in DirectX 10?

What I wrote was:

ID3D10Buffer* g_pVertexBuffer[2];

g_pd3dDevice->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );

But I can not pass g_pVertexBuffer as an argument like that. I'm getting the following error:

E0167 argument of type "ID3D10Buffer *(*)[2]" is incompatible with parameter of type "ID3D10Buffer *const *"

My project`s facebook page is “DreamLand Page”
Juliean
Juliean

You are already trying to pass an array-argument. You do not need to & it an additional time. An array degenerates to a pointer (T*), which in your case gives you ID3D10Buffer** (as the array-T is ID3D10Buffer*). Just pass “g_pVertexBuffer” as the argument - the compiler is protecting you here from passing garbage (if the code would compile, the API would try to read the array-address as ID3D10Buffer addresses and crash.

Calin
Calin

Juliean thank you

My project`s facebook page is “DreamLand Page”
Calin
Calin

I have managed to pass an array of buffers to IASetVertexBuffers() but that's probably not what I'm looking for. I am trying to display two different shapes. They don't cover how to do that in the basic SDK tutorials. Displaying the same box or whatever twice in different places is easy, just set the proper matrix and call the drawing function again. But how about displaying two shapes each with a unique array of vertices?

SimpleVertex vertices[] =
{
   { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR4( 0.0f, 0.0f, 1.0f, 1.0f ) },
   { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR4( 0.0f, 1.0f, 0.0f, 1.0f ) },
   { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR4( 0.0f, 1.0f, 1.0f, 1.0f ) },
   { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR4( 1.0f, 0.0f, 0.0f, 1.0f ) },
   { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR4( 1.0f, 0.0f, 1.0f, 1.0f ) },
   { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR4( 1.0f, 1.0f, 0.0f, 1.0f ) },
   { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR4( 1.0f, 1.0f, 1.0f, 1.0f ) },
   { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR4( 0.0f, 0.0f, 0.0f, 1.0f ) },
};
SimpleVertex vertices1[] =
{
   { D3DXVECTOR3(0, 2.0f, -1.0f), D3DXVECTOR4(0.0f, 0.0f, 1.0f, 1.0f) },
   { D3DXVECTOR3(1.0f, 2.0f, -1.0f), D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f) },
   { D3DXVECTOR3(1.0f, 2.0f, 1.0f), D3DXVECTOR4(0.0f, 1.0f, 1.0f, 1.0f) },
   { D3DXVECTOR3(0.0f, 2.0f, 1.0f), D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f) },
   { D3DXVECTOR3(-1.0f, -1.0f, -1.0f), D3DXVECTOR4(1.0f, 0.0f, 1.0f, 1.0f) },
   { D3DXVECTOR3(1.0f, -1.0f, -1.0f), D3DXVECTOR4(1.0f, 1.0f, 0.0f, 1.0f) },
   { D3DXVECTOR3(1.0f, -1.0f, 1.0f), D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f) },
   { D3DXVECTOR3(-1.0f, -1.0f, 1.0f), D3DXVECTOR4(0.0f, 0.0f, 0.0f, 1.0f) },
};
D3D10_BUFFER_DESC bd;
bd.Usage = D3D10_USAGE_DEFAULT;
bd.ByteWidth = sizeof( SimpleVertex ) * 8;
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA InitData;


InitData.pSysMem = vertices;
hr = g_pd3dDevice->CreateBuffer( & bd, & InitData, & g_pVertexBuffer[0]);
if( FAILED( hr ) )
   return hr;
InitData.pSysMem = vertices1;
hr = g_pd3dDevice->CreateBuffer(&bd, &InitData, & g_pVertexBuffer[1]);
if (FAILED(hr))
   return hr;

// Set vertex buffer
UINT stride = sizeof( SimpleVertex );
UINT offset = 0;
g_pd3dDevice->IASetVertexBuffers( 0, 2, g_pVertexBuffer, &stride, &offset);


/*********Later************/

  g_pWorldVariable->SetMatrix( ( float* )&g_World );
  g_pViewVariable->SetMatrix( ( float* )&g_View );
  g_pProjectionVariable->SetMatrix( ( float* )&g_Projection );

  D3D10_TECHNIQUE_DESC techDesc;
  g_pTechnique->GetDesc( &techDesc );
  for( UINT p = 0; p < techDesc.Passes; ++p )
  {
      g_pTechnique->GetPassByIndex( p )->Apply( 0 );
      g_pd3dDevice->DrawIndexed( 36, 0, 0 );        // 36 vertices needed for 12 triangles in a triangle list
  }
My project`s facebook page is “DreamLand Page”
Juliean
Juliean

Calin said:
But how about displaying two shapes each with a unique array of vertices?

You use a different IASetVertexBuffers-call before each different draw-call then.

ID3d10Buffer* Buffer1;
g_pd3dDevice->IASetVertexBuffers( 0, 1, &Buffer1, &stride, &offset);

// => call your "Later" section here

ID3d10Buffer* Buffer2;
g_pd3dDevice->IASetVertexBuffers( 0, 1, &Buffer2, &stride, &offset);

// => and another draw-call goes here

This is true for most resources BTW. The functions accept multiple elements because there are techniques where different vertex-buffers are combined for one mesh (ie. splitting certain data that is not needed for something like a shadow-pass; or instancing). But you can always just set the data you need for one particular draw-call.

Calin
Calin

Problem solved. Thank you.

The functions accept multiple elements because there are techniques where different vertex-buffers

Yeah I was suspecting it's about some advanced technique.

My project`s facebook page is “DreamLand Page”

Topic Locked

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

Sign in to reply to this topic.