My program uses PyOpenGL (so it's Python) with psyco.
I have around 21,000 line segments which I need to render in each frame of my render (unless the user zooms in, in which case line segments are culled and not sent to the card at all). This is currently taking around 1.5 seconds each frame to complete. That's just not good enough, so I'm looking at ways to reduce the number of distinct line segments.
I imagine there would be cases where multiple line segments can be merged into one big line, but I honestly do not even know where to begin with this. I do have the start point and end point of each line stored, so that might help things. Note that I am able to take as long as I need to at startup, and memory usage isn't too much of a concern.
Any ideas would be much appreciated.
It's almost certainly the overhead of all the immediate mode function calls that's killing your performance. I would do the following.
Don't use GL_LINE_STRIPS
, use a single list of GL_LINES
instead so they can be rendered in one go.
Use glDrawArrays
instead of immediate mode rendering:
float* coordinates = {....}; //x and y coordinate pairs for all line segments
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 2 * sizeof(float), coordinates);
glDrawArrays(GL_LINES, 0, 2 * linecount);
glDisableClientState(GL_VERTEX_ARRAY);
(For even better performance you can store the vertex buffer in something called a vertex buffer object, but this should be fine to begin with)
One final thing, if you're do culling on a per line basis it's probably faster to just skip it and send all the lines to the GPU.