From 3060e1d1a21b228eaa6138c5bb72edbe8b4264ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 12 Apr 2015 20:33:38 +0200 Subject: [PATCH] Platform: finally add VSync support to Sdl2Application. Sorry that it took ages. Oh, actually, I'm not able to test this AT ALL because my awesomely amazing NVidia Optimus laptop CANNOT (what?!) do VSync because of some bad design decisions from previous century that led to the disaster that we now know as X11 and as I heard it is impossible to work around that or something. Ugh. --- src/Magnum/Platform/Sdl2Application.cpp | 18 ++++++++++++++++++ src/Magnum/Platform/Sdl2Application.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+) 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 *