4 * Freeglut state query methods.
\r
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
\r
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
\r
8 * Creation date: Thu Dec 16 1999
\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 "freeglut_internal.h"
\r
32 * TODO BEFORE THE STABLE RELEASE:
\r
34 * glutGet() -- X11 tests passed, but check if all enums
\r
35 * handled (what about Win32?)
\r
36 * glutDeviceGet() -- X11 tests passed, but check if all enums
\r
37 * handled (what about Win32?)
\r
38 * glutGetModifiers() -- OK, but could also remove the limitation
\r
39 * glutLayerGet() -- what about GLUT_NORMAL_DAMAGED?
\r
41 * The fail-on-call policy will help adding the most needed things imho.
\r
44 extern int fgPlatformGlutGet ( GLenum eWhat );
\r
46 /* -- LOCAL DEFINITIONS ---------------------------------------------------- */
\r
48 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
\r
50 #if TARGET_HOST_POSIX_X11
\r
52 * Queries the GL context about some attributes
\r
54 static int fghGetConfig( int attribute )
\r
56 int returnValue = 0;
\r
57 int result; /* Not checked */
\r
59 if( fgStructure.CurrentWindow )
\r
60 result = glXGetFBConfigAttrib( fgDisplay.Display,
\r
61 *(fgStructure.CurrentWindow->Window.FBConfig),
\r
68 static int fgPlatformGlutGet ( GLenum eWhat )
\r
75 * The window/context specific queries are handled mostly by
\r
78 case GLUT_WINDOW_NUM_SAMPLES:
\r
79 #ifdef GLX_VERSION_1_3
\r
80 glGetIntegerv(GL_SAMPLES, &nsamples);
\r
85 * The rest of GLX queries under X are general enough to use a macro to
\r
88 # define GLX_QUERY(a,b) case a: return fghGetConfig( b );
\r
90 GLX_QUERY( GLUT_WINDOW_RGBA, GLX_RGBA );
\r
91 GLX_QUERY( GLUT_WINDOW_DOUBLEBUFFER, GLX_DOUBLEBUFFER );
\r
92 GLX_QUERY( GLUT_WINDOW_BUFFER_SIZE, GLX_BUFFER_SIZE );
\r
93 GLX_QUERY( GLUT_WINDOW_STENCIL_SIZE, GLX_STENCIL_SIZE );
\r
94 GLX_QUERY( GLUT_WINDOW_DEPTH_SIZE, GLX_DEPTH_SIZE );
\r
95 GLX_QUERY( GLUT_WINDOW_RED_SIZE, GLX_RED_SIZE );
\r
96 GLX_QUERY( GLUT_WINDOW_GREEN_SIZE, GLX_GREEN_SIZE );
\r
97 GLX_QUERY( GLUT_WINDOW_BLUE_SIZE, GLX_BLUE_SIZE );
\r
98 GLX_QUERY( GLUT_WINDOW_ALPHA_SIZE, GLX_ALPHA_SIZE );
\r
99 GLX_QUERY( GLUT_WINDOW_ACCUM_RED_SIZE, GLX_ACCUM_RED_SIZE );
\r
100 GLX_QUERY( GLUT_WINDOW_ACCUM_GREEN_SIZE, GLX_ACCUM_GREEN_SIZE );
\r
101 GLX_QUERY( GLUT_WINDOW_ACCUM_BLUE_SIZE, GLX_ACCUM_BLUE_SIZE );
\r
102 GLX_QUERY( GLUT_WINDOW_ACCUM_ALPHA_SIZE, GLX_ACCUM_ALPHA_SIZE );
\r
103 GLX_QUERY( GLUT_WINDOW_STEREO, GLX_STEREO );
\r
107 /* Colormap size is handled in a bit different way than all the rest */
\r
108 case GLUT_WINDOW_COLORMAP_SIZE:
\r
109 if( (fghGetConfig( GLX_RGBA )) || (fgStructure.CurrentWindow == NULL) )
\r
112 * We've got a RGBA visual, so there is no colormap at all.
\r
113 * The other possibility is that we have no current window set.
\r
119 const GLXFBConfig * fbconfig =
\r
120 fgStructure.CurrentWindow->Window.FBConfig;
\r
122 XVisualInfo * visualInfo =
\r
123 glXGetVisualFromFBConfig( fgDisplay.Display, *fbconfig );
\r
125 const int result = visualInfo->visual->map_entries;
\r
133 * Those calls are somewhat similiar, as they use XGetWindowAttributes()
\r
136 case GLUT_WINDOW_X:
\r
137 case GLUT_WINDOW_Y:
\r
138 case GLUT_WINDOW_BORDER_WIDTH:
\r
139 case GLUT_WINDOW_HEADER_HEIGHT:
\r
144 if( fgStructure.CurrentWindow == NULL )
\r
147 XTranslateCoordinates(
\r
149 fgStructure.CurrentWindow->Window.Handle,
\r
150 fgDisplay.RootWindow,
\r
155 case GLUT_WINDOW_X: return x;
\r
156 case GLUT_WINDOW_Y: return y;
\r
161 XTranslateCoordinates(
\r
163 fgStructure.CurrentWindow->Window.Handle,
\r
164 w, 0, 0, &x, &y, &w);
\r
168 case GLUT_WINDOW_BORDER_WIDTH: return x;
\r
169 case GLUT_WINDOW_HEADER_HEIGHT: return y;
\r
173 case GLUT_WINDOW_WIDTH:
\r
174 case GLUT_WINDOW_HEIGHT:
\r
176 XWindowAttributes winAttributes;
\r
178 if( fgStructure.CurrentWindow == NULL )
\r
180 XGetWindowAttributes(
\r
182 fgStructure.CurrentWindow->Window.Handle,
\r
187 case GLUT_WINDOW_WIDTH: return winAttributes.width ;
\r
188 case GLUT_WINDOW_HEIGHT: return winAttributes.height ;
\r
192 /* I do not know yet if there will be a fgChooseVisual() function for Win32 */
\r
193 case GLUT_DISPLAY_MODE_POSSIBLE:
\r
195 /* We should not have to call fgChooseFBConfig again here. */
\r
196 GLXFBConfig * fbconfig;
\r
199 fbconfig = fgChooseFBConfig(NULL);
\r
201 if (fbconfig == NULL)
\r
214 /* This is system-dependant */
\r
215 case GLUT_WINDOW_FORMAT_ID:
\r
216 if( fgStructure.CurrentWindow == NULL )
\r
219 return fghGetConfig( GLX_VISUAL_ID );
\r
222 fgWarning( "glutGet(): missing enum handle %d", eWhat );
\r
228 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
\r
231 * General settings assignment method
\r
233 void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
\r
235 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetOption" );
\r
238 * XXX In chronological code add order. (WHY in that order?)
\r
242 case GLUT_INIT_WINDOW_X:
\r
243 fgState.Position.X = (GLint)value;
\r
246 case GLUT_INIT_WINDOW_Y:
\r
247 fgState.Position.Y = (GLint)value;
\r
250 case GLUT_INIT_WINDOW_WIDTH:
\r
251 fgState.Size.X = (GLint)value;
\r
254 case GLUT_INIT_WINDOW_HEIGHT:
\r
255 fgState.Size.Y = (GLint)value;
\r
258 case GLUT_INIT_DISPLAY_MODE:
\r
259 fgState.DisplayMode = (unsigned int)value;
\r
262 case GLUT_ACTION_ON_WINDOW_CLOSE:
\r
263 fgState.ActionOnWindowClose = value;
\r
266 case GLUT_RENDERING_CONTEXT:
\r
267 fgState.UseCurrentContext =
\r
268 ( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE;
\r
271 case GLUT_DIRECT_RENDERING:
\r
272 fgState.DirectContext = value;
\r
275 case GLUT_WINDOW_CURSOR:
\r
276 if( fgStructure.CurrentWindow != NULL )
\r
277 fgStructure.CurrentWindow->State.Cursor = value;
\r
281 fgState.AuxiliaryBufferNumber = value;
\r
284 case GLUT_MULTISAMPLE:
\r
285 fgState.SampleNumber = value;
\r
289 fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
\r
295 * General settings query method
\r
297 int FGAPIENTRY glutGet( GLenum eWhat )
\r
301 case GLUT_INIT_STATE:
\r
302 return fgState.Initialised;
\r
304 case GLUT_ELAPSED_TIME:
\r
305 return fgElapsedTime();
\r
308 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGet" );
\r
310 /* XXX In chronological code add order. (WHY in that order?) */
\r
313 /* Following values are stored in fgState and fgDisplay global structures */
\r
314 case GLUT_SCREEN_WIDTH: return fgDisplay.ScreenWidth ;
\r
315 case GLUT_SCREEN_HEIGHT: return fgDisplay.ScreenHeight ;
\r
316 case GLUT_SCREEN_WIDTH_MM: return fgDisplay.ScreenWidthMM ;
\r
317 case GLUT_SCREEN_HEIGHT_MM: return fgDisplay.ScreenHeightMM;
\r
318 case GLUT_INIT_WINDOW_X: return fgState.Position.Use ?
\r
319 fgState.Position.X : -1 ;
\r
320 case GLUT_INIT_WINDOW_Y: return fgState.Position.Use ?
\r
321 fgState.Position.Y : -1 ;
\r
322 case GLUT_INIT_WINDOW_WIDTH: return fgState.Size.Use ?
\r
323 fgState.Size.X : -1 ;
\r
324 case GLUT_INIT_WINDOW_HEIGHT: return fgState.Size.Use ?
\r
325 fgState.Size.Y : -1 ;
\r
326 case GLUT_INIT_DISPLAY_MODE: return fgState.DisplayMode ;
\r
327 case GLUT_INIT_MAJOR_VERSION: return fgState.MajorVersion ;
\r
328 case GLUT_INIT_MINOR_VERSION: return fgState.MinorVersion ;
\r
329 case GLUT_INIT_FLAGS: return fgState.ContextFlags ;
\r
330 case GLUT_INIT_PROFILE: return fgState.ContextProfile ;
\r
332 /* The window structure queries */
\r
333 case GLUT_WINDOW_PARENT:
\r
334 if( fgStructure.CurrentWindow == NULL ) return 0;
\r
335 if( fgStructure.CurrentWindow->Parent == NULL ) return 0;
\r
336 return fgStructure.CurrentWindow->Parent->ID;
\r
338 case GLUT_WINDOW_NUM_CHILDREN:
\r
339 if( fgStructure.CurrentWindow == NULL )
\r
341 return fgListLength( &fgStructure.CurrentWindow->Children );
\r
343 case GLUT_WINDOW_CURSOR:
\r
344 if( fgStructure.CurrentWindow == NULL )
\r
346 return fgStructure.CurrentWindow->State.Cursor;
\r
348 case GLUT_MENU_NUM_ITEMS:
\r
349 if( fgStructure.CurrentMenu == NULL )
\r
351 return fgListLength( &fgStructure.CurrentMenu->Entries );
\r
353 case GLUT_ACTION_ON_WINDOW_CLOSE:
\r
354 return fgState.ActionOnWindowClose;
\r
356 case GLUT_VERSION :
\r
357 return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH;
\r
359 case GLUT_RENDERING_CONTEXT:
\r
360 return fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT
\r
361 : GLUT_CREATE_NEW_CONTEXT;
\r
363 case GLUT_DIRECT_RENDERING:
\r
364 return fgState.DirectContext;
\r
366 case GLUT_FULL_SCREEN:
\r
367 return fgStructure.CurrentWindow->State.IsFullscreen;
\r
370 return fgState.AuxiliaryBufferNumber;
\r
372 case GLUT_MULTISAMPLE:
\r
373 return fgState.SampleNumber;
\r
376 return fgPlatformGlutGet ( eWhat );
\r
383 * Returns various device information.
\r
385 int FGAPIENTRY glutDeviceGet( GLenum eWhat )
\r
387 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" );
\r
389 /* XXX WARNING: we are mostly lying in this function. */
\r
392 case GLUT_HAS_KEYBOARD:
\r
394 * Win32 is assumed a keyboard, and this cannot be queried,
\r
395 * except for WindowsCE.
\r
397 * X11 has a core keyboard by definition, although it can
\r
398 * be present as a virtual/dummy keyboard. For now, there
\r
399 * is no reliable way to tell if a real keyboard is present.
\r
401 #if defined(_WIN32_CE)
\r
402 return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;
\r
403 # if FREEGLUT_LIB_PRAGMAS
\r
404 # pragma comment (lib,"Kbdui.lib")
\r
411 #if TARGET_HOST_POSIX_X11
\r
413 /* X11 has a mouse by definition */
\r
414 case GLUT_HAS_MOUSE:
\r
417 case GLUT_NUM_MOUSE_BUTTONS:
\r
418 /* We should be able to pass NULL when the last argument is zero,
\r
419 * but at least one X server has a bug where this causes a segfault.
\r
421 * In XFree86/Xorg servers, a mouse wheel is seen as two buttons
\r
422 * rather than an Axis; "freeglut_main.c" expects this when
\r
423 * checking for a wheel event.
\r
427 int nbuttons = XGetPointerMapping(fgDisplay.Display, &map,0);
\r
431 #elif TARGET_HOST_MS_WINDOWS
\r
433 case GLUT_HAS_MOUSE:
\r
435 * MS Windows can be booted without a mouse.
\r
437 return GetSystemMetrics( SM_MOUSEPRESENT );
\r
439 case GLUT_NUM_MOUSE_BUTTONS:
\r
440 # if defined(_WIN32_WCE)
\r
443 return GetSystemMetrics( SM_CMOUSEBUTTONS );
\r
447 case GLUT_HAS_JOYSTICK:
\r
448 return fgJoystickDetect ();
\r
450 case GLUT_OWNS_JOYSTICK:
\r
451 return fgState.JoysticksInitialised;
\r
453 case GLUT_JOYSTICK_POLL_RATE:
\r
454 return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.JoystickPollRate : 0;
\r
456 /* XXX The following two are only for Joystick 0 but this is an improvement */
\r
457 case GLUT_JOYSTICK_BUTTONS:
\r
458 return glutJoystickGetNumButtons ( 0 );
\r
460 case GLUT_JOYSTICK_AXES:
\r
461 return glutJoystickGetNumAxes ( 0 );
\r
463 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
\r
464 return fgInputDeviceDetect ();
\r
466 case GLUT_NUM_DIALS:
\r
467 if ( fgState.InputDevsInitialised ) return 8;
\r
470 case GLUT_NUM_BUTTON_BOX_BUTTONS:
\r
473 case GLUT_HAS_SPACEBALL:
\r
474 return fgHasSpaceball();
\r
476 case GLUT_HAS_TABLET:
\r
479 case GLUT_NUM_SPACEBALL_BUTTONS:
\r
480 return fgSpaceballNumButtons();
\r
482 case GLUT_NUM_TABLET_BUTTONS:
\r
485 case GLUT_DEVICE_IGNORE_KEY_REPEAT:
\r
486 return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.IgnoreKeyRepeat : 0;
\r
488 case GLUT_DEVICE_KEY_REPEAT:
\r
489 return fgState.KeyRepeat;
\r
492 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
\r
496 /* And now -- the failure. */
\r
501 * This should return the current state of ALT, SHIFT and CTRL keys.
\r
503 int FGAPIENTRY glutGetModifiers( void )
\r
505 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetModifiers" );
\r
506 if( fgState.Modifiers == INVALID_MODIFIERS )
\r
508 fgWarning( "glutGetModifiers() called outside an input callback" );
\r
512 return fgState.Modifiers;
\r
516 * Return the state of the GLUT API overlay subsystem. A misery ;-)
\r
518 int FGAPIENTRY glutLayerGet( GLenum eWhat )
\r
520 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLayerGet" );
\r
523 * This is easy as layers are not implemented ;-)
\r
525 * XXX Can we merge the UNIX/X11 and WIN32 sections? Or
\r
526 * XXX is overlay support planned?
\r
531 #if TARGET_HOST_POSIX_X11
\r
533 case GLUT_OVERLAY_POSSIBLE:
\r
536 case GLUT_LAYER_IN_USE:
\r
537 return GLUT_NORMAL;
\r
539 case GLUT_HAS_OVERLAY:
\r
542 case GLUT_TRANSPARENT_INDEX:
\r
544 * Return just anything, which is always defined as zero
\r
550 case GLUT_NORMAL_DAMAGED:
\r
551 /* XXX Actually I do not know. Maybe. */
\r
554 case GLUT_OVERLAY_DAMAGED:
\r
557 #elif TARGET_HOST_MS_WINDOWS
\r
559 case GLUT_OVERLAY_POSSIBLE:
\r
560 /* return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
\r
561 PFD_OVERLAY_PLANE ); */
\r
564 case GLUT_LAYER_IN_USE:
\r
565 return GLUT_NORMAL;
\r
567 case GLUT_HAS_OVERLAY:
\r
570 case GLUT_TRANSPARENT_INDEX:
\r
572 * Return just anything, which is always defined as zero
\r
578 case GLUT_NORMAL_DAMAGED:
\r
579 /* XXX Actually I do not know. Maybe. */
\r
582 case GLUT_OVERLAY_DAMAGED:
\r
587 fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );
\r
591 /* And fail. That's good. Programs do love failing. */
\r
595 int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int * size)
\r
599 #if TARGET_HOST_POSIX_X11
\r
601 GLXFBConfig * fbconfigArray; /* Array of FBConfigs */
\r
602 int fbconfigArraySize; /* Number of FBConfigs in the array */
\r
603 int attribute_name = 0;
\r
606 FREEGLUT_EXIT_IF_NOT_INITIALISED("glutGetModeValues");
\r
613 #if TARGET_HOST_POSIX_X11
\r
615 case GLUT_MULTISAMPLE:
\r
617 attributes[0] = GLX_BUFFER_SIZE;
\r
618 attributes[1] = GLX_DONT_CARE;
\r
624 FBConfigs are now sorted by increasing number of auxiliary
\r
625 buffers. We want at least one buffer.
\r
627 attributes[2] = GLX_AUX_BUFFERS;
\r
629 attributes[4] = None;
\r
631 attribute_name = GLX_AUX_BUFFERS;
\r
636 case GLUT_MULTISAMPLE:
\r
637 attributes[2] = GLX_AUX_BUFFERS;
\r
638 attributes[3] = GLX_DONT_CARE;
\r
639 attributes[4] = GLX_SAMPLE_BUFFERS;
\r
642 FBConfigs are now sorted by increasing number of samples per
\r
643 pixel. We want at least one sample.
\r
645 attributes[6] = GLX_SAMPLES;
\r
647 attributes[8] = None;
\r
649 attribute_name = GLX_SAMPLES;
\r
654 fbconfigArray = glXChooseFBConfig(fgDisplay.Display,
\r
657 &fbconfigArraySize);
\r
659 if (fbconfigArray != NULL)
\r
662 int result; /* Returned by glXGetFBConfigAttrib. Not checked. */
\r
663 int previous_value;
\r
666 temp_array = malloc(sizeof(int) * fbconfigArraySize);
\r
667 previous_value = 0;
\r
669 for (i = 0; i < fbconfigArraySize; i++)
\r
673 result = glXGetFBConfigAttrib(fgDisplay.Display,
\r
677 if (value > previous_value)
\r
679 temp_array[*size] = value;
\r
680 previous_value = value;
\r
685 array = malloc(sizeof(int) * (*size));
\r
686 for (i = 0; i < *size; i++)
\r
688 array[i] = temp_array[i];
\r
692 XFree(fbconfigArray);
\r
705 /*** END OF FILE ***/
\r