Allow changing r_swapInterval (VSync) on-the-fly

Not supported with SDL1.2 - but that's only still supported by dhewm3
because I'm too lazy to rip it out :-p
This commit is contained in:
Daniel Gibson 2024-05-30 05:54:18 +02:00
parent 139020f52b
commit e3d67f0ac9
4 changed files with 22 additions and 2 deletions

View file

@ -260,6 +260,10 @@ static void R_CheckCvars( void ) {
R_SetColorMappings();
}
}
if ( r_swapInterval.IsModified() ) {
GLimp_SetSwapInterval( r_swapInterval.GetInteger() );
}
}
/*

View file

@ -1113,6 +1113,8 @@ const int GRAB_HIDECURSOR = (1 << 1);
const int GRAB_RELATIVEMOUSE = (1 << 2);
void GLimp_GrabInput(int flags);
bool GLimp_SetSwapInterval( int swapInterval );
/*
====================================================================

View file

@ -404,8 +404,7 @@ try_again:
context = SDL_GL_CreateContext(window);
if (SDL_GL_SetSwapInterval(r_swapInterval.GetInteger()) < 0)
common->Warning("SDL_GL_SWAP_CONTROL not supported");
GLimp_SetSwapInterval( r_swapInterval.GetInteger() );
SDL_GetWindowSize(window, &glConfig.vidWidth, &glConfig.vidHeight);
@ -737,3 +736,17 @@ void GLimp_GrabInput(int flags) {
SDL_WM_GrabInput( (flags & GRAB_RELATIVEMOUSE) ? SDL_GRAB_ON : SDL_GRAB_OFF );
#endif
}
bool GLimp_SetSwapInterval( int swapInterval )
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
if ( SDL_GL_SetSwapInterval( swapInterval ) < 0 ) {
common->Warning( "SDL_GL_SetSwapInterval( %d ) not supported", swapInterval );
return false;
}
return true;
#else
common->Warning( "SDL1.2 does not support changing the swapinterval (vsync) on-the-fly!" );
return false;
#endif
}

View file

@ -397,6 +397,7 @@ void GLimp_SwapBuffers() {};
void GLimp_ActivateContext() {};
void GLimp_DeactivateContext() {};
void GLimp_GrabInput(int flags) {};
bool GLimp_SetSwapInterval( int swapInterval ) { return false; }
#ifdef _MSC_VER
#pragma warning(pop)