TL;DR : OpenGL does not consider the restart value and instead see it as a vertex. What am I doing wrong?
I have a VBO storing a collection of polygons (will move to triangle fans later, for now does not help). I am willing to use glPrimitiveRestartIndex to declare when a polygon finishes and when a new one start.
I draw with
GL2 gl2 = gl.getGL2();
gl2.glEnable (GL2.GL_PRIMITIVE_RESTART);
gl2.glPrimitiveRestartIndex (PRIMITIVE_RESTART_VALUE); // 0xffffffff, or -1
...
gl2.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
gl2.glDrawElements (glGeometryType, elementSize, GL.GL_UNSIGNED_INT, firstCoordOffset);
I generate VBO with a restart value every 4 point
protected void append(int[] hexahedronPoints, int p1, int p2, int p3, int p4) {
elementArray[cursor++] = hexahedronPoints[p1];
elementArray[cursor++] = hexahedronPoints[p2];
elementArray[cursor++] = hexahedronPoints[p3];
elementArray[cursor++] = hexahedronPoints[p4];
if(DrawableVBO2.PRIMITIVE_RESTART)
elementArray[cursor++] = DrawableVBO2.PRIMITIVE_RESTART_VALUE;
}
OpenGL does not consider the restart value and instead see it as a vertex. The below picture show a VBO fed with an element array made of 4 indices and 1 primitive restart flag. The four points are labeled and declared in order : 3, 2, 6, 7. Then comes the restart flag that is considered as a fifth point in the polygon.
When drawing, I verify that
- element array has the appropriate content. |3|2|6|7|-1| (where -1 is my restart flag, and the buffer has no more element).
- indices refer to the vertex I setup (1st point : x=1.0 y=2.0 z=-2.0, 2nd point : x=1.0 y=2.0 z=-1.5, 3rd point : x=0.0 y=2.0 z=-1.5, 4th point : x=0.0 y=2.0 z=-2.0).
Complete VBO is here, with drawing here. Defining the restart flag is done here.
NB : Any point of the vertex array is shared between up to 8 polygons. I can not use glMultiDrawElements as a replacer (that would require to repeat most of the vertices of the vertex array by a factor of 8)
NB2 : My code is in Java with JOGL.