I have a simple OpenGL application where I'm drawing coastline data. The data is a long list of polygons (about 41000) where each polygon is a list of (x,y) points. The polygons are all different lengths (since some coastlines are longer than others). Now, using a display list this is trivial to draw - this is Python code but I'm sure you get the gist:
self.coastlines_dl = GL.glGenLists(1)
GL.glNewList(self.coastlines_dl, GL.GL_COMPILE)
for poly in coastline_polys:
GL.glBegin(GL.GL_LINE_STRIP)
for point in poly:
GL.glVertex3f(point[0], point[1], 0.0)
GL.glEnd()
GL.glEndList()
and then during the render loop:
GL.glCallList(self.coastlines_dl)
This performs very well.
My question is: how do I do the equivalent using VBOs? My initial approach, since I've never used VBOs before and just wanted to get it working, was to create a VBO for each polygon, and then draw each VBO in the render loop, something like:
for v in self.vbos:
v.bind()
GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
GL.glVertexPointerf(v)
GL.glDrawArrays(GL.GL_LINE_STRIP, 0, v.data.shape[0])
GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
v.unbind()
This works, in that it draws the data, but the framerate is appalling, which is not surprising since I'm binding and drawing 41000+ times per frame.
So can I put all my polys into one big VBO and just do one bind and one glDrawArrays? What I don't understand is how glDrawArrays would know how many points are in each polygon, since it's different for every one?
Apologies if this is very trivial, but I keep reading that anything I can do with display lists can be done with VBOs, but I can't find an example that shows what I need to do.
Edit 1 - In Light of Slow VBO Performance, Here's My Platform details
Windows 7 64 bit
i5-2430M
GPU is just onboard Intel HD Graphics 3000
4GB RAM
Application is Python OpenGL. Python version is 2.7.9 64 bit, with PyOpenGL 3.1.0 amd64, and using a QT QGLWidget via PySide 1.2.2 amd64.
Here's a dump from gDEBugger:
General
-------
OpenGL Version 3.1
Shading Language Version 1.40 - Intel Build 8.15.10.2345
Is Backward-Compatible Yes
Is Forward-Compatible No
Is Debug Context Yes
Renderer Vendor Intel
Renderer Name Intel(R) HD Graphics Family
Renderer Version 3.1.0 - Build 8.15.10.2345
Renderer Type Installable client
Marked for Deletion No
OpenGL Sharing Contexts None
Pixel Format Information
------------------------
Pixel Format ID 9
Hardware Acceleration Full
Double-Buffered Yes
Stereographic No
Native Rendering No
Channel Bits
Red 8
Green 8
Blue 8
Alpha 8
Depth 24
Stencil 8
Accumulation 64