Hi
TL;DR : I hardly understand the datastructure required to invoke glMultiDrawElements, could you tell me where I am wrong?
I want to draw quads (based on GL_TRIANGLE_FAN
) that share vertices between each other. I want to use glMultiDrawElements
and would like to avoid repeating and ordering them them manually to fit the glMultiDrawArrays
function requirements (which would also require to have points of a triangle fan contiguous).
Given the left side example, I am willing to build quads as follow
elementCount : {4, 4}
elementIndices : {{P0, P1, P2, P3}, {P3, P2, P5, P4}}
Here is how I try to do it (in Java with JOGL)
I first register vertices, normals and colors with FloatBuffers. I think I do this properly since I can use glMultiDrawArrays
properly with other cases where vertices are repeated and contiguous.
Then I invoke glMultiDrawElements
as follow :
glMultiDrawElements(glGeometryType, elementsCountBuffer, GL.GL_UNSIGNED_INT, elementsIndicesBuffer, elementsIndicesBuffer.capacity());
where elementsCountBuffer
is filled with a 1D array as follow :
IntBuffer elementCountBuffer = Buffers.newDirectIntBuffer(elementsCount); // int[] elementsCount
elementCountBuffer.rewind();
and elementsIndicesBuffer
is filled with a 2D array as follow :
PointerBuffer elementIndicesBuffer = PointerBuffer.allocateDirect(size(elementsIndices)); // int[][] elementsIndices, where size(array) returns #row x #columns
for (int i = 0; i < elementsIndices.length; i++) {
// Each i is the ID of a GL_TRIANGLE_FAN
for (int j = 0; j < elementsIndices[i].length; j++) {
// Each j is the index of a vertex to use in the vertex/normal/color buffers to draw the ith triangle fan
elementIndicesBuffer.put(elementsIndices[i][j]);
}
}
elementIndicesBuffer.rewind();
I am almost sure I do this wrong because the man page of the function states that the last argument - drawcount
- should describe the length of the two buffer, hence that they should be equals .
As the purpose of this function is to draw multiple elements based on vertices that may be shared among these elements, I wonder how elementIndicesBuffer
could be anything else than a 2D array? Otherwise, if it is a 1D array, how can I register in it the list of indices for the first triangle fan, then second triangle fan, etc?
Thanks!