glCompileShader — compile a shader object
void glCompileShader( | GLuint shader) ; |
For implementations that support a shader compiler, glCompileShader
compiles the source code strings that have been stored in the shader object specified by shader
.
The compilation status will be stored as part of the shader object's state. This value will be set to GL_TRUE
if the shader was compiled without errors and is ready for use, and GL_FALSE
otherwise. It can be queried by calling glGetShaderiv with arguments shader
and GL_COMPILE_STATUS
.
Compilation of a shader can fail for a number of reasons as specified by the OpenGL ES Shading Language Specification. Whether or not the compilation was successful, information about the compilation can be obtained from the shader object's information log by calling glGetShaderInfoLog.
Shader compiler support is optional, and thus must be queried before use by calling glGet with argument GL_SHADER_COMPILER
. glShaderSource, glCompileShader
, glGetShaderPrecisionFormat, and glReleaseShaderCompiler will each generate GL_INVALID_OPERATION
on implementations that do not support a shader compiler. Such implementations instead offer the glShaderBinary alternative for supplying a pre-compiled shader binary.
GL_INVALID_OPERATION
is generated if a shader compiler is not supported.
GL_INVALID_VALUE
is generated if shader
is not a value generated by OpenGL.
GL_INVALID_OPERATION
is generated if shader
is not a shader object.
glGet with argument GL_SHADER_COMPILER
glGetShaderInfoLog with argument shader
glGetShaderiv with arguments shader
and GL_COMPILE_STATUS
GLuint vshader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vshader, 1, &vertex_shader_source, NULL); // vertex_shader_source is a GLchar* containing glsl shader source code glCompileShader(vshader); GLint vertex_compiled; glGetShaderiv(vshader, GL_COMPILE_STATUS, &vertex_compiled); if (vertex_compiled != GL_TRUE) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(vshader, 1024, &log_length, message); // Write the error to a log } GLuint fshader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fshader, 1, &fragment_shader_source, NULL); // fragment_shader_source is a GLchar* containing glsl shader source code glCompileShader(fshader); GLint fragment_compiled; glGetShaderiv(fshader, GL_COMPILE_STATUS, &fragment_compiled); if (fragment_compiled != GL_TRUE) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(fshader, 1024, &log_length, message); // Write the error to a log } GLuint program = glCreateProgram(); // This step is unnecessary if you use the location specifier in your shader // e.g. layout (location = 0) in vec3 position; glBindAttribLocation(program, 0, "position"); // The index passed into glBindAttribLocation is glBindAttribLocation(program, 1, "texcoord"); // used by glEnableVertexAttribArray. "position" glBindAttribLocation(program, 2, "normal"); // "texcoord" "normal" and "color" are the names of the glBindAttribLocation(program, 3, "color"); // respective inputs in your fragment shader. glAttachShader(program, vshader); glAttachShader(program, fshader); glLinkProgram(program); GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); if (program_linked != GL_TRUE) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); // Write the error to a log }
open.gl - The Graphics Pipeline
open.gl - Transform Feedback
opengl-tutorial.org - Tutorial 2 : The first triangle
glCreateShader, glLinkProgram, glReleaseShaderCompiler, glShaderSource, glGetShaderPrecisionFormat
Copyright © 2003-2005 3Dlabs Inc. Ltd. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. https://opencontent.org/openpub/.