Multiple meshes in one vertex buffer?

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

+7
c ++ 3d direct3d vertex-buffer
source share
4 answers

You can store multiple cells in one vertex buffer. You can get some performance by putting several small grids in one buffer. For really large grids you should use separate buffers. SetStreamSource allows SetStreamSource to specify the vertex buffer offset for your current grid.

 pRawDevice->SetStreamSource( 0, m_VertexBuffer->GetBuffer(), m_VertexBuffer->GetOffset(), m_VertexBuffer->GetStride() ); 
+5
source share

TBH, as a rule, the reason for placing them in one large buffer is to save on drawing calls. The cost of switching the vertex buffer is quite minimal. If you can combine them all into one vertex buffer and display 10 objects in 1 callback, then you get a big win.

Usually, to combine them, you simply create 1 large vertex buffer with all the vertex data already converted in the world, one after the other. Then you create an index buffer that displays them one by one. Then you have everything connected with minimal calls for drawing. Of course, if you have moved one thing that requires updating part of the vertex buffer, and therefore its ideal situation for static geometry.

If all objects are the same, will you use only 1 vertex buffer (with one object definition in it) and 1 index buffer anyway? Matrices move or animate an object ...

If all objects are different and moving / animated, I just stick to separate VBs. I doubt that you noticed any difference by combining them all together.

+2
source share

Well, my experience is that it is not so much different, as long as your buffers are not very small or really huge. I suspect that any inefficiency in the switching buffers will be consistent with increased efficiency, giving the driver more control over his memory with smaller buffers.

0
source share

With OpenGL, you can use glVertexPointer() to start drawing at a specific offset within VBO. not sure about D3D.

-2
source share

All Articles