# DrawIndexedPrimitive parameter confusion with dynamic vertexbuffers

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

## Recommended Posts

I'm working on getting all the parameters/flags straight for a vertex buffer using the D3DUSAGE_DYNAMIC flag. The code generally looks like the stuff described here, in "Usage style 2" : http://msdn.microsoft.com/en-us/library/bb147263%28VS.85%29.aspx?ppud=4#Using_Dynamic_Vertex_and_Index_Buffers After the vertexBuffer is filled, and assuming the last fill was of flag D3DLOCK_NOOVERWRITE, I'm confused what the correct "BaseVertexIndex" parameter to pass to DrawIndexedPrimitive should be. Question is, should this param be relative to the absolute start of the vertexBuffer, or relative to the position of the last lock? The only way I know how to ask this is with an example, so here goes: (I'm skipping the index population for simplicity, but please assume it is there :) ) 1.) The program starts up, and I store 8 vertexes in a vector, intending to draw a cube. I have another vector w/ 3 vertexes, to draw a simple triangle. 2.) after creating the vertex buffer (with cavernous amount of space) I lock it using NOOVERWRITE and use memcpy to copy the 8 cube verts, then the 3 triangle verts. 3.) that frame, I draw the cube first with a BaseVertexIndex of 0, and the triangle with a baseVertexIndex of 8. 4.) next frame, I again lock with NOOVERWRITE. The cube gets copied in about 11 vertexes past 0, and the triangle 19. 5.) POINT OF CONFUSION : Second draw happens. Should the BaseVertexIndex of the cube and triangle be 0 and 8 (like it was last time) or should it be 11 and 19, since this is the absolute offset of the objects for this frame in the vertexBuffer? When I first started coding this, I thought for sure it should be 11 and 19 and didn't think about it at all. All I ended up with was crazy flickering. So, by luck tried it w/ 0 and 8, and worked! But maybe this was only an illusion, it worked because it was still drawing the vertexes added in step #2 above, and not the stuff added in step #4. And this is the main reason why I'm posting here, asking.

##### Share on other sites
Uhhh... Ok problem solved.

After some experimentation with rotating the vertexes every frame, it seems like I def had this wrong. The baseVertexOffset definitely needs to be offset by the absolute position of the vertexes in the buffer, not the position of the last lock (In other words, the correct answer is the simple, intuitive one!!). I've had this wrong and have been drawing from a crusty spot in the buffer for a week now.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 12
• 15
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632655
• Total Posts
3007675
• ### Who's Online (See full list)

There are no registered users currently online

×