reduce number of drawElements call (TRIANGLE_STRIP)

312 views
Skip to first unread message

Laurent Le Goff

unread,
Jul 20, 2011, 2:18:26 PM7/20/11
to webgl-d...@googlegroups.com
Hi,

I would like to reduce the number of drawElements call when rendering a mesh. The mesh that have been loaded has some sets of Triangles strip. I've put all this indices of vertices in a U16 array prefixed by the number of vertices for each set of triangle strips, example:

[6, 1, 4, 3, 6, 7, 9, 5, 7, 1, 3, 6, 4 etc...]
explain: Each red value in the array is the next number of vertices to use.

in javascript, this array is loaded as an Element Buffer and for each set of triangle strip there's a call to drawElements
javascript code :

gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indicesBuffer);
int offset = 0
while(offset < indices.length) {
   var setLength = indices[offset];
   offset++;
   gl.drawElements(gl.TRIANGLE_STRIP, setLength, gl.UNSIGNED_SHORT, offset);
   offset += setLength;
}

this work just fine but there's a lot call to drawElements, how can I reduce this ?

I think moving this to vertex shader program but I don't know how ?

this is the actual vertex shader:

attribute vec3 aVertexPosition;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;

void main(void) {
   gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}

Any help is appreciated
Thanks

Laurent





Hakuro

unread,
Jul 20, 2011, 2:43:16 PM7/20/11
to webgl-d...@googlegroups.com
Hi Laurent.
You can try inserting degenerate triangles to reduce # of draw calls like,
[1, 4, 3, 6, 7, 9, 9, 7, 7, 1, 3, 6, 4 etc...]
You can issue the vbo with single draw call.

Thanks!
Hak Matsuda

Laurent Le Goff

unread,
Jul 20, 2011, 2:55:04 PM7/20/11
to webgl-d...@googlegroups.com
I'll try and post the result.
Thanks

Laurent Le Goff

unread,
Jul 21, 2011, 3:26:57 AM7/21/11
to webgl-d...@googlegroups.com
How about triangle fans ?

Laurent Le Goff

unread,
Jul 21, 2011, 4:24:45 AM7/21/11
to webgl-d...@googlegroups.com
yeah !!
It works for triangle strip :-)

How about triangle fans ?
Reply all
Reply to author
Forward
0 new messages