Login  Register

Re: MultiDrawElements

Posted by Martin on Oct 01, 2021; 4:00pm
URL: https://forum.jogamp.org/MultiDrawElements-tp4036014p4041329.html

Resolved! There is a method in PointerBuffer that was not used by James and Elect which simplify the 2D index. Here is an example assuming an input int[][] elementsIndice, where each line is a list of indices for 1 element (e.g. a triangle fan). Each line can have a different number of vertex indices.

PointerBuffer elementIndicesBuffer = PointerBuffer.allocateDirect(elementsIndices.length);
IntBuffer elementCountBuffer = Buffers.newDirectIntBuffer(elementsCount);

for (int i = 0; i < elementsIndices.length; i++) {
  IntBuffer elementDataBufferI =  Buffers.newDirectIntBuffer(elementsIndices[i]);
  elementDataBufferI.rewind();
 
  elementIndicesBuffer.referenceBuffer(elementDataBufferI);
  elementCountBuffer.put(elementsIndices[i].length);
}

elementCountBuffer.rewind();
elementIndicesBuffer.rewind();



Surprisingly, there is no need to bind any element buffer. Vertex, color and normal buffer must be bind. Then one simply invoke

glMultiDrawElements(GL.GL_TRIANGLE_FAN, elementCountBuffer, GL.GL_UNSIGNED_INT, elementsIndicesBuffer, elementCountBuffer.capacity());