Search code examples
opengloptimizationshader

Should shader programs be shared in OpenGL


Scenario: let's say I have a shader program implementing basic illumination and coloring (phong + multiple texture maps) in OpenGL. Since all my objects in the scene should look the same (except textures), I thought to just bind the same shader program for each object and just update the uniforms (MVP matrix, normal matrix and about 20 object specific properties).

My question: since glUniform calls are not exactly free, should I clone my program in order drastically cut down on glUniform calls? Sharing it, I would only need to update the MVP and normal matrix.


Solution

  • Changing uniform values is much cheaper than changing programs. The AZDO presentation made it clear that changing programs is something that, if you care about performance in large-scale rendering operations, should be done relatively sparingly.