JavaScript EditorFree JavaScript Editor     Ajax Editor 

Main Page
Previous Page
Next Page

7.3. Compiling Shader Objects

After the source code strings have been loaded into a shader object, the source code must be compiled to check its validity. The result of compilation remains as part of the shader object until another compilation operation occurs or until the shader object itself is deleted. The command to compile a shader object is

void glCompileShader(GLuint shader)

Compiles the source code strings that have been stored in the shader object specified by shader.

The compilation status is stored as part of the shader object's state. This value is 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 glGetShader with arguments shader and GL_COMPILE_STATUS.

A shader will fail to compile if it is lexically, grammatically, or semantically incorrect. Whether or not the compilation was successful, information about the compilation can be obtained from the shader object's information log with glGetShaderInfoLog.

The OpenGL Shading Language has compilation rules that are slightly different depending on the type of shader being compiled, and so the compilation takes into consideration whether the shader is a vertex shader or a fragment shader.

Information about the compile operation can be obtained by calling glGetShaderInfoLog (described in Section 7.6) with shader, but the information log should not be used as an indication of whether the compilation was successful. If the shader object was compiled successfully, either the information log is an empty string or it contains information about the compile operation. If the shader object was not compiled successfully, the information log contains information about any lexical, grammatical, or semantic errors that occurred, along with warning messages and any other information the compiler deems pertinent.

Previous Page
Next Page

JavaScript EditorAjax Editor     JavaScript Editor