【发布时间】:2019-12-04 04:48:19
【问题描述】:
标题是我的问题。 OpenGL v 4.1 是否可以替换“绑定”布局限定符?
我使用的是 MacOS 和 Xcode,所以如果我运行 OpenGL 4.2,我会收到 glewinit 错误提示“缺少 GL 版本”。
如果我用 OpenGL 4.1 运行这段代码,当然它不能识别 'binding' 关键字。
我的顶点着色器代码是:
#version 410
layout (location=0) in vec3 pos;
layout (location=1) in vec2 texCoord;
out vec2 tc;
uniform mat4 mv_matrix;
uniform mat4 proj_matrix;
layout (binding=0) uniform sampler2D samp; // not used in vertex shader
void main(void) {
gl_Position = proj_matrix * mv_matrix * vec4(pos, 1.0);
tc = texCoord;
}
我的片段着色器代码是:
#version 410
in vec2 tc; // interpolated incoming texture coordinate
out vec4 color;
uniform mat4 mv_matrix;
uniform mat4 proj_matrix;
layout (binding=0) uniform sampler2D samp;
void main(void) {
color = texture(samp, tc);
}
【问题讨论】:
-
因为绑定点是 0 (
binding=0) 你根本不需要它,因为 0 是默认值。
标签: opengl layout binding glsl qualifiers