Archived

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

binary1230

Dynamic Vertex Buffers? Is it possible? [Advanced Question]

Recommended Posts

OK, check this out. I am porting an overhead 2d map editor for my game from OpenGL to DirectX. This is really irrelevant though. What I need to know is this: In this editor, I was able to let the user point and click to create connected lines on the screen. Basically, I had an array of vertices [implemented with the vector<> class] set up and every time the user clicked, it added a new vertex to the top. At render time, the lines were drawn using glVertex() from the value in the array. I am using a vertex buffer [and an index buffer really] in DirectX, and I want to know if there is a way to resize the vertex buffer without creating a new one. I know how to lock/unlock buffers like that, but how do I go about resizing them? Or is it easier to just create a new one with the old vertex data and the new vertex added to it? Or better yet... [I know this is probably unlikely, but here goes] is it possible to render vertices by hand. Something like this... d3dDev->BeginScene(); for (int v = 0; v < numVertices; v++) { [something]->DrawVertex(x, y, z) } d3dDev->EndScene(); Ok, I know that the above is dumb and doesnt exist like that, but does something exist like that.... Another idea... create a vertex buffer with 2 vertices in it. I keep all the vertices in an array. Then I loop through all the vertices and stick them two at a time into the vertex buffer, draw a line, and then do the next two, and so on. I know I can do this, I just worry about the overhead of locking/unlocking perhaps thousands of times per render. Also, performance [as we know it] is not a huge issue here because instead of rendering as often as possible, it renders only when it needs to. So if something might take 100 milliseconds or something outrageous, its not as huge a deal here.

Share this post


Link to post
Share on other sites
You are probably better off speedwise just allocating a vertex buffer as big as you think you will ever need, and working with a copy in system memory and locking and copying updates as necessary. Otherwise you can use DrawIndexedPrimitiveUP, which allows you to specify pointers to sys mem for indices and vertices, although I am almost positive it will be slower.

Share this post


Link to post
Share on other sites