2 * (C) Copyright IBM Corporation 2003
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.
26 * \file glcontextmodes.c
27 * Utility routines for working with \c __GLcontextModes structures. At
28 * some point most or all of these functions will be moved to the Mesa
31 * \author Ian Romanick <idr@us.ibm.com>
34 #if defined(IN_MINI_GLX)
38 # include "GL/internal/dri_interface.h"
40 # define _mesa_memset memset
42 # if defined(HAVE_DIX_CONFIG_H)
43 # include <dix-config.h>
47 # include "GL/glxint.h"
52 # define _mesa_malloc(b) xalloc(b)
53 # define _mesa_free(m) xfree(m)
54 # define _mesa_memset memset
56 # include <X11/Xlibint.h>
57 # define _mesa_memset memset
58 # define _mesa_malloc(b) Xmalloc(b)
59 # define _mesa_free(m) Xfree(m)
60 # endif /* XFree86Server */
61 #endif /* !defined(IN_MINI_GLX) */
63 #include "glcontextmodes.h"
65 #if !defined(IN_MINI_GLX)
66 #define NUM_VISUAL_TYPES 6
69 * Convert an X visual type to a GLX visual type.
71 * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
73 * \return If \c visualType is a valid X visual type, a GLX visual type will
74 * be returned. Otherwise \c GLX_NONE will be returned.
77 _gl_convert_from_x_visual_type( int visualType
)
79 static const int glx_visual_types
[ NUM_VISUAL_TYPES
] = {
80 GLX_STATIC_GRAY
, GLX_GRAY_SCALE
,
81 GLX_STATIC_COLOR
, GLX_PSEUDO_COLOR
,
82 GLX_TRUE_COLOR
, GLX_DIRECT_COLOR
85 return ( (unsigned) visualType
< NUM_VISUAL_TYPES
)
86 ? glx_visual_types
[ visualType
] : GLX_NONE
;
91 * Convert a GLX visual type to an X visual type.
93 * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR,
94 * \c GLX_STATIC_GRAY, etc.) to be converted.
95 * \return If \c visualType is a valid GLX visual type, an X visual type will
96 * be returned. Otherwise -1 will be returned.
99 _gl_convert_to_x_visual_type( int visualType
)
101 static const int x_visual_types
[ NUM_VISUAL_TYPES
] = {
102 TrueColor
, DirectColor
,
103 PseudoColor
, StaticColor
,
104 GrayScale
, StaticGray
107 return ( (unsigned) (visualType
- GLX_TRUE_COLOR
) < NUM_VISUAL_TYPES
)
108 ? x_visual_types
[ visualType
- GLX_TRUE_COLOR
] : -1;
113 * Copy a GLX visual config structure to a GL context mode structure. All
114 * of the fields in \c config are copied to \c mode. Additional fields in
115 * \c mode that can be derrived from the fields of \c config (i.e.,
116 * \c haveDepthBuffer) are also filled in. The remaining fields in \c mode
117 * that cannot be derrived are set to default values.
119 * \param mode Destination GL context mode.
120 * \param config Source GLX visual config.
123 * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes
124 * structure will be set to the \c vid of the \c __GLXvisualConfig structure.
127 _gl_copy_visual_to_context_mode( __GLcontextModes
* mode
,
128 const __GLXvisualConfig
* config
)
130 __GLcontextModes
* const next
= mode
->next
;
132 (void) _mesa_memset( mode
, 0, sizeof( __GLcontextModes
) );
135 mode
->visualID
= config
->vid
;
136 mode
->visualType
= _gl_convert_from_x_visual_type( config
->class );
137 mode
->xRenderable
= GL_TRUE
;
138 mode
->fbconfigID
= config
->vid
;
139 mode
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
141 mode
->rgbMode
= (config
->rgba
!= 0);
142 mode
->renderType
= (mode
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
144 mode
->colorIndexMode
= !(mode
->rgbMode
);
145 mode
->doubleBufferMode
= (config
->doubleBuffer
!= 0);
146 mode
->stereoMode
= (config
->stereo
!= 0);
148 mode
->haveAccumBuffer
= ((config
->accumRedSize
+
149 config
->accumGreenSize
+
150 config
->accumBlueSize
+
151 config
->accumAlphaSize
) > 0);
152 mode
->haveDepthBuffer
= (config
->depthSize
> 0);
153 mode
->haveStencilBuffer
= (config
->stencilSize
> 0);
155 mode
->redBits
= config
->redSize
;
156 mode
->greenBits
= config
->greenSize
;
157 mode
->blueBits
= config
->blueSize
;
158 mode
->alphaBits
= config
->alphaSize
;
159 mode
->redMask
= config
->redMask
;
160 mode
->greenMask
= config
->greenMask
;
161 mode
->blueMask
= config
->blueMask
;
162 mode
->alphaMask
= config
->alphaMask
;
163 mode
->rgbBits
= mode
->rgbMode
? config
->bufferSize
: 0;
164 mode
->indexBits
= mode
->colorIndexMode
? config
->bufferSize
: 0;
166 mode
->accumRedBits
= config
->accumRedSize
;
167 mode
->accumGreenBits
= config
->accumGreenSize
;
168 mode
->accumBlueBits
= config
->accumBlueSize
;
169 mode
->accumAlphaBits
= config
->accumAlphaSize
;
170 mode
->depthBits
= config
->depthSize
;
171 mode
->stencilBits
= config
->stencilSize
;
173 mode
->numAuxBuffers
= config
->auxBuffers
;
174 mode
->level
= config
->level
;
176 mode
->visualRating
= config
->visualRating
;
177 mode
->transparentPixel
= config
->transparentPixel
;
178 mode
->transparentRed
= config
->transparentRed
;
179 mode
->transparentGreen
= config
->transparentGreen
;
180 mode
->transparentBlue
= config
->transparentBlue
;
181 mode
->transparentAlpha
= config
->transparentAlpha
;
182 mode
->transparentIndex
= config
->transparentIndex
;
184 mode
->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
186 mode
->bindToTextureRgb
= (mode
->rgbMode
) ? GL_TRUE
: GL_FALSE
;
187 mode
->bindToTextureRgba
= (mode
->rgbMode
&& mode
->alphaBits
) ?
189 mode
->bindToMipmapTexture
= mode
->rgbMode
? GL_TRUE
: GL_FALSE
;
190 mode
->bindToTextureTargets
= mode
->rgbMode
?
191 GLX_TEXTURE_1D_BIT_EXT
| GLX_TEXTURE_2D_BIT_EXT
|
192 GLX_TEXTURE_RECTANGLE_BIT_EXT
: 0;
193 mode
->yInverted
= GL_FALSE
;
198 * Get data from a GL context mode.
200 * \param mode GL context mode whose data is to be returned.
201 * \param attribute Attribute of \c mode that is to be returned.
202 * \param value_return Location to store the data member of \c mode.
203 * \return If \c attribute is a valid attribute of \c mode, zero is
204 * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
207 _gl_get_context_mode_data(const __GLcontextModes
*mode
, int attribute
,
212 *value_return
= GL_TRUE
;
214 case GLX_BUFFER_SIZE
:
215 *value_return
= mode
->rgbBits
;
218 *value_return
= mode
->rgbMode
;
221 *value_return
= mode
->redBits
;
224 *value_return
= mode
->greenBits
;
227 *value_return
= mode
->blueBits
;
230 *value_return
= mode
->alphaBits
;
232 case GLX_DOUBLEBUFFER
:
233 *value_return
= mode
->doubleBufferMode
;
236 *value_return
= mode
->stereoMode
;
238 case GLX_AUX_BUFFERS
:
239 *value_return
= mode
->numAuxBuffers
;
242 *value_return
= mode
->depthBits
;
244 case GLX_STENCIL_SIZE
:
245 *value_return
= mode
->stencilBits
;
247 case GLX_ACCUM_RED_SIZE
:
248 *value_return
= mode
->accumRedBits
;
250 case GLX_ACCUM_GREEN_SIZE
:
251 *value_return
= mode
->accumGreenBits
;
253 case GLX_ACCUM_BLUE_SIZE
:
254 *value_return
= mode
->accumBlueBits
;
256 case GLX_ACCUM_ALPHA_SIZE
:
257 *value_return
= mode
->accumAlphaBits
;
260 *value_return
= mode
->level
;
262 case GLX_TRANSPARENT_TYPE_EXT
:
263 *value_return
= mode
->transparentPixel
;
265 case GLX_TRANSPARENT_RED_VALUE
:
266 *value_return
= mode
->transparentRed
;
268 case GLX_TRANSPARENT_GREEN_VALUE
:
269 *value_return
= mode
->transparentGreen
;
271 case GLX_TRANSPARENT_BLUE_VALUE
:
272 *value_return
= mode
->transparentBlue
;
274 case GLX_TRANSPARENT_ALPHA_VALUE
:
275 *value_return
= mode
->transparentAlpha
;
277 case GLX_TRANSPARENT_INDEX_VALUE
:
278 *value_return
= mode
->transparentIndex
;
280 case GLX_X_VISUAL_TYPE
:
281 *value_return
= mode
->visualType
;
283 case GLX_CONFIG_CAVEAT
:
284 *value_return
= mode
->visualRating
;
287 *value_return
= mode
->visualID
;
289 case GLX_DRAWABLE_TYPE
:
290 *value_return
= mode
->drawableType
;
292 case GLX_RENDER_TYPE
:
293 *value_return
= mode
->renderType
;
295 case GLX_X_RENDERABLE
:
296 *value_return
= mode
->xRenderable
;
298 case GLX_FBCONFIG_ID
:
299 *value_return
= mode
->fbconfigID
;
301 case GLX_MAX_PBUFFER_WIDTH
:
302 *value_return
= mode
->maxPbufferWidth
;
304 case GLX_MAX_PBUFFER_HEIGHT
:
305 *value_return
= mode
->maxPbufferHeight
;
307 case GLX_MAX_PBUFFER_PIXELS
:
308 *value_return
= mode
->maxPbufferPixels
;
310 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
311 *value_return
= mode
->optimalPbufferWidth
;
313 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
314 *value_return
= mode
->optimalPbufferHeight
;
316 case GLX_SWAP_METHOD_OML
:
317 *value_return
= mode
->swapMethod
;
319 case GLX_SAMPLE_BUFFERS_SGIS
:
320 *value_return
= mode
->sampleBuffers
;
322 case GLX_SAMPLES_SGIS
:
323 *value_return
= mode
->samples
;
325 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
326 *value_return
= mode
->bindToTextureRgb
;
328 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
329 *value_return
= mode
->bindToTextureRgba
;
331 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
332 *value_return
= mode
->bindToMipmapTexture
;
334 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
335 *value_return
= mode
->bindToTextureTargets
;
337 case GLX_Y_INVERTED_EXT
:
338 *value_return
= mode
->yInverted
;
341 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
342 * It is ONLY for communication between the GLX client and the GLX
345 case GLX_VISUAL_SELECT_GROUP_SGIX
:
347 return GLX_BAD_ATTRIBUTE
;
350 #endif /* !defined(IN_MINI_GLX) */
354 * Allocate a linked list of \c __GLcontextModes structures. The fields of
355 * each structure will be initialized to "reasonable" default values. In
356 * most cases this is the default value defined by table 3.4 of the GLX
357 * 1.3 specification. This means that most values are either initialized to
358 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
359 * extensions is added, the new values will be initialized to appropriate
360 * values from the extension specification.
362 * \param count Number of structures to allocate.
363 * \param minimum_size Minimum size of a structure to allocate. This allows
364 * for differences in the version of the
365 * \c __GLcontextModes stucture used in libGL and in a
367 * \returns A pointer to the first element in a linked list of \c count
368 * stuctures on success, or \c NULL on failure.
370 * \warning Use of \c minimum_size does \b not guarantee binary compatibility.
371 * The fundamental assumption is that if the \c minimum_size
372 * specified by the driver and the size of the \c __GLcontextModes
373 * structure in libGL is the same, then the meaning of each byte in
374 * the structure is the same in both places. \b Be \b careful!
375 * Basically this means that fields have to be added in libGL and
376 * then propagated to drivers. Drivers should \b never arbitrarilly
377 * extend the \c __GLcontextModes data-structure.
380 _gl_context_modes_create( unsigned count
, size_t minimum_size
)
382 const size_t size
= (minimum_size
> sizeof( __GLcontextModes
))
383 ? minimum_size
: sizeof( __GLcontextModes
);
384 __GLcontextModes
* base
= NULL
;
385 __GLcontextModes
** next
;
389 for ( i
= 0 ; i
< count
; i
++ ) {
390 *next
= (__GLcontextModes
*) _mesa_malloc( size
);
391 if ( *next
== NULL
) {
392 _gl_context_modes_destroy( base
);
397 (void) _mesa_memset( *next
, 0, size
);
398 (*next
)->visualID
= GLX_DONT_CARE
;
399 (*next
)->visualType
= GLX_DONT_CARE
;
400 (*next
)->visualRating
= GLX_NONE
;
401 (*next
)->transparentPixel
= GLX_NONE
;
402 (*next
)->transparentRed
= GLX_DONT_CARE
;
403 (*next
)->transparentGreen
= GLX_DONT_CARE
;
404 (*next
)->transparentBlue
= GLX_DONT_CARE
;
405 (*next
)->transparentAlpha
= GLX_DONT_CARE
;
406 (*next
)->transparentIndex
= GLX_DONT_CARE
;
407 (*next
)->xRenderable
= GLX_DONT_CARE
;
408 (*next
)->fbconfigID
= GLX_DONT_CARE
;
409 (*next
)->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
410 (*next
)->bindToTextureRgb
= GLX_DONT_CARE
;
411 (*next
)->bindToTextureRgba
= GLX_DONT_CARE
;
412 (*next
)->bindToMipmapTexture
= GLX_DONT_CARE
;
413 (*next
)->bindToTextureTargets
= 0;
414 (*next
)->yInverted
= GLX_DONT_CARE
;
416 next
= & ((*next
)->next
);
424 * Destroy a linked list of \c __GLcontextModes structures created by
425 * \c _gl_context_modes_create.
427 * \param modes Linked list of structures to be destroyed. All structres
428 * in the list will be freed.
431 _gl_context_modes_destroy( __GLcontextModes
* modes
)
433 while ( modes
!= NULL
) {
434 __GLcontextModes
* const next
= modes
->next
;
443 * Find a context mode matching a Visual ID.
445 * \param modes List list of context-mode structures to be searched.
446 * \param vid Visual ID to be found.
447 * \returns A pointer to a context-mode in \c modes if \c vid was found in
448 * the list, or \c NULL if it was not.
452 _gl_context_modes_find_visual( __GLcontextModes
* modes
, int vid
)
454 while ( modes
!= NULL
) {
455 if ( modes
->visualID
== vid
) {
467 * Determine if two context-modes are the same. This is intended to be used
468 * by libGL implementations to compare to sets of driver generated FBconfigs.
470 * \param a Context-mode to be compared.
471 * \param b Context-mode to be compared.
472 * \returns \c GL_TRUE if the two context-modes are the same. \c GL_FALSE is
473 * returned otherwise.
476 _gl_context_modes_are_same( const __GLcontextModes
* a
,
477 const __GLcontextModes
* b
)
479 return( (a
->rgbMode
== b
->rgbMode
) &&
480 (a
->floatMode
== b
->floatMode
) &&
481 (a
->colorIndexMode
== b
->colorIndexMode
) &&
482 (a
->doubleBufferMode
== b
->doubleBufferMode
) &&
483 (a
->stereoMode
== b
->stereoMode
) &&
484 (a
->redBits
== b
->redBits
) &&
485 (a
->greenBits
== b
->greenBits
) &&
486 (a
->blueBits
== b
->blueBits
) &&
487 (a
->alphaBits
== b
->alphaBits
) &&
488 #if 0 /* For some reason these don't get set on the client-side in libGL. */
489 (a
->redMask
== b
->redMask
) &&
490 (a
->greenMask
== b
->greenMask
) &&
491 (a
->blueMask
== b
->blueMask
) &&
492 (a
->alphaMask
== b
->alphaMask
) &&
494 (a
->rgbBits
== b
->rgbBits
) &&
495 (a
->indexBits
== b
->indexBits
) &&
496 (a
->accumRedBits
== b
->accumRedBits
) &&
497 (a
->accumGreenBits
== b
->accumGreenBits
) &&
498 (a
->accumBlueBits
== b
->accumBlueBits
) &&
499 (a
->accumAlphaBits
== b
->accumAlphaBits
) &&
500 (a
->depthBits
== b
->depthBits
) &&
501 (a
->stencilBits
== b
->stencilBits
) &&
502 (a
->numAuxBuffers
== b
->numAuxBuffers
) &&
503 (a
->level
== b
->level
) &&
504 (a
->pixmapMode
== b
->pixmapMode
) &&
505 (a
->visualRating
== b
->visualRating
) &&
507 (a
->transparentPixel
== b
->transparentPixel
) &&
509 ((a
->transparentPixel
!= GLX_TRANSPARENT_RGB
) ||
510 ((a
->transparentRed
== b
->transparentRed
) &&
511 (a
->transparentGreen
== b
->transparentGreen
) &&
512 (a
->transparentBlue
== b
->transparentBlue
) &&
513 (a
->transparentAlpha
== b
->transparentAlpha
))) &&
515 ((a
->transparentPixel
!= GLX_TRANSPARENT_INDEX
) ||
516 (a
->transparentIndex
== b
->transparentIndex
)) &&
518 (a
->sampleBuffers
== b
->sampleBuffers
) &&
519 (a
->samples
== b
->samples
) &&
520 ((a
->drawableType
& b
->drawableType
) != 0) &&
521 (a
->renderType
== b
->renderType
) &&
522 (a
->maxPbufferWidth
== b
->maxPbufferWidth
) &&
523 (a
->maxPbufferHeight
== b
->maxPbufferHeight
) &&
524 (a
->maxPbufferPixels
== b
->maxPbufferPixels
) &&
525 (a
->optimalPbufferWidth
== b
->optimalPbufferWidth
) &&
526 (a
->optimalPbufferHeight
== b
->optimalPbufferHeight
) &&
527 (a
->swapMethod
== b
->swapMethod
) &&
528 (a
->bindToTextureRgb
== b
->bindToTextureRgb
) &&
529 (a
->bindToTextureRgba
== b
->bindToTextureRgba
) &&
530 (a
->bindToMipmapTexture
== b
->bindToMipmapTexture
) &&
531 (a
->bindToTextureTargets
== b
->bindToTextureTargets
) &&
532 (a
->yInverted
== b
->yInverted
) );