Search code examples
openglglslopengl-extensions

GLAD, extensions not being loaded


My application sent me this message when I tried to run a GLSL3.3 shader

#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.

So I went back and added said extension to the GLAD generator: You can see my choices below!
http://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D3.3&extensions=GL_ARB_explicit_uniform_location

Afterwards, I copy-pasted my glad.c and glad.h files back into my file and compiled... and to my surprise, I got the same error! (Didn't include KHR.h file)

What am I doing wrong?


Solution

  • This has nothing to do with GLAD. It has everything to do with how extensions work in GLSL.

    In OpenGL, extensions simply exist; your implementation provides them and they have effects, whether you explicitly use them or not. Whether you use an extension loader or not, the implementation still provides their functionality.

    But in GLSL, that's not how it works. When you say #version 330 core, you are saying that the following text forms to The OpenGL Shading Language, as defined by version 3.30 of the specification. Exactly and only that language.

    GLSL 3.30 does not allow uniform locations to be specified in the shader. For that, you must be using either GLSL version 4.30 or the ARB_explicit_uniform_location extension.

    In GLSL, extensions only apply to the language when you explicitly ask for them. Since you did not ask for the ARB_explicit_uniform_location extension, its grammatical changes do not apply to your shader. Hence the compile error.

    If you want a shader to use an extension, you must specify it explicitly with a #extension declaration:

    #extension GL_ARB_explicit_uniform_location : require
    

    This should come after your #version declaration, but before any actual GLSL text.