Frontend: Add toggle for software rendering

This commit is contained in:
Connor McLaughlin 2019-10-27 21:52:10 +10:00
parent d1be9460b9
commit 12ce777e30
4 changed files with 41 additions and 12 deletions

View file

@ -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;

View file

@ -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;

View file

@ -21,8 +21,8 @@
#include <nfd.h>
Log_SetChannel(SDLInterface);
static constexpr std::array<std::pair<GPURenderer, const char*>, 2> s_gpu_renderer_names = {
{{GPURenderer::HardwareOpenGL, "Hardware (OpenGL)"}, {GPURenderer::Software, "Software"}}};
static constexpr std::array<std::pair<Settings::GPURenderer, const char*>, 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);

View file

@ -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);