# How to detect GLSL warnings?

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?

• 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

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;
}


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.
• 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