mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-03 08:28:29 +00:00
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:
@@ -2012,6 +2012,26 @@ GLES2_RenderPresent(SDL_Renderer *renderer)
|
||||
SDL_GL_SwapWindow(renderer->window);
|
||||
}
|
||||
|
||||
static int
|
||||
GLES2_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;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************************************
|
||||
* Bind/unbinding of textures
|
||||
@@ -2197,6 +2217,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
renderer->RenderPresent = GLES2_RenderPresent;
|
||||
renderer->DestroyTexture = GLES2_DestroyTexture;
|
||||
renderer->DestroyRenderer = GLES2_DestroyRenderer;
|
||||
renderer->SetVSync = GLES2_SetVSync;
|
||||
renderer->GL_BindTexture = GLES2_BindTexture;
|
||||
renderer->GL_UnbindTexture = GLES2_UnbindTexture;
|
||||
|
||||
|
Reference in New Issue
Block a user