From 54902989a1806ce0921caa92ff22f773e55fafbc Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 03:01:43 +0100 Subject: [PATCH 01/13] Check if required renderer is available before disabling options --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 66 ++++++++++++++++++++- src/frontend/qt_sdl/VideoSettingsDialog.h | 1 + 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 619ecda3..4efb5adf 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -41,15 +41,79 @@ void VideoSettingsDialog::setEnabled() { auto& cfg = emuInstance->getGlobalConfig(); int renderer = cfg.GetInt("3D.Renderer"); + int ogldisplay = cfg.GetBool("Screen.UseGL"); + + int supportedRenderer = getsupportedRenderers(); + + bool base_gl = supportedRenderer > renderer3D_Software; + bool compute_gl = supportedRenderer == renderer3D_OpenGLCompute; + + if (!compute_gl) + { + ui->rb3DCompute->setEnabled(false); + if (renderer == renderer3D_OpenGLCompute) // fallback to software renderer + ui->rb3DSoftware->setChecked(true); + } + + if (!base_gl) + { + renderer = renderer3D_Software; + ogldisplay = false; + + ui->rb3DOpenGL->setEnabled(false); + if (renderer == renderer3D_OpenGL) // fallback to software renderer + ui->rb3DSoftware->setChecked(true); + } bool softwareRenderer = renderer == renderer3D_Software; - ui->cbGLDisplay->setEnabled(softwareRenderer); + ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl); ui->cbSoftwareThreaded->setEnabled(softwareRenderer); ui->cbxGLResolution->setEnabled(!softwareRenderer); ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL); ui->cbxComputeHiResCoords->setEnabled(renderer == renderer3D_OpenGLCompute); } +int VideoSettingsDialog::getsupportedRenderers() +{ + ScreenPanelGL *glpanel = new ScreenPanelGL(this); + std::optional windowinfo = glpanel->getWindowInfo(); + + int renderer = renderer3D_Software; + + if (windowinfo.has_value()) + { + std::array versionsToTry = { + GL::Context::Version{GL::Context::Profile::Core, 4, 3}, + GL::Context::Version{GL::Context::Profile::Core, 3, 2} + }; + + std::unique_ptr glContext = GL::Context::Create(*windowinfo, versionsToTry); + + if (glContext) + { + const char* gl_version_str = reinterpret_cast(glGetString(GL_VERSION)); + + if (gl_version_str) + { + int gl_version = 0; + + if (isdigit(gl_version_str[0]) && isdigit(gl_version_str[2])) + gl_version = (gl_version_str[0] - '0') * 100 + + (gl_version_str[2] - '0') * 10; + + if (gl_version >= 430) + renderer = renderer3D_OpenGLCompute; + else if (gl_version >= 320) + renderer = renderer3D_OpenGL; + } + } + } + + delete glpanel; + + return renderer; +} + VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog) { ui->setupUi(this); diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index e7ba5cc7..dad58dd2 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -74,6 +74,7 @@ private slots: private: void setVsyncControlEnable(bool hasOGL); void setEnabled(); + int getsupportedRenderers(); Ui::VideoSettingsDialog* ui; EmuInstance* emuInstance; From bdcb7f6d26fe394ca0459f533dd42d982b951079 Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 03:02:24 +0100 Subject: [PATCH 02/13] Fix Vsync never being editable (from master) --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 4efb5adf..34777d0e 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -67,6 +67,7 @@ void VideoSettingsDialog::setEnabled() bool softwareRenderer = renderer == renderer3D_Software; ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl); + ui->cbVSync->setEnabled(!softwareRenderer || (softwareRenderer && ogldisplay)); ui->cbSoftwareThreaded->setEnabled(softwareRenderer); ui->cbxGLResolution->setEnabled(!softwareRenderer); ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL); From 7b516d639681c5e1c9b291f865e09747b086c784 Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 03:19:44 +0100 Subject: [PATCH 03/13] Add some comments in VideoSettingsDialog --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 34777d0e..73413ceb 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -43,6 +43,7 @@ void VideoSettingsDialog::setEnabled() int renderer = cfg.GetInt("3D.Renderer"); int ogldisplay = cfg.GetBool("Screen.UseGL"); + // We will need it to disable specific options where unsupported int supportedRenderer = getsupportedRenderers(); bool base_gl = supportedRenderer > renderer3D_Software; @@ -67,7 +68,7 @@ void VideoSettingsDialog::setEnabled() bool softwareRenderer = renderer == renderer3D_Software; ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl); - ui->cbVSync->setEnabled(!softwareRenderer || (softwareRenderer && ogldisplay)); + ui->cbVSync->setEnabled(!softwareRenderer || (softwareRenderer && ogldisplay)); // Either an openGL renderer is used or OpenGL Display is enabled ui->cbSoftwareThreaded->setEnabled(softwareRenderer); ui->cbxGLResolution->setEnabled(!softwareRenderer); ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL); @@ -98,10 +99,12 @@ int VideoSettingsDialog::getsupportedRenderers() { int gl_version = 0; + // A proper version string or object isn't provided, so we have to parse it ourselves if (isdigit(gl_version_str[0]) && isdigit(gl_version_str[2])) gl_version = (gl_version_str[0] - '0') * 100 + (gl_version_str[2] - '0') * 10; + // OpenGL 4.3 is required for Compute Shaders while 3.2 is the base requirement if (gl_version >= 430) renderer = renderer3D_OpenGLCompute; else if (gl_version >= 320) From 61afc57ff2aa062ae61b0cb9c5839da95463a2ba Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 04:35:28 +0100 Subject: [PATCH 04/13] use setVsyncControlEnable instead for toggling vsync settings --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 73413ceb..9252cc4d 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -68,7 +68,7 @@ void VideoSettingsDialog::setEnabled() bool softwareRenderer = renderer == renderer3D_Software; ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl); - ui->cbVSync->setEnabled(!softwareRenderer || (softwareRenderer && ogldisplay)); // Either an openGL renderer is used or OpenGL Display is enabled + setVsyncControlEnable(UsesGL()); ui->cbSoftwareThreaded->setEnabled(softwareRenderer); ui->cbxGLResolution->setEnabled(!softwareRenderer); ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL); From 94a2bce37cd42ef30d5ac3f69724cc8c2d2ccd76 Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 05:03:57 +0100 Subject: [PATCH 05/13] Cache supported renderers --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 10 ++++------ src/frontend/qt_sdl/VideoSettingsDialog.h | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 9252cc4d..aea733a1 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -43,12 +43,6 @@ void VideoSettingsDialog::setEnabled() int renderer = cfg.GetInt("3D.Renderer"); int ogldisplay = cfg.GetBool("Screen.UseGL"); - // We will need it to disable specific options where unsupported - int supportedRenderer = getsupportedRenderers(); - - bool base_gl = supportedRenderer > renderer3D_Software; - bool compute_gl = supportedRenderer == renderer3D_OpenGLCompute; - if (!compute_gl) { ui->rb3DCompute->setEnabled(false); @@ -124,6 +118,10 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( setAttribute(Qt::WA_DeleteOnClose); emuInstance = ((MainWindow*)parent)->getEmuInstance(); + int supportedRenderers = getsupportedRenderers(); + + base_gl = supportedRenderers > renderer3D_Software; + compute_gl = supportedRenderers == renderer3D_OpenGLCompute; auto& cfg = emuInstance->getGlobalConfig(); oldRenderer = cfg.GetInt("3D.Renderer"); diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index dad58dd2..a47d0a55 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -78,6 +78,8 @@ private: Ui::VideoSettingsDialog* ui; EmuInstance* emuInstance; + bool base_gl; + bool compute_gl; QButtonGroup* grp3DRenderer; From 04357bddc8761c7b36f377f53c27500be954d03f Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 05:07:45 +0100 Subject: [PATCH 06/13] Add missing fallback to software renderer for the Compute shader renderer --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index aea733a1..6c4a9d6c 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -47,7 +47,10 @@ void VideoSettingsDialog::setEnabled() { ui->rb3DCompute->setEnabled(false); if (renderer == renderer3D_OpenGLCompute) // fallback to software renderer + { ui->rb3DSoftware->setChecked(true); + renderer = renderer3D_Software; + } } if (!base_gl) From 7fa6f73b0cc72f9220af0b01e3e386a5bd975993 Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 05:08:44 +0100 Subject: [PATCH 07/13] Set settings in cfg for use in setVsyncControlEnable --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 6c4a9d6c..65164976 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -53,17 +53,20 @@ void VideoSettingsDialog::setEnabled() } } - if (!base_gl) + if (!base_gl) // fallback to software renderer { renderer = renderer3D_Software; ogldisplay = false; ui->rb3DOpenGL->setEnabled(false); - if (renderer == renderer3D_OpenGL) // fallback to software renderer + if (renderer == renderer3D_OpenGL) ui->rb3DSoftware->setChecked(true); } + cfg.SetInt("3D.Renderer", renderer); + cfg.SetBool("Screen.UseGL", ogldisplay); bool softwareRenderer = renderer == renderer3D_Software; + ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl); setVsyncControlEnable(UsesGL()); ui->cbSoftwareThreaded->setEnabled(softwareRenderer); From f0986fd32da9966aea4caf9a493ed9cb14e46844 Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 18:58:42 +0100 Subject: [PATCH 08/13] Remove redundant check when base requirements aren't met --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 65164976..cb89d518 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -59,8 +59,7 @@ void VideoSettingsDialog::setEnabled() ogldisplay = false; ui->rb3DOpenGL->setEnabled(false); - if (renderer == renderer3D_OpenGL) - ui->rb3DSoftware->setChecked(true); + ui->rb3DSoftware->setChecked(true); } cfg.SetInt("3D.Renderer", renderer); From 4f6679b821cc62e3cea37503b8b82792de05bbad Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 19:05:15 +0100 Subject: [PATCH 09/13] Use cached variables instead of re-fetching from settings --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index cb89d518..80fc1ed5 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -67,7 +67,7 @@ void VideoSettingsDialog::setEnabled() bool softwareRenderer = renderer == renderer3D_Software; ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl); - setVsyncControlEnable(UsesGL()); + setVsyncControlEnable(ogldisplay || !softwareRenderer); ui->cbSoftwareThreaded->setEnabled(softwareRenderer); ui->cbxGLResolution->setEnabled(!softwareRenderer); ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL); From d34aed7ccd68740403de9383d099adeb6390e09e Mon Sep 17 00:00:00 2001 From: Gess1t Date: Mon, 28 Oct 2024 19:23:43 +0100 Subject: [PATCH 10/13] Uncheck OpenGL display when requirements aren't met Also disable the vsync interval label to match other part of the UX --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 80fc1ed5..88ec017e 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -59,6 +59,7 @@ void VideoSettingsDialog::setEnabled() ogldisplay = false; ui->rb3DOpenGL->setEnabled(false); + ui->cbGLDisplay->setChecked(false); ui->rb3DSoftware->setChecked(true); } @@ -217,6 +218,7 @@ void VideoSettingsDialog::on_VideoSettingsDialog_rejected() void VideoSettingsDialog::setVsyncControlEnable(bool hasOGL) { + ui->label_2->setEnabled(hasOGL); ui->cbVSync->setEnabled(hasOGL); ui->sbVSyncInterval->setEnabled(hasOGL); } From 4677d9f7eab7228ee8466e90b4040f5658956681 Mon Sep 17 00:00:00 2001 From: Gess1t Date: Wed, 30 Oct 2024 23:18:14 +0100 Subject: [PATCH 11/13] Change casing to comply with review --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 38 ++++++++++----------- src/frontend/qt_sdl/VideoSettingsDialog.h | 4 +-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 88ec017e..81d1af74 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -41,9 +41,9 @@ void VideoSettingsDialog::setEnabled() { auto& cfg = emuInstance->getGlobalConfig(); int renderer = cfg.GetInt("3D.Renderer"); - int ogldisplay = cfg.GetBool("Screen.UseGL"); + int oglDisplay = cfg.GetBool("Screen.UseGL"); - if (!compute_gl) + if (!computeGl) { ui->rb3DCompute->setEnabled(false); if (renderer == renderer3D_OpenGLCompute) // fallback to software renderer @@ -53,10 +53,10 @@ void VideoSettingsDialog::setEnabled() } } - if (!base_gl) // fallback to software renderer + if (!baseGl) // fallback to software renderer { renderer = renderer3D_Software; - ogldisplay = false; + oglDisplay = false; ui->rb3DOpenGL->setEnabled(false); ui->cbGLDisplay->setChecked(false); @@ -64,11 +64,11 @@ void VideoSettingsDialog::setEnabled() } cfg.SetInt("3D.Renderer", renderer); - cfg.SetBool("Screen.UseGL", ogldisplay); + cfg.SetBool("Screen.UseGL", oglDisplay); bool softwareRenderer = renderer == renderer3D_Software; - ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl); - setVsyncControlEnable(ogldisplay || !softwareRenderer); + ui->cbGLDisplay->setEnabled(softwareRenderer && baseGl); + setVsyncControlEnable(oglDisplay || !softwareRenderer); ui->cbSoftwareThreaded->setEnabled(softwareRenderer); ui->cbxGLResolution->setEnabled(!softwareRenderer); ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL); @@ -77,32 +77,32 @@ void VideoSettingsDialog::setEnabled() int VideoSettingsDialog::getsupportedRenderers() { - ScreenPanelGL *glpanel = new ScreenPanelGL(this); - std::optional windowinfo = glpanel->getWindowInfo(); + ScreenPanelGL *glPanel = new ScreenPanelGL(this); + std::optional windowInfo = glPanel->getWindowInfo(); int renderer = renderer3D_Software; - if (windowinfo.has_value()) + if (windowInfo.has_value()) { std::array versionsToTry = { GL::Context::Version{GL::Context::Profile::Core, 4, 3}, GL::Context::Version{GL::Context::Profile::Core, 3, 2} }; - std::unique_ptr glContext = GL::Context::Create(*windowinfo, versionsToTry); + std::unique_ptr glContext = GL::Context::Create(*windowInfo, versionsToTry); if (glContext) { - const char* gl_version_str = reinterpret_cast(glGetString(GL_VERSION)); + const char* glVersionStr = reinterpret_cast(glGetString(GL_VERSION)); - if (gl_version_str) + if (glVersionStr) { int gl_version = 0; // A proper version string or object isn't provided, so we have to parse it ourselves - if (isdigit(gl_version_str[0]) && isdigit(gl_version_str[2])) - gl_version = (gl_version_str[0] - '0') * 100 + - (gl_version_str[2] - '0') * 10; + if (isdigit(glVersionStr[0]) && isdigit(glVersionStr[2])) + gl_version = (glVersionStr[0] - '0') * 100 + + (glVersionStr[2] - '0') * 10; // OpenGL 4.3 is required for Compute Shaders while 3.2 is the base requirement if (gl_version >= 430) @@ -113,7 +113,7 @@ int VideoSettingsDialog::getsupportedRenderers() } } - delete glpanel; + delete glPanel; return renderer; } @@ -126,8 +126,8 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( emuInstance = ((MainWindow*)parent)->getEmuInstance(); int supportedRenderers = getsupportedRenderers(); - base_gl = supportedRenderers > renderer3D_Software; - compute_gl = supportedRenderers == renderer3D_OpenGLCompute; + baseGl = supportedRenderers > renderer3D_Software; + computeGl = supportedRenderers == renderer3D_OpenGLCompute; auto& cfg = emuInstance->getGlobalConfig(); oldRenderer = cfg.GetInt("3D.Renderer"); diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index a47d0a55..18223b0e 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -78,8 +78,8 @@ private: Ui::VideoSettingsDialog* ui; EmuInstance* emuInstance; - bool base_gl; - bool compute_gl; + bool baseGl; + bool computeGl; QButtonGroup* grp3DRenderer; From 4b234bd161d2dfd691758b0a2bed0a3fb85359fc Mon Sep 17 00:00:00 2001 From: Gess1t Date: Wed, 30 Oct 2024 23:18:30 +0100 Subject: [PATCH 12/13] Check length on glVersionStr --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 81d1af74..b161b404 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -95,7 +95,7 @@ int VideoSettingsDialog::getsupportedRenderers() { const char* glVersionStr = reinterpret_cast(glGetString(GL_VERSION)); - if (glVersionStr) + if (glVersionStr && strlen(glVersionStr) >= 3) { int gl_version = 0; From 58b456b9b708e204aad234ee43de2affc413562e Mon Sep 17 00:00:00 2001 From: Gess1t Date: Fri, 1 Nov 2024 03:10:54 +0100 Subject: [PATCH 13/13] Move getsupportedRenderers function to SupportedRenderers class --- src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/SupportedRenderers.cpp | 63 +++++++++++++++++++++ src/frontend/qt_sdl/SupportedRenderers.h | 52 +++++++++++++++++ src/frontend/qt_sdl/VideoSettingsDialog.cpp | 51 ++--------------- src/frontend/qt_sdl/VideoSettingsDialog.h | 2 - src/frontend/qt_sdl/Window.cpp | 5 ++ 6 files changed, 125 insertions(+), 49 deletions(-) create mode 100644 src/frontend/qt_sdl/SupportedRenderers.cpp create mode 100644 src/frontend/qt_sdl/SupportedRenderers.h diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 56f82d89..4f25f7ef 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -31,6 +31,7 @@ set(SOURCES_QT_SDL ROMInfoDialog.cpp RAMInfoDialog.cpp TitleManagerDialog.cpp + SupportedRenderers.cpp OSD_shaders.h font.h Platform.cpp diff --git a/src/frontend/qt_sdl/SupportedRenderers.cpp b/src/frontend/qt_sdl/SupportedRenderers.cpp new file mode 100644 index 00000000..3fb3e92c --- /dev/null +++ b/src/frontend/qt_sdl/SupportedRenderers.cpp @@ -0,0 +1,63 @@ +#include "types.h" +#include "Platform.h" +#include "Config.h" +#include "GPU.h" +#include "main.h" + +#include "SupportedRenderers.h" + +SupportedRenderers* SupportedRenderers::instance = nullptr; + +SupportedRenderers::SupportedRenderers(QWidget* parent) +{ + if (SupportedRenderers::instance == nullptr) + instance = this; + + software = true; + + // OpenGL + setSupportedOpenGLRenderers(parent); + + // Future renderers +} + +SupportedRenderers::~SupportedRenderers() {} + +void SupportedRenderers::setSupportedOpenGLRenderers(QWidget* parent) +{ + ScreenPanelGL *glPanel = new ScreenPanelGL(parent); + std::optional windowInfo = glPanel->getWindowInfo(); + + if (windowInfo.has_value()) + { + std::array versionsToTry = { + GL::Context::Version{GL::Context::Profile::Core, 4, 3}, + GL::Context::Version{GL::Context::Profile::Core, 3, 2} + }; + + std::unique_ptr glContext = GL::Context::Create(*windowInfo, versionsToTry); + + if (glContext) + { + const char* glVersionStr = reinterpret_cast(glGetString(GL_VERSION)); + + if (glVersionStr && strlen(glVersionStr) >= 3) + { + int gl_version = 0; + + // A proper version string or object isn't provided, so we have to parse it ourselves + if (isdigit(glVersionStr[0]) && isdigit(glVersionStr[2])) + gl_version = (glVersionStr[0] - '0') * 100 + + (glVersionStr[2] - '0') * 10; + + // OpenGL 4.3 is required for Compute Shaders while 3.2 is the base requirement + if (gl_version >= 430) + computeGl = true; + if (gl_version >= 320) + baseGl = true; + } + } + } + + delete glPanel; +} \ No newline at end of file diff --git a/src/frontend/qt_sdl/SupportedRenderers.h b/src/frontend/qt_sdl/SupportedRenderers.h new file mode 100644 index 00000000..3a14b840 --- /dev/null +++ b/src/frontend/qt_sdl/SupportedRenderers.h @@ -0,0 +1,52 @@ +/* + Copyright 2016-2024 melonDS team + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef SUPPORTEDRENDERERS_H +#define SUPPORTEDRENDERERS_H + +using namespace melonDS; + +#include "glad/glad.h" + +#include + +#include "EmuInstance.h" + + +class SupportedRenderers +{ +public: + explicit SupportedRenderers(QWidget* parent); + ~SupportedRenderers(); + + static SupportedRenderers* instance; + + // Software + bool software; + + // OpenGL + bool baseGl; + bool computeGl; + + // Future renderers + +private: + void setSupportedOpenGLRenderers(QWidget* parent); +}; + +#endif // SUPPORTEDRENDERERS_H diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index b161b404..bea6f009 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -24,6 +24,7 @@ #include "Config.h" #include "GPU.h" #include "main.h" +#include "SupportedRenderers.h" #include "VideoSettingsDialog.h" #include "ui_VideoSettingsDialog.h" @@ -39,6 +40,9 @@ VideoSettingsDialog* VideoSettingsDialog::currentDlg = nullptr; void VideoSettingsDialog::setEnabled() { + bool baseGl = SupportedRenderers::instance->baseGl; + bool computeGl = SupportedRenderers::instance->computeGl; + auto& cfg = emuInstance->getGlobalConfig(); int renderer = cfg.GetInt("3D.Renderer"); int oglDisplay = cfg.GetBool("Screen.UseGL"); @@ -75,59 +79,12 @@ void VideoSettingsDialog::setEnabled() ui->cbxComputeHiResCoords->setEnabled(renderer == renderer3D_OpenGLCompute); } -int VideoSettingsDialog::getsupportedRenderers() -{ - ScreenPanelGL *glPanel = new ScreenPanelGL(this); - std::optional windowInfo = glPanel->getWindowInfo(); - - int renderer = renderer3D_Software; - - if (windowInfo.has_value()) - { - std::array versionsToTry = { - GL::Context::Version{GL::Context::Profile::Core, 4, 3}, - GL::Context::Version{GL::Context::Profile::Core, 3, 2} - }; - - std::unique_ptr glContext = GL::Context::Create(*windowInfo, versionsToTry); - - if (glContext) - { - const char* glVersionStr = reinterpret_cast(glGetString(GL_VERSION)); - - if (glVersionStr && strlen(glVersionStr) >= 3) - { - int gl_version = 0; - - // A proper version string or object isn't provided, so we have to parse it ourselves - if (isdigit(glVersionStr[0]) && isdigit(glVersionStr[2])) - gl_version = (glVersionStr[0] - '0') * 100 + - (glVersionStr[2] - '0') * 10; - - // OpenGL 4.3 is required for Compute Shaders while 3.2 is the base requirement - if (gl_version >= 430) - renderer = renderer3D_OpenGLCompute; - else if (gl_version >= 320) - renderer = renderer3D_OpenGL; - } - } - } - - delete glPanel; - - return renderer; -} - VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); emuInstance = ((MainWindow*)parent)->getEmuInstance(); - int supportedRenderers = getsupportedRenderers(); - - baseGl = supportedRenderers > renderer3D_Software; - computeGl = supportedRenderers == renderer3D_OpenGLCompute; auto& cfg = emuInstance->getGlobalConfig(); oldRenderer = cfg.GetInt("3D.Renderer"); diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index 18223b0e..dad58dd2 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -78,8 +78,6 @@ private: Ui::VideoSettingsDialog* ui; EmuInstance* emuInstance; - bool baseGl; - bool computeGl; QButtonGroup* grp3DRenderer; diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 5c599e70..5416f4dd 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -83,6 +83,7 @@ #include "CameraManager.h" #include "Window.h" #include "AboutDialog.h" +#include "SupportedRenderers.h" using namespace melonDS; @@ -693,6 +694,10 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) : // if the window was closed in fullscreen do not restore this setWindowState(windowState() & ~Qt::WindowFullScreen); } + + if (id == 0 && SupportedRenderers::instance == nullptr) + SupportedRenderers* renderers = new SupportedRenderers(this); + show(); panel = nullptr;