Answers to my previous question suggested that I use a Vertex Buffer Object and merge my position data with my color data into a single array, which I have now done in this simple test case:
http://jsfiddle.net/headchem/r28mm/14/
Pseudo code for every frame:
function drawFrame() {
// clear global vertex[] array containing both position and color
// recreate it with new triangles and colors (determined elsewhere)
drawShapes();
// put the vertex array into the VBO using gl.bufferData
// finish with a single call to gl.drawArrays(gl.TRIANGLES, 0, numItems);
render();
}
I know there is no silver bullet, but for my goal of rendering a screen full of changing unique triangles, is this the most efficient way possible? Would using bufferSubData offer any benefit over bufferData?
When I tested this in an animation loop, I could update around 800 triangles per frame before framerate suffered. Is this the limit of what I can do when I want unique and changing triangles on every frame? I see people throwing around much larger numbers like 50k triangles - is that because they are able to cache their vertex array on the graphics card and don't need to change every vertex and color on every frame? When using the canvas api, I can draw 1500 differently colored and positioned rectangles before framerate dips - what am I doing wrong with my WebGL that the canvas api outperforms it?