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 3 of 3

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,511
    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
    2,955
    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.

Posting Permissions

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