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>
35 #include "GL/glxint.h"
39 #include "glxconfig.h"
41 #define NUM_VISUAL_TYPES 6
44 * Get data from a GLX config
46 * \param mode GL context mode whose data is to be returned.
47 * \param attribute Attribute of \c mode that is to be returned.
48 * \param value_return Location to store the data member of \c mode.
49 * \return If \c attribute is a valid attribute of \c mode, zero is
50 * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned.
53 glx_config_get(struct glx_config
* mode
, int attribute
, int *value_return
)
57 *value_return
= GL_TRUE
;
60 *value_return
= mode
->rgbBits
;
63 *value_return
= mode
->rgbMode
;
66 *value_return
= mode
->redBits
;
69 *value_return
= mode
->greenBits
;
72 *value_return
= mode
->blueBits
;
75 *value_return
= mode
->alphaBits
;
77 case GLX_DOUBLEBUFFER
:
78 *value_return
= mode
->doubleBufferMode
;
81 *value_return
= mode
->stereoMode
;
84 *value_return
= mode
->numAuxBuffers
;
87 *value_return
= mode
->depthBits
;
89 case GLX_STENCIL_SIZE
:
90 *value_return
= mode
->stencilBits
;
92 case GLX_ACCUM_RED_SIZE
:
93 *value_return
= mode
->accumRedBits
;
95 case GLX_ACCUM_GREEN_SIZE
:
96 *value_return
= mode
->accumGreenBits
;
98 case GLX_ACCUM_BLUE_SIZE
:
99 *value_return
= mode
->accumBlueBits
;
101 case GLX_ACCUM_ALPHA_SIZE
:
102 *value_return
= mode
->accumAlphaBits
;
105 *value_return
= mode
->level
;
107 #ifndef GLX_USE_APPLEGL /* This isn't supported by CGL. */
108 case GLX_TRANSPARENT_TYPE_EXT
:
109 *value_return
= mode
->transparentPixel
;
112 case GLX_TRANSPARENT_RED_VALUE
:
113 *value_return
= mode
->transparentRed
;
115 case GLX_TRANSPARENT_GREEN_VALUE
:
116 *value_return
= mode
->transparentGreen
;
118 case GLX_TRANSPARENT_BLUE_VALUE
:
119 *value_return
= mode
->transparentBlue
;
121 case GLX_TRANSPARENT_ALPHA_VALUE
:
122 *value_return
= mode
->transparentAlpha
;
124 case GLX_TRANSPARENT_INDEX_VALUE
:
125 *value_return
= mode
->transparentIndex
;
127 case GLX_X_VISUAL_TYPE
:
128 *value_return
= mode
->visualType
;
130 case GLX_CONFIG_CAVEAT
:
131 *value_return
= mode
->visualRating
;
134 *value_return
= mode
->visualID
;
136 case GLX_DRAWABLE_TYPE
:
137 *value_return
= mode
->drawableType
;
139 case GLX_RENDER_TYPE
:
140 *value_return
= mode
->renderType
;
142 case GLX_X_RENDERABLE
:
143 *value_return
= mode
->xRenderable
;
145 case GLX_FBCONFIG_ID
:
146 *value_return
= mode
->fbconfigID
;
148 case GLX_MAX_PBUFFER_WIDTH
:
149 *value_return
= mode
->maxPbufferWidth
;
151 case GLX_MAX_PBUFFER_HEIGHT
:
152 *value_return
= mode
->maxPbufferHeight
;
154 case GLX_MAX_PBUFFER_PIXELS
:
155 *value_return
= mode
->maxPbufferPixels
;
157 #ifndef GLX_USE_APPLEGL /* These aren't supported by CGL. */
158 case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
:
159 *value_return
= mode
->optimalPbufferWidth
;
161 case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
:
162 *value_return
= mode
->optimalPbufferHeight
;
164 case GLX_SWAP_METHOD_OML
:
165 *value_return
= mode
->swapMethod
;
168 case GLX_SAMPLE_BUFFERS_SGIS
:
169 *value_return
= mode
->sampleBuffers
;
171 case GLX_SAMPLES_SGIS
:
172 *value_return
= mode
->samples
;
174 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
175 *value_return
= mode
->bindToTextureRgb
;
177 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
178 *value_return
= mode
->bindToTextureRgba
;
180 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
181 *value_return
= mode
->bindToMipmapTexture
== GL_TRUE
? GL_TRUE
:
184 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
185 *value_return
= mode
->bindToTextureTargets
;
187 case GLX_Y_INVERTED_EXT
:
188 *value_return
= mode
->yInverted
;
191 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
192 * It is ONLY for communication between the GLX client and the GLX
195 case GLX_VISUAL_SELECT_GROUP_SGIX
:
197 return GLX_BAD_ATTRIBUTE
;
203 * Allocate a linked list of \c struct glx_config structures. The fields of
204 * each structure will be initialized to "reasonable" default values. In
205 * most cases this is the default value defined by table 3.4 of the GLX
206 * 1.3 specification. This means that most values are either initialized to
207 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
208 * extensions is added, the new values will be initialized to appropriate
209 * values from the extension specification.
211 * \param count Number of structures to allocate.
212 * \param minimum_size Minimum size of a structure to allocate. This allows
213 * for differences in the version of the
214 * \c struct glx_config stucture used in libGL and in a
216 * \returns A pointer to the first element in a linked list of \c count
217 * stuctures on success, or \c NULL on failure.
219 _X_HIDDEN
struct glx_config
*
220 glx_config_create_list(unsigned count
)
222 const size_t size
= sizeof(struct glx_config
);
223 struct glx_config
*base
= NULL
;
224 struct glx_config
**next
;
228 for (i
= 0; i
< count
; i
++) {
229 *next
= (struct glx_config
*) malloc(size
);
231 glx_config_destroy_list(base
);
236 (void) memset(*next
, 0, size
);
237 (*next
)->visualID
= GLX_DONT_CARE
;
238 (*next
)->visualType
= GLX_DONT_CARE
;
239 (*next
)->visualRating
= GLX_NONE
;
240 (*next
)->transparentPixel
= GLX_NONE
;
241 (*next
)->transparentRed
= GLX_DONT_CARE
;
242 (*next
)->transparentGreen
= GLX_DONT_CARE
;
243 (*next
)->transparentBlue
= GLX_DONT_CARE
;
244 (*next
)->transparentAlpha
= GLX_DONT_CARE
;
245 (*next
)->transparentIndex
= GLX_DONT_CARE
;
246 (*next
)->xRenderable
= GLX_DONT_CARE
;
247 (*next
)->fbconfigID
= GLX_DONT_CARE
;
248 (*next
)->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
249 (*next
)->bindToTextureRgb
= GLX_DONT_CARE
;
250 (*next
)->bindToTextureRgba
= GLX_DONT_CARE
;
251 (*next
)->bindToMipmapTexture
= GLX_DONT_CARE
;
252 (*next
)->bindToTextureTargets
= GLX_DONT_CARE
;
253 (*next
)->yInverted
= GLX_DONT_CARE
;
255 next
= &((*next
)->next
);
262 glx_config_destroy_list(struct glx_config
*configs
)
264 while (configs
!= NULL
) {
265 struct glx_config
*const next
= configs
->next
;
274 * Find a context mode matching a Visual ID.
276 * \param modes List list of context-mode structures to be searched.
277 * \param vid Visual ID to be found.
278 * \returns A pointer to a context-mode in \c modes if \c vid was found in
279 * the list, or \c NULL if it was not.
282 _X_HIDDEN
struct glx_config
*
283 glx_config_find_visual(struct glx_config
*configs
, int vid
)
285 struct glx_config
*c
;
287 for (c
= configs
; c
!= NULL
; c
= c
->next
)
288 if (c
->visualID
== vid
)
294 _X_HIDDEN
struct glx_config
*
295 glx_config_find_fbconfig(struct glx_config
*configs
, int fbid
)
297 struct glx_config
*c
;
299 for (c
= configs
; c
!= NULL
; c
= c
->next
)
300 if (c
->fbconfigID
== fbid
)