diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index c231d5362..30d0bb8b1 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -215,6 +215,24 @@ void Sdl2Application::swapBuffers() { #endif } +Int Sdl2Application::swapInterval() const { + return SDL_GL_GetSwapInterval(); +} + +bool Sdl2Application::setSwapInterval(const Int interval) { + if(SDL_GL_SetSwapInterval(interval) == -1) { + Error() << "Platform::Sdl2Application::setSwapInterval(): cannot set swap interval:" << SDL_GetError(); + return false; + } + + if(SDL_GL_GetSwapInterval() != interval) { + Error() << "Platform::Sdl2Application::setSwapInterval(): swap interval setting ignored by the driver"; + return false; + } + + return true; +} + Sdl2Application::~Sdl2Application() { _context.reset(); diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 9248da50d..a7037b29f 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -276,9 +276,23 @@ class Sdl2Application { * @brief Swap buffers * * Paints currently rendered framebuffer on screen. + * @see @ref setSwapInterval() */ void swapBuffers(); + /** @brief Swap interval */ + Int swapInterval() const; + + /** + * @brief Set swap interval + * + * Set `0` for no VSync, `1` for enabled VSync. Some platforms support + * `-1` for late swap tearing. Prints error message and returns `false` + * if swap interval cannot be set, `true` otherwise. Default is + * driver-dependent, you can query the value with @ref swapInterval(). + */ + bool setSwapInterval(Int interval); + /** * @brief Redraw immediately *