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/QFile>
|
||||
#include <QtGui/QtEvents>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtGui/QOpenGLContext>
|
||||
#include <QtGui/QOpenGLFunctions>
|
||||
#include <QOpenGLWindow>
|
||||
#include <QOpenGLWidget>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
|
@ -56,7 +58,7 @@ void CrashCheckStart() {
|
|||
|
||||
const char kOptionAllowLinuxNvidiaOpenGL[] = "allow-linux-nvidia-opengl";
|
||||
|
||||
Capabilities CheckCapabilities(QWidget *widget) {
|
||||
Capabilities CheckCapabilities(QWidget *widget, bool avoidWidgetCreation) {
|
||||
if (ForceDisabled) {
|
||||
LOG_ONCE(("OpenGL: Force-disabled."));
|
||||
return {};
|
||||
|
|
@ -88,19 +90,43 @@ Capabilities CheckCapabilities(QWidget *widget) {
|
|||
}
|
||||
|
||||
CrashCheckStart();
|
||||
auto tester = QOpenGLWidget(widget);
|
||||
tester.setFormat(format);
|
||||
tester.grabFramebuffer(); // Force initialize().
|
||||
if (!tester.window()->windowHandle()) {
|
||||
tester.window()->createWinId();
|
||||
const auto tester = [&] {
|
||||
std::unique_ptr<QObject> result;
|
||||
if (avoidWidgetCreation) {
|
||||
const auto w = new QOpenGLWindow();
|
||||
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();
|
||||
|
||||
const auto context = tester.context();
|
||||
const auto context = avoidWidgetCreation ? testerWindow->context() : testerWidget->context();
|
||||
if (!context
|
||||
|| !context->isValid()/*
|
||||
// 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."));
|
||||
return {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ struct Capabilities {
|
|||
bool transparency = false;
|
||||
};
|
||||
|
||||
[[nodiscard]] Capabilities CheckCapabilities(QWidget *widget = nullptr);
|
||||
[[nodiscard]] Capabilities CheckCapabilities(
|
||||
QWidget *widget = nullptr,
|
||||
bool avoidWidgetCreation = false);
|
||||
[[nodiscard]] Backend ChooseBackendDefault(Capabilities capabilities);
|
||||
|
||||
void ForceDisable(bool disable);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue