7
\$\begingroup\$

I've recently started porting some old rendering demos I did to modern OpenGL. I had a debug drawing class in my old code which used immediate mode glBegin(), glEnd() etc. for rendering debug objects such as triangles, cubes and spheres etc.

Originally I replaced the code in these functions with code to generate the VAO and VBOs (for position and colour), bind them, assign the vertex data, render, then disable and delete the VBOs and VAO. Is there anything wrong with this?

I've been thinking about modifying the class so that every time it gets a draw primitive call it generates the VAO and VBOs and assigns the vertex data but doesn't actually do the rendering until after all the other rendering has been completed. Then it renders all the debug prims that have been stored at once.

I'm not sure of the benefits of either way of doing this and was just wondering what people thought.

\$\endgroup\$

2 Answers 2

7
\$\begingroup\$

If you are doing debug drawing, then performance really shouldn't be your highest concern. Getting it working is far more important. After all, you won't be using this stuff in release builds, so what does it matter?

However, if you are interested in one way to do it, this page on buffer object streaming suggests ways to improve performance for manually-generated vertex data. Pay particular attention to the "Buffer Update" method.

\$\endgroup\$
1
\$\begingroup\$

Whether you want to use immediate mode or VBOs, it depends on the complexity of the scene. I've seen some examples where tangent/normal lines are drawn using immediate mode.

There is nothing wrong with using VBOs for debugging. However, keep in mind that, generally speaking, batching will give you performance benefits no matter which approach you use, so always look to use it whenever possible. You can still benefit a lot from batching in immediate mode (maybe even more), because it will greatly reduce the number of state changes. If batched properly, you will only ever need one GlBegin() and GlEnd(), and all similar data is tightly grouped together. The only difference is that you'll be batching state calls instead of vertex data.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ I'm not wanting to use immediate mode at all as it's been deprecated. At the minute I've replaced immediate mode so that on a call to say DrawDebugCube() it creates the vertex buffers, populates them with data, renders them and then deletes them. What I'm thinking of doing is having DrawDebugCube() just create the buffers and populate them. Then all of the debug prims that have been buffered get rendered all at once later on. \$\endgroup\$
    – user10329
    Commented Oct 4, 2011 at 22:39

You must log in to answer this question.

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