Qt: Support disabling vsync via glXSwapInterval

This commit is contained in:
Connor McLaughlin 2020-04-23 13:04:40 +10:00
parent fc6a165438
commit ea25b58dd3
3 changed files with 41 additions and 1 deletions

View File

@ -39,6 +39,8 @@ endif()
if(ANDROID) if(ANDROID)
find_package(EGL REQUIRED) find_package(EGL REQUIRED)
else()
find_package(OpenGL COMPONENTS EGL GLX OpenGL)
endif() endif()

View File

@ -58,4 +58,9 @@ if(WIN32)
d3d11hostdisplay.h d3d11hostdisplay.h
) )
target_link_libraries(duckstation-qt PRIVATE d3d11.lib dxgi.lib) 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() endif()

View File

@ -4,8 +4,10 @@
#include "imgui.h" #include "imgui.h"
#include "qtdisplaywidget.h" #include "qtdisplaywidget.h"
#include "qthostinterface.h" #include "qthostinterface.h"
#include <QtGui/QGuiApplication>
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QWindow> #include <QtGui/QWindow>
#include <QtCore/QDebug>
#include <array> #include <array>
#include <imgui_impl_opengl3.h> #include <imgui_impl_opengl3.h>
#include <tuple> #include <tuple>
@ -22,8 +24,10 @@ static void* GetProcAddressCallback(const char* name)
return (void*)ctx->getProcAddress(name); return (void*)ctx->getProcAddress(name);
} }
#ifdef WIN32 #if defined(WIN32)
#include "common/windows_headers.h" #include "common/windows_headers.h"
#elif defined(HAS_GLX)
#include <GL/glx.h>
#endif #endif
/// Changes the swap interval on a window. Since Qt doesn't expose this functionality, we need to change it manually /// 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) if (wgl_swap_interval_ext)
wgl_swap_interval_ext(interval); 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<decltype(glx_swap_interval_ext)>(
glXGetProcAddress(reinterpret_cast<const GLubyte*>("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 #endif
} }