mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01: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:
parent
8d0a90a588
commit
6ba7058a0e
4 changed files with 14 additions and 49 deletions
|
@ -605,11 +605,12 @@ static void menuactionpress(void)
|
||||||
game.savestatsandsettings_menu();
|
game.savestatsandsettings_menu();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
/* FIXME: Upgrade to SDL 2.0.18 and remove this ifdef when it releases! */
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 17)
|
||||||
//toggle vsync
|
//toggle vsync
|
||||||
music.playef(11);
|
music.playef(11);
|
||||||
#ifndef __HAIKU__ // FIXME: Remove after SDL VSync bug is fixed! -flibit
|
|
||||||
graphics.screenbuffer->vsync = !graphics.screenbuffer->vsync;
|
graphics.screenbuffer->vsync = !graphics.screenbuffer->vsync;
|
||||||
graphics.screenbuffer->resetRendererWorkaround();
|
graphics.screenbuffer->toggleVSync();
|
||||||
game.savestatsandsettings_menu();
|
game.savestatsandsettings_menu();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -370,10 +370,12 @@ static void menurender(void)
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
graphics.bigprint(-1, 30, "Toggle VSync", tr, tg, tb, true);
|
graphics.bigprint(-1, 30, "Toggle VSync", tr, tg, tb, true);
|
||||||
#ifdef __HAIKU__ // FIXME: Remove after SDL VSync bug is fixed! -flibit
|
/* FIXME: Upgrade to SDL 2.0.18 and remove this ifdef when it releases! */
|
||||||
graphics.Print(-1, 65, "Edit the config file on Haiku!", tr, tg, tb, true);
|
#if SDL_VERSION_ATLEAST(2, 0, 17)
|
||||||
#else
|
|
||||||
graphics.Print(-1, 65, "Turn VSync on or off.", tr, tg, tb, true);
|
graphics.Print(-1, 65, "Turn VSync on or off.", tr, tg, tb, true);
|
||||||
|
#else
|
||||||
|
graphics.Print(-1, 65, "Your SDL version is too old!", tr, tg, tb, true);
|
||||||
|
graphics.Print(-1, 75, "Edit the config file.", tr, tg, tb, true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!graphics.screenbuffer->vsync)
|
if (!graphics.screenbuffer->vsync)
|
||||||
|
|
|
@ -371,48 +371,10 @@ void Screen::toggleLinearFilter(void)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::resetRendererWorkaround(void)
|
void Screen::toggleVSync(void)
|
||||||
{
|
{
|
||||||
SDL_SetHintWithPriority(
|
#if SDL_VERSION_ATLEAST(2, 0, 17)
|
||||||
SDL_HINT_RENDER_VSYNC,
|
vsync = !vsync;
|
||||||
vsync ? "1" : "0",
|
SDL_RenderSetVSync(m_renderer, (int) vsync);
|
||||||
SDL_HINT_OVERRIDE
|
#endif
|
||||||
);
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
void toggleFullScreen(void);
|
void toggleFullScreen(void);
|
||||||
void toggleStretchMode(void);
|
void toggleStretchMode(void);
|
||||||
void toggleLinearFilter(void);
|
void toggleLinearFilter(void);
|
||||||
void resetRendererWorkaround(void);
|
void toggleVSync(void);
|
||||||
|
|
||||||
bool isWindowed;
|
bool isWindowed;
|
||||||
bool isFiltered;
|
bool isFiltered;
|
||||||
|
|
Loading…
Reference in a new issue