From afff68cfc0731c441ececa83bf43c3d8bebe5c5a Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 11 Oct 2024 21:52:48 -0700 Subject: [PATCH] Qt: Show a dummy shader settings tab if shaders aren't supported --- CHANGES | 1 + src/platform/qt/SettingsView.cpp | 36 +++++++++++++++++++------------- src/platform/qt/SettingsView.h | 4 ++-- src/platform/qt/Window.cpp | 8 ++++++- src/platform/qt/Window.h | 1 + 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index a3d67111c..d6fd60848 100644 --- a/CHANGES +++ b/CHANGES @@ -58,6 +58,7 @@ Misc: - Qt: Pass logging context through to video proxy thread (fixes mgba.io/i/3095) - Qt: Show maker code and game version in ROM info - Qt: Make window corners square on Windows 11 (fixes mgba.io/i/3285) + - Qt: Show a dummy shader settings tab if shaders aren't supported - Res: Port NSO-gba-colors shader (closes mgba.io/i/2834) - Scripting: Add `callbacks:oneshot` for single-call callbacks - Switch: Add bilinear filtering option (closes mgba.io/i/3111) diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 66c125466..c86dcf06e 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -397,29 +397,38 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC shortcutView->setController(shortcutController); shortcutView->setInputController(inputController); addPage(tr("Shortcuts"), shortcutView, Page::SHORTCUTS); + +#if defined(BUILD_GLES2) || defined(USE_EPOXY) + m_dummyShader = new QLabel(tr("Shaders are not supported when the display driver is not OpenGL.\n\n" + "If it is set to OpenGL and you still see this, your graphics card or drivers may be too old.")); + m_dummyShader->setWordWrap(true); + m_dummyShader->setAlignment(Qt::AlignCenter); + addPage(tr("Shaders"), m_dummyShader, Page::SHADERS); +#endif } SettingsView::~SettingsView() { -#if defined(BUILD_GL) || defined(BUILD_GLES2) - setShaderSelector(nullptr); +#if defined(BUILD_GLES2) || defined(USE_EPOXY) + if (m_shader) { + m_shader->setParent(nullptr); + } #endif } void SettingsView::setShaderSelector(ShaderSelector* shaderSelector) { -#if defined(BUILD_GL) || defined(BUILD_GLES2) - if (m_shader) { - auto items = m_ui.tabs->findItems(tr("Shaders"), Qt::MatchFixedString); - for (const auto& item : items) { - m_ui.tabs->removeItemWidget(item); - } - m_ui.stackedWidget->removeWidget(m_shader); - m_shader->setParent(nullptr); +#if defined(BUILD_GLES2) || defined(USE_EPOXY) + auto items = m_ui.tabs->findItems(tr("Shaders"), Qt::MatchFixedString); + for (QListWidgetItem* item : items) { + delete item; + } + if (!m_shader) { + m_ui.stackedWidget->removeWidget(m_dummyShader); } m_shader = shaderSelector; if (shaderSelector) { - m_ui.stackedWidget->addWidget(m_shader); - m_ui.tabs->addItem(tr("Shaders")); - connect(m_ui.buttonBox, &QDialogButtonBox::accepted, m_shader, &ShaderSelector::saved); + addPage(tr("Shaders"), m_shader, Page::SHADERS); + } else { + addPage(tr("Shaders"), m_dummyShader, Page::SHADERS); } #endif } @@ -579,7 +588,6 @@ void SettingsView::updateConfig() { if (displayDriver != m_controller->getQtOption("displayDriver")) { m_controller->setQtOption("displayDriver", displayDriver); Display::setDriver(static_cast(displayDriver.toInt())); - setShaderSelector(nullptr); emit displayDriverChanged(); } diff --git a/src/platform/qt/SettingsView.h b/src/platform/qt/SettingsView.h index 010b4ef0d..85cf35a99 100644 --- a/src/platform/qt/SettingsView.h +++ b/src/platform/qt/SettingsView.h @@ -51,8 +51,6 @@ public: SettingsView(ConfigController* controller, InputController* inputController, ShortcutController* shortcutController, LogController* logController, QWidget* parent = nullptr); ~SettingsView(); - void setShaderSelector(ShaderSelector* shaderSelector); - signals: void biosLoaded(int platform, const QString&); void audioDriverChanged(); @@ -66,6 +64,7 @@ signals: public slots: void selectPage(Page); + void setShaderSelector(ShaderSelector* shaderSelector); private slots: void selectBios(QLineEdit*); @@ -81,6 +80,7 @@ private: ConfigController* m_controller; InputController* m_input; ShaderSelector* m_shader = nullptr; + QLabel* m_dummyShader; LogConfigModel m_logModel; QTimer m_checkTimer; diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 77c7695fb..ddf34f4f9 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -550,6 +550,7 @@ void Window::openSettingsWindow(SettingsView::Page page) { #ifdef USE_SQLITE3 connect(settingsWindow, &SettingsView::libraryCleared, m_libraryView, &LibraryController::clear); #endif + connect(this, &Window::shaderSelectorAdded, settingsWindow, &SettingsView::setShaderSelector); openView(settingsWindow); settingsWindow->selectPage(page); } @@ -1050,7 +1051,12 @@ void Window::reloadDisplayDriver() { } #if defined(BUILD_GL) || defined(BUILD_GLES2) m_shaderView.reset(); - m_shaderView = std::make_unique(m_display.get(), m_config); + if (m_display->supportsShaders()) { + m_shaderView = std::make_unique(m_display.get(), m_config); + emit shaderSelectorAdded(m_shaderView.get()); + } else { + emit shaderSelectorAdded(nullptr); + } #endif connect(m_display.get(), &QGBA::Display::hideCursor, [this]() { diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index f91e3ff30..cb467f89d 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -73,6 +73,7 @@ signals: void startDrawing(); void shutdown(); void paused(bool); + void shaderSelectorAdded(ShaderSelector*); public slots: void setController(CoreController* controller, const QString& fname);