diff --git a/include/renderer.hpp b/include/renderer.hpp index 50ed1a32d..8381c2796 100644 --- a/include/renderer.hpp +++ b/include/renderer.hpp @@ -12,6 +12,9 @@ enum class RendererType : s8 { OpenGL = 1, }; +std::optional fromString(std::string inString); +const char* toString(RendererType rendererType); + class GPU; class Renderer { diff --git a/src/config.cpp b/src/config.cpp index 6923204de..beb76b957 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -33,7 +33,19 @@ void EmulatorConfig::load(const std::filesystem::path& path) { if (gpuResult.is_ok()) { auto gpu = gpuResult.unwrap(); - rendererType = RendererType(toml::find_or(gpu, "Renderer", int64_t(rendererType))); + // Get renderer + auto rendererResult = toml::expect(gpu, "Renderer"); + if (rendererResult.is_ok()) { + auto rendererName = rendererResult.unwrap(); + if (auto configRendererType = fromString(rendererName); configRendererType.has_value()) { + rendererType = configRendererType.value(); + } else { + Helpers::warn("Invalid renderer specified: %s\n", rendererName); + } + } else { + Helpers::warn("Renderer not specified: %s\n", rendererResult.unwrap_err()); + } + shaderJitEnabled = toml::find_or(gpu, "EnableShaderJIT", false); } } @@ -57,7 +69,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(rendererType); + data["GPU"]["Renderer"] = toString(rendererType); data["GPU"]["EnableShaderJIT"] = shaderJitEnabled; std::ofstream file(path, std::ios::out); diff --git a/src/renderer.cpp b/src/renderer.cpp index b3da05014..a000bb856 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -1,4 +1,24 @@ #include "renderer.hpp" +std::optional fromString(std::string inString) { + // case-insensitive + std::transform(inString.begin(), inString.end(), inString.begin(), [](unsigned char c) { return std::tolower(c); }); + + if (inString == "null") + return RendererType::Null; + else if (inString == "opengl") + return RendererType::OpenGL; + + return std::nullopt; +} + +const char* toString(RendererType rendererType) { + switch (rendererType) { + case RendererType::Null: return "null"; + case RendererType::OpenGL: return "opengl"; + default: return "Invalid"; + } +} + Renderer::Renderer(GPU& gpu, const std::array& internalRegs) : gpu(gpu), regs(internalRegs) {} Renderer::~Renderer() {} \ No newline at end of file