From 527ee0f45d3414f23cf6f16f75c5cd4cf4ac6664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 27 Jun 2022 11:20:24 +0200 Subject: [PATCH] Platform: fix Sdl2Application::setSwapInterval() with late swap behavior. For quite a while, setSwapInterval() was reporting that "swap interval was ignored by the driver". Since I used to have that behavior ages ago on a NVidia Optimus machine (where it was just *impossible* to have VSync, imagine that!!), I assumed it was a similar wart in Mesa and didn't bother looking into it. It turns out, however, that calling setSwapInterval(1) may result in SDL_GL_GetSwapInterval() returning -1 instead of 1, thus helpfully enabling late-swap behavior for me. Since -1 != -1, the code treated that the same as if SDL_GL_GetSwapInterval() returned 0 (which was the case with NV Optimus having broken VSync), but it's not an error in fact. --- doc/changelog.dox | 3 +++ src/Magnum/Platform/Sdl2Application.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 2834686af..dcba6fcb0 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -725,6 +725,9 @@ See also: case as for a WebGL-enabled context - Fixed a crash in @ref Platform::GlfwApplication::setCursor() on the upcoming GLFW 3.4 +- Fixed @ref Platform::Sdl2Application::setSwapInterval() to take late swap + behavior (@cpp -1 @ce) into account instead of treating it as an error + and continuing with timer-based framerate capping - @ref SceneGraph::BasicMatrixTransformation2D, @ref SceneGraph::BasicMatrixTransformation3D, @ref SceneGraph::BasicRigidMatrixTransformation2D and diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 73053b600..c1d6fa8be 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -781,8 +781,11 @@ bool Sdl2Application::setSwapInterval(const Int interval) { return false; } - if(SDL_GL_GetSwapInterval() != interval) { - Error() << "Platform::Sdl2Application::setSwapInterval(): swap interval setting ignored by the driver"; + /* Setting interval to 1 may cause SDL_GL_GetSwapInterval() to return -1, + which is a valid case */ + const Int actualInterval = SDL_GL_GetSwapInterval(); + if(actualInterval != interval && !(interval == 1 && actualInterval == -1)) { + Error() << "Platform::Sdl2Application::setSwapInterval(): swap interval setting ignored by the driver:" << SDL_GetError(); _flags &= ~Flag::VSyncEnabled; return false; }