Question

In my DirectX 11 based engine, I have a Mesh class which (obviously) has a vertex and an index buffer.

  • The mesh vertices can be changed at runtime by the user of my engine (e.g. setting the location / color / etc. of single or multiple vertices).
  • A mesh can also have animations loaded from a model which are then run by the user.

Now I don't know if I should use a dynamic or static vertex buffer.

  1. If the mesh has animations, I should of course use a dynamic vertex buffer. But what if the user never tends to run an animation and the vertices stay the same (e.g. a simple character in idle state for a long time)?
  2. The user might (but would not) change vertices all the time (e.g. an asteroid rain hits a floor which deforms), possibly every frame. Rebinding a static buffer every time would be a bad idea here.

Should I always use a dynamic buffer? Should I always use a static buffer and rebind it every frame?

Or should I automatically detect the usage and switch from dynamic / static after a mesh became updated / idle every time for a specific amount of frames (let's say ~120 frames)? This means more development (detecting this behavior and then changing the buffers), is it a good idea?

I would not want to confront the engine user with two different classes (so that he has to decide to use a static / dynamic buffer eventually). It should be part of my engine to handle this.

Was it helpful?

Solution

Character animation is usually done with skinning/skeletal animation that doesn't require updating vertices at each frame but only the bone matrices for each model. Each vertex attribute is often influenced by a few bones with some weights (often at max 4 bones per vertex) defined statically.

Sometimes you need also to generate some vertices procedurally, or animate them from the CPU because the code on the GPU could be too complex, so in this case you need to use a dynamic vertex buffer.

In both scenarios it is unlikely that the behavior of the animation is not known in advance (statically), neither you should encounter cases where you would have to switch between them. Though for dynamic vertex buffer, you can just avoid updating the buffer when you don't want to make animations. It could be tempting to use only dynamic buffer in case an animation may be required, but in practice these is bad for the GPU to initialize vertex buffers in the worst case (dynamic), so the recommended way is to prefer static scenarios with animations on the GPU whenever possible and only use dynamic buffers in special scenarios

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top