2 * freeglut_state_x11.c
\r
4 * X11-specific freeglut state query methods.
\r
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
\r
7 * Written by John F. Fay, <fayjf@sourceforge.net>
\r
8 * Creation date: Sat Feb 4 2012
\r
10 * Permission is hereby granted, free of charge, to any person obtaining a
\r
11 * copy of this software and associated documentation files (the "Software"),
\r
12 * to deal in the Software without restriction, including without limitation
\r
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
14 * and/or sell copies of the Software, and to permit persons to whom the
\r
15 * Software is furnished to do so, subject to the following conditions:
\r
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
\r
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 #include <GL/freeglut.h>
\r
29 #include "../Common/freeglut_internal.h"
\r
32 * TODO BEFORE THE STABLE RELEASE:
\r
34 * fgPlatformChooseFBConfig() -- OK, but what about glutInitDisplayString()?
\r
37 /* A helper function to check if a display mode is possible to use */
\r
38 #if TARGET_HOST_POSIX_X11
\r
39 GLXFBConfig* fgPlatformChooseFBConfig( int* numcfgs );
\r
43 * Queries the GL context about some attributes
\r
45 int fgPlatformGetConfig( int attribute )
\r
47 int returnValue = 0;
\r
48 int result; /* Not checked */
\r
50 if( fgStructure.CurrentWindow )
\r
51 result = glXGetFBConfigAttrib( fgDisplay.pDisplay.Display,
\r
52 *(fgStructure.CurrentWindow->Window.pContext.FBConfig),
\r
59 int fgPlatformGlutGet ( GLenum eWhat )
\r
66 * The window/context specific queries are handled mostly by
\r
67 * fgPlatformGetConfig().
\r
69 case GLUT_WINDOW_NUM_SAMPLES:
\r
70 #ifdef GLX_VERSION_1_3
\r
71 glGetIntegerv(GL_SAMPLES, &nsamples);
\r
76 * The rest of GLX queries under X are general enough to use a macro to
\r
79 # define GLX_QUERY(a,b) case a: return fgPlatformGetConfig( b );
\r
81 GLX_QUERY( GLUT_WINDOW_RGBA, GLX_RGBA );
\r
82 GLX_QUERY( GLUT_WINDOW_DOUBLEBUFFER, GLX_DOUBLEBUFFER );
\r
83 GLX_QUERY( GLUT_WINDOW_BUFFER_SIZE, GLX_BUFFER_SIZE );
\r
84 GLX_QUERY( GLUT_WINDOW_STENCIL_SIZE, GLX_STENCIL_SIZE );
\r
85 GLX_QUERY( GLUT_WINDOW_DEPTH_SIZE, GLX_DEPTH_SIZE );
\r
86 GLX_QUERY( GLUT_WINDOW_RED_SIZE, GLX_RED_SIZE );
\r
87 GLX_QUERY( GLUT_WINDOW_GREEN_SIZE, GLX_GREEN_SIZE );
\r
88 GLX_QUERY( GLUT_WINDOW_BLUE_SIZE, GLX_BLUE_SIZE );
\r
89 GLX_QUERY( GLUT_WINDOW_ALPHA_SIZE, GLX_ALPHA_SIZE );
\r
90 GLX_QUERY( GLUT_WINDOW_ACCUM_RED_SIZE, GLX_ACCUM_RED_SIZE );
\r
91 GLX_QUERY( GLUT_WINDOW_ACCUM_GREEN_SIZE, GLX_ACCUM_GREEN_SIZE );
\r
92 GLX_QUERY( GLUT_WINDOW_ACCUM_BLUE_SIZE, GLX_ACCUM_BLUE_SIZE );
\r
93 GLX_QUERY( GLUT_WINDOW_ACCUM_ALPHA_SIZE, GLX_ACCUM_ALPHA_SIZE );
\r
94 GLX_QUERY( GLUT_WINDOW_STEREO, GLX_STEREO );
\r
98 /* Colormap size is handled in a bit different way than all the rest */
\r
99 case GLUT_WINDOW_COLORMAP_SIZE:
\r
100 if( (fgPlatformGetConfig( GLX_RGBA )) || (fgStructure.CurrentWindow == NULL) )
\r
103 * We've got a RGBA visual, so there is no colormap at all.
\r
104 * The other possibility is that we have no current window set.
\r
110 const GLXFBConfig * fbconfig =
\r
111 fgStructure.CurrentWindow->Window.pContext.FBConfig;
\r
113 XVisualInfo * visualInfo =
\r
114 glXGetVisualFromFBConfig( fgDisplay.pDisplay.Display, *fbconfig );
\r
116 const int result = visualInfo->visual->map_entries;
\r
124 * Those calls are somewhat similiar, as they use XGetWindowAttributes()
\r
127 case GLUT_WINDOW_X:
\r
128 case GLUT_WINDOW_Y:
\r
129 case GLUT_WINDOW_BORDER_WIDTH:
\r
130 case GLUT_WINDOW_HEADER_HEIGHT:
\r
135 if( fgStructure.CurrentWindow == NULL )
\r
138 XTranslateCoordinates(
\r
139 fgDisplay.pDisplay.Display,
\r
140 fgStructure.CurrentWindow->Window.Handle,
\r
141 fgDisplay.pDisplay.RootWindow,
\r
146 case GLUT_WINDOW_X: return x;
\r
147 case GLUT_WINDOW_Y: return y;
\r
152 XTranslateCoordinates(
\r
153 fgDisplay.pDisplay.Display,
\r
154 fgStructure.CurrentWindow->Window.Handle,
\r
155 w, 0, 0, &x, &y, &w);
\r
159 case GLUT_WINDOW_BORDER_WIDTH: return x;
\r
160 case GLUT_WINDOW_HEADER_HEIGHT: return y;
\r
164 case GLUT_WINDOW_WIDTH:
\r
165 case GLUT_WINDOW_HEIGHT:
\r
167 XWindowAttributes winAttributes;
\r
169 if( fgStructure.CurrentWindow == NULL )
\r
171 XGetWindowAttributes(
\r
172 fgDisplay.pDisplay.Display,
\r
173 fgStructure.CurrentWindow->Window.Handle,
\r
178 case GLUT_WINDOW_WIDTH: return winAttributes.width ;
\r
179 case GLUT_WINDOW_HEIGHT: return winAttributes.height ;
\r
183 /* I do not know yet if there will be a fgChooseVisual() function for Win32 */
\r
184 case GLUT_DISPLAY_MODE_POSSIBLE:
\r
186 /* We should not have to call fgPlatformChooseFBConfig again here. */
\r
187 GLXFBConfig * fbconfig;
\r
190 fbconfig = fgPlatformChooseFBConfig(NULL);
\r
192 if (fbconfig == NULL)
\r
205 /* This is system-dependant */
\r
206 case GLUT_WINDOW_FORMAT_ID:
\r
207 if( fgStructure.CurrentWindow == NULL )
\r
210 return fgPlatformGetConfig( GLX_VISUAL_ID );
\r
213 fgWarning( "glutGet(): missing enum handle %d", eWhat );
\r
219 int fgPlatformGlutDeviceGet ( GLenum eWhat )
\r
223 case GLUT_HAS_KEYBOARD:
\r
225 * X11 has a core keyboard by definition, although it can
\r
226 * be present as a virtual/dummy keyboard. For now, there
\r
227 * is no reliable way to tell if a real keyboard is present.
\r
231 /* X11 has a mouse by definition */
\r
232 case GLUT_HAS_MOUSE:
\r
235 case GLUT_NUM_MOUSE_BUTTONS:
\r
236 /* We should be able to pass NULL when the last argument is zero,
\r
237 * but at least one X server has a bug where this causes a segfault.
\r
239 * In XFree86/Xorg servers, a mouse wheel is seen as two buttons
\r
240 * rather than an Axis; "freeglut_main.c" expects this when
\r
241 * checking for a wheel event.
\r
245 int nbuttons = XGetPointerMapping(fgDisplay.pDisplay.Display, &map,0);
\r
250 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
\r
254 /* And now -- the failure. */
\r
258 int fgPlatformGlutLayerGet( GLenum eWhat )
\r
261 * This is easy as layers are not implemented ;-)
\r
263 * XXX Can we merge the UNIX/X11 and WIN32 sections? Or
\r
264 * XXX is overlay support planned?
\r
268 case GLUT_OVERLAY_POSSIBLE:
\r
271 case GLUT_LAYER_IN_USE:
\r
272 return GLUT_NORMAL;
\r
274 case GLUT_HAS_OVERLAY:
\r
277 case GLUT_TRANSPARENT_INDEX:
\r
279 * Return just anything, which is always defined as zero
\r
285 case GLUT_NORMAL_DAMAGED:
\r
286 /* XXX Actually I do not know. Maybe. */
\r
289 case GLUT_OVERLAY_DAMAGED:
\r
293 fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );
\r
297 /* And fail. That's good. Programs do love failing. */
\r
302 int *fgPlatformGlutGetModeValues(GLenum eWhat, int *size)
\r
307 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
\r
308 int fbconfigArraySize; /* Number of FBConfigs in the array */
\r
309 int attribute_name = 0;
\r
317 case GLUT_MULTISAMPLE:
\r
319 attributes[0] = GLX_BUFFER_SIZE;
\r
320 attributes[1] = GLX_DONT_CARE;
\r
326 FBConfigs are now sorted by increasing number of auxiliary
\r
327 buffers. We want at least one buffer.
\r
329 attributes[2] = GLX_AUX_BUFFERS;
\r
331 attributes[4] = None;
\r
333 attribute_name = GLX_AUX_BUFFERS;
\r
338 case GLUT_MULTISAMPLE:
\r
339 attributes[2] = GLX_AUX_BUFFERS;
\r
340 attributes[3] = GLX_DONT_CARE;
\r
341 attributes[4] = GLX_SAMPLE_BUFFERS;
\r
344 FBConfigs are now sorted by increasing number of samples per
\r
345 pixel. We want at least one sample.
\r
347 attributes[6] = GLX_SAMPLES;
\r
349 attributes[8] = None;
\r
351 attribute_name = GLX_SAMPLES;
\r
356 fbconfigArray = glXChooseFBConfig(fgDisplay.pDisplay.Display,
\r
357 fgDisplay.pDisplay.Screen,
\r
359 &fbconfigArraySize);
\r
361 if (fbconfigArray != NULL)
\r
364 int result; /* Returned by glXGetFBConfigAttrib. Not checked. */
\r
365 int previous_value;
\r
368 temp_array = malloc(sizeof(int) * fbconfigArraySize);
\r
369 previous_value = 0;
\r
371 for (i = 0; i < fbconfigArraySize; i++)
\r
375 result = glXGetFBConfigAttrib(fgDisplay.pDisplay.Display,
\r
379 if (value > previous_value)
\r
381 temp_array[*size] = value;
\r
382 previous_value = value;
\r
387 array = malloc(sizeof(int) * (*size));
\r
388 for (i = 0; i < *size; i++)
\r
390 array[i] = temp_array[i];
\r
394 XFree(fbconfigArray);
\r