Sign in to follow this  
littlekid

D3DLOCK_NOOVERWRITE flag

Recommended Posts

littlekid    229
i don't understand the SDK documentation on the D3DLOCK_NOOVERWRITE flag. Does it mean than when I write to the buffer with this flag, it will append to the existing buffer and no overwrite the current contents? Which means Or directx create a new buffer and write the vertex into it so as to not touch the existing buffer data?

Share this post


Link to post
Share on other sites
SimmerD    1210
Yes, it is saying that you will append to the buffer, so it won't stall the hw, and it won't ask the driver for a renamed buffer.

It will let the hw read from the first part of the buffer while you are appending to the end.

Share this post


Link to post
Share on other sites
Armadon    1091
Hi there littlekid,
How are you doing?

The Problem
D3DLOCK_NOOVERWRITE

The Solution
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."

Specifying this flag will make sure that you will never overwrite any data. You can generally first write data to the vertex buffer using D3DLOCK_DISCARD and then when you want to add to the buffer you can use D3DLOCK_NOOVERWRITE to make sure that you don't overwrite the data that you have in there currently. Normally used for batching.

When using this flag the driver could also keep rendering from the buffer without actually needing to finish the lock.

I hope this helps.
Take care buddy.

Share this post


Link to post
Share on other sites
littlekid    229
do i have to change the size of the buffer? Lets say i create the buffer initially for 100 vertices. Then I fill it up completely at the start. Later on I lock using D3DLOCK_NOOVERWRITE and append another 30 vertices into the buffer. Hence must i recreate a new buffer of size 130??

Share this post


Link to post
Share on other sites
Note that it won't automatically append. You're promising that's what you'll do. If you break that promise, you may get rendering errors.

Example usage.
Create VB of 400 verts.
Lock at 0 for 100 verts with DISCARD, write data, unlock, draw
Lock at 100 for 200 verts with NOOVERWRITE, write data, unlock, draw
Lock at 300 for 50 verts with NOOVERWRITE, write data, unlock, draw
Lock at 0 for 100 verts with DISCARD, write data, unlock, draw

You'll notice I didn't actually completely fill the buffer. Depending on what you're rendering, you might be able to put in 50 verts, render them, then put another 50 into a fresh buffer. In other cases you can't chop up the data, and may need to begin at index 0 before filling the buffer. This is fine.

edit for new post above:
NOOVERWRITE and DISCARD are for DYNAMIC buffers only, and typically are used like I show above. Filled with what needs drawing, then drawn. You generally don't go back and draw from a previous part of the buffer. After a DISCARD (and possibly after an EndScene()) you can't refer to the previous data. It's gone.

If you're putting multiple meshes into a STATIC VB, these flags don't apply. Pass 0 as flags (I don't remember if it's XBox or PC D3D that complains about a Lock with flags==0, but since those flags are DYNAMIC specific, I'm not sure what flag their debug check was expecting to find). In this case, make the buffer as large as you're expecting you'll need to begin with. If you need to resize, you'll need to create a new buffer and put the data into it again. Another option is to not use just 1 buffer, and after the first is full, start filling in a second one, then a third, etc.

Share this post


Link to post
Share on other sites
Armadon    1091
Hi there littlekid,
How are you doing again buddy?

The Problem
Overwriting data in the vertex buffer and recreation of the buffer.

The Solution
It's generally a good idea to judge or to calculate how big your buffer will be so that you can cater for events like you have described.
You will need to recreate your buffer if you want to write more data than it can currently hold or you might want to opt to write over the part of the data. This is totally up to you.

It might also complain that the buffer is full and that you have specified that you want to write more data than it can currently hold. I really don't know I have never tried anything like that, you might get unexpected results.

So I would say, make provision for the largest amount of data you want to write to the buffer and send to the GPU to be rendered and then you can clean the buffer and rewrite the next values etc...

I hope this helps buddy.
Take care.

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