I’m fairly new to OpenGL retained mode. I’ve been hunting around for best practices with regards to handling large numbers of sprites. If I have thousands of sprites, with anything from none to all requiring updating per frame, how best to pass that information to the shader? I’ve read plenty of different approaches without finding any consensus.
I have put all my sprite vertices into a single VBO. If I want to update their individual positions, rotations etc within a scene, I could,
Recalculate all the vertex positions on the CPU per frame and call glBufferData(…) to update the VBO. Pros, only requires one glDrawArrays(…) call. Cons increased bandwidth and CPU.
Recalculate the model matrix for each sprite. On render, call glUniformMatrix4fv(…) to update the model matrix uniform in the vertex shader, then call glDrawArrays(…) per sprite (six verts). Pros, lower bandwidth and CPU, moved matrix calcs to GPU. Cons, many more draw calls and uniform state changes.
Store a model matrix for each sprite as 3*vec4 stream/dynamic VBOs and pass to the vertex shader as attributes. Update using glBufferData(…). Pros, only requires one glDrawArrays(…) call and moved matrix calcs to GPU. Cons, increased bandwidth.
Each approach seems to have at least one significant drawback. Have I missed a trick? Can anyone give me advice on which approach I should take?
Thanks in advance!