mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-16 10:49:47 -06:00
Move getsupportedRenderers function to SupportedRenderers class
This commit is contained in:
@ -31,6 +31,7 @@ set(SOURCES_QT_SDL
|
|||||||
ROMInfoDialog.cpp
|
ROMInfoDialog.cpp
|
||||||
RAMInfoDialog.cpp
|
RAMInfoDialog.cpp
|
||||||
TitleManagerDialog.cpp
|
TitleManagerDialog.cpp
|
||||||
|
SupportedRenderers.cpp
|
||||||
OSD_shaders.h
|
OSD_shaders.h
|
||||||
font.h
|
font.h
|
||||||
Platform.cpp
|
Platform.cpp
|
||||||
|
63
src/frontend/qt_sdl/SupportedRenderers.cpp
Normal file
63
src/frontend/qt_sdl/SupportedRenderers.cpp
Normal file
@ -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> windowInfo = glPanel->getWindowInfo();
|
||||||
|
|
||||||
|
if (windowInfo.has_value())
|
||||||
|
{
|
||||||
|
std::array<GL::Context::Version, 2> versionsToTry = {
|
||||||
|
GL::Context::Version{GL::Context::Profile::Core, 4, 3},
|
||||||
|
GL::Context::Version{GL::Context::Profile::Core, 3, 2}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<GL::Context> glContext = GL::Context::Create(*windowInfo, versionsToTry);
|
||||||
|
|
||||||
|
if (glContext)
|
||||||
|
{
|
||||||
|
const char* glVersionStr = reinterpret_cast<const char*>(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;
|
||||||
|
}
|
52
src/frontend/qt_sdl/SupportedRenderers.h
Normal file
52
src/frontend/qt_sdl/SupportedRenderers.h
Normal file
@ -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 <QApplication>
|
||||||
|
|
||||||
|
#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
|
@ -24,6 +24,7 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "GPU.h"
|
#include "GPU.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "SupportedRenderers.h"
|
||||||
|
|
||||||
#include "VideoSettingsDialog.h"
|
#include "VideoSettingsDialog.h"
|
||||||
#include "ui_VideoSettingsDialog.h"
|
#include "ui_VideoSettingsDialog.h"
|
||||||
@ -39,6 +40,9 @@ VideoSettingsDialog* VideoSettingsDialog::currentDlg = nullptr;
|
|||||||
|
|
||||||
void VideoSettingsDialog::setEnabled()
|
void VideoSettingsDialog::setEnabled()
|
||||||
{
|
{
|
||||||
|
bool baseGl = SupportedRenderers::instance->baseGl;
|
||||||
|
bool computeGl = SupportedRenderers::instance->computeGl;
|
||||||
|
|
||||||
auto& cfg = emuInstance->getGlobalConfig();
|
auto& cfg = emuInstance->getGlobalConfig();
|
||||||
int renderer = cfg.GetInt("3D.Renderer");
|
int renderer = cfg.GetInt("3D.Renderer");
|
||||||
int oglDisplay = cfg.GetBool("Screen.UseGL");
|
int oglDisplay = cfg.GetBool("Screen.UseGL");
|
||||||
@ -75,59 +79,12 @@ void VideoSettingsDialog::setEnabled()
|
|||||||
ui->cbxComputeHiResCoords->setEnabled(renderer == renderer3D_OpenGLCompute);
|
ui->cbxComputeHiResCoords->setEnabled(renderer == renderer3D_OpenGLCompute);
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoSettingsDialog::getsupportedRenderers()
|
|
||||||
{
|
|
||||||
ScreenPanelGL *glPanel = new ScreenPanelGL(this);
|
|
||||||
std::optional<WindowInfo> windowInfo = glPanel->getWindowInfo();
|
|
||||||
|
|
||||||
int renderer = renderer3D_Software;
|
|
||||||
|
|
||||||
if (windowInfo.has_value())
|
|
||||||
{
|
|
||||||
std::array<GL::Context::Version, 2> versionsToTry = {
|
|
||||||
GL::Context::Version{GL::Context::Profile::Core, 4, 3},
|
|
||||||
GL::Context::Version{GL::Context::Profile::Core, 3, 2}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unique_ptr<GL::Context> glContext = GL::Context::Create(*windowInfo, versionsToTry);
|
|
||||||
|
|
||||||
if (glContext)
|
|
||||||
{
|
|
||||||
const char* glVersionStr = reinterpret_cast<const char*>(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)
|
VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
emuInstance = ((MainWindow*)parent)->getEmuInstance();
|
emuInstance = ((MainWindow*)parent)->getEmuInstance();
|
||||||
int supportedRenderers = getsupportedRenderers();
|
|
||||||
|
|
||||||
baseGl = supportedRenderers > renderer3D_Software;
|
|
||||||
computeGl = supportedRenderers == renderer3D_OpenGLCompute;
|
|
||||||
|
|
||||||
auto& cfg = emuInstance->getGlobalConfig();
|
auto& cfg = emuInstance->getGlobalConfig();
|
||||||
oldRenderer = cfg.GetInt("3D.Renderer");
|
oldRenderer = cfg.GetInt("3D.Renderer");
|
||||||
|
@ -78,8 +78,6 @@ private:
|
|||||||
|
|
||||||
Ui::VideoSettingsDialog* ui;
|
Ui::VideoSettingsDialog* ui;
|
||||||
EmuInstance* emuInstance;
|
EmuInstance* emuInstance;
|
||||||
bool baseGl;
|
|
||||||
bool computeGl;
|
|
||||||
|
|
||||||
QButtonGroup* grp3DRenderer;
|
QButtonGroup* grp3DRenderer;
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@
|
|||||||
#include "CameraManager.h"
|
#include "CameraManager.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "AboutDialog.h"
|
#include "AboutDialog.h"
|
||||||
|
#include "SupportedRenderers.h"
|
||||||
|
|
||||||
using namespace melonDS;
|
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
|
// if the window was closed in fullscreen do not restore this
|
||||||
setWindowState(windowState() & ~Qt::WindowFullScreen);
|
setWindowState(windowState() & ~Qt::WindowFullScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id == 0 && SupportedRenderers::instance == nullptr)
|
||||||
|
SupportedRenderers* renderers = new SupportedRenderers(this);
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
|
||||||
panel = nullptr;
|
panel = nullptr;
|
||||||
|
Reference in New Issue
Block a user