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?
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() );
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With