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) xalloc(b)
57 # define _mesa_free(m) xfree(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) Xfree(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
;
95 * Convert a GLX visual type to an X visual type.
97 * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR,
98 * \c GLX_STATIC_GRAY, etc.) to be converted.
99 * \return If \c visualType is a valid GLX visual type, an X visual type will
100 * be returned. Otherwise -1 will be returned.
103 _gl_convert_to_x_visual_type(int visualType
)
105 static const int x_visual_types
[NUM_VISUAL_TYPES
] = {
106 TrueColor
, DirectColor
,
107 PseudoColor
, StaticColor
,
108 GrayScale
, StaticGray
111 return ((unsigned) (visualType
- GLX_TRUE_COLOR
) < NUM_VISUAL_TYPES
)
112 ? x_visual_types
[visualType
- GLX_TRUE_COLOR
] : -1;
117 * Copy a GLX visual config structure to a GL context mode structure. All
118 * of the fields in \c config are copied to \c mode. Additional fields in
119 * \c mode that can be derrived from the fields of \c config (i.e.,
120 * \c haveDepthBuffer) are also filled in. The remaining fields in \c mode
121 * that cannot be derived are set to default values.
123 * \param mode Destination GL context mode.
124 * \param config Source GLX visual config.
127 * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes
128 * structure will be set to the \c vid of the \c __GLXvisualConfig structure.
131 _gl_copy_visual_to_context_mode(__GLcontextModes
* mode
,
132 const __GLXvisualConfig
* config
)
134 __GLcontextModes
*const next
= mode
->next
;
136 (void) _mesa_memset(mode
, 0, sizeof(__GLcontextModes
));
139 mode
->visualID
= config
->vid
;
140 mode
->visualType
= _gl_convert_from_x_visual_type(config
->class);
141 mode
->xRenderable
= GL_TRUE
;
142 mode
->fbconfigID
= config
->vid
;
143 mode
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
145 mode
->rgbMode
= (config
->rgba
!= 0);
146 mode
->renderType
= (mode
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
148 mode
->colorIndexMode
= !(mode
->rgbMode
);
149 mode
->doubleBufferMode
= (config
->doubleBuffer
!= 0);
150 mode
->stereoMode
= (config
->stereo
!= 0);
152 mode
->haveAccumBuffer
= ((config
->accumRedSize
+
153 config
->accumGreenSize
+
154 config
->accumBlueSize
+
155 config
->accumAlphaSize
) > 0);
156 mode
->haveDepthBuffer
= (config
->depthSize
> 0);
157 mode
->haveStencilBuffer
= (config
->stencilSize
> 0);
159 mode
->redBits
= config
->redSize
;
160 mode
->greenBits
= config
->greenSize
;
161 mode
->blueBits
= config
->blueSize
;
162 mode
->alphaBits
= config
->alphaSize
;
163 mode
->redMask
= config
->redMask
;
164 mode
->greenMask
= config
->greenMask
;
165 mode
->blueMask
= config
->blueMask
;
166 mode
->alphaMask
= config
->alphaMask
;
167 mode
->rgbBits
= mode
->rgbMode
? config
->bufferSize
: 0;
168 mode
->indexBits
= mode
->colorIndexMode
? config
->bufferSize
: 0;
170 mode
->accumRedBits
= config
->accumRedSize
;
171 mode
->accumGreenBits
= config
->accumGreenSize
;
172 mode
->accumBlueBits
= config
->accumBlueSize
;
173 mode
->accumAlphaBits
= config
->accumAlphaSize
;
174 mode
->depthBits
= config
->depthSize
;
175 mode
->stencilBits
= config
->stencilSize
;
177 mode
->numAuxBuffers
= config
->auxBuffers
;
178 mode
->level
= config
->level
;
180 mode
->visualRating
= config
->visualRating
;
181 mode
->transparentPixel
= config
->transparentPixel
;
182 mode
->transparentRed
= config
->transparentRed
;
183 mode
->transparentGreen
= config
->transparentGreen
;
184 mode
->transparentBlue
= config
->transparentBlue
;
185 mode
->transparentAlpha
= config
->transparentAlpha
;
186 mode
->transparentIndex
= config
->transparentIndex
;
187 mode
->samples
= config
->multiSampleSize
;
188 mode
->sampleBuffers
= config
->nMultiSampleBuffers
;
189 /* mode->visualSelectGroup = config->visualSelectGroup; ? */
191 mode
->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
193 mode
->bindToTextureRgb
= (mode
->rgbMode
) ? GL_TRUE
: GL_FALSE
;
194 mode
->bindToTextureRgba
= (mode
->rgbMode
&& mode
->alphaBits
) ?
196 mode
->bindToMipmapTexture
= mode
->rgbMode
? GL_TRUE
: GL_FALSE
;
197 mode
->bindToTextureTargets
= mode
->rgbMode
?
198 GLX_TEXTURE_1D_BIT_EXT
| GLX_TEXTURE_2D_BIT_EXT
|
199 GLX_TEXTURE_RECTANGLE_BIT_EXT
: 0;
200 mode
->yInverted
= GL_FALSE
;
205 * Get data from a GL context mode.
207 * \param mode GL context mode whose data is to be returned.
208 * \param attribute Attribute of \c mode that is to be returned.
209 * \param value_return Location to store the data member of \c mode.
210 * \return If \c attribute is a valid attribute of \c mode, zero is
211 * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
214 _gl_get_context_mode_data(const __GLcontextModes
* mode
, int attribute
,
219 *value_return
= GL_TRUE
;
221 case GLX_BUFFER_SIZE
:
222 *value_return
= mode
->rgbBits
;
225 *value_return
= mode
->rgbMode
;
228 *value_return
= mode
->redBits
;
231 *value_return
= mode
->greenBits
;
234 *value_return
= mode
->blueBits
;
237 *value_return
= mode
->alphaBits
;
239 case GLX_DOUBLEBUFFER
:
240 *value_return
= mode
->doubleBufferMode
;
243 *value_return
= mode
->stereoMode
;
245 case GLX_AUX_BUFFERS
:
246 *value_return
= mode
->numAuxBuffers
;
249 *value_return
= mode
->depthBits
;
251 case GLX_STENCIL_SIZE
:
252 *value_return
= mode
->stencilBits
;
254 case GLX_ACCUM_RED_SIZE
:
255 *value_return
= mode
->accumRedBits
;
257 case GLX_ACCUM_GREEN_SIZE
:
258 *value_return
= mode
->accumGreenBits
;
260 case GLX_ACCUM_BLUE_SIZE
:
261 *value_return
= mode
->accumBlueBits
;
263 case GLX_ACCUM_ALPHA_SIZE
:
264 *value_return
= mode
->accumAlphaBits
;
267 *value_return
= mode
->level
;
269 case GLX_TRANSPARENT_TYPE_EXT
:
270 *value_return
= mode
->transparentPixel
;
272 case GLX_TRANSPARENT_RED_VALUE
:
273 *value_return
= mode
->transparentRed
;
275 case GLX_TRANSPARENT_GREEN_VALUE
:
276 *value_return
= mode
->transparentGreen
;
278 case GLX_TRANSPARENT_BLUE_VALUE
:
279 *value_return
= mode
->transparentBlue
;
281 case GLX_TRANSPARENT_ALPHA_VALUE
:
282 *value_return
= mode
->transparentAlpha
;
284 case GLX_TRANSPARENT_INDEX_VALUE
:
285 *value_return
= mode
->transparentIndex
;
287 case GLX_X_VISUAL_TYPE
:
288 *value_return
= mode
->visualType
;
290 case GLX_CONFIG_CAVEAT
:
291 *value_return
= mode
->visualRating
;
294 *value_return
= mode
->visualID
;
296 case GLX_DRAWABLE_TYPE
:
297 *value_return
= mode
->drawableType
;
299 case GLX_RENDER_TYPE
:
300 *value_return
= mode
->renderType
;
302 case GLX_X_RENDERABLE
:
303 *value_return
= mode
->xRenderable
;
305 case GLX_FBCONFIG_ID
:
306 *value_return
= mode
->fbconfigID
;
308 case GLX_MAX_PBUFFER_WIDTH
:
309 *value_return
= mode
->maxPbufferWidth
;
311 case GLX_MAX_PBUFFER_HEIGHT
:
312 *value_return
= mode
->maxPbufferHeight
;
314 case GLX_MAX_PBUFFER_PIXELS
:
315 *value_return
= mode
->maxPbufferPixels
;
317 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
318 *value_return
= mode
->optimalPbufferWidth
;
320 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
321 *value_return
= mode
->optimalPbufferHeight
;
323 case GLX_SWAP_METHOD_OML
:
324 *value_return
= mode
->swapMethod
;
326 case GLX_SAMPLE_BUFFERS_SGIS
:
327 *value_return
= mode
->sampleBuffers
;
329 case GLX_SAMPLES_SGIS
:
330 *value_return
= mode
->samples
;
332 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
333 *value_return
= mode
->bindToTextureRgb
;
335 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
336 *value_return
= mode
->bindToTextureRgba
;
338 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
339 *value_return
= mode
->bindToMipmapTexture
== GL_TRUE
? GL_TRUE
:
342 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
343 *value_return
= mode
->bindToTextureTargets
;
345 case GLX_Y_INVERTED_EXT
:
346 *value_return
= mode
->yInverted
;
349 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
350 * It is ONLY for communication between the GLX client and the GLX
353 case GLX_VISUAL_SELECT_GROUP_SGIX
:
355 return GLX_BAD_ATTRIBUTE
;
358 #endif /* !defined(IN_MINI_GLX) */
362 * Allocate a linked list of \c __GLcontextModes structures. The fields of
363 * each structure will be initialized to "reasonable" default values. In
364 * most cases this is the default value defined by table 3.4 of the GLX
365 * 1.3 specification. This means that most values are either initialized to
366 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
367 * extensions is added, the new values will be initialized to appropriate
368 * values from the extension specification.
370 * \param count Number of structures to allocate.
371 * \param minimum_size Minimum size of a structure to allocate. This allows
372 * for differences in the version of the
373 * \c __GLcontextModes stucture used in libGL and in a
375 * \returns A pointer to the first element in a linked list of \c count
376 * stuctures on success, or \c NULL on failure.
378 * \warning Use of \c minimum_size does \b not guarantee binary compatibility.
379 * The fundamental assumption is that if the \c minimum_size
380 * specified by the driver and the size of the \c __GLcontextModes
381 * structure in libGL is the same, then the meaning of each byte in
382 * the structure is the same in both places. \b Be \b careful!
383 * Basically this means that fields have to be added in libGL and
384 * then propagated to drivers. Drivers should \b never arbitrarilly
385 * extend the \c __GLcontextModes data-structure.
388 _gl_context_modes_create(unsigned count
, size_t minimum_size
)
390 const size_t size
= (minimum_size
> sizeof(__GLcontextModes
))
391 ? minimum_size
: sizeof(__GLcontextModes
);
392 __GLcontextModes
*base
= NULL
;
393 __GLcontextModes
**next
;
397 for (i
= 0; i
< count
; i
++) {
398 *next
= (__GLcontextModes
*) _mesa_malloc(size
);
400 _gl_context_modes_destroy(base
);
405 (void) _mesa_memset(*next
, 0, size
);
406 (*next
)->visualID
= GLX_DONT_CARE
;
407 (*next
)->visualType
= GLX_DONT_CARE
;
408 (*next
)->visualRating
= GLX_NONE
;
409 (*next
)->transparentPixel
= GLX_NONE
;
410 (*next
)->transparentRed
= GLX_DONT_CARE
;
411 (*next
)->transparentGreen
= GLX_DONT_CARE
;
412 (*next
)->transparentBlue
= GLX_DONT_CARE
;
413 (*next
)->transparentAlpha
= GLX_DONT_CARE
;
414 (*next
)->transparentIndex
= GLX_DONT_CARE
;
415 (*next
)->xRenderable
= GLX_DONT_CARE
;
416 (*next
)->fbconfigID
= GLX_DONT_CARE
;
417 (*next
)->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
418 (*next
)->bindToTextureRgb
= GLX_DONT_CARE
;
419 (*next
)->bindToTextureRgba
= GLX_DONT_CARE
;
420 (*next
)->bindToMipmapTexture
= GLX_DONT_CARE
;
421 (*next
)->bindToTextureTargets
= GLX_DONT_CARE
;
422 (*next
)->yInverted
= GLX_DONT_CARE
;
424 next
= &((*next
)->next
);
432 * Destroy a linked list of \c __GLcontextModes structures created by
433 * \c _gl_context_modes_create.
435 * \param modes Linked list of structures to be destroyed. All structres
436 * in the list will be freed.
439 _gl_context_modes_destroy(__GLcontextModes
* modes
)
441 while (modes
!= NULL
) {
442 __GLcontextModes
*const next
= modes
->next
;
451 * Find a context mode matching a Visual ID.
453 * \param modes List list of context-mode structures to be searched.
454 * \param vid Visual ID to be found.
455 * \returns A pointer to a context-mode in \c modes if \c vid was found in
456 * the list, or \c NULL if it was not.
460 _gl_context_modes_find_visual(__GLcontextModes
* modes
, int vid
)
464 for (m
= modes
; m
!= NULL
; m
= m
->next
)
465 if (m
->visualID
== vid
)
472 _gl_context_modes_find_fbconfig(__GLcontextModes
* modes
, int fbid
)
476 for (m
= modes
; m
!= NULL
; m
= m
->next
)
477 if (m
->fbconfigID
== fbid
)
484 * Determine if two context-modes are the same. This is intended to be used
485 * by libGL implementations to compare to sets of driver generated FBconfigs.
487 * \param a Context-mode to be compared.
488 * \param b Context-mode to be compared.
489 * \returns \c GL_TRUE if the two context-modes are the same. \c GL_FALSE is
490 * returned otherwise.
493 _gl_context_modes_are_same(const __GLcontextModes
* a
,
494 const __GLcontextModes
* b
)
496 return ((a
->rgbMode
== b
->rgbMode
) &&
497 (a
->floatMode
== b
->floatMode
) &&
498 (a
->colorIndexMode
== b
->colorIndexMode
) &&
499 (a
->doubleBufferMode
== b
->doubleBufferMode
) &&
500 (a
->stereoMode
== b
->stereoMode
) &&
501 (a
->redBits
== b
->redBits
) &&
502 (a
->greenBits
== b
->greenBits
) &&
503 (a
->blueBits
== b
->blueBits
) && (a
->alphaBits
== b
->alphaBits
) &&
504 #if 0 /* For some reason these don't get set on the client-side in libGL. */
505 (a
->redMask
== b
->redMask
) &&
506 (a
->greenMask
== b
->greenMask
) &&
507 (a
->blueMask
== b
->blueMask
) && (a
->alphaMask
== b
->alphaMask
) &&
509 (a
->rgbBits
== b
->rgbBits
) &&
510 (a
->indexBits
== b
->indexBits
) &&
511 (a
->accumRedBits
== b
->accumRedBits
) &&
512 (a
->accumGreenBits
== b
->accumGreenBits
) &&
513 (a
->accumBlueBits
== b
->accumBlueBits
) &&
514 (a
->accumAlphaBits
== b
->accumAlphaBits
) &&
515 (a
->depthBits
== b
->depthBits
) &&
516 (a
->stencilBits
== b
->stencilBits
) &&
517 (a
->numAuxBuffers
== b
->numAuxBuffers
) &&
518 (a
->level
== b
->level
) &&
519 (a
->pixmapMode
== b
->pixmapMode
) &&
520 (a
->visualRating
== b
->visualRating
) &&
521 (a
->transparentPixel
== b
->transparentPixel
) &&
522 ((a
->transparentPixel
!= GLX_TRANSPARENT_RGB
) ||
523 ((a
->transparentRed
== b
->transparentRed
) &&
524 (a
->transparentGreen
== b
->transparentGreen
) &&
525 (a
->transparentBlue
== b
->transparentBlue
) &&
526 (a
->transparentAlpha
== b
->transparentAlpha
))) &&
527 ((a
->transparentPixel
!= GLX_TRANSPARENT_INDEX
) ||
528 (a
->transparentIndex
== b
->transparentIndex
)) &&
529 (a
->sampleBuffers
== b
->sampleBuffers
) &&
530 (a
->samples
== b
->samples
) &&
531 ((a
->drawableType
& b
->drawableType
) != 0) &&
532 (a
->renderType
== b
->renderType
) &&
533 (a
->maxPbufferWidth
== b
->maxPbufferWidth
) &&
534 (a
->maxPbufferHeight
== b
->maxPbufferHeight
) &&
535 (a
->maxPbufferPixels
== b
->maxPbufferPixels
) &&
536 (a
->optimalPbufferWidth
== b
->optimalPbufferWidth
) &&
537 (a
->optimalPbufferHeight
== b
->optimalPbufferHeight
) &&
538 (a
->swapMethod
== b
->swapMethod
) &&
539 (a
->bindToTextureRgb
== b
->bindToTextureRgb
) &&
540 (a
->bindToTextureRgba
== b
->bindToTextureRgba
) &&
541 (a
->bindToMipmapTexture
== b
->bindToMipmapTexture
) &&
542 (a
->bindToTextureTargets
== b
->bindToTextureTargets
) &&
543 (a
->yInverted
== b
->yInverted
));