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 * Print message to \c stderr if the \c LIBGL_DEBUG environment variable
44 * Is called from the drivers.
46 * \param f \c printf like format string.
49 __driUtilMessage(const char *f
, ...)
53 if (getenv("LIBGL_DEBUG")) {
54 fprintf(stderr
, "libGL: ");
56 vfprintf(stderr
, f
, args
);
58 fprintf(stderr
, "\n");
64 driParseDebugString( const char * debug
,
65 const struct dri_debug_control
* control
)
71 if ( debug
!= NULL
) {
72 while( control
->string
!= NULL
) {
73 if ( !strcmp( debug
, "all" ) ||
74 strstr( debug
, control
->string
) != NULL
) {
75 flag
|= control
->flag
;
88 * Create the \c GL_RENDERER string for DRI drivers.
90 * Almost all DRI drivers use a \c GL_RENDERER string of the form:
92 * "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
94 * Using the supplied chip name, driver data, and AGP speed, this function
97 * \param buffer Buffer to hold the \c GL_RENDERER string.
98 * \param hardware_name Name of the hardware.
99 * \param agp_mode AGP mode (speed).
102 * The length of the string stored in \c buffer. This does \b not include
103 * the terminating \c NUL character.
106 driGetRendererString( char * buffer
, const char * hardware_name
,
112 offset
= sprintf( buffer
, "Mesa DRI %s", hardware_name
);
114 /* Append any AGP-specific information.
116 switch ( agp_mode
) {
121 offset
+= sprintf( & buffer
[ offset
], " AGP %ux", agp_mode
);
128 /* Append any CPU-specific information.
130 cpu
= _mesa_get_cpu_string();
132 offset
+= sprintf(buffer
+ offset
, " %s", cpu
);
142 #define need_GL_ARB_copy_buffer
143 #define need_GL_ARB_draw_buffers
144 #define need_GL_ARB_multisample
145 #define need_GL_ARB_texture_compression
146 #define need_GL_ARB_transpose_matrix
147 #define need_GL_ARB_vertex_buffer_object
148 #define need_GL_ARB_window_pos
149 #define need_GL_EXT_compiled_vertex_array
150 #define need_GL_EXT_multi_draw_arrays
151 #define need_GL_EXT_polygon_offset
152 #define need_GL_EXT_texture_object
153 #define need_GL_EXT_vertex_array
154 #define need_GL_IBM_multimode_draw_arrays
155 #define need_GL_MESA_window_pos
157 /* These are needed in *all* drivers because Mesa internally implements
158 * certain functionality in terms of functions provided by these extensions.
159 * For example, glBlendFunc is implemented by calling glBlendFuncSeparateEXT.
161 #define need_GL_EXT_blend_func_separate
162 #define need_GL_NV_vertex_program
164 #include "main/remap_helper.h"
166 static const struct dri_extension all_mesa_extensions
[] = {
167 { "GL_ARB_copy_buffer", GL_ARB_copy_buffer_functions
},
168 { "GL_ARB_draw_buffers", GL_ARB_draw_buffers_functions
},
169 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
170 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
171 { "GL_ARB_transpose_matrix", GL_ARB_transpose_matrix_functions
},
172 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
173 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
174 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
175 { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions
},
176 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
177 { "GL_EXT_polygon_offset", GL_EXT_polygon_offset_functions
},
178 { "GL_EXT_texture_object", GL_EXT_texture_object_functions
},
179 { "GL_EXT_vertex_array", GL_EXT_vertex_array_functions
},
180 { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions
},
181 { "GL_MESA_window_pos", GL_MESA_window_pos_functions
},
182 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
188 * Enable and map extensions supported by the driver.
190 * When ctx is NULL, extensions are not enabled, but their functions
191 * are still mapped. When extensions_to_enable is NULL, all static
192 * functions known to mesa core are mapped.
195 * ARB_imaging isn't handled properly. In Mesa, enabling ARB_imaging also
196 * enables all the sub-extensions that are folded into it. This means that
197 * we need to add entry-points (via \c driInitSingleExtension) for those
198 * new functions here.
200 void driInitExtensions( struct gl_context
* ctx
,
201 const struct dri_extension
* extensions_to_enable
,
202 GLboolean enable_imaging
)
204 static int first_time
= 1;
209 driInitExtensions( NULL
, all_mesa_extensions
, GL_FALSE
);
212 if ( (ctx
!= NULL
) && enable_imaging
) {
213 _mesa_enable_imaging_extensions( ctx
);
216 /* The caller is too lazy to list any extension */
217 if ( extensions_to_enable
== NULL
) {
218 /* Map the static functions. Together with those mapped by remap
219 * table, this should cover everything mesa core knows.
221 _mesa_map_static_functions();
225 for ( i
= 0 ; extensions_to_enable
[i
].name
!= NULL
; i
++ ) {
226 driInitSingleExtension( ctx
, & extensions_to_enable
[i
] );
234 * Enable and map functions for a single extension
236 * \param ctx Context where extension is to be enabled.
237 * \param ext Extension that is to be enabled.
239 * \sa driInitExtensions, _mesa_enable_extension, _mesa_map_function_array
241 void driInitSingleExtension( struct gl_context
* ctx
,
242 const struct dri_extension
* ext
)
244 if ( ext
->functions
!= NULL
) {
245 _mesa_map_function_array(ext
->functions
);
249 _mesa_enable_extension( ctx
, ext
->name
);
255 * Utility function used by drivers to test the verions of other components.
257 * \param driver_name Name of the driver. Used in error messages.
258 * \param driActual Actual DRI version supplied __driCreateNewScreen.
259 * \param driExpected Minimum DRI version required by the driver.
260 * \param ddxActual Actual DDX version supplied __driCreateNewScreen.
261 * \param ddxExpected Minimum DDX minor and range of DDX major version required by the driver.
262 * \param drmActual Actual DRM version supplied __driCreateNewScreen.
263 * \param drmExpected Minimum DRM version required by the driver.
265 * \returns \c GL_TRUE if all version requirements are met. Otherwise,
266 * \c GL_FALSE is returned.
268 * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2
271 * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
272 * function and \c driCheckDriDdxDrmVersions2 should be renamed.
275 driCheckDriDdxDrmVersions3(const char * driver_name
,
276 const __DRIversion
* driActual
,
277 const __DRIversion
* driExpected
,
278 const __DRIversion
* ddxActual
,
279 const __DRIutilversion2
* ddxExpected
,
280 const __DRIversion
* drmActual
,
281 const __DRIversion
* drmExpected
)
283 static const char format
[] = "%s DRI driver expected %s version %d.%d.x "
284 "but got version %d.%d.%d\n";
285 static const char format2
[] = "%s DRI driver expected %s version %d-%d.%d.x "
286 "but got version %d.%d.%d\n";
289 /* Check the DRI version */
290 if ( (driActual
->major
!= driExpected
->major
)
291 || (driActual
->minor
< driExpected
->minor
) ) {
292 fprintf(stderr
, format
, driver_name
, "DRI",
293 driExpected
->major
, driExpected
->minor
,
294 driActual
->major
, driActual
->minor
, driActual
->patch
);
298 /* Check that the DDX driver version is compatible */
299 if ( (ddxActual
->major
< ddxExpected
->major_min
)
300 || (ddxActual
->major
> ddxExpected
->major_max
)
301 || (ddxActual
->minor
< ddxExpected
->minor
) ) {
302 fprintf(stderr
, format2
, driver_name
, "DDX",
303 ddxExpected
->major_min
, ddxExpected
->major_max
, ddxExpected
->minor
,
304 ddxActual
->major
, ddxActual
->minor
, ddxActual
->patch
);
308 /* Check that the DRM driver version is compatible */
309 if ( (drmActual
->major
!= drmExpected
->major
)
310 || (drmActual
->minor
< drmExpected
->minor
) ) {
311 fprintf(stderr
, format
, driver_name
, "DRM",
312 drmExpected
->major
, drmExpected
->minor
,
313 drmActual
->major
, drmActual
->minor
, drmActual
->patch
);
321 driCheckDriDdxDrmVersions2(const char * driver_name
,
322 const __DRIversion
* driActual
,
323 const __DRIversion
* driExpected
,
324 const __DRIversion
* ddxActual
,
325 const __DRIversion
* ddxExpected
,
326 const __DRIversion
* drmActual
,
327 const __DRIversion
* drmExpected
)
329 __DRIutilversion2 ddx_expected
;
330 ddx_expected
.major_min
= ddxExpected
->major
;
331 ddx_expected
.major_max
= ddxExpected
->major
;
332 ddx_expected
.minor
= ddxExpected
->minor
;
333 ddx_expected
.patch
= ddxExpected
->patch
;
334 return driCheckDriDdxDrmVersions3(driver_name
, driActual
,
335 driExpected
, ddxActual
, & ddx_expected
,
336 drmActual
, drmExpected
);
339 GLboolean
driClipRectToFramebuffer( const struct gl_framebuffer
*buffer
,
341 GLsizei
*width
, GLsizei
*height
)
344 if (*x
< buffer
->_Xmin
) {
345 *width
-= (buffer
->_Xmin
- *x
);
350 if (*x
+ *width
> buffer
->_Xmax
)
351 *width
-= (*x
+ *width
- buffer
->_Xmax
- 1);
356 /* bottom clipping */
357 if (*y
< buffer
->_Ymin
) {
358 *height
-= (buffer
->_Ymin
- *y
);
363 if (*y
+ *height
> buffer
->_Ymax
)
364 *height
-= (*y
+ *height
- buffer
->_Ymax
- 1);
373 * Creates a set of \c struct gl_config that a driver will expose.
375 * A set of \c struct gl_config will be created based on the supplied
376 * parameters. The number of modes processed will be 2 *
377 * \c num_depth_stencil_bits * \c num_db_modes.
379 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
380 * \c db_modes, and \c visType into each \c struct gl_config element.
381 * However, the meanings of \c fb_format and \c fb_type require further
382 * explanation. The \c fb_format specifies which color components are in
383 * each pixel and what the default order is. For example, \c GL_RGB specifies
384 * that red, green, blue are available and red is in the "most significant"
385 * position and blue is in the "least significant". The \c fb_type specifies
386 * the bit sizes of each component and the actual ordering. For example, if
387 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
388 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
391 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
392 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
393 * \c struct gl_config structure is \b identical to the \c GL_RGBA or
394 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
395 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
396 * still uses 32-bits.
398 * If in doubt, look at the tables used in the function.
400 * \param ptr_to_modes Pointer to a pointer to a linked list of
401 * \c struct gl_config. Upon completion, a pointer to
402 * the next element to be process will be stored here.
403 * If the function fails and returns \c GL_FALSE, this
404 * value will be unmodified, but some elements in the
405 * linked list may be modified.
406 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
407 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
408 * \param fb_type Type of the pixels in the framebuffer. Currently only
409 * \c GL_UNSIGNED_SHORT_5_6_5,
410 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
411 * \c GL_UNSIGNED_INT_8_8_8_8, and
412 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
413 * \param depth_bits Array of depth buffer sizes to be exposed.
414 * \param stencil_bits Array of stencil buffer sizes to be exposed.
415 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
417 * \param db_modes Array of buffer swap modes. If an element has a
418 * value of \c GLX_NONE, then it represents a
419 * single-buffered mode. Other valid values are
420 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
421 * \c GLX_SWAP_UNDEFINED_OML. See the
422 * GLX_OML_swap_method extension spec for more details.
423 * \param num_db_modes Number of entries in \c db_modes.
424 * \param msaa_samples Array of msaa sample count. 0 represents a visual
425 * without a multisample buffer.
426 * \param num_msaa_modes Number of entries in \c msaa_samples.
427 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
428 * \c GLX_DIRECT_COLOR.
431 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
432 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
436 * There is currently no way to support packed RGB modes (i.e., modes with
437 * exactly 3 bytes per pixel) or floating-point modes. This could probably
438 * be done by creating some new, private enums with clever names likes
439 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
440 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
443 driCreateConfigs(GLenum fb_format
, GLenum fb_type
,
444 const uint8_t * depth_bits
, const uint8_t * stencil_bits
,
445 unsigned num_depth_stencil_bits
,
446 const GLenum
* db_modes
, unsigned num_db_modes
,
447 const uint8_t * msaa_samples
, unsigned num_msaa_modes
,
448 GLboolean enable_accum
)
450 static const uint8_t bits_table
[4][4] = {
452 { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
453 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
454 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
455 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
458 static const uint32_t masks_table_rgb
[6][4] = {
459 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
460 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
461 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
462 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
463 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */
464 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
467 static const uint32_t masks_table_rgba
[6][4] = {
468 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
469 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
470 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
471 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
472 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
473 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
476 static const uint32_t masks_table_bgr
[6][4] = {
477 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
478 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
479 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
480 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
481 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
482 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
485 static const uint32_t masks_table_bgra
[6][4] = {
486 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
487 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
488 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
489 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
490 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
491 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
494 static const uint8_t bytes_per_pixel
[6] = {
503 const uint8_t * bits
;
504 const uint32_t * masks
;
506 __DRIconfig
**configs
, **c
;
507 struct gl_config
*modes
;
510 unsigned num_accum_bits
= (enable_accum
) ? 2 : 1;
513 case GL_UNSIGNED_BYTE_3_3_2
:
516 case GL_UNSIGNED_BYTE_2_3_3_REV
:
519 case GL_UNSIGNED_SHORT_5_6_5
:
522 case GL_UNSIGNED_SHORT_5_6_5_REV
:
525 case GL_UNSIGNED_INT_8_8_8_8
:
528 case GL_UNSIGNED_INT_8_8_8_8_REV
:
532 fprintf( stderr
, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
533 __FUNCTION__
, __LINE__
, fb_type
);
538 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
541 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
544 switch ( fb_format
) {
546 masks
= masks_table_rgb
[ index
];
550 masks
= masks_table_rgba
[ index
];
554 masks
= masks_table_bgr
[ index
];
558 masks
= masks_table_bgra
[ index
];
562 fprintf( stderr
, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
563 __FUNCTION__
, __LINE__
, fb_format
);
567 switch ( bytes_per_pixel
[ index
] ) {
569 bits
= bits_table
[0];
572 bits
= bits_table
[1];
575 bits
= ((fb_format
== GL_RGB
) || (fb_format
== GL_BGR
))
581 num_modes
= num_depth_stencil_bits
* num_db_modes
* num_accum_bits
* num_msaa_modes
;
582 configs
= calloc(1, (num_modes
+ 1) * sizeof *configs
);
587 for ( k
= 0 ; k
< num_depth_stencil_bits
; k
++ ) {
588 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
589 for ( h
= 0 ; h
< num_msaa_modes
; h
++ ) {
590 for ( j
= 0 ; j
< num_accum_bits
; j
++ ) {
591 *c
= malloc (sizeof **c
);
592 modes
= &(*c
)->modes
;
595 memset(modes
, 0, sizeof *modes
);
596 modes
->redBits
= bits
[0];
597 modes
->greenBits
= bits
[1];
598 modes
->blueBits
= bits
[2];
599 modes
->alphaBits
= bits
[3];
600 modes
->redMask
= masks
[0];
601 modes
->greenMask
= masks
[1];
602 modes
->blueMask
= masks
[2];
603 modes
->alphaMask
= masks
[3];
604 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
605 + modes
->blueBits
+ modes
->alphaBits
;
607 modes
->accumRedBits
= 16 * j
;
608 modes
->accumGreenBits
= 16 * j
;
609 modes
->accumBlueBits
= 16 * j
;
610 modes
->accumAlphaBits
= (masks
[3] != 0) ? 16 * j
: 0;
611 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
613 modes
->stencilBits
= stencil_bits
[k
];
614 modes
->depthBits
= depth_bits
[k
];
616 modes
->transparentPixel
= GLX_NONE
;
617 modes
->transparentRed
= GLX_DONT_CARE
;
618 modes
->transparentGreen
= GLX_DONT_CARE
;
619 modes
->transparentBlue
= GLX_DONT_CARE
;
620 modes
->transparentAlpha
= GLX_DONT_CARE
;
621 modes
->transparentIndex
= GLX_DONT_CARE
;
622 modes
->rgbMode
= GL_TRUE
;
624 if ( db_modes
[i
] == GLX_NONE
) {
625 modes
->doubleBufferMode
= GL_FALSE
;
628 modes
->doubleBufferMode
= GL_TRUE
;
629 modes
->swapMethod
= db_modes
[i
];
632 modes
->samples
= msaa_samples
[h
];
633 modes
->sampleBuffers
= modes
->samples
? 1 : 0;
636 modes
->haveAccumBuffer
= ((modes
->accumRedBits
+
637 modes
->accumGreenBits
+
638 modes
->accumBlueBits
+
639 modes
->accumAlphaBits
) > 0);
640 modes
->haveDepthBuffer
= (modes
->depthBits
> 0);
641 modes
->haveStencilBuffer
= (modes
->stencilBits
> 0);
643 modes
->bindToTextureRgb
= GL_TRUE
;
644 modes
->bindToTextureRgba
= GL_TRUE
;
645 modes
->bindToMipmapTexture
= GL_FALSE
;
646 modes
->bindToTextureTargets
=
647 __DRI_ATTRIB_TEXTURE_1D_BIT
|
648 __DRI_ATTRIB_TEXTURE_2D_BIT
|
649 __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT
;
651 modes
->sRGBCapable
= GL_FALSE
;
661 __DRIconfig
**driConcatConfigs(__DRIconfig
**a
,
674 all
= malloc((i
+ j
+ 1) * sizeof *all
);
676 for (i
= 0; a
[i
] != NULL
; i
++)
678 for (j
= 0; b
[j
] != NULL
; j
++)
688 #define __ATTRIB(attrib, field) \
689 { attrib, offsetof(struct gl_config, field) }
691 static const struct { unsigned int attrib
, offset
; } attribMap
[] = {
692 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE
, rgbBits
),
693 __ATTRIB(__DRI_ATTRIB_LEVEL
, level
),
694 __ATTRIB(__DRI_ATTRIB_RED_SIZE
, redBits
),
695 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE
, greenBits
),
696 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE
, blueBits
),
697 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE
, alphaBits
),
698 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE
, depthBits
),
699 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE
, stencilBits
),
700 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE
, accumRedBits
),
701 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE
, accumGreenBits
),
702 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE
, accumBlueBits
),
703 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE
, accumAlphaBits
),
704 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS
, sampleBuffers
),
705 __ATTRIB(__DRI_ATTRIB_SAMPLES
, samples
),
706 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER
, doubleBufferMode
),
707 __ATTRIB(__DRI_ATTRIB_STEREO
, stereoMode
),
708 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS
, numAuxBuffers
),
709 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE
, transparentPixel
),
710 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE
, transparentPixel
),
711 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE
, transparentRed
),
712 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE
, transparentGreen
),
713 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE
, transparentBlue
),
714 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE
, transparentAlpha
),
715 __ATTRIB(__DRI_ATTRIB_FLOAT_MODE
, floatMode
),
716 __ATTRIB(__DRI_ATTRIB_RED_MASK
, redMask
),
717 __ATTRIB(__DRI_ATTRIB_GREEN_MASK
, greenMask
),
718 __ATTRIB(__DRI_ATTRIB_BLUE_MASK
, blueMask
),
719 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK
, alphaMask
),
720 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH
, maxPbufferWidth
),
721 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
, maxPbufferHeight
),
722 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS
, maxPbufferPixels
),
723 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH
, optimalPbufferWidth
),
724 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT
, optimalPbufferHeight
),
725 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, swapMethod
),
726 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB
, bindToTextureRgb
),
727 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
, bindToTextureRgba
),
728 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE
, bindToMipmapTexture
),
729 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS
, bindToTextureTargets
),
730 __ATTRIB(__DRI_ATTRIB_YINVERTED
, yInverted
),
731 __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE
, sRGBCapable
),
733 /* The struct field doesn't matter here, these are handled by the
734 * switch in driGetConfigAttribIndex. We need them in the array
735 * so the iterator includes them though.*/
736 __ATTRIB(__DRI_ATTRIB_RENDER_TYPE
, level
),
737 __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT
, level
),
738 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, level
)
741 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
745 * Return the value of a configuration attribute. The attribute is
746 * indicated by the index.
749 driGetConfigAttribIndex(const __DRIconfig
*config
,
750 unsigned int index
, unsigned int *value
)
752 switch (attribMap
[index
].attrib
) {
753 case __DRI_ATTRIB_RENDER_TYPE
:
754 /* no support for color index mode */
755 *value
= __DRI_ATTRIB_RGBA_BIT
;
757 case __DRI_ATTRIB_CONFIG_CAVEAT
:
758 if (config
->modes
.visualRating
== GLX_NON_CONFORMANT_CONFIG
)
759 *value
= __DRI_ATTRIB_NON_CONFORMANT_CONFIG
;
760 else if (config
->modes
.visualRating
== GLX_SLOW_CONFIG
)
761 *value
= __DRI_ATTRIB_SLOW_BIT
;
765 case __DRI_ATTRIB_SWAP_METHOD
:
766 /* XXX no return value??? */
769 case __DRI_ATTRIB_FLOAT_MODE
:
770 /* this field is not int-sized */
771 *value
= config
->modes
.floatMode
;
775 /* any other int-sized field */
776 *value
= *(unsigned int *)
777 ((char *) &config
->modes
+ attribMap
[index
].offset
);
787 * Get the value of a configuration attribute.
788 * \param attrib the attribute (one of the _DRI_ATTRIB_x tokens)
789 * \param value returns the attribute's value
790 * \return 1 for success, 0 for failure
793 driGetConfigAttrib(const __DRIconfig
*config
,
794 unsigned int attrib
, unsigned int *value
)
798 for (i
= 0; i
< ARRAY_SIZE(attribMap
); i
++)
799 if (attribMap
[i
].attrib
== attrib
)
800 return driGetConfigAttribIndex(config
, i
, value
);
807 * Get a configuration attribute name and value, given an index.
808 * \param index which field of the __DRIconfig to query
809 * \param attrib returns the attribute name (one of the _DRI_ATTRIB_x tokens)
810 * \param value returns the attribute's value
811 * \return 1 for success, 0 for failure
814 driIndexConfigAttrib(const __DRIconfig
*config
, int index
,
815 unsigned int *attrib
, unsigned int *value
)
817 if (index
>= 0 && index
< ARRAY_SIZE(attribMap
)) {
818 *attrib
= attribMap
[index
].attrib
;
819 return driGetConfigAttribIndex(config
, index
, value
);