Ban*_*urt 3 opengl legacy glsl
我目前正在尝试弄清楚如何在旧 GLSL 中的着色器之间共享统一。在制服前面粘贴“共享”无法编译。 编辑:我知道制服的范围是一个程序。modeliew-projection-matrix 就是一个例子。人们不想为每个程序单独设置它,但只设置一次。
有办法做到吗?
这是(顶点)着色器代码:
#version 130
in vec4 position;
in float size;
in vec4 incol;
out vec4 color;
shared uniform ivec4 relWorldOffset;
uniform vec4[14] cubestrip;
uint cubeindex;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix
* (cubestrip[cubeindex] * size
+ relWorldOffset + position);
cubeindex++;
color = incol;
cubeindex %= 14U;
Run Code Online (Sandbox Code Playgroud)
这是错误:
0:6(1): error: syntax error, unexpected NEW_IDENTIFIER, expecting $end
Run Code Online (Sandbox Code Playgroud)
GLSL 中没有shared这样的关键字。您可能正在寻找统一块或统一缓冲区对象(UBO)。根据OpenGL wiki,它们需要 OpenGL 3.1 版本(因此#version 140需要 GLSL 或更高版本)。如果这不是问题,GLSL 语法将如下所示:
uniform MatrixBlock
{
mat4 projection;
mat4 modelview;
};
Run Code Online (Sandbox Code Playgroud)
另外,请查看本教程和GLSL 1.40 规范(第 4.3.5.1 章)以获取更多指导。
(编辑:实际上,shared关键字是在最新的 OpenGL 版本中定义的,但它仅用作计算着色器中的布局限定符,以使变量在工作组内共享。)
| 归档时间: |
|
| 查看次数: |
2594 次 |
| 最近记录: |