4 * X11-specific freeglut state query methods.
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
7 * Written by John F. Fay, <fayjf@sourceforge.net>
8 * Creation date: Sat Feb 4 2012
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <GL/freeglut.h>
29 #include "../fg_internal.h"
32 * TODO BEFORE THE STABLE RELEASE:
34 * fgPlatformChooseFBConfig() -- OK, but what about glutInitDisplayString()?
37 /* A helper function to check if a display mode is possible to use */
38 GLXFBConfig* fgPlatformChooseFBConfig( int* numcfgs );
41 * Queries the GL context about some attributes
43 int fgPlatformGetConfig( int attribute )
46 int result; /* Not checked */
48 if( fgStructure.CurrentWindow )
49 result = glXGetFBConfigAttrib( fgDisplay.pDisplay.Display,
50 *(fgStructure.CurrentWindow->Window.pContext.FBConfig),
57 int fgPlatformGlutGet ( GLenum eWhat )
64 * The window/context specific queries are handled mostly by
65 * fgPlatformGetConfig().
67 case GLUT_WINDOW_NUM_SAMPLES:
68 #ifdef GLX_VERSION_1_3
69 glGetIntegerv(GL_SAMPLES, &nsamples);
74 * The rest of GLX queries under X are general enough to use a macro to
77 # define GLX_QUERY(a,b) case a: return fgPlatformGetConfig( b );
79 GLX_QUERY( GLUT_WINDOW_RGBA, GLX_RGBA );
80 GLX_QUERY( GLUT_WINDOW_DOUBLEBUFFER, GLX_DOUBLEBUFFER );
81 GLX_QUERY( GLUT_WINDOW_BUFFER_SIZE, GLX_BUFFER_SIZE );
82 GLX_QUERY( GLUT_WINDOW_STENCIL_SIZE, GLX_STENCIL_SIZE );
83 GLX_QUERY( GLUT_WINDOW_DEPTH_SIZE, GLX_DEPTH_SIZE );
84 GLX_QUERY( GLUT_WINDOW_RED_SIZE, GLX_RED_SIZE );
85 GLX_QUERY( GLUT_WINDOW_GREEN_SIZE, GLX_GREEN_SIZE );
86 GLX_QUERY( GLUT_WINDOW_BLUE_SIZE, GLX_BLUE_SIZE );
87 GLX_QUERY( GLUT_WINDOW_ALPHA_SIZE, GLX_ALPHA_SIZE );
88 GLX_QUERY( GLUT_WINDOW_ACCUM_RED_SIZE, GLX_ACCUM_RED_SIZE );
89 GLX_QUERY( GLUT_WINDOW_ACCUM_GREEN_SIZE, GLX_ACCUM_GREEN_SIZE );
90 GLX_QUERY( GLUT_WINDOW_ACCUM_BLUE_SIZE, GLX_ACCUM_BLUE_SIZE );
91 GLX_QUERY( GLUT_WINDOW_ACCUM_ALPHA_SIZE, GLX_ACCUM_ALPHA_SIZE );
92 GLX_QUERY( GLUT_WINDOW_STEREO, GLX_STEREO );
96 /* Colormap size is handled in a bit different way than all the rest */
97 case GLUT_WINDOW_COLORMAP_SIZE:
98 if( (fgPlatformGetConfig( GLX_RGBA )) || (fgStructure.CurrentWindow == NULL) )
101 * We've got a RGBA visual, so there is no colormap at all.
102 * The other possibility is that we have no current window set.
108 const GLXFBConfig * fbconfig =
109 fgStructure.CurrentWindow->Window.pContext.FBConfig;
111 XVisualInfo * visualInfo =
112 glXGetVisualFromFBConfig( fgDisplay.pDisplay.Display, *fbconfig );
114 const int result = visualInfo->visual->map_entries;
122 * Those calls are somewhat similiar, as they use XGetWindowAttributes()
127 case GLUT_WINDOW_BORDER_WIDTH:
128 case GLUT_WINDOW_HEADER_HEIGHT:
133 if( fgStructure.CurrentWindow == NULL )
136 XTranslateCoordinates(
137 fgDisplay.pDisplay.Display,
138 fgStructure.CurrentWindow->Window.Handle,
139 fgDisplay.pDisplay.RootWindow,
144 case GLUT_WINDOW_X: return x;
145 case GLUT_WINDOW_Y: return y;
150 XTranslateCoordinates(
151 fgDisplay.pDisplay.Display,
152 fgStructure.CurrentWindow->Window.Handle,
153 w, 0, 0, &x, &y, &w);
157 case GLUT_WINDOW_BORDER_WIDTH: return x;
158 case GLUT_WINDOW_HEADER_HEIGHT: return y;
162 case GLUT_WINDOW_WIDTH:
163 case GLUT_WINDOW_HEIGHT:
165 XWindowAttributes winAttributes;
167 if( fgStructure.CurrentWindow == NULL )
169 XGetWindowAttributes(
170 fgDisplay.pDisplay.Display,
171 fgStructure.CurrentWindow->Window.Handle,
176 case GLUT_WINDOW_WIDTH: return winAttributes.width ;
177 case GLUT_WINDOW_HEIGHT: return winAttributes.height ;
181 /* I do not know yet if there will be a fgChooseVisual() function for Win32 */
182 case GLUT_DISPLAY_MODE_POSSIBLE:
184 /* We should not have to call fgPlatformChooseFBConfig again here. */
185 GLXFBConfig * fbconfig;
188 fbconfig = fgPlatformChooseFBConfig(NULL);
190 if (fbconfig == NULL)
203 /* This is system-dependant */
204 case GLUT_WINDOW_FORMAT_ID:
205 if( fgStructure.CurrentWindow == NULL )
208 return fgPlatformGetConfig( GLX_VISUAL_ID );
211 fgWarning( "glutGet(): missing enum handle %d", eWhat );
219 int fgPlatformGlutDeviceGet ( GLenum eWhat )
223 case GLUT_HAS_KEYBOARD:
225 * X11 has a core keyboard by definition, although it can
226 * be present as a virtual/dummy keyboard. For now, there
227 * is no reliable way to tell if a real keyboard is present.
231 /* X11 has a mouse by definition */
235 case GLUT_NUM_MOUSE_BUTTONS:
236 /* We should be able to pass NULL when the last argument is zero,
237 * but at least one X server has a bug where this causes a segfault.
239 * In XFree86/Xorg servers, a mouse wheel is seen as two buttons
240 * rather than an Axis; "freeglut_main.c" expects this when
241 * checking for a wheel event.
245 int nbuttons = XGetPointerMapping(fgDisplay.pDisplay.Display, &map,0);
250 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
254 /* And now -- the failure. */
259 int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size)
264 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
265 int fbconfigArraySize; /* Number of FBConfigs in the array */
266 int attribute_name = 0;
274 case GLUT_MULTISAMPLE:
276 attributes[0] = GLX_BUFFER_SIZE;
277 attributes[1] = GLX_DONT_CARE;
283 FBConfigs are now sorted by increasing number of auxiliary
284 buffers. We want at least one buffer.
286 attributes[2] = GLX_AUX_BUFFERS;
288 attributes[4] = None;
290 attribute_name = GLX_AUX_BUFFERS;
295 case GLUT_MULTISAMPLE:
296 attributes[2] = GLX_AUX_BUFFERS;
297 attributes[3] = GLX_DONT_CARE;
298 attributes[4] = GLX_SAMPLE_BUFFERS;
301 FBConfigs are now sorted by increasing number of samples per
302 pixel. We want at least one sample.
304 attributes[6] = GLX_SAMPLES;
306 attributes[8] = None;
308 attribute_name = GLX_SAMPLES;
313 fbconfigArray = glXChooseFBConfig(fgDisplay.pDisplay.Display,
314 fgDisplay.pDisplay.Screen,
318 if (fbconfigArray != NULL)
321 int result; /* Returned by glXGetFBConfigAttrib. Not checked. */
325 temp_array = malloc(sizeof(int) * fbconfigArraySize);
328 for (i = 0; i < fbconfigArraySize; i++)
332 result = glXGetFBConfigAttrib(fgDisplay.pDisplay.Display,
336 if (value > previous_value)
338 temp_array[*size] = value;
339 previous_value = value;
344 array = malloc(sizeof(int) * (*size));
345 for (i = 0; i < *size; i++)
347 array[i] = temp_array[i];
351 XFree(fbconfigArray);