GLAPI/glLinkProgram: Difference between revisions
4.0 API. |
m Bot: Adding better formatting. |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
== Function Definition == | == Function Definition == | ||
void '''glLinkProgram'''(GLuint | void '''glLinkProgram'''(GLuint {{param|program}}); | ||
; program | ; program | ||
Line 15: | Line 15: | ||
== Description == | == Description == | ||
'''glLinkProgram''' links the program object specified by | '''glLinkProgram''' links the program object specified by {{param|program}}. If any shader objects of type {{enum|GL_VERTEX_SHADER}} are attached to {{param|program}}, they will be used to create an executable that will run on the programmable vertex processor. If any shader objects of type {{enum|GL_GEOMETRY_SHADER}} are attached to {{param|program}}, they will be used to create an executable that will run on the programmable geometry processor. If any shader objects of type {{enum|GL_FRAGMENT_SHADER}} are attached to {{param|program}}, they will be used to create an executable that will run on the programmable fragment processor. | ||
The status of the link operation will be stored as part of the program object's state. This value will be set to {{ | The status of the link operation will be stored as part of the program object's state. This value will be set to {{enum|GL_TRUE}} if the program object was linked without errors and is ready for use, and {{enum|GL_FALSE}} otherwise. It can be queried by calling {{apifunc|glGetProgram}} with arguments {{param|program}} and {{enum|GL_LINK_STATUS}}. | ||
As a result of a successful link operation, all active user-defined uniform variables belonging to | As a result of a successful link operation, all active user-defined uniform variables belonging to {{param|program}} will be initialized to 0, and each of the program object's active uniform variables will be assigned a location that can be queried by calling {{apifunc|glGetUniformLocation}}. Also, any active user-defined attribute variables that have not been bound to a generic vertex attribute index will be bound to one at this time. | ||
Linking of a program object can fail for a number of reasons as specified in the ''OpenGL Shading Language Specification''. The following lists some of the conditions that will cause a link error. | Linking of a program object can fail for a number of reasons as specified in the ''OpenGL Shading Language Specification''. The following lists some of the conditions that will cause a link error. | ||
Line 39: | Line 39: | ||
* One or more of the attached shader objects has not been successfully compiled. | * One or more of the attached shader objects has not been successfully compiled. | ||
* Binding a generic attribute matrix caused some rows of the matrix to fall outside the allowed maximum of {{ | * Binding a generic attribute matrix caused some rows of the matrix to fall outside the allowed maximum of {{enum|GL_MAX_VERTEX_ATTRIBS}}. | ||
* Not enough contiguous vertex attribute slots could be found to bind attribute matrices. | * Not enough contiguous vertex attribute slots could be found to bind attribute matrices. | ||
Line 51: | Line 51: | ||
* The program object contains objects to form a geometry shader and the input primitive type, output primitive type, or maximum output vertex count is specified differently in multiple geometry shader objects. | * The program object contains objects to form a geometry shader and the input primitive type, output primitive type, or maximum output vertex count is specified differently in multiple geometry shader objects. | ||
* The number of active outputs in the fragment shader is greater than the value of {{ | * The number of active outputs in the fragment shader is greater than the value of {{enum|GL_MAX_DRAW_BUFFERS}}. | ||
* The program has an active output assigned to a location greater than or equal to the value of {{ | * The program has an active output assigned to a location greater than or equal to the value of {{enum|GL_MAX_DUAL_SOURCE_DRAW_BUFFERS}} and has an active output assigned an index greater than or equal to one. | ||
* More than one varying out variable is bound to the same number and index. | * More than one varying out variable is bound to the same number and index. | ||
Line 59: | Line 59: | ||
* The explicit binding assigments do not leave enough space for the linker to automatically assign a location for a varying out array, which requires multiple contiguous locations. | * The explicit binding assigments do not leave enough space for the linker to automatically assign a location for a varying out array, which requires multiple contiguous locations. | ||
* The | * The {{param|count}} specified by {{apifunc|glTransformFeedbackVaryings}} is non-zero, but the program object has no vertex or geometry shader. | ||
* Any variable name specified to | * Any variable name specified to {{apifunc|glTransformFeedbackVaryings}} in the {{param|varyings}} array is not declared as an output in the vertex shader (or the geometry shader, if active). | ||
* Any two entries in the | * Any two entries in the {{param|varyings}} array given {{apifunc|glTransformFeedbackVaryings}} specify the same varying variable. | ||
* The total number of components to capture in any transform feedback varying variable is greater than the constant {{ | * The total number of components to capture in any transform feedback varying variable is greater than the constant {{enum|GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS}} and the buffer mode is {{enum|GL_SEPARATE_ATTRIBS}}. | ||
When a program object has been successfully linked, the program object can be made part of current state by calling | When a program object has been successfully linked, the program object can be made part of current state by calling {{apifunc|glUseProgram}}. Whether or not the link operation was successful, the program object's information log will be overwritten. The information log can be retrieved by calling {{apifunc|glGetProgramInfoLog}}. | ||
'''glLinkProgram''' will also install the generated executables as part of the current rendering state if the link operation was successful and the specified program object is already currently in use as a result of a previous call to | '''glLinkProgram''' will also install the generated executables as part of the current rendering state if the link operation was successful and the specified program object is already currently in use as a result of a previous call to {{apifunc|glUseProgram}}. If the program object currently in use is relinked unsuccessfully, its link status will be set to {{enum|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 | If {{param|program}} contains shader objects of type {{enum|GL_VERTEX_SHADER}}, and optionally of type {{enum|GL_GEOMETRY_SHADER}}, but does not contain shader objects of type {{enum|GL_FRAGMENT_SHADER}}, the vertex shader executable will be installed on the programmable vertex processor, the geometry shader executable, if present, will be installed on the programmable geometry processor, but no executable will be installed on the fragment processor. The results of rasterizing primitives with such a program will be undefined. | ||
The program object's information log is updated and the program is generated at the time of the link operation. After the link operation, applications are free to modify attached shader objects, compile attached shader objects, detach shader objects, delete shader objects, and attach additional shader objects. None of these operations affects the information log or the program that is part of the program object. | The program object's information log is updated and the program is generated at the time of the link operation. After the link operation, applications are free to modify attached shader objects, compile attached shader objects, detach shader objects, delete shader objects, and attach additional shader objects. None of these operations affects the information log or the program that is part of the program object. | ||
Line 77: | Line 77: | ||
== Notes == | == Notes == | ||
If the link operation is unsuccessful, any information about a previous link operation on | If the link operation is unsuccessful, any information about a previous link operation on {{param|program}} is lost (i.e., a failed link does not restore the old state of {{param|program}} ). Certain information can still be retrieved from {{param|program}} even after an unsuccessful link operation. See for instance {{apifunc|glGetActiveAttrib}} and {{apifunc|glGetActiveUniform}}. | ||
== Errors == | == Errors == | ||
{{ | {{enum|GL_INVALID_VALUE}} is generated if {{param|program}} is not a value generated by OpenGL. | ||
{{ | {{enum|GL_INVALID_OPERATION}} is generated if {{param|program}} is not a program object. | ||
{{ | {{enum|GL_INVALID_OPERATION}} is generated if {{param|program}} is the currently active program object and transform feedback mode is active. | ||
== Associated Gets == | == Associated Gets == | ||
{{apifunc|glGet}} with the argument {{enum|GL_CURRENT_PROGRAM}} | |||
{{apifunc|glGetActiveAttrib}} with argument {{param|program}} and the index of an active attribute variable | |||
{{apifunc|glGetActiveUniform}} with argument {{param|program}} and the index of an active uniform variable{{param|}} | |||
{{apifunc|glGetAttachedShaders}} with argument {{param|program}} | |||
{{apifunc|glGetAttribLocation}} with argument {{param|program}} and an attribute variable name | |||
{{apifunc|glGetProgram}} with arguments {{param|program}} and {{enum|GL_LINK_STATUS}} | |||
{{apifunc|glGetProgramInfoLog}} with argument {{param|program}} | |||
{{apifunc|glGetUniform}} with argument {{param|program}} and a uniform variable location | |||
{{apifunc|glGetUniformLocation}} with argument {{param|program}} and a uniform variable name | |||
{{apifunc|glIsProgram}} | |||
== See Also == | == See Also == | ||
{{apifunc|glAttachShader}}, {{apifunc|glBindAttribLocation}}, {{apifunc|glBindFragDataLocation}}, {{apifunc|glBindFragDataLocationIndexed}}, {{apifunc|glCompileShader}}, {{apifunc|glCreateProgram}}, {{apifunc|glCreateShaderProgram}}, {{apifunc|glDeleteProgram}}, {{apifunc|glDetachShader}}, {{apifunc|glProgramBinary}}, {{apifunc|glUniform}}, {{apifunc|glUseProgram}}, {{apifunc|glTransformFeedbackVaryings}}, {{apifunc|glValidateProgram}} | |||
== Copyright == | == Copyright == | ||
Line 117: | Line 117: | ||
Copyright © 2003-2005 3Dlabs Inc. Ltd. Copyright © 2010 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. [http://opencontent.org/openpub/ http://opencontent.org/openpub/]. | Copyright © 2003-2005 3Dlabs Inc. Ltd. Copyright © 2010 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. [http://opencontent.org/openpub/ http://opencontent.org/openpub/]. | ||
[[Category:API Reference | [[Category:Core API Reference|LinkProgram]] | ||
[[Category:Core API Ref Shader Program Creation|LinkProgram]] | |||
[[Category:Program Object API State Functions|LinkProgram]] |
Latest revision as of 10:02, 15 August 2013
Core in version | 4.6 | |
---|---|---|
Core since version | 2.0 |
glLinkProgram: Links a program object
Function Definition
void glLinkProgram(GLuint program);
- program
- Specifies the handle of the program object to be linked.
Description
glLinkProgram links the program object specified by program. If any shader objects of type GL_VERTEX_SHADER are attached to program, they will be used to create an executable that will run on the programmable vertex processor. If any shader objects of type GL_GEOMETRY_SHADER are attached to program, they will be used to create an executable that will run on the programmable geometry processor. If any shader objects of type GL_FRAGMENT_SHADER are attached to program, they will be used to create an executable that will run on the programmable fragment processor.
The status of the link operation will be stored as part of the program object's state. This value will be set to GL_TRUE if the program object was linked without errors and is ready for use, and GL_FALSE otherwise. It can be queried by calling glGetProgram with arguments program and GL_LINK_STATUS.
As a result of a successful link operation, all active user-defined uniform variables belonging to program will be initialized to 0, and each of the program object's active uniform variables will be assigned a location that can be queried by calling glGetUniformLocation. Also, any active user-defined attribute variables that have not been bound to a generic vertex attribute index will be bound to one at this time.
Linking of a program object can fail for a number of reasons as specified in the OpenGL Shading Language Specification. The following lists some of the conditions that will cause a link error.
- The number of active attribute variables supported by the implementation has been exceeded.
- The storage limit for uniform variables has been exceeded.
- The number of active uniform variables supported by the implementation has been exceeded.
- The main function is missing for the vertex, geometry or fragment shader.
- A varying variable actually used in the fragment shader is not declared in the same way (or is not declared at all) in the vertex shader, or geometry shader shader if present.
- A reference to a function or variable name is unresolved.
- A shared global is declared with two different types or two different initial values.
- One or more of the attached shader objects has not been successfully compiled.
- Binding a generic attribute matrix caused some rows of the matrix to fall outside the allowed maximum of GL_MAX_VERTEX_ATTRIBS.
- Not enough contiguous vertex attribute slots could be found to bind attribute matrices.
- The program object contains objects to form a fragment shader but does not contain objects to form a vertex shader.
- The program object contains objects to form a geometry shader but does not contain objects to form a vertex shader.
- The program object contains objects to form a geometry shader and the input primitive type, output primitive type, or maximum output vertex count is not specified in any compiled geometry shader object.
- The program object contains objects to form a geometry shader and the input primitive type, output primitive type, or maximum output vertex count is specified differently in multiple geometry shader objects.
- The number of active outputs in the fragment shader is greater than the value of GL_MAX_DRAW_BUFFERS.
- The program has an active output assigned to a location greater than or equal to the value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS and has an active output assigned an index greater than or equal to one.
- More than one varying out variable is bound to the same number and index.
- The explicit binding assigments do not leave enough space for the linker to automatically assign a location for a varying out array, which requires multiple contiguous locations.
- The count specified by glTransformFeedbackVaryings is non-zero, but the program object has no vertex or geometry shader.
- Any variable name specified to glTransformFeedbackVaryings in the varyings array is not declared as an output in the vertex shader (or the geometry shader, if active).
- Any two entries in the varyings array given glTransformFeedbackVaryings specify the same varying variable.
- The total number of components to capture in any transform feedback varying variable is greater than the constant GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS and the buffer mode is GL_SEPARATE_ATTRIBS.
When a program object has been successfully linked, the program object can be made part of current state by calling glUseProgram. Whether or not the link operation was successful, the program object's information log will be overwritten. The information log can be retrieved by calling glGetProgramInfoLog.
glLinkProgram will also install the generated executables as part of the current rendering state if the link operation was successful and the specified program object is already currently in use as a result of a previous call to glUseProgram. 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 contains shader objects of type GL_VERTEX_SHADER, and optionally of type GL_GEOMETRY_SHADER, but does not contain shader objects of type GL_FRAGMENT_SHADER, the vertex shader executable will be installed on the programmable vertex processor, the geometry shader executable, if present, will be installed on the programmable geometry processor, but no executable will be installed on the fragment processor. The results of rasterizing primitives with such a program will be undefined.
The program object's information log is updated and the program is generated at the time of the link operation. After the link operation, applications are free to modify attached shader objects, compile attached shader objects, detach shader objects, delete shader objects, and attach additional shader objects. None of these operations affects the information log or the program that is part of the program object.
Notes
If the link operation is unsuccessful, any information about a previous link operation on program is lost (i.e., a failed link does not restore the old state of program ). Certain information can still be retrieved from program even after an unsuccessful link operation. See for instance glGetActiveAttrib and glGetActiveUniform.
Errors
GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.
GL_INVALID_OPERATION is generated if program is not a program object.
GL_INVALID_OPERATION is generated if program is the currently active program object and transform feedback mode is active.
Associated Gets
glGet with the argument GL_CURRENT_PROGRAM
glGetActiveAttrib with argument program and the index of an active attribute variable
glGetActiveUniform with argument program and the index of an active uniform variable
glGetAttachedShaders with argument program
glGetAttribLocation with argument program and an attribute variable name
glGetProgram with arguments program and GL_LINK_STATUS
glGetProgramInfoLog with argument program
glGetUniform with argument program and a uniform variable location
glGetUniformLocation with argument program and a uniform variable name
See Also
glAttachShader, glBindAttribLocation, glBindFragDataLocation, glBindFragDataLocationIndexed, glCompileShader, glCreateProgram, glCreateShaderProgram, glDeleteProgram, glDetachShader, glProgramBinary, glUniform, glUseProgram, glTransformFeedbackVaryings, glValidateProgram
Copyright
Copyright © 2003-2005 3Dlabs Inc. Ltd. Copyright © 2010 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.