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?


1 Answer 1


Don't use DrawUserIndexedPrimitive... create an individual vertexbuffer for your moving objects.. or group all your moving objects in a vertex buffer to share it...

in your object draw call, you can set an individual indexbuffer and transform the position passing the world matrix to the effect

  • \$\begingroup\$ How would I use two Vertex buffers at once? I'm fairly new to 3D. Would I still be calling SetVertexBuffer every frame? \$\endgroup\$
    – MattMcg
    Aug 1, 2013 at 21:57
  • \$\begingroup\$ For each draw call you have to set the right vertex buffer... you should think that the vertex buffer is in gpu memory ... you only pass vertex to gpu memory when you call SetData, so set up the vertexbuffer in the device is relatively cheap \$\endgroup\$
    – Blau
    Aug 1, 2013 at 22:24
  • \$\begingroup\$ Ah thats perfect then. I had no idea SetData was the GPU part and assumed SetVertexBuffer was the expensive part. Thanks, that makes more sense. \$\endgroup\$
    – MattMcg
    Aug 1, 2013 at 22:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .