port video settings shit

This commit is contained in:
Arisotura 2024-05-26 21:28:00 +02:00
parent de18f029a6
commit 5fb8836440
12 changed files with 183 additions and 165 deletions

View File

@ -37,17 +37,6 @@ namespace Config
{ {
using namespace melonDS; using namespace melonDS;
bool ScreenUseGL;
bool ScreenVSync;
int ScreenVSyncInterval;
int _3DRenderer;
bool Threaded3D;
int GL_ScaleFactor;
bool GL_BetterPolygons;
bool GL_HiresCoordinates;
const char* kConfigFile = "melonDS.toml"; const char* kConfigFile = "melonDS.toml";
@ -63,6 +52,7 @@ DefaultList<int> DefaultInts =
{"Instance*.Window*.Width", 256}, {"Instance*.Window*.Width", 256},
{"Instance*.Window*.Height", 384}, {"Instance*.Window*.Height", 384},
{"Screen.VSyncInterval", 1}, {"Screen.VSyncInterval", 1},
{"3D.Renderer", renderer3D_Software},
{"3D.GL.ScaleFactor", 1}, {"3D.GL.ScaleFactor", 1},
{"MaxFPS", 1000}, {"MaxFPS", 1000},
#ifdef JIT_ENABLED #ifdef JIT_ENABLED
@ -86,11 +76,7 @@ DefaultList<int> DefaultInts =
RangeList IntRanges = RangeList IntRanges =
{ {
{"Emu.ConsoleType", {0, 1}}, {"Emu.ConsoleType", {0, 1}},
#ifdef OGLRENDERER_ENABLED {"3D.Renderer", {0, renderer3D_Max-1}},
{"3D.Renderer", {0, 1}},
#else
{"3D.Renderer", {0, 0}},
#endif
{"Screen.VSyncInterval", {1, 20}}, {"Screen.VSyncInterval", {1, 20}},
{"3D.GL.ScaleFactor", {1, 16}}, {"3D.GL.ScaleFactor", {1, 16}},
{"Audio.Interpolation", {0, 3}}, {"Audio.Interpolation", {0, 3}},
@ -108,7 +94,8 @@ RangeList IntRanges =
DefaultList<bool> DefaultBools = DefaultList<bool> DefaultBools =
{ {
{"Screen.Filter", true}, {"Screen.Filter", true},
{"3D.Soft.Threaded3D", true}, {"3D.Soft.Threaded", true},
{"3D.GL.HiresCoordinates", true},
{"LimitFPS", true}, {"LimitFPS", true},
{"Window*.ShowOSD", true}, {"Window*.ShowOSD", true},
{"Emu.DirectBoot", true}, {"Emu.DirectBoot", true},
@ -205,10 +192,11 @@ LegacyEntry LegacyFile[] =
{"ScreenVSyncInterval", 0, "Screen.VSyncInterval", false}, {"ScreenVSyncInterval", 0, "Screen.VSyncInterval", false},
{"3DRenderer", 0, "3D.Renderer", false}, {"3DRenderer", 0, "3D.Renderer", false},
{"Threaded3D", 1, "3D.Soft.Threaded3D", false}, {"Threaded3D", 1, "3D.Soft.Threaded", false},
{"GL_ScaleFactor", 0, "3D.GL.ScaleFactor", false}, {"GL_ScaleFactor", 0, "3D.GL.ScaleFactor", false},
{"GL_BetterPolygons", 1, "3D.GL.BetterPolygons", false}, {"GL_BetterPolygons", 1, "3D.GL.BetterPolygons", false},
{"GL_HiresCoordinates", 1, "3D.GL.HiresCoordinates", false},
{"LimitFPS", 1, "LimitFPS", false}, {"LimitFPS", 1, "LimitFPS", false},
{"MaxFPS", 0, "MaxFPS", false}, {"MaxFPS", 0, "MaxFPS", false},

View File

@ -16,8 +16,8 @@
with melonDS. If not, see http://www.gnu.org/licenses/. with melonDS. If not, see http://www.gnu.org/licenses/.
*/ */
#ifndef PLATFORMCONFIG_H #ifndef CONFIG_H
#define PLATFORMCONFIG_H #define CONFIG_H
#include <variant> #include <variant>
#include <string> #include <string>
@ -131,18 +131,6 @@ private:
}; };
extern bool ScreenUseGL;
extern bool ScreenVSync;
extern int ScreenVSyncInterval;
extern int _3DRenderer;
extern bool Threaded3D;
extern int GL_ScaleFactor;
extern bool GL_BetterPolygons;
extern bool GL_HiresCoordinates;
bool Load(); bool Load();
void Save(); void Save();
@ -151,4 +139,4 @@ inline Table GetGlobalTable() { return GetLocalTable(-1); }
} }
#endif // PLATFORMCONFIG_H #endif // CONFIG_H

View File

@ -156,6 +156,64 @@ void EmuInstance::osdAddMessage(unsigned int color, const char* fmt, ...)
} }
bool EmuInstance::usesOpenGL()
{
return globalCfg.GetBool("Screen.UseGL") ||
(globalCfg.GetInt("3D.Renderer") != renderer3D_Software);
}
void EmuInstance::initOpenGL()
{
for (int i = 0; i < kMaxWindows; i++)
{
if (windowList[i])
windowList[i]->initOpenGL();
}
setVSyncGL(true);
}
void EmuInstance::deinitOpenGL()
{
for (int i = 0; i < kMaxWindows; i++)
{
if (windowList[i])
windowList[i]->deinitOpenGL();
}
}
void EmuInstance::setVSyncGL(bool vsync)
{
int intv;
vsync = vsync && globalCfg.GetBool("Screen.VSync");
if (vsync)
intv = globalCfg.GetInt("Screen.VSyncInterval");
else
intv = 0;
for (int i = 0; i < kMaxWindows; i++)
{
if (windowList[i])
windowList[i]->setGLSwapInterval(intv);
}
}
void EmuInstance::makeCurrentGL()
{
mainWindow->makeCurrentGL();
}
void EmuInstance::drawScreenGL()
{
for (int i = 0; i < kMaxWindows; i++)
{
if (windowList[i])
windowList[i]->drawScreenGL();
}
}
int EmuInstance::lastSep(const std::string& path) int EmuInstance::lastSep(const std::string& path)
{ {
int i = path.length() - 1; int i = path.length() - 1;

View File

@ -88,6 +88,13 @@ public:
void osdAddMessage(unsigned int color, const char* fmt, ...); void osdAddMessage(unsigned int color, const char* fmt, ...);
bool usesOpenGL();
void initOpenGL();
void deinitOpenGL();
void setVSyncGL(bool vsync);
void makeCurrentGL();
void drawScreenGL();
// return: empty string = setup OK, non-empty = error message // return: empty string = setup OK, non-empty = error message
QString verifySetup(); QString verifySetup();

View File

@ -66,9 +66,6 @@ using namespace melonDS;
// TEMP // TEMP
extern bool RunningSomething; extern bool RunningSomething;
//extern MainWindow* mainWindow; //extern MainWindow* mainWindow;
extern int autoScreenSizing;
extern int videoRenderer;
extern bool videoSettingsDirty;
EmuThread::EmuThread(EmuInstance* inst, QObject* parent) : QThread(parent) EmuThread::EmuThread(EmuInstance* inst, QObject* parent) : QThread(parent)
@ -83,10 +80,6 @@ EmuThread::EmuThread(EmuInstance* inst, QObject* parent) : QThread(parent)
void EmuThread::attachWindow(MainWindow* window) void EmuThread::attachWindow(MainWindow* window)
{ {
windowList.push_back(window);
window->attachEmuThread(this);
mainWindow = windowList.front();
connect(this, SIGNAL(windowUpdate()), window->panel, SLOT(repaint())); connect(this, SIGNAL(windowUpdate()), window->panel, SLOT(repaint()));
connect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString))); connect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString)));
connect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart())); connect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart()));
@ -115,14 +108,11 @@ void EmuThread::detachWindow(MainWindow* window)
disconnect(this, SIGNAL(windowFullscreenToggle()), window, SLOT(onFullscreenToggled())); disconnect(this, SIGNAL(windowFullscreenToggle()), window, SLOT(onFullscreenToggled()));
disconnect(this, SIGNAL(swapScreensToggle()), window->actScreenSwap, SLOT(trigger())); disconnect(this, SIGNAL(swapScreensToggle()), window->actScreenSwap, SLOT(trigger()));
disconnect(this, SIGNAL(screenEmphasisToggle()), window, SLOT(onScreenEmphasisToggled())); disconnect(this, SIGNAL(screenEmphasisToggle()), window, SLOT(onScreenEmphasisToggled()));
windowList.remove(window);
window->attachEmuThread(nullptr);
mainWindow = windowList.front();
} }
void EmuThread::run() void EmuThread::run()
{ {
Config::Table& globalCfg = emuInstance->getGlobalConfig();
u32 mainScreenPos[3]; u32 mainScreenPos[3];
Platform::FileHandle* file; Platform::FileHandle* file;
@ -136,25 +126,18 @@ void EmuThread::run()
videoSettingsDirty = false; videoSettingsDirty = false;
if (mainWindow->hasOpenGL()) if (emuInstance->usesOpenGL())
{ {
//screenGL = static_cast<ScreenPanelGL*>(mainWindow->panel); emuInstance->initOpenGL();
//screenGL->initOpenGL();
//mainWindow->initOpenGL();
for (auto window : windowList)
window->initOpenGL();
useOpenGL = true; useOpenGL = true;
videoRenderer = Config::_3DRenderer; videoRenderer = globalCfg.GetInt("3D.Renderer");
} }
else else
{ {
//screenGL = nullptr;
useOpenGL = false; useOpenGL = false;
videoRenderer = 0; videoRenderer = 0;
} }
//screenGL = nullptr;
//videoRenderer = 0;
updateRenderer(); updateRenderer();
@ -253,20 +236,15 @@ void EmuThread::run()
} }
if (useOpenGL) if (useOpenGL)
mainWindow->makeCurrentGL(); emuInstance->makeCurrentGL();
// update render settings if needed // update render settings if needed
// HACK: if (videoSettingsDirty)
// once the fast forward hotkey is released, we need to update vsync
// to the old setting again
if (videoSettingsDirty || emuInstance->hotkeyReleased(HK_FastForward))
{ {
if (useOpenGL) if (useOpenGL)
{ {
for (auto window : windowList) emuInstance->setVSyncGL(true);
window->setGLSwapInterval(Config::ScreenVSync ? Config::ScreenVSyncInterval : 0); videoRenderer = globalCfg.GetInt("3D.Renderer");
videoRenderer = Config::_3DRenderer;
} }
#ifdef OGLRENDERER_ENABLED #ifdef OGLRENDERER_ENABLED
else else
@ -353,9 +331,7 @@ void EmuThread::run()
else else
{ {
FrontBuffer = emuInstance->nds->GPU.FrontBuffer; FrontBuffer = emuInstance->nds->GPU.FrontBuffer;
//screenGL->drawScreenGL(); emuInstance->drawScreenGL();
for (auto window : windowList)
window->drawScreenGL();
} }
#ifdef MELONCAP #ifdef MELONCAP
@ -373,11 +349,17 @@ void EmuThread::run()
bool fastforward = emuInstance->hotkeyDown(HK_FastForward); bool fastforward = emuInstance->hotkeyDown(HK_FastForward);
if (fastforward && useOpenGL && Config::ScreenVSync) if (useOpenGL)
{ {
//screenGL->setSwapInterval(0); // when using OpenGL: when toggling fast-forward, change the vsync interval
for (auto window : windowList) if (emuInstance->hotkeyPressed(HK_FastForward))
window->setGLSwapInterval(0); {
emuInstance->setVSyncGL(false);
}
else if (emuInstance->hotkeyReleased(HK_FastForward))
{
emuInstance->setVSyncGL(true);
}
} }
if (emuInstance->audioDSiVolumeSync && emuInstance->nds->ConsoleType == 1) if (emuInstance->audioDSiVolumeSync && emuInstance->nds->ConsoleType == 1)
@ -468,27 +450,20 @@ void EmuThread::run()
if (useOpenGL) if (useOpenGL)
{ {
for (auto window : windowList) emuInstance->drawScreenGL();
window->drawScreenGL();
} }
ContextRequestKind contextRequest = ContextRequest; ContextRequestKind contextRequest = ContextRequest;
if (contextRequest == contextRequest_InitGL) if (contextRequest == contextRequest_InitGL)
{ {
//screenGL = static_cast<ScreenPanelGL*>(mainWindow->panel); emuInstance->initOpenGL();
//screenGL->initOpenGL();
for (auto window : windowList)
window->initOpenGL();
useOpenGL = true; useOpenGL = true;
ContextRequest = contextRequest_None; ContextRequest = contextRequest_None;
} }
else if (contextRequest == contextRequest_DeInitGL) else if (contextRequest == contextRequest_DeInitGL)
{ {
//screenGL->deinitOpenGL(); emuInstance->deinitOpenGL();
//screenGL = nullptr;
for (auto window : windowList)
window->deinitOpenGL();
useOpenGL = false; useOpenGL = false;
ContextRequest = contextRequest_None; ContextRequest = contextRequest_None;
@ -608,16 +583,23 @@ void EmuThread::updateRenderer()
} }
lastVideoRenderer = videoRenderer; lastVideoRenderer = videoRenderer;
auto& cfg = emuInstance->getGlobalConfig();
switch (videoRenderer) switch (videoRenderer)
{ {
case renderer3D_Software: case renderer3D_Software:
static_cast<SoftRenderer&>(emuInstance->nds->GPU.GetRenderer3D()).SetThreaded(Config::Threaded3D, emuInstance->nds->GPU); static_cast<SoftRenderer&>(emuInstance->nds->GPU.GetRenderer3D()).SetThreaded(
cfg.GetBool("3D.Soft.Threaded"),
emuInstance->nds->GPU);
break; break;
case renderer3D_OpenGL: case renderer3D_OpenGL:
static_cast<GLRenderer&>(emuInstance->nds->GPU.GetRenderer3D()).SetRenderSettings(Config::GL_BetterPolygons, Config::GL_ScaleFactor); static_cast<GLRenderer&>(emuInstance->nds->GPU.GetRenderer3D()).SetRenderSettings(
cfg.GetBool("3D.GL.BetterPolygons"),
cfg.GetInt("3D.GL.ScaleFactor"));
break; break;
case renderer3D_OpenGLCompute: case renderer3D_OpenGLCompute:
static_cast<ComputeRenderer&>(emuInstance->nds->GPU.GetRenderer3D()).SetRenderSettings(Config::GL_ScaleFactor, Config::GL_HiresCoordinates); static_cast<ComputeRenderer&>(emuInstance->nds->GPU.GetRenderer3D()).SetRenderSettings(
cfg.GetInt("3D.GL.ScaleFactor"),
cfg.GetBool("3D.GL.HiresCoordinates"));
break; break;
default: __builtin_unreachable(); default: __builtin_unreachable();
} }

View File

@ -67,6 +67,7 @@ public:
void initContext(); void initContext();
void deinitContext(); void deinitContext();
void updateVideoSettings() { videoSettingsDirty = true; }
int FrontBuffer = 0; int FrontBuffer = 0;
QMutex FrontBufferLock; QMutex FrontBufferLock;
@ -122,10 +123,6 @@ private:
EmuInstance* emuInstance; EmuInstance* emuInstance;
//ScreenPanelGL* screenGL;
MainWindow* mainWindow;
std::list<MainWindow*> windowList;
int autoScreenSizing; int autoScreenSizing;
int lastVideoRenderer = -1; int lastVideoRenderer = -1;

View File

@ -873,8 +873,6 @@ void ScreenPanelGL::initOpenGL()
glEnableVertexAttribArray(0); // position glEnableVertexAttribArray(0); // position
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)(0)); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)(0));
glContext->SetSwapInterval(Config::ScreenVSync ? Config::ScreenVSyncInterval : 0);
transferLayout(); transferLayout();
} }

View File

@ -16,7 +16,6 @@
with melonDS. If not, see http://www.gnu.org/licenses/. with melonDS. If not, see http://www.gnu.org/licenses/.
*/ */
#include <stdio.h>
#include <QFileDialog> #include <QFileDialog>
#include <QtGlobal> #include <QtGlobal>
@ -30,21 +29,25 @@
#include "ui_VideoSettingsDialog.h" #include "ui_VideoSettingsDialog.h"
inline bool UsesGL() inline bool VideoSettingsDialog::UsesGL()
{ {
return (Config::ScreenUseGL != 0) || (Config::_3DRenderer != renderer3D_Software); auto& cfg = emuInstance->getGlobalConfig();
return cfg.GetBool("Screen.UseGL") || (cfg.GetInt("3D.Renderer") != renderer3D_Software);
} }
VideoSettingsDialog* VideoSettingsDialog::currentDlg = nullptr; VideoSettingsDialog* VideoSettingsDialog::currentDlg = nullptr;
void VideoSettingsDialog::setEnabled() void VideoSettingsDialog::setEnabled()
{ {
bool softwareRenderer = Config::_3DRenderer == renderer3D_Software; auto& cfg = emuInstance->getGlobalConfig();
int renderer = cfg.GetInt("3D.Renderer");
bool softwareRenderer = renderer == renderer3D_Software;
ui->cbGLDisplay->setEnabled(softwareRenderer); ui->cbGLDisplay->setEnabled(softwareRenderer);
ui->cbSoftwareThreaded->setEnabled(softwareRenderer); ui->cbSoftwareThreaded->setEnabled(softwareRenderer);
ui->cbxGLResolution->setEnabled(!softwareRenderer); ui->cbxGLResolution->setEnabled(!softwareRenderer);
ui->cbBetterPolygons->setEnabled(Config::_3DRenderer == renderer3D_OpenGL); ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL);
ui->cbxComputeHiResCoords->setEnabled(Config::_3DRenderer == renderer3D_OpenGLCompute); ui->cbxComputeHiResCoords->setEnabled(renderer == renderer3D_OpenGLCompute);
} }
VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog) VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog)
@ -52,14 +55,17 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
oldRenderer = Config::_3DRenderer; emuInstance = ((MainWindow*)parent)->getEmuInstance();
oldGLDisplay = Config::ScreenUseGL;
oldVSync = Config::ScreenVSync; auto& cfg = emuInstance->getGlobalConfig();
oldVSyncInterval = Config::ScreenVSyncInterval; oldRenderer = cfg.GetInt("3D.Renderer");
oldSoftThreaded = Config::Threaded3D; oldGLDisplay = cfg.GetBool("Screen.UseGL");
oldGLScale = Config::GL_ScaleFactor; oldVSync = cfg.GetBool("Screen.VSync");
oldGLBetterPolygons = Config::GL_BetterPolygons; oldVSyncInterval = cfg.GetInt("Screen.VSyncInterval");
oldHiresCoordinates = Config::GL_HiresCoordinates; oldSoftThreaded = cfg.GetBool("3D.Soft.Threaded");
oldGLScale = cfg.GetInt("3D.GL.ScaleFactor");
oldGLBetterPolygons = cfg.GetBool("3D.GL.BetterPolygons");
oldHiresCoordinates = cfg.GetBool("3D.GL.HiresCoordinates");
grp3DRenderer = new QButtonGroup(this); grp3DRenderer = new QButtonGroup(this);
grp3DRenderer->addButton(ui->rb3DSoftware, renderer3D_Software); grp3DRenderer->addButton(ui->rb3DSoftware, renderer3D_Software);
@ -70,7 +76,7 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(
#else #else
connect(grp3DRenderer, SIGNAL(idClicked(int)), this, SLOT(onChange3DRenderer(int))); connect(grp3DRenderer, SIGNAL(idClicked(int)), this, SLOT(onChange3DRenderer(int)));
#endif #endif
grp3DRenderer->button(Config::_3DRenderer)->setChecked(true); grp3DRenderer->button(oldRenderer)->setChecked(true);
#ifndef OGLRENDERER_ENABLED #ifndef OGLRENDERER_ENABLED
ui->rb3DOpenGL->setEnabled(false); ui->rb3DOpenGL->setEnabled(false);
@ -80,21 +86,21 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(
ui->rb3DCompute->setEnabled(false); ui->rb3DCompute->setEnabled(false);
#endif #endif
ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0); ui->cbGLDisplay->setChecked(oldGLDisplay != 0);
ui->cbVSync->setChecked(Config::ScreenVSync != 0); ui->cbVSync->setChecked(oldVSync != 0);
ui->sbVSyncInterval->setValue(Config::ScreenVSyncInterval); ui->sbVSyncInterval->setValue(oldVSyncInterval);
ui->cbSoftwareThreaded->setChecked(Config::Threaded3D != 0); ui->cbSoftwareThreaded->setChecked(oldSoftThreaded);
for (int i = 1; i <= 16; i++) for (int i = 1; i <= 16; i++)
ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i)); ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i));
ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor-1); ui->cbxGLResolution->setCurrentIndex(oldGLScale-1);
ui->cbBetterPolygons->setChecked(Config::GL_BetterPolygons != 0); ui->cbBetterPolygons->setChecked(oldGLBetterPolygons != 0);
ui->cbxComputeHiResCoords->setChecked(Config::GL_HiresCoordinates != 0); ui->cbxComputeHiResCoords->setChecked(oldHiresCoordinates != 0);
if (!Config::ScreenVSync) if (!oldVSync)
ui->sbVSyncInterval->setEnabled(false); ui->sbVSyncInterval->setEnabled(false);
setVsyncControlEnable(UsesGL()); setVsyncControlEnable(UsesGL());
@ -117,14 +123,15 @@ void VideoSettingsDialog::on_VideoSettingsDialog_rejected()
{ {
bool old_gl = UsesGL(); bool old_gl = UsesGL();
Config::_3DRenderer = oldRenderer; auto& cfg = emuInstance->getGlobalConfig();
Config::ScreenUseGL = oldGLDisplay; cfg.SetInt("3D.Renderer", oldRenderer);
Config::ScreenVSync = oldVSync; cfg.SetBool("Screen.UseGL", oldGLDisplay);
Config::ScreenVSyncInterval = oldVSyncInterval; cfg.SetBool("Screen.VSync", oldVSync);
Config::Threaded3D = oldSoftThreaded; cfg.SetInt("Screen.VSyncInterval", oldVSyncInterval);
Config::GL_ScaleFactor = oldGLScale; cfg.SetBool("3D.Soft.Threaded", oldSoftThreaded);
Config::GL_BetterPolygons = oldGLBetterPolygons; cfg.SetInt("3D.GL.ScaleFactor", oldGLScale);
Config::GL_HiresCoordinates = oldHiresCoordinates; cfg.SetBool("3D.GL.BetterPolygons", oldGLBetterPolygons);
cfg.SetBool("3D.GL.HiresCoordinates", oldHiresCoordinates);
emit updateVideoSettings(old_gl != UsesGL()); emit updateVideoSettings(old_gl != UsesGL());
@ -141,7 +148,8 @@ void VideoSettingsDialog::onChange3DRenderer(int renderer)
{ {
bool old_gl = UsesGL(); bool old_gl = UsesGL();
Config::_3DRenderer = renderer; auto& cfg = emuInstance->getGlobalConfig();
cfg.SetInt("3D.Renderer", renderer);
setEnabled(); setEnabled();
@ -152,7 +160,8 @@ void VideoSettingsDialog::on_cbGLDisplay_stateChanged(int state)
{ {
bool old_gl = UsesGL(); bool old_gl = UsesGL();
Config::ScreenUseGL = (state != 0); auto& cfg = emuInstance->getGlobalConfig();
cfg.SetBool("Screen.UseGL", (state != 0));
setVsyncControlEnable(UsesGL()); setVsyncControlEnable(UsesGL());
@ -163,19 +172,25 @@ void VideoSettingsDialog::on_cbVSync_stateChanged(int state)
{ {
bool vsync = (state != 0); bool vsync = (state != 0);
ui->sbVSyncInterval->setEnabled(vsync); ui->sbVSyncInterval->setEnabled(vsync);
Config::ScreenVSync = vsync;
auto& cfg = emuInstance->getGlobalConfig();
cfg.SetBool("Screen.VSync", vsync);
emit updateVideoSettings(false); emit updateVideoSettings(false);
} }
void VideoSettingsDialog::on_sbVSyncInterval_valueChanged(int val) void VideoSettingsDialog::on_sbVSyncInterval_valueChanged(int val)
{ {
Config::ScreenVSyncInterval = val; auto& cfg = emuInstance->getGlobalConfig();
cfg.SetInt("Screen.VSyncInterval", val);
emit updateVideoSettings(false); emit updateVideoSettings(false);
} }
void VideoSettingsDialog::on_cbSoftwareThreaded_stateChanged(int state) void VideoSettingsDialog::on_cbSoftwareThreaded_stateChanged(int state)
{ {
Config::Threaded3D = (state != 0); auto& cfg = emuInstance->getGlobalConfig();
cfg.SetBool("3D.Soft.Threaded", (state != 0));
emit updateVideoSettings(false); emit updateVideoSettings(false);
} }
@ -185,7 +200,8 @@ void VideoSettingsDialog::on_cbxGLResolution_currentIndexChanged(int idx)
// prevent a spurious change // prevent a spurious change
if (ui->cbxGLResolution->count() < 16) return; if (ui->cbxGLResolution->count() < 16) return;
Config::GL_ScaleFactor = idx+1; auto& cfg = emuInstance->getGlobalConfig();
cfg.SetInt("3D.GL.ScaleFactor", idx+1);
setVsyncControlEnable(UsesGL()); setVsyncControlEnable(UsesGL());
@ -194,14 +210,16 @@ void VideoSettingsDialog::on_cbxGLResolution_currentIndexChanged(int idx)
void VideoSettingsDialog::on_cbBetterPolygons_stateChanged(int state) void VideoSettingsDialog::on_cbBetterPolygons_stateChanged(int state)
{ {
Config::GL_BetterPolygons = (state != 0); auto& cfg = emuInstance->getGlobalConfig();
cfg.SetBool("3D.GL.BetterPolygons", (state != 0));
emit updateVideoSettings(false); emit updateVideoSettings(false);
} }
void VideoSettingsDialog::on_cbxComputeHiResCoords_stateChanged(int state) void VideoSettingsDialog::on_cbxComputeHiResCoords_stateChanged(int state)
{ {
Config::GL_HiresCoordinates = (state != 0); auto& cfg = emuInstance->getGlobalConfig();
cfg.SetBool("3D.GL.HiresCoordinates", (state != 0));
emit updateVideoSettings(false); emit updateVideoSettings(false);
} }

View File

@ -24,6 +24,7 @@
namespace Ui { class VideoSettingsDialog; } namespace Ui { class VideoSettingsDialog; }
class VideoSettingsDialog; class VideoSettingsDialog;
class EmuInstance;
class VideoSettingsDialog : public QDialog class VideoSettingsDialog : public QDialog
{ {
@ -33,6 +34,8 @@ public:
explicit VideoSettingsDialog(QWidget* parent); explicit VideoSettingsDialog(QWidget* parent);
~VideoSettingsDialog(); ~VideoSettingsDialog();
bool UsesGL();
static VideoSettingsDialog* currentDlg; static VideoSettingsDialog* currentDlg;
static VideoSettingsDialog* openDlg(QWidget* parent) static VideoSettingsDialog* openDlg(QWidget* parent)
{ {
@ -73,6 +76,7 @@ private:
void setEnabled(); void setEnabled();
Ui::VideoSettingsDialog* ui; Ui::VideoSettingsDialog* ui;
EmuInstance* emuInstance;
QButtonGroup* grp3DRenderer; QButtonGroup* grp3DRenderer;

View File

@ -107,9 +107,6 @@ static bool FileIsSupportedFiletype(const QString& filename, bool insideArchive)
extern CameraManager* camManager[2]; extern CameraManager* camManager[2];
extern bool camStarted[2]; extern bool camStarted[2];
extern int videoRenderer;
extern bool videoSettingsDirty;
// AAAAAAA // AAAAAAA
static bool FileExtensionInList(const QString& filename, const QStringList& extensions, Qt::CaseSensitivity cs = Qt::CaseInsensitive) static bool FileExtensionInList(const QString& filename, const QStringList& extensions, Qt::CaseSensitivity cs = Qt::CaseInsensitive)
@ -203,7 +200,8 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
emuInstance(inst), emuInstance(inst),
globalCfg(inst->globalCfg), globalCfg(inst->globalCfg),
localCfg(inst->localCfg), localCfg(inst->localCfg),
windowCfg(localCfg.GetTable("Window"+std::to_string(id), "Window0")) windowCfg(localCfg.GetTable("Window"+std::to_string(id), "Window0")),
emuThread(inst->getEmuThread())
{ {
test_num = test++; test_num = test++;
#ifndef _WIN32 #ifndef _WIN32
@ -709,11 +707,6 @@ MainWindow::~MainWindow()
delete[] actScreenAspectBot; delete[] actScreenAspectBot;
} }
void MainWindow::attachEmuThread(EmuThread* thread)
{
emuThread = thread;
}
void MainWindow::osdAddMessage(unsigned int color, const char* msg) void MainWindow::osdAddMessage(unsigned int color, const char* msg)
{ {
if (!showOSD) return; if (!showOSD) return;
@ -731,16 +724,20 @@ void MainWindow::closeEvent(QCloseEvent* event)
if (hasOGL) if (hasOGL)
{ {
// we intentionally don't unpause here // we intentionally don't unpause here
// TODO this ought to change if we do multi-window shiz
emuThread->emuPause(); emuThread->emuPause();
emuThread->deinitContext(); emuThread->deinitContext();
} }
emuThread->detachWindow(this);
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
void MainWindow::createScreenPanel() void MainWindow::createScreenPanel()
{ {
hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); hasOGL = globalCfg.GetBool("Screen.UseGL") ||
(globalCfg.GetInt("3D.Renderer") != renderer3D_Software);
if (hasOGL) if (hasOGL)
{ {
@ -749,8 +746,7 @@ void MainWindow::createScreenPanel()
panel = panelGL; panel = panelGL;
bool res = panelGL->createContext(); panelGL->createContext();
printf("WIN %d CONTEXT: %d\n", test_num, res);
} }
if (!hasOGL) if (!hasOGL)
@ -777,7 +773,7 @@ GL::Context* MainWindow::getOGLContext()
} }
void MainWindow::initOpenGL() void MainWindow::initOpenGL()
{printf("WINDOW %d INIT OPENGL %d\n", test_num, hasOGL); {
if (!hasOGL) return; if (!hasOGL) return;
ScreenPanelGL* glpanel = static_cast<ScreenPanelGL*>(panel); ScreenPanelGL* glpanel = static_cast<ScreenPanelGL*>(panel);
@ -2087,8 +2083,7 @@ void MainWindow::onUpdateVideoSettings(bool glchange)
connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(repaint())); connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(repaint()));
} }
printf("update video settings\n"); emuThread->updateVideoSettings();
videoSettingsDirty = true;
if (glchange) if (glchange)
{ {

View File

@ -110,8 +110,6 @@ public:
EmuInstance* getEmuInstance() { return emuInstance; } EmuInstance* getEmuInstance() { return emuInstance; }
Config::Table& getWindowConfig() { return windowCfg; } Config::Table& getWindowConfig() { return windowCfg; }
void attachEmuThread(EmuThread* thread);
bool hasOpenGL() { return hasOGL; } bool hasOpenGL() { return hasOGL; }
GL::Context* getOGLContext(); GL::Context* getOGLContext();
void initOpenGL(); void initOpenGL();

View File

@ -135,17 +135,9 @@ bool RunningSomething;
//EmuThread* emuThread; //EmuThread* emuThread;
EmuInstance* testinst; EmuInstance* testinst;
int autoScreenSizing = 0;
int videoRenderer;
bool videoSettingsDirty;
CameraManager* camManager[2]; CameraManager* camManager[2];
bool camStarted[2]; bool camStarted[2];
//extern int AspectRatiosNum;
@ -299,7 +291,7 @@ int main(int argc, char** argv)
QString errorStr = "Failed to initialize SDL. This could indicate an issue with your audio driver.\n\nThe error was: "; QString errorStr = "Failed to initialize SDL. This could indicate an issue with your audio driver.\n\nThe error was: ";
errorStr += err; errorStr += err;
QMessageBox::critical(NULL, "melonDS", errorStr); QMessageBox::critical(nullptr, "melonDS", errorStr);
return 1; return 1;
} }
@ -308,17 +300,10 @@ int main(int argc, char** argv)
SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_InitSubSystem(SDL_INIT_VIDEO);
SDL_EnableScreenSaver(); SDL_DisableScreenSaver(); SDL_EnableScreenSaver(); SDL_DisableScreenSaver();
if (!Config::Load()) QMessageBox::critical(NULL, "melonDS", "Unable to write to config.\nPlease check the write permissions of the folder you placed melonDS in."); if (!Config::Load())
QMessageBox::critical(nullptr,
#define SANITIZE(var, min, max) { var = std::clamp(var, min, max); } "melonDS",
#ifdef OGLRENDERER_ENABLED "Unable to write to config.\nPlease check the write permissions of the folder you placed melonDS in.");
SANITIZE(Config::_3DRenderer, 0, 1); // 0 is the software renderer, 1 is the OpenGL renderer
#else
SANITIZE(Config::_3DRenderer, 0, 0);
#endif
SANITIZE(Config::ScreenVSyncInterval, 1, 20);
SANITIZE(Config::GL_ScaleFactor, 1, 16);
#undef SANITIZE
camStarted[0] = false; camStarted[0] = false;
camStarted[1] = false; camStarted[1] = false;