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

@@ -1743,6 +1743,24 @@ D3D_Reset(SDL_Renderer * renderer)
return 0;
}
static int
D3D_SetVSync(SDL_Renderer * renderer, const int vsync)
{
D3D_RenderData *data = renderer->driverdata;
if (vsync) {
data->pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
} else {
data->pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
}
if (D3D_Reset(renderer) < 0) {
/* D3D_Reset will call SDL_SetError() */
return -1;
}
return 0;
}
SDL_Renderer *
D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
{
@@ -1805,6 +1823,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->RenderPresent = D3D_RenderPresent;
renderer->DestroyTexture = D3D_DestroyTexture;
renderer->DestroyRenderer = D3D_DestroyRenderer;
renderer->SetVSync = D3D_SetVSync;
renderer->info = D3D_RenderDriver.info;
renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
renderer->driverdata = data;