Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SURFACESDL: Implemented fallback in case lack of VSYNC #3500

Merged
merged 2 commits into from Nov 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions backends/graphics/surfacesdl/surfacesdl-graphics.cpp
Expand Up @@ -109,7 +109,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
_osdIconSurface(nullptr),
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
_renderer(nullptr), _screenTexture(nullptr),
_renderer(nullptr), _screenTexture(nullptr), _vsync(false),
#endif
#if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0)
_originalBitsPerPixel(0),
Expand Down Expand Up @@ -237,6 +237,10 @@ bool SurfaceSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
#ifdef USE_ASPECT
case OSystem::kFeatureAspectRatioCorrection:
return _videoMode.aspectRatioCorrection;
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
case OSystem::kFeatureVSync:
return _vsync;
#endif
case OSystem::kFeatureFilteringMode:
return _videoMode.filtering;
Expand Down Expand Up @@ -2585,8 +2589,17 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,

_renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, rendererFlags);
if (!_renderer) {
deinitializeRenderer();
return nullptr;
if (_vsync) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check for rendererFlags & SDL_RENDERER_PRESENTVSYNC here, no need for a separate flag

// VSYNC might not be available, so retry without VSYNC
warning("SDL_SetVideoMode: SDL_CreateRenderer() failed with VSYNC option, retrying without it...");
_vsync = false;
rendererFlags &= ~SDL_RENDERER_PRESENTVSYNC;
_renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, rendererFlags);
}
if (!_renderer) {
deinitializeRenderer();
return nullptr;
}
}

getWindowSizeFromSdl(&_windowWidth, &_windowHeight);
Expand Down