Do uniform values remain in GLSL shader if unbound?(如果未绑定,统一值是否保留在 GLSL 着色器中?)
问题描述
我正在编写一个程序,该程序对不同的图元使用两种不同的着色器.我的问题是:如果我绑定一个程序,给它发送统一变量,然后使用另一个着色器程序并返回到第一个,传递的统一值会保留吗?这是一些伪代码:
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();
}
}
推荐答案
是的,uniforms 是特定于某个程序的,如果你解除绑定和重新绑定它,它就会持久化.
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 统一变量
...制服是程序对象特定的状态.一旦加载,它们就会保留它们的值,只要程序对象被使用,它们的值就会恢复,只要程序对象没有被重新链接....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 着色器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果未绑定,统一值是否保留在 GLSL 着色器中?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
