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/extensions.h"
36 #include "glapi/dispatch.h"
39 int driDispatchRemapTable
[ driDispatchRemapTable_size
];
41 #if defined(USE_X86_ASM)
42 #include "x86/common_x86_asm.h"
45 #if defined(USE_PPC_ASM)
46 #include "ppc/common_ppc_features.h"
50 driParseDebugString( const char * debug
,
51 const struct dri_debug_control
* control
)
57 if ( debug
!= NULL
) {
58 while( control
->string
!= NULL
) {
59 if ( !strcmp( debug
, "all" ) ||
60 strstr( debug
, control
->string
) != NULL
) {
61 flag
|= control
->flag
;
74 * Create the \c GL_RENDERER string for DRI drivers.
76 * Almost all DRI drivers use a \c GL_RENDERER string of the form:
78 * "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
80 * Using the supplied chip name, driver data, and AGP speed, this function
83 * \param buffer Buffer to hold the \c GL_RENDERER string.
84 * \param hardware_name Name of the hardware.
85 * \param driver_date Driver date.
86 * \param agp_mode AGP mode (speed).
89 * The length of the string stored in \c buffer. This does \b not include
90 * the terminating \c NUL character.
93 driGetRendererString( char * buffer
, const char * hardware_name
,
94 const char * driver_date
, GLuint agp_mode
)
97 const char * cpu
[MAX_INFO
];
103 offset
= sprintf( buffer
, "Mesa DRI %s %s", hardware_name
, driver_date
);
105 /* Append any AGP-specific information.
107 switch ( agp_mode
) {
112 offset
+= sprintf( & buffer
[ offset
], " AGP %ux", agp_mode
);
119 /* Append any CPU-specific information.
122 if ( _mesa_x86_cpu_features
) {
128 cpu
[next
] = (cpu_has_mmxext
) ? "/MMX+" : "/MMX";
132 # ifdef USE_3DNOW_ASM
133 if ( cpu_has_3dnow
) {
134 cpu
[next
] = (cpu_has_3dnowext
) ? "/3DNow!+" : "/3DNow!";
140 cpu
[next
] = (cpu_has_xmm2
) ? "/SSE2" : "/SSE";
145 #elif defined(USE_SPARC_ASM)
150 #elif defined(USE_PPC_ASM)
151 if ( _mesa_ppc_cpu_features
) {
152 cpu
[next
] = (cpu_has_64
) ? " PowerPC 64" : " PowerPC";
158 cpu
[next
] = "/Altivec";
163 if ( ! cpu_has_fpu
) {
164 cpu
[next
] = "/No FPU";
169 for ( i
= 0 ; i
< next
; i
++ ) {
170 const size_t len
= strlen( cpu
[i
] );
172 strncpy( & buffer
[ offset
], cpu
[i
], len
);
182 #define need_GL_ARB_multisample
183 #define need_GL_ARB_transpose_matrix
184 #define need_GL_ARB_window_pos
185 #define need_GL_EXT_compiled_vertex_array
186 #define need_GL_EXT_polygon_offset
187 #define need_GL_EXT_texture_object
188 #define need_GL_EXT_vertex_array
189 #define need_GL_MESA_window_pos
191 /* These are needed in *all* drivers because Mesa internally implements
192 * certain functionality in terms of functions provided by these extensions.
193 * For example, glBlendFunc is implemented by calling glBlendFuncSeparateEXT.
195 #define need_GL_EXT_blend_func_separate
196 #define need_GL_NV_vertex_program
198 #include "extension_helper.h"
200 static const struct dri_extension all_mesa_extensions
[] = {
201 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
202 { "GL_ARB_transpose_matrix", GL_ARB_transpose_matrix_functions
},
203 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
204 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
205 { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions
},
206 { "GL_EXT_polygon_offset", GL_EXT_polygon_offset_functions
},
207 { "GL_EXT_texture_object", GL_EXT_texture_object_functions
},
208 { "GL_EXT_vertex_array", GL_EXT_vertex_array_functions
},
209 { "GL_MESA_window_pos", GL_MESA_window_pos_functions
},
210 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
216 * Enable extensions supported by the driver.
219 * ARB_imaging isn't handled properly. In Mesa, enabling ARB_imaging also
220 * enables all the sub-extensions that are folded into it. This means that
221 * we need to add entry-points (via \c driInitSingleExtension) for those
222 * new functions here.
224 void driInitExtensions( GLcontext
* ctx
,
225 const struct dri_extension
* extensions_to_enable
,
226 GLboolean enable_imaging
)
228 static int first_time
= 1;
232 for ( i
= 0 ; i
< driDispatchRemapTable_size
; i
++ ) {
233 driDispatchRemapTable
[i
] = -1;
237 driInitExtensions( ctx
, all_mesa_extensions
, GL_FALSE
);
240 if ( (ctx
!= NULL
) && enable_imaging
) {
241 _mesa_enable_imaging_extensions( ctx
);
244 for ( i
= 0 ; extensions_to_enable
[i
].name
!= NULL
; i
++ ) {
245 driInitSingleExtension( ctx
, & extensions_to_enable
[i
] );
253 * Enable and add dispatch functions for a single extension
255 * \param ctx Context where extension is to be enabled.
256 * \param ext Extension that is to be enabled.
258 * \sa driInitExtensions, _mesa_enable_extension, _glapi_add_entrypoint
261 * Determine if it would be better to use \c strlen instead of the hardcoded
264 void driInitSingleExtension( GLcontext
* ctx
,
265 const struct dri_extension
* ext
)
270 if ( ext
->functions
!= NULL
) {
271 for ( i
= 0 ; ext
->functions
[i
].strings
!= NULL
; i
++ ) {
272 const char * functions
[16];
273 const char * parameter_signature
;
274 const char * str
= ext
->functions
[i
].strings
;
279 /* Separate the parameter signature from the rest of the string.
280 * If the parameter signature is empty (i.e., the string starts
281 * with a NUL character), then the function has a void parameter
284 parameter_signature
= str
;
285 while ( str
[0] != '\0' ) {
291 /* Divide the string into the substrings that name each
292 * entry-point for the function.
294 for ( j
= 0 ; j
< 16 ; j
++ ) {
295 if ( str
[0] == '\0' ) {
302 while ( str
[0] != '\0' ) {
309 /* Add each entry-point to the dispatch table.
311 offset
= _glapi_add_dispatch( functions
, parameter_signature
);
313 #if 0 /* this causes noise with egl */
314 fprintf(stderr
, "DISPATCH ERROR! _glapi_add_dispatch failed "
315 "to add %s!\n", functions
[0]);
318 else if (ext
->functions
[i
].remap_index
!= -1) {
319 driDispatchRemapTable
[ ext
->functions
[i
].remap_index
] =
322 else if (ext
->functions
[i
].offset
!= offset
) {
323 fprintf(stderr
, "DISPATCH ERROR! %s -> %u != %u\n",
324 functions
[0], offset
, ext
->functions
[i
].offset
);
330 _mesa_enable_extension( ctx
, ext
->name
);
336 * Utility function used by drivers to test the verions of other components.
338 * If one of the version requirements is not met, a message is logged using
339 * \c __driUtilMessage.
341 * \param driver_name Name of the driver. Used in error messages.
342 * \param driActual Actual DRI version supplied __driCreateNewScreen.
343 * \param driExpected Minimum DRI version required by the driver.
344 * \param ddxActual Actual DDX version supplied __driCreateNewScreen.
345 * \param ddxExpected Minimum DDX minor and range of DDX major version required by the driver.
346 * \param drmActual Actual DRM version supplied __driCreateNewScreen.
347 * \param drmExpected Minimum DRM version required by the driver.
349 * \returns \c GL_TRUE if all version requirements are met. Otherwise,
350 * \c GL_FALSE is returned.
352 * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2, __driUtilMessage
355 * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
356 * function and \c driCheckDriDdxDrmVersions2 should be renamed.
359 driCheckDriDdxDrmVersions3(const char * driver_name
,
360 const __DRIversion
* driActual
,
361 const __DRIversion
* driExpected
,
362 const __DRIversion
* ddxActual
,
363 const __DRIutilversion2
* ddxExpected
,
364 const __DRIversion
* drmActual
,
365 const __DRIversion
* drmExpected
)
367 static const char format
[] = "%s DRI driver expected %s version %d.%d.x "
368 "but got version %d.%d.%d\n";
369 static const char format2
[] = "%s DRI driver expected %s version %d-%d.%d.x "
370 "but got version %d.%d.%d\n";
373 /* Check the DRI version */
374 if ( (driActual
->major
!= driExpected
->major
)
375 || (driActual
->minor
< driExpected
->minor
) ) {
376 fprintf(stderr
, format
, driver_name
, "DRI",
377 driExpected
->major
, driExpected
->minor
,
378 driActual
->major
, driActual
->minor
, driActual
->patch
);
382 /* Check that the DDX driver version is compatible */
383 /* for miniglx we pass in -1 so we can ignore the DDX version */
384 if ( (ddxActual
->major
!= -1) && ((ddxActual
->major
< ddxExpected
->major_min
)
385 || (ddxActual
->major
> ddxExpected
->major_max
)
386 || (ddxActual
->minor
< ddxExpected
->minor
)) ) {
387 fprintf(stderr
, format2
, driver_name
, "DDX",
388 ddxExpected
->major_min
, ddxExpected
->major_max
, ddxExpected
->minor
,
389 ddxActual
->major
, ddxActual
->minor
, ddxActual
->patch
);
393 /* Check that the DRM driver version is compatible */
394 if ( (drmActual
->major
!= drmExpected
->major
)
395 || (drmActual
->minor
< drmExpected
->minor
) ) {
396 fprintf(stderr
, format
, driver_name
, "DRM",
397 drmExpected
->major
, drmExpected
->minor
,
398 drmActual
->major
, drmActual
->minor
, drmActual
->patch
);
406 driCheckDriDdxDrmVersions2(const char * driver_name
,
407 const __DRIversion
* driActual
,
408 const __DRIversion
* driExpected
,
409 const __DRIversion
* ddxActual
,
410 const __DRIversion
* ddxExpected
,
411 const __DRIversion
* drmActual
,
412 const __DRIversion
* drmExpected
)
414 __DRIutilversion2 ddx_expected
;
415 ddx_expected
.major_min
= ddxExpected
->major
;
416 ddx_expected
.major_max
= ddxExpected
->major
;
417 ddx_expected
.minor
= ddxExpected
->minor
;
418 ddx_expected
.patch
= ddxExpected
->patch
;
419 return driCheckDriDdxDrmVersions3(driver_name
, driActual
,
420 driExpected
, ddxActual
, & ddx_expected
,
421 drmActual
, drmExpected
);
424 GLboolean
driClipRectToFramebuffer( const GLframebuffer
*buffer
,
426 GLsizei
*width
, GLsizei
*height
)
429 if (*x
< buffer
->_Xmin
) {
430 *width
-= (buffer
->_Xmin
- *x
);
435 if (*x
+ *width
> buffer
->_Xmax
)
436 *width
-= (*x
+ *width
- buffer
->_Xmax
- 1);
441 /* bottom clipping */
442 if (*y
< buffer
->_Ymin
) {
443 *height
-= (buffer
->_Ymin
- *y
);
448 if (*y
+ *height
> buffer
->_Ymax
)
449 *height
-= (*y
+ *height
- buffer
->_Ymax
- 1);
458 * Creates a set of \c __GLcontextModes that a driver will expose.
460 * A set of \c __GLcontextModes will be created based on the supplied
461 * parameters. The number of modes processed will be 2 *
462 * \c num_depth_stencil_bits * \c num_db_modes.
464 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
465 * \c db_modes, and \c visType into each \c __GLcontextModes element.
466 * However, the meanings of \c fb_format and \c fb_type require further
467 * explanation. The \c fb_format specifies which color components are in
468 * each pixel and what the default order is. For example, \c GL_RGB specifies
469 * that red, green, blue are available and red is in the "most significant"
470 * position and blue is in the "least significant". The \c fb_type specifies
471 * the bit sizes of each component and the actual ordering. For example, if
472 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
473 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
476 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
477 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
478 * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
479 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
480 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
481 * still uses 32-bits.
483 * If in doubt, look at the tables used in the function.
485 * \param ptr_to_modes Pointer to a pointer to a linked list of
486 * \c __GLcontextModes. Upon completion, a pointer to
487 * the next element to be process will be stored here.
488 * If the function fails and returns \c GL_FALSE, this
489 * value will be unmodified, but some elements in the
490 * linked list may be modified.
491 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
492 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
493 * \param fb_type Type of the pixels in the framebuffer. Currently only
494 * \c GL_UNSIGNED_SHORT_5_6_5,
495 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
496 * \c GL_UNSIGNED_INT_8_8_8_8, and
497 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
498 * \param depth_bits Array of depth buffer sizes to be exposed.
499 * \param stencil_bits Array of stencil buffer sizes to be exposed.
500 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
502 * \param db_modes Array of buffer swap modes. If an element has a
503 * value of \c GLX_NONE, then it represents a
504 * single-buffered mode. Other valid values are
505 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
506 * \c GLX_SWAP_UNDEFINED_OML. See the
507 * GLX_OML_swap_method extension spec for more details.
508 * \param num_db_modes Number of entries in \c db_modes.
509 * \param msaa_samples Array of msaa sample count. 0 represents a visual
510 * without a multisample buffer.
511 * \param num_msaa_modes Number of entries in \c msaa_samples.
512 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
513 * \c GLX_DIRECT_COLOR.
516 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
517 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
521 * There is currently no way to support packed RGB modes (i.e., modes with
522 * exactly 3 bytes per pixel) or floating-point modes. This could probably
523 * be done by creating some new, private enums with clever names likes
524 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
525 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
528 driCreateConfigs(GLenum fb_format
, GLenum fb_type
,
529 const uint8_t * depth_bits
, const uint8_t * stencil_bits
,
530 unsigned num_depth_stencil_bits
,
531 const GLenum
* db_modes
, unsigned num_db_modes
,
532 const u_int8_t
* msaa_samples
, unsigned num_msaa_modes
)
534 static const uint8_t bits_table
[4][4] = {
536 { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
537 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
538 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
539 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
542 static const uint32_t masks_table_rgb
[6][4] = {
543 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
544 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
545 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
546 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
547 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */
548 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
551 static const uint32_t masks_table_rgba
[6][4] = {
552 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
553 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
554 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
555 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
556 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
557 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
560 static const uint32_t masks_table_bgr
[6][4] = {
561 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
562 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
563 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
564 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
565 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
566 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
569 static const uint32_t masks_table_bgra
[6][4] = {
570 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
571 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
572 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
573 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
574 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
575 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
578 static const uint8_t bytes_per_pixel
[6] = {
587 const uint8_t * bits
;
588 const uint32_t * masks
;
590 __DRIconfig
**configs
, **c
;
591 __GLcontextModes
*modes
;
594 unsigned num_accum_bits
= 2;
597 case GL_UNSIGNED_BYTE_3_3_2
:
600 case GL_UNSIGNED_BYTE_2_3_3_REV
:
603 case GL_UNSIGNED_SHORT_5_6_5
:
606 case GL_UNSIGNED_SHORT_5_6_5_REV
:
609 case GL_UNSIGNED_INT_8_8_8_8
:
612 case GL_UNSIGNED_INT_8_8_8_8_REV
:
616 fprintf( stderr
, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
617 __FUNCTION__
, __LINE__
, fb_type
);
622 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
625 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
628 switch ( fb_format
) {
630 masks
= masks_table_rgb
[ index
];
634 masks
= masks_table_rgba
[ index
];
638 masks
= masks_table_bgr
[ index
];
642 masks
= masks_table_bgra
[ index
];
646 fprintf( stderr
, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
647 __FUNCTION__
, __LINE__
, fb_format
);
651 switch ( bytes_per_pixel
[ index
] ) {
653 bits
= bits_table
[0];
656 bits
= bits_table
[1];
659 bits
= ((fb_format
== GL_RGB
) || (fb_format
== GL_BGR
))
665 num_modes
= num_depth_stencil_bits
* num_db_modes
* num_accum_bits
* num_msaa_modes
;
666 configs
= _mesa_calloc((num_modes
+ 1) * sizeof *configs
);
671 for ( k
= 0 ; k
< num_depth_stencil_bits
; k
++ ) {
672 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
673 for ( h
= 0 ; h
< num_msaa_modes
; h
++ ) {
674 for ( j
= 0 ; j
< num_accum_bits
; j
++ ) {
675 *c
= _mesa_malloc (sizeof **c
);
676 modes
= &(*c
)->modes
;
679 memset(modes
, 0, sizeof *modes
);
680 modes
->redBits
= bits
[0];
681 modes
->greenBits
= bits
[1];
682 modes
->blueBits
= bits
[2];
683 modes
->alphaBits
= bits
[3];
684 modes
->redMask
= masks
[0];
685 modes
->greenMask
= masks
[1];
686 modes
->blueMask
= masks
[2];
687 modes
->alphaMask
= masks
[3];
688 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
689 + modes
->blueBits
+ modes
->alphaBits
;
691 modes
->accumRedBits
= 16 * j
;
692 modes
->accumGreenBits
= 16 * j
;
693 modes
->accumBlueBits
= 16 * j
;
694 modes
->accumAlphaBits
= (masks
[3] != 0) ? 16 * j
: 0;
695 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
697 modes
->stencilBits
= stencil_bits
[k
];
698 modes
->depthBits
= depth_bits
[k
];
700 modes
->transparentPixel
= GLX_NONE
;
701 modes
->transparentRed
= GLX_DONT_CARE
;
702 modes
->transparentGreen
= GLX_DONT_CARE
;
703 modes
->transparentBlue
= GLX_DONT_CARE
;
704 modes
->transparentAlpha
= GLX_DONT_CARE
;
705 modes
->transparentIndex
= GLX_DONT_CARE
;
706 modes
->visualType
= GLX_DONT_CARE
;
707 modes
->renderType
= GLX_RGBA_BIT
;
708 modes
->drawableType
= GLX_WINDOW_BIT
;
709 modes
->rgbMode
= GL_TRUE
;
711 if ( db_modes
[i
] == GLX_NONE
) {
712 modes
->doubleBufferMode
= GL_FALSE
;
715 modes
->doubleBufferMode
= GL_TRUE
;
716 modes
->swapMethod
= db_modes
[i
];
719 modes
->samples
= msaa_samples
[h
];
720 modes
->sampleBuffers
= modes
->samples
? 1 : 0;
723 modes
->haveAccumBuffer
= ((modes
->accumRedBits
+
724 modes
->accumGreenBits
+
725 modes
->accumBlueBits
+
726 modes
->accumAlphaBits
) > 0);
727 modes
->haveDepthBuffer
= (modes
->depthBits
> 0);
728 modes
->haveStencilBuffer
= (modes
->stencilBits
> 0);
730 modes
->bindToTextureRgb
= GL_TRUE
;
731 modes
->bindToTextureRgba
= GL_TRUE
;
732 modes
->bindToMipmapTexture
= GL_FALSE
;
733 modes
->bindToTextureTargets
= modes
->rgbMode
?
734 __DRI_ATTRIB_TEXTURE_1D_BIT
|
735 __DRI_ATTRIB_TEXTURE_2D_BIT
|
736 __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT
:
747 const __DRIconfig
**driConcatConfigs(__DRIconfig
**a
, __DRIconfig
**b
)
749 const __DRIconfig
**all
;
759 all
= _mesa_malloc((i
+ j
+ 1) * sizeof *all
);
761 for (i
= 0; a
[i
] != NULL
; i
++)
763 for (j
= 0; b
[j
] != NULL
; j
++)
773 #define __ATTRIB(attrib, field) \
774 { attrib, offsetof(__GLcontextModes, field) }
776 static const struct { unsigned int attrib
, offset
; } attribMap
[] = {
777 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE
, rgbBits
),
778 __ATTRIB(__DRI_ATTRIB_LEVEL
, level
),
779 __ATTRIB(__DRI_ATTRIB_RED_SIZE
, redBits
),
780 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE
, greenBits
),
781 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE
, blueBits
),
782 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE
, alphaBits
),
783 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE
, depthBits
),
784 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE
, stencilBits
),
785 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE
, accumRedBits
),
786 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE
, accumGreenBits
),
787 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE
, accumBlueBits
),
788 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE
, accumAlphaBits
),
789 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS
, sampleBuffers
),
790 __ATTRIB(__DRI_ATTRIB_SAMPLES
, samples
),
791 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER
, doubleBufferMode
),
792 __ATTRIB(__DRI_ATTRIB_STEREO
, stereoMode
),
793 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS
, numAuxBuffers
),
794 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE
, transparentPixel
),
795 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE
, transparentPixel
),
796 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE
, transparentRed
),
797 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE
, transparentGreen
),
798 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE
, transparentBlue
),
799 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE
, transparentAlpha
),
800 __ATTRIB(__DRI_ATTRIB_FLOAT_MODE
, floatMode
),
801 __ATTRIB(__DRI_ATTRIB_RED_MASK
, redMask
),
802 __ATTRIB(__DRI_ATTRIB_GREEN_MASK
, greenMask
),
803 __ATTRIB(__DRI_ATTRIB_BLUE_MASK
, blueMask
),
804 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK
, alphaMask
),
805 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH
, maxPbufferWidth
),
806 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
, maxPbufferHeight
),
807 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS
, maxPbufferPixels
),
808 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH
, optimalPbufferWidth
),
809 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT
, optimalPbufferHeight
),
810 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, swapMethod
),
811 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB
, bindToTextureRgb
),
812 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
, bindToTextureRgba
),
813 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE
, bindToMipmapTexture
),
814 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS
, bindToTextureTargets
),
815 __ATTRIB(__DRI_ATTRIB_YINVERTED
, yInverted
),
817 /* The struct field doesn't matter here, these are handled by the
818 * switch in driGetConfigAttribIndex. We need them in the array
819 * so the iterator includes them though.*/
820 __ATTRIB(__DRI_ATTRIB_RENDER_TYPE
, level
),
821 __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT
, level
),
822 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, level
)
825 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
828 driGetConfigAttribIndex(const __DRIconfig
*config
,
829 unsigned int index
, unsigned int *value
)
831 switch (attribMap
[index
].attrib
) {
832 case __DRI_ATTRIB_RENDER_TYPE
:
833 if (config
->modes
.rgbMode
)
834 *value
= __DRI_ATTRIB_RGBA_BIT
;
836 *value
= __DRI_ATTRIB_COLOR_INDEX_BIT
;
838 case __DRI_ATTRIB_CONFIG_CAVEAT
:
839 if (config
->modes
.visualRating
== GLX_NON_CONFORMANT_CONFIG
)
840 *value
= __DRI_ATTRIB_NON_CONFORMANT_CONFIG
;
841 else if (config
->modes
.visualRating
== GLX_SLOW_CONFIG
)
842 *value
= __DRI_ATTRIB_SLOW_BIT
;
846 case __DRI_ATTRIB_SWAP_METHOD
:
849 case __DRI_ATTRIB_FLOAT_MODE
:
850 *value
= config
->modes
.floatMode
;
854 *value
= *(unsigned int *)
855 ((char *) &config
->modes
+ attribMap
[index
].offset
);
864 driGetConfigAttrib(const __DRIconfig
*config
,
865 unsigned int attrib
, unsigned int *value
)
869 for (i
= 0; i
< ARRAY_SIZE(attribMap
); i
++)
870 if (attribMap
[i
].attrib
== attrib
)
871 return driGetConfigAttribIndex(config
, i
, value
);
877 driIndexConfigAttrib(const __DRIconfig
*config
, int index
,
878 unsigned int *attrib
, unsigned int *value
)
880 if (index
>= 0 && index
< ARRAY_SIZE(attribMap
)) {
881 *attrib
= attribMap
[index
].attrib
;
882 return driGetConfigAttribIndex(config
, index
, value
);