Efficently set shader uniform parameter.
I'm relative new to opengl ES 2.0, and just wondering if someone can give me an answer on this.
From opengl es 2.0 specification, I've learned that for every glUseProgram call, it will clear out all uniform register ,which is an expensive operation, and in order to have the vertex shader working properly, I need to reset all view/projection matrices etc.
My question is, for a render frame, the view/projection matrix might be almost identical across all draw calls, and everytime I change the shader, it have to reset those matrices and cost CPU/GPU time. Is there a way to avoid this like using constant register in directX or uniform buffer object for opengl es 3.0 ?
Any help is really appreciated.
Originally Posted by PengPeng
"Expensive" is a relative term and OpenGL ES 2.0 is for embedded systems and not intended to match the performance of desktop OpenGL implementations.
The approach I use is to only switch shaders when absolutely necessary. It can be better to have a larger shader with more uniform parameters than a lot of smaller shaders that must be switched frequently.
Which is exactly why developers will typically sort draw calls based on program first to avoid the expensive state transitions. Ideally, a program would only be selected once per frame.
I haven't had the same experience. Some uniforms I set at initialization time and never change them, whereas other uniforms are changes every call. I switch programs a lot, too, because I don't have control of the display list. Have you tried not setting uniforms that do not change for a given program?