Archived

This topic is now archived and is closed to further replies.

Commando

Q about dynamic vertex buffers (DX 8)

Recommended Posts

Ok, if I lock a dynamic vertex buffer with the flag NOOVERWRITE and fill some vertices starting from offset O, can I still draw the vertices that are before the offset O or are those vertices somehow invalid? I''m using directX8. Hopefully I was clear enough... Commando Commando''s Base

Share this post


Link to post
Share on other sites
Yep you can still draw those vertices, you just can''t read or write to them during the lock (because the graphics hardware might be using them).

For a 100 vertex buffer this is fine:

Offs = 0;
Lock( Offs, 100, NOOVERWRITE, )
Fill/Read/Write 100 vertices starting at Offs
Unlock
Draw*Primitive starting at Offs

Offs += 100;
Lock( Offs, 100, NOOVERWRITE, )
Fill/Read/Write 100 vertices starting at Offs
Unlock
Draw*Primitive starting at Offs



http://www.gamedev.net/community/forums/topic.asp?topic_id=57162




--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Ok thx. The way I''m trying to do is:


Offs = 0
Lock( Offs, 100, DISCARD, )
Fill 100 vertices starting at Offs
Unlock
Draw(indexed)Primitive starting at Offs
// Do smth like change matrices
Lock( Offs + 100, 100, NOOVERWRITE, )
Fill 100 vertices starting at Offs + 100
Unlock
Draw(indexed)Primitive starting at Offs


That does not properly (crashes at the NOOVERWRITE part). However it works perfectly when I change it to:


Offs = 0
Lock( Offs, 100, DISCARD, )
Fill 100 vertices starting at Offs
Unlock
Draw(indexed)Primitive starting at Offs
// do smth like change matrices
Lock( Offs, 100, DISCARD, )
Fill 100 + 100 vertices starting at Offs
Unlock
Draw(indexed)Primitive starting at Offs


Can''t see a reason why it works with DISCARD but doesn''t with NOOVERWRITE. The VB is big enough (<5000, only >3000 used per frame). The IB is static, could that affect some way? Sure I could use the DISCARD part all the time but then I''m doing quite a lot of unnecessary VB filling, I thought it would be clever to only fill those vertices that are "new".

Commando
Commando''s Base

Share this post


Link to post
Share on other sites
I just noticed the following thing from nVidia''s dynamicVB header example:


// Use at beginning of frame to force a flush of VB contents on first draw
void FlushAtFrameStart() { mbFlush = true; }


Is it necessary to flush (=DISCARD on the first Lock) the VB at the beginning of each frame? I don''t flush the VB every frame if the player doesn''t move (so I use the old data from previous frame), could that cause problems? Whatabout Locking outside BegineScene - EndScene, is that legal?

Commando
Commando''s Base

Share this post


Link to post
Share on other sites