Shaders & programsGL 2.0
glGetShaderiv
Queries a property of a shader — mainly whether it compiled.
Part of the family glGet*
Signature
void glGetShaderiv(GLuint shader, GLenum pname, GLint *params);
How it works
glCompileShader never reports failure by itself: it returns nothing, and a shader that did not compile just makes the later link fail. So right after compiling, ask with GL_COMPILE_STATUS. If it is GL_FALSE, ask for GL_INFO_LOG_LENGTH and read the message with glGetShaderInfoLog; it names the line and the mistake.
Skipping this check is the most common reason for a black screen with no error anywhere.
Parameters
shaderGLuint
Shader to query.
pnameGLenum
Which property.
Common values
- GL_COMPILE_STATUS
- GL_TRUE if the last compile succeeded.
- GL_INFO_LOG_LENGTH
- Size of the compile log, including the null terminator.
- GL_SHADER_TYPE
- The stage given to glCreateShader.
- GL_DELETE_STATUS
- GL_TRUE if flagged for deletion.
paramsGLint *
Where the result is written.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_OPERATION
- shader is a program ID, not a shader.
Example
example.cpp
1GLint len = 0;
2glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
3std::string log(len, '\0');
4glGetShaderInfoLog(shader, len, nullptr, log.data());