Changing mesh in vertexbuffer?

I have a mesh which changes each frame. The change is not large, but there is generally always some change.

The previous implementation used drawUserPrimitive and was quite slow. The mesh has a lot of shared vertices, so i was considering using a vertexbuffer and drawing indexed triangles.

The question is now how to do this fastest.

Is it very costly to lock the vertexbuffer each frame, alter som vertices and unlock

If I sometimes have 4096 vertices and some times have 10, then the buffer needs to be created with the capasity of the largest number, but what when it is almost empty I can not delete a vertex, so it will really just be unreferenced by the index array, but will all vertices still be transformed each frame, even though no triangles use them



Answer this question

Changing mesh in vertexbuffer?

  • JunJie1800

    There is not a signal for each vertex, however there is a post-transform vertex cache. Whether or not the GPU has to retransform a vertex or not depends on the post-transform vertex cache size and if you are drawing indexed primitives. The post-transform vertex cache only works when using an index buffer. The vertex cache is of limited size, that is why it is important if vertices are reused, they are referenced close together in the index buffer. If the vertex is not in the post-transform cache it will have to retransform it.
  • Load

    That was good to know. I assume that there exists a signal somewhere for each vertex, so once a vertex is transformed it will not be transformed again, when later another primitive uses it as well


  • benney

    Only vertices referenced by the index buffer will be transformed, so don't worry about it. It's quite standard to create a vertex buffer that's larger than what you need. This way you can also append to it (using D3DLOCK_NOOVERWRITE when locking), which is faster than replacing existing data.

  • Changing mesh in vertexbuffer?