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 case GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT:
192 *value_return = mode->sRGBCapable;
195 /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
196 * It is ONLY for communication between the GLX client and the GLX
199 case GLX_VISUAL_SELECT_GROUP_SGIX:
201 return GLX_BAD_ATTRIBUTE;
207 * Allocate a linked list of \c struct glx_config structures. The fields of
208 * each structure will be initialized to "reasonable" default values. In
209 * most cases this is the default value defined by table 3.4 of the GLX
210 * 1.3 specification. This means that most values are either initialized to
211 * zero or \c GLX_DONT_CARE (which is -1). As support for additional
212 * extensions is added, the new values will be initialized to appropriate
213 * values from the extension specification.
215 * \param count Number of structures to allocate.
216 * \param minimum_size Minimum size of a structure to allocate. This allows
217 * for differences in the version of the
218 * \c struct glx_config stucture used in libGL and in a
220 * \returns A pointer to the first element in a linked list of \c count
221 * stuctures on success, or \c NULL on failure.
223 _X_HIDDEN struct glx_config *
224 glx_config_create_list(unsigned count)
226 const size_t size = sizeof(struct glx_config);
227 struct glx_config *base = NULL;
228 struct glx_config **next;
232 for (i = 0; i < count; i++) {
233 *next = (struct glx_config *) malloc(size);
235 glx_config_destroy_list(base);
240 (void) memset(*next, 0, size);
241 (*next)->visualID = GLX_DONT_CARE;
242 (*next)->visualType = GLX_DONT_CARE;
243 (*next)->visualRating = GLX_NONE;
244 (*next)->transparentPixel = GLX_NONE;
245 (*next)->transparentRed = GLX_DONT_CARE;
246 (*next)->transparentGreen = GLX_DONT_CARE;
247 (*next)->transparentBlue = GLX_DONT_CARE;
248 (*next)->transparentAlpha = GLX_DONT_CARE;
249 (*next)->transparentIndex = GLX_DONT_CARE;
250 (*next)->xRenderable = GLX_DONT_CARE;
251 (*next)->fbconfigID = GLX_DONT_CARE;
252 (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML;
253 (*next)->bindToTextureRgb = GLX_DONT_CARE;
254 (*next)->bindToTextureRgba = GLX_DONT_CARE;
255 (*next)->bindToMipmapTexture = GLX_DONT_CARE;
256 (*next)->bindToTextureTargets = GLX_DONT_CARE;
257 (*next)->yInverted = GLX_DONT_CARE;
258 (*next)->sRGBCapable = GLX_DONT_CARE;
260 next = &((*next)->next);
267 glx_config_destroy_list(struct glx_config *configs)
269 while (configs != NULL) {
270 struct glx_config *const next = configs->next;
279 * Find a context mode matching a Visual ID.
281 * \param modes List list of context-mode structures to be searched.
282 * \param vid Visual ID to be found.
283 * \returns A pointer to a context-mode in \c modes if \c vid was found in
284 * the list, or \c NULL if it was not.
287 _X_HIDDEN struct glx_config *
288 glx_config_find_visual(struct glx_config *configs, int vid)
290 struct glx_config *c;
292 for (c = configs; c != NULL; c = c->next)
293 if (c->visualID == vid)
299 _X_HIDDEN struct glx_config *
300 glx_config_find_fbconfig(struct glx_config *configs, int fbid)
302 struct glx_config *c;
304 for (c = configs; c != NULL; c = c->next)
305 if (c->fbconfigID == fbid)