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>
35 #include "GL/glxint.h"
39 #include "glcontextmodes.h"
41 #define NUM_VISUAL_TYPES 6
44 * Convert an X visual type to a GLX visual type.
46 * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
48 * \return If \c visualType is a valid X visual type, a GLX visual type will
49 * be returned. Otherwise \c GLX_NONE will be returned.
52 _gl_convert_from_x_visual_type(int visualType
)
54 static const int glx_visual_types
[NUM_VISUAL_TYPES
] = {
55 GLX_STATIC_GRAY
, GLX_GRAY_SCALE
,
56 GLX_STATIC_COLOR
, GLX_PSEUDO_COLOR
,
57 GLX_TRUE_COLOR
, GLX_DIRECT_COLOR
60 return ((unsigned) visualType
< NUM_VISUAL_TYPES
)
61 ? glx_visual_types
[visualType
] : GLX_NONE
;
66 * Convert a GLX visual type to an X visual type.
68 * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR,
69 * \c GLX_STATIC_GRAY, etc.) to be converted.
70 * \return If \c visualType is a valid GLX visual type, an X visual type will
71 * be returned. Otherwise -1 will be returned.
74 _gl_convert_to_x_visual_type(int visualType
)
76 static const int x_visual_types
[NUM_VISUAL_TYPES
] = {
77 TrueColor
, DirectColor
,
78 PseudoColor
, StaticColor
,
82 return ((unsigned) (visualType
- GLX_TRUE_COLOR
) < NUM_VISUAL_TYPES
)
83 ? x_visual_types
[visualType
- GLX_TRUE_COLOR
] : -1;
88 * Copy a GLX visual config structure to a GL context mode structure. All
89 * of the fields in \c config are copied to \c mode. Additional fields in
90 * \c mode that can be derrived from the fields of \c config (i.e.,
91 * \c haveDepthBuffer) are also filled in. The remaining fields in \c mode
92 * that cannot be derived are set to default values.
94 * \param mode Destination GL context mode.
95 * \param config Source GLX visual config.
98 * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes
99 * structure will be set to the \c vid of the \c __GLXvisualConfig structure.
102 _gl_copy_visual_to_context_mode(__GLcontextModes
* mode
,
103 const __GLXvisualConfig
* config
)
105 __GLcontextModes
*const next
= mode
->next
;
107 (void) memset(mode
, 0, sizeof(__GLcontextModes
));
110 mode
->visualID
= config
->vid
;
111 mode
->visualType
= _gl_convert_from_x_visual_type(config
->class);
112 mode
->xRenderable
= GL_TRUE
;
113 mode
->fbconfigID
= config
->vid
;
114 mode
->drawableType
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
;
116 mode
->rgbMode
= (config
->rgba
!= 0);
117 mode
->renderType
= (mode
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
119 mode
->colorIndexMode
= !(mode
->rgbMode
);
120 mode
->doubleBufferMode
= (config
->doubleBuffer
!= 0);
121 mode
->stereoMode
= (config
->stereo
!= 0);
123 mode
->haveAccumBuffer
= ((config
->accumRedSize
+
124 config
->accumGreenSize
+
125 config
->accumBlueSize
+
126 config
->accumAlphaSize
) > 0);
127 mode
->haveDepthBuffer
= (config
->depthSize
> 0);
128 mode
->haveStencilBuffer
= (config
->stencilSize
> 0);
130 mode
->redBits
= config
->redSize
;
131 mode
->greenBits
= config
->greenSize
;
132 mode
->blueBits
= config
->blueSize
;
133 mode
->alphaBits
= config
->alphaSize
;
134 mode
->redMask
= config
->redMask
;
135 mode
->greenMask
= config
->greenMask
;
136 mode
->blueMask
= config
->blueMask
;
137 mode
->alphaMask
= config
->alphaMask
;
138 mode
->rgbBits
= mode
->rgbMode
? config
->bufferSize
: 0;
139 mode
->indexBits
= mode
->colorIndexMode
? config
->bufferSize
: 0;
141 mode
->accumRedBits
= config
->accumRedSize
;
142 mode
->accumGreenBits
= config
->accumGreenSize
;
143 mode
->accumBlueBits
= config
->accumBlueSize
;
144 mode
->accumAlphaBits
= config
->accumAlphaSize
;
145 mode
->depthBits
= config
->depthSize
;
146 mode
->stencilBits
= config
->stencilSize
;
148 mode
->numAuxBuffers
= config
->auxBuffers
;
149 mode
->level
= config
->level
;
151 mode
->visualRating
= config
->visualRating
;
152 mode
->transparentPixel
= config
->transparentPixel
;
153 mode
->transparentRed
= config
->transparentRed
;
154 mode
->transparentGreen
= config
->transparentGreen
;
155 mode
->transparentBlue
= config
->transparentBlue
;
156 mode
->transparentAlpha
= config
->transparentAlpha
;
157 mode
->transparentIndex
= config
->transparentIndex
;
158 mode
->samples
= config
->multiSampleSize
;
159 mode
->sampleBuffers
= config
->nMultiSampleBuffers
;
160 /* mode->visualSelectGroup = config->visualSelectGroup; ? */
162 mode
->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
164 mode
->bindToTextureRgb
= (mode
->rgbMode
) ? GL_TRUE
: GL_FALSE
;
165 mode
->bindToTextureRgba
= (mode
->rgbMode
&& mode
->alphaBits
) ?
167 mode
->bindToMipmapTexture
= mode
->rgbMode
? GL_TRUE
: GL_FALSE
;
168 mode
->bindToTextureTargets
= mode
->rgbMode
?
169 GLX_TEXTURE_1D_BIT_EXT
| GLX_TEXTURE_2D_BIT_EXT
|
170 GLX_TEXTURE_RECTANGLE_BIT_EXT
: 0;
171 mode
->yInverted
= GL_FALSE
;
176 * Get data from a GL context mode.
178 * \param mode GL context mode whose data is to be returned.
179 * \param attribute Attribute of \c mode that is to be returned.
180 * \param value_return Location to store the data member of \c mode.
181 * \return If \c attribute is a valid attribute of \c mode, zero is
182 * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
185 _gl_get_context_mode_data(const __GLcontextModes
* mode
, int attribute
,
190 *value_return
= GL_TRUE
;
192 case GLX_BUFFER_SIZE
:
193 *value_return
= mode
->rgbBits
;
196 *value_return
= mode
->rgbMode
;
199 *value_return
= mode
->redBits
;
202 *value_return
= mode
->greenBits
;
205 *value_return
= mode
->blueBits
;
208 *value_return
= mode
->alphaBits
;
210 case GLX_DOUBLEBUFFER
:
211 *value_return
= mode
->doubleBufferMode
;
214 *value_return
= mode
->stereoMode
;
216 case GLX_AUX_BUFFERS
:
217 *value_return
= mode
->numAuxBuffers
;
220 *value_return
= mode
->depthBits
;
222 case GLX_STENCIL_SIZE
:
223 *value_return
= mode
->stencilBits
;
225 case GLX_ACCUM_RED_SIZE
:
226 *value_return
= mode
->accumRedBits
;
228 case GLX_ACCUM_GREEN_SIZE
:
229 *value_return
= mode
->accumGreenBits
;
231 case GLX_ACCUM_BLUE_SIZE
:
232 *value_return
= mode
->accumBlueBits
;
234 case GLX_ACCUM_ALPHA_SIZE
:
235 *value_return
= mode
->accumAlphaBits
;
238 *value_return
= mode
->level
;
240 #ifndef GLX_USE_APPLEGL /* This isn't supported by CGL. */
241 case GLX_TRANSPARENT_TYPE_EXT
:
242 *value_return
= mode
->transparentPixel
;
245 case GLX_TRANSPARENT_RED_VALUE
:
246 *value_return
= mode
->transparentRed
;
248 case GLX_TRANSPARENT_GREEN_VALUE
:
249 *value_return
= mode
->transparentGreen
;
251 case GLX_TRANSPARENT_BLUE_VALUE
:
252 *value_return
= mode
->transparentBlue
;
254 case GLX_TRANSPARENT_ALPHA_VALUE
:
255 *value_return
= mode
->transparentAlpha
;
257 case GLX_TRANSPARENT_INDEX_VALUE
:
258 *value_return
= mode
->transparentIndex
;
260 case GLX_X_VISUAL_TYPE
:
261 *value_return
= mode
->visualType
;
263 case GLX_CONFIG_CAVEAT
:
264 *value_return
= mode
->visualRating
;
267 *value_return
= mode
->visualID
;
269 case GLX_DRAWABLE_TYPE
:
270 *value_return
= mode
->drawableType
;
272 case GLX_RENDER_TYPE
:
273 *value_return
= mode
->renderType
;
275 case GLX_X_RENDERABLE
:
276 *value_return
= mode
->xRenderable
;
278 case GLX_FBCONFIG_ID
:
279 *value_return
= mode
->fbconfigID
;
281 case GLX_MAX_PBUFFER_WIDTH
:
282 *value_return
= mode
->maxPbufferWidth
;
284 case GLX_MAX_PBUFFER_HEIGHT
:
285 *value_return
= mode
->maxPbufferHeight
;
287 case GLX_MAX_PBUFFER_PIXELS
:
288 *value_return
= mode
->maxPbufferPixels
;
290 #ifndef GLX_USE_APPLEGL /* These aren't supported by CGL. */
291 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
292 *value_return
= mode
->optimalPbufferWidth
;
294 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
295 *value_return
= mode
->optimalPbufferHeight
;
297 case GLX_SWAP_METHOD_OML
:
298 *value_return
= mode
->swapMethod
;
301 case GLX_SAMPLE_BUFFERS_SGIS
:
302 *value_return
= mode
->sampleBuffers
;
304 case GLX_SAMPLES_SGIS
:
305 *value_return
= mode
->samples
;
307 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
308 *value_return
= mode
->bindToTextureRgb
;
310 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
311 *value_return
= mode
->bindToTextureRgba
;
313 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
314 *value_return
= mode
->bindToMipmapTexture
== GL_TRUE
? GL_TRUE
:
317 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
318 *value_return
= mode
->bindToTextureTargets
;
320 case GLX_Y_INVERTED_EXT
:
321 *value_return
= mode
->yInverted
;
324 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
325 * It is ONLY for communication between the GLX client and the GLX
328 case GLX_VISUAL_SELECT_GROUP_SGIX
:
330 return GLX_BAD_ATTRIBUTE
;
336 * Allocate a linked list of \c __GLcontextModes structures. The fields of
337 * each structure will be initialized to "reasonable" default values. In
338 * most cases this is the default value defined by table 3.4 of the GLX
339 * 1.3 specification. This means that most values are either initialized to
340 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
341 * extensions is added, the new values will be initialized to appropriate
342 * values from the extension specification.
344 * \param count Number of structures to allocate.
345 * \param minimum_size Minimum size of a structure to allocate. This allows
346 * for differences in the version of the
347 * \c __GLcontextModes stucture used in libGL and in a
349 * \returns A pointer to the first element in a linked list of \c count
350 * stuctures on success, or \c NULL on failure.
352 * \warning Use of \c minimum_size does \b not guarantee binary compatibility.
353 * The fundamental assumption is that if the \c minimum_size
354 * specified by the driver and the size of the \c __GLcontextModes
355 * structure in libGL is the same, then the meaning of each byte in
356 * the structure is the same in both places. \b Be \b careful!
357 * Basically this means that fields have to be added in libGL and
358 * then propagated to drivers. Drivers should \b never arbitrarilly
359 * extend the \c __GLcontextModes data-structure.
362 _gl_context_modes_create(unsigned count
, size_t minimum_size
)
364 const size_t size
= (minimum_size
> sizeof(__GLcontextModes
))
365 ? minimum_size
: sizeof(__GLcontextModes
);
366 __GLcontextModes
*base
= NULL
;
367 __GLcontextModes
**next
;
371 for (i
= 0; i
< count
; i
++) {
372 *next
= (__GLcontextModes
*) malloc(size
);
374 _gl_context_modes_destroy(base
);
379 (void) memset(*next
, 0, size
);
380 (*next
)->visualID
= GLX_DONT_CARE
;
381 (*next
)->visualType
= GLX_DONT_CARE
;
382 (*next
)->visualRating
= GLX_NONE
;
383 (*next
)->transparentPixel
= GLX_NONE
;
384 (*next
)->transparentRed
= GLX_DONT_CARE
;
385 (*next
)->transparentGreen
= GLX_DONT_CARE
;
386 (*next
)->transparentBlue
= GLX_DONT_CARE
;
387 (*next
)->transparentAlpha
= GLX_DONT_CARE
;
388 (*next
)->transparentIndex
= GLX_DONT_CARE
;
389 (*next
)->xRenderable
= GLX_DONT_CARE
;
390 (*next
)->fbconfigID
= GLX_DONT_CARE
;
391 (*next
)->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
392 (*next
)->bindToTextureRgb
= GLX_DONT_CARE
;
393 (*next
)->bindToTextureRgba
= GLX_DONT_CARE
;
394 (*next
)->bindToMipmapTexture
= GLX_DONT_CARE
;
395 (*next
)->bindToTextureTargets
= GLX_DONT_CARE
;
396 (*next
)->yInverted
= GLX_DONT_CARE
;
398 next
= &((*next
)->next
);
406 * Destroy a linked list of \c __GLcontextModes structures created by
407 * \c _gl_context_modes_create.
409 * \param modes Linked list of structures to be destroyed. All structres
410 * in the list will be freed.
413 _gl_context_modes_destroy(__GLcontextModes
* modes
)
415 while (modes
!= NULL
) {
416 __GLcontextModes
*const next
= modes
->next
;
425 * Find a context mode matching a Visual ID.
427 * \param modes List list of context-mode structures to be searched.
428 * \param vid Visual ID to be found.
429 * \returns A pointer to a context-mode in \c modes if \c vid was found in
430 * the list, or \c NULL if it was not.
434 _gl_context_modes_find_visual(__GLcontextModes
* modes
, int vid
)
438 for (m
= modes
; m
!= NULL
; m
= m
->next
)
439 if (m
->visualID
== vid
)
446 _gl_context_modes_find_fbconfig(__GLcontextModes
* modes
, int fbid
)
450 for (m
= modes
; m
!= NULL
; m
= m
->next
)
451 if (m
->fbconfigID
== fbid
)
458 * Determine if two context-modes are the same. This is intended to be used
459 * by libGL implementations to compare to sets of driver generated FBconfigs.
461 * \param a Context-mode to be compared.
462 * \param b Context-mode to be compared.
463 * \returns \c GL_TRUE if the two context-modes are the same. \c GL_FALSE is
464 * returned otherwise.
467 _gl_context_modes_are_same(const __GLcontextModes
* a
,
468 const __GLcontextModes
* b
)
470 return ((a
->rgbMode
== b
->rgbMode
) &&
471 (a
->floatMode
== b
->floatMode
) &&
472 (a
->colorIndexMode
== b
->colorIndexMode
) &&
473 (a
->doubleBufferMode
== b
->doubleBufferMode
) &&
474 (a
->stereoMode
== b
->stereoMode
) &&
475 (a
->redBits
== b
->redBits
) &&
476 (a
->greenBits
== b
->greenBits
) &&
477 (a
->blueBits
== b
->blueBits
) && (a
->alphaBits
== b
->alphaBits
) &&
478 #if 0 /* For some reason these don't get set on the client-side in libGL. */
479 (a
->redMask
== b
->redMask
) &&
480 (a
->greenMask
== b
->greenMask
) &&
481 (a
->blueMask
== b
->blueMask
) && (a
->alphaMask
== b
->alphaMask
) &&
483 (a
->rgbBits
== b
->rgbBits
) &&
484 (a
->indexBits
== b
->indexBits
) &&
485 (a
->accumRedBits
== b
->accumRedBits
) &&
486 (a
->accumGreenBits
== b
->accumGreenBits
) &&
487 (a
->accumBlueBits
== b
->accumBlueBits
) &&
488 (a
->accumAlphaBits
== b
->accumAlphaBits
) &&
489 (a
->depthBits
== b
->depthBits
) &&
490 (a
->stencilBits
== b
->stencilBits
) &&
491 (a
->numAuxBuffers
== b
->numAuxBuffers
) &&
492 (a
->level
== b
->level
) &&
493 (a
->pixmapMode
== b
->pixmapMode
) &&
494 (a
->visualRating
== b
->visualRating
) &&
495 (a
->transparentPixel
== b
->transparentPixel
) &&
496 ((a
->transparentPixel
!= GLX_TRANSPARENT_RGB
) ||
497 ((a
->transparentRed
== b
->transparentRed
) &&
498 (a
->transparentGreen
== b
->transparentGreen
) &&
499 (a
->transparentBlue
== b
->transparentBlue
) &&
500 (a
->transparentAlpha
== b
->transparentAlpha
))) &&
501 ((a
->transparentPixel
!= GLX_TRANSPARENT_INDEX
) ||
502 (a
->transparentIndex
== b
->transparentIndex
)) &&
503 (a
->sampleBuffers
== b
->sampleBuffers
) &&
504 (a
->samples
== b
->samples
) &&
505 ((a
->drawableType
& b
->drawableType
) != 0) &&
506 (a
->renderType
== b
->renderType
) &&
507 (a
->maxPbufferWidth
== b
->maxPbufferWidth
) &&
508 (a
->maxPbufferHeight
== b
->maxPbufferHeight
) &&
509 (a
->maxPbufferPixels
== b
->maxPbufferPixels
) &&
510 (a
->optimalPbufferWidth
== b
->optimalPbufferWidth
) &&
511 (a
->optimalPbufferHeight
== b
->optimalPbufferHeight
) &&
512 (a
->swapMethod
== b
->swapMethod
) &&
513 (a
->bindToTextureRgb
== b
->bindToTextureRgb
) &&
514 (a
->bindToTextureRgba
== b
->bindToTextureRgba
) &&
515 (a
->bindToMipmapTexture
== b
->bindToMipmapTexture
) &&
516 (a
->bindToTextureTargets
== b
->bindToTextureTargets
) &&
517 (a
->yInverted
== b
->yInverted
));