From ae4a4dfc291489f6b065a63fe20cd93f815fe825 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 22 Jul 2023 20:47:19 +0300 Subject: [PATCH] Hook up sw rendering backend --- include/renderer.hpp | 1 + src/core/PICA/gpu.cpp | 7 +++++++ src/emulator.cpp | 17 +++++++++-------- src/renderer.cpp | 9 ++++++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/renderer.hpp b/include/renderer.hpp index e14afcea..970b8933 100644 --- a/include/renderer.hpp +++ b/include/renderer.hpp @@ -12,6 +12,7 @@ enum class RendererType : s8 { Null = 0, OpenGL = 1, Vulkan = 2, + Software = 3, }; class GPU; diff --git a/src/core/PICA/gpu.cpp b/src/core/PICA/gpu.cpp index d75b0ae5..d7c37925 100644 --- a/src/core/PICA/gpu.cpp +++ b/src/core/PICA/gpu.cpp @@ -8,6 +8,7 @@ #include "PICA/float_types.hpp" #include "PICA/regs.hpp" #include "renderer_null/renderer_null.hpp" +#include "renderer_sw/renderer_sw.hpp" #ifdef PANDA3DS_ENABLE_OPENGL #include "renderer_gl/renderer_gl.hpp" #endif @@ -25,6 +26,12 @@ GPU::GPU(Memory& mem, EmulatorConfig& config) : mem(mem), config(config) { renderer.reset(new RendererNull(*this, regs)); break; } + + case RendererType::Software: { + renderer.reset(new RendererSw(*this, regs)); + break; + } + #ifdef PANDA3DS_ENABLE_OPENGL case RendererType::OpenGL: { renderer.reset(new RendererGL(*this, regs)); diff --git a/src/emulator.cpp b/src/emulator.cpp index ce42d273..98c4c67f 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,8 +1,5 @@ #include "emulator.hpp" - -#ifdef PANDA3DS_ENABLE_OPENGL #include -#endif #ifdef _WIN32 #include @@ -27,13 +24,18 @@ Emulator::Emulator() Helpers::warn("Failed to initialize SDL2 GameController: %s", SDL_GetError()); } + // We need OpenGL for software rendering or for OpenGL if it's enabled + bool needOpenGL = config.rendererType == RendererType::Software; #ifdef PANDA3DS_ENABLE_OPENGL - if (config.rendererType == RendererType::OpenGL) { - // Request OpenGL 4.1 Core (Max available on MacOS) + needOpenGL = needOpenGL || (config.rendererType == RendererType::OpenGL); +#endif + + if (needOpenGL) { + // Demand 3.3 core for software renderer, or 4.1 core for OpenGL renderer (max available on MacOS) // MacOS gets mad if we don't explicitly demand a core profile SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, config.rendererType == RendererType::Software ? 3 : 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, config.rendererType == RendererType::Software ? 3 : 1); window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); if (window == nullptr) { @@ -49,7 +51,6 @@ Emulator::Emulator() Helpers::panic("OpenGL init failed: %s", SDL_GetError()); } } -#endif if (SDL_WasInit(SDL_INIT_GAMECONTROLLER)) { gameController = SDL_GameControllerOpen(0); diff --git a/src/renderer.cpp b/src/renderer.cpp index 3ba29aea..22d0accb 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -13,9 +13,11 @@ std::optional Renderer::typeFromString(std::string inString) { // Huge table of possible names and misspellings // Please stop misspelling Vulkan as Vulcan static const std::unordered_map map = { - {"null", RendererType::Null}, {"nil", RendererType::Null}, {"none", RendererType::Null}, - {"gl", RendererType::OpenGL}, {"ogl", RendererType::OpenGL}, {"opengl", RendererType::OpenGL}, - {"vk", RendererType::Vulkan}, {"vulkan", RendererType::Vulkan}, {"vulcan", RendererType::Vulkan}, + {"null", RendererType::Null}, {"nil", RendererType::Null}, {"none", RendererType::Null}, + {"gl", RendererType::OpenGL}, {"ogl", RendererType::OpenGL}, {"opengl", RendererType::OpenGL}, + {"vk", RendererType::Vulkan}, {"vulkan", RendererType::Vulkan}, {"vulcan", RendererType::Vulkan}, + {"sw", RendererType::Software}, {"soft", RendererType::Software}, {"software", RendererType::Software}, + {"softrast", RendererType::Software}, }; if (auto search = map.find(inString); search != map.end()) { @@ -30,6 +32,7 @@ const char* Renderer::typeToString(RendererType rendererType) { case RendererType::Null: return "null"; case RendererType::OpenGL: return "opengl"; case RendererType::Vulkan: return "vulkan"; + case RendererType::Software: return "software"; default: return "Invalid"; } } \ No newline at end of file