4 * Freeglut state query methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Thu Dec 16 1999
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.
32 #define G_LOG_DOMAIN "freeglut-state"
34 #include "../include/GL/freeglut.h"
35 #include "../include/GL/freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
40 * glutGet() -- X11 tests passed, but check if all enums handled (what about Win32?)
41 * glutDeviceGet() -- X11 tests passed, but check if all enums handled (what about Win32?)
42 * glutGetModifiers() -- OK, but could also remove the limitation
43 * glutLayerGet() -- what about GLUT_NORMAL_DAMAGED?
45 * The fail-on-call policy will help adding the most needed things imho.
48 /* -- LOCAL DEFINITIONS ---------------------------------------------------- */
51 * Those are definitions introduced to make the glutGet() more easy,
52 * however they might introduce errors if someone ports GLX to Win32 :)
54 * Btw. this is not that a bad idea (wrapping WGL around GLX)...
57 # define GLX_RGBA 0x01
58 # define GLX_DOUBLEBUFFER 0x02
59 # define GLX_BUFFER_SIZE 0x03
60 # define GLX_STENCIL_SIZE 0x04
61 # define GLX_DEPTH_SIZE 0x05
62 # define GLX_RED_SIZE 0x06
63 # define GLX_GREEN_SIZE 0x07
64 # define GLX_BLUE_SIZE 0x08
65 # define GLX_ALPHA_SIZE 0x09
66 # define GLX_ACCUM_RED_SIZE 0x0A
67 # define GLX_ACCUM_GREEN_SIZE 0x0B
68 # define GLX_ACCUM_BLUE_SIZE 0x0C
69 # define GLX_ACCUM_ALPHA_SIZE 0x0D
70 # define GLX_STEREO 0x0E
74 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
77 * Queries the GL context about some attributes
79 static int fghGetConfig( int attribute )
84 * Return nothing if there is no current window set
86 if( fgStructure.Window == NULL )
89 #if TARGET_HOST_UNIX_X11
91 * glXGetConfig should work fine
93 glXGetConfig( fgDisplay.Display, fgStructure.Window->Window.VisualInfo, attribute, &returnValue );
95 #elif TARGET_HOST_WIN32
97 * This is going to be a bit harder than the X11 version...
99 # pragma message( "freeglut_state.c::fghGetConfig() says hello world my name is not implemented!" )
103 case GLX_DOUBLEBUFFER:
104 case GLX_BUFFER_SIZE:
111 case GLX_STENCIL_SIZE:
113 case GLX_ACCUM_RED_SIZE:
114 case GLX_ACCUM_GREEN_SIZE:
115 case GLX_ACCUM_BLUE_SIZE:
116 case GLX_ACCUM_ALPHA_SIZE:
120 * Well, this looks like not implemented to me :)
128 * Have the query results returned
130 return( returnValue );
133 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
136 * General settings query method
138 int FGAPIENTRY glutGet( GLenum eWhat )
140 freeglut_assert_ready;
143 * Check what is the caller querying for. In chronological code add order.
147 case GLUT_ELAPSED_TIME:
149 * This is easy and nicely portable, as we are using GLib...
151 return( fgElapsedTime() );
154 * Following values are stored in fgState and fgDisplay global structures
156 case GLUT_SCREEN_WIDTH: return( fgDisplay.ScreenWidth );
157 case GLUT_SCREEN_HEIGHT: return( fgDisplay.ScreenHeight );
158 case GLUT_SCREEN_WIDTH_MM: return( fgDisplay.ScreenWidthMM );
159 case GLUT_SCREEN_HEIGHT_MM: return( fgDisplay.ScreenHeightMM );
160 case GLUT_INIT_WINDOW_X: return( fgState.Position.X );
161 case GLUT_INIT_WINDOW_Y: return( fgState.Position.Y );
162 case GLUT_INIT_WINDOW_WIDTH: return( fgState.Size.X );
163 case GLUT_INIT_WINDOW_HEIGHT: return( fgState.Size.Y );
164 case GLUT_INIT_DISPLAY_MODE: return( fgState.DisplayMode );
167 * The window/context specific queries are handled mostly by fghGetConfig().
169 case GLUT_WINDOW_NUM_SAMPLES:
171 * Multisampling. Return what I know about multisampling.
176 * The rest of GLX queries is general enough to use a macro to check them
178 # define GLX_QUERY(a,b) case a: return( fghGetConfig( b ) );
180 GLX_QUERY( GLUT_WINDOW_RGBA, GLX_RGBA );
181 GLX_QUERY( GLUT_WINDOW_DOUBLEBUFFER, GLX_DOUBLEBUFFER );
182 GLX_QUERY( GLUT_WINDOW_BUFFER_SIZE, GLX_BUFFER_SIZE );
183 GLX_QUERY( GLUT_WINDOW_STENCIL_SIZE, GLX_STENCIL_SIZE );
184 GLX_QUERY( GLUT_WINDOW_DEPTH_SIZE, GLX_DEPTH_SIZE );
185 GLX_QUERY( GLUT_WINDOW_RED_SIZE, GLX_RED_SIZE );
186 GLX_QUERY( GLUT_WINDOW_GREEN_SIZE, GLX_GREEN_SIZE );
187 GLX_QUERY( GLUT_WINDOW_BLUE_SIZE, GLX_BLUE_SIZE );
188 GLX_QUERY( GLUT_WINDOW_ALPHA_SIZE, GLX_ALPHA_SIZE );
189 GLX_QUERY( GLUT_WINDOW_ACCUM_RED_SIZE, GLX_ACCUM_RED_SIZE );
190 GLX_QUERY( GLUT_WINDOW_ACCUM_GREEN_SIZE, GLX_ACCUM_GREEN_SIZE );
191 GLX_QUERY( GLUT_WINDOW_ACCUM_BLUE_SIZE, GLX_ACCUM_BLUE_SIZE );
192 GLX_QUERY( GLUT_WINDOW_ACCUM_ALPHA_SIZE, GLX_ACCUM_ALPHA_SIZE );
193 GLX_QUERY( GLUT_WINDOW_STEREO, GLX_STEREO );
197 #if TARGET_HOST_UNIX_X11
199 * Colormap size is handled in a bit different way than all the rest
201 case GLUT_WINDOW_COLORMAP_SIZE:
203 * Check for the visual type
205 if( (fghGetConfig( GLX_RGBA )) || (fgStructure.Window == NULL) )
208 * We've got a RGBA visual, so there is no colormap at all.
209 * The other possibility is that we have no current window set.
215 * Otherwise return the number of entries in the colormap
217 return( fgStructure.Window->Window.VisualInfo->visual->map_entries );
220 * Those calls are somewhat similiar, as they use XGetWindowAttributes() function
225 XWindowAttributes winAttributes;
226 Window another, window;
230 * Return zero if there is no current window set
232 if( fgStructure.Window == NULL )
236 * So, grab the current window's position
238 window = fgStructure.Window->Window.Handle;
241 * Grab the current window's attributes now
243 XGetWindowAttributes(
250 * Correct the results for the parental relation and border size
252 XTranslateCoordinates(
256 -winAttributes.border_width,
257 -winAttributes.border_width,
263 * See if we have to return the X or Y coordinate
265 return( eWhat == GLUT_WINDOW_X ? x : y );
268 case GLUT_WINDOW_WIDTH:
269 case GLUT_WINDOW_HEIGHT:
271 XWindowAttributes winAttributes;
274 * Return zero if there is no current window set
276 if( fgStructure.Window == NULL )
280 * Checking for window's size is much easier:
282 XGetWindowAttributes(
284 fgStructure.Window->Window.Handle,
289 * See if to return the window's width or height
291 return( eWhat == GLUT_WINDOW_WIDTH ? winAttributes.width : winAttributes.height );
295 * I do not know yet if there will be a fgChooseVisual() function for Win32
297 case GLUT_DISPLAY_MODE_POSSIBLE:
299 * Check if the current display mode is possible
301 return( fgChooseVisual() == NULL ? 0 : 1 );
304 * This is system-dependant
306 case GLUT_WINDOW_FORMAT_ID:
308 * Return the visual ID, if there is a current window naturally:
310 if( fgStructure.Window == NULL )
313 return( fgStructure.Window->Window.VisualInfo->visualid );
315 #elif TARGET_HOST_WIN32
319 case GLUT_WINDOW_WIDTH:
320 case GLUT_WINDOW_HEIGHT:
325 * Check if there is a window to be queried for dimensions:
327 freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 );
330 * We need to call GetWindowRect() first...
332 GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
335 * ...then we've got to correct the results we've just received...
337 winRect.left += GetSystemMetrics( SM_CXSIZEFRAME ) - 1;
338 winRect.right -= GetSystemMetrics( SM_CXSIZEFRAME ) - 1;
339 winRect.top += GetSystemMetrics( SM_CYSIZEFRAME ) - 1 + GetSystemMetrics( SM_CYCAPTION );
340 winRect.bottom -= GetSystemMetrics( SM_CYSIZEFRAME ) + 1;
343 * ...and finally return the caller the desired value:
347 case GLUT_WINDOW_X: return( winRect.left );
348 case GLUT_WINDOW_Y: return( winRect.top );
349 case GLUT_WINDOW_WIDTH: return( winRect.right - winRect.left );
350 case GLUT_WINDOW_HEIGHT: return( winRect.bottom - winRect.top );
355 case GLUT_DISPLAY_MODE_POSSIBLE:
357 * Check if the current display mode is possible
359 return( fgSetupPixelFormat( fgStructure.Window, TRUE ) );
361 case GLUT_WINDOW_FORMAT_ID:
363 * Return the pixel format of the current window
365 if( fgStructure.Window != NULL )
366 return( GetPixelFormat( fgStructure.Window->Window.Device ) );
369 * If the current window does not exist, fail:
376 * The window structure queries
378 case GLUT_WINDOW_PARENT:
380 * Return the ID number of current window's parent, if any
382 if( fgStructure.Window == NULL ) return( 0 );
383 if( fgStructure.Window->Parent == NULL ) return( 0 );
385 return( fgStructure.Window->Parent->ID );
387 case GLUT_WINDOW_NUM_CHILDREN:
389 * Return the number of children attached to the current window
391 if( fgStructure.Window == NULL )
394 return( fgListLength( &fgStructure.Window->Children ) );
396 case GLUT_WINDOW_CURSOR:
398 * Return the currently selected window cursor
400 if( fgStructure.Window == NULL )
403 return( fgStructure.Window->State.Cursor );
405 case GLUT_MENU_NUM_ITEMS:
407 * Return the number of menu entries in the current menu
409 if( fgStructure.Menu == NULL )
412 return( fgListLength( &fgStructure.Menu->Entries ) );
416 * Just have it reported, so that we can see what needs to be implemented
418 fgWarning( "glutGet(): missing enum handle %i\n", eWhat );
423 * If nothing happens, then we are in deep trouble...
429 * Returns various device information.
431 int FGAPIENTRY glutDeviceGet( GLenum eWhat )
433 freeglut_assert_ready;
436 * See why are we bothered...
438 * WARNING: we are mostly lying in this function.
442 case GLUT_HAS_KEYBOARD:
444 * We always have a keyboard present on PC machines...
448 #if TARGET_HOST_UNIX_X11
452 * Hey, my Atari 65XE hasn't had a mouse!
456 case GLUT_NUM_MOUSE_BUTTONS:
458 * Return the number of mouse buttons available. This is a big guess.
462 #elif TARGET_HOST_WIN32
466 * The Windows can be booted without a mouse.
467 * It would be nice to have this reported.
469 return( GetSystemMetrics( SM_MOUSEPRESENT ) );
471 case GLUT_NUM_MOUSE_BUTTONS:
473 * We are much more fortunate under Win32 about this...
475 return( GetSystemMetrics( SM_CMOUSEBUTTONS ) );
479 case GLUT_JOYSTICK_POLL_RATE:
480 case GLUT_HAS_JOYSTICK:
481 case GLUT_JOYSTICK_BUTTONS:
482 case GLUT_JOYSTICK_AXES:
484 * WARNING: THIS IS A BIG LIE!
488 case GLUT_HAS_SPACEBALL:
489 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
490 case GLUT_HAS_TABLET:
492 * Sounds cool. And unuseful.
496 case GLUT_NUM_SPACEBALL_BUTTONS:
497 case GLUT_NUM_BUTTON_BOX_BUTTONS:
499 case GLUT_NUM_TABLET_BUTTONS:
501 * Zero is not the answer. Zero is the question. Continuum is the answer.
505 case GLUT_DEVICE_IGNORE_KEY_REPEAT:
507 * Return what we think about the key auto repeat settings
509 return( fgState.IgnoreKeyRepeat );
511 case GLUT_DEVICE_KEY_REPEAT:
513 * WARNING: THIS IS A BIG LIE!
515 return( GLUT_KEY_REPEAT_DEFAULT );
521 fgWarning( "glutDeviceGet(): missing enum handle %i\n", eWhat );
526 * And now -- the failure.
532 * This should return the current state of ALT, SHIFT and CTRL keys.
534 int FGAPIENTRY glutGetModifiers( void )
537 * Fail if there is no current window or called outside an input callback
539 if( fgStructure.Window == NULL )
542 if( fgStructure.Window->State.Modifiers == 0xffffffff )
544 fgWarning( "glutGetModifiers() called outside an input callback" );
549 * Return the current modifiers state otherwise
551 return( fgStructure.Window->State.Modifiers );
555 * Return the state of the GLUT API overlay subsystem. A misery ;-)
557 int FGAPIENTRY glutLayerGet( GLenum eWhat )
559 freeglut_assert_ready;
562 * This is easy as layers are not implemented ;-)
566 case GLUT_OVERLAY_POSSIBLE:
568 * Nope, overlays are not possible.
572 case GLUT_LAYER_IN_USE:
574 * The normal plane is always in use
576 return( GLUT_NORMAL );
578 case GLUT_HAS_OVERLAY:
580 * No window is allowed to have an overlay
584 case GLUT_TRANSPARENT_INDEX:
586 * Return just anything, which is always defined as zero
590 case GLUT_NORMAL_DAMAGED:
592 * Actually I do not know. Maybe.
596 case GLUT_OVERLAY_DAMAGED:
598 * Return minus one to mark that no layer is in use
604 * Complain to the user about the obvious bug
606 fgWarning( "glutLayerGet(): missing enum handle %i\n", eWhat );
611 * And fail. That's good. Programs do love failing.
616 /*** END OF FILE ***/