From 12ce777e30be8237909655267779d283abfc5b56 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 27 Oct 2019 21:52:10 +1000 Subject: [PATCH] Frontend: Add toggle for software rendering --- src/core/settings.h | 12 +++++------ src/core/system.cpp | 6 +++--- src/duckstation/sdl_interface.cpp | 34 ++++++++++++++++++++++++++++--- src/duckstation/sdl_interface.h | 1 + 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/core/settings.h b/src/core/settings.h index 59dde1862..c179fb9a2 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -1,14 +1,14 @@ #pragma once #include "types.h" -enum class GPURenderer -{ - HardwareOpenGL, - Software -}; - struct Settings { + enum class GPURenderer + { + HardwareOpenGL, + Software + }; + Settings(); bool start_paused = false; diff --git a/src/core/system.cpp b/src/core/system.cpp index f38851019..d0547f7d8 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -108,11 +108,11 @@ bool System::CreateGPU() { switch (m_settings.gpu_renderer) { - case GPURenderer::HardwareOpenGL: + case Settings::GPURenderer::HardwareOpenGL: m_gpu = GPU::CreateHardwareOpenGLRenderer(); break; - case GPURenderer::Software: + case Settings::GPURenderer::Software: default: m_gpu = GPU::CreateSoftwareRenderer(); break; @@ -122,7 +122,7 @@ bool System::CreateGPU() { Log_ErrorPrintf("Failed to initialize GPU, falling back to software"); m_gpu.reset(); - m_settings.gpu_renderer = GPURenderer::Software; + m_settings.gpu_renderer = Settings::GPURenderer::Software; m_gpu = GPU::CreateSoftwareRenderer(); if (!m_gpu->Initialize(this, m_dma.get(), m_interrupt_controller.get(), m_timers.get())) return false; diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index c0a4dc8b2..4330f4c64 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -21,8 +21,8 @@ #include Log_SetChannel(SDLInterface); -static constexpr std::array, 2> s_gpu_renderer_names = { - {{GPURenderer::HardwareOpenGL, "Hardware (OpenGL)"}, {GPURenderer::Software, "Software"}}}; +static constexpr std::array, 2> s_gpu_renderer_names = { + {{Settings::GPURenderer::HardwareOpenGL, "Hardware (OpenGL)"}, {Settings::GPURenderer::Software, "Software"}}}; SDLInterface::SDLInterface() = default; @@ -596,6 +596,14 @@ void SDLInterface::HandleSDLKeyEvent(const SDL_Event* event) DoFrameStep(); } break; + + case SDL_SCANCODE_PAGEUP: + case SDL_SCANCODE_PAGEDOWN: + { + if (pressed) + DoToggleSoftwareRendering(); + } + break; } } @@ -785,7 +793,7 @@ void SDLInterface::DrawMainMenuBar() { if (ImGui::BeginMenu("Renderer")) { - const GPURenderer current = m_system->GetSettings().gpu_renderer; + const Settings::GPURenderer current = m_system->GetSettings().gpu_renderer; for (const auto& it : s_gpu_renderer_names) { if (ImGui::MenuItem(it.second, nullptr, current == it.first)) @@ -1187,6 +1195,26 @@ void SDLInterface::DoFrameStep() m_paused = false; } +void SDLInterface::DoToggleSoftwareRendering() +{ + if (!m_system) + return; + + auto& settings = m_system->GetSettings(); + if (settings.gpu_renderer != Settings::GPURenderer::Software) + { + settings.gpu_renderer = Settings::GPURenderer::Software; + AddOSDMessage("Switched to software GPU renderer."); + } + else + { + settings.gpu_renderer = Settings::GPURenderer::HardwareOpenGL; + AddOSDMessage("Switched to hardware GPU renderer."); + } + + m_system->RecreateGPU(); +} + void SDLInterface::Run() { m_audio_stream->PauseOutput(false); diff --git a/src/duckstation/sdl_interface.h b/src/duckstation/sdl_interface.h index 8db9c2849..ce6298a14 100644 --- a/src/duckstation/sdl_interface.h +++ b/src/duckstation/sdl_interface.h @@ -74,6 +74,7 @@ private: void DoSaveState(u32 index); void DoTogglePause(); void DoFrameStep(); + void DoToggleSoftwareRendering(); void HandleSDLEvent(const SDL_Event* event); void HandleSDLKeyEvent(const SDL_Event* event);