• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Name
2
3    ARB_explicit_attrib_location
4
5Name Strings
6
7    GL_ARB_explicit_attrib_location
8
9Contact
10
11    Ian Romanick, Intel (ian.d.romanick 'at' intel.com)
12
13Notice
14
15    Copyright (c) 2010-2013 The Khronos Group Inc. Copyright terms at
16        http://www.khronos.org/registry/speccopyright.html
17
18Specification Update Policy
19
20    Khronos-approved extension specifications are updated in response to
21    issues and bugs prioritized by the Khronos OpenGL Working Group. For
22    extensions which have been promoted to a core Specification, fixes will
23    first appear in the latest version of that core Specification, and will
24    eventually be backported to the extension document. This policy is
25    described in more detail at
26        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
27
28Status
29
30    Complete. Approved by the ARB at the 2010/01/22 F2F meeting.
31    Approved by the Khronos Board of Promoters on March 10, 2010.
32
33Version
34
35    Last Modified Date:         August 1, 2011
36    Revision:                   12
37
38Number
39
40    ARB Extension #79
41
42Dependencies
43
44    Requires OpenGL 2.0 or GL_ARB_vertex_shader.
45
46    This extension interacts with GL_ARB_blend_func_extended.
47
48    This extension is written against the OpenGL 3.2 (Core Profile)
49    specification dated 7/24/2009 and the OpenGL Shading Language 1.50.09
50    specification dated 7/24/2009.
51
52    This extension interacts with GL_ARB_separate_shader_objects,
53    GL_ARB_gpu_shader_fp64, OpenGL 4.0, and OpenGL 4.1.
54
55Overview
56
57    This extension provides a method to pre-assign attribute locations to
58    named vertex shader inputs and color numbers to named fragment shader
59    outputs.  This allows applications to globally assign a particular
60    semantic meaning, such as diffuse color or vertex normal, to a particular
61    attribute location without knowing how that attribute will be named in any
62    particular shader.
63
64IP Status
65
66    No known IP claims.
67
68New Procedures and Functions
69
70    None
71
72New Tokens
73
74    None
75
76Additions to Chapter 2 of the OpenGL 3.2 Specification (OpenGL Operation)
77
78    Section 2.11.3 "Vertex Attributes":
79
80    Modify the seventh paragraph on page 53 to read:
81
82    "When a program is linked, any active attributes without a binding
83    specified either through BindAttribLocation or explicitly set
84    within the shader text will be automatically be bound to vertex
85    attributes by the GL. ...  LinkProgram will fail if the attribute
86    bindings assigned by BindAttribLocation do not leave not enough space
87    to assign a location for an active matrix attribute or an active
88    attribute array, both of which require multiple contiguous generic
89    attributes.  If an active attribute has a binding explicitly set within
90    the shader text and a different binding assigned by BindAttribLocation,
91    the assignment in the shader text is used."
92
93Additions to Chapter 3 of the OpenGL 3.2 Specification (Rasterization)
94
95    Section 3.9.2 "Shader Execution", subsection "Shader Outputs":
96
97    Replace the fourth paragraph of page 183:
98
99    When a program is linked, any varying out variables without a binding
100    specified through BindFragDataLocationIndexed, BindFragDataLocation, or
101    explicitly set within the shader text will automatically be bound to
102    fragment colors and indices by the GL.  All such assignments will use
103    color indices of zero.  Such bindings can be queried using the commands
104    GetFragDataLocation and GetFragDataIndex.  If a varying out variable has a
105    binding explicitly set within the shader text and a different binding
106    assigned by BindFragDataLocationIndexed or BindFragDataLocation, the
107    assignment in the shader text is used.  Output binding assignments will
108    cause LinkProgram to fail:
109
110      * if the number of active outputs is greater than the value of
111        MAX_DRAW_BUFFERS;
112
113      * if the program has an active output assigned to a location greater
114        than or equal to the value of MAX_DUAL_SOURCE_DRAW_BUFFERS and has an
115        active output assigned an index greater than or equal to one;
116
117      * if more than one varying out variable is bound to the same number and
118        index; or
119
120      * if the explicit binding assigments do not leave enough space for the
121        linker to automatically assign a location for a varying out array,
122        which requires multiple contiguous locations.
123
124
125Additions to Chapter 4 of the OpenGL 3.2 Specification (Per-Fragment
126Operations and the Framebuffer)
127
128    None.
129
130Additions to Chapter 5 of the OpenGL 3.2 Specification (Special Functions)
131
132    None.
133
134Additions to Chapter 6 of the OpenGL 3.2 Specification (State and State
135Request)
136
137    None.
138
139Additions to Appendix A of the OpenGL 3.2 Specification (Invariance)
140
141    None.
142
143Additions to Appendix B of the OpenGL 3.2 Specification (Corollaries)
144
145    None.
146
147Additions to Appendix C of the OpenGL 3.2 Specification (Compressed Texture
148Image Formats)
149
150    None.
151
152Additions to Appendix D of the OpenGL 3.2 Specification (Shared Objects and
153Multiple Contexts)
154
155    None.
156
157Additions to Appendix E of the OpenGL 3.2 Specification (The Deprecation
158Model)
159
160    None.
161
162Additions to the AGL/GLX/WGL Specifications
163
164    None.
165
166Dependencies on ARB_blend_func_extended
167
168    If ARB_blend_func_extended is not supported, remove <index> from the
169    layout-qualifier-id list for fragment shader outputs.  Remove all language
170    regarding "Nth input to the blend equation," and remove the "factor"
171    example.  Additionally, remove references to BindFragDataLocationIndexed
172    and GetFragDataIndex in the API spec language.
173
174Dependencies on ARB_separate_shader_objects, ARB_gpu_shader_fp64, OpenGL 4.0,
175and OpenGL 4.1
176
177    If ARB_separate_shader_objects (or OpenGL 4.1) is supported, the layout
178    location qualifier introduced by this extension is extended to apply to
179    inputs for non-vertex shaders and outputs for non-fragment shaders.  If
180    ARB_gpu_shader_fp64 (or OpenGL 4.0) is supported, such inputs and outputs
181    can have double-precision component types.
182
183    When these extensions are supported, there are special rules for the
184    number of locations consumed by "dvec3" and "dvec4" types, which require
185    more storage than is available in a four-component single-precision
186    vector.  The rules are:
187
188      * dvec3/dvec4 vertex inputs consume one location (generic vertex
189        attribute), but can count as two vectors for the purposes of
190        determining if the vertex shader consumes too many inputs
191
192      * dvec3/dvec4 inputs and outputs for other stages consume two locations
193
194    The relevant spec edits (modifying language introduced here) can be found
195    in the ARB_separate_shader_objects extension.
196
197GLX protocol
198
199    None.
200
201Errors
202
203    None, see issue #1.
204
205New State
206
207    None.
208
209New Implementation Dependent State
210
211    None.
212
213
214Modifications to The OpenGL Shading Language Specification, Version 1.50.09
215
216    Including the following line in a shader can be used to control
217    the language feature described in thie extension:
218
219      #extension GL_ARB_explicit_attrib_location : <behavior>
220
221    where <behavior> is as described in section 3.3.
222
223    A new preprocessor #define is added to the OpenGL Shading Language:
224
225      #define GL_ARB_explicit_attrib_location 1
226
227    Modify the second paragraph of section 4.3.4 "Inputs", p. 30 to read:
228
229    ...  The values copied in are established by the OpenGL API or through the
230    use of the of the layout identifier <location>. ...
231
232    Replace the first paragraph of section 4.3.8.1 "Input Layout Qualifiers"
233    with:
234
235    Vertex shaders allow input layout qualifiers on input variable
236    declarations.  The layout qualifier identifier for vertex shader inputs
237    is:
238
239      layout-qualifier-id
240        location = integer-constant
241
242    Only one argument is accepted.  For example,
243
244      layout(location = 3) in vec4 normal;
245
246    will establish that the vertex shader input <normal> is copied in from
247    vector location number 3.
248
249    If the named vertex shader input has a scalar or vector type, it will
250    consume a single location.
251
252    If the named vertex shader input is an array, it will be assigned
253    consecutive locations starting with the location specified.  For example,
254
255      layout(location = 6) in vec4 colors[3];
256
257    will establish that the vertex shader input <colors> is copied in from
258    vector location numbers 6, 7, and 8.
259
260    If the named vertex shader input is an <n>x<m> matrix, it will be assigned
261    multiple locations starting with the location specified.  The number of
262    locations assigned for each matrix will be the same as for an <n>-element
263    array of <m>-component vectors.  For example,
264
265        layout(location = 9) in mat4 transforms[2];
266
267    will establish that input <transforms> is assigned to vector location
268    numbers 9-16, with transforms[0] being assigned to locations 9-12 and
269    transforms[1] being assigned to locations 13-16.
270
271    If an input variable with no location assigned in the shader text has a
272    location specified through the OpenGL API, the API-assigned location will
273    be used.  Otherwise, such variables will be assigned a location by the
274    linker.  See section 2.11.3 of the OpenGL Specification for more details.
275    A link error will occur if an input variable is declared in multiple
276    vertex shaders with conflicting locations.
277
278    Replace the first paragraph of section 4.3.8.2 "Output Layout Qualifiers"
279    with:
280
281    Vertex shaders cannot have output layout qualifiers.
282
283    Add the following text after the second paragraph on page 39:
284
285    Fragment shaders allow output layout qualifiers on output variable
286    declarations.  The layout qualifier identifier for fragment shader
287    outputs is:
288
289      layout-qualifier-id
290        location = integer-constant
291        index = integer-constant
292
293    Each of these qualifiers may appear at most once.  If <index> is specified,
294    <location> must also be specified.  If <index> is not specified, the
295    default value 0 is used.  For example,
296
297      layout(location = 3) out vec4 color;
298
299    will establish that the fragment shader output <color> is copied out to
300    fragment color 3 as the first (index zero) input to the blend equation.
301    And,
302
303      layout(location = 3, index = 1) out vec4 factor;
304
305    will establish that the fragment shader output <factor> is copied out to
306    fragment color 3 as the second (index one) input to the blend equation.
307
308    If the named fragment shader output is an array, it will be assigned
309    consecutive locations starting with the location specified.  For example,
310
311      layout(location = 2) out vec4 colors[3];
312
313    will establish that the fragment shader output <colors> is copied in from
314    vector location numbers 2, 3, and 4.
315
316    If an output variable with no location or index assigned in the shader
317    text has a location specified through the OpenGL API, the API-assigned
318    location will be used.  Otherwise, such variables will be assigned a
319    location by the linker.  All such assignments will have a color index of
320    zero.  See section 3.9.2 of the OpenGL Specification for more details.  A
321    link error will occur if an input variable is declared in multiple vertex
322    shaders with conflicting location or index values.
323
324
325Issues
326
327    1. How should the error be reported when the attribute location
328       specified in the shader source is larger than MAX_VERTEX_ATTRIBUTES?
329
330       RESOLVED.  Generate a link error.  The existing spec language already
331       covers this case:
332
333       "LinkProgram will fail if the assigned binding of an active attribute
334       variable would cause the GL to reference a non-existent generic
335       attribute (one greater than or equal to MAX_VERTEX_ATTRIBS)."
336
337    2. What happens when the shader text binds an input to a
338       particular attribute location and the same attribute location is
339       bound to a different attribute via the API?
340
341       RESOLVED.  The setting in the shader is always used.
342
343    3. Should layout-qualifier-id be index or location?
344
345       RESOLVED.  location.  The API uses both.  <index> is used as the
346       parameter name to VertexAttribPointer and BindAttribLocation, but
347       "location" is used in the name of BindAttribLocation and
348       GetAttribLocation.  However, there is some expectation that <index> may
349       be used for another purpose later.
350
351    4. The GL spec allows BindAttribLocation to be called before attaching
352       shaders or linking.  If an application does this and specifies a
353       layout, which takes precedence?
354
355       RESOLVED.  The setting the shader is always used.
356
357           The three options that were considered:
358
359           a. The setting from the API, if specified, always wins.
360
361           b. The setting from the shader, if specified, always wins.
362
363           c. The setting is order dependent.  If the shader is
364              attached after the API setting is made, the shader
365              layout is used.  If the API setting is made after the
366              shader is attached, the API setting is used.
367
368    5. What happens if an input or output variable is declared in two
369       shader objects with conflicting attribute locations?
370
371       RESOLVED.  A link error will occur.
372
373    6. What happens if an input or output variable is declared in two
374       shader objects with an attribute location assigned in one shader but
375       not the other.
376
377       RESOLVED.  The link will succeed and use the explicit assignment from
378       the first shader, as long as there are no other conflicting
379       assignments.
380
381
382Revision History
383
384    (v12, 2011-08-01, Pat Brown)
385        Add GLSL spec language explicitly specifying the number of vertex
386        shader input locations consumed by basic scalar/vector types and by
387        basic matrix types (bug 7809).  Also add interactions with
388        ARB_separate_shader_objects and ARB_gpu_shader_fp64, which extend the
389        location mechanism introduced here.
390
391    (v11, 2010-01-14, Pat Brown)
392        Resolve the behavior of conflicting attribute assignments via shader
393        text and API calls, with shader text prevailing (bug 5803).  Resolve
394        the behavior of conflicting assignments within two separate shader
395        objects (link error).  Add spec language allowing for a link error if
396        explicit attribute assignments don't leave enough space for array
397        inputs or outputs (bug 5809).  Clarify that any automatic assignments
398        for fragment outputs will use color index zero (bug 5809, interaction
399        with ARB_blend_func_extended).  Fix GLSL language to clarify that
400        layout qualifiers for attribute assignments are on individual
401        declarations, and not on the interface qualifiers "in" or "out".
402
403    (v10, 2009-12-11, Jon Leech)
404        Remove ARB suffixes for integration into 3.3 core spec.
405
406    (v9, 2009-10-29, Ian Romanick)
407        Resolved issue #4.
408        Changed the resolution of issue #2 to match the resolution to
409        #4.
410
411    (v8, 2009-10-26, Ian Romanick)
412        Added interactions with ARB_blend_func_extended.
413
414    (v7, 2009-10-23, Ian Romanick)
415        Reworded overview to include mention of fragment shader outputs.
416        Explicitly state the behavior of specifying a layout for an array.
417        Resolved issue #1 - link error.
418        Resolved issue #3 - changed the use of <index> to <location>.
419        Added issue #4.
420
421    (v6, 2009-10-22, Ian Romanick)
422        Added ability to specify fragment shader output bindings.
423
424       Changed layout syntax from "layout(index(n))" to "layout(index =
425        n)".  This eliminated the need to modify the shading language
426        grammar.  This matches the max_vertices layout qualifier used by
427        geometry shaders.
428
429    (v5, 2009-10-22, Ian Romanick)
430        Re-worded spec based on OpenGL 3.2 and GLSL 1.50.
431
432    (v4, 2009-10-22, Ian Romanick)
433        Convert MESA to ARB.  Added issue #3.
434
435    (v3, 2009-02-17, Ian Romanick)
436        After reading the manual page for glBindAttribLocation, added a
437        resolution for issue #2.
438
439    (v2, 2009-02-11, Ian Romanick)
440        Modified to use the layout keyword from uniform blocks instead
441        of the unusual array-subscript syntax previously proposed.
442        Updated issue #1.
443
444    (v1, 2009-01-23, Ian Romanick)
445        Initial version.
446