SDL: Generalize VSYNC option so it works for 2D games too, in both SDL surface and opengl graphic modes.

This commit is contained in:
Vanfanel 2021-10-21 08:02:00 +02:00 committed by Daniel
parent fc7f51afb0
commit 3a59c28179
5 changed files with 21 additions and 2 deletions

View file

@ -539,6 +539,13 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
return false; return false;
} }
#if SDL_VERSION_ATLEAST(2, 0, 0)
_vsync = ConfMan.getBool("vsync");
if (SDL_GL_SetSwapInterval(_vsync ? 1 : 0)) {
warning("Unable to %s VSync: %s", _vsync ? "enable" : "disable", SDL_GetError());
}
#endif
notifyContextCreate(rgba8888, rgba8888); notifyContextCreate(rgba8888, rgba8888);
int actualWidth, actualHeight; int actualWidth, actualHeight;
getWindowSizeFromSdl(&actualWidth, &actualHeight); getWindowSizeFromSdl(&actualWidth, &actualHeight);

View file

@ -92,6 +92,9 @@ private:
bool _ignoreLoadVideoMode; bool _ignoreLoadVideoMode;
bool _gotResize; bool _gotResize;
#if SDL_VERSION_ATLEAST(2, 0, 0)
bool _vsync;
#endif
bool _wantsFullScreen; bool _wantsFullScreen;
uint _ignoreResizeEvents; uint _ignoreResizeEvents;

View file

@ -2560,6 +2560,7 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
deinitializeRenderer(); deinitializeRenderer();
uint32 createWindowFlags = SDL_WINDOW_RESIZABLE; uint32 createWindowFlags = SDL_WINDOW_RESIZABLE;
uint32 rendererFlags = 0;
if ((flags & SDL_FULLSCREEN) != 0) { if ((flags & SDL_FULLSCREEN) != 0) {
createWindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP; createWindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
} }
@ -2576,7 +2577,14 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
#endif #endif
_renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0); #if SDL_VERSION_ATLEAST(2, 0, 0)
_vsync = ConfMan.getBool("vsync");
if (_vsync) {
rendererFlags |= SDL_RENDERER_PRESENTVSYNC;
}
#endif
_renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, rendererFlags);
if (!_renderer) { if (!_renderer) {
deinitializeRenderer(); deinitializeRenderer();
return nullptr; return nullptr;

View file

@ -193,6 +193,7 @@ protected:
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors); int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha); int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key); int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
bool _vsync;
#endif #endif
/** Unseen game screen */ /** Unseen game screen */

View file

@ -1466,7 +1466,7 @@ void OptionsDialog::addGraphicControls(GuiObject *boss, const Common::String &pr
// Fullscreen checkbox // Fullscreen checkbox
_fullscreenCheckbox = new CheckboxWidget(boss, prefix + "grFullscreenCheckbox", _("Fullscreen mode"), Common::U32String(), kFullscreenToggled); _fullscreenCheckbox = new CheckboxWidget(boss, prefix + "grFullscreenCheckbox", _("Fullscreen mode"), Common::U32String(), kFullscreenToggled);
_vsyncCheckbox = new CheckboxWidget(boss, prefix + "grVSyncCheckbox", _("V-Sync in 3D Games"), _("Wait for the vertical sync to refresh the screen in 3D renderer")); _vsyncCheckbox = new CheckboxWidget(boss, prefix + "grVSyncCheckbox", _("V-Sync"), _("Wait for the vertical sync to refresh the screen in order to prevent tearing artifacts"));
if (g_system->getOverlayWidth() > 320) if (g_system->getOverlayWidth() > 320)
_rendererTypePopUpDesc = new StaticTextWidget(boss, prefix + "grRendererTypePopupDesc", _("Game 3D Renderer:")); _rendererTypePopUpDesc = new StaticTextWidget(boss, prefix + "grRendererTypePopupDesc", _("Game 3D Renderer:"));