Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebGL - Is the gl.useProgram() an expensive call to make?

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

like image 966
AlvinfromDiaspar Avatar asked Dec 26 '22 08:12

AlvinfromDiaspar


1 Answers

  • 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.

like image 86
Dragan Okanovic Avatar answered Jan 03 '23 14:01

Dragan Okanovic