DirectX 9.0 vertex buffer update

I made a small 3D viewing application using DirectX 9.0. Now I would like to add some editing features. Suppose I want to edit a large polygon. While the user is editing the form, the vertices will be added, deleted and moved. Right now, each polygon is stored as a vertex buffer. My question is, what is the best way to save and display the form while the user edits it? If I destroy and recreate the vertex buffer every time a change occurs, I believe that it will be too resource intensive and suboptimal.

I, although I have to ask my questions in the main post, so here they are:

I have three different tasks, two of which I do not know how to implement:
1) Editing a vertex: Easy, I just update the old vertex with a new position in VB.
2) Removing a vertex: what happens here? How to remove it without creating a new VB? Should I just add an empty VB?
3) Adding the top: What is here? Can I change the length of a dynamic VB and add vertices at the end?

Another thought that I think will work:
1) Editing is easy
2) Deleting would simply mean that I would rewrite the deleted vertex, possibly to the position of the previous or next vertex, so it would not be visible.
3) The add-on will create a new vertex buffer, but will resize as a vector or list. Each time he recreated it, the size would be something like NewSize = OldSize * 1.1 (adding 10% more)
so subsequent additions should not recreate VB.
Thus, 1 and 2 never create a new VB, and 3 can sometimes create one. How does this sound?

+4
source share
1 answer

You do not need to destroy the buffer every frame. Create a dynamic buffer.

See the article Using Vertex buffers with DirectX if you haven’t already:

For dynamic vertex buffers containing information about primitives that often change in the scene, we need to specify the D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY to use and the D3DPOOL_DEFAULT flag for the pool.

Remember, however, data must still be sent to the pipeline for each update. Thus, a certain performance will be compared to static buffers with consistent data.

You should also try to keep the minimum buffer updates, as well as buffer switches. Are there many such editable polygons in your application? If so, you might consider putting them in one buffer.


Official Q / A website for graphics / game developers: https://gamedev.stackexchange.com/


Update

Sounds good to me.

Dynamic vertex buffers, on the other hand, are populated and discarded every frame.

This is taken from the article and is largely the answer for 1. and 2 .. Instead of updating individual vertices or carefully choosing which vertices should be overwritten, I would simply update the entire buffer content. A full buffer must be sent to the device anyway. You would have to check it out, though, to be sure.

Regarding 3 .. You cannot resize the buffer after it is created, but you can create a larger buffer than necessary. Therefore, try to evaluate a good supply. If the buffer is still too small, you will have to create a new one. There is no other solution for this. You have already found a possible algorithm for dynamically increasing the size of the buffer.

There are so many options when it comes to graphics performance, it is almost impossible to give specific answers. Are you already facing restrictions? If not, don’t worry. Be generous with your resources while you are still developing.

+4
source

Source: https://habr.com/ru/post/1399439/


All Articles