Forward-compatible line drawing

Hello everybody,

what is the correct and most efficient way to draw single lines in a forward-compatible way? In my application, lines are only used for debugging purposes (i.e. to represent normals of a mesh, drawing a bounding box, a grid, origin axis etc.), so they are neither often used nor particularly important. However, the visual debugging output is quite handy sometimes.

Currently, I am drawing the lines in immediate mode, which does not affect the performance in any noticable way, but as the output should also work with forward-compatible contexts, I need to change this. Implementing vertex, color and index buffer as well as a vertex array object for each line or line bundle produces a significant overhead which leads to a massive performance drop. Due to object-oriented encapsulation, it is not possible to collect all lines of the entire application into a single buffer, so most of the lines or line bundles have to be treated separately. Having hundreds of bounding boxes, this really kills the application with non-immediate-mode drawing.

So, my question: How do I draw all those single tiny objects without major overhead in a forward-compatible way?

Regards,
nostalgic

Due to object-oriented encapsulation, it is not possible to collect all lines of the entire application into a single buffer

Then fix that. D3D and console developers have found ways to do this. You can too.

This isn’t even a hard problem. You expose a function that draws a line. This function takes the line data and stores it in some data structure. When it’s time to render stuff, you go through all of the lines, add them to the buffer object, and draw them all at once.

If there’s “object-oriented encapsulation” stopping you, then you need to re-evaluate how you’re doing this “object-oriented encapsulation”. Technology exists to solve your problems. If it’s getting in the way of solving something remove it.

Thank you for your answer. As you noticed yourself, this is not really a problem I am having, I am just asking for different ways of what I could think of. If collecting all lines into a single buffer is necessary to draw them efficiently, I will do that. However, neglecting meaningful design patterns of software (namely the encapsulation of objects) seems like a very drastical way to solve a problem.

However, neglecting meaningful design patterns of software (namely the encapsulation of objects) seems like a very drastical way to solve a problem.

There is nothing about object encapsulation that would prevent you from implementing this exactly as I described. If it does, then you are doing it wrong.

The object that you collect the lines in is an object. It can be encapsulated with a proper API and everything. This object will be exposed to those who might need it, via encapsulated APIs and such. And when the graphics system (which is an encapsulated object) is executed, it will take that object, have it pour its contents into a buffer object, and render the data from that buffer.

All object-oriented, all encapsulated.

My point was that if your encapsulation is getting in the way, then the problem is in your encapsulation. You have designed yourself into a bad situation. So fix that.

I had a similar problem, and to be honest Alfonse is right. Performance vs elegance is always a trade-off. Graphics programming usually results in lots of compromises for performance.