From ea25b58dd33a4bfe81214d6e345ec5da1ec31539 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 23 Apr 2020 13:04:40 +1000 Subject: [PATCH] Qt: Support disabling vsync via glXSwapInterval --- CMakeLists.txt | 2 ++ src/duckstation-qt/CMakeLists.txt | 5 ++++ src/duckstation-qt/openglhostdisplay.cpp | 35 +++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 142f8bdd0..b1a657054 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ endif() if(ANDROID) find_package(EGL REQUIRED) +else() + find_package(OpenGL COMPONENTS EGL GLX OpenGL) endif() diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index c45298b6d..45a9703c4 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -58,4 +58,9 @@ if(WIN32) d3d11hostdisplay.h ) target_link_libraries(duckstation-qt PRIVATE d3d11.lib dxgi.lib) +else() + if(OpenGL_GLX_FOUND) + target_compile_definitions(duckstation-qt PRIVATE "HAS_GLX") + target_link_libraries(duckstation-qt PRIVATE OpenGL::GLX) + endif() endif() diff --git a/src/duckstation-qt/openglhostdisplay.cpp b/src/duckstation-qt/openglhostdisplay.cpp index 8efd32310..a6b119f99 100644 --- a/src/duckstation-qt/openglhostdisplay.cpp +++ b/src/duckstation-qt/openglhostdisplay.cpp @@ -4,8 +4,10 @@ #include "imgui.h" #include "qtdisplaywidget.h" #include "qthostinterface.h" +#include #include #include +#include #include #include #include @@ -22,8 +24,10 @@ static void* GetProcAddressCallback(const char* name) return (void*)ctx->getProcAddress(name); } -#ifdef WIN32 +#if defined(WIN32) #include "common/windows_headers.h" +#elif defined(HAS_GLX) +#include #endif /// Changes the swap interval on a window. Since Qt doesn't expose this functionality, we need to change it manually @@ -55,6 +59,35 @@ static void SetSwapInterval(QOpenGLContext* context, int interval) if (wgl_swap_interval_ext) wgl_swap_interval_ext(interval); +#elif __linux__ + const QString platform_name(QGuiApplication::platformName()); + if (platform_name == QStringLiteral("xcb")) + { + static void(*glx_swap_interval_ext)(Display*, GLXDrawable, int) = nullptr; + + if (last_context != context) + { + glx_swap_interval_ext = nullptr; + last_context = context; + + glx_swap_interval_ext = reinterpret_cast( + glXGetProcAddress(reinterpret_cast("glXSwapIntervalEXT"))); + if (!glx_swap_interval_ext) + return; + } + + if (!glx_swap_interval_ext) + return; + + Display* dpy = glXGetCurrentDisplay(); + GLXDrawable drawable = glXGetCurrentDrawable(); + if (dpy && drawable != GLX_NONE) + glx_swap_interval_ext(dpy, drawable, interval); + } + else + { + qCritical() << "Unknown platform: " << platform_name; + } #endif }