Example/GLSL Shader Compile Error Testing: Difference between revisions
< Example
m simplifying |
mNo edit summary |
||
Line 20: | Line 20: | ||
glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog); | glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog); | ||
// 'errorLog' now contains information that can e.g. be | // 'errorLog' now contains information that can e.g. be passed to stderr | ||
// Exit with failure. | // Exit with failure. |
Revision as of 22:47, 4 December 2014
Shader compilation error checking.
GLuint shader = glCreateShader(...);
// Get strings for glShaderSource.
glShaderSource(shader, ...);
glCompileShader(shader);
GLint isCompiled;
glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE)
{
GLint maxLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
GLchar errorLog[maxLength];
glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog);
// 'errorLog' now contains information that can e.g. be passed to stderr
// Exit with failure.
glDeleteShader(shader); // Don't leak the shader.
return;
}
// Shader compilation is successful.