Add glimpParms_t GLimp_GetCurState() to get current window state

it's queried from SDL so it should be up-to-date.
Using it in GLimp_SetScreenParms(), as it mostly did the same SDL calls
to get the current state for the partial vid_restart
This commit is contained in:
Daniel Gibson 2024-06-12 22:26:30 +02:00
parent 387430a01f
commit 94738f1f16
4 changed files with 60 additions and 21 deletions

View file

@ -366,7 +366,7 @@ static void R_CheckPortableExtensions( void ) {
glConfig.anisotropicAvailable = R_CheckExtension( "GL_EXT_texture_filter_anisotropic" );
if ( glConfig.anisotropicAvailable ) {
qglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glConfig.maxTextureAnisotropy );
common->Printf( " maxTextureAnisotropy: %f\n", glConfig.maxTextureAnisotropy );
common->Printf( " maxTextureAnisotropy: %g\n", glConfig.maxTextureAnisotropy );
} else {
glConfig.maxTextureAnisotropy = 1;
}
@ -689,6 +689,7 @@ void R_InitOpenGL( void ) {
parms.width = glConfig.vidWidth;
parms.height = glConfig.vidHeight;
parms.fullScreen = r_fullscreen.GetBool();
parms.fullScreenDesktop = r_fullscreenDesktop.GetBool();
parms.displayHz = r_displayRefresh.GetInteger();
parms.multiSamples = r_multiSamples.GetInteger();
parms.stereo = false;
@ -1987,6 +1988,7 @@ void R_VidRestart_f( const idCmdArgs &args ) {
parms.height = wantedHeight;
parms.fullScreen = ( forceWindow ) ? false : r_fullscreen.GetBool();
parms.fullScreenDesktop = r_fullscreenDesktop.GetBool();
parms.displayHz = r_displayRefresh.GetInteger();
// "vid_restart partial windowed" is used in case of errors to return to windowed mode
// before things explode more. in that case just keep whatever MSAA setting is active

View file

@ -1065,6 +1065,7 @@ typedef struct {
int width;
int height;
bool fullScreen;
bool fullScreenDesktop;
bool stereo;
int displayHz;
int multiSamples;
@ -1119,6 +1120,8 @@ bool GLimp_SetSwapInterval( int swapInterval );
bool GLimp_SetWindowResizable( bool enableResizable );
void GLimp_UpdateWindowSize();
glimpParms_t GLimp_GetCurState();
/*
====================================================================

View file

@ -157,7 +157,7 @@ bool GLimp_Init(glimpParms_t parms) {
if (parms.fullScreen == 1)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
if(r_fullscreenDesktop.GetBool())
if(parms.fullScreenDesktop)
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
else
#endif
@ -279,10 +279,10 @@ try_again:
#if SDL_VERSION_ATLEAST(2, 0, 0)
if ( r_fullscreen.GetBool() && r_fullscreenDesktop.GetBool() ) {
if ( parms.fullScreen && parms.fullScreenDesktop ) {
common->Printf( "Will create a pseudo-fullscreen window at the current desktop resolution\n" );
} else {
const char* windowMode = r_fullscreen.GetBool() ? "fullscreen-" : "";
const char* windowMode = parms.fullScreen ? "fullscreen-" : "";
common->Printf("Will create a %swindow with resolution %dx%d (r_mode = %d)\n",
windowMode, parms.width, parms.height, r_mode.GetInteger());
}
@ -609,34 +609,23 @@ GLimp_SetScreenParms
*/
bool GLimp_SetScreenParms(glimpParms_t parms) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
int curMultiSamples = 0;
if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &curMultiSamples ) == 0 && curMultiSamples > 0 ) {
if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &curMultiSamples ) != 0 ) {
curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA
}
} else {
curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA
}
glimpParms_t curState = GLimp_GetCurState();
if( parms.multiSamples != -1 && parms.multiSamples != curMultiSamples ) {
if( parms.multiSamples != -1 && parms.multiSamples != curState.multiSamples ) {
// if MSAA settings have changed, we really need a vid_restart
return false;
}
Uint32 winFlags = SDL_GetWindowFlags( window );
bool isFullscreen = (winFlags & SDL_WINDOW_FULLSCREEN) != 0;
bool isFullscreenDesktop = (winFlags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
bool wantFullscreenDesktop = parms.fullScreen && r_fullscreenDesktop.GetBool();
bool wantFullscreenDesktop = parms.fullScreen && parms.fullScreenDesktop;
// TODO: parms.displayHz ?
if ( isFullscreenDesktop && wantFullscreenDesktop ) {
if ( curState.fullScreenDesktop && wantFullscreenDesktop ) {
return true; // nothing to do (resolution is not configurable in that mode)
}
if ( !parms.fullScreen ) { // we want windowed mode
if ( isFullscreen && SDL_SetWindowFullscreen( window, 0 ) != 0 ) {
if ( curState.fullScreen && SDL_SetWindowFullscreen( window, 0 ) != 0 ) {
common->Warning( "GLimp_SetScreenParms(): Couldn't switch to windowed mode, SDL error: %s\n", SDL_GetError() );
return false;
}
@ -645,7 +634,7 @@ bool GLimp_SetScreenParms(glimpParms_t parms) {
} else { // we want some kind of fullscreen mode
// it's probably safest to first switch to windowed mode
if ( isFullscreen ) {
if ( curState.fullScreen ) {
SDL_SetWindowFullscreen( window, 0 );
}
@ -702,6 +691,50 @@ bool GLimp_SetScreenParms(glimpParms_t parms) {
#endif
}
// sets a glimpParms_t based on the current true state (according to SDL)
// Note: here, ret.fullScreenDesktop is only true if currently in fullscreen desktop mode
// (and ret.fullScreen is true as well)
glimpParms_t GLimp_GetCurState()
{
glimpParms_t ret = {};
#if SDL_VERSION_ATLEAST(2, 0, 0)
int curMultiSamples = 0;
if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &curMultiSamples ) == 0 && curMultiSamples > 0 ) {
if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &curMultiSamples ) != 0 ) {
curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA
}
} else {
curMultiSamples = 0; // SDL_GL_GetAttribute() call failed, assume no MSAA
}
ret.multiSamples = curMultiSamples;
Uint32 winFlags = SDL_GetWindowFlags( window );
ret.fullScreen = (winFlags & SDL_WINDOW_FULLSCREEN) != 0;
ret.fullScreenDesktop = (winFlags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
if ( ret.fullScreen && !ret.fullScreenDesktop ) { // I think SDL_GetWindowDisplayMode() is only for "real" fullscreen?
SDL_DisplayMode real_mode = {};
if ( SDL_GetWindowDisplayMode( window, &real_mode ) == 0 ) {
ret.width = real_mode.w;
ret.height = real_mode.h;
ret.displayHz = real_mode.refresh_rate;
}
}
if ( ret.width == 0 && ret.height == 0 ) { // windowed mode or SDL_GetWindowDisplayMode() failed
SDL_GetWindowSize( window, &ret.width, &ret.height );
}
assert( ret.width == glConfig.winWidth && ret.height == glConfig.winHeight );
assert( ret.fullScreen == glConfig.isFullscreen );
#else
assert( 0 && "Don't use GLimp_GetCurState() with SDL1.2 !" );
#endif
return ret;
}
/*
===================
GLimp_Shutdown

View file

@ -400,6 +400,7 @@ void GLimp_GrabInput(int flags) {};
bool GLimp_SetSwapInterval( int swapInterval ) { return false; }
void GLimp_UpdateWindowSize() {}
bool GLimp_SetWindowResizable( bool enableResizable ) { return false; }
glimpParms_t GLimp_GetCurState() { glimpParms_t ret = {}; return ret; }
#ifdef _MSC_VER
#pragma warning(pop)