From 6cfd00e42da7e3c0c8b68f2f9ed35dacec38b048 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:58:38 -0700 Subject: [PATCH] qt: Partially fix Wayland support. (#7054) * qt: Partially fix Wayland on NVIDIA. * qt: Fix Vulkan under Wayland. Showing and hiding the window here messes up the surface, causing an instant crash on load. * qt: Properly set up GLES context when requested. --- src/citra_qt/bootmanager.cpp | 43 ++++++++++++++++++++++++++++++------ src/citra_qt/main.cpp | 4 ---- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index c1c4ac753..e708620c5 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -2,8 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include - #include #include #include @@ -29,6 +27,8 @@ #include "video_core/video_core.h" #ifdef HAS_OPENGL +#include + #include #include #endif @@ -144,7 +144,13 @@ public: explicit OpenGLSharedContext() { QSurfaceFormat format; - format.setVersion(4, 3); + if (Settings::values.use_gles) { + format.setRenderableType(QSurfaceFormat::RenderableType::OpenGLES); + format.setVersion(3, 2); + } else { + format.setRenderableType(QSurfaceFormat::RenderableType::OpenGL); + format.setVersion(4, 3); + } format.setProfile(QSurfaceFormat::CoreProfile); if (Settings::values.renderer_debug) { @@ -364,7 +370,8 @@ static Frontend::WindowSystemType GetWindowSystemType() { return Frontend::WindowSystemType::Windows; else if (platform_name == QStringLiteral("xcb")) return Frontend::WindowSystemType::X11; - else if (platform_name == QStringLiteral("wayland")) + else if (platform_name == QStringLiteral("wayland") || + platform_name == QStringLiteral("wayland-egl")) return Frontend::WindowSystemType::Wayland; else if (platform_name == QStringLiteral("cocoa") || platform_name == QStringLiteral("ios")) return Frontend::WindowSystemType::MacOS; @@ -413,7 +420,8 @@ GRenderWindow::GRenderWindow(QWidget* parent_, EmuThread* emu_thread_, Core::Sys setLayout(layout); this->setMouseTracking(true); - strict_context_required = QGuiApplication::platformName() == QStringLiteral("wayland"); + strict_context_required = QGuiApplication::platformName() == QStringLiteral("wayland") || + QGuiApplication::platformName() == QStringLiteral("wayland-egl"); GMainWindow* parent = GetMainWindow(); connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete); @@ -721,10 +729,19 @@ void GRenderWindow::InitializeSoftware() { main_context = std::make_unique(); } +#ifdef HAS_OPENGL +static void* GetProcAddressGL(const char* name) { + return reinterpret_cast(QOpenGLContext::currentContext()->getProcAddress(name)); +} +#endif + bool GRenderWindow::LoadOpenGL() { +#ifdef HAS_OPENGL auto context = CreateSharedContext(); auto scope = context->Acquire(); - if (!gladLoadGL()) { + + auto gl_load_func = Settings::values.use_gles ? gladLoadGLES2Loader : gladLoadGLLoader; + if (!gl_load_func(GetProcAddressGL)) { QMessageBox::warning( this, tr("Error while initializing OpenGL!"), tr("Your GPU may not support OpenGL, or you do not have the latest graphics driver.")); @@ -734,16 +751,28 @@ bool GRenderWindow::LoadOpenGL() { const QString renderer = QString::fromUtf8(reinterpret_cast(glGetString(GL_RENDERER))); - if (!GLAD_GL_VERSION_4_3) { + if (!Settings::values.use_gles && !GLAD_GL_VERSION_4_3) { LOG_ERROR(Frontend, "GPU does not support OpenGL 4.3: {}", renderer.toStdString()); QMessageBox::warning(this, tr("Error while initializing OpenGL 4.3!"), tr("Your GPU may not support OpenGL 4.3, or you do not have the " "latest graphics driver.

GL Renderer:
%1") .arg(renderer)); return false; + } else if (Settings::values.use_gles && !GLAD_GL_ES_VERSION_3_2) { + LOG_ERROR(Frontend, "GPU does not support OpenGL ES 3.2: {}", renderer.toStdString()); + QMessageBox::warning(this, tr("Error while initializing OpenGL ES 3.2!"), + tr("Your GPU may not support OpenGL ES 3.2, or you do not have the " + "latest graphics driver.

GL Renderer:
%1") + .arg(renderer)); + return false; } return true; +#else + QMessageBox::warning(this, tr("OpenGL not available!"), + tr("Citra has not been compiled with OpenGL support.")); + return false; +#endif } void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) { diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 65d88770b..6ef30d21d 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1270,10 +1270,6 @@ void GMainWindow::BootGame(const QString& filename) { setMouseTracking(true); } - // show and hide the render_window to create the context - render_window->show(); - render_window->hide(); - loading_screen->Prepare(system.GetAppLoader()); loading_screen->show();