4

I'm wondering if this API method used to load a shader program is expensive or not to call? Im considering making this call per object in my 3D scene.

gl.useProgram(shaderProgram);

thanks

AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140

1 Answers1

12
  • this says it's better to use glUseProgram than is to glAttachShader+glLinkProgram
  • this says that changing shaders is always heavy, but glUseProgram is least heavy
  • this says it's generally efficient
  • this says that moderate and careful use won't become a bottleneck
  • this talks a bit about shader-switching performance optimization

So, conslusion: use it moderately. If you don't have much objects - great, if you do - try optimizing shader switching, or reusing shaders multiple times, or use same shader that utilizes branching somehow.

useProgram has got medium performance hit. It's not super-light, neither it's super-heavy like linkProgram and compileShader.

Hope this helps.

Community
  • 1
  • 1
Dragan Okanovic
  • 7,509
  • 3
  • 32
  • 48