What is the fastest way to draw multiple polygons?

With a single large polygon, GL_LINE_LOOP would be the obvious choice. But if we want to draw many polygons what is the fastest way to do it? For example, with 5 million points, and polygon length of about 100?

The way we are currently using is GL_LINES with indices 0,1 1,2 2,3, etc.
This is very wasteful and inefficient, but it allows a single call to OpenGL to draw multiple polygons, and it seems that anything else we have found would be more inefficient.

A second question is whether there is any way to draw filled polygons followed by line polygons in a single call? The answer would appear to be no, just checking whether there is some trick

In OpenGL 3.1 or later, you can use glEnable(GL_PRIMITIVE_RESTART) and glPrimitiveRestartIndex to render multiple strips or loops with a single glDrawElements call.

In OpenGL 1.4 or later, you can use glMultiDrawElements to pack multiple draw calls (with a common mode parameter) into a single call.

There is no mechanism to render different types of primitives (e.g. lines and triangles) in a single draw call.

Convex polygons, or concave?

Not sure. I know the number of segments

Well, OpenGL doesn’t directly support filling non-convex polygons (in 3+ core profile, it doesn’t support filled polygons other than triangles, which are always convex), so non-convex polygons either have to be tessellated into triangles (GLU can do this) or filled using stencilling.

This is GIS data, so now that I look at it, it’s not convex though the lines don’t cross each other. Thanks for pointing out the tesselation problem, I had not thought of that.

I’ve made a solution that intends to solve this problem … it may even be usable ;o7
presentation

Thanks! I will look at that right away.

Ouch. That’s what I was concerned about when I asked about non-convex.

Poly data from GIS sources is often complex and not optimized for realtime rendering. It’s often concave, and there may be hundreds or thousands of edges in a single polygon.

If you can pre-tessellate it, great. Otherwise, consider the trade-offs between 1) runtime tessellation on-load or instead using 2) a stencil-based coverage method to mark pixels in the poly (or group of polys having the same material/shading) followed by a simple quad to texture/shade on the appearance of the poly(s).

If the polygon is static (i.e. doesn’t change after loading), the trade-off probably favours tessellation. You only have to tessellate once, while stencilling has to be done each time you draw the object. For stencil-drawing regions which are highly non-convex, there may be a lot of overdraw. Stencilling is more useful if the polygon is dynamic.