0
$\begingroup$

When I switch between two different OpenGL shaders instances do I need to re-upload the uniform variables.

For example I have a shader that have a Project and View matrix uniforms defined:

uniform mat4 view; uniform mat4 projection; 

My C++ program creates two "instances" of this shader each of which belongs to a different object--ignore the fact that I shouldn't do this in this example. Each instance is assigned to a different object. As each object is rendered I switch shaders using glUsProgram.

My question is: do I need to re-upload the Projection and View uniforms even though they don't change during application execution? Will each shader instance remember its uniform variables while it is switched-out?

Basically, I'm asking if any uniform variables need to be re-uploaded on every call or does the shader remember between calls and switches?

$\endgroup$

1 Answer 1

0
$\begingroup$

Yes, you need to "reupload" your uniforms. Uniforms are tied to a shader program and glUseProgram will "reset" them, since their locations are tied and thus "unique" to the shader program

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.