Locking a VB

Started by
6 comments, last by Hippokrates 21 years, 7 months ago
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...
Im Anfang war die Tat...Faust
Advertisement
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]
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
In other words, keep a copy of your vertex data in an array somewhere. Make changes to your texture coordinates in the vertices stored in this array, and copy it to the VB whenever necessary.

--Hoozit.
----------------------Check out my game demo and resume at www.fivestory.com/projects/game.
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...
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 coordsVB->Lock(...&p, ...);Vertex * v = (Vertex *)p;memcpy(&v[4].tu, ...);memcpy(&v[4].tv, ...);VB->Unlock(); 
Im Anfang war die Tat...Faust
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

Weeeeell if you put it like this... *gg* ^__^
Im Anfang war die Tat...Faust
What are you doing with the tex coords? Is it something that can be achieved with a texture matrix or something else?

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials

This topic is closed to new replies.

Advertisement