Archived

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

Locking a VB

This topic is 5571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a special flag that I have to set when locking a (static) VB in order not to delete its content? I would like to update only texture coordinates and because of this I would not want to loose the content...

Share this post


Link to post
Share on other sites
Don't specify any flags when locking the static buffer. Just use zero or D3D_DEFAULT (same thing). If its contents are not being preserved, that is because you created it with the D3DUSAGE_WRITEONLY flag. But honestly, there's no reason for you to read its contents, and by creating it with WRITEONLY, you can often get a nice speed boost.

~CGameProgrammer( );

EDIT: Also, you can't just update its texture coordinates. You can make them the only thing you change, but you will have to lock the entire static buffer to do so - it will be a lot faster just making it write-only and rewriting the entire thing when the coordinates change.

[edited by - CGameProgrammer on September 9, 2002 5:37:59 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you want a stronger system...

Interlace 2 VB, one with the vertex position and normal and the other one with the texture coordinates. This way you avoid rewritting data that you''ve already got and you can use the most optimal setting on the buffer with vertex position...

Share this post


Link to post
Share on other sites
Well when I was writing this I was thinking of 2 different problems at the same time.
If I locked an Indexbuffer everytime I wanted to write to it and just wrote 6 Indices (during geometry generation) I got an exceptional error in D3D8.dll. I think that perhaps the Indexbuffers content was screwed up by me locking and not completely rewriting it.
The second problem is the one with the texture coordinates. What I want to do is this:

//Changing the 5th vertex texture coords
VB->Lock(...&p, ...);
Vertex * v = (Vertex *)p;
memcpy(&v[4].tu, ...);
memcpy(&v[4].tv, ...);
VB->Unlock();

Share this post


Link to post
Share on other sites
Why are you using memcpy to just set a texture coordinate? You''ve gone through the trouble of type casting to a vertex structure, so:


  

// To access a single (or multiple in succession) vertex:

Vertex *p;
VB->Lock(VertexNum * sizeof(Vertex), NumVerticesToAccess * sizeof(Vertex), (BYTE**)&p, 0);

p->tu = 0.0f; p->tv = 0.0f;
p++;
p->tu = 1.0f; p->tv = 1.0f;
p++;
// ...

VB->Unlock();


// To access all vertices:

Vertex *p;
VB->Lock(0, 0, (BYTE**)&p, 0);
p[0].tu = 0.0f; p[0].tv = 0.0f;
VB->Unlock();




Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
and Focus On: Advanced Animation with DirectX

Share this post


Link to post
Share on other sites