Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

c++ - Do uniform values remain in GLSL shader if unbound?

I am writing a program that uses two different shaders for different primitives. My question is: if I bind a program, send it uniform variables, then use another shader program and come back to the first one, will the passed uniform values remain? Here is some pseudocode:

glUseProgram(shader1);
glUniform(shader1,...);
//stuff

for(elements in a list) {
    if(element.type = 1) {
        glUseProgram(shader2);
        element.draw();
    } else {
        glUseProgram(shader1); //Here, do the uniforms from above remain, if shader2 was bound before?
        element.draw();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, uniforms are specific to a program, and will be persistent if you unbind and rebind it.

Also, if you want, you could easily verify this yourself in that sample with glGetUniform.

From the OpenGL 4.1 Specification:

2.11.7 Uniform Variables

... Uniforms are program object-specific state. They retain their values once loaded, and their values are restored whenever a program object is used, as long as the program object has not been re-linked. ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...