'''glUseProgram''' installs the program object specified by ''program'' as part of current rendering state. One or more executables are created in a program object by successfully attaching shader objects to it with [[GLAPI/glAttachShader|glAttachShader]], successfully compiling the shader objects with [[GLAPI/glCompileShader|glCompileShader]], and successfully linking the program object with [[GLAPI/glLinkProgram|glLinkProgram]].

+

'''glUseProgram''' installs the program object specified by {{param|program}} as part of current rendering state. One or more executables are created in a program object by successfully attaching shader objects to it with {{apifunc|glAttachShader}}, successfully compiling the shader objects with {{apifunc|glCompileShader}}, and successfully linking the program object with {{apifunc|glLinkProgram}}.

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

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

−

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 will affect the executables that are part of the current state. However, relinking the program object that is currently in use will install the program object as part of the current rendering state if the link operation was successful (see [[GLAPI/glLinkProgram|glLinkProgram]] ). If the program object currently in use is relinked unsuccessfully, its link status will be set to {{code|GL_FALSE}}, but the executables and associated state will remain part of the current state until a subsequent call to '''glUseProgram''' removes it from use. After it is removed from use, it cannot be made part of current state until it has been successfully relinked.

+

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 will affect the executables that are part of the current state. However, relinking the program object that is currently in use will install the program object as part of the current rendering state if the link operation was successful (see {{apifunc|glLinkProgram}} ). If the program object currently in use is relinked unsuccessfully, its link status will be set to {{code|GL_FALSE}}, but the executables and associated state will remain part of the current state until a subsequent call to '''glUseProgram''' removes it from use. After it is removed from use, it cannot be made part of current state until it has been successfully relinked.

−

If ''program'' is zero, then the current rendering state refers to an ''invalid'' program object and the results of shader execution are undefined. However, this is not an error.

+

If {{param|program}} is zero, then the current rendering state refers to an ''invalid'' program object and the results of shader execution are undefined. However, this is not an error.

−

If ''program'' does not contain shader objects of type {{code|GL_FRAGMENT_SHADER}}, an executable will be installed on the vertex, and possibly geometry processors, but the results of fragment shader execution will be undefined.

+

If {{param|program}} does not contain shader objects of type {{code|GL_FRAGMENT_SHADER}}, an executable will be installed on the vertex, and possibly geometry processors, but the results of fragment shader execution will be undefined.

== Notes ==

== Notes ==

Line 33:

Line 33:

== Errors ==

== Errors ==

−

{{code|GL_INVALID_VALUE}} is generated if ''program'' is neither 0 nor a value generated by OpenGL.

+

{{code|GL_INVALID_VALUE}} is generated if {{param|program}} is neither 0 nor a value generated by OpenGL.

−

{{code|GL_INVALID_OPERATION}} is generated if ''program'' is not a program object.

+

{{code|GL_INVALID_OPERATION}} is generated if {{param|program}} is not a program object.

−

{{code|GL_INVALID_OPERATION}} is generated if ''program'' could not be made part of current state.

+

{{code|GL_INVALID_OPERATION}} is generated if {{param|program}} could not be made part of current state.

{{code|GL_INVALID_OPERATION}} is generated if transform feedback mode is active.

{{code|GL_INVALID_OPERATION}} is generated if transform feedback mode is active.

Line 43:

Line 43:

== Associated Gets ==

== Associated Gets ==

−

[[GLAPI/glGet|glGet]] with the argument {{code|GL_CURRENT_PROGRAM}}

+

{{apifunc|glGet}} with the argument {{code|GL_CURRENT_PROGRAM}}

−

[[GLAPI/glGetActiveAttrib|glGetActiveAttrib]] with a valid program object and the index of an active attribute variable

+

{{apifunc|glGetActiveAttrib}} with a valid program object and the index of an active attribute variable

−

[[GLAPI/glGetActiveUniform|glGetActiveUniform]] with a valid program object and the index of an active uniform variable

+

{{apifunc|glGetActiveUniform}} with a valid program object and the index of an active uniform variable

−

[[GLAPI/glGetAttachedShaders|glGetAttachedShaders]] with a valid program object

+

{{apifunc|glGetAttachedShaders}} with a valid program object

−

[[GLAPI/glGetAttribLocation|glGetAttribLocation]] with a valid program object and the name of an attribute variable

+

{{apifunc|glGetAttribLocation}} with a valid program object and the name of an attribute variable

−

[[GLAPI/glGetProgram|glGetProgram]] with a valid program object and the parameter to be queried

+

{{apifunc|glGetProgram}} with a valid program object and the parameter to be queried

−

[[GLAPI/glGetProgramInfoLog|glGetProgramInfoLog]] with a valid program object

+

{{apifunc|glGetProgramInfoLog}} with a valid program object

−

[[GLAPI/glGetUniform|glGetUniform]] with a valid program object and the location of a uniform variable

+

{{apifunc|glGetUniform}} with a valid program object and the location of a uniform variable

−

[[GLAPI/glGetUniformLocation|glGetUniformLocation]] with a valid program object and the name of a uniform variable

+

{{apifunc|glGetUniformLocation}} with a valid program object and the name of a uniform variable

Contents

Function Definition

void glUseProgram(GLuint program​);

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. One or more executables are created in a program object by 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 will contain 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. A program object will contain an executable that will run on the geometry processor if it contains one or more shader objects of type GL_GEOMETRY_SHADER​ that have been successfully compiled and linked. Similarly, a program object will contain 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.

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 will affect the executables that are part of the current state. However, relinking the program object that is currently in use will install 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 will be set to GL_FALSE​, but the executables and associated state will remain part of the current state until a subsequent call to glUseProgram removes it from use. After it is removed from use, it cannot be made part of current state until it has been successfully relinked.

If program​ is zero, then the current rendering state refers to an invalid program object and the results of shader execution are undefined. However, this is not an error.

If program​ does not contain shader objects of type GL_FRAGMENT_SHADER​, an executable will be installed on the vertex, and possibly geometry processors, but the results of fragment shader execution will be undefined.

Notes

Like buffer 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 providing the synchronization 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 transform feedback mode is active.