1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
3 * (C) Copyright IBM Corporation 2003
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file glcontextmodes.c
28 * Utility routines for working with \c __GLcontextModes structures. At
29 * some point most or all of these functions will be moved to the Mesa
32 * \author Ian Romanick <idr@us.ibm.com>
35 #if defined(IN_MINI_GLX)
38 #if defined(HAVE_DIX_CONFIG_H)
39 # include <dix-config.h>
43 #include "GL/glxint.h"
47 #if defined(IN_MINI_GLX)
50 # define _mesa_malloc(b) malloc(b)
51 # define _mesa_free(m) free(m)
52 # define _mesa_memset memset
57 # define _mesa_malloc(b) xalloc(b)
58 # define _mesa_free(m) xfree(m)
59 # define _mesa_memset memset
61 # include <X11/Xlibint.h>
62 # define _mesa_memset memset
63 # define _mesa_malloc(b) Xmalloc(b)
64 # define _mesa_free(m) Xfree(m)
65 # endif /* XFree86Server */
66 #endif /* !defined(IN_MINI_GLX) */
68 #include "glcontextmodes.h"
70 #if !defined(IN_MINI_GLX)
71 #define NUM_VISUAL_TYPES 6
74 * Convert an X visual type to a GLX visual type.
76 * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
78 * \return If \c visualType is a valid X visual type, a GLX visual type will
79 * be returned. Otherwise \c GLX_NONE will be returned.
82 _gl_convert_from_x_visual_type(int visualType
)
84 static const int glx_visual_types
[NUM_VISUAL_TYPES
] = {
85 GLX_STATIC_GRAY
, GLX_GRAY_SCALE
,
86 GLX_STATIC_COLOR
, GLX_PSEUDO_COLOR
,
87 GLX_TRUE_COLOR
, GLX_DIRECT_COLOR
90 return ((unsigned) visualType
< NUM_VISUAL_TYPES
)
91 ? glx_visual_types
[visualType
] : GLX_NONE
;
96 * Convert a GLX visual type to an X visual type.
98 * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR,
99 * \c GLX_STATIC_GRAY, etc.) to be converted.
100 * \return If \c visualType is a valid GLX visual type, an X visual type will
101 * be returned. Otherwise -1 will be returned.
104 _gl_convert_to_x_visual_type(int visualType
)
106 static const int x_visual_types
[NUM_VISUAL_TYPES
] = {
107 TrueColor
, DirectColor
,
108 PseudoColor
, StaticColor
,
109 GrayScale
, StaticGray
112 return ((unsigned) (visualType
- GLX_TRUE_COLOR
) < NUM_VISUAL_TYPES
)
113 ? x_visual_types
[visualType
- GLX_TRUE_COLOR
] : -1;
118 * Copy a GLX visual config structure to a GL context mode structure. All
119 * of the fields in \c config are copied to \c mode. Additional fields in
120 * \c mode that can be derrived from the fields of \c config (i.e.,
121 * \c haveDepthBuffer) are also filled in. The remaining fields in \c mode
122 * that cannot be derived are set to default values.
124 * \param mode Destination GL context mode.
125 * \param config Source GLX visual config.
128 * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes
129 * structure will be set to the \c vid of the \c __GLXvisualConfig structure.
132 _gl_copy_visual_to_context_mode(__GLcontextModes
* mode
,
133 const __GLXvisualConfig
* config
)
135 __GLcontextModes
*const next
= mode
->next
;
137 (void) _mesa_memset(mode
, 0, sizeof(__GLcontextModes
));
140 mode
->visualID
= config
->vid
;
141 mode
->visualType
= _gl_convert_from_x_visual_type(config
->class);
142 mode
->xRenderable
= GL_TRUE
;
143 mode
->fbconfigID
= config
->vid
;
144 mode
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
146 mode
->rgbMode
= (config
->rgba
!= 0);
147 mode
->renderType
= (mode
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
149 mode
->colorIndexMode
= !(mode
->rgbMode
);
150 mode
->doubleBufferMode
= (config
->doubleBuffer
!= 0);
151 mode
->stereoMode
= (config
->stereo
!= 0);
153 mode
->haveAccumBuffer
= ((config
->accumRedSize
+
154 config
->accumGreenSize
+
155 config
->accumBlueSize
+
156 config
->accumAlphaSize
) > 0);
157 mode
->haveDepthBuffer
= (config
->depthSize
> 0);
158 mode
->haveStencilBuffer
= (config
->stencilSize
> 0);
160 mode
->redBits
= config
->redSize
;
161 mode
->greenBits
= config
->greenSize
;
162 mode
->blueBits
= config
->blueSize
;
163 mode
->alphaBits
= config
->alphaSize
;
164 mode
->redMask
= config
->redMask
;
165 mode
->greenMask
= config
->greenMask
;
166 mode
->blueMask
= config
->blueMask
;
167 mode
->alphaMask
= config
->alphaMask
;
168 mode
->rgbBits
= mode
->rgbMode
? config
->bufferSize
: 0;
169 mode
->indexBits
= mode
->colorIndexMode
? config
->bufferSize
: 0;
171 mode
->accumRedBits
= config
->accumRedSize
;
172 mode
->accumGreenBits
= config
->accumGreenSize
;
173 mode
->accumBlueBits
= config
->accumBlueSize
;
174 mode
->accumAlphaBits
= config
->accumAlphaSize
;
175 mode
->depthBits
= config
->depthSize
;
176 mode
->stencilBits
= config
->stencilSize
;
178 mode
->numAuxBuffers
= config
->auxBuffers
;
179 mode
->level
= config
->level
;
181 mode
->visualRating
= config
->visualRating
;
182 mode
->transparentPixel
= config
->transparentPixel
;
183 mode
->transparentRed
= config
->transparentRed
;
184 mode
->transparentGreen
= config
->transparentGreen
;
185 mode
->transparentBlue
= config
->transparentBlue
;
186 mode
->transparentAlpha
= config
->transparentAlpha
;
187 mode
->transparentIndex
= config
->transparentIndex
;
188 mode
->samples
= config
->multiSampleSize
;
189 mode
->sampleBuffers
= config
->nMultiSampleBuffers
;
190 /* mode->visualSelectGroup = config->visualSelectGroup; ? */
192 mode
->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
194 mode
->bindToTextureRgb
= (mode
->rgbMode
) ? GL_TRUE
: GL_FALSE
;
195 mode
->bindToTextureRgba
= (mode
->rgbMode
&& mode
->alphaBits
) ?
197 mode
->bindToMipmapTexture
= mode
->rgbMode
? GL_TRUE
: GL_FALSE
;
198 mode
->bindToTextureTargets
= mode
->rgbMode
?
199 GLX_TEXTURE_1D_BIT_EXT
| GLX_TEXTURE_2D_BIT_EXT
|
200 GLX_TEXTURE_RECTANGLE_BIT_EXT
: 0;
201 mode
->yInverted
= GL_FALSE
;
206 * Get data from a GL context mode.
208 * \param mode GL context mode whose data is to be returned.
209 * \param attribute Attribute of \c mode that is to be returned.
210 * \param value_return Location to store the data member of \c mode.
211 * \return If \c attribute is a valid attribute of \c mode, zero is
212 * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
215 _gl_get_context_mode_data(const __GLcontextModes
* mode
, int attribute
,
220 *value_return
= GL_TRUE
;
222 case GLX_BUFFER_SIZE
:
223 *value_return
= mode
->rgbBits
;
226 *value_return
= mode
->rgbMode
;
229 *value_return
= mode
->redBits
;
232 *value_return
= mode
->greenBits
;
235 *value_return
= mode
->blueBits
;
238 *value_return
= mode
->alphaBits
;
240 case GLX_DOUBLEBUFFER
:
241 *value_return
= mode
->doubleBufferMode
;
244 *value_return
= mode
->stereoMode
;
246 case GLX_AUX_BUFFERS
:
247 *value_return
= mode
->numAuxBuffers
;
250 *value_return
= mode
->depthBits
;
252 case GLX_STENCIL_SIZE
:
253 *value_return
= mode
->stencilBits
;
255 case GLX_ACCUM_RED_SIZE
:
256 *value_return
= mode
->accumRedBits
;
258 case GLX_ACCUM_GREEN_SIZE
:
259 *value_return
= mode
->accumGreenBits
;
261 case GLX_ACCUM_BLUE_SIZE
:
262 *value_return
= mode
->accumBlueBits
;
264 case GLX_ACCUM_ALPHA_SIZE
:
265 *value_return
= mode
->accumAlphaBits
;
268 *value_return
= mode
->level
;
270 case GLX_TRANSPARENT_TYPE_EXT
:
271 *value_return
= mode
->transparentPixel
;
273 case GLX_TRANSPARENT_RED_VALUE
:
274 *value_return
= mode
->transparentRed
;
276 case GLX_TRANSPARENT_GREEN_VALUE
:
277 *value_return
= mode
->transparentGreen
;
279 case GLX_TRANSPARENT_BLUE_VALUE
:
280 *value_return
= mode
->transparentBlue
;
282 case GLX_TRANSPARENT_ALPHA_VALUE
:
283 *value_return
= mode
->transparentAlpha
;
285 case GLX_TRANSPARENT_INDEX_VALUE
:
286 *value_return
= mode
->transparentIndex
;
288 case GLX_X_VISUAL_TYPE
:
289 *value_return
= mode
->visualType
;
291 case GLX_CONFIG_CAVEAT
:
292 *value_return
= mode
->visualRating
;
295 *value_return
= mode
->visualID
;
297 case GLX_DRAWABLE_TYPE
:
298 *value_return
= mode
->drawableType
;
300 case GLX_RENDER_TYPE
:
301 *value_return
= mode
->renderType
;
303 case GLX_X_RENDERABLE
:
304 *value_return
= mode
->xRenderable
;
306 case GLX_FBCONFIG_ID
:
307 *value_return
= mode
->fbconfigID
;
309 case GLX_MAX_PBUFFER_WIDTH
:
310 *value_return
= mode
->maxPbufferWidth
;
312 case GLX_MAX_PBUFFER_HEIGHT
:
313 *value_return
= mode
->maxPbufferHeight
;
315 case GLX_MAX_PBUFFER_PIXELS
:
316 *value_return
= mode
->maxPbufferPixels
;
318 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
319 *value_return
= mode
->optimalPbufferWidth
;
321 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
322 *value_return
= mode
->optimalPbufferHeight
;
324 case GLX_SWAP_METHOD_OML
:
325 *value_return
= mode
->swapMethod
;
327 case GLX_SAMPLE_BUFFERS_SGIS
:
328 *value_return
= mode
->sampleBuffers
;
330 case GLX_SAMPLES_SGIS
:
331 *value_return
= mode
->samples
;
333 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
334 *value_return
= mode
->bindToTextureRgb
;
336 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
337 *value_return
= mode
->bindToTextureRgba
;
339 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
340 *value_return
= mode
->bindToMipmapTexture
== GL_TRUE
? GL_TRUE
:
343 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
344 *value_return
= mode
->bindToTextureTargets
;
346 case GLX_Y_INVERTED_EXT
:
347 *value_return
= mode
->yInverted
;
350 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
351 * It is ONLY for communication between the GLX client and the GLX
354 case GLX_VISUAL_SELECT_GROUP_SGIX
:
356 return GLX_BAD_ATTRIBUTE
;
359 #endif /* !defined(IN_MINI_GLX) */
363 * Allocate a linked list of \c __GLcontextModes structures. The fields of
364 * each structure will be initialized to "reasonable" default values. In
365 * most cases this is the default value defined by table 3.4 of the GLX
366 * 1.3 specification. This means that most values are either initialized to
367 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
368 * extensions is added, the new values will be initialized to appropriate
369 * values from the extension specification.
371 * \param count Number of structures to allocate.
372 * \param minimum_size Minimum size of a structure to allocate. This allows
373 * for differences in the version of the
374 * \c __GLcontextModes stucture used in libGL and in a
376 * \returns A pointer to the first element in a linked list of \c count
377 * stuctures on success, or \c NULL on failure.
379 * \warning Use of \c minimum_size does \b not guarantee binary compatibility.
380 * The fundamental assumption is that if the \c minimum_size
381 * specified by the driver and the size of the \c __GLcontextModes
382 * structure in libGL is the same, then the meaning of each byte in
383 * the structure is the same in both places. \b Be \b careful!
384 * Basically this means that fields have to be added in libGL and
385 * then propagated to drivers. Drivers should \b never arbitrarilly
386 * extend the \c __GLcontextModes data-structure.
389 _gl_context_modes_create(unsigned count
, size_t minimum_size
)
391 const size_t size
= (minimum_size
> sizeof(__GLcontextModes
))
392 ? minimum_size
: sizeof(__GLcontextModes
);
393 __GLcontextModes
*base
= NULL
;
394 __GLcontextModes
**next
;
398 for (i
= 0; i
< count
; i
++) {
399 *next
= (__GLcontextModes
*) _mesa_malloc(size
);
401 _gl_context_modes_destroy(base
);
406 (void) _mesa_memset(*next
, 0, size
);
407 (*next
)->visualID
= GLX_DONT_CARE
;
408 (*next
)->visualType
= GLX_DONT_CARE
;
409 (*next
)->visualRating
= GLX_NONE
;
410 (*next
)->transparentPixel
= GLX_NONE
;
411 (*next
)->transparentRed
= GLX_DONT_CARE
;
412 (*next
)->transparentGreen
= GLX_DONT_CARE
;
413 (*next
)->transparentBlue
= GLX_DONT_CARE
;
414 (*next
)->transparentAlpha
= GLX_DONT_CARE
;
415 (*next
)->transparentIndex
= GLX_DONT_CARE
;
416 (*next
)->xRenderable
= GLX_DONT_CARE
;
417 (*next
)->fbconfigID
= GLX_DONT_CARE
;
418 (*next
)->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
419 (*next
)->bindToTextureRgb
= GLX_DONT_CARE
;
420 (*next
)->bindToTextureRgba
= GLX_DONT_CARE
;
421 (*next
)->bindToMipmapTexture
= GLX_DONT_CARE
;
422 (*next
)->bindToTextureTargets
= GLX_DONT_CARE
;
423 (*next
)->yInverted
= GLX_DONT_CARE
;
425 next
= &((*next
)->next
);
433 * Destroy a linked list of \c __GLcontextModes structures created by
434 * \c _gl_context_modes_create.
436 * \param modes Linked list of structures to be destroyed. All structres
437 * in the list will be freed.
440 _gl_context_modes_destroy(__GLcontextModes
* modes
)
442 while (modes
!= NULL
) {
443 __GLcontextModes
*const next
= modes
->next
;
452 * Find a context mode matching a Visual ID.
454 * \param modes List list of context-mode structures to be searched.
455 * \param vid Visual ID to be found.
456 * \returns A pointer to a context-mode in \c modes if \c vid was found in
457 * the list, or \c NULL if it was not.
461 _gl_context_modes_find_visual(__GLcontextModes
* modes
, int vid
)
465 for (m
= modes
; m
!= NULL
; m
= m
->next
)
466 if (m
->visualID
== vid
)
473 _gl_context_modes_find_fbconfig(__GLcontextModes
* modes
, int fbid
)
477 for (m
= modes
; m
!= NULL
; m
= m
->next
)
478 if (m
->fbconfigID
== fbid
)
485 * Determine if two context-modes are the same. This is intended to be used
486 * by libGL implementations to compare to sets of driver generated FBconfigs.
488 * \param a Context-mode to be compared.
489 * \param b Context-mode to be compared.
490 * \returns \c GL_TRUE if the two context-modes are the same. \c GL_FALSE is
491 * returned otherwise.
494 _gl_context_modes_are_same(const __GLcontextModes
* a
,
495 const __GLcontextModes
* b
)
497 return ((a
->rgbMode
== b
->rgbMode
) &&
498 (a
->floatMode
== b
->floatMode
) &&
499 (a
->colorIndexMode
== b
->colorIndexMode
) &&
500 (a
->doubleBufferMode
== b
->doubleBufferMode
) &&
501 (a
->stereoMode
== b
->stereoMode
) &&
502 (a
->redBits
== b
->redBits
) &&
503 (a
->greenBits
== b
->greenBits
) &&
504 (a
->blueBits
== b
->blueBits
) && (a
->alphaBits
== b
->alphaBits
) &&
505 #if 0 /* For some reason these don't get set on the client-side in libGL. */
506 (a
->redMask
== b
->redMask
) &&
507 (a
->greenMask
== b
->greenMask
) &&
508 (a
->blueMask
== b
->blueMask
) && (a
->alphaMask
== b
->alphaMask
) &&
510 (a
->rgbBits
== b
->rgbBits
) &&
511 (a
->indexBits
== b
->indexBits
) &&
512 (a
->accumRedBits
== b
->accumRedBits
) &&
513 (a
->accumGreenBits
== b
->accumGreenBits
) &&
514 (a
->accumBlueBits
== b
->accumBlueBits
) &&
515 (a
->accumAlphaBits
== b
->accumAlphaBits
) &&
516 (a
->depthBits
== b
->depthBits
) &&
517 (a
->stencilBits
== b
->stencilBits
) &&
518 (a
->numAuxBuffers
== b
->numAuxBuffers
) &&
519 (a
->level
== b
->level
) &&
520 (a
->pixmapMode
== b
->pixmapMode
) &&
521 (a
->visualRating
== b
->visualRating
) &&
522 (a
->transparentPixel
== b
->transparentPixel
) &&
523 ((a
->transparentPixel
!= GLX_TRANSPARENT_RGB
) ||
524 ((a
->transparentRed
== b
->transparentRed
) &&
525 (a
->transparentGreen
== b
->transparentGreen
) &&
526 (a
->transparentBlue
== b
->transparentBlue
) &&
527 (a
->transparentAlpha
== b
->transparentAlpha
))) &&
528 ((a
->transparentPixel
!= GLX_TRANSPARENT_INDEX
) ||
529 (a
->transparentIndex
== b
->transparentIndex
)) &&
530 (a
->sampleBuffers
== b
->sampleBuffers
) &&
531 (a
->samples
== b
->samples
) &&
532 ((a
->drawableType
& b
->drawableType
) != 0) &&
533 (a
->renderType
== b
->renderType
) &&
534 (a
->maxPbufferWidth
== b
->maxPbufferWidth
) &&
535 (a
->maxPbufferHeight
== b
->maxPbufferHeight
) &&
536 (a
->maxPbufferPixels
== b
->maxPbufferPixels
) &&
537 (a
->optimalPbufferWidth
== b
->optimalPbufferWidth
) &&
538 (a
->optimalPbufferHeight
== b
->optimalPbufferHeight
) &&
539 (a
->swapMethod
== b
->swapMethod
) &&
540 (a
->bindToTextureRgb
== b
->bindToTextureRgb
) &&
541 (a
->bindToTextureRgba
== b
->bindToTextureRgba
) &&
542 (a
->bindToMipmapTexture
== b
->bindToMipmapTexture
) &&
543 (a
->bindToTextureTargets
== b
->bindToTextureTargets
) &&
544 (a
->yInverted
== b
->yInverted
));