X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_gamemode.c;h=6934534ade59622eb96f508b1a167e51245a26f9;hb=1fd9514b5c5df8a4bf974787f26f6cc3dd84c1cc;hp=24a8be153e875e97ec31e204bacba25871eda792;hpb=577caff92e03ec8cbe4ca36448697939ed5d7dfc;p=freeglut diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index 24a8be1..6934534 100644 --- a/src/freeglut_gamemode.c +++ b/src/freeglut_gamemode.c @@ -40,6 +40,65 @@ /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ +static int xrandr_resize(int xsz, int ysz, int just_checking) +{ + int res = -1; + +#ifdef HAVE_X11_EXTENSIONS_XRANDR_H + int event_base, error_base; + Status st; + XRRScreenConfiguration *xrr_config; + XRRScreenSize *ssizes; + Rotation rot; + int i, ssizes_count, curr; + Time timestamp, cfg_timestamp; + + /* must check at runtime for the availability of the extension */ + if(!XRRQueryExtension(fgDisplay.Display, &event_base, &error_base)) { + return -1; + } + + if(!(xrr_config = XRRGetScreenInfo(fgDisplay.Display, fgDisplay.RootWindow))) { + fgWarning("XRRGetScreenInfo failed"); + return -1; + } + ssizes = XRRConfigSizes(xrr_config, &ssizes_count); + curr = XRRConfigCurrentConfiguration(xrr_config, &rot); + timestamp = XRRConfigTimes(xrr_config, &cfg_timestamp); + + if(xsz == ssizes[curr].width && ysz == ssizes[curr].height) { + /* no need to switch, we're already in the requested mode */ + res = 0; + goto done; + } + + for(i=0; ivdisplay, fgState.GameModeDepth, ( exactMatch ? refresh : fgState.GameModeRefresh ) ) ) { + if (!exactMatch) + { + /* Update the chosen refresh rate, otherwise a + * glutGameModeGet(GLUT_GAME_MODE_REFRESH_RATE) would not + * return the right values + */ + fgState.GameModeRefresh = refresh; + } + return i; } } @@ -259,14 +349,22 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) GLboolean success = GL_FALSE; #if TARGET_HOST_POSIX_X11 + /* first try to use XRandR, then fallback to XF86VidMode */ +# ifdef HAVE_X11_EXTENSIONS_XRANDR_H + if(xrandr_resize(fgState.GameModeSize.X, fgState.GameModeSize.Y, haveToTest) != -1) { + return GL_TRUE; + } +# endif + + /* * This highly depends on the XFree86 extensions, * not approved as X Consortium standards */ -# ifdef X_XF86VidModeGetAllModeLines +# ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H /* - * This is also used by applcations which check modes by calling + * This is also used by applications which check modes by calling * glutGameModeGet(GLUT_GAME_MODE_POSSIBLE), so allow the check: */ if( haveToTest || fgDisplay.DisplayModeValid ) @@ -274,6 +372,33 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) XF86VidModeModeInfo** displayModes; int i, displayModesCount; + /* current display mode was queried in fghRememberState + * set defaulted values to the current display mode's + */ + if (fgState.GameModeSize.X == -1) + { + fgState.GameModeSize.X = fgDisplay.DisplayMode.hdisplay; + } + if (fgState.GameModeSize.Y == -1) + { + fgState.GameModeSize.Y = fgDisplay.DisplayMode.vdisplay; + } + if (fgState.GameModeDepth == -1) + { + /* can't get color depth from this, nor can we change it, do nothing + * TODO: get with XGetVisualInfo()? but then how to set? + */ + } + if (fgState.GameModeRefresh != -1) + { + /* Compute the displays refresh rate, dotclock comes in kHz. */ + int refresh = ( fgDisplay.DisplayModeClock * 1000 ) / + ( fgDisplay.DisplayMode.htotal * fgDisplay.DisplayMode.vtotal ); + + fgState.GameModeRefresh = refresh; + } + + /* query all possible display modes */ if( !XF86VidModeGetAllModeLines( fgDisplay.Display, fgDisplay.Screen, @@ -320,6 +445,7 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) DEVMODE devMode; char *fggmstr = NULL; + char displayMode[300]; success = GL_FALSE; @@ -352,12 +478,15 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) case DISP_CHANGE_SUCCESSFUL: success = GL_TRUE; - /* update vars in case if windows switched to proper mode */ - EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode ); - fgState.GameModeSize.X = devMode.dmPelsWidth; - fgState.GameModeSize.Y = devMode.dmPelsHeight; - fgState.GameModeDepth = devMode.dmBitsPerPel; - fgState.GameModeRefresh = devMode.dmDisplayFrequency; + if (!haveToTest) + { + /* update vars in case if windows switched to proper mode */ + EnumDisplaySettings( fgDisplay.DisplayName, FREEGLUT_ENUM_CURRENT_SETTINGS, &devMode ); + fgState.GameModeSize.X = devMode.dmPelsWidth; + fgState.GameModeSize.Y = devMode.dmPelsHeight; + fgState.GameModeDepth = devMode.dmBitsPerPel; + fgState.GameModeRefresh = devMode.dmDisplayFrequency; + } break; case DISP_CHANGE_RESTART: fggmstr = "The computer must be restarted for the graphics mode to work."; @@ -380,8 +509,14 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) } if ( !success ) - fgWarning(fggmstr); /* I'd rather get info whats going on in my program than wonder about */ - /* magic happenings behind my back, its lib for devels at last ;) */ + { + /* I'd rather get info whats going on in my program than wonder about */ + /* magic happenings behind my back, its lib for devels at last ;) */ + + /* append display mode to error to make things more informative */ + sprintf(displayMode,"%s Problem with requested mode: %ix%i:%i@%i", fggmstr, devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmDisplayFrequency); + fgWarning(displayMode); + } #endif return success; @@ -418,7 +553,10 @@ void FGAPIENTRY glutGameModeString( const char* string ) string ); - /* Hopefully it worked, and if not, we still have the default values */ + /* All values not specified are now set to -1, which means those + * aspects of the current display mode are not changed in + * fghChangeDisplayMode() above. + */ fgState.GameModeSize.X = width; fgState.GameModeSize.Y = height; fgState.GameModeDepth = depth; @@ -501,7 +639,7 @@ int FGAPIENTRY glutEnterGameMode( void ) fgState.GameModeSize.X/2, fgState.GameModeSize.Y/2 ); -# ifdef X_XF86VidModeSetViewPort +# ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H if( fgDisplay.DisplayModeValid ) {