Merge branch 'sw-vsync-fix' into 'next'

Fix software vsync

See merge request STJr/SRB2!1940
This commit is contained in:
LJ Sonic 2023-03-13 18:28:28 +00:00
commit ac4d89e4d8

View file

@ -102,8 +102,10 @@ rendermode_t chosenrendermode = render_none; // set by command line arguments
boolean highcolor = false;
static void VidWaitChanged(void);
// synchronize page flipping with screen refresh
consvar_t cv_vidwait = CVAR_INIT ("vid_wait", "On", CV_SAVE, CV_OnOff, NULL);
consvar_t cv_vidwait = CVAR_INIT ("vid_wait", "On", CV_SAVE | CV_CALL, CV_OnOff, VidWaitChanged);
static consvar_t cv_stretch = CVAR_INIT ("stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL);
static consvar_t cv_alwaysgrabmouse = CVAR_INIT ("alwaysgrabmouse", "Off", CV_SAVE, CV_OnOff, NULL);
@ -274,6 +276,22 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen, SDL_bool
}
}
static void VidWaitChanged(void)
{
if (renderer && rendermode == render_soft)
{
#if SDL_VERSION_ATLEAST(2, 0, 18)
SDL_RenderSetVSync(renderer, cv_vidwait.value ? 1 : 0);
#endif
}
#ifdef HWRENDER
else if (rendermode == render_opengl && sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext)
{
SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0);
}
#endif
}
static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code)
{
if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z)
@ -1476,15 +1494,19 @@ static SDL_bool Impl_CreateContext(void)
int flags = 0; // Use this to set SDL_RENDERER_* flags now
if (usesdl2soft)
flags |= SDL_RENDERER_SOFTWARE;
#if 0
// This shit is BROKEN.
// - The version of SDL we're using cannot toggle VSync at runtime. We'll need a new SDL version implemented to have this work properly.
// - cv_vidwait is initialized before config is loaded, so it's forced to default value at runtime, and forced off when switching. The config loading code would need restructured.
// - With both this & frame interpolation on, I_FinishUpdate takes x10 longer. At this point, it is simpler to use a standard FPS cap.
// So you can probably guess why I'm kinda over this, I'm just disabling it.
else if (cv_vidwait.value)
{
#if SDL_VERSION_ATLEAST(2, 0, 18)
// If SDL is new enough, we can turn off vsync later.
flags |= SDL_RENDERER_PRESENTVSYNC;
#else
// However, if it isn't, we should just silently turn vid_wait off
// This is because the renderer will be created before the config
// is read and vid_wait is set from the user's preferences, and thus
// vid_wait will have no effect.
CV_StealthSetValue(cv_vidwait, 0);
#endif
}
if (!renderer)
renderer = SDL_CreateRenderer(window, -1, flags);
@ -1571,6 +1593,7 @@ boolean VID_CheckRenderer(void)
else if (vid.glstate == VID_GL_LIBRARY_ERROR)
rendererchanged = false;
}
else
#endif
if (!contextcreated)