Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple meshes in one vertex buffer?

Do I need to use one vertex buffer per mesh, or can I store multiple meshes in one vertex buffer? If so, should I do it, and how would I do it?

like image 492
Electro Avatar asked Oct 13 '09 12:10

Electro


2 Answers

You can store multiple meshes in one vertex buffer. You may gain some performance by putting several small meshes in in one buffer. For really large meshes you should use seperate buffers. SetStreamSource lets you specify the vertex buffer offset for your current mesh.

pRawDevice->SetStreamSource( 0, m_VertexBuffer->GetBuffer(), m_VertexBuffer->GetOffset(), m_VertexBuffer->GetStride() );
like image 147
Simon H. Avatar answered Sep 29 '22 02:09

Simon H.


TBH generally the reason for putting them all in one big buffer is to save on draw calls. The cost of switching a vertex buffer is fairly minimal. If you can merge them all into 1 vertex buffer and render 10 objects in 1 draw call then you are on to a big win.

Usually to merge them you just create 1 big vertex buffer with all the vertex data, already world transformed in it, one after another. You then set up an index buffer that renders them one after another. You then have everything drawing in minimal draw calls. Of course if you move one thing that requires updating a portion of the vertex buffer which is why its an ideal situation for static geometry.

If all the objects are the same you'll only be using 1 vertex buffer (with 1 object definition in it) and 1 index buffer anyway right? Matrices move or animate the object ...

If all the objects are different and moving/animating then i'd just stick with individual VBs. I doubt you'd notice any difference by merging them all together.

like image 32
Goz Avatar answered Sep 29 '22 02:09

Goz