Add configurable Renderer backend
There are still some initialization errors to work through, such as config not being initialized properly by the time GPU tries to utilize it too. Also some life-time issues. But manually forcing it to use the Null backnd successfully works and allows games to be "played" headlessly.
This commit is contained in:
@@ -31,6 +31,7 @@ void EmulatorConfig::load(const std::filesystem::path& path) {
|
||||
if (gpuResult.is_ok()) {
|
||||
auto gpu = gpuResult.unwrap();
|
||||
|
||||
rendererType = RendererType(toml::find_or<toml::integer>(gpu, "Renderer", int64_t(rendererType)));
|
||||
shaderJitEnabled = toml::find_or<toml::boolean>(gpu, "EnableShaderJIT", false);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +55,7 @@ void EmulatorConfig::save(const std::filesystem::path& path) {
|
||||
printf("Saving new configuration file %s\n", path.string().c_str());
|
||||
}
|
||||
|
||||
data["GPU"]["Renderer"] = static_cast<s8>(rendererType);
|
||||
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
|
||||
|
||||
std::ofstream file(path, std::ios::out);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "PICA/float_types.hpp"
|
||||
#include "PICA/regs.hpp"
|
||||
|
||||
#include "renderer_null/renderer_null.hpp"
|
||||
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||
#include "renderer_gl/renderer_gl.hpp"
|
||||
#endif
|
||||
@@ -20,10 +20,22 @@ GPU::GPU(Memory& mem, EmulatorConfig& config) : mem(mem), config(config) {
|
||||
vram = new u8[vramSize];
|
||||
mem.setVRAM(vram); // Give the bus a pointer to our VRAM
|
||||
|
||||
// TODO: Configurable backend
|
||||
switch (config.rendererType) {
|
||||
case RendererType::Null: {
|
||||
renderer.reset(new RendererNull(*this, regs));
|
||||
break;
|
||||
}
|
||||
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||
renderer.reset(new RendererGL(*this, regs));
|
||||
case RendererType::OpenGL: {
|
||||
renderer.reset(new RendererGL(*this, regs));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
Helpers::panic("Invalid rendering backend index: %d", static_cast<s8>(config.rendererType));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GPU::reset() {
|
||||
|
||||
@@ -26,24 +26,26 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory
|
||||
}
|
||||
|
||||
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||
// Request OpenGL 4.1 Core (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);
|
||||
window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
|
||||
if (config.rendererType == RendererType::OpenGL) {
|
||||
// Request OpenGL 4.1 Core (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);
|
||||
window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
|
||||
|
||||
if (window == nullptr) {
|
||||
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
||||
}
|
||||
if (window == nullptr) {
|
||||
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
glContext = SDL_GL_CreateContext(window);
|
||||
if (glContext == nullptr) {
|
||||
Helpers::panic("OpenGL context creation failed: %s", SDL_GetError());
|
||||
}
|
||||
glContext = SDL_GL_CreateContext(window);
|
||||
if (glContext == nullptr) {
|
||||
Helpers::panic("OpenGL context creation failed: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
if (!gladLoadGL(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress))) {
|
||||
Helpers::panic("OpenGL init failed: %s", SDL_GetError());
|
||||
if (!gladLoadGL(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress))) {
|
||||
Helpers::panic("OpenGL init failed: %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -56,7 +58,6 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory
|
||||
}
|
||||
}
|
||||
|
||||
config.load(std::filesystem::current_path() / "config.toml");
|
||||
reset(ReloadOption::NoReload);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "emulator.hpp"
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
Emulator emu;
|
||||
int main(int argc, char *argv[]) {
|
||||
Emulator emu;
|
||||
|
||||
emu.initGraphicsContext();
|
||||
emu.initGraphicsContext();
|
||||
|
||||
if (argc > 1) {
|
||||
auto romPath = std::filesystem::current_path() / argv[1];
|
||||
|
||||
Reference in New Issue
Block a user