Migrate RenderType string functions to static Renderer functions

Also fix some IWYU build errors
This commit is contained in:
Wunkolo 2023-07-18 10:02:07 -07:00
parent 528ed510c2
commit 0b60cf6901
4 changed files with 13 additions and 13 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <span>
#include <optional>
#include "PICA/pica_vertex.hpp"
#include "PICA/regs.hpp"
@ -12,9 +13,6 @@ enum class RendererType : s8 {
OpenGL = 1,
};
std::optional<RendererType> fromString(std::string inString);
const char* toString(RendererType rendererType);
class GPU;
class Renderer {
@ -37,6 +35,8 @@ class Renderer {
virtual ~Renderer();
static constexpr u32 vertexBufferSize = 0x10000;
static std::optional<RendererType> typeFromString(std::string inString);
static const char* typeToString(RendererType rendererType);
virtual void reset() = 0;
virtual void display() = 0; // Display the 3DS screen contents to the window

View file

@ -37,13 +37,13 @@ void EmulatorConfig::load(const std::filesystem::path& path) {
auto rendererResult = toml::expect<std::string>(gpu, "Renderer");
if (rendererResult.is_ok()) {
auto rendererName = rendererResult.unwrap();
if (auto configRendererType = fromString(rendererName); configRendererType.has_value()) {
if (auto configRendererType = Renderer::typeFromString(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());
Helpers::warn("Renderer not specified: %s\n", rendererResult.unwrap_err().c_str());
}
shaderJitEnabled = toml::find_or<toml::boolean>(gpu, "EnableShaderJIT", false);
@ -69,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"] = toString(rendererType);
data["GPU"]["Renderer"] = Renderer::typeToString(rendererType);
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
std::ofstream file(path, std::ios::out);

View file

@ -32,7 +32,7 @@ GPU::GPU(Memory& mem, EmulatorConfig& config) : mem(mem), config(config) {
}
#endif
default: {
Helpers::panic("Rendering backend not supported: %s", toString(config.rendererType));
Helpers::panic("Rendering backend not supported: %s", Renderer::typeToString(config.rendererType));
break;
}
}

View file

@ -1,6 +1,9 @@
#include "renderer.hpp"
std::optional<RendererType> fromString(std::string inString) {
Renderer::Renderer(GPU& gpu, const std::array<u32, regNum>& internalRegs) : gpu(gpu), regs(internalRegs) {}
Renderer::~Renderer() {}
std::optional<RendererType> Renderer::typeFromString(std::string inString) {
// case-insensitive
std::transform(inString.begin(), inString.end(), inString.begin(), [](unsigned char c) { return std::tolower(c); });
@ -12,13 +15,10 @@ std::optional<RendererType> fromString(std::string inString) {
return std::nullopt;
}
const char* toString(RendererType rendererType) {
const char* Renderer::typeToString(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() {}
}