mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 09:54:10 +03:00
Fix VSync renderer workaround
SDL just got an API to toggle VSync without having to tear down the renderer ( libsdl-org/SDL#4157 ). We can remove the workaround and use that instead. For now, we are putting it behind an ifdef until SDL 2.0.18 officially releases in November. Fixes #831.
This commit is contained in:
@@ -371,48 +371,10 @@ void Screen::toggleLinearFilter(void)
|
||||
);
|
||||
}
|
||||
|
||||
void Screen::resetRendererWorkaround(void)
|
||||
void Screen::toggleVSync(void)
|
||||
{
|
||||
SDL_SetHintWithPriority(
|
||||
SDL_HINT_RENDER_VSYNC,
|
||||
vsync ? "1" : "0",
|
||||
SDL_HINT_OVERRIDE
|
||||
);
|
||||
|
||||
/* FIXME: This exists because SDL_HINT_RENDER_VSYNC is not dynamic!
|
||||
* As a result, our only workaround is to tear down the renderer
|
||||
* and recreate everything so that it can process the variable.
|
||||
* -flibit
|
||||
*/
|
||||
|
||||
if (m_renderer == NULL)
|
||||
{
|
||||
/* We haven't made it to init yet, don't worry about it */
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_RendererInfo renderInfo;
|
||||
SDL_GetRendererInfo(m_renderer, &renderInfo);
|
||||
bool curVsync = (renderInfo.flags & SDL_RENDERER_PRESENTVSYNC) != 0;
|
||||
if (vsync == curVsync)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(m_screenTexture);
|
||||
SDL_DestroyRenderer(m_renderer);
|
||||
|
||||
m_renderer = SDL_CreateRenderer(m_window, -1, 0);
|
||||
m_screenTexture = SDL_CreateTexture(
|
||||
m_renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
320,
|
||||
240
|
||||
);
|
||||
|
||||
/* Ugh, have to make sure to re-apply graphics options after doing the
|
||||
* above, otherwise letterbox/integer won't be applied...
|
||||
*/
|
||||
ResizeScreen(-1, -1);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 17)
|
||||
vsync = !vsync;
|
||||
SDL_RenderSetVSync(m_renderer, (int) vsync);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user