Sign in to follow this  
jmgunn87

adding and removing vertices from vertexbuffer

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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().

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this