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_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_draw_buffers", GL_ARB_draw_buffers_functions
},
168 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
169 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
170 { "GL_ARB_transpose_matrix", GL_ARB_transpose_matrix_functions
},
171 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
172 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
173 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
174 { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions
},
175 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
176 { "GL_EXT_polygon_offset", GL_EXT_polygon_offset_functions
},
177 { "GL_EXT_texture_object", GL_EXT_texture_object_functions
},
178 { "GL_EXT_vertex_array", GL_EXT_vertex_array_functions
},
179 { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions
},
180 { "GL_MESA_window_pos", GL_MESA_window_pos_functions
},
181 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
187 * Enable and map extensions supported by the driver.
189 * When ctx is NULL, extensions are not enabled, but their functions
190 * are still mapped. When extensions_to_enable is NULL, all static
191 * functions known to mesa core are mapped.
194 * ARB_imaging isn't handled properly. In Mesa, enabling ARB_imaging also
195 * enables all the sub-extensions that are folded into it. This means that
196 * we need to add entry-points (via \c driInitSingleExtension) for those
197 * new functions here.
199 void driInitExtensions( GLcontext
* ctx
,
200 const struct dri_extension
* extensions_to_enable
,
201 GLboolean enable_imaging
)
203 static int first_time
= 1;
208 driInitExtensions( NULL
, all_mesa_extensions
, GL_FALSE
);
211 if ( (ctx
!= NULL
) && enable_imaging
) {
212 _mesa_enable_imaging_extensions( ctx
);
215 /* The caller is too lazy to list any extension */
216 if ( extensions_to_enable
== NULL
) {
217 /* Map the static functions. Together with those mapped by remap
218 * table, this should cover everything mesa core knows.
220 _mesa_map_static_functions();
224 for ( i
= 0 ; extensions_to_enable
[i
].name
!= NULL
; i
++ ) {
225 driInitSingleExtension( ctx
, & extensions_to_enable
[i
] );
233 * Enable and map functions for a single extension
235 * \param ctx Context where extension is to be enabled.
236 * \param ext Extension that is to be enabled.
238 * \sa driInitExtensions, _mesa_enable_extension, _mesa_map_function_array
240 void driInitSingleExtension( GLcontext
* ctx
,
241 const struct dri_extension
* ext
)
243 if ( ext
->functions
!= NULL
) {
244 _mesa_map_function_array(ext
->functions
);
248 _mesa_enable_extension( ctx
, ext
->name
);
254 * Utility function used by drivers to test the verions of other components.
256 * \param driver_name Name of the driver. Used in error messages.
257 * \param driActual Actual DRI version supplied __driCreateNewScreen.
258 * \param driExpected Minimum DRI version required by the driver.
259 * \param ddxActual Actual DDX version supplied __driCreateNewScreen.
260 * \param ddxExpected Minimum DDX minor and range of DDX major version required by the driver.
261 * \param drmActual Actual DRM version supplied __driCreateNewScreen.
262 * \param drmExpected Minimum DRM version required by the driver.
264 * \returns \c GL_TRUE if all version requirements are met. Otherwise,
265 * \c GL_FALSE is returned.
267 * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2
270 * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
271 * function and \c driCheckDriDdxDrmVersions2 should be renamed.
274 driCheckDriDdxDrmVersions3(const char * driver_name
,
275 const __DRIversion
* driActual
,
276 const __DRIversion
* driExpected
,
277 const __DRIversion
* ddxActual
,
278 const __DRIutilversion2
* ddxExpected
,
279 const __DRIversion
* drmActual
,
280 const __DRIversion
* drmExpected
)
282 static const char format
[] = "%s DRI driver expected %s version %d.%d.x "
283 "but got version %d.%d.%d\n";
284 static const char format2
[] = "%s DRI driver expected %s version %d-%d.%d.x "
285 "but got version %d.%d.%d\n";
288 /* Check the DRI version */
289 if ( (driActual
->major
!= driExpected
->major
)
290 || (driActual
->minor
< driExpected
->minor
) ) {
291 fprintf(stderr
, format
, driver_name
, "DRI",
292 driExpected
->major
, driExpected
->minor
,
293 driActual
->major
, driActual
->minor
, driActual
->patch
);
297 /* Check that the DDX driver version is compatible */
298 if ( (ddxActual
->major
< ddxExpected
->major_min
)
299 || (ddxActual
->major
> ddxExpected
->major_max
)
300 || (ddxActual
->minor
< ddxExpected
->minor
) ) {
301 fprintf(stderr
, format2
, driver_name
, "DDX",
302 ddxExpected
->major_min
, ddxExpected
->major_max
, ddxExpected
->minor
,
303 ddxActual
->major
, ddxActual
->minor
, ddxActual
->patch
);
307 /* Check that the DRM driver version is compatible */
308 if ( (drmActual
->major
!= drmExpected
->major
)
309 || (drmActual
->minor
< drmExpected
->minor
) ) {
310 fprintf(stderr
, format
, driver_name
, "DRM",
311 drmExpected
->major
, drmExpected
->minor
,
312 drmActual
->major
, drmActual
->minor
, drmActual
->patch
);
320 driCheckDriDdxDrmVersions2(const char * driver_name
,
321 const __DRIversion
* driActual
,
322 const __DRIversion
* driExpected
,
323 const __DRIversion
* ddxActual
,
324 const __DRIversion
* ddxExpected
,
325 const __DRIversion
* drmActual
,
326 const __DRIversion
* drmExpected
)
328 __DRIutilversion2 ddx_expected
;
329 ddx_expected
.major_min
= ddxExpected
->major
;
330 ddx_expected
.major_max
= ddxExpected
->major
;
331 ddx_expected
.minor
= ddxExpected
->minor
;
332 ddx_expected
.patch
= ddxExpected
->patch
;
333 return driCheckDriDdxDrmVersions3(driver_name
, driActual
,
334 driExpected
, ddxActual
, & ddx_expected
,
335 drmActual
, drmExpected
);
338 GLboolean
driClipRectToFramebuffer( const GLframebuffer
*buffer
,
340 GLsizei
*width
, GLsizei
*height
)
343 if (*x
< buffer
->_Xmin
) {
344 *width
-= (buffer
->_Xmin
- *x
);
349 if (*x
+ *width
> buffer
->_Xmax
)
350 *width
-= (*x
+ *width
- buffer
->_Xmax
- 1);
355 /* bottom clipping */
356 if (*y
< buffer
->_Ymin
) {
357 *height
-= (buffer
->_Ymin
- *y
);
362 if (*y
+ *height
> buffer
->_Ymax
)
363 *height
-= (*y
+ *height
- buffer
->_Ymax
- 1);
372 * Creates a set of \c __GLcontextModes that a driver will expose.
374 * A set of \c __GLcontextModes will be created based on the supplied
375 * parameters. The number of modes processed will be 2 *
376 * \c num_depth_stencil_bits * \c num_db_modes.
378 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
379 * \c db_modes, and \c visType into each \c __GLcontextModes element.
380 * However, the meanings of \c fb_format and \c fb_type require further
381 * explanation. The \c fb_format specifies which color components are in
382 * each pixel and what the default order is. For example, \c GL_RGB specifies
383 * that red, green, blue are available and red is in the "most significant"
384 * position and blue is in the "least significant". The \c fb_type specifies
385 * the bit sizes of each component and the actual ordering. For example, if
386 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
387 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
390 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
391 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
392 * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
393 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
394 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
395 * still uses 32-bits.
397 * If in doubt, look at the tables used in the function.
399 * \param ptr_to_modes Pointer to a pointer to a linked list of
400 * \c __GLcontextModes. Upon completion, a pointer to
401 * the next element to be process will be stored here.
402 * If the function fails and returns \c GL_FALSE, this
403 * value will be unmodified, but some elements in the
404 * linked list may be modified.
405 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
406 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
407 * \param fb_type Type of the pixels in the framebuffer. Currently only
408 * \c GL_UNSIGNED_SHORT_5_6_5,
409 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
410 * \c GL_UNSIGNED_INT_8_8_8_8, and
411 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
412 * \param depth_bits Array of depth buffer sizes to be exposed.
413 * \param stencil_bits Array of stencil buffer sizes to be exposed.
414 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
416 * \param db_modes Array of buffer swap modes. If an element has a
417 * value of \c GLX_NONE, then it represents a
418 * single-buffered mode. Other valid values are
419 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
420 * \c GLX_SWAP_UNDEFINED_OML. See the
421 * GLX_OML_swap_method extension spec for more details.
422 * \param num_db_modes Number of entries in \c db_modes.
423 * \param msaa_samples Array of msaa sample count. 0 represents a visual
424 * without a multisample buffer.
425 * \param num_msaa_modes Number of entries in \c msaa_samples.
426 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
427 * \c GLX_DIRECT_COLOR.
430 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
431 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
435 * There is currently no way to support packed RGB modes (i.e., modes with
436 * exactly 3 bytes per pixel) or floating-point modes. This could probably
437 * be done by creating some new, private enums with clever names likes
438 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
439 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
442 driCreateConfigs(GLenum fb_format
, GLenum fb_type
,
443 const uint8_t * depth_bits
, const uint8_t * stencil_bits
,
444 unsigned num_depth_stencil_bits
,
445 const GLenum
* db_modes
, unsigned num_db_modes
,
446 const uint8_t * msaa_samples
, unsigned num_msaa_modes
,
447 GLboolean enable_accum
)
449 static const uint8_t bits_table
[4][4] = {
451 { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
452 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
453 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
454 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
457 static const uint32_t masks_table_rgb
[6][4] = {
458 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
459 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
460 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
461 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
462 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */
463 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
466 static const uint32_t masks_table_rgba
[6][4] = {
467 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
468 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
469 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
470 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
471 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
472 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
475 static const uint32_t masks_table_bgr
[6][4] = {
476 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
477 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
478 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
479 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
480 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
481 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
484 static const uint32_t masks_table_bgra
[6][4] = {
485 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
486 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
487 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
488 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
489 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
490 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
493 static const uint8_t bytes_per_pixel
[6] = {
502 const uint8_t * bits
;
503 const uint32_t * masks
;
505 __DRIconfig
**configs
, **c
;
506 __GLcontextModes
*modes
;
509 unsigned num_accum_bits
= (enable_accum
) ? 2 : 1;
512 case GL_UNSIGNED_BYTE_3_3_2
:
515 case GL_UNSIGNED_BYTE_2_3_3_REV
:
518 case GL_UNSIGNED_SHORT_5_6_5
:
521 case GL_UNSIGNED_SHORT_5_6_5_REV
:
524 case GL_UNSIGNED_INT_8_8_8_8
:
527 case GL_UNSIGNED_INT_8_8_8_8_REV
:
531 fprintf( stderr
, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
532 __FUNCTION__
, __LINE__
, fb_type
);
537 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
540 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
543 switch ( fb_format
) {
545 masks
= masks_table_rgb
[ index
];
549 masks
= masks_table_rgba
[ index
];
553 masks
= masks_table_bgr
[ index
];
557 masks
= masks_table_bgra
[ index
];
561 fprintf( stderr
, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
562 __FUNCTION__
, __LINE__
, fb_format
);
566 switch ( bytes_per_pixel
[ index
] ) {
568 bits
= bits_table
[0];
571 bits
= bits_table
[1];
574 bits
= ((fb_format
== GL_RGB
) || (fb_format
== GL_BGR
))
580 num_modes
= num_depth_stencil_bits
* num_db_modes
* num_accum_bits
* num_msaa_modes
;
581 configs
= calloc(1, (num_modes
+ 1) * sizeof *configs
);
586 for ( k
= 0 ; k
< num_depth_stencil_bits
; k
++ ) {
587 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
588 for ( h
= 0 ; h
< num_msaa_modes
; h
++ ) {
589 for ( j
= 0 ; j
< num_accum_bits
; j
++ ) {
590 *c
= malloc (sizeof **c
);
591 modes
= &(*c
)->modes
;
594 memset(modes
, 0, sizeof *modes
);
595 modes
->redBits
= bits
[0];
596 modes
->greenBits
= bits
[1];
597 modes
->blueBits
= bits
[2];
598 modes
->alphaBits
= bits
[3];
599 modes
->redMask
= masks
[0];
600 modes
->greenMask
= masks
[1];
601 modes
->blueMask
= masks
[2];
602 modes
->alphaMask
= masks
[3];
603 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
604 + modes
->blueBits
+ modes
->alphaBits
;
606 modes
->accumRedBits
= 16 * j
;
607 modes
->accumGreenBits
= 16 * j
;
608 modes
->accumBlueBits
= 16 * j
;
609 modes
->accumAlphaBits
= (masks
[3] != 0) ? 16 * j
: 0;
610 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
612 modes
->stencilBits
= stencil_bits
[k
];
613 modes
->depthBits
= depth_bits
[k
];
615 modes
->transparentPixel
= GLX_NONE
;
616 modes
->transparentRed
= GLX_DONT_CARE
;
617 modes
->transparentGreen
= GLX_DONT_CARE
;
618 modes
->transparentBlue
= GLX_DONT_CARE
;
619 modes
->transparentAlpha
= GLX_DONT_CARE
;
620 modes
->transparentIndex
= GLX_DONT_CARE
;
621 modes
->visualType
= GLX_DONT_CARE
;
622 modes
->renderType
= GLX_RGBA_BIT
;
623 modes
->drawableType
= GLX_WINDOW_BIT
;
624 modes
->rgbMode
= GL_TRUE
;
626 if ( db_modes
[i
] == GLX_NONE
) {
627 modes
->doubleBufferMode
= GL_FALSE
;
630 modes
->doubleBufferMode
= GL_TRUE
;
631 modes
->swapMethod
= db_modes
[i
];
634 modes
->samples
= msaa_samples
[h
];
635 modes
->sampleBuffers
= modes
->samples
? 1 : 0;
638 modes
->haveAccumBuffer
= ((modes
->accumRedBits
+
639 modes
->accumGreenBits
+
640 modes
->accumBlueBits
+
641 modes
->accumAlphaBits
) > 0);
642 modes
->haveDepthBuffer
= (modes
->depthBits
> 0);
643 modes
->haveStencilBuffer
= (modes
->stencilBits
> 0);
645 modes
->bindToTextureRgb
= GL_TRUE
;
646 modes
->bindToTextureRgba
= GL_TRUE
;
647 modes
->bindToMipmapTexture
= GL_FALSE
;
648 modes
->bindToTextureTargets
=
649 __DRI_ATTRIB_TEXTURE_1D_BIT
|
650 __DRI_ATTRIB_TEXTURE_2D_BIT
|
651 __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT
;
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(__GLcontextModes, 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
),
732 /* The struct field doesn't matter here, these are handled by the
733 * switch in driGetConfigAttribIndex. We need them in the array
734 * so the iterator includes them though.*/
735 __ATTRIB(__DRI_ATTRIB_RENDER_TYPE
, level
),
736 __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT
, level
),
737 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD
, level
)
740 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
743 driGetConfigAttribIndex(const __DRIconfig
*config
,
744 unsigned int index
, unsigned int *value
)
746 switch (attribMap
[index
].attrib
) {
747 case __DRI_ATTRIB_RENDER_TYPE
:
748 *value
= __DRI_ATTRIB_RGBA_BIT
;
750 case __DRI_ATTRIB_CONFIG_CAVEAT
:
751 if (config
->modes
.visualRating
== GLX_NON_CONFORMANT_CONFIG
)
752 *value
= __DRI_ATTRIB_NON_CONFORMANT_CONFIG
;
753 else if (config
->modes
.visualRating
== GLX_SLOW_CONFIG
)
754 *value
= __DRI_ATTRIB_SLOW_BIT
;
758 case __DRI_ATTRIB_SWAP_METHOD
:
761 case __DRI_ATTRIB_FLOAT_MODE
:
762 *value
= config
->modes
.floatMode
;
766 *value
= *(unsigned int *)
767 ((char *) &config
->modes
+ attribMap
[index
].offset
);
776 driGetConfigAttrib(const __DRIconfig
*config
,
777 unsigned int attrib
, unsigned int *value
)
781 for (i
= 0; i
< ARRAY_SIZE(attribMap
); i
++)
782 if (attribMap
[i
].attrib
== attrib
)
783 return driGetConfigAttribIndex(config
, i
, value
);
789 driIndexConfigAttrib(const __DRIconfig
*config
, int index
,
790 unsigned int *attrib
, unsigned int *value
)
792 if (index
>= 0 && index
< ARRAY_SIZE(attribMap
)) {
793 *attrib
= attribMap
[index
].attrib
;
794 return driGetConfigAttribIndex(config
, index
, value
);