2 * (C) Copyright IBM Corporation 2002, 2004
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Utility functions for DRI drivers.
29 * \author Ian Romanick <idr@us.ibm.com>
34 #include "main/mtypes.h"
35 #include "main/cpuinfo.h"
36 #include "main/extensions.h"
41 driParseDebugString( const char * debug
,
42 const struct dri_debug_control
* control
)
48 if ( debug
!= NULL
) {
49 while( control
->string
!= NULL
) {
50 if ( !strcmp( debug
, "all" ) ||
51 strstr( debug
, control
->string
) != NULL
) {
52 flag
|= control
->flag
;
65 * Create the \c GL_RENDERER string for DRI drivers.
67 * Almost all DRI drivers use a \c GL_RENDERER string of the form:
69 * "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
71 * Using the supplied chip name, driver data, and AGP speed, this function
74 * \param buffer Buffer to hold the \c GL_RENDERER string.
75 * \param hardware_name Name of the hardware.
76 * \param driver_date Driver date.
77 * \param agp_mode AGP mode (speed).
80 * The length of the string stored in \c buffer. This does \b not include
81 * the terminating \c NUL character.
84 driGetRendererString( char * buffer
, const char * hardware_name
,
85 const char * driver_date
, GLuint agp_mode
)
90 offset
= sprintf( buffer
, "Mesa DRI %s %s", hardware_name
, driver_date
);
92 /* Append any AGP-specific information.
99 offset
+= sprintf( & buffer
[ offset
], " AGP %ux", agp_mode
);
106 /* Append any CPU-specific information.
108 cpu
= _mesa_get_cpu_string();
110 offset
+= sprintf(buffer
+ offset
, " %s", cpu
);
120 #define need_GL_ARB_draw_buffers
121 #define need_GL_ARB_multisample
122 #define need_GL_ARB_texture_compression
123 #define need_GL_ARB_transpose_matrix
124 #define need_GL_ARB_vertex_buffer_object
125 #define need_GL_ARB_window_pos
126 #define need_GL_EXT_compiled_vertex_array
127 #define need_GL_EXT_multi_draw_arrays
128 #define need_GL_EXT_polygon_offset
129 #define need_GL_EXT_texture_object
130 #define need_GL_EXT_vertex_array
131 #define need_GL_IBM_multimode_draw_arrays
132 #define need_GL_MESA_window_pos
134 /* These are needed in *all* drivers because Mesa internally implements
135 * certain functionality in terms of functions provided by these extensions.
136 * For example, glBlendFunc is implemented by calling glBlendFuncSeparateEXT.
138 #define need_GL_EXT_blend_func_separate
139 #define need_GL_NV_vertex_program
141 #include "main/remap_helper.h"
143 static const struct dri_extension all_mesa_extensions
[] = {
144 { "GL_ARB_draw_buffers", GL_ARB_draw_buffers_functions
},
145 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
146 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
147 { "GL_ARB_transpose_matrix", GL_ARB_transpose_matrix_functions
},
148 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
149 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
150 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
151 { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions
},
152 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
153 { "GL_EXT_polygon_offset", GL_EXT_polygon_offset_functions
},
154 { "GL_EXT_texture_object", GL_EXT_texture_object_functions
},
155 { "GL_EXT_vertex_array", GL_EXT_vertex_array_functions
},
156 { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions
},
157 { "GL_MESA_window_pos", GL_MESA_window_pos_functions
},
158 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
164 * Enable and map extensions supported by the driver.
166 * When ctx is NULL, extensions are not enabled, but their functions
167 * are still mapped. When extensions_to_enable is NULL, all static
168 * functions known to mesa core are mapped.
171 * ARB_imaging isn't handled properly. In Mesa, enabling ARB_imaging also
172 * enables all the sub-extensions that are folded into it. This means that
173 * we need to add entry-points (via \c driInitSingleExtension) for those
174 * new functions here.
176 void driInitExtensions( GLcontext
* ctx
,
177 const struct dri_extension
* extensions_to_enable
,
178 GLboolean enable_imaging
)
180 static int first_time
= 1;
185 driInitExtensions( NULL
, all_mesa_extensions
, GL_FALSE
);
188 if ( (ctx
!= NULL
) && enable_imaging
) {
189 _mesa_enable_imaging_extensions( ctx
);
192 /* The caller is too lazy to list any extension */
193 if ( extensions_to_enable
== NULL
) {
194 /* Map the static functions. Together with those mapped by remap
195 * table, this should cover everything mesa core knows.
197 _mesa_map_static_functions();
201 for ( i
= 0 ; extensions_to_enable
[i
].name
!= NULL
; i
++ ) {
202 driInitSingleExtension( ctx
, & extensions_to_enable
[i
] );
210 * Enable and map functions for a single extension
212 * \param ctx Context where extension is to be enabled.
213 * \param ext Extension that is to be enabled.
215 * \sa driInitExtensions, _mesa_enable_extension, _mesa_map_function_array
217 void driInitSingleExtension( GLcontext
* ctx
,
218 const struct dri_extension
* ext
)
220 if ( ext
->functions
!= NULL
) {
221 _mesa_map_function_array(ext
->functions
);
225 _mesa_enable_extension( ctx
, ext
->name
);
231 * Utility function used by drivers to test the verions of other components.
233 * If one of the version requirements is not met, a message is logged using
234 * \c __driUtilMessage.
236 * \param driver_name Name of the driver. Used in error messages.
237 * \param driActual Actual DRI version supplied __driCreateNewScreen.
238 * \param driExpected Minimum DRI version required by the driver.
239 * \param ddxActual Actual DDX version supplied __driCreateNewScreen.
240 * \param ddxExpected Minimum DDX minor and range of DDX major version required by the driver.
241 * \param drmActual Actual DRM version supplied __driCreateNewScreen.
242 * \param drmExpected Minimum DRM version required by the driver.
244 * \returns \c GL_TRUE if all version requirements are met. Otherwise,
245 * \c GL_FALSE is returned.
247 * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2, __driUtilMessage
250 * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
251 * function and \c driCheckDriDdxDrmVersions2 should be renamed.
254 driCheckDriDdxDrmVersions3(const char * driver_name
,
255 const __DRIversion
* driActual
,
256 const __DRIversion
* driExpected
,
257 const __DRIversion
* ddxActual
,
258 const __DRIutilversion2
* ddxExpected
,
259 const __DRIversion
* drmActual
,
260 const __DRIversion
* drmExpected
)
262 static const char format
[] = "%s DRI driver expected %s version %d.%d.x "
263 "but got version %d.%d.%d\n";
264 static const char format2
[] = "%s DRI driver expected %s version %d-%d.%d.x "
265 "but got version %d.%d.%d\n";
268 /* Check the DRI version */
269 if ( (driActual
->major
!= driExpected
->major
)
270 || (driActual
->minor
< driExpected
->minor
) ) {
271 fprintf(stderr
, format
, driver_name
, "DRI",
272 driExpected
->major
, driExpected
->minor
,
273 driActual
->major
, driActual
->minor
, driActual
->patch
);
277 /* Check that the DDX driver version is compatible */
278 if ( (ddxActual
->major
< ddxExpected
->major_min
)
279 || (ddxActual
->major
> ddxExpected
->major_max
)
280 || (ddxActual
->minor
< ddxExpected
->minor
) ) {
281 fprintf(stderr
, format2
, driver_name
, "DDX",
282 ddxExpected
->major_min
, ddxExpected
->major_max
, ddxExpected
->minor
,
283 ddxActual
->major
, ddxActual
->minor
, ddxActual
->patch
);
287 /* Check that the DRM driver version is compatible */
288 if ( (drmActual
->major
!= drmExpected
->major
)
289 || (drmActual
->minor
< drmExpected
->minor
) ) {
290 fprintf(stderr
, format
, driver_name
, "DRM",
291 drmExpected
->major
, drmExpected
->minor
,
292 drmActual
->major
, drmActual
->minor
, drmActual
->patch
);
300 driCheckDriDdxDrmVersions2(const char * driver_name
,
301 const __DRIversion
* driActual
,
302 const __DRIversion
* driExpected
,
303 const __DRIversion
* ddxActual
,
304 const __DRIversion
* ddxExpected
,
305 const __DRIversion
* drmActual
,
306 const __DRIversion
* drmExpected
)
308 __DRIutilversion2 ddx_expected
;
309 ddx_expected
.major_min
= ddxExpected
->major
;
310 ddx_expected
.major_max
= ddxExpected
->major
;
311 ddx_expected
.minor
= ddxExpected
->minor
;
312 ddx_expected
.patch
= ddxExpected
->patch
;
313 return driCheckDriDdxDrmVersions3(driver_name
, driActual
,
314 driExpected
, ddxActual
, & ddx_expected
,
315 drmActual
, drmExpected
);
318 GLboolean
driClipRectToFramebuffer( const GLframebuffer
*buffer
,
320 GLsizei
*width
, GLsizei
*height
)
323 if (*x
< buffer
->_Xmin
) {
324 *width
-= (buffer
->_Xmin
- *x
);
329 if (*x
+ *width
> buffer
->_Xmax
)
330 *width
-= (*x
+ *width
- buffer
->_Xmax
- 1);
335 /* bottom clipping */
336 if (*y
< buffer
->_Ymin
) {
337 *height
-= (buffer
->_Ymin
- *y
);
342 if (*y
+ *height
> buffer
->_Ymax
)
343 *height
-= (*y
+ *height
- buffer
->_Ymax
- 1);
352 * Creates a set of \c __GLcontextModes that a driver will expose.
354 * A set of \c __GLcontextModes will be created based on the supplied
355 * parameters. The number of modes processed will be 2 *
356 * \c num_depth_stencil_bits * \c num_db_modes.
358 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
359 * \c db_modes, and \c visType into each \c __GLcontextModes element.
360 * However, the meanings of \c fb_format and \c fb_type require further
361 * explanation. The \c fb_format specifies which color components are in
362 * each pixel and what the default order is. For example, \c GL_RGB specifies
363 * that red, green, blue are available and red is in the "most significant"
364 * position and blue is in the "least significant". The \c fb_type specifies
365 * the bit sizes of each component and the actual ordering. For example, if
366 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
367 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
370 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
371 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
372 * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
373 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
374 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
375 * still uses 32-bits.
377 * If in doubt, look at the tables used in the function.
379 * \param ptr_to_modes Pointer to a pointer to a linked list of
380 * \c __GLcontextModes. Upon completion, a pointer to
381 * the next element to be process will be stored here.
382 * If the function fails and returns \c GL_FALSE, this
383 * value will be unmodified, but some elements in the
384 * linked list may be modified.
385 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
386 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
387 * \param fb_type Type of the pixels in the framebuffer. Currently only
388 * \c GL_UNSIGNED_SHORT_5_6_5,
389 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
390 * \c GL_UNSIGNED_INT_8_8_8_8, and
391 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
392 * \param depth_bits Array of depth buffer sizes to be exposed.
393 * \param stencil_bits Array of stencil buffer sizes to be exposed.
394 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
396 * \param db_modes Array of buffer swap modes. If an element has a
397 * value of \c GLX_NONE, then it represents a
398 * single-buffered mode. Other valid values are
399 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
400 * \c GLX_SWAP_UNDEFINED_OML. See the
401 * GLX_OML_swap_method extension spec for more details.
402 * \param num_db_modes Number of entries in \c db_modes.
403 * \param msaa_samples Array of msaa sample count. 0 represents a visual
404 * without a multisample buffer.
405 * \param num_msaa_modes Number of entries in \c msaa_samples.
406 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
407 * \c GLX_DIRECT_COLOR.
410 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
411 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
415 * There is currently no way to support packed RGB modes (i.e., modes with
416 * exactly 3 bytes per pixel) or floating-point modes. This could probably
417 * be done by creating some new, private enums with clever names likes
418 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
419 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
422 driCreateConfigs(GLenum fb_format
, GLenum fb_type
,
423 const uint8_t * depth_bits
, const uint8_t * stencil_bits
,
424 unsigned num_depth_stencil_bits
,
425 const GLenum
* db_modes
, unsigned num_db_modes
,
426 const uint8_t * msaa_samples
, unsigned num_msaa_modes
,
427 GLboolean enable_accum
)
429 static const uint8_t bits_table
[4][4] = {
431 { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
432 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
433 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
434 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
437 static const uint32_t masks_table_rgb
[6][4] = {
438 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
439 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
440 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
441 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
442 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */
443 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
446 static const uint32_t masks_table_rgba
[6][4] = {
447 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
448 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
449 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
450 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
451 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
452 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
455 static const uint32_t masks_table_bgr
[6][4] = {
456 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
457 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
458 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
459 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
460 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
461 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
464 static const uint32_t masks_table_bgra
[6][4] = {
465 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
466 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
467 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
468 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
469 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
470 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
473 static const uint8_t bytes_per_pixel
[6] = {
482 const uint8_t * bits
;
483 const uint32_t * masks
;
485 __DRIconfig
**configs
, **c
;
486 __GLcontextModes
*modes
;
489 unsigned num_accum_bits
= (enable_accum
) ? 2 : 1;
492 case GL_UNSIGNED_BYTE_3_3_2
:
495 case GL_UNSIGNED_BYTE_2_3_3_REV
:
498 case GL_UNSIGNED_SHORT_5_6_5
:
501 case GL_UNSIGNED_SHORT_5_6_5_REV
:
504 case GL_UNSIGNED_INT_8_8_8_8
:
507 case GL_UNSIGNED_INT_8_8_8_8_REV
:
511 fprintf( stderr
, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
512 __FUNCTION__
, __LINE__
, fb_type
);
517 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
520 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
523 switch ( fb_format
) {
525 masks
= masks_table_rgb
[ index
];
529 masks
= masks_table_rgba
[ index
];
533 masks
= masks_table_bgr
[ index
];
537 masks
= masks_table_bgra
[ index
];
541 fprintf( stderr
, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
542 __FUNCTION__
, __LINE__
, fb_format
);
546 switch ( bytes_per_pixel
[ index
] ) {
548 bits
= bits_table
[0];
551 bits
= bits_table
[1];
554 bits
= ((fb_format
== GL_RGB
) || (fb_format
== GL_BGR
))
560 num_modes
= num_depth_stencil_bits
* num_db_modes
* num_accum_bits
* num_msaa_modes
;
561 configs
= calloc(1, (num_modes
+ 1) * sizeof *configs
);
566 for ( k
= 0 ; k
< num_depth_stencil_bits
; k
++ ) {
567 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
568 for ( h
= 0 ; h
< num_msaa_modes
; h
++ ) {
569 for ( j
= 0 ; j
< num_accum_bits
; j
++ ) {
570 *c
= malloc (sizeof **c
);
571 modes
= &(*c
)->modes
;
574 memset(modes
, 0, sizeof *modes
);
575 modes
->redBits
= bits
[0];
576 modes
->greenBits
= bits
[1];
577 modes
->blueBits
= bits
[2];
578 modes
->alphaBits
= bits
[3];
579 modes
->redMask
= masks
[0];
580 modes
->greenMask
= masks
[1];
581 modes
->blueMask
= masks
[2];
582 modes
->alphaMask
= masks
[3];
583 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
584 + modes
->blueBits
+ modes
->alphaBits
;
586 modes
->accumRedBits
= 16 * j
;
587 modes
->accumGreenBits
= 16 * j
;
588 modes
->accumBlueBits
= 16 * j
;
589 modes
->accumAlphaBits
= (masks
[3] != 0) ? 16 * j
: 0;
590 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
592 modes
->stencilBits
= stencil_bits
[k
];
593 modes
->depthBits
= depth_bits
[k
];
595 modes
->transparentPixel
= GLX_NONE
;
596 modes
->transparentRed
= GLX_DONT_CARE
;
597 modes
->transparentGreen
= GLX_DONT_CARE
;
598 modes
->transparentBlue
= GLX_DONT_CARE
;
599 modes
->transparentAlpha
= GLX_DONT_CARE
;
600 modes
->transparentIndex
= GLX_DONT_CARE
;
601 modes
->visualType
= GLX_DONT_CARE
;
602 modes
->renderType
= GLX_RGBA_BIT
;
603 modes
->drawableType
= GLX_WINDOW_BIT
;
604 modes
->rgbMode
= GL_TRUE
;
606 if ( db_modes
[i
] == GLX_NONE
) {
607 modes
->doubleBufferMode
= GL_FALSE
;
610 modes
->doubleBufferMode
= GL_TRUE
;
611 modes
->swapMethod
= db_modes
[i
];
614 modes
->samples
= msaa_samples
[h
];
615 modes
->sampleBuffers
= modes
->samples
? 1 : 0;
618 modes
->haveAccumBuffer
= ((modes
->accumRedBits
+
619 modes
->accumGreenBits
+
620 modes
->accumBlueBits
+
621 modes
->accumAlphaBits
) > 0);
622 modes
->haveDepthBuffer
= (modes
->depthBits
> 0);
623 modes
->haveStencilBuffer
= (modes
->stencilBits
> 0);
625 modes
->bindToTextureRgb
= GL_TRUE
;
626 modes
->bindToTextureRgba
= GL_TRUE
;
627 modes
->bindToMipmapTexture
= GL_FALSE
;
628 modes
->bindToTextureTargets
= modes
->rgbMode
?
629 __DRI_ATTRIB_TEXTURE_1D_BIT
|
630 __DRI_ATTRIB_TEXTURE_2D_BIT
|
631 __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT
:
642 __DRIconfig
**driConcatConfigs(__DRIconfig
**a
,
655 all
= malloc((i
+ j
+ 1) * sizeof *all
);
657 for (i
= 0; a
[i
] != NULL
; i
++)
659 for (j
= 0; b
[j
] != NULL
; j
++)
669 #define __ATTRIB(attrib, field) \
670 { attrib, offsetof(__GLcontextModes, field) }
672 static const struct { unsigned int attrib
, offset
; } attribMap
[] = {
673 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE
, rgbBits
),
674 __ATTRIB(__DRI_ATTRIB_LEVEL
, level
),
675 __ATTRIB(__DRI_ATTRIB_RED_SIZE
, redBits
),
676 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE
, greenBits
),
677 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE
, blueBits
),
678 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE
, alphaBits
),
679 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE
, depthBits
),
680 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE
, stencilBits
),
681 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE
, accumRedBits
),
682 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE
, accumGreenBits
),
683 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE
, accumBlueBits
),
684 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE
, accumAlphaBits
),
685 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS
, sampleBuffers
),
686 __ATTRIB(__DRI_ATTRIB_SAMPLES
, samples
),
687 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER
, doubleBufferMode
),
688 __ATTRIB(__DRI_ATTRIB_STEREO
, stereoMode
),
689 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS
, numAuxBuffers
),
690 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE
, transparentPixel
),
691 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE
, transparentPixel
),
692 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE
, transparentRed
),
693 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE
, transparentGreen
),
694 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE
, transparentBlue
),
695 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE
, transparentAlpha
),
696 __ATTRIB(__DRI_ATTRIB_FLOAT_MODE
, floatMode
),
697 __ATTRIB(__DRI_ATTRIB_RED_MASK
, redMask
),
698 __ATTRIB(__DRI_ATTRIB_GREEN_MASK
, greenMask
),
699 __ATTRIB(__DRI_ATTRIB_BLUE_MASK
, blueMask
),
700 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK
, alphaMask
),
701 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH
, maxPbufferWidth
),
702 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
, maxPbufferHeight
),
703 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS
, maxPbufferPixels
),
704 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH
, optimalPbufferWidth
),
705 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT
, optimalPbufferHeight
),
706 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, swapMethod
),
707 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB
, bindToTextureRgb
),
708 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
, bindToTextureRgba
),
709 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE
, bindToMipmapTexture
),
710 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS
, bindToTextureTargets
),
711 __ATTRIB(__DRI_ATTRIB_YINVERTED
, yInverted
),
713 /* The struct field doesn't matter here, these are handled by the
714 * switch in driGetConfigAttribIndex. We need them in the array
715 * so the iterator includes them though.*/
716 __ATTRIB(__DRI_ATTRIB_RENDER_TYPE
, level
),
717 __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT
, level
),
718 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, level
)
721 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
724 driGetConfigAttribIndex(const __DRIconfig
*config
,
725 unsigned int index
, unsigned int *value
)
727 switch (attribMap
[index
].attrib
) {
728 case __DRI_ATTRIB_RENDER_TYPE
:
729 if (config
->modes
.rgbMode
)
730 *value
= __DRI_ATTRIB_RGBA_BIT
;
732 *value
= __DRI_ATTRIB_COLOR_INDEX_BIT
;
734 case __DRI_ATTRIB_CONFIG_CAVEAT
:
735 if (config
->modes
.visualRating
== GLX_NON_CONFORMANT_CONFIG
)
736 *value
= __DRI_ATTRIB_NON_CONFORMANT_CONFIG
;
737 else if (config
->modes
.visualRating
== GLX_SLOW_CONFIG
)
738 *value
= __DRI_ATTRIB_SLOW_BIT
;
742 case __DRI_ATTRIB_SWAP_METHOD
:
745 case __DRI_ATTRIB_FLOAT_MODE
:
746 *value
= config
->modes
.floatMode
;
750 *value
= *(unsigned int *)
751 ((char *) &config
->modes
+ attribMap
[index
].offset
);
760 driGetConfigAttrib(const __DRIconfig
*config
,
761 unsigned int attrib
, unsigned int *value
)
765 for (i
= 0; i
< ARRAY_SIZE(attribMap
); i
++)
766 if (attribMap
[i
].attrib
== attrib
)
767 return driGetConfigAttribIndex(config
, i
, value
);
773 driIndexConfigAttrib(const __DRIconfig
*config
, int index
,
774 unsigned int *attrib
, unsigned int *value
)
776 if (index
>= 0 && index
< ARRAY_SIZE(attribMap
)) {
777 *attrib
= attribMap
[index
].attrib
;
778 return driGetConfigAttribIndex(config
, index
, value
);