From ed6cf225f10640bc37a6719610b923b7c746303a Mon Sep 17 00:00:00 2001 From: flightlessmango Date: Wed, 26 Jun 2024 16:10:07 +0200 Subject: [PATCH] present_mode: proper vsync implementation --- src/gl/inject_glx.cpp | 11 +++++++++++ src/hud_elements.h | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gl/inject_glx.cpp b/src/gl/inject_glx.cpp index 7f8c71c..1dbd089 100644 --- a/src/gl/inject_glx.cpp +++ b/src/gl/inject_glx.cpp @@ -131,8 +131,19 @@ EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) { return ret; } +#ifndef GLX_SWAP_INTERVAL_EXT +#define GLX_SWAP_INTERVAL_EXT 0x20F1 +#endif + static void do_imgui_swap(void *dpy, void *drawable) { + static auto last_time = std::chrono::steady_clock::now(); + auto current_time = std::chrono::steady_clock::now(); + + std::chrono::duration elapsed_seconds = current_time - last_time; + if (HUDElements.vsync == 10 || elapsed_seconds.count() > 5.0) + glx.QueryDrawable(dpy, drawable, GLX_SWAP_INTERVAL_EXT, &HUDElements.vsync); + GLint vp[4]; if (!is_blacklisted()) { imgui_create(glx.GetCurrentContext(), gl_wsi::GL_WSI_GLX); diff --git a/src/hud_elements.h b/src/hud_elements.h index f49fa54..08c3b7e 100644 --- a/src/hud_elements.h +++ b/src/hud_elements.h @@ -52,6 +52,7 @@ class HudElements{ uint32_t vendorID; int hdr_status = 0; int refresh = 0; + unsigned int vsync = 10; std::unique_ptr winesync_ptr = nullptr; std::unique_ptr net = nullptr; #ifdef __linux__ @@ -158,11 +159,8 @@ class HudElements{ std::string get_present_mode(){ if (is_vulkan) return presentModeMap[cur_present_mode]; - // TODO: the opengl side is probably not as solid. - // But it also might not be possible to figure out if vsync - // is on or off unless we specify it. else - return params->gl_vsync == 0 ? "OFF" : "ON"; + return vsync == 0 ? "OFF" : "ON"; } };