I have a bunch of GL_POLYGONS I need to render using vertex arrays (which are put into Vertex Buffer Objects).
I am using indexing and glDrawElements().
I am aware that you can batch GL_TRIANGLE_STRIPS using redundant vertices, so they are linked up during rendering.
Is something similar possible with GL_POLYGON?
If possible, I would like to avoid calling glDrawElements() in a loop, specifying indices for each polygon.
(This is not for OpenGL ES – I am using OpenGL on a laptop.)
Edit #1:
I want to add here that Tim’s answer below (primitive restart) works, but you need remember to enable this mode – something that took me a while to figure out. ie:
// enable primitive restart
glEnable(GL_PRIMITIVE_RESTART);
You can use
glMultiDrawElementsif you want to draw multiple polygons with a single draw call. You just pass in an an array of pointers to indexes.Alternatively, if you’re targetting a higher version of OpenGL, you can use something called
glPrimitiveRestartIndex, which allows you to specify a special index value that restarts the current primitive. So you could define a ‘special’ index, and then any time you insert that index into your array, the polygon will restart with the next index. This is only core in OpenGL 3+ though.