Add SDL_RenderSetVSync()

Currently, if an application wants to toggle VSync, they'd have to tear
down the renderer and recreate it. This patch fixes that by letting
applications call SDL_RenderSetVSync().

This is the same as the patch in #3673, except it applies to all
renderers (including PSP, even thought it seems that the VSync flag is
disabled for that renderer). Furthermore, the renderer flags also change
as well, which #3673 didn't do. It is also an API instead of using hint
callbacks (which could be potentially dangerous).

Closes #3673.
This commit is contained in:
Misa 2021-03-07 15:20:45 -08:00 committed by Sam Lantinga
parent b2504b5da6
commit 4549769d7d
13 changed files with 168 additions and 0 deletions

View file

@ -1229,6 +1229,27 @@ static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
return 0;
}
static int
GLES_SetVSync(SDL_Renderer * renderer, const int vsync)
{
int retval;
if (vsync) {
retval = SDL_GL_SetSwapInterval(1);
} else {
retval = SDL_GL_SetSwapInterval(0);
}
if (retval != 0) {
return retval;
}
if (SDL_GL_GetSwapInterval() > 0) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
} else {
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
}
return retval;
}
static SDL_Renderer *
GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
{
@ -1294,6 +1315,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->RenderPresent = GLES_RenderPresent;
renderer->DestroyTexture = GLES_DestroyTexture;
renderer->DestroyRenderer = GLES_DestroyRenderer;
renderer->SetVSync = GLES_SetVSync;
renderer->GL_BindTexture = GLES_BindTexture;
renderer->GL_UnbindTexture = GLES_UnbindTexture;
renderer->info = GLES_RenderDriver.info;