Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Applying transformations to individual vertex buffers

This topic is 6175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's something I found that works nicely.



What's a good usage pattern for vertex buffers if I'm generating dynamic data?

1. Create a vertex buffer using the D3DUSAGE_DYNAMIC and D3DUSAGE_WRITEONLY usage flags, and the D3DPOOL_DEFAULT pool flag. (Also specify D3DUSAGE_SOFTWAREPROCESSING if you are using software vertex processing.)

2. I = 0.

3. Set state (textures, renderstates, and so on).

4. Check if there is space in the buffer, that is, i.e. I + M <= N? (Where M is the number of new vertices).

5. If yes, then Lock the VB with D3DLOCK_NOOVERWRITE. This tells Direct3D and the driver that you will be adding vertices and won't be modifying the ones that you previously batched. Therefore, if a DMA operation was in progress, it isn't interrupted. If no, goto 11.

6. Fill in the M vertices at I.

7. Unlock.

8. Call Draw[Indexed] Primitive. For non-indexed primitives use I as the StartVertex parameter. For indexed primitives, ensure the indices point to the correct portion of the vertex buffer (it may be easiest to use the BaseVertexIndex parameter of the SetIndices call to achieve this).

9. I += M.

10. Goto 3.

11. Ok, so we are out of space, so let us start with a new VB. We don't want to use the same one because there might be a DMA operation in progress. We communicate to this to Direct3D and the driver by locking the same VB with the D3DLOCK_DISCARD flag. What this means is "you can give me a new pointer because I am done with the old one and don't really care about the old contents any more."

12. I = 0.

13. Goto 4 (or 6).

Edited by - burp on November 23, 2001 12:19:39 PM

Share this post

Link to post
Share on other sites
If all you want to do is transform a bunch of vertices by the same amount, just make a transformation matrix and set the world matrix to your transformation matrix and render your triangles.

If you want to actually modify individual vertices by different amounts (like waves on an ocean), then you should keep a copy of the vertex buffer in system memory, modify the system copy, and lock and copy the changed portions over to the vertex buffer as necessary.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!