Search code examples
openglvbovertex-shadervertices

Update VBO or use uniforms?


Let's say I've got hundreds of rectangles on my scene. Each of them is changing each frame:

  • they move over scene, they rotate, scale up/down
  • vertices's color changes and should be combined with texture's color
  • textures coordinates changes because those are 2D animations

How should I do it to get the best performance? There are my ideas. Please help me choose which is the best of them or suggest something else:

  • update VBO each frame
  • make more vertices than need (example: store all animation's frames in VBO) and choose which is rendered (call glDrawElements many times)
  • send changing data via uniforms and recalculate it in vertex shader instead of CPU

The main question actually is: which functions can I call as many times as I want and which I should avoid calling more than few time per main loop?


Solution

  • Usually the model remains the same in its local space so you only need to upload it once to the VBO. Changes such as translations, rotations, scaling, etc are performed by loading corresponding transformation matrices into uniforms and using them in the shaders.