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 driver_date Driver date.
100 * \param agp_mode AGP mode (speed).
103 * The length of the string stored in \c buffer. This does \b not include
104 * the terminating \c NUL character.
107 driGetRendererString( char * buffer
, const char * hardware_name
,
108 const char * driver_date
, GLuint agp_mode
)
113 offset
= sprintf( buffer
, "Mesa DRI %s %s", hardware_name
, driver_date
);
115 /* Append any AGP-specific information.
117 switch ( agp_mode
) {
122 offset
+= sprintf( & buffer
[ offset
], " AGP %ux", agp_mode
);
129 /* Append any CPU-specific information.
131 cpu
= _mesa_get_cpu_string();
133 offset
+= sprintf(buffer
+ offset
, " %s", cpu
);
143 #define need_GL_ARB_copy_buffer
144 #define need_GL_ARB_draw_buffers
145 #define need_GL_ARB_multisample
146 #define need_GL_ARB_texture_compression
147 #define need_GL_ARB_transpose_matrix
148 #define need_GL_ARB_vertex_buffer_object
149 #define need_GL_ARB_window_pos
150 #define need_GL_EXT_compiled_vertex_array
151 #define need_GL_EXT_multi_draw_arrays
152 #define need_GL_EXT_polygon_offset
153 #define need_GL_EXT_texture_object
154 #define need_GL_EXT_vertex_array
155 #define need_GL_IBM_multimode_draw_arrays
156 #define need_GL_MESA_window_pos
158 /* These are needed in *all* drivers because Mesa internally implements
159 * certain functionality in terms of functions provided by these extensions.
160 * For example, glBlendFunc is implemented by calling glBlendFuncSeparateEXT.
162 #define need_GL_EXT_blend_func_separate
163 #define need_GL_NV_vertex_program
165 #include "main/remap_helper.h"
167 static const struct dri_extension all_mesa_extensions
[] = {
168 { "GL_ARB_copy_buffer", GL_ARB_copy_buffer_functions
},
169 { "GL_ARB_draw_buffers", GL_ARB_draw_buffers_functions
},
170 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
171 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
172 { "GL_ARB_transpose_matrix", GL_ARB_transpose_matrix_functions
},
173 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
174 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
175 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
176 { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions
},
177 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
178 { "GL_EXT_polygon_offset", GL_EXT_polygon_offset_functions
},
179 { "GL_EXT_texture_object", GL_EXT_texture_object_functions
},
180 { "GL_EXT_vertex_array", GL_EXT_vertex_array_functions
},
181 { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions
},
182 { "GL_MESA_window_pos", GL_MESA_window_pos_functions
},
183 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
189 * Enable and map extensions supported by the driver.
191 * When ctx is NULL, extensions are not enabled, but their functions
192 * are still mapped. When extensions_to_enable is NULL, all static
193 * functions known to mesa core are mapped.
196 * ARB_imaging isn't handled properly. In Mesa, enabling ARB_imaging also
197 * enables all the sub-extensions that are folded into it. This means that
198 * we need to add entry-points (via \c driInitSingleExtension) for those
199 * new functions here.
201 void driInitExtensions( struct gl_context
* ctx
,
202 const struct dri_extension
* extensions_to_enable
,
203 GLboolean enable_imaging
)
205 static int first_time
= 1;
210 driInitExtensions( NULL
, all_mesa_extensions
, GL_FALSE
);
213 if ( (ctx
!= NULL
) && enable_imaging
) {
214 _mesa_enable_imaging_extensions( ctx
);
217 /* The caller is too lazy to list any extension */
218 if ( extensions_to_enable
== NULL
) {
219 /* Map the static functions. Together with those mapped by remap
220 * table, this should cover everything mesa core knows.
222 _mesa_map_static_functions();
226 for ( i
= 0 ; extensions_to_enable
[i
].name
!= NULL
; i
++ ) {
227 driInitSingleExtension( ctx
, & extensions_to_enable
[i
] );
235 * Enable and map functions for a single extension
237 * \param ctx Context where extension is to be enabled.
238 * \param ext Extension that is to be enabled.
240 * \sa driInitExtensions, _mesa_enable_extension, _mesa_map_function_array
242 void driInitSingleExtension( struct gl_context
* ctx
,
243 const struct dri_extension
* ext
)
245 if ( ext
->functions
!= NULL
) {
246 _mesa_map_function_array(ext
->functions
);
250 _mesa_enable_extension( ctx
, ext
->name
);
256 * Utility function used by drivers to test the verions of other components.
258 * \param driver_name Name of the driver. Used in error messages.
259 * \param driActual Actual DRI version supplied __driCreateNewScreen.
260 * \param driExpected Minimum DRI version required by the driver.
261 * \param ddxActual Actual DDX version supplied __driCreateNewScreen.
262 * \param ddxExpected Minimum DDX minor and range of DDX major version required by the driver.
263 * \param drmActual Actual DRM version supplied __driCreateNewScreen.
264 * \param drmExpected Minimum DRM version required by the driver.
266 * \returns \c GL_TRUE if all version requirements are met. Otherwise,
267 * \c GL_FALSE is returned.
269 * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2
272 * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
273 * function and \c driCheckDriDdxDrmVersions2 should be renamed.
276 driCheckDriDdxDrmVersions3(const char * driver_name
,
277 const __DRIversion
* driActual
,
278 const __DRIversion
* driExpected
,
279 const __DRIversion
* ddxActual
,
280 const __DRIutilversion2
* ddxExpected
,
281 const __DRIversion
* drmActual
,
282 const __DRIversion
* drmExpected
)
284 static const char format
[] = "%s DRI driver expected %s version %d.%d.x "
285 "but got version %d.%d.%d\n";
286 static const char format2
[] = "%s DRI driver expected %s version %d-%d.%d.x "
287 "but got version %d.%d.%d\n";
290 /* Check the DRI version */
291 if ( (driActual
->major
!= driExpected
->major
)
292 || (driActual
->minor
< driExpected
->minor
) ) {
293 fprintf(stderr
, format
, driver_name
, "DRI",
294 driExpected
->major
, driExpected
->minor
,
295 driActual
->major
, driActual
->minor
, driActual
->patch
);
299 /* Check that the DDX driver version is compatible */
300 if ( (ddxActual
->major
< ddxExpected
->major_min
)
301 || (ddxActual
->major
> ddxExpected
->major_max
)
302 || (ddxActual
->minor
< ddxExpected
->minor
) ) {
303 fprintf(stderr
, format2
, driver_name
, "DDX",
304 ddxExpected
->major_min
, ddxExpected
->major_max
, ddxExpected
->minor
,
305 ddxActual
->major
, ddxActual
->minor
, ddxActual
->patch
);
309 /* Check that the DRM driver version is compatible */
310 if ( (drmActual
->major
!= drmExpected
->major
)
311 || (drmActual
->minor
< drmExpected
->minor
) ) {
312 fprintf(stderr
, format
, driver_name
, "DRM",
313 drmExpected
->major
, drmExpected
->minor
,
314 drmActual
->major
, drmActual
->minor
, drmActual
->patch
);
322 driCheckDriDdxDrmVersions2(const char * driver_name
,
323 const __DRIversion
* driActual
,
324 const __DRIversion
* driExpected
,
325 const __DRIversion
* ddxActual
,
326 const __DRIversion
* ddxExpected
,
327 const __DRIversion
* drmActual
,
328 const __DRIversion
* drmExpected
)
330 __DRIutilversion2 ddx_expected
;
331 ddx_expected
.major_min
= ddxExpected
->major
;
332 ddx_expected
.major_max
= ddxExpected
->major
;
333 ddx_expected
.minor
= ddxExpected
->minor
;
334 ddx_expected
.patch
= ddxExpected
->patch
;
335 return driCheckDriDdxDrmVersions3(driver_name
, driActual
,
336 driExpected
, ddxActual
, & ddx_expected
,
337 drmActual
, drmExpected
);
340 GLboolean
driClipRectToFramebuffer( const struct gl_framebuffer
*buffer
,
342 GLsizei
*width
, GLsizei
*height
)
345 if (*x
< buffer
->_Xmin
) {
346 *width
-= (buffer
->_Xmin
- *x
);
351 if (*x
+ *width
> buffer
->_Xmax
)
352 *width
-= (*x
+ *width
- buffer
->_Xmax
- 1);
357 /* bottom clipping */
358 if (*y
< buffer
->_Ymin
) {
359 *height
-= (buffer
->_Ymin
- *y
);
364 if (*y
+ *height
> buffer
->_Ymax
)
365 *height
-= (*y
+ *height
- buffer
->_Ymax
- 1);
374 * Creates a set of \c struct gl_config that a driver will expose.
376 * A set of \c struct gl_config will be created based on the supplied
377 * parameters. The number of modes processed will be 2 *
378 * \c num_depth_stencil_bits * \c num_db_modes.
380 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
381 * \c db_modes, and \c visType into each \c struct gl_config element.
382 * However, the meanings of \c fb_format and \c fb_type require further
383 * explanation. The \c fb_format specifies which color components are in
384 * each pixel and what the default order is. For example, \c GL_RGB specifies
385 * that red, green, blue are available and red is in the "most significant"
386 * position and blue is in the "least significant". The \c fb_type specifies
387 * the bit sizes of each component and the actual ordering. For example, if
388 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
389 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
392 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
393 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
394 * \c struct gl_config structure is \b identical to the \c GL_RGBA or
395 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
396 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
397 * still uses 32-bits.
399 * If in doubt, look at the tables used in the function.
401 * \param ptr_to_modes Pointer to a pointer to a linked list of
402 * \c struct gl_config. Upon completion, a pointer to
403 * the next element to be process will be stored here.
404 * If the function fails and returns \c GL_FALSE, this
405 * value will be unmodified, but some elements in the
406 * linked list may be modified.
407 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
408 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
409 * \param fb_type Type of the pixels in the framebuffer. Currently only
410 * \c GL_UNSIGNED_SHORT_5_6_5,
411 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
412 * \c GL_UNSIGNED_INT_8_8_8_8, and
413 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
414 * \param depth_bits Array of depth buffer sizes to be exposed.
415 * \param stencil_bits Array of stencil buffer sizes to be exposed.
416 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
418 * \param db_modes Array of buffer swap modes. If an element has a
419 * value of \c GLX_NONE, then it represents a
420 * single-buffered mode. Other valid values are
421 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
422 * \c GLX_SWAP_UNDEFINED_OML. See the
423 * GLX_OML_swap_method extension spec for more details.
424 * \param num_db_modes Number of entries in \c db_modes.
425 * \param msaa_samples Array of msaa sample count. 0 represents a visual
426 * without a multisample buffer.
427 * \param num_msaa_modes Number of entries in \c msaa_samples.
428 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
429 * \c GLX_DIRECT_COLOR.
432 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
433 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
437 * There is currently no way to support packed RGB modes (i.e., modes with
438 * exactly 3 bytes per pixel) or floating-point modes. This could probably
439 * be done by creating some new, private enums with clever names likes
440 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
441 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
444 driCreateConfigs(GLenum fb_format
, GLenum fb_type
,
445 const uint8_t * depth_bits
, const uint8_t * stencil_bits
,
446 unsigned num_depth_stencil_bits
,
447 const GLenum
* db_modes
, unsigned num_db_modes
,
448 const uint8_t * msaa_samples
, unsigned num_msaa_modes
,
449 GLboolean enable_accum
)
451 static const uint8_t bits_table
[4][4] = {
453 { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
454 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
455 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
456 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
459 static const uint32_t masks_table_rgb
[6][4] = {
460 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
461 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
462 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
463 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
464 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */
465 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
468 static const uint32_t masks_table_rgba
[6][4] = {
469 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
470 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
471 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
472 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
473 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
474 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
477 static const uint32_t masks_table_bgr
[6][4] = {
478 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
479 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
480 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
481 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
482 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
483 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
486 static const uint32_t masks_table_bgra
[6][4] = {
487 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
488 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
489 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
490 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
491 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
492 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
495 static const uint8_t bytes_per_pixel
[6] = {
504 const uint8_t * bits
;
505 const uint32_t * masks
;
507 __DRIconfig
**configs
, **c
;
508 struct gl_config
*modes
;
511 unsigned num_accum_bits
= (enable_accum
) ? 2 : 1;
514 case GL_UNSIGNED_BYTE_3_3_2
:
517 case GL_UNSIGNED_BYTE_2_3_3_REV
:
520 case GL_UNSIGNED_SHORT_5_6_5
:
523 case GL_UNSIGNED_SHORT_5_6_5_REV
:
526 case GL_UNSIGNED_INT_8_8_8_8
:
529 case GL_UNSIGNED_INT_8_8_8_8_REV
:
533 fprintf( stderr
, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
534 __FUNCTION__
, __LINE__
, fb_type
);
539 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
542 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
545 switch ( fb_format
) {
547 masks
= masks_table_rgb
[ index
];
551 masks
= masks_table_rgba
[ index
];
555 masks
= masks_table_bgr
[ index
];
559 masks
= masks_table_bgra
[ index
];
563 fprintf( stderr
, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
564 __FUNCTION__
, __LINE__
, fb_format
);
568 switch ( bytes_per_pixel
[ index
] ) {
570 bits
= bits_table
[0];
573 bits
= bits_table
[1];
576 bits
= ((fb_format
== GL_RGB
) || (fb_format
== GL_BGR
))
582 num_modes
= num_depth_stencil_bits
* num_db_modes
* num_accum_bits
* num_msaa_modes
;
583 configs
= calloc(1, (num_modes
+ 1) * sizeof *configs
);
588 for ( k
= 0 ; k
< num_depth_stencil_bits
; k
++ ) {
589 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
590 for ( h
= 0 ; h
< num_msaa_modes
; h
++ ) {
591 for ( j
= 0 ; j
< num_accum_bits
; j
++ ) {
592 *c
= malloc (sizeof **c
);
593 modes
= &(*c
)->modes
;
596 memset(modes
, 0, sizeof *modes
);
597 modes
->redBits
= bits
[0];
598 modes
->greenBits
= bits
[1];
599 modes
->blueBits
= bits
[2];
600 modes
->alphaBits
= bits
[3];
601 modes
->redMask
= masks
[0];
602 modes
->greenMask
= masks
[1];
603 modes
->blueMask
= masks
[2];
604 modes
->alphaMask
= masks
[3];
605 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
606 + modes
->blueBits
+ modes
->alphaBits
;
608 modes
->accumRedBits
= 16 * j
;
609 modes
->accumGreenBits
= 16 * j
;
610 modes
->accumBlueBits
= 16 * j
;
611 modes
->accumAlphaBits
= (masks
[3] != 0) ? 16 * j
: 0;
612 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
614 modes
->stencilBits
= stencil_bits
[k
];
615 modes
->depthBits
= depth_bits
[k
];
617 modes
->transparentPixel
= GLX_NONE
;
618 modes
->transparentRed
= GLX_DONT_CARE
;
619 modes
->transparentGreen
= GLX_DONT_CARE
;
620 modes
->transparentBlue
= GLX_DONT_CARE
;
621 modes
->transparentAlpha
= GLX_DONT_CARE
;
622 modes
->transparentIndex
= GLX_DONT_CARE
;
623 modes
->rgbMode
= GL_TRUE
;
625 if ( db_modes
[i
] == GLX_NONE
) {
626 modes
->doubleBufferMode
= GL_FALSE
;
629 modes
->doubleBufferMode
= GL_TRUE
;
630 modes
->swapMethod
= db_modes
[i
];
633 modes
->samples
= msaa_samples
[h
];
634 modes
->sampleBuffers
= modes
->samples
? 1 : 0;
637 modes
->haveAccumBuffer
= ((modes
->accumRedBits
+
638 modes
->accumGreenBits
+
639 modes
->accumBlueBits
+
640 modes
->accumAlphaBits
) > 0);
641 modes
->haveDepthBuffer
= (modes
->depthBits
> 0);
642 modes
->haveStencilBuffer
= (modes
->stencilBits
> 0);
644 modes
->bindToTextureRgb
= GL_TRUE
;
645 modes
->bindToTextureRgba
= GL_TRUE
;
646 modes
->bindToMipmapTexture
= GL_FALSE
;
647 modes
->bindToTextureTargets
=
648 __DRI_ATTRIB_TEXTURE_1D_BIT
|
649 __DRI_ATTRIB_TEXTURE_2D_BIT
|
650 __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT
;
660 __DRIconfig
**driConcatConfigs(__DRIconfig
**a
,
673 all
= malloc((i
+ j
+ 1) * sizeof *all
);
675 for (i
= 0; a
[i
] != NULL
; i
++)
677 for (j
= 0; b
[j
] != NULL
; j
++)
687 #define __ATTRIB(attrib, field) \
688 { attrib, offsetof(struct gl_config, field) }
690 static const struct { unsigned int attrib
, offset
; } attribMap
[] = {
691 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE
, rgbBits
),
692 __ATTRIB(__DRI_ATTRIB_LEVEL
, level
),
693 __ATTRIB(__DRI_ATTRIB_RED_SIZE
, redBits
),
694 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE
, greenBits
),
695 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE
, blueBits
),
696 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE
, alphaBits
),
697 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE
, depthBits
),
698 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE
, stencilBits
),
699 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE
, accumRedBits
),
700 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE
, accumGreenBits
),
701 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE
, accumBlueBits
),
702 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE
, accumAlphaBits
),
703 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS
, sampleBuffers
),
704 __ATTRIB(__DRI_ATTRIB_SAMPLES
, samples
),
705 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER
, doubleBufferMode
),
706 __ATTRIB(__DRI_ATTRIB_STEREO
, stereoMode
),
707 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS
, numAuxBuffers
),
708 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE
, transparentPixel
),
709 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE
, transparentPixel
),
710 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE
, transparentRed
),
711 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE
, transparentGreen
),
712 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE
, transparentBlue
),
713 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE
, transparentAlpha
),
714 __ATTRIB(__DRI_ATTRIB_FLOAT_MODE
, floatMode
),
715 __ATTRIB(__DRI_ATTRIB_RED_MASK
, redMask
),
716 __ATTRIB(__DRI_ATTRIB_GREEN_MASK
, greenMask
),
717 __ATTRIB(__DRI_ATTRIB_BLUE_MASK
, blueMask
),
718 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK
, alphaMask
),
719 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH
, maxPbufferWidth
),
720 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
, maxPbufferHeight
),
721 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS
, maxPbufferPixels
),
722 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH
, optimalPbufferWidth
),
723 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT
, optimalPbufferHeight
),
724 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, swapMethod
),
725 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB
, bindToTextureRgb
),
726 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
, bindToTextureRgba
),
727 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE
, bindToMipmapTexture
),
728 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS
, bindToTextureTargets
),
729 __ATTRIB(__DRI_ATTRIB_YINVERTED
, yInverted
),
731 /* The struct field doesn't matter here, these are handled by the
732 * switch in driGetConfigAttribIndex. We need them in the array
733 * so the iterator includes them though.*/
734 __ATTRIB(__DRI_ATTRIB_RENDER_TYPE
, level
),
735 __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT
, level
),
736 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, level
)
739 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
743 * Return the value of a configuration attribute. The attribute is
744 * indicated by the index.
747 driGetConfigAttribIndex(const __DRIconfig
*config
,
748 unsigned int index
, unsigned int *value
)
750 switch (attribMap
[index
].attrib
) {
751 case __DRI_ATTRIB_RENDER_TYPE
:
752 /* no support for color index mode */
753 *value
= __DRI_ATTRIB_RGBA_BIT
;
755 case __DRI_ATTRIB_CONFIG_CAVEAT
:
756 if (config
->modes
.visualRating
== GLX_NON_CONFORMANT_CONFIG
)
757 *value
= __DRI_ATTRIB_NON_CONFORMANT_CONFIG
;
758 else if (config
->modes
.visualRating
== GLX_SLOW_CONFIG
)
759 *value
= __DRI_ATTRIB_SLOW_BIT
;
763 case __DRI_ATTRIB_SWAP_METHOD
:
764 /* XXX no return value??? */
767 case __DRI_ATTRIB_FLOAT_MODE
:
768 /* this field is not int-sized */
769 *value
= config
->modes
.floatMode
;
773 /* any other int-sized field */
774 *value
= *(unsigned int *)
775 ((char *) &config
->modes
+ attribMap
[index
].offset
);
785 * Get the value of a configuration attribute.
786 * \param attrib the attribute (one of the _DRI_ATTRIB_x tokens)
787 * \param value returns the attribute's value
788 * \return 1 for success, 0 for failure
791 driGetConfigAttrib(const __DRIconfig
*config
,
792 unsigned int attrib
, unsigned int *value
)
796 for (i
= 0; i
< ARRAY_SIZE(attribMap
); i
++)
797 if (attribMap
[i
].attrib
== attrib
)
798 return driGetConfigAttribIndex(config
, i
, value
);
805 * Get a configuration attribute name and value, given an index.
806 * \param index which field of the __DRIconfig to query
807 * \param attrib returns the attribute name (one of the _DRI_ATTRIB_x tokens)
808 * \param value returns the attribute's value
809 * \return 1 for success, 0 for failure
812 driIndexConfigAttrib(const __DRIconfig
*config
, int index
,
813 unsigned int *attrib
, unsigned int *value
)
815 if (index
>= 0 && index
< ARRAY_SIZE(attribMap
)) {
816 *attrib
= attribMap
[index
].attrib
;
817 return driGetConfigAttribIndex(config
, index
, value
);