【问题标题】:GLSL Layout Qualifier Binding Points for out-dated OpenGL version过时 OpenGL 版本的 GLSL 布局限定符绑定点
【发布时间】: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


【解决方案1】:

“替换”是什么意思?您可以使用 glUniformBlockBinding 从 OpenGL 分配统一缓冲区绑定点。但是没有其他方法可以在着色器本身中定义它。毕竟,如果有的话,为什么我们首先需要binding 限定符?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多