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