GLSL:Can't get location after set layout of uniforms

0

This is my vertex shader and fragment shader:

    static const char skybox_shader_vs[] =
        "#version 330 core\n"
        "\n"
        "layout (location = 0) in vec3 in_position;\n"
        "layout (location = 3) in vec2 in_texcoord;\n"
        "\n"
        "out vec2 tex_coord;\n"
        "\n"
        "uniform mat4 tc_rotate;\n"
        "\n"
        "void main(void)\n"
        "{\n"
        "    gl_Position = tc_rotate * vec4(in_position, 1.0);\n"
        "    tex_coord = in_texcoord;\n"
        "}\n"
    ;
----------------------------------------------------------------------
    static const char skybox_shader_fs[] =
        "#version 330 core\n"
        "\n"
        "in vec2 tex_coord;\n"
        "\n"
        "layout (location = 0) out vec4 color;\n"
        "\n"
        "uniform sampler2D tex;\n"
        "uniform float lod;\n"
        "\n"
        "void main(void)\n"
        "{\n"
        "    color = textureLod(tex, tex_coord,lod);\n"
        "}\n"
    ;

After link and use program successfully,I can get location of any uniforms:

    GLint location = glGetUniformLocation(mipmap_prog, "lod");
    glUniform1f(location, 1);

but when I set location of uniforms like this:

    static const char skybox_shader_fs[] =
        "#version 330 core\n"
        "\n"
        "in vec2 tex_coord;\n"
        "\n"
        "layout (location = 0) out vec4 color;\n"
        "\n"
        "uniform sampler2D tex;\n"
        "layout (location = 4)uniform float lod;\n"
        "\n"
        "void main(void)\n"
        "{\n"
        "    color = textureLod(tex, tex_coord,lod);\n"
        "}\n"
    ;

value of lacation is 0xffffffff,where is my mistake?

opengl
glsl
asked on Stack Overflow Apr 26, 2020 by Chris

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0