I've been trying to find a way to draw thousands of lines in opengl and take as little performance loss as possible. I have to draw beteewn 10000 to 100000 unconnected lines with 21 points each, and I'm not sure how to go about this issue. From what I've found on the web I should try to minimize the overhead of drawing calls and also not to constantly send data to the gpu. Until now I've tried a few things:
- Using just one VBO for everything.
This way I just send the data once, but end up having draw calls for each line separated by 21 points like glDrawArrays(GL_LINE_STRIP, i * 21, 21) where I iterate over i for the amount of lines. Though this kinda works, but it seems like there could be an easier, more elegant solution, without that many draw calls.
- Using diferent VBOs for each line.
I didn't really think this was a good idea, it gets really messy and end up having just as many draw calls.
Is there a way to draw thousands of lines with one draw call?, and if not, how should I go about this issue?
I'm using OpenGL 3.3.
glVertexPointer
to define an array of vertex data and afterwards draws them with one call toglDrawArrays
? – wsdookadrGL_LINES
. Instead of 10000 line_strips with 21 point each, you'll draw 210000 lines. UsingglDrawElements
will also save quite a lot of memory. – Kien Truong