From 60d90e03a42a057d1bd7466e6a5683c6f7ae93b9 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Fri, 5 Apr 2024 22:30:58 -0300 Subject: [PATCH] windows: prefer regular vsync instead of dwm flush syncs. The latter can cause stuttering issues on some setups. --- src/modules/window/sdl/Window.cpp | 8 +++++++- src/modules/window/sdl/Window.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 1c8684793..3d5df2c55 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -79,6 +79,12 @@ Window::Window() SDL_version version = {}; SDL_GetVersion(&version); hasSDL203orEarlier = (version.major == 2 && version.minor == 0 && version.patch <= 3); + +#ifdef LOVE_WINDOWS + // Turned off by default, because it (ironically) causes stuttering issues + // on some setups. More investigation is needed before enabling it. + canUseDwmFlush = SDL_GetHintBoolean("LOVE_GRAPHICS_VSYNC_DWM", SDL_FALSE) != SDL_FALSE; +#endif } Window::~Window() @@ -1032,7 +1038,7 @@ void Window::swapBuffers() // - DWM refreshes don't always match the refresh rate of the monitor the window is in (or the requested swap // interval), so we only use it when they do match. // - The user may force GL vsync, and DwmFlush shouldn't be used together with GL vsync. - if (context != nullptr && !settings.fullscreen && swapInterval == 1) + if (context != nullptr && canUseDwmFlush && !settings.fullscreen && swapInterval == 1) { // Desktop composition is always enabled in Windows 8+. But DwmIsCompositionEnabled won't always return true... // (see DwmIsCompositionEnabled docs). diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index 054f33f15..2c2eb5e2e 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -161,6 +161,10 @@ class Window final : public love::window::Window WindowSettings settings; StrongRef icon; +#ifdef LOVE_WINDOWS + bool canUseDwmFlush = false; +#endif + bool open; bool mouseGrabbed;