diff --git a/components/sdlutil/sdlgraphicswindow.cpp b/components/sdlutil/sdlgraphicswindow.cpp index dc6129e43..3b76e6887 100644 --- a/components/sdlutil/sdlgraphicswindow.cpp +++ b/components/sdlutil/sdlgraphicswindow.cpp @@ -113,7 +113,7 @@ void GraphicsWindowSDL2::init() return; } - SDL_GL_SetSwapInterval(_traits->vsync ? 1 : 0); + setSwapInterval(_traits->vsync); SDL_GL_MakeCurrent(oldWin, oldCtx); @@ -194,11 +194,31 @@ void GraphicsWindowSDL2::setSyncToVBlank(bool on) SDL_GL_MakeCurrent(mWindow, mContext); - SDL_GL_SetSwapInterval(on ? 1 : 0); + setSwapInterval(on); SDL_GL_MakeCurrent(oldWin, oldCtx); } +void GraphicsWindowSDL2::setSwapInterval(bool enable) +{ + if (enable) + { + if (SDL_GL_SetSwapInterval(-1) == -1) + { + OSG_NOTICE << "Adaptive vsync unsupported" << std::endl; + if (SDL_GL_SetSwapInterval(1) == -1) + { + OSG_NOTICE << "Vertical synchronization unsupported, disabling" << std::endl; + SDL_GL_SetSwapInterval(0); + } + } + } + else + { + SDL_GL_SetSwapInterval(0); + } +} + void GraphicsWindowSDL2::raiseWindow() { SDL_RaiseWindow(mWindow); diff --git a/components/sdlutil/sdlgraphicswindow.hpp b/components/sdlutil/sdlgraphicswindow.hpp index 4b48b4073..dd8076776 100644 --- a/components/sdlutil/sdlgraphicswindow.hpp +++ b/components/sdlutil/sdlgraphicswindow.hpp @@ -80,6 +80,9 @@ public: SDL_Window *mWindow; }; + +private: + void setSwapInterval(bool enable); }; }