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)
37 #if defined(HAVE_DIX_CONFIG_H)
38 #include <dix-config.h>
42 #include "GL/glxint.h"
46 #if defined(IN_MINI_GLX)
49 #define _mesa_malloc(b) malloc(b)
50 #define _mesa_free(m) free(m)
51 #define _mesa_memset memset
56 #define _mesa_malloc(b) malloc(b)
57 #define _mesa_free(m) free(m)
58 #define _mesa_memset memset
60 #include <X11/Xlibint.h>
61 #define _mesa_memset memset
62 #define _mesa_malloc(b) Xmalloc(b)
63 #define _mesa_free(m) free(m)
64 #endif /* XFree86Server */
65 #endif /* !defined(IN_MINI_GLX) */
67 #include "glcontextmodes.h"
69 #if !defined(IN_MINI_GLX)
70 #define NUM_VISUAL_TYPES 6
73 * Convert an X visual type to a GLX visual type.
75 * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
77 * \return If \c visualType is a valid X visual type, a GLX visual type will
78 * be returned. Otherwise \c GLX_NONE will be returned.
81 _gl_convert_from_x_visual_type(int visualType
)
83 static const int glx_visual_types
[NUM_VISUAL_TYPES
] = {
84 GLX_STATIC_GRAY
, GLX_GRAY_SCALE
,
85 GLX_STATIC_COLOR
, GLX_PSEUDO_COLOR
,
86 GLX_TRUE_COLOR
, GLX_DIRECT_COLOR
89 return ((unsigned)visualType
< NUM_VISUAL_TYPES
)
90 ? glx_visual_types
[visualType
] : GLX_NONE
;
94 * Convert a GLX visual type to an X visual type.
96 * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR,
97 * \c GLX_STATIC_GRAY, etc.) to be converted.
98 * \return If \c visualType is a valid GLX visual type, an X visual type will
99 * be returned. Otherwise -1 will be returned.
102 _gl_convert_to_x_visual_type(int visualType
)
104 static const int x_visual_types
[NUM_VISUAL_TYPES
] = {
105 TrueColor
, DirectColor
,
106 PseudoColor
, StaticColor
,
107 GrayScale
, StaticGray
110 return ((unsigned)(visualType
- GLX_TRUE_COLOR
) < NUM_VISUAL_TYPES
)
111 ? x_visual_types
[visualType
- GLX_TRUE_COLOR
] : -1;
115 * Copy a GLX visual config structure to a GL context mode structure. All
116 * of the fields in \c config are copied to \c mode. Additional fields in
117 * \c mode that can be derrived from the fields of \c config (i.e.,
118 * \c haveDepthBuffer) are also filled in. The remaining fields in \c mode
119 * that cannot be derived are set to default values.
121 * \param mode Destination GL context mode.
122 * \param config Source GLX visual config.
125 * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes
126 * structure will be set to the \c vid of the \c __GLXvisualConfig structure.
129 _gl_copy_visual_to_context_mode(__GLcontextModes
* mode
,
130 const __GLXvisualConfig
* config
)
132 __GLcontextModes
* const next
= mode
->next
;
134 (void)_mesa_memset(mode
, 0, sizeof(__GLcontextModes
));
137 mode
->visualID
= config
->vid
;
138 mode
->visualType
= _gl_convert_from_x_visual_type(config
->class);
139 mode
->xRenderable
= GL_TRUE
;
140 mode
->fbconfigID
= config
->vid
;
141 mode
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
143 mode
->rgbMode
= (config
->rgba
!= 0);
144 mode
->renderType
= (mode
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
146 mode
->colorIndexMode
= !(mode
->rgbMode
);
147 mode
->doubleBufferMode
= (config
->doubleBuffer
!= 0);
148 mode
->stereoMode
= (config
->stereo
!= 0);
150 mode
->haveAccumBuffer
= ((config
->accumRedSize
+
151 config
->accumGreenSize
+
152 config
->accumBlueSize
+
153 config
->accumAlphaSize
) > 0);
154 mode
->haveDepthBuffer
= (config
->depthSize
> 0);
155 mode
->haveStencilBuffer
= (config
->stencilSize
> 0);
157 mode
->redBits
= config
->redSize
;
158 mode
->greenBits
= config
->greenSize
;
159 mode
->blueBits
= config
->blueSize
;
160 mode
->alphaBits
= config
->alphaSize
;
161 mode
->redMask
= config
->redMask
;
162 mode
->greenMask
= config
->greenMask
;
163 mode
->blueMask
= config
->blueMask
;
164 mode
->alphaMask
= config
->alphaMask
;
165 mode
->rgbBits
= mode
->rgbMode
? config
->bufferSize
: 0;
166 mode
->indexBits
= mode
->colorIndexMode
? config
->bufferSize
: 0;
168 mode
->accumRedBits
= config
->accumRedSize
;
169 mode
->accumGreenBits
= config
->accumGreenSize
;
170 mode
->accumBlueBits
= config
->accumBlueSize
;
171 mode
->accumAlphaBits
= config
->accumAlphaSize
;
172 mode
->depthBits
= config
->depthSize
;
173 mode
->stencilBits
= config
->stencilSize
;
175 mode
->numAuxBuffers
= config
->auxBuffers
;
176 mode
->level
= config
->level
;
178 mode
->visualRating
= config
->visualRating
;
179 mode
->transparentPixel
= config
->transparentPixel
;
180 mode
->transparentRed
= config
->transparentRed
;
181 mode
->transparentGreen
= config
->transparentGreen
;
182 mode
->transparentBlue
= config
->transparentBlue
;
183 mode
->transparentAlpha
= config
->transparentAlpha
;
184 mode
->transparentIndex
= config
->transparentIndex
;
185 mode
->samples
= config
->multiSampleSize
;
186 mode
->sampleBuffers
= config
->nMultiSampleBuffers
;
187 /* mode->visualSelectGroup = config->visualSelectGroup; ? */
189 mode
->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
191 mode
->bindToTextureRgb
= (mode
->rgbMode
) ? GL_TRUE
: GL_FALSE
;
192 mode
->bindToTextureRgba
= (mode
->rgbMode
&& mode
->alphaBits
) ?
194 mode
->bindToMipmapTexture
= mode
->rgbMode
? GL_TRUE
: GL_FALSE
;
195 mode
->bindToTextureTargets
= mode
->rgbMode
?
196 GLX_TEXTURE_1D_BIT_EXT
|
197 GLX_TEXTURE_2D_BIT_EXT
|
198 GLX_TEXTURE_RECTANGLE_BIT_EXT
: 0;
199 mode
->yInverted
= GL_FALSE
;
203 * Get data from a GL context mode.
205 * \param mode GL context mode whose data is to be returned.
206 * \param attribute Attribute of \c mode that is to be returned.
207 * \param value_return Location to store the data member of \c mode.
208 * \return If \c attribute is a valid attribute of \c mode, zero is
209 * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
212 _gl_get_context_mode_data(const __GLcontextModes
*mode
, int attribute
,
217 *value_return
= GL_TRUE
;
220 case GLX_BUFFER_SIZE
:
221 *value_return
= mode
->rgbBits
;
225 *value_return
= mode
->rgbMode
;
229 *value_return
= mode
->redBits
;
233 *value_return
= mode
->greenBits
;
237 *value_return
= mode
->blueBits
;
241 *value_return
= mode
->alphaBits
;
244 case GLX_DOUBLEBUFFER
:
245 *value_return
= mode
->doubleBufferMode
;
249 *value_return
= mode
->stereoMode
;
252 case GLX_AUX_BUFFERS
:
253 *value_return
= mode
->numAuxBuffers
;
257 *value_return
= mode
->depthBits
;
260 case GLX_STENCIL_SIZE
:
261 *value_return
= mode
->stencilBits
;
264 case GLX_ACCUM_RED_SIZE
:
265 *value_return
= mode
->accumRedBits
;
268 case GLX_ACCUM_GREEN_SIZE
:
269 *value_return
= mode
->accumGreenBits
;
272 case GLX_ACCUM_BLUE_SIZE
:
273 *value_return
= mode
->accumBlueBits
;
276 case GLX_ACCUM_ALPHA_SIZE
:
277 *value_return
= mode
->accumAlphaBits
;
281 *value_return
= mode
->level
;
284 case GLX_TRANSPARENT_TYPE_EXT
:
285 *value_return
= mode
->transparentPixel
;
288 case GLX_TRANSPARENT_RED_VALUE
:
289 *value_return
= mode
->transparentRed
;
292 case GLX_TRANSPARENT_GREEN_VALUE
:
293 *value_return
= mode
->transparentGreen
;
296 case GLX_TRANSPARENT_BLUE_VALUE
:
297 *value_return
= mode
->transparentBlue
;
300 case GLX_TRANSPARENT_ALPHA_VALUE
:
301 *value_return
= mode
->transparentAlpha
;
304 case GLX_TRANSPARENT_INDEX_VALUE
:
305 *value_return
= mode
->transparentIndex
;
308 case GLX_X_VISUAL_TYPE
:
309 *value_return
= mode
->visualType
;
312 case GLX_CONFIG_CAVEAT
:
313 *value_return
= mode
->visualRating
;
317 *value_return
= mode
->visualID
;
320 case GLX_DRAWABLE_TYPE
:
321 *value_return
= mode
->drawableType
;
324 case GLX_RENDER_TYPE
:
325 *value_return
= mode
->renderType
;
328 case GLX_X_RENDERABLE
:
329 *value_return
= mode
->xRenderable
;
332 case GLX_FBCONFIG_ID
:
333 *value_return
= mode
->fbconfigID
;
336 case GLX_MAX_PBUFFER_WIDTH
:
337 *value_return
= mode
->maxPbufferWidth
;
340 case GLX_MAX_PBUFFER_HEIGHT
:
341 *value_return
= mode
->maxPbufferHeight
;
344 case GLX_MAX_PBUFFER_PIXELS
:
345 *value_return
= mode
->maxPbufferPixels
;
348 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
349 *value_return
= mode
->optimalPbufferWidth
;
352 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
353 *value_return
= mode
->optimalPbufferHeight
;
356 case GLX_SWAP_METHOD_OML
:
357 *value_return
= mode
->swapMethod
;
360 case GLX_SAMPLE_BUFFERS_SGIS
:
361 *value_return
= mode
->sampleBuffers
;
364 case GLX_SAMPLES_SGIS
:
365 *value_return
= mode
->samples
;
368 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
369 *value_return
= mode
->bindToTextureRgb
;
372 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
373 *value_return
= mode
->bindToTextureRgba
;
376 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
377 *value_return
= mode
->bindToMipmapTexture
== GL_TRUE
? GL_TRUE
:
381 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
382 *value_return
= mode
->bindToTextureTargets
;
385 case GLX_Y_INVERTED_EXT
:
386 *value_return
= mode
->yInverted
;
389 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
390 * It is ONLY for communication between the GLX client and the GLX
393 case GLX_VISUAL_SELECT_GROUP_SGIX
:
395 return GLX_BAD_ATTRIBUTE
;
398 #endif /* !defined(IN_MINI_GLX) */
401 * Allocate a linked list of \c __GLcontextModes structures. The fields of
402 * each structure will be initialized to "reasonable" default values. In
403 * most cases this is the default value defined by table 3.4 of the GLX
404 * 1.3 specification. This means that most values are either initialized to
405 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
406 * extensions is added, the new values will be initialized to appropriate
407 * values from the extension specification.
409 * \param count Number of structures to allocate.
410 * \param minimum_size Minimum size of a structure to allocate. This allows
411 * for differences in the version of the
412 * \c __GLcontextModes stucture used in libGL and in a
414 * \returns A pointer to the first element in a linked list of \c count
415 * stuctures on success, or \c NULL on failure.
417 * \warning Use of \c minimum_size does \b not guarantee binary compatibility.
418 * The fundamental assumption is that if the \c minimum_size
419 * specified by the driver and the size of the \c __GLcontextModes
420 * structure in libGL is the same, then the meaning of each byte in
421 * the structure is the same in both places. \b Be \b careful!
422 * Basically this means that fields have to be added in libGL and
423 * then propagated to drivers. Drivers should \b never arbitrarilly
424 * extend the \c __GLcontextModes data-structure.
427 _gl_context_modes_create(unsigned count
, size_t minimum_size
)
429 const size_t size
= (minimum_size
> sizeof(__GLcontextModes
))
430 ? minimum_size
: sizeof(__GLcontextModes
);
431 __GLcontextModes
* base
= NULL
;
432 __GLcontextModes
** next
;
436 for (i
= 0; i
< count
; i
++) {
437 *next
= (__GLcontextModes
*)_mesa_malloc(size
);
439 _gl_context_modes_destroy(base
);
444 (void)_mesa_memset(*next
, 0, size
);
445 (*next
)->visualID
= GLX_DONT_CARE
;
446 (*next
)->visualType
= GLX_DONT_CARE
;
447 (*next
)->visualRating
= GLX_NONE
;
448 (*next
)->transparentPixel
= GLX_NONE
;
449 (*next
)->transparentRed
= GLX_DONT_CARE
;
450 (*next
)->transparentGreen
= GLX_DONT_CARE
;
451 (*next
)->transparentBlue
= GLX_DONT_CARE
;
452 (*next
)->transparentAlpha
= GLX_DONT_CARE
;
453 (*next
)->transparentIndex
= GLX_DONT_CARE
;
454 (*next
)->xRenderable
= GLX_DONT_CARE
;
455 (*next
)->fbconfigID
= GLX_DONT_CARE
;
456 (*next
)->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
457 (*next
)->bindToTextureRgb
= GLX_DONT_CARE
;
458 (*next
)->bindToTextureRgba
= GLX_DONT_CARE
;
459 (*next
)->bindToMipmapTexture
= GLX_DONT_CARE
;
460 (*next
)->bindToTextureTargets
= GLX_DONT_CARE
;
461 (*next
)->yInverted
= GLX_DONT_CARE
;
463 next
= &((*next
)->next
);
470 * Destroy a linked list of \c __GLcontextModes structures created by
471 * \c _gl_context_modes_create.
473 * \param modes Linked list of structures to be destroyed. All structres
474 * in the list will be freed.
477 _gl_context_modes_destroy(__GLcontextModes
* modes
)
479 while (modes
!= NULL
) {
480 __GLcontextModes
* const next
= modes
->next
;
488 * Find a context mode matching a Visual ID.
490 * \param modes List list of context-mode structures to be searched.
491 * \param vid Visual ID to be found.
492 * \returns A pointer to a context-mode in \c modes if \c vid was found in
493 * the list, or \c NULL if it was not.
497 _gl_context_modes_find_visual(__GLcontextModes
*modes
, int vid
)
501 for (m
= modes
; m
!= NULL
; m
= m
->next
)
502 if (m
->visualID
== vid
)
509 _gl_context_modes_find_fbconfig(__GLcontextModes
*modes
, int fbid
)
513 for (m
= modes
; m
!= NULL
; m
= m
->next
)
514 if (m
->fbconfigID
== fbid
)
521 * Determine if two context-modes are the same. This is intended to be used
522 * by libGL implementations to compare to sets of driver generated FBconfigs.
524 * \param a Context-mode to be compared.
525 * \param b Context-mode to be compared.
526 * \returns \c GL_TRUE if the two context-modes are the same. \c GL_FALSE is
527 * returned otherwise.
530 _gl_context_modes_are_same(const __GLcontextModes
* a
,
531 const __GLcontextModes
* b
)
533 return ((a
->rgbMode
== b
->rgbMode
) &&
534 (a
->floatMode
== b
->floatMode
) &&
535 (a
->colorIndexMode
== b
->colorIndexMode
) &&
536 (a
->doubleBufferMode
== b
->doubleBufferMode
) &&
537 (a
->stereoMode
== b
->stereoMode
) &&
538 (a
->redBits
== b
->redBits
) &&
539 (a
->greenBits
== b
->greenBits
) &&
540 (a
->blueBits
== b
->blueBits
) &&
541 (a
->alphaBits
== b
->alphaBits
) &&
542 #if 0 /* For some reason these don't get set on the client-side in libGL. */
543 (a
->redMask
== b
->redMask
) &&
544 (a
->greenMask
== b
->greenMask
) &&
545 (a
->blueMask
== b
->blueMask
) &&
546 (a
->alphaMask
== b
->alphaMask
) &&
548 (a
->rgbBits
== b
->rgbBits
) &&
549 (a
->indexBits
== b
->indexBits
) &&
550 (a
->accumRedBits
== b
->accumRedBits
) &&
551 (a
->accumGreenBits
== b
->accumGreenBits
) &&
552 (a
->accumBlueBits
== b
->accumBlueBits
) &&
553 (a
->accumAlphaBits
== b
->accumAlphaBits
) &&
554 (a
->depthBits
== b
->depthBits
) &&
555 (a
->stencilBits
== b
->stencilBits
) &&
556 (a
->numAuxBuffers
== b
->numAuxBuffers
) &&
557 (a
->level
== b
->level
) &&
558 (a
->visualRating
== b
->visualRating
) &&
560 (a
->transparentPixel
== b
->transparentPixel
) &&
562 ((a
->transparentPixel
!= GLX_TRANSPARENT_RGB
) ||
563 ((a
->transparentRed
== b
->transparentRed
) &&
564 (a
->transparentGreen
== b
->transparentGreen
) &&
565 (a
->transparentBlue
== b
->transparentBlue
) &&
566 (a
->transparentAlpha
== b
->transparentAlpha
))) &&
568 ((a
->transparentPixel
!= GLX_TRANSPARENT_INDEX
) ||
569 (a
->transparentIndex
== b
->transparentIndex
)) &&
571 (a
->sampleBuffers
== b
->sampleBuffers
) &&
572 (a
->samples
== b
->samples
) &&
573 ((a
->drawableType
& b
->drawableType
) != 0) &&
574 (a
->renderType
== b
->renderType
) &&
575 (a
->maxPbufferWidth
== b
->maxPbufferWidth
) &&
576 (a
->maxPbufferHeight
== b
->maxPbufferHeight
) &&
577 (a
->maxPbufferPixels
== b
->maxPbufferPixels
) &&
578 (a
->optimalPbufferWidth
== b
->optimalPbufferWidth
) &&
579 (a
->optimalPbufferHeight
== b
->optimalPbufferHeight
) &&
580 (a
->swapMethod
== b
->swapMethod
) &&
581 (a
->bindToTextureRgb
== b
->bindToTextureRgb
) &&
582 (a
->bindToTextureRgba
== b
->bindToTextureRgba
) &&
583 (a
->bindToMipmapTexture
== b
->bindToMipmapTexture
) &&
584 (a
->bindToTextureTargets
== b
->bindToTextureTargets
) &&
585 (a
->yInverted
== b
->yInverted
));