JavaScript EditorFree JavaScript Editor     Ajax Editor 



Main Page
Previous Page
Next Page

glUseProgram

Name

glUseProgram Installs a program object as part of current rendering state

C Specification

void glUseProgram(GLuint program)

Parameters

program

Specifies the handle of the program object                                                whose executables are to be used as part of 
                                               current rendering state.


Description

glUseProgram installs the program object specified by program as part of current rendering state. Creating one or more executables in a program object involves successfully attaching shader objects to it with glAttachShader, successfully compiling the shader objects with glCompileShader, and successfully linking the program object with glLinkProgram.

A program object contains an executable that will run on the vertex processor if it contains one or more shader objects of type GL_VERTEX_SHADER that have been successfully compiled and linked. Similarly, a program object contains an executable that will run on the fragment processor if it contains one or more shader objects of type GL_FRAGMENT_SHADER that have been successfully compiled and linked.

Successfully installing an executable on a programmable processor disables the corresponding fixed functionality of OpenGL. Specifically, if an executable is installed on the vertex processor, the OpenGL fixed functionality is disabled as follows.

  • The modelview matrix is not applied to vertex coordinates.

  • The projection matrix is not applied to vertex coordinates.

  • The texture matrices are not applied to texture coordinates.

  • Normals are not transformed to eye coordinates.

  • Normals are not rescaled or normalized.

  • Normalization of GL_AUTO_NORMAL evaluated normals is not performed.

  • Texture coordinates are not generated automatically.

  • Per-vertex lighting is not performed.

  • Color material computations are not performed.

  • Color index lighting is not performed.

This list also applies to setting the current raster position.

The executable that is installed on the vertex processor is expected to implement any or all of the desired functionality from the preceding list. Similarly, if an executable is installed on the fragment processor, the OpenGL fixed functionality is disabled as follows.

  • Texture environment and texture functions are not applied.

  • Texture application is not applied.

  • Color sum is not applied.

  • Fog is not applied.

Again, the fragment shader that is installed is expected to implement any or all of the desired functionality from the preceding list.

While a program object is in use, applications are free to modify attached shader objects, compile attached shader objects, attach additional shader objects, and detach or delete shader objects. None of these operations affect the executables that are part of the current state. However, relinking the program object that is currently in use installs the program object as part of the current rendering state if the link operation was successful (see glLinkProgram). If the program object currently in use is relinked unsuccessfully, its link status is set to GL_FALSE but the executables and associated state remain part of the current state until a subsequent call to glUseProgram removes the program object from use. After it is removed from use, it cannot be made part of current state until it has been successfully relinked.

If program contains shader objects of type GL_VERTEX_SHADER but does not contain shader objects of type GL_FRAGMENT_SHADER, an executable is installed on the vertex processor but fixed functionality is used for fragment processing. Similarly, if program contains shader objects of type GL_FRAGMENT_SHADER but does not contain shader objects of type GL_VERTEX_SHADER, an executable is installed on the fragment processor but fixed functionality is used for vertex processing. If program is 0, the programmable processors are disabled and fixed functionality is used for both vertex and fragment processing.

Notes

glUseProgram is available only if the GL version is 2.0 or greater.

While a program object is in use, the state that controls the disabled fixed functionality may also be updated with the normal OpenGL calls.

Like display lists and texture objects, the name space for program objects may be shared across a set of contexts, as long as the server sides of the contexts share the same address space. If the name space is shared across contexts, any attached objects and the data associated with those attached objects are shared as well.

Applications are responsible for synchronizing across API calls when objects are accessed from different execution threads.

Errors

GL_INVALID_VALUE is generated if program is neither 0 nor a value generated by OpenGL.

GL_INVALID_OPERATION is generated if program is not a program object.

GL_INVALID_OPERATION is generated if program could not be made part of current state.

GL_INVALID_OPERATION is generated if glUseProgram is executed between the execution of glBegin and the corresponding execution of glEnd.

Associated Gets

glGet with the argument GL_CURRENT_PROGRAM

glGetActiveAttrib with a valid program object and the index of an active attribute variable

glGetActiveUniform with a valid program object and the index of an active uniform variable

glGetAttachedShaders with a valid program object

glGetAttribLocation with a valid program object and the name of an attribute variable

glGetProgram with a valid program object and the parameter to be queried

glGetProgramInfoLog with a valid program object

glGetUniform with a valid program object and the location of a uniform variable

glGetUniformLocation with a valid program object and the name of a uniform variable

glIsProgram

See Also

gllAttachShader, glBindAttribLocation, glCompileShader, glCreateProgram,glDeleteProgram, glDetachShader, glLinkProgram, glUniform, glValidateProgram, glVertexAttrib


Previous Page
Next Page




JavaScript EditorAjax Editor     JavaScript Editor