X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_gamemode.c;h=b30b46f54be6e321e0af94b4d3a24c762bd82b91;hb=edcfc6757dc71f2764b1a6b44c9b0bde45364b16;hp=c1764b8926bf1701f27e99f85f33a4db5f6e6dc4;hpb=41e63805080267e9dbd100d30deac6ba0b34678e;p=freeglut diff --git a/src/freeglut_gamemode.c b/src/freeglut_gamemode.c index c1764b8..b30b46f 100644 --- a/src/freeglut_gamemode.c +++ b/src/freeglut_gamemode.c @@ -25,10 +25,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include "freeglut_internal.h" @@ -63,12 +59,12 @@ static void fghRememberState( void ) * Remember the current ViewPort location of the screen to be able to * restore the ViewPort on LeaveGameMode(): */ - XF86VidModeGetViewPort( - fgDisplay.Display, - fgDisplay.Screen, - &fgDisplay.DisplayViewPortX, - &fgDisplay.DisplayViewPortY - ); + if( !XF86VidModeGetViewPort( + fgDisplay.Display, + fgDisplay.Screen, + &fgDisplay.DisplayViewPortX, + &fgDisplay.DisplayViewPortY ) ) + fgWarning( "XF86VidModeGetViewPort failed" ); /* * Remember the current pointer location before going fullscreen @@ -96,7 +92,7 @@ static void fghRememberState( void ) ); if( !fgDisplay.DisplayModeValid ) - fgWarning( "Runtime use of XF86VidModeGetModeLine failed." ); + fgWarning( "XF86VidModeGetModeLine failed" ); # else /* @@ -148,12 +144,16 @@ static void fghRestoreState( void ) XF86VidModeModeInfo** displayModes; int i, displayModesCount; - XF86VidModeGetAllModeLines( - fgDisplay.Display, - fgDisplay.Screen, - &displayModesCount, - &displayModes - ); + if( !XF86VidModeGetAllModeLines( + fgDisplay.Display, + fgDisplay.Screen, + &displayModesCount, + &displayModes ) ) + { + fgWarning( "XF86VidModeGetAllModeLines failed" ); + return; + } + /* * Check every of the modes looking for one that matches our demands. @@ -165,17 +165,22 @@ static void fghRestoreState( void ) displayModes[ i ]->vdisplay == fgDisplay.DisplayMode.vdisplay && displayModes[ i ]->dotclock == fgDisplay.DisplayModeClock ) { - XF86VidModeSwitchToMode( - fgDisplay.Display, - fgDisplay.Screen, - displayModes[ i ] - ); - XF86VidModeSetViewPort( - fgDisplay.Display, - fgDisplay.Screen, - fgDisplay.DisplayViewPortX, - fgDisplay.DisplayViewPortY - ); + if( !XF86VidModeSwitchToMode( + fgDisplay.Display, + fgDisplay.Screen, + displayModes[ i ] ) ) + { + fgWarning( "XF86VidModeSwitchToMode failed" ); + break; + } + + if( !XF86VidModeSetViewPort( + fgDisplay.Display, + fgDisplay.Screen, + fgDisplay.DisplayViewPortX, + fgDisplay.DisplayViewPortY ) ) + fgWarning( "XF86VidModeSetViewPort failed" ); + /* * For the case this would be the last X11 call the application @@ -184,9 +189,10 @@ static void fghRestoreState( void ) */ XFlush( fgDisplay.Display ); - return; + break; } } + XFree( displayModes ); } # else @@ -221,6 +227,7 @@ static GLboolean fghCheckDisplayMode( int width, int height, int depth, int refr */ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) { + GLboolean success = GL_FALSE; #if TARGET_HOST_UNIX_X11 /* @@ -236,38 +243,52 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) if( haveToTest || fgDisplay.DisplayModeValid ) { XF86VidModeModeInfo** displayModes; - int i, displayModesCount; + int i, ignoreRefreshRate, displayModesCount; - XF86VidModeGetAllModeLines( - fgDisplay.Display, - fgDisplay.Screen, - &displayModesCount, - &displayModes - ); + if( !XF86VidModeGetAllModeLines( + fgDisplay.Display, + fgDisplay.Screen, + &displayModesCount, + &displayModes ) ) + { + fgWarning( "XF86VidModeGetAllModeLines failed" ); + return success; + } - /* Check every of the modes looking for one that matches our demands */ - for( i = 0; i < displayModesCount; i++ ) + + /* + * Check every of the modes looking for one that matches our demands, + * ignoring the refresh rate if no exact match could be found. + */ + for( ignoreRefreshRate = 0; + !success && ( ignoreRefreshRate <= 1 ); + ignoreRefreshRate++) { - if( fghCheckDisplayMode( displayModes[ i ]->hdisplay, - displayModes[ i ]->vdisplay, - fgState.GameModeDepth, - fgState.GameModeRefresh ) ) + for( i = 0; + !success && ( i < displayModesCount ); + i++ ) { - if( haveToTest ) - return GL_TRUE; - /* OKi, this is the display mode we have been looking for... */ - XF86VidModeSwitchToMode( - fgDisplay.Display, - fgDisplay.Screen, - displayModes[ i ] - ); - return GL_TRUE; + /* Compute the displays refresh rate, dotclock comes in kHz. */ + int refresh = ( displayModes[ i ]->dotclock * 1000 ) / + ( displayModes[ i ]->htotal * displayModes[ i ]->vtotal ); + + success = fghCheckDisplayMode( displayModes[ i ]->hdisplay, + displayModes[ i ]->vdisplay, + fgState.GameModeDepth, + ( ignoreRefreshRate ? fgState.GameModeRefresh : refresh ) ); } } - } - /* Something must have gone wrong */ - return GL_FALSE; + if( !haveToTest && success ) { + if( !XF86VidModeSwitchToMode( + fgDisplay.Display, + fgDisplay.Screen, + displayModes[ i ] ) ) + fgWarning( "XF86VidModeSwitchToMode failed" ); + } + + XFree( displayModes ); + } # else /* @@ -279,7 +300,6 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE unsigned int displayModes = 0, mode = 0xffffffff; - GLboolean success = GL_FALSE; /* HDC desktopDC; */ DEVMODE devMode; @@ -345,9 +365,9 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest ) } } - return success; - #endif + + return success; } @@ -360,6 +380,8 @@ void FGAPIENTRY glutGameModeString( const char* string ) { int width = 640, height = 480, depth = 16, refresh = 72; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeString" ); + /* * This one seems a bit easier than glutInitDisplayString. The bad thing * about it that I was unable to find the game mode string definition, so @@ -391,6 +413,8 @@ void FGAPIENTRY glutGameModeString( const char* string ) */ int FGAPIENTRY glutEnterGameMode( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutEnterGameMode" ); + if( fgStructure.GameMode ) fgAddToWindowDestroyList( fgStructure.GameMode ); else @@ -466,7 +490,8 @@ int FGAPIENTRY glutEnterGameMode( void ) Window child; /* Change to viewport to the window topleft edge: */ - XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 ); + if( !XF86VidModeSetViewPort( fgDisplay.Display, fgDisplay.Screen, 0, 0 ) ) + fgWarning( "XF86VidModeSetViewPort failed" ); /* * Final window repositioning: It could be avoided using an undecorated @@ -509,12 +534,13 @@ int FGAPIENTRY glutEnterGameMode( void ) */ void FGAPIENTRY glutLeaveGameMode( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveGameMode" ); + freeglut_return_if_fail( fgStructure.GameMode ); fgStructure.GameMode->State.IsGameMode = GL_FALSE; fgAddToWindowDestroyList( fgStructure.GameMode ); - fgStructure.GameMode = NULL; #if TARGET_HOST_UNIX_X11 @@ -532,6 +558,8 @@ void FGAPIENTRY glutLeaveGameMode( void ) */ int FGAPIENTRY glutGameModeGet( GLenum eWhat ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGameModeGet" ); + switch( eWhat ) { case GLUT_GAME_MODE_ACTIVE: