Possible to leave some vertices in vertexbuffer, while adding and removing others?

Started by
8 comments, last by gunning 18 years, 8 months ago
Hi, with a vertex buffer, I was wondering if it was possible to say write 30 vertices into the vb, then without having to re-add those 30 vertices, to add/remove 100 or so vertices constantly? thanks
Advertisement
As long as the vertex buffer isn't a dynamic buffer that you lock with DISCARD, it's possible.

In addition, if you know you will never be modifying those 30 vertices while you tweak the rest, limit your range of locked vertices to only those you modify. This can be done by setting the offset and size parameters of the IDirect3DVertexBuffer9::Lock method.
....[size="1"]Brent Gunning
Quote:Original post by Coder
As long as the vertex buffer isn't a dynamic buffer that you lock with DISCARD, it's possible.


My vertexbuffer is dynamic, but if i remove the discard flag, would that be ok then?

Quote:Original post by skittleo
by setting the offset and size parameters of the IDirect3DVertexBuffer9::Lock method.


so for the offset I should say 'sizeof(Vertex)*30', and for the size parameter, should I just set it to the size of the 'new vertices' that are being added? eg 100 new vertices, so sizeof(Vertex)*100?

Thanks alot
Quote:Original post by johnnyBravo
My vertexbuffer is dynamic, but if i remove the discard flag, would that be ok then?


Yep. Even if you limit the data you modify with offset and size, Direct3D will still hand you a fresh set of memory to fill.

Quote:Original post by johnnyBravo
so for the offset I should say 'sizeof(Vertex)*30', and for the size parameter, should I just set it to the size of the 'new vertices' that are being added? eg 100 new vertices, so sizeof(Vertex)*100?


You got it.
....[size="1"]Brent Gunning
Quote:Original post by skittleo
Quote:Original post by johnnyBravo
My vertexbuffer is dynamic, but if i remove the discard flag, would that be ok then?


Yep. Even if you limit the data you modify with offset and size, Direct3D will still hand you a fresh set of memory to fill.

If you don't lock with the DISCARD flag, you won't be handed a fresh set of memory to fill (i.e. you won't get vertex buffer renaming). You'll have to wait for the card to finish any operations it's doing on the buffer before you can write.

Quote:Original post by Coder
If you don't lock with the DISCARD flag, you won't be handed a fresh set of memory to fill (i.e. you won't get vertex buffer renaming). You'll have to wait for the card to finish any operations it's doing on the buffer before you can write.


So should I use the D3DLOCK_NOOVERWRITE flag instead>

As in the sdk docs it says that it will return the driver immediately and continue rendering, does this mean it will allow me access to the vb straight away, but it will also continue to render what it was doing before i interrupted it?

Quote:
D3DLOCK_NOOVERWRITE
The application promises not to overwrite any data in the vertex and index buffers. Specifying this flag allows the driver to return immediately and continue rendering, using this buffer. If this flag is not used, the driver must finish rendering before returning from locking.


thanks.
If you're not going to overwrite vertices that are being used by the card and specfiy the NOOVERWRITE flag, then yes, it'll return immediately.

I have found that either the runtime and/or drivers expect NO_OVERWRITE to imply that you are APPENDING to the buffer.

That is certainly the normal usage case, so this may just have been bugs assuming this, but I ran into problems when I used no_overwrite to mean ( I don't have any writes pending to this area I'm going to write to, but it's not necessarily appending ).

So, I would recommend keeping your static vertices in another buffer, refilling the whole vb every time with discard, or keep appending new stuff to the end, and skip the unused old dynamic stuff until you run out of space, then lock with discard.
Quote:Original post by Coder
Quote:Original post by skittleo
Quote:Original post by johnnyBravo
My vertexbuffer is dynamic, but if i remove the discard flag, would that be ok then?


Yep. Even if you limit the data you modify with offset and size, Direct3D will still hand you a fresh set of memory to fill.

If you don't lock with the DISCARD flag, you won't be handed a fresh set of memory to fill (i.e. you won't get vertex buffer renaming). You'll have to wait for the card to finish any operations it's doing on the buffer before you can write.


I was under the assumption that we were still talking about the discard flag.
....[size="1"]Brent Gunning

This topic is closed to new replies.

Advertisement