How can I reduce draw calls when using glBufferSubData and DYNAMIC_DRAW?
Posted
by
Kronos
on Game Development
See other posts from Game Development
or by Kronos
Published on 2014-05-19T14:20:48Z
Indexed on
2014/05/28
22:09 UTC
Read the original article
Hit count: 556
At first I had the problem where I had about 150 rectangles rendered every tick. I only used STATIC_DRAW
and glBufferData
. I added support for DYNAMIC_DRAW
and glBufferSubData
and now I have a very good result... but the number of draw calls (glDrawArrays
) is the same. Best practices from Mozilla Dev website said it should be reduced, but how?
Every rectangle has a method render()
in which I do following (shortend):
_gl.bindBuffer(WebGL.ARRAY_BUFFER, vertexBuffer);
_gl.enableVertexAttribArray(a_position);
_gl.vertexAttribPointer(a_position, 2, WebGL.FLOAT, false, 0, 0);
_gl.bufferSubData(WebGL.ARRAY_BUFFER, 0, vertices);
_gl.bindBuffer(WebGL.ARRAY_BUFFER, texCoordBuffer);
_gl.enableVertexAttribArray(a_texCoordLocation);
_gl.vertexAttribPointer(a_texCoordLocation, 2, WebGL.FLOAT, false, 0, 0);
_gl.bufferSubData(WebGL.ARRAY_BUFFER, 0, texVertices);
_gl.uniform2fv(_utranslation, _translation);
_gl.uniform2fv(_urotation, _rotation);
_gl.uniform2f(_location, Dart2D.WIDTH, Dart2D.HEIGHT);
_gl.drawArrays(WebGL.TRIANGLES, 0, 6);
So every rectangle calls drawArrays
in every frame...
© Game Development or respective owner