X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2FCommon%2Ffreeglut_state.c;h=8962df33764308b3de3fe6a599c392070fa4a336;hb=6c3c78f5fe46f0126e26dcae456ebdec502913f5;hp=bf7300a50093a2d9cf72a651f36e4b2850592e98;hpb=e837701fc740ce27feb9342c1bbbf1945ab19331;p=freeglut diff --git a/src/Common/freeglut_state.c b/src/Common/freeglut_state.c index bf7300a..8962df3 100644 --- a/src/Common/freeglut_state.c +++ b/src/Common/freeglut_state.c @@ -42,6 +42,14 @@ */ extern int fgPlatformGlutGet ( GLenum eWhat ); +extern int fgPlatformGlutDeviceGet ( GLenum eWhat ); +extern int fgPlatformGlutLayerGet ( GLenum eWhat ); + +/* A helper function to check if a display mode is possible to use */ +#if TARGET_HOST_POSIX_X11 +GLXFBConfig* fgChooseFBConfig( int* numcfgs ); +#endif + /* -- LOCAL DEFINITIONS ---------------------------------------------------- */ @@ -57,15 +65,15 @@ static int fghGetConfig( int attribute ) int result; /* Not checked */ if( fgStructure.CurrentWindow ) - result = glXGetFBConfigAttrib( fgDisplay.Display, - *(fgStructure.CurrentWindow->Window.FBConfig), + result = glXGetFBConfigAttrib( fgDisplay.pDisplay.Display, + *(fgStructure.CurrentWindow->Window.pContext.FBConfig), attribute, &returnValue ); return returnValue; } -static int fgPlatformGlutGet ( GLenum eWhat ) +int fgPlatformGlutGet ( GLenum eWhat ) { int nsamples = 0; @@ -117,10 +125,10 @@ static int fgPlatformGlutGet ( GLenum eWhat ) else { const GLXFBConfig * fbconfig = - fgStructure.CurrentWindow->Window.FBConfig; + fgStructure.CurrentWindow->Window.pContext.FBConfig; XVisualInfo * visualInfo = - glXGetVisualFromFBConfig( fgDisplay.Display, *fbconfig ); + glXGetVisualFromFBConfig( fgDisplay.pDisplay.Display, *fbconfig ); const int result = visualInfo->visual->map_entries; @@ -145,7 +153,7 @@ static int fgPlatformGlutGet ( GLenum eWhat ) return 0; XTranslateCoordinates( - fgDisplay.Display, + fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle, fgDisplay.RootWindow, 0, 0, &x, &y, &w); @@ -159,7 +167,7 @@ static int fgPlatformGlutGet ( GLenum eWhat ) if ( w == 0 ) return 0; XTranslateCoordinates( - fgDisplay.Display, + fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle, w, 0, 0, &x, &y, &w); @@ -178,7 +186,7 @@ static int fgPlatformGlutGet ( GLenum eWhat ) if( fgStructure.CurrentWindow == NULL ) return 0; XGetWindowAttributes( - fgDisplay.Display, + fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle, &winAttributes ); @@ -223,6 +231,92 @@ static int fgPlatformGlutGet ( GLenum eWhat ) break; } } + + +int fgPlatformGlutDeviceGet ( GLenum eWhat ) +{ + switch( eWhat ) + { + case GLUT_HAS_KEYBOARD: + /* + * X11 has a core keyboard by definition, although it can + * be present as a virtual/dummy keyboard. For now, there + * is no reliable way to tell if a real keyboard is present. + */ + return 1; + + /* X11 has a mouse by definition */ + case GLUT_HAS_MOUSE: + return 1 ; + + case GLUT_NUM_MOUSE_BUTTONS: + /* We should be able to pass NULL when the last argument is zero, + * but at least one X server has a bug where this causes a segfault. + * + * In XFree86/Xorg servers, a mouse wheel is seen as two buttons + * rather than an Axis; "freeglut_main.c" expects this when + * checking for a wheel event. + */ + { + unsigned char map; + int nbuttons = XGetPointerMapping(fgDisplay.pDisplay.Display, &map,0); + return nbuttons; + } + + default: + fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat ); + break; + } + + /* And now -- the failure. */ + return -1; +} + +int fgPlatformGlutLayerGet( GLenum eWhat ) +{ + /* + * This is easy as layers are not implemented ;-) + * + * XXX Can we merge the UNIX/X11 and WIN32 sections? Or + * XXX is overlay support planned? + */ + switch( eWhat ) + { + case GLUT_OVERLAY_POSSIBLE: + return 0; + + case GLUT_LAYER_IN_USE: + return GLUT_NORMAL; + + case GLUT_HAS_OVERLAY: + return 0; + + case GLUT_TRANSPARENT_INDEX: + /* + * Return just anything, which is always defined as zero + * + * XXX HUH? + */ + return 0; + + case GLUT_NORMAL_DAMAGED: + /* XXX Actually I do not know. Maybe. */ + return 0; + + case GLUT_OVERLAY_DAMAGED: + return -1; + + default: + fgWarning( "glutLayerGet(): missing enum handle %d", eWhat ); + break; + } + + /* And fail. That's good. Programs do love failing. */ + return -1; +} + + + #endif /* -- INTERFACE FUNCTIONS -------------------------------------------------- */ @@ -389,61 +483,6 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat ) /* XXX WARNING: we are mostly lying in this function. */ switch( eWhat ) { - case GLUT_HAS_KEYBOARD: - /* - * Win32 is assumed a keyboard, and this cannot be queried, - * except for WindowsCE. - * - * X11 has a core keyboard by definition, although it can - * be present as a virtual/dummy keyboard. For now, there - * is no reliable way to tell if a real keyboard is present. - */ -#if defined(_WIN32_CE) - return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0; -# if FREEGLUT_LIB_PRAGMAS -# pragma comment (lib,"Kbdui.lib") -# endif - -#else - return 1; -#endif - -#if TARGET_HOST_POSIX_X11 - - /* X11 has a mouse by definition */ - case GLUT_HAS_MOUSE: - return 1 ; - - case GLUT_NUM_MOUSE_BUTTONS: - /* We should be able to pass NULL when the last argument is zero, - * but at least one X server has a bug where this causes a segfault. - * - * In XFree86/Xorg servers, a mouse wheel is seen as two buttons - * rather than an Axis; "freeglut_main.c" expects this when - * checking for a wheel event. - */ - { - unsigned char map; - int nbuttons = XGetPointerMapping(fgDisplay.Display, &map,0); - return nbuttons; - } - -#elif TARGET_HOST_MS_WINDOWS - - case GLUT_HAS_MOUSE: - /* - * MS Windows can be booted without a mouse. - */ - return GetSystemMetrics( SM_MOUSEPRESENT ); - - case GLUT_NUM_MOUSE_BUTTONS: -# if defined(_WIN32_WCE) - return 1; -# else - return GetSystemMetrics( SM_CMOUSEBUTTONS ); -# endif -#endif - case GLUT_HAS_JOYSTICK: return fgJoystickDetect (); @@ -489,8 +528,7 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat ) return fgState.KeyRepeat; default: - fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat ); - break; + return fgPlatformGlutDeviceGet ( eWhat ); } /* And now -- the failure. */ @@ -528,64 +566,8 @@ int FGAPIENTRY glutLayerGet( GLenum eWhat ) switch( eWhat ) { -#if TARGET_HOST_POSIX_X11 - - case GLUT_OVERLAY_POSSIBLE: - return 0; - - case GLUT_LAYER_IN_USE: - return GLUT_NORMAL; - - case GLUT_HAS_OVERLAY: - return 0; - - case GLUT_TRANSPARENT_INDEX: - /* - * Return just anything, which is always defined as zero - * - * XXX HUH? - */ - return 0; - - case GLUT_NORMAL_DAMAGED: - /* XXX Actually I do not know. Maybe. */ - return 0; - - case GLUT_OVERLAY_DAMAGED: - return -1; - -#elif TARGET_HOST_MS_WINDOWS - - case GLUT_OVERLAY_POSSIBLE: -/* return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE, - PFD_OVERLAY_PLANE ); */ - return 0 ; - - case GLUT_LAYER_IN_USE: - return GLUT_NORMAL; - - case GLUT_HAS_OVERLAY: - return 0; - - case GLUT_TRANSPARENT_INDEX: - /* - * Return just anything, which is always defined as zero - * - * XXX HUH? - */ - return 0; - - case GLUT_NORMAL_DAMAGED: - /* XXX Actually I do not know. Maybe. */ - return 0; - - case GLUT_OVERLAY_DAMAGED: - return -1; -#endif - default: - fgWarning( "glutLayerGet(): missing enum handle %d", eWhat ); - break; + return fgPlatformGlutLayerGet( eWhat ); } /* And fail. That's good. Programs do love failing. */ @@ -651,8 +633,8 @@ int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int * size) break; } - fbconfigArray = glXChooseFBConfig(fgDisplay.Display, - fgDisplay.Screen, + fbconfigArray = glXChooseFBConfig(fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.Screen, attributes, &fbconfigArraySize); @@ -670,7 +652,7 @@ int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int * size) { int value; - result = glXGetFBConfigAttrib(fgDisplay.Display, + result = glXGetFBConfigAttrib(fgDisplay.pDisplay.Display, fbconfigArray[i], attribute_name, &value);