mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 06:35:40 +12:00
Add string-based renderer backend configuration
Rather than using integer-indices, just use plaintext case-insensitive names and leave the actual enum indexes as an implementation detail.
This commit is contained in:
parent
2c57936c50
commit
528ed510c2
4 changed files with 38 additions and 3 deletions
|
@ -12,6 +12,9 @@ enum class RendererType : s8 {
|
|||
OpenGL = 1,
|
||||
};
|
||||
|
||||
std::optional<RendererType> fromString(std::string inString);
|
||||
const char* toString(RendererType rendererType);
|
||||
|
||||
class GPU;
|
||||
|
||||
class Renderer {
|
||||
|
|
|
@ -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<toml::integer>(gpu, "Renderer", int64_t(rendererType)));
|
||||
// Get renderer
|
||||
auto rendererResult = toml::expect<std::string>(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.c_str());
|
||||
}
|
||||
} else {
|
||||
Helpers::warn("Renderer not specified: %s\n", rendererResult.unwrap_err());
|
||||
}
|
||||
|
||||
shaderJitEnabled = toml::find_or<toml::boolean>(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<s8>(rendererType);
|
||||
data["GPU"]["Renderer"] = toString(rendererType);
|
||||
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
|
||||
|
||||
std::ofstream file(path, std::ios::out);
|
||||
|
|
|
@ -32,7 +32,7 @@ GPU::GPU(Memory& mem, EmulatorConfig& config) : mem(mem), config(config) {
|
|||
}
|
||||
#endif
|
||||
default: {
|
||||
Helpers::panic("Invalid rendering backend index: %d", static_cast<s8>(config.rendererType));
|
||||
Helpers::panic("Rendering backend not supported: %s", toString(config.rendererType));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,24 @@
|
|||
#include "renderer.hpp"
|
||||
|
||||
std::optional<RendererType> 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<u32, regNum>& internalRegs) : gpu(gpu), regs(internalRegs) {}
|
||||
Renderer::~Renderer() {}
|
Loading…
Add table
Reference in a new issue