0
\$\begingroup\$

I am constructing the game scenario and buttons using Vertex Buffers. I am making a v_buffer for each item, and then releasing them. I don't like my method. Should I reuse my vertex buffer for multiple draws? Why or why not?

v_buffer->Release();
v_bufferGrass->Release();
v_bufferMargin->Release();
v_bufferDirtGrassShadow->Release();
// ...and many more v_buffers than I don't want to maintain.
\$\endgroup\$
2
  • \$\begingroup\$ You are doing it wrong. Use vertex buffer per mesh, not per vertex. \$\endgroup\$
    – concept3d
    Mar 2, 2014 at 14:54
  • \$\begingroup\$ You may be using the wrong word when you use "vertex" here. A vertex is a single set of attributes (position, texcoords, color, normal). A primitive is a single triangle/linesegment/point. A mesh/geometry is made up of multiple primitives. You may be asking if you should be using a separate buffer for each of your meshes, or if you can share a single vertex buffer for more than one mesh. \$\endgroup\$ Mar 2, 2014 at 16:01

1 Answer 1

1
\$\begingroup\$

You can and should re-use vertex buffers when possible. It's a particularly bad idea to create and destroy vertex buffers for each object per frame, because the process of doing so takes a toll on both CPU and GPU resources.

You should strive to have one vertex buffer per model under normal circumstances. That means if you have a goblin character in your game, you have one goblin vertex buffer. Even if you render fifty goblins, you reuse the same vertex buffer, chaining only the world transformation every time you render with that buffer.

For some classes of object (such as purely static geometry) you can in fact pack multiple objects into one buffer, further reducing resource load.

You should create your buffers as early as you can and release them as late as is practical; for simple games, you can create them all on startup and only release them on shutdown (in practice, for larger projects, resource constraints and optimizations may make it worth your while to initialize later or release earlier, but you certainly want to be far, far away from creating/destroying buffers every frame).

You can update vertex buffers every frame, but make sure that when you do so you have created the buffer with the appropriate API hints that tell the GPU you're planning on doing so. This will allow it to prioritize the resource in memory appropriately.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .