如果未绑定,均匀值保留在GLSL着色器中? [英] Do uniform values remain in GLSL shader if unbound?
本文介绍了如果未绑定,均匀值保留在GLSL着色器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个程序,它使用两个不同的着色器来处理不同的图元。我的问题是,如果我绑定一个程序,发送统一的变量,然后使用另一个着色程序,并回到第一个,将传递的统一值保持?下面是一些伪代码:
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();
}
}
推荐答案
是,制服是特定于程序的,如果你解除绑定并重新绑定,它将是持久的。
Yes, uniforms are specific to a program, and will be persistent if you unbind and rebind it.
此外,如果你愿意, glGetUniform 。
Also, if you want, you could easily verify this yourself in that sample with glGetUniform.
从 OpenGL 4.1规范:
2.11.7统一变量
... Uniforms是程序对象的特定状态。它们在加载后保留它们的值,并且只要程序对象被使用,它们的值就被恢复,只要程序对象没有被重新链接。 ...
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. ...
这篇关于如果未绑定,均匀值保留在GLSL着色器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文