Skip to content

Commit

Permalink
SDL: Support VSync with OpenGL in SDL1 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 authored and sev- committed Jan 16, 2023
1 parent 138a983 commit 40f797f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
11 changes: 4 additions & 7 deletions backends/graphics/openglsdl/openglsdl-graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(SdlEventSource *eventSource,
_glContextType = OpenGL::kContextGL;
#endif

#if SDL_VERSION_ATLEAST(2, 0, 0)
_vsync = ConfMan.getBool("vsync");
#endif

// Retrieve a list of working fullscreen modes
Common::Rect desktopRes = _window->getDesktopResolution();
Expand Down Expand Up @@ -199,9 +197,9 @@ bool OpenGLSdlGraphicsManager::hasFeature(OSystem::Feature f) const {
switch (f) {
case OSystem::kFeatureFullscreenMode:
case OSystem::kFeatureIconifyWindow:
case OSystem::kFeatureVSync:
#if SDL_VERSION_ATLEAST(2, 0, 0)
case OSystem::kFeatureFullscreenToggleKeepsContext:
case OSystem::kFeatureVSync:
#endif
return true;

Expand All @@ -217,12 +215,10 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
_wantsFullScreen = enable;
break;

#if SDL_VERSION_ATLEAST(2, 0, 0)
case OSystem::kFeatureVSync:
assert(getTransactionMode() != kTransactionNone);
_vsync = enable;
break;
#endif

case OSystem::kFeatureIconifyWindow:
if (enable) {
Expand Down Expand Up @@ -251,10 +247,9 @@ bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
return _wantsFullScreen;
}
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)

case OSystem::kFeatureVSync:
return _vsync;
#endif

default:
return OpenGLGraphicsManager::getFeatureState(f);
Expand Down Expand Up @@ -598,6 +593,8 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
notifyContextDestroy();
}

SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, _vsync ? 1 : 0);

_hwScreen = SDL_SetVideoMode(width, height, 32, flags);

if (!_hwScreen) {
Expand Down
2 changes: 0 additions & 2 deletions backends/graphics/openglsdl/openglsdl-graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ class OpenGLSdlGraphicsManager : public OpenGL::OpenGLGraphicsManager, public Sd
uint _graphicsScale;
bool _gotResize;

#if SDL_VERSION_ATLEAST(2, 0, 0)
bool _vsync;
#endif
bool _wantsFullScreen;
uint _ignoreResizeEvents;

Expand Down

0 comments on commit 40f797f

Please sign in to comment.