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

Thread: debugging shader with no errors

  1. #1
    Member Regular Contributor strattonbrazil's Avatar
    Join Date
    Jun 2007
    Location
    Los Angeles, CA
    Posts
    306

    debugging shader with no errors

    I have setup the usual code for setting up a GLSL program, but after error checking and not getting errors, glUseProgram doesn't change the program. I'm wondering if the glGetShaderInfoLog and glGetProgramInfoLog don't turn up any errors after being setup, what else can you debug to see why glUseProgram doesn't start the program?

    Here's my setup code:

    Code :
      const GLsizei maxLength = 1000;
      GLsizei log_length;
      GLchar log[maxLength];
     
      // allocate the shaders
      GLuint v = glCreateShader(GL_VERTEX_SHADER);
      GLuint f = glCreateShader(GL_FRAGMENT_SHADER);
      GLint length[1];
      const GLchar* source[1];
     
      // create vertex shader
      source[0] = v_source;
      length[0] = strlen(source[0]);
      glShaderSource(v, 1, source, length);
      glCompileShader(v);
     
      // check vertex compilation
      glGetShaderInfoLog(v, maxLength, &log_length, log);
      std::cout << log;
     
      // create fragment shader
      source[0] = f_source;
      length[0] = strlen(source[0]);
      glShaderSource(f, 1, source, length);
      glCompileShader(f);
     
      // check fragment compilation
      glGetShaderInfoLog(f, maxLength, &amp;log_length, log);
      std::cout << log;
     
      program = glCreateProgram();
      glAttachShader(program, v);
      glAttachShader(program, f);
      glLinkProgram(program);
     
      glGetProgramInfoLog(program, maxLength, &amp;log_length, log);
      std::cout << log;
     
      glValidateProgram(program);
     
      glGetProgramInfoLog(program, maxLength, &amp;log_length, log);
      std::cout << log;
     
      cout << "Created program" << endl;

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: debugging shader with no errors

    At the very least you should probably check the link status after linking your program (GetProgramiv with LINK_STATUS), and for good measure a compile status check wouldn't hurt (GetShaderiv with COMPILE_STATUS).

    P.S. Wouldn't hardcode that array length if I were you! ;-) (Look at GetShaderiv/GetProgramiv with INFO_LOG_LENGTH.)

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: debugging shader with no errors

    ...

    The spec.

    The spec on info logs

    If shader is a shader object, the returned info log will either be an empty string
    or it will contain information about the last compilation attempt for that object. If
    program is a program object, the returned info log will either be an empty string or
    it will contain information about the last link attempt or last validation attempt for
    that object.
    The info log is typically only useful during application development and an
    application should not expect different GL implementations to produce identical
    info logs.
    Each program object has an information log that is overwritten as a result of a
    link operation. This information log can be queried with GetProgramInfoLog to
    obtain more information about the link operation or the validation information.
    So error information isn't strictly required to be written to the logs (though in practice it usually is).

  4. #4
    Intern Contributor IneQuation.pl's Avatar
    Join Date
    Aug 2008
    Location
    Gliwice, Poland
    Posts
    69

    Re: debugging shader with no errors

    Yes, but some errors can just cause the surfaces not to be rendered, or rendered improperly without even a hint in the info log.

    Try glslDevil.

  5. #5
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: debugging shader with no errors

    glslDevil is quite nice. i use RenderMonkey once in a while because it supports GLSL, compiling and checking shaders right away and has a somewhat pretty interface. Pretty good tool for developing and testing shaders.

Posting Permissions

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