adding and removing vertices from vertexbuffer

Started by
7 comments, last by voodoohaust 14 years, 2 months ago
just a quick question, its been niggling me for a while, Which is the best way to go about adding and removing vertices from a directx vertex buffer? thanks.
Advertisement
You don't. The size of a vertex buffer is fixed once it's created, and you can't resize it.

What you should do instead is simply keep track of how many vertices you have copied into a vertex buffer at any given time, that way you can specify the appropriate information when you make a Draw call.
so, i want to remove a vertex from a buffer. if i cant resize or remove vertices i have to create either a new vertex buffer or use multiple vertex buffers? Is there not a more efficient way to manage this? i can imagine lots of creation and destruction of objects doing that, let alone the device state switches.
Quote:
so, i want to remove a vertex from a buffer. if i cant resize or remove vertices i have to create either a new vertex buffer or use multiple vertex buffers? Is there not a more efficient way to manage this? i can imagine lots of creation and destruction of objects doing that, let alone the device state switches.

It is not possible. It would be just as inefficient to resize the buffer directly as it would be for you to recreate it (within some reasonable, but negligible, margin of error).

Instead, as MJP said, you want to simply write to only a portion of the buffer, and keep track of what you have written so you specify only that many vertices should be used when drawing.
hmmm...

In your opinion(s) would using a single vertex buffer( created with a large size ) to store all vertices in a scene be a good idea or should i choose to create individual buffers for each object? Which is optimal?

I'm in the process at the moment of implementing batch rendering and need to weigh up the options here.

Any advice would be very much appreciated!
One more thing bugging me now,

How do i tell the device which vertices to draw in an ID3DXMesh object?
Thats all wrapped up with DrawSubset().
This only way you can add/remove vertex at will is to use DrawPrimitiveUP/DrawIndexdPrimitiveUP. BUT !! your vertex array will NOT be located in video memory.
damn, i dont want to use that! lol

or i can just use drawindexedprimitive using D3DPT_TRIANGLELIST which is what D3DXMESH uses for drawsubset() as i have just found out. hmmmm maybe i am overcomplicating this.
As soon as you will change your vertex/index buffer you will lose performance.

Now you can only modify your index buffer to add/remove index in order to change the mesh topology.

This topic is closed to new replies.

Advertisement