Allow Ui::GL::CheckCapapilities to work without QWidget
This commit is contained in:
parent
1d1c524b2c
commit
b1d5c7c116
2 changed files with 38 additions and 10 deletions
|
|
@ -14,9 +14,11 @@
|
||||||
|
|
||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
|
#include <QtGui/QtEvents>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
#include <QtGui/QOpenGLContext>
|
#include <QtGui/QOpenGLContext>
|
||||||
#include <QtGui/QOpenGLFunctions>
|
#include <QtGui/QOpenGLFunctions>
|
||||||
|
#include <QOpenGLWindow>
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
@ -56,7 +58,7 @@ void CrashCheckStart() {
|
||||||
|
|
||||||
const char kOptionAllowLinuxNvidiaOpenGL[] = "allow-linux-nvidia-opengl";
|
const char kOptionAllowLinuxNvidiaOpenGL[] = "allow-linux-nvidia-opengl";
|
||||||
|
|
||||||
Capabilities CheckCapabilities(QWidget *widget) {
|
Capabilities CheckCapabilities(QWidget *widget, bool avoidWidgetCreation) {
|
||||||
if (ForceDisabled) {
|
if (ForceDisabled) {
|
||||||
LOG_ONCE(("OpenGL: Force-disabled."));
|
LOG_ONCE(("OpenGL: Force-disabled."));
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -88,19 +90,43 @@ Capabilities CheckCapabilities(QWidget *widget) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CrashCheckStart();
|
CrashCheckStart();
|
||||||
auto tester = QOpenGLWidget(widget);
|
const auto tester = [&] {
|
||||||
tester.setFormat(format);
|
std::unique_ptr<QObject> result;
|
||||||
tester.grabFramebuffer(); // Force initialize().
|
if (avoidWidgetCreation) {
|
||||||
if (!tester.window()->windowHandle()) {
|
const auto w = new QOpenGLWindow();
|
||||||
tester.window()->createWinId();
|
auto e = QResizeEvent(QSize(), QSize());
|
||||||
|
w->setFormat(format);
|
||||||
|
w->create();
|
||||||
|
static_cast<QObject*>(w)->event(&e); // Force initialize().
|
||||||
|
w->grabFramebuffer(); // Force makeCurrent().
|
||||||
|
result.reset(w);
|
||||||
|
} else {
|
||||||
|
const auto w = new QOpenGLWidget(widget);
|
||||||
|
w->setFormat(format);
|
||||||
|
w->grabFramebuffer(); // Force initialize().
|
||||||
|
if (!w->window()->windowHandle()) {
|
||||||
|
w->window()->createWinId();
|
||||||
}
|
}
|
||||||
|
result.reset(w);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}();
|
||||||
|
const auto testerWidget = avoidWidgetCreation
|
||||||
|
? nullptr
|
||||||
|
: static_cast<QOpenGLWidget*>(tester.get());
|
||||||
|
const auto testerWindow = avoidWidgetCreation
|
||||||
|
? static_cast<QOpenGLWindow*>(tester.get())
|
||||||
|
: nullptr;
|
||||||
|
/*const auto testerQWindow = avoidWidgetCreation
|
||||||
|
? static_cast<QWindow*>(tester.get())
|
||||||
|
: testerWidget->window()->windowHandle();*/
|
||||||
CrashCheckFinish();
|
CrashCheckFinish();
|
||||||
|
|
||||||
const auto context = tester.context();
|
const auto context = avoidWidgetCreation ? testerWindow->context() : testerWidget->context();
|
||||||
if (!context
|
if (!context
|
||||||
|| !context->isValid()/*
|
|| !context->isValid()/*
|
||||||
// This check doesn't work for a widget with WA_NativeWindow.
|
// This check doesn't work for a widget with WA_NativeWindow.
|
||||||
|| !context->makeCurrent(tester.window()->windowHandle())*/) {
|
|| !context->makeCurrent(testerQWindow)*/) {
|
||||||
LOG_ONCE(("OpenGL: Could not create widget in a window."));
|
LOG_ONCE(("OpenGL: Could not create widget in a window."));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@ struct Capabilities {
|
||||||
bool transparency = false;
|
bool transparency = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] Capabilities CheckCapabilities(QWidget *widget = nullptr);
|
[[nodiscard]] Capabilities CheckCapabilities(
|
||||||
|
QWidget *widget = nullptr,
|
||||||
|
bool avoidWidgetCreation = false);
|
||||||
[[nodiscard]] Backend ChooseBackendDefault(Capabilities capabilities);
|
[[nodiscard]] Backend ChooseBackendDefault(Capabilities capabilities);
|
||||||
|
|
||||||
void ForceDisable(bool disable);
|
void ForceDisable(bool disable);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue