Remmie

Hi people,

I am working with a dynamic vertexbuffer and I am wondering what the best practise is to fill the buffer with data. I have two different approaches to tackle this problem but as I cant figure out what is the best solution is I need your help.

Option1:
Create a vertexbuffer with flags dynamic and write only and keep a seperate array of vertices. If I want to update the buffer I can update the vertex array and then set this array into the vertexbuffer.

Option2:
Create the vertexbuffer, again with the dynamic flag, and just get the set and set the data from the vertexbuffer.

Option1 needs double the space space but might be faster as the get function is not needed. Option2 is the other way around.

Please tell me which option you would prefer.
Kind regards!


Re: XNA Framework Dynamic Vertexbuffer

BlueG

Were it me, I'd go with option 1 to avoid the extra get.

If you want to avoid holding an extra copy of your vertex data, then set the resource management mode on the vertex buffer to manual instead of automatic. Then XNA won't retain an extra copy of that data in system memory so the only copies will be the one that XNA manages in device memory and the copy that you are keeping. However, doing this you need to recreate the vertex buffer whenever the device is lost, which can be detected by an event on the device object itself (you actually want to recreate the resource during the DeviceReset event, not the DeviceLost event, however).






Re: XNA Framework Dynamic Vertexbuffer

Shawn Hargreaves - MSFT

I'd actually recommend using DrawUserPrimitives for this, and avoid using a vertex buffer at all.




Re: XNA Framework Dynamic Vertexbuffer

clayman

I want to konw is there any performance difference between draw prmitives with vertex array and vertex buffer



Re: XNA Framework Dynamic Vertexbuffer

BlueG

Using the vertex array, all of the data has to be sent across the system bus to draw the data each frame. A vertex buffer can actually stay on the graphics card so long as you don't change it.






Re: XNA Framework Dynamic Vertexbuffer

BlueG

I wasn't sure from his original message if he was changing the data each frame or only occassionally. If only occassionally, wouldn't a vertex buffer reduce the amount of data being sent to the card each frame

Of course, that's moot if the scene isn't complicated. After all, why do the extra work of a vertex buffer if it simply isn't needed






Re: XNA Framework Dynamic Vertexbuffer

Remmie

First of all thanks for the numerous replies to my post. My intention is to have an object that can change shape during a game, like procedural models. This will probably not be done every frame. I think that in my case having a manual vertex buffer and a local array of vertices works best. Every time the changes to an object are completed I update the vertex buffer and render it for a number of frames.

As a side note on the draw on the DrawUserPrimitives. I guess that this creates a lot of overhead (aspecially for larger models) and is only really usable in the scenario that the vertices are changed on a frame basis.