View Full Version : Best way to setup multiple "objects"

11-22-2011, 09:28 AM
I've been working on a maze generator as expressed in my other thread. I've currently got a vertex buffer object and a vertex array object to store the vertices and indices of the maze grid and the lines. Right now I'm only drawing lines.

I'd like to also add some shapes to mark start and end point as well as the solve and backtrack path markers. I figured I could use GL_TRIANGLE_STRIP for those.

My question is, do I need to set up multiple buffer arrays for each different part of my scene? or should I just keep adding vertices and indices and use different draw commands with offsets to the same buffer that encompasses the whole scene?

11-22-2011, 10:06 AM
There's no fixed answer to this kind of thing. What you are dealing with is fairly simple geometry, so any solution is 'good'. When you have arbitary models, you tend to stick them into separate buffer objects, unless you can guarantee certain aspects such as sizes and offsets.
Personally, I'd use separate buffer objects.

11-22-2011, 10:07 AM
Using a single buffer when you can is a good idea. Then you have less OpenGL*state to switch.

For a simple case where all buffers contain static (or change rarely, not every frame) you can get away with 1 index buffer, 1 vertex buffer and 1 vertex array object. For each shape, reserve a range from vertex and index buffer. If you can use base vertex version of draw commands, you do not need to remap indices, if not them you will need to adjust vertex indices based on the offset in the vertex buffer.

If you have dynamic content, you may want to add buffers with different usage hints. You may also cycle between 2 or more buffers on alternate frames, this can improve performance.