Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

After compiling a shader with glCompileShader, I can call glGetShaderiv with GL_COMPILE_STATUS to check if the shader compiled successfully. I can also call glGetShaderInfoLog to get information about possible errors, warnings or other info. The information log returned by this function is unspecified.

In a tool where users can write their own shaders, I would like to print all errors and warnings from the compilation, but nothing if no warnings or errors were found. The problem is that the GL_COMPILE_STATUS returns only false if the compilation failed and true otherwise. If no problems were found, some drivers return empty info log from glGetShaderInfoLog, but some drivers can return something else such as "No errors.", which I do not want to print to the user. How is this problem generally solved?

share|improve this question
    
Have you thought of checking the output of the compilation for the words "error" or "warning"? If there isn't any, than you don't print it, but if there is a warning, usually the output is " ([line_number]) : warning [warning_code] : [description]" –  Makers_F Mar 3 '13 at 16:05
    
Seems like all solutions are just variations of parsing the log and matching for known strings. I ended up checking for "shader was successfully compiled to run on hardware", which is the output from AMD drivers. Perhaps your idea would be more generic. –  msell Mar 3 '13 at 20:25

1 Answer 1

up vote 7 down vote accepted

Well, the way I solve it is by always fetching the log (even if none is available) and after that check for success.

    glGetShaderiv(m_HandleVertex, GL_INFO_LOG_LENGTH, &bufflen);
    if (bufflen > 1)
    {
        GLchar* log_string = new char[bufflen + 1];
        glGetShaderInfoLog(m_HandleVertex, bufflen, 0, log_string);
        LOG_TRACE("Log found for '%s.vert':\n%s", m_Name.GetData(), log_string);

        delete log_string;
    }

    glGetShaderiv(m_HandleVertex, GL_COMPILE_STATUS, &success);
    if (success != GL_TRUE)
    { 
        LOG_ERROR("Failed to compile vertex shader.");
        return false; 
    }

I did it this way because you might otherwise miss the warnings a shader returns. If a shader has warnings, but no errors, success will be true so you won't print the log, but warnings can also give you a clue as to why a shader fails to behave the way you want it.

share|improve this answer
    
The problem is that some drivers return non-empty info log even when there are neither errors nor warnings. Those I don't want to log. –  msell Jun 11 '12 at 9:59
1  
It's driver-specific, which is a problem. I resolved it by checking if (strcmp(log_string, "No errors.")) but that's just for NVIDIA's drivers. Unless you want to add similar checks for all other drivers (NVIDIA, AMD, ATI, Intel, Windows, Mac, Linux) I'd say: learn to live with it. –  knight666 Jun 11 '12 at 10:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.