Hook up sw rendering backend

This commit is contained in:
wheremyfoodat 2023-07-22 20:47:19 +03:00
parent f328200c65
commit ae4a4dfc29
4 changed files with 23 additions and 11 deletions

View file

@ -12,6 +12,7 @@ enum class RendererType : s8 {
Null = 0,
OpenGL = 1,
Vulkan = 2,
Software = 3,
};
class GPU;

View file

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

View file

@ -1,8 +1,5 @@
#include "emulator.hpp"
#ifdef PANDA3DS_ENABLE_OPENGL
#include <glad/gl.h>
#endif
#ifdef _WIN32
#include <windows.h>
@ -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);

View file

@ -13,9 +13,11 @@ std::optional<RendererType> Renderer::typeFromString(std::string inString) {
// Huge table of possible names and misspellings
// Please stop misspelling Vulkan as Vulcan
static const std::unordered_map<std::string, RendererType> 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";
}
}