1Name 2 3 NV_explicit_attrib_location 4 5Name Strings 6 7 GL_NV_explicit_attrib_location 8 9Contributors 10 11 Contributors to ARB_explicit_attrib_location 12 Mathias Heyer, NVIDIA 13 14Contact 15 16 Greg Roth, NVIDIA (groth 'at' nvidia.com) 17 18Status 19 20 Shipping on Tegra 21 22Version 23 24 Last Modified Date: September 20, 2013 25 Revision: 2 26 27Number 28 29 OpenGL ES Extension #159 30 31Dependencies 32 33 Requires OpenGL ES 2.0. 34 35 Written based on the wording of the OpenGL ES 2.0.25 Full Specification 36 (November 2, 2010). 37 38 Written based on the wording of The OpenGL ES Shading Language 1.0.17 39 Specification (May 12, 2009). 40 41Overview 42 43 This extension provides a method to pre-assign attribute locations 44 to named vertex shader inputs. This allows applications to globally 45 assign a particular semantic meaning, such as diffuse color or 46 vertex normal, to a particular attribute location without knowing 47 how that attribute will be named in any particular shader. 48 49New Procedures and Functions 50 51 None 52 53New Tokens 54 55 None 56 57Additions to Chapter 2 of the OpenGL ES 2.0 Specification (OpenGL Operation) 58 59 Section 2.10.4 "Shader Variables", subsection "Vertex Attributes" 60 61 Modify the first paragraph to read: 62 63 "Vertex shaders can define named attribute variables, which are 64 bound to the generic vertex attributes that are set by 65 VertexAttrib*. This binding can be specified by the application 66 before the program is linked, either through BindAttribLocation 67 (described below) or explicitly within the shader text, or 68 automatically assigned by the GL when the program is linked." 69 70 Modify the third paragraph describing BindAttribLocation to read: 71 72 "When a program is linked, any active attributes without a binding 73 specified either through BindAttribLocation or explicitly set within 74 the shader text will automatically be bound to vertex attributes by 75 the GL. Such bindings can be queried using the command 76 GetAttribLocation. LinkProgram will fail if the assigned binding of 77 an active attribute variable would cause the GL to reference a 78 nonexistent generic attribute (one greater than or equal to the 79 value of MAX_VERTEX_ATTRIBS). LinkProgram will fail if the attribute 80 bindings specified either through BindAttribLocation or explicitly 81 set within the shader text do not leave enough space to assign a 82 location for an active matrix attribute, which requires multiple 83 contiguous generic attributes. If an active attribute has a binding 84 explicitly set within the shader text and a different binding 85 assigned by BindAttribLocation, the assignment in the shader text is 86 used." 87 88Additions to OpenGL ES Shading Language 1.00 Specification 89 90 Including the following line in a shader can be used to control 91 the language feature described in this extension: 92 93 #extension GL_NV_explicit_attrib_location : <behavior> 94 95 where <behavior> is as described in section 3.4. 96 97 A new preprocessor #define is added to the OpenGL ES Shading Language: 98 99 #define GL_NV_explicit_attrib_location 1 100 101Section 4.3.3 "Attribute" 102 103 Add new section 4.3.3.1 "Attribute Layout Qualifiers" 104 105 "Vertex shaders allow location layout qualifiers on attribute 106 variable declarations. They can appear with an individual variable 107 declared with an attribute qualifier: 108 109 <layout-qualifier> attribute <declaration>; 110 111 Layouts qualified declarations can only be made at global scope, 112 and only on attribute variable declarations. 113 114 <layout-qualifier> expands to: 115 116 layout-qualifier : 117 layout (<layout-qualifier-id>) 118 119 <layout-qualifier-id> : 120 location = <integer-constant> 121 122 Only one argument is accepted. For example, 123 124 layout(location = 3) attribute vec4 normal; 125 126 will establish that the vertex shader attribute <normal> is copied 127 in from vector location number 3. 128 129 If the named vertex shader input has a scalar or vector type, it 130 will consume a single location. 131 132 If the named vertex shader attribute is a matrix, it will be 133 assigned multiple locations starting with the location specified. 134 The number of locations assigned for each matrix will be equal to 135 the number of columns in the matrix For example, 136 137 layout(location = 9) attribute mat4 transform; 138 139 will establish that input <transform> is assigned to vector location 140 numbers 9-12. 141 142 If an attribute variable with no location assigned in the shader 143 text has a location specified through the OpenGL ES API, the API- 144 assigned location will be used. Otherwise, such variables will be 145 assigned a location by the linker. See section 2.10.4 of the OpenGL 146 ES Specification for more details. 147 148Errors 149 150 None, see issue #1. 151 152New State 153 154 None. 155 156New Implementation Dependent State 157 158 None. 159 160Issues 161 162 1. How should the error be reported when the attribute location 163 specified in the shader source is larger than MAX_VERTEX_ATTRIBUTES? 164 165 RESOLVED. Generate a link error. The existing spec language already 166 covers this case: 167 168 "LinkProgram will fail if the assigned binding of an active attribute 169 variable would cause the GL to reference a non-existent generic 170 attribute (one greater than or equal to MAX_VERTEX_ATTRIBS)." 171 172 2. What happens when the shader text binds an input to a 173 particular attribute location and the same attribute location is 174 bound to a different attribute via the API? 175 176 RESOLVED. The setting in the shader is always used. 177 178 3. Should layout-qualifier-id be index or location? 179 180 RESOLVED. location. The API uses both. <index> is used as the 181 parameter name to VertexAttribPointer and BindAttribLocation, but 182 "location" is used in the name of BindAttribLocation and 183 GetAttribLocation. However, there is some expectation that <index> may 184 be used for another purpose later. 185 186 4. The GL spec allows BindAttribLocation to be called before attaching 187 shaders or linking. If an application does this and specifies a 188 layout, which takes precedence? 189 190 RESOLVED. The setting the shader is always used. 191 192 The three options that were considered: 193 194 a. The setting from the API, if specified, always wins. 195 196 b. The setting from the shader, if specified, always wins. 197 198 c. The setting is order dependent. If the shader is 199 attached after the API setting is made, the shader 200 layout is used. If the API setting is made after the 201 shader is attached, the API setting is used. 202 203 5. What happens if an input or output variable is declared in two 204 shader objects with conflicting attribute locations? 205 206 RESOLVED. Not relevant to ES. 207 208 6. What happens if an input or output variable is declared in two 209 shader objects with an attribute location assigned in one shader but 210 not the other. 211 212 RESOLVED. Not relevant to ES. 213 214 215Revision History 216 217 Rev. Date Author Changes 218 ---- ---------- --------- ------------------------------------ 219 2 09/20/2013 dkoch minor edits for publishing 220 1 04/25/2012 groth First revision based on 221 ARB_explicit_attrib_location. 222