Using a Vertex Buffer and DrawUserIndexedPrimitives?

Posted by MattMcg on Game Development See other posts from Game Development or by MattMcg
Published on 2013-08-01T21:03:42Z Indexed on 2013/08/02 16:07 UTC
Read the original article Hit count: 263

Filed under:
|
|

Let's say I have a large but static world and only a single moving object on said world.

To increase performance I wish to use a vertex and index buffer for the static part of the world.

I set them up and they work fine however if I throw in another draw call to DrawUserIndexedPrimitives (to draw my one single moving object) after the call to DrawIndexedPrimitives, it will error out saying a valid vertex buffer must be set.

I can only assume the DrawUserIndexedPrimitive call destroyed/replaced the vertex buffer I set. In order to get around this I must call device.SetVertexBuffer(vertexBuffer) every frame. Something tells me that isn't correct as that kind of defeats the point of a buffer?

To shed some light, the large vertex buffer is the final merged mesh of many repeated cubes (think Minecraft) which I manually create to reduce the amount of vertices/indexes needed (for example two connected cubes become one cuboid, the connecting faces are cut out), and also the amount of matrix translations (as it would suck to do one per cube). The moving objects would be other items in the world which are dynamic and not fixed to the block grid, so things like the NPCs who move constantly.

How do I go about handling the large static world but also allowing objects to freely move about?

© Game Development or respective owner

Related posts about XNA

Related posts about 3d