Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Unknown layout specifier "binding = 1"

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    18

    Unknown layout specifier "binding = 1"

    I am atm creating a camera with the help of GLM. Everything went well until the point I had to specify a matrix4x4 uniform in my shader.
    I use layout specifiers to specify my uniforms. The big problem with this is, that it gives me an error: error C3008: unknown layout specifier 'binding = 1'.

    Does anyone know how I can fix this probem?

    (Sorry I do not know how to create codeblocks, if someone can explain this too I would be really gratefull)

    My vertex shader:

    Code glsl:
    #version 450
     
    layout(location=0) in vec3 position;
    layout(location=1) in vec4 colour;
    layout(location=2) in vec2 uv;
     
    out vec4 fragColour;
    out vec2 fragUV;
     
    layout(binding = 1)uniform mat4 orthoMat;
     
    void main()
    {
        fragColour = colour;
        gl_Position = vec4(orthoMat * vec4(position, 1.0));
        fragUV = vec2(uv.x, 1.0 - uv.y);
    }

    My fragment shader:

    Code glsl:
    #version 450
     
    in vec4 fragColour;
    in vec2 fragUV;
     
    out vec4 colour;
     
    layout(binding = 0) uniform sampler2D diffuse;
     
    void main()
    {
        vec4 textureColour = texture(diffuse, fragUV);
        colour = textureColour * fragColour;
    }
    Last edited by Dark Photon; 01-07-2018 at 12:50 PM.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,031
    Uniforms have locations. Only uniforms of opaque types have bindings.

    So that should be `layout(location = 1) uniform mat4 orthoMat;`.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    18
    So when I use a sampler I should bind it, when it uses a normal uniform it should use the location?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,929
    Quote Originally Posted by geomazzix View Post
    So when I use a sampler I should bind it, when it uses a normal uniform it should use the location?
    The location= qualifier fixes the variable's location, returned by glGetUniformLocation() and passed to glUniform*(). If you don't use it, the location is allocated by the linker. In that case, you must use glGetUniformLocation() to query the location in the application code; if you use location=, you can hard-code the location.

    The binding= qualifier sets the initial value (texture unit index) for sampler uniforms. If you don't use it, you need to set the value in the application code using glUniform1i(). If you set the value via a binding= qualifier, then there's no need to set it in the application code, so you probably don't care about the variable's location.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •