diff --git a/src/GPU.cpp b/src/GPU.cpp index afef71df..2d5834e6 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -396,7 +396,7 @@ void AssignFramebuffers() void InitRenderer(int renderer) { #ifdef OGLRENDERER_ENABLED - if (renderer == 1) + if (renderer != renderer3D_Software) { CurGLCompositor = GLCompositor::New(); // Create opengl renderer diff --git a/src/GPU.h b/src/GPU.h index 96d5b540..ee75fc19 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -160,6 +160,7 @@ struct RenderSettings int GL_ScaleFactor; bool GL_BetterPolygons; + bool GL_HiresCoordinates; }; @@ -170,6 +171,16 @@ void Stop(); void DoSavestate(Savestate* file); +enum +{ + renderer3D_Software = 0, +#ifdef OGLRENDERER_ENABLED + renderer3D_OpenGL, + renderer3D_OpenGLCompute, +#endif + renderer3D_Max, +}; + void InitRenderer(int renderer); void DeInitRenderer(); void ResetRenderer(); diff --git a/src/GPU3D_Compute.cpp b/src/GPU3D_Compute.cpp index e5c34797..76df9e0b 100644 --- a/src/GPU3D_Compute.cpp +++ b/src/GPU3D_Compute.cpp @@ -196,6 +196,8 @@ void ComputeRenderer::SetRenderSettings(GPU::RenderSettings& settings) TilesPerLine = ScreenWidth/TileSize; TileLines = ScreenHeight/TileSize; + HiresCoordinates = settings.GL_HiresCoordinates; + MaxWorkTiles = TilesPerLine*TileLines*8; for (int i = 0; i < tilememoryLayer_Num; i++) @@ -628,8 +630,16 @@ void ComputeRenderer::RenderFrame() s32 ytop = ScreenHeight, ybot = 0; for (int i = 0; i < polygon->NumVertices; i++) { - scaledPositions[i][0] = (polygon->Vertices[i]->HiresPosition[0] * ScaleFactor) >> 4; - scaledPositions[i][1] = (polygon->Vertices[i]->HiresPosition[1] * ScaleFactor) >> 4; + if (HiresCoordinates) + { + scaledPositions[i][0] = (polygon->Vertices[i]->HiresPosition[0] * ScaleFactor) >> 4; + scaledPositions[i][1] = (polygon->Vertices[i]->HiresPosition[1] * ScaleFactor) >> 4; + } + else + { + scaledPositions[i][0] = polygon->Vertices[i]->FinalPosition[0] * ScaleFactor; + scaledPositions[i][1] = polygon->Vertices[i]->FinalPosition[1] * ScaleFactor; + } ytop = std::min(scaledPositions[i][1], ytop); ybot = std::max(scaledPositions[i][1], ybot); } diff --git a/src/GPU3D_Compute.h b/src/GPU3D_Compute.h index d91075a0..73f840b9 100644 --- a/src/GPU3D_Compute.h +++ b/src/GPU3D_Compute.h @@ -209,6 +209,7 @@ private: int TilesPerLine, TileLines; int ScaleFactor = -1; int MaxWorkTiles; + bool HiresCoordinates; void DeleteShaders(); diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index 898e4a16..699f5307 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -21,6 +21,7 @@ #include #include "Platform.h" #include "Config.h" +#include "GPU.h" namespace Config @@ -57,6 +58,7 @@ bool Threaded3D; int GL_ScaleFactor; bool GL_BetterPolygons; +bool GL_HiresCoordinates; bool LimitFPS; bool AudioSync; @@ -232,11 +234,12 @@ ConfigEntry ConfigFile[] = {"ScreenVSync", 1, &ScreenVSync, false, false}, {"ScreenVSyncInterval", 0, &ScreenVSyncInterval, 1, false}, - {"3DRenderer", 0, &_3DRenderer, 0, false}, + {"3DRenderer", 0, &_3DRenderer, GPU::renderer3D_Software, false}, {"Threaded3D", 1, &Threaded3D, true, false}, {"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, false}, {"GL_BetterPolygons", 1, &GL_BetterPolygons, false, false}, + {"GL_HiresCoordinates", 1, &GL_HiresCoordinates, true, false}, {"LimitFPS", 1, &LimitFPS, true, false}, {"AudioSync", 1, &AudioSync, false}, diff --git a/src/frontend/qt_sdl/Config.h b/src/frontend/qt_sdl/Config.h index 504c068d..9f3f6e43 100644 --- a/src/frontend/qt_sdl/Config.h +++ b/src/frontend/qt_sdl/Config.h @@ -103,6 +103,7 @@ extern bool Threaded3D; extern int GL_ScaleFactor; extern bool GL_BetterPolygons; +extern bool GL_HiresCoordinates; extern bool LimitFPS; extern bool AudioSync; diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 95ec7d31..5ef10c5a 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -23,6 +23,7 @@ #include "types.h" #include "Platform.h" #include "Config.h" +#include "GPU.h" #include "VideoSettingsDialog.h" #include "ui_VideoSettingsDialog.h" @@ -30,11 +31,20 @@ inline bool UsesGL() { - return (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + return (Config::ScreenUseGL != 0) || (Config::_3DRenderer != GPU::renderer3D_Software); } VideoSettingsDialog* VideoSettingsDialog::currentDlg = nullptr; +void VideoSettingsDialog::setEnabled() +{ + bool softwareRenderer = Config::_3DRenderer == GPU::renderer3D_Software; + ui->cbGLDisplay->setEnabled(softwareRenderer); + ui->cbSoftwareThreaded->setEnabled(softwareRenderer); + ui->cbxGLResolution->setEnabled(!softwareRenderer); + ui->cbBetterPolygons->setEnabled(Config::_3DRenderer == GPU::renderer3D_OpenGL); + ui->cbxComputeHiResCoords->setEnabled(Config::_3DRenderer == GPU::renderer3D_OpenGLCompute); +} VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog) { @@ -48,10 +58,12 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( oldSoftThreaded = Config::Threaded3D; oldGLScale = Config::GL_ScaleFactor; oldGLBetterPolygons = Config::GL_BetterPolygons; + oldHiresCoordinates = Config::GL_HiresCoordinates; grp3DRenderer = new QButtonGroup(this); - grp3DRenderer->addButton(ui->rb3DSoftware, 0); - grp3DRenderer->addButton(ui->rb3DOpenGL, 1); + grp3DRenderer->addButton(ui->rb3DSoftware, GPU::renderer3D_Software); + grp3DRenderer->addButton(ui->rb3DOpenGL, GPU::renderer3D_OpenGL); + grp3DRenderer->addButton(ui->rb3DCompute, GPU::renderer3D_OpenGLCompute); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int))); #else @@ -75,25 +87,13 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor-1); ui->cbBetterPolygons->setChecked(Config::GL_BetterPolygons != 0); + ui->cbxComputeHiResCoords->setChecked(Config::GL_HiresCoordinates != 0); if (!Config::ScreenVSync) ui->sbVSyncInterval->setEnabled(false); setVsyncControlEnable(UsesGL()); - if (Config::_3DRenderer == 0) - { - ui->cbGLDisplay->setEnabled(true); - ui->cbSoftwareThreaded->setEnabled(true); - ui->cbxGLResolution->setEnabled(false); - ui->cbBetterPolygons->setEnabled(false); - } - else - { - ui->cbGLDisplay->setEnabled(false); - ui->cbSoftwareThreaded->setEnabled(false); - ui->cbxGLResolution->setEnabled(true); - ui->cbBetterPolygons->setEnabled(true); - } + setEnabled(); } VideoSettingsDialog::~VideoSettingsDialog() @@ -119,6 +119,7 @@ void VideoSettingsDialog::on_VideoSettingsDialog_rejected() Config::Threaded3D = oldSoftThreaded; Config::GL_ScaleFactor = oldGLScale; Config::GL_BetterPolygons = oldGLBetterPolygons; + Config::GL_HiresCoordinates = oldHiresCoordinates; emit updateVideoSettings(old_gl != UsesGL()); @@ -133,31 +134,18 @@ void VideoSettingsDialog::setVsyncControlEnable(bool hasOGL) void VideoSettingsDialog::onChange3DRenderer(int renderer) { - bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + bool old_gl = UsesGL(); Config::_3DRenderer = renderer; - if (renderer == 0) - { - ui->cbGLDisplay->setEnabled(true); - ui->cbSoftwareThreaded->setEnabled(true); - ui->cbxGLResolution->setEnabled(false); - ui->cbBetterPolygons->setEnabled(false); - } - else - { - ui->cbGLDisplay->setEnabled(false); - ui->cbSoftwareThreaded->setEnabled(false); - ui->cbxGLResolution->setEnabled(true); - ui->cbBetterPolygons->setEnabled(true); - } + setEnabled(); emit updateVideoSettings(old_gl != UsesGL()); } void VideoSettingsDialog::on_cbGLDisplay_stateChanged(int state) { - bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + bool old_gl = UsesGL(); Config::ScreenUseGL = (state != 0); @@ -205,3 +193,10 @@ void VideoSettingsDialog::on_cbBetterPolygons_stateChanged(int state) emit updateVideoSettings(false); } + +void VideoSettingsDialog::on_cbxComputeHiResCoords_stateChanged(int state) +{ + Config::GL_HiresCoordinates = (state != 0); + + emit updateVideoSettings(false); +} diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index 7fee5bb8..166a8266 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -65,10 +65,12 @@ private slots: void on_cbxGLResolution_currentIndexChanged(int idx); void on_cbBetterPolygons_stateChanged(int state); + void on_cbxComputeHiResCoords_stateChanged(int state); void on_cbSoftwareThreaded_stateChanged(int state); private: void setVsyncControlEnable(bool hasOGL); + void setEnabled(); Ui::VideoSettingsDialog* ui; @@ -81,6 +83,7 @@ private: int oldSoftThreaded; int oldGLScale; int oldGLBetterPolygons; + int oldHiresCoordinates; }; #endif // VIDEOSETTINGSDIALOG_H diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.ui b/src/frontend/qt_sdl/VideoSettingsDialog.ui index 11cfe3d9..ff9baf8f 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.ui +++ b/src/frontend/qt_sdl/VideoSettingsDialog.ui @@ -6,7 +6,7 @@ 0 0 - 408 + 427 262 @@ -24,7 +24,7 @@ QLayout::SetFixedSize - -1 + 6 @@ -39,13 +39,6 @@ - - - - <html><head/><body><p>The resolution at which the 3D graphics will be rendered. Higher resolutions improve graphics quality when the main window is enlarged, but may also cause glitches.</p></body></html> - - - @@ -56,6 +49,20 @@ + + + + <html><head/><body><p>The resolution at which the 3D graphics will be rendered. Higher resolutions improve graphics quality when the main window is enlarged, but may also cause glitches.</p></body></html> + + + + + + + Use high resolution coordinates + + + @@ -94,23 +101,7 @@ Display settings - - - - - 0 - 0 - - - - <html><head/><body><p>The interval at which to synchronize to the monitor's refresh rate. Set to 1 for a 60Hz monitor, 2 for 120Hz, ...</p></body></html> - - - VSync interval: - - - - + <html><head/><body><p>The interval at which to synchronize to the monitor's refresh rate. Set to 1 for a 60Hz monitor, 2 for 120Hz, ...</p></body></html> @@ -123,7 +114,7 @@ - + <html><head/><body><p>Use OpenGL to draw the DS screens to the main window. May result in better frame pacing. Mandatory when using the OpenGL 3D renderer.</p></body></html> @@ -133,17 +124,7 @@ - - - - <html><head/><body><p>When using OpenGL, synchronize the video output to your monitor's refresh rate.</p></body></html> - - - VSync - - - - + Qt::Vertical @@ -159,13 +140,39 @@ + + + + <html><head/><body><p>When using OpenGL, synchronize the video output to your monitor's refresh rate.</p></body></html> + + + VSync + + + + + + + + 0 + 0 + + + + <html><head/><body><p>The interval at which to synchronize to the monitor's refresh rate. Set to 1 for a 60Hz monitor, 2 for 120Hz, ...</p></body></html> + + + VSync interval: + + + <html><head/><body><p>The OpenGL renderer may be faster than software and supports graphical enhancements, but is more prone to glitches.</p></body></html> - OpenGL + OpenGL (Classic) @@ -186,6 +193,13 @@ + + + + OpenGL (Compute shader) + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 875a39b6..54a98c42 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -323,6 +323,7 @@ void EmuThread::run() videoSettings.Soft_Threaded = Config::Threaded3D != 0; videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; videoSettings.GL_BetterPolygons = Config::GL_BetterPolygons; + videoSettings.GL_HiresCoordinates = Config::GL_HiresCoordinates; if (mainWindow->hasOGL) { @@ -444,16 +445,17 @@ void EmuThread::run() else #endif { - videoRenderer = 0; + videoRenderer = GPU::renderer3D_Software; } - videoRenderer = oglContext ? Config::_3DRenderer : 0; + videoRenderer = oglContext ? Config::_3DRenderer : GPU::renderer3D_Software; videoSettingsDirty = false; videoSettings.Soft_Threaded = Config::Threaded3D != 0; videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; videoSettings.GL_BetterPolygons = Config::GL_BetterPolygons; + videoSettings.GL_HiresCoordinates = Config::GL_HiresCoordinates; GPU::SetRenderSettings(videoRenderer, videoSettings); } @@ -1860,7 +1862,7 @@ void MainWindow::closeEvent(QCloseEvent* event) void MainWindow::createScreenPanel() { - hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != GPU::renderer3D_Software); if (hasOGL) { @@ -3273,13 +3275,7 @@ int main(int argc, char** argv) #define SANITIZE(var, min, max) { var = std::clamp(var, min, max); } SANITIZE(Config::ConsoleType, 0, 1); - SANITIZE(Config::_3DRenderer, - 0, - 0 // Minimum, Software renderer - #ifdef OGLRENDERER_ENABLED - + 1 // OpenGL Renderer - #endif - ); + SANITIZE(Config::_3DRenderer, (int)GPU::renderer3D_Software, (int)GPU::renderer3D_Max); SANITIZE(Config::ScreenVSyncInterval, 1, 20); SANITIZE(Config::GL_ScaleFactor, 1, 16); SANITIZE(Config::AudioInterp, 0, 3);