1Name 2 3 ARB_vertex_array_bgra 4 5Name Strings 6 7 GL_ARB_vertex_array_bgra 8 9Contributors 10 11 Jason Green, TransGaming 12 Gavriel State, TransGaming 13 Daniel Koch, TransGaming 14 Rob Barris, Blizzard 15 Mark Krenek, Aspyr 16 Ryan Gordon, Destineer 17 Nicholas Vining, Destineer 18 19Contact 20 21 Mark Kilgard, NVIDIA (mjk 'at' nvidia.com) 22 Daniel Koch, TransGaming (daniel 'at' transgaming.com) 23 24Notice 25 26 Copyright (c) 2009-2013 The Khronos Group Inc. Copyright terms at 27 http://www.khronos.org/registry/speccopyright.html 28 29Specification Update Policy 30 31 Khronos-approved extension specifications are updated in response to 32 issues and bugs prioritized by the Khronos OpenGL Working Group. For 33 extensions which have been promoted to a core Specification, fixes will 34 first appear in the latest version of that core Specification, and will 35 eventually be backported to the extension document. This policy is 36 described in more detail at 37 https://www.khronos.org/registry/OpenGL/docs/update_policy.php 38 39Status 40 41 Complete. Approved by the ARB on July 3, 2009. 42 Implemented by NVIDIA, October 2008 43 44Version 45 46 Last Modified Date: June 26, 2009 47 Version: 2 48 49Number 50 51 ARB Extension #68 52 53Dependencies 54 55 This extension is written against the OpenGL 2.1 Specification but 56 can apply to OpenGL 1.1 and up. 57 58 This extension interacts with EXT_vertex_array. 59 60 This extension interacts with EXT_secondary_color. 61 62 This extension interacts with NV_vertex_program. 63 64 This extension interacts with ARB_vertex_program. 65 66 This extension interacts with ARB_vertex_shader. 67 68Overview 69 70 This extension provides a single new component format for vertex 71 arrays to read 4-component unsigned byte vertex attributes with a 72 BGRA component ordering. 73 74 OpenGL expects vertex arrays containing 4 unsigned bytes per 75 element to be in the RGBA, STRQ, or XYZW order (reading components 76 left-to-right in their lower address to higher address order). 77 Essentially the order the components appear in memory is the order 78 the components appear in the resulting vertex attribute vector. 79 80 However Direct3D has color (diffuse and specular) vertex arrays 81 containing 4 unsigned bytes per element that are in a BGRA order 82 (again reading components left-to-right in their lower address 83 to higher address order). Direct3D calls this "ARGB" reading the 84 components in the opposite order (reading components left-to-right 85 in their higher address to lower address order). This ordering is 86 generalized in the DirectX 10 by the DXGI_FORMAT_B8G8R8A8_UNORM 87 format. 88 89 For an OpenGL application to source color data from a vertex 90 buffer formatted for Direct3D's color array format conventions, 91 the application is forced to either: 92 93 1. Rely on a vertex program or shader to swizzle the color components 94 from the BGRA to conventional RGBA order. 95 96 2. Re-order the color data components in the vertex buffer from 97 Direct3D's native BGRA order to OpenGL's native RGBA order. 98 99 Neither option is entirely satisfactory. 100 101 Option 1 means vertex shaders have to be re-written to source colors 102 differently. If the same vertex shader is used with vertex arrays 103 configured to source the color as 4 floating-point color components, 104 the swizzle for BGRA colors stored as 4 unsigned bytes is no longer 105 appropriate. The shader's swizzling of colors becomes dependent on 106 the type and number of color components. Ideally the vertex shader 107 should be independent from the format and component ordering of the 108 data it sources. 109 110 Option 2 is expensive because vertex buffers may have to be 111 reformatted prior to use. OpenGL treats the memory for vertex arrays 112 (whether client-side memory or buffer objects) as essentially untyped 113 memory and vertex arrays can be stored separately, interleaved, 114 or even interwoven (where multiple arrays overlap with differing 115 strides and formats). 116 117 Rather than force a re-ordering of either vertex array components 118 in memory or a vertex array format-dependent re-ordering of vertex 119 shader inputs, OpenGL can simply provide a vertex array format that 120 matches the Direct3D color component ordering. 121 122 This approach mimics that of the EXT_bgra extension for pixel and 123 texel formats except for vertex instead of image data. 124 125New Procedures and Functions 126 127 None 128 129New Tokens 130 131 Accepted by the <size> parameter of ColorPointer, 132 SecondaryColorPointer, and VertexAttribPointer: 133 134 BGRA 0x80E1 135 136Additions to Chapter 2 of the OpenGL 2.1 Specification (OpenGL Operation) 137 138 -- Section 2.8 "Vertex Arrays" (page 24) 139 140 Replace the sentence beginning "size, when present, ..." with: 141 142 "size, when present, indicates the number of values per vertex that 143 are stored in the array as well as their component ordering." 144 145 Add these final sentences to the end of the same paragraph: 146 147 "The error INVALID_VALUE is generated if size is BGRA and type is 148 not UNSIGNED_BYTE. The error INVALID_VALUE is generated by 149 VertexAttribPointer if size is BGRA and normalized is FALSE." 150 151 Edit Table 2.4 "Vertex array sizes (values per vertex) and data types" 152 as follows: 153 154 * Rename the "Sizes" column to "Sizes and component ordering". 155 156 * Add "BGRA" to the "Sizes and component order" column of the 157 following rows: ColorPointer, SecondaryColorPointer, and 158 VertexAttribPointer. 159 160 These are the commands capable of accepting normalized 161 coordinates and accepting 4 for "size" plus the special case of 162 SecondaryColorPointer command. 163 164 * Add the following sentence to the end of the table caption: 165 "If the size parameter is BGRA, the vertex array values are always 166 normalized irrespective of the Normalized column." 167 168 "The one, two, three, or four values in an array that correspond to 169 a single vertex comprise an array element. When the BGRA token is 170 specified for size, it indicates four values. The values within 171 each array element are stored sequentially in memory. However if 172 the size is specified with BGRA, the first, second, third, and fourth 173 values of each array element are read from the third, second, first, 174 and fourth values in memory respectively." 175 176Additions to Chapter 3 of the OpenGL 2.1 Specification (Rasterization) 177 178 None 179 180Additions to Chapter 4 of the OpenGL 2.1 Specification (Per-Fragment 181Operations and the Frame Buffer) 182 183 None 184 185Additions to Chapter 5 of the OpenGL 2.1 Specification (Special 186Functions) 187 188 None 189 190Additions to Chapter 6 of the OpenGL 2.1 Specification (State and 191State Requests) 192 193 None 194 195Additions to the AGL/GLX/WGL Specifications 196 197 None 198 199Additions to the OpenGL Shading Language 200 201 None 202 203GLX Protocol 204 205 None 206 207Errors 208 209 The error INVALID_VALUE is generated when ColorPointer, 210 SecondaryColorPointer, or VertexAttribPointer is 211 called with size set to BGRA and type is not UNSIGNED_BYTE. 212 213 The error INVALID_VALUE is generated when VertexAttribPointer is 214 called with size set to BGRA and normalized is FALSE. 215 216Dependencies on EXT_vertex_array 217 218 This extension's additional behavior for ColorPointer apply to 219 ColorPointerEXT too. 220 221Dependencies on EXT_secondary_color 222 223 This extension's additional behavior for SecondaryColorPointer 224 applies to SecondaryColorPointerEXT too. 225 226Dependencies on NV_vertex_program 227 228 This extension's additional behavior for VertexAttribPointer applies 229 to VertexAttribPointerNV too. 230 231Dependencies on ARB_vertex_program and ARB_vertex_shader 232 233 This extension's additional behavior for VertexAttribPointer applies 234 to VertexAttribPointerARB too. 235 236Dependencies on ARB_compatibility and OpenGL 3.1 (or later): 237 238 If using an OpenGL 3.1 (or later) and ARB_compatibility is not supported 239 ignore all references to ColorPointer and SecondaryColorPointer and the 240 associated state and queries. 241 242New State 243 244 Change tables 6.6 and 6.7 to fix Type column by making the type 245 a k-valued integer where k is 3, 2, and 5 for color, secondary, 246 and vertex attrib arrays respectively. 247 248(table 6.6, "Vertex Array Data", p. 271) 249 Get Value Type Get Command Initial Value Description Sec Attribute 250 --------- ---- ----------- ------------- --------------------- --- --------- 251 COLOR_ARRAY_SIZE Z3 GetIntegerv 4 Color components 2.8 vertex-array 252 per vertex 253 SECONDARY_COLOR_ARRAY_SIZE Z2 GetIntegerv 3 Secondary color 2.8 vertex-array 254 components per vertex 255 256(table 6.7, "Vertex Array Data (cont.)", p. 272) 257 Get Value Type Get Command Initial Value Description Sec Attribute 258 --------- -------- ----------- ------------- --------------------- --- --------- 259 VERTEX_ATTRIB_ARRAY_SIZE 16* x Z5 GetIntegerv 4 Vertex attrib array 2.8 vertex-array 260 size 261 262New Implementation Dependent State 263 264 None 265 266Issues 267 268 1. What should this extension be called? 269 270 RESOLVED: ARB_vertex_array_bgra 271 272 Because the extension adds a new "vertex array" format with the 273 "bgra" component ordering and assuming a normalized representation 274 as BGRA with UNSIGNED_BYTE would provide for image data. This 275 extension is the ARB-ratified version of EXT_vertex_array_bgra. 276 277 2. How should the vertex array API be changed? 278 279 RESOLVED: Allow BGRA as a valid token for the size field of 280 vertex array specification commands. While the size parameter 281 is of type GLint, the valid sizes are in the 1 to 4 range so 282 the GL_BGRA token is easily distinguished from the existing 283 small integer values. 284 285 This mimics the way OpenGL 1.1 changed the "components" field 286 of glTexImage1D and glTexImage2D to specify an internalformat 287 rather than simply a number of components from 1 to 4. 288 289 This approach has the advantage of not adding any new commands 290 or tokens since the GL_BGRA token already exists. 291 292 3. What vertex array specification commands should accept the new 293 BGRA vertex array format for their size parameter? 294 295 RESOLVED: All vertex array specification commands which accept 4 296 as a valid size plus the glSecondaryColorPointer command because 297 Direct3D allows a BGRA-ordered secondary color (its specular 298 vertex attribute) to be specified. 299 300 Because DirectX 10 makes its formats highly orthogonal and it 301 allows a corresponding format (DXGI_FORMAT_B8G8R8A8_UNORM), 302 the BGRA vertex array format should be similarly general. 303 304 4. Should a 4-component BGRA secondary color be allowed? 305 306 RESOLVED: Yes. 307 308 DirectX 9 supports a 4-component secondary color. All four 309 components should be available to a vertex shader or vertex 310 program. Fixed-function operation without lighting enabled 311 should pass through the secondary color alpha component. However 312 fixed-function lighting specifies its output secondary color alpha 313 is always output as 1 and ignores the input secondary color alpha. 314 315 5. So should 4 be allowed as a valid size parameter for 316 glSecondaryColorPointer? 317 318 RESOLVED: Not for this extension. We leave it to another 319 extension or core revision could extend the secondary color to 320 4 components. 321 322 6. Should the BGRA vertex array format only work with the 323 GL_UNSIGNED_BYTE type? 324 325 RESOLVED: Yes. 326 327 This is consistent with Direct3D's use of the D3DCOLOR type which 328 is defined with a BGRA ordering and 8-bit normalized components. 329 330 7. How should the BGRA vertex array format's normalized behavior 331 interact with the "normalized" parameter of glVertexAttribPointer? 332 333 RESOLVED: Since BGRA implies normalization, it should be an 334 error to request BGRA with the normalized parameter set to false. 335 336 This ensures the following statement in the caption of table 2.4 337 remains true: "For generic vertex attributes, fixed-point data 338 are normalized if and only if the VertexAttribPointer normalized 339 flag is set." 340 341 8. Should the glVertexAttribIPointerEXT command accept GL_BGRA for 342 its size parameter? 343 344 RESOLVED: No. Because the BGRA vertex array format implies 345 normalized component values, that is inconsistent with providing 346 integer vertex attributes. 347 348 9. Should this apply to glVertexPointer? 349 350 RESOLVED: No. glVertexPointer doesn't support GL_UNSIGNED_BYTE 351 as a type so GL_BGRA doesn't make sense. 352 353 10. To what vertex arrays should this extension apply? 354 355 RESOLVED: Just primary color (glColorPointer), secondary 356 color (glSecondaryColorPointer), and generic vertex attribs 357 (glVertexAttribPointer). 358 359 The rationale is these are the formats that take 4 component 360 attributes that can be normalized (making a special exception to 361 treat the secondary color array as having 4 components for the 362 purpose of BGRA support to match Direct3D). Texture coordinate 363 sets and vertex positions are not normalized. Normals are 364 normalized but only 4 coordinates. 365 366 11. What Direct3D 9 functionality provides BGRA vertex arrays? 367 368 You can specify BGRA vertex arrays with either Flexible Vertex 369 Formats (FVFs) or a Direct3D 9 Vertex Declaration. 370 371 The FVF formats are D3DFVF_DIFFUSE and D3DFVF_SPECULAR. 372 373 The Vertex Declaration declaration data type is 374 D3DDECLTYPE_D3DCOLOR. 375 376Revision History 377 378 Rev. Date Author Changes 379 ---- -------- --------- ---------------------------------------- 380 1 5/19/09 dgkoch copy & rename from EXT version rev 5. 381 2 6/26/09 dgkoch add interactions with ARB_compatibility 382 correct Type and Initial values columns in 383 table 6.7 384