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.
27 * Utility routines for working with \c struct glx_config 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>
38 #include "glxconfig.h"
40 #define NUM_VISUAL_TYPES 6
43 * Get data from a GLX config
45 * \param mode GL context mode whose data is to be returned.
46 * \param attribute Attribute of \c mode that is to be returned.
47 * \param value_return Location to store the data member of \c mode.
48 * \return If \c attribute is a valid attribute of \c mode, zero is
49 * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
52 glx_config_get(struct glx_config
* mode
, int attribute
, int *value_return
)
56 *value_return
= GL_TRUE
;
59 *value_return
= mode
->rgbBits
;
62 *value_return
= !(mode
->renderType
& GLX_COLOR_INDEX_BIT
);
65 *value_return
= mode
->redBits
;
68 *value_return
= mode
->greenBits
;
71 *value_return
= mode
->blueBits
;
74 *value_return
= mode
->alphaBits
;
76 case GLX_DOUBLEBUFFER
:
77 *value_return
= mode
->doubleBufferMode
;
80 *value_return
= mode
->stereoMode
;
83 *value_return
= mode
->numAuxBuffers
;
86 *value_return
= mode
->depthBits
;
88 case GLX_STENCIL_SIZE
:
89 *value_return
= mode
->stencilBits
;
91 case GLX_ACCUM_RED_SIZE
:
92 *value_return
= mode
->accumRedBits
;
94 case GLX_ACCUM_GREEN_SIZE
:
95 *value_return
= mode
->accumGreenBits
;
97 case GLX_ACCUM_BLUE_SIZE
:
98 *value_return
= mode
->accumBlueBits
;
100 case GLX_ACCUM_ALPHA_SIZE
:
101 *value_return
= mode
->accumAlphaBits
;
104 *value_return
= mode
->level
;
106 #ifndef GLX_USE_APPLEGL /* This isn't supported by CGL. */
107 case GLX_TRANSPARENT_TYPE_EXT
:
108 *value_return
= mode
->transparentPixel
;
111 case GLX_TRANSPARENT_RED_VALUE
:
112 *value_return
= mode
->transparentRed
;
114 case GLX_TRANSPARENT_GREEN_VALUE
:
115 *value_return
= mode
->transparentGreen
;
117 case GLX_TRANSPARENT_BLUE_VALUE
:
118 *value_return
= mode
->transparentBlue
;
120 case GLX_TRANSPARENT_ALPHA_VALUE
:
121 *value_return
= mode
->transparentAlpha
;
123 case GLX_TRANSPARENT_INDEX_VALUE
:
124 *value_return
= mode
->transparentIndex
;
126 case GLX_X_VISUAL_TYPE
:
127 *value_return
= mode
->visualType
;
129 case GLX_CONFIG_CAVEAT
:
130 *value_return
= mode
->visualRating
;
133 *value_return
= mode
->visualID
;
135 case GLX_DRAWABLE_TYPE
:
136 *value_return
= mode
->drawableType
;
138 case GLX_RENDER_TYPE
:
139 *value_return
= mode
->renderType
;
141 case GLX_X_RENDERABLE
:
142 *value_return
= mode
->xRenderable
;
144 case GLX_FBCONFIG_ID
:
145 *value_return
= mode
->fbconfigID
;
147 case GLX_MAX_PBUFFER_WIDTH
:
148 *value_return
= mode
->maxPbufferWidth
;
150 case GLX_MAX_PBUFFER_HEIGHT
:
151 *value_return
= mode
->maxPbufferHeight
;
153 case GLX_MAX_PBUFFER_PIXELS
:
154 *value_return
= mode
->maxPbufferPixels
;
156 #ifndef GLX_USE_APPLEGL /* These aren't supported by CGL. */
157 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
158 *value_return
= mode
->optimalPbufferWidth
;
160 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
161 *value_return
= mode
->optimalPbufferHeight
;
163 case GLX_SWAP_METHOD_OML
:
164 *value_return
= mode
->swapMethod
;
167 case GLX_SAMPLE_BUFFERS_SGIS
:
168 *value_return
= mode
->sampleBuffers
;
170 case GLX_SAMPLES_SGIS
:
171 *value_return
= mode
->samples
;
173 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
174 *value_return
= mode
->bindToTextureRgb
;
176 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
177 *value_return
= mode
->bindToTextureRgba
;
179 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
180 *value_return
= mode
->bindToMipmapTexture
== GL_TRUE
? GL_TRUE
:
183 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
184 *value_return
= mode
->bindToTextureTargets
;
186 case GLX_Y_INVERTED_EXT
:
187 *value_return
= mode
->yInverted
;
190 case GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT
:
191 *value_return
= mode
->sRGBCapable
;
194 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
195 * It is ONLY for communication between the GLX client and the GLX
198 case GLX_VISUAL_SELECT_GROUP_SGIX
:
200 return GLX_BAD_ATTRIBUTE
;
206 * Allocate a linked list of \c struct glx_config structures. The fields of
207 * each structure will be initialized to "reasonable" default values. In
208 * most cases this is the default value defined by table 3.4 of the GLX
209 * 1.3 specification. This means that most values are either initialized to
210 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
211 * extensions is added, the new values will be initialized to appropriate
212 * values from the extension specification.
214 * \param count Number of structures to allocate.
215 * \returns A pointer to the first element in a linked list of \c count
216 * stuctures on success, or \c NULL on failure.
218 _X_HIDDEN
struct glx_config
*
219 glx_config_create_list(unsigned count
)
221 struct glx_config
*c
= NULL
;
224 if (!(c
= calloc(count
, sizeof(struct glx_config
))))
227 for (i
= 0; i
< count
; i
++) {
228 c
[i
].visualID
= GLX_DONT_CARE
;
229 c
[i
].visualType
= GLX_DONT_CARE
;
230 c
[i
].visualRating
= GLX_NONE
;
231 c
[i
].transparentPixel
= GLX_NONE
;
232 c
[i
].transparentRed
= GLX_DONT_CARE
;
233 c
[i
].transparentGreen
= GLX_DONT_CARE
;
234 c
[i
].transparentBlue
= GLX_DONT_CARE
;
235 c
[i
].transparentAlpha
= GLX_DONT_CARE
;
236 c
[i
].transparentIndex
= GLX_DONT_CARE
;
237 c
[i
].xRenderable
= GLX_DONT_CARE
;
238 c
[i
].fbconfigID
= GLX_DONT_CARE
;
239 c
[i
].swapMethod
= GLX_SWAP_UNDEFINED_OML
;
240 c
[i
].bindToTextureRgb
= GLX_DONT_CARE
;
241 c
[i
].bindToTextureRgba
= GLX_DONT_CARE
;
242 c
[i
].bindToMipmapTexture
= GLX_DONT_CARE
;
243 c
[i
].bindToTextureTargets
= GLX_DONT_CARE
;
244 c
[i
].yInverted
= GLX_DONT_CARE
;
245 c
[i
].sRGBCapable
= GLX_DONT_CARE
;
248 c
[i
].next
= &(c
[i
+1]);
255 glx_config_destroy_list(struct glx_config
*configs
)
262 * Find a context mode matching a Visual ID.
264 * \param modes List list of context-mode structures to be searched.
265 * \param vid Visual ID to be found.
266 * \returns A pointer to a context-mode in \c modes if \c vid was found in
267 * the list, or \c NULL if it was not.
270 _X_HIDDEN
struct glx_config
*
271 glx_config_find_visual(struct glx_config
*configs
, int vid
)
273 struct glx_config
*c
;
275 for (c
= configs
; c
!= NULL
; c
= c
->next
)
276 if (c
->visualID
== vid
)
282 _X_HIDDEN
struct glx_config
*
283 glx_config_find_fbconfig(struct glx_config
*configs
, int fbid
)
285 struct glx_config
*c
;
287 for (c
= configs
; c
!= NULL
; c
= c
->next
)
288 if (c
->fbconfigID
== fbid
)