GLAD,扩展未加载

问题描述 投票:0回答:1

当我尝试运行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文件)

我究竟做错了什么?

opengl glsl opengl-extensions
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扩展,因此其语法更改不适用于您的着色器。因此编译错误。

如果你想要一个着色器使用扩展,你必须specify it explicitly with a #extension declaration

#extension GL_ARB_explicit_uniform_location : require

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

© www.soinside.com 2019 - 2024. All rights reserved.