Do uniform values remain in GLSL shader if unbound?

瘦欲@ 提交于 2019-11-27 17:33:13

问题


I am making a program that uses two different shaders for different 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();
    }
}

回答1:


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


来源:https://stackoverflow.com/questions/10857602/do-uniform-values-remain-in-glsl-shader-if-unbound

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!