0

当我尝试运行 GLSL3.3 着色器时,我的应用程序向我发送了此消息

#version 330
layout(location = 0) in vec2 position;
layout(location = 1) uniform float TimeUniform = 0.0f;
out float TimeUniformFrag;
void main() {
    gl_Position = vec4(position.x - 1.0f, position.y - 1.0f, 0.0f, 1.0f);
    TimeUniformFrag = TimeUniform;
}
...
Vertex Shader: 0:3(1): error: uniform explicit location requires GL_ARB_explicit_uniform_location and either GL_ARB_explicit_attrib_location or GLSL 3.30.

所以我回过头来为 GLAD 生成器添加了上述扩展:你可以在下面看到我的选择!
http://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D3.3&extensions=GL_ARB_explicit_uniform_location

之后,我将我的glad.c 和glad.h 文件复制粘贴回我的文件并编译……令我惊讶的是,我得到了同样的错误!(不包括 KHR.h 文件)

我究竟做错了什么?

4

1 回答 1

5

这与 GLAD 无关。它与扩展在 GLSL 中的工作方式有关。

在 OpenGL 中,扩展只是存在;您的实现提供了它们并且它们具有效果,无论您是否明确使用它们。无论您是否使用扩展加载器,实现仍然提供它们的功能。

但在 GLSL 中,它不是这样工作的。当您说 时#version 330 core,您是在说以下文本形成 OpenGL 着色语言,由规范的 3.30 版定义。正是并且只有那种语言。

GLSL 3.30 不允许在着色器中指定统一位置。为此,您必须使用 GLSL 4.30 版或 ARB_explicit_uniform_location 扩展。

在 GLSL 中,扩展仅适用于您明确要求的语言。由于您没有要求 ARB_explicit_uniform_location 扩展,因此其语法更改不适用于您的着色器。因此编译错误。

如果您希望着色器使用扩展,则必须使用声明明确指定它#extension

#extension GL_ARB_explicit_uniform_location : require

这应该在您的#version声明之后,但任何实际的 GLSL 文本之前。

于 2017-12-27T19:34:23.660 回答