3
\$\begingroup\$

Currently I am developing an RTS game using XNA ( / ANX.Framework ). There is one thing bothers me. I am not sure in what way or how to organise Buffers. Should I use a new Vertexbuffer for any object ( e.g. a Char, a Table, an model ) or is it better to use ONE HUGE/ BIG Buffer to store any geometry in?

I am still new to 3D Programming though I finished yet couple games using DirectX 9.

Well, I hope this question qin't a duplicate and I appreciate any answer leading me into the right direction.

\$\endgroup\$
4
\$\begingroup\$

As long as performance isn't a concern, you can do whatever's convenient - which probably means a separate vertex/index buffer for each mesh.

If you sort your meshes when drawing, so that all instances of the same mesh are drawn together (e.g. all units of type A are drawn, then all units of type B, etc.), you can reduce state changes and also set yourself up well for adding geometry instancing later if it becomes necessary for performance. This will be a good pattern if you don't have too many different meshes, but potentially many instances of each mesh - which seems likely for an RTS (not too many unit/terrain types, but potentially a lot of units/tiles on screen).

The "one huge buffer" approach can reduce the number of state changes / draw calls still further if necessary, but it takes more code to manage, and requires a few other things like texture atlasing in order to actually realize the performance gains. I wouldn't worry about it unless and until performance analysis indicates that you truly need it.

\$\endgroup\$
2
\$\begingroup\$

There are certain guidelines you can use, but keep in mind that they may not always apply (or even matter) depending on the application:

  • Less draw calls is usually better for performance, hence less VBOs, this will reduce state changes. This is usually possible for objects that share the same material.

  • Use interleaved vertex attributes, for example store {V1,N1,V2,N2} instead of {V1,V2} {N1,N2}, as this will increase cache coherency.

  • Don't use misaligned vertex data. It is better to have data that are 4-bytes aligned for example:

V1{ half, half, half, half } --> Next vertex starts at 8 which is a multiple of 4-bytes

Better than

V1{ half, half, half } --> Next vertex starts at 6 which is not a multiple of > 4-bytes.

Because the driver is going to take more time aligning your data. It's even a good practice to add padding to force data alignment.

  • Draw from index buffers instead of vertex buffers, this will minimize computations performed on vertices (e.g. transformation) as there will be less vertices,
  • When using index buffer keep in mind not to de-reference vertices that are far away from each other in the vertex buffer as this will not help the cache coherency, for example de-referencing Index1=1 then Index2=3000 is usually a bad idea.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.