From 98d04702ae81e18c9636c1f934f883a8ebb7f1a3 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Mon, 23 Aug 2021 10:10:13 +0200 Subject: [PATCH] sdl: set vsync swap interval to 2 for 120 Hz displays Issue #293 --- core/wsi/sdl.cpp | 18 ++++++++++++++++-- core/wsi/sdl.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/wsi/sdl.cpp b/core/wsi/sdl.cpp index a07a86b16..9fa3abfea 100644 --- a/core/wsi/sdl.cpp +++ b/core/wsi/sdl.cpp @@ -85,7 +85,21 @@ bool SDLGLGraphicsContext::Init() // Swap immediately swapOnVSync = false; #endif - SDL_GL_SetSwapInterval((int)swapOnVSync); + swapInterval = 1; + int displayIndex = SDL_GetWindowDisplayIndex(window); + if (displayIndex < 0) + WARN_LOG(RENDERER, "Cannot get the window display index: %s", SDL_GetError()); + else + { + SDL_DisplayMode mode{}; + if (SDL_GetDesktopDisplayMode(displayIndex, &mode) == 0) { + INFO_LOG(RENDERER, "Monitor refresh rate: %d Hz", mode.refresh_rate); + if (mode.refresh_rate > 100) + swapInterval = 2; + } + } + + SDL_GL_SetSwapInterval(swapOnVSync ? swapInterval : 0); #ifdef GLES load_gles_symbols(); @@ -109,7 +123,7 @@ void SDLGLGraphicsContext::Swap() if (swapOnVSync == (settings.input.fastForwardMode || !config::VSync)) { swapOnVSync = (!settings.input.fastForwardMode && config::VSync); - SDL_GL_SetSwapInterval((int)swapOnVSync); + SDL_GL_SetSwapInterval(swapOnVSync ? swapInterval : 0); } #endif SDL_GL_SwapWindow(window); diff --git a/core/wsi/sdl.h b/core/wsi/sdl.h index d1f9c5b29..83ec28d0d 100644 --- a/core/wsi/sdl.h +++ b/core/wsi/sdl.h @@ -46,6 +46,7 @@ private: SDL_Window* window = nullptr; SDL_GLContext glcontext = nullptr; bool swapOnVSync = false; + int swapInterval = 1; }; extern SDLGLGraphicsContext theGLContext;