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: GLSL program fails to link without errors

  1. #1
    Newbie Newbie
    Join Date
    Oct 2018
    Posts
    1

    GLSL program fails to link without errors

    Hi all,

    I'm trying to use a Geometry shader.
    My OpenGL program is compossed by this 3 shaders:

    Code :
    //#shader vertex
    #version 330 core
    layout(location=0) in vec4 position;
    layout(location=1) in float type;
     
    uniform vec4 u_colors[4];
    out vec4 fragmentColor;
    uniform mat4 u_view;
    uniform mat4 u_model;
    uniform mat4 u_proj;
    void main() {
        gl_Position = u_proj * u_view * u_model * position;
        fragmentColor = u_colors[int(type)];
    }
     
    //#shader fragment
    #version 330 core
    in vec4 fragmentColor;
    out vec4 color;
    void main() {
        color = fragmentColor;
    }
     
    //#shader geometry
    #version 330
    layout (lines) in;
    layout (line_strip, max_vertices = 2) out;
    in vec4 vFragColorVs[2];
    out vec4 vFragColor;
    void main(void) {
         int i;
         for ( i=0; i < gl_in.length(); i++) {
              vFragColor = vFragColorVs[i];
              gl_Position = gl_in[i].gl_Position;
              EmitVertex();
         }
         EndPrimitive();
    }

    When I try to compile it there are no compilation errors.
    Thats the code that I use to link:

    Code :
    glLinkProgram(rendererID);
     
        GLint isLinked = 0;
        glGetProgramiv(rendererID, GL_LINK_STATUS, &isLinked);
        if (isLinked == GL_FALSE)
        {
            int length;
            std::string log;
            glGetProgramiv(rendererID, GL_INFO_LOG_LENGTH, &length);
            log.reserve(static_cast<unsigned long>(length));
            glGetProgramInfoLog(rendererID, length, &length, &log[0]);
     
            // The program is useless now. So delete it.
            glDeleteProgram(rendererID);
            std::cerr << "cannot Link: " << log << std::endl;
            throw std::runtime_error("cannot link opengl program");
        }

    The output is only cannot link: without a log message.
    The program without the Geometry shader links and works well.

    Where is the mistake?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,569
    I believe what you're doing with trying to reading the link log into a std::string isn't portable.

    Try this: Shader_Compilation#Error_handling. That is, read it into a vector of chars, or into a raw char array.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,007
    Quote Originally Posted by NoeMurr View Post
    Code :
            std::string log;
            glGetProgramiv(rendererID, GL_INFO_LOG_LENGTH, &length);
            log.reserve(static_cast<unsigned long>(length));
            glGetProgramInfoLog(rendererID, length, &length, &log[0]);
    string::reserve() only reserves space; the length will still be zero. Use e.g.
    Code :
    log.assign(length, '\0');
    to enlarge the string. Or just create the string at the appropriate size:
    Code :
    std::string log(length, '\0');
    Note that a vector has essentially the same issue; vector::reserve() will only reserve space, it won't change the length.

  4. #4
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Oxford, England
    Posts
    472
    The fragmentColor is the issue. You need to pass the colour from the vertex shader, to the geom shader, and out to the fragment shader. e.g.

    // in vertex shader:
    out vec4 gs_fragmentColor;

    // in geom shader:
    in vec4 gs_fragmentColor[];
    out vec4 fs_fragmentColor;

    // in frag shader:
    in vec4 fs_fragmentColor;


    Currently you're assuming
    fragmentColor will go directly from the vertex shader to the fragment shader (it won't!), and the vFragColorVs/vFragColor vars in your geom shader don't match the vertex/fragment shader inputs/outputs.

Posting Permissions

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