Example/GLSL Shader Compile Error Testing: Difference between revisions
< Example
categorization |
Using bad coding style (ie: not initializing variables) is NOT simplifying. |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
GLuint shader = glCreateShader(...); | GLuint shader = glCreateShader(...); | ||
//Get strings for glShaderSource. | // Get strings for glShaderSource. | ||
glShaderSource(shader, ...); | glShaderSource(shader, ...); | ||
Line 16: | Line 16: | ||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); | ||
//The maxLength includes the NULL character | // The maxLength includes the NULL character | ||
std::vector< | std::vector<GLchar> errorLog(maxLength); | ||
glGetShaderInfoLog( | glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]); | ||
//Provide the infolog in whatever manor you deem best. | // Provide the infolog in whatever manor you deem best. | ||
//Exit with failure. | // Exit with failure. | ||
glDeleteShader(shader); // Don't leak the shader. | |||
return; | return; | ||
} | } | ||
//Shader compilation is successful. | // Shader compilation is successful. | ||
</source> | </source> | ||
<noinclude>[[Category:Example Code]]</noinclude> | <noinclude>[[Category:Example Code]]</noinclude> |
Latest revision as of 14:21, 6 December 2014
Shader compilation error checking.
GLuint shader = glCreateShader(...);
// Get strings for glShaderSource.
glShaderSource(shader, ...);
glCompileShader(shader);
GLint isCompiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE)
{
GLint maxLength = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<GLchar> errorLog(maxLength);
glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]);
// Provide the infolog in whatever manor you deem best.
// Exit with failure.
glDeleteShader(shader); // Don't leak the shader.
return;
}
// Shader compilation is successful.