Qt: Support disabling vsync via glXSwapInterval
This commit is contained in:
parent
fc6a165438
commit
ea25b58dd3
|
@ -39,6 +39,8 @@ endif()
|
|||
|
||||
if(ANDROID)
|
||||
find_package(EGL REQUIRED)
|
||||
else()
|
||||
find_package(OpenGL COMPONENTS EGL GLX OpenGL)
|
||||
endif()
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
#include "imgui.h"
|
||||
#include "qtdisplaywidget.h"
|
||||
#include "qthostinterface.h"
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtCore/QDebug>
|
||||
#include <array>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
#include <tuple>
|
||||
|
@ -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 <GL/glx.h>
|
||||
#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<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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue