aboutsummaryrefslogtreecommitdiff
path: root/source/30-game
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-05-30 23:42:02 -0700
committerrtk0c <[email protected]>2022-05-30 23:42:02 -0700
commit8a0f2cd0b398ee0b7740e44a0e5fb2f75d090ccb (patch)
tree2838fd73313948f4db156b60c079468314eb1564 /source/30-game
parent3571627772b245e3e1a45b66e9a8fe4d50d06c8c (diff)
Changeset: 59 Integrate enum codegen into the actual project
Diffstat (limited to 'source/30-game')
-rw-r--r--source/30-game/GraphicsTags.cpp41
-rw-r--r--source/30-game/GraphicsTags.hpp23
-rw-r--r--source/30-game/Shader.cpp32
3 files changed, 31 insertions, 65 deletions
diff --git a/source/30-game/GraphicsTags.cpp b/source/30-game/GraphicsTags.cpp
index 522a58f..eb9a079 100644
--- a/source/30-game/GraphicsTags.cpp
+++ b/source/30-game/GraphicsTags.cpp
@@ -6,43 +6,6 @@
using namespace std::literals;
-std::string_view Tags::NameOf(VertexElementSemantic semantic) {
- switch (semantic) {
- case VES_Position: return "Position"sv;
- case VES_BlendWeights: return "BlendWeights"sv;
- case VES_BlendIndices: return "BlendIndices"sv;
- case VES_Normal: return "Normal"sv;
- case VES_Color1: return "Color1"sv;
- case VES_Color2: return "Color2"sv;
- case VES_Color3: return "Color3"sv;
- case VES_TexCoords1: return "TexCoords1"sv;
- case VES_TexCoords2: return "TexCoords2"sv;
- case VES_TexCoords3: return "TexCoords3"sv;
- case VES_Binormal: return "Binormal"sv;
- case VES_Tangent: return "Tangent"sv;
- case VES_Generic: return "Generic"sv;
- case VES_COUNT: break;
- }
- return std::string_view();
-}
-
-Tags::VertexElementSemantic Tags::FindVertexElementSemantic(std::string_view name) {
- if (name == "Position"sv) return VES_Position;
- if (name == "BlendWeights"sv) return VES_BlendWeights;
- if (name == "BlendIndices"sv) return VES_BlendIndices;
- if (name == "Normal"sv) return VES_Normal;
- if (name == "Color1"sv) return VES_Color1;
- if (name == "Color2"sv) return VES_Color2;
- if (name == "Color3"sv) return VES_Color3;
- if (name == "TexCoords1"sv) return VES_TexCoords1;
- if (name == "TexCoords2"sv) return VES_TexCoords2;
- if (name == "TexCoords3"sv) return VES_TexCoords3;
- if (name == "Binormal"sv) return VES_Binormal;
- if (name == "Tangent"sv) return VES_Tangent;
- if (name == "Generic"sv) return VES_Generic;
- return VES_COUNT;
-}
-
int Tags::SizeOf(VertexElementType type) {
switch (type) {
case VET_Float1:
@@ -287,7 +250,7 @@ struct GLTypeInfo {
} const kGLTypeInfo;
} // namespace ProjectBrussel_UNITY_ID
-std::string_view Tags::NameOfGLType(GLenum value) {
+std::string_view Tags::GLTypeToString(GLenum value) {
using namespace ProjectBrussel_UNITY_ID;
auto iter = kGLTypeInfo.enum2Name.find(value);
if (iter != kGLTypeInfo.enum2Name.end()) {
@@ -297,7 +260,7 @@ std::string_view Tags::NameOfGLType(GLenum value) {
}
}
-GLenum Tags::FindGLType(std::string_view name) {
+GLenum Tags::GLTypeFromString(std::string_view name) {
using namespace ProjectBrussel_UNITY_ID;
auto iter = kGLTypeInfo.name2Enum.find(name);
if (iter != kGLTypeInfo.name2Enum.end()) {
diff --git a/source/30-game/GraphicsTags.hpp b/source/30-game/GraphicsTags.hpp
index f83b99c..cdf79eb 100644
--- a/source/30-game/GraphicsTags.hpp
+++ b/source/30-game/GraphicsTags.hpp
@@ -1,12 +1,12 @@
#pragma once
+#include <MacrosCodegen.hpp>
+
#include <glad/glad.h>
#include <limits>
#include <string>
#include <string_view>
-#include <MacrosCodegen.hpp>
-
namespace Tags {
/// Vertex element semantics, used to identify the meaning of vertex buffer contents
enum VertexElementSemantic {
@@ -36,9 +36,6 @@ enum VertexElementSemantic {
};
BRUSSEL_ENUM(VertexElementSemantic, ToString FromString ExcludeHeuristics);
-std::string_view NameOf(VertexElementSemantic semantic);
-VertexElementSemantic FindVertexElementSemantic(std::string_view name);
-
enum VertexElementType {
VET_Float1,
VET_Float2,
@@ -66,17 +63,16 @@ enum VertexElementType {
VET_Uint4,
VET_Byte4, /// signed bytes
- VET_NORM_BEGIN,
- VET_Byte4Norm = VET_NORM_BEGIN, /// signed bytes (normalized to -1..1)
+ VET_Byte4Norm, /// signed bytes (normalized to -1..1)
VET_Ubyte4Norm, /// unsigned bytes (normalized to 0..1)
VET_Short2Norm, /// signed shorts (normalized to -1..1)
VET_Short4Norm,
VET_Ushort2Norm, /// unsigned shorts (normalized to 0..1)
VET_Ushort4Norm,
- VET_NORM_END = VET_Ushort4Norm,
};
-// TODO this enum isn't continuous, not supported yet
-// BRUSSEL_ENUM(VertexElementType, ToString FromString ExcludeHeuristics);
+constexpr auto VET_NORM_BEGIN = VET_Byte4Norm;
+constexpr auto VET_NORM_END = VET_Ushort4Norm;
+BRUSSEL_ENUM(VertexElementType, ToString FromString ExcludeHeuristics);
int SizeOf(VertexElementType type);
int VectorLenOf(VertexElementType type);
@@ -95,11 +91,12 @@ enum TexFilter {
TF_Linear,
TF_Nearest,
};
+BRUSSEL_ENUM(TexFilter, ToString FromString ExcludeHeuristics);
-std::string_view NameOfGLType(GLenum);
-GLenum FindGLType(std::string_view name);
+std::string_view GLTypeToString(GLenum);
+GLenum GLTypeFromString(std::string_view name);
-constexpr GLuint kInvalidLocation = std::numeric_limits<GLuint>::max();
+constexpr auto kInvalidLocation = std::numeric_limits<GLuint>::max();
} // namespace Tags
#include <generated/GraphicsTags.gh.inl>
diff --git a/source/30-game/Shader.cpp b/source/30-game/Shader.cpp
index 48881f0..4a58635 100644
--- a/source/30-game/Shader.cpp
+++ b/source/30-game/Shader.cpp
@@ -1,9 +1,11 @@
#include "Shader.hpp"
#include "AppConfig.hpp"
-#include "RapidJsonHelper.hpp"
-#include "ScopeGuard.hpp"
-#include "Utils.hpp"
+
+#include <Metadata.hpp>
+#include <RapidJsonHelper.hpp>
+#include <ScopeGuard.hpp>
+#include <Utils.hpp>
#include <imgui.h>
#include <misc/cpp/imgui_stdlib.h>
@@ -16,20 +18,20 @@
using namespace std::literals;
void ShaderMathVariable::ShowInfo() const {
- ImGui::BulletText("Location: %d\nName: %s\nSemantic: %s\nType: %s %dx%d",
+ ImGui::BulletText("Location: %d\nName: %s\nSemantic: %.*s\nType: %.*s %dx%d",
location,
name.c_str(),
- Tags::NameOf(semantic).data(),
- Tags::NameOfGLType(scalarType).data(),
+ PRINTF_STRING_VIEW(Metadata::EnumToString(semantic)),
+ PRINTF_STRING_VIEW(Tags::GLTypeToString(scalarType)),
width,
height);
}
void ShaderSamplerVariable::ShowInfo() const {
- ImGui::BulletText("Location: %d\nName: %s\nSemantic: %s\nType: Sampler",
+ ImGui::BulletText("Location: %d\nName: %s\nSemantic: %.*s\nType: Sampler",
location,
name.c_str(),
- Tags::NameOf(semantic).data());
+ PRINTF_STRING_VIEW(Metadata::EnumToString(semantic)));
}
bool ShaderThingId::IsValid() const {
@@ -527,18 +529,22 @@ bool Shader::IsValid() const {
namespace ProjectBrussel_UNITY_ID {
void WriteShaderVariable(rapidjson::Value& value, rapidjson::Document& root, const ShaderVariable& var) {
value.AddMember("Name", var.name, root.GetAllocator());
- value.AddMember("Semantic", rapidjson::StringRef(Tags::NameOf(var.semantic)), root.GetAllocator());
+ value.AddMember("Semantic", rapidjson::StringRef(Metadata::EnumToString(var.semantic)), root.GetAllocator());
value.AddMember("OpenGLLocation", var.location, root.GetAllocator());
}
bool ReadShaderVariable(const rapidjson::Value& value, ShaderVariable& var) {
+ using namespace Tags;
+
BRUSSEL_JSON_GET(value, "Name", std::string, var.name, return false);
{ // Semantic
auto rvSemantic = rapidjson::GetProperty(value, rapidjson::kStringType, "Semantic"sv);
if (!rvSemantic) {
- var.semantic = Tags::VES_Generic;
+ var.semantic = VES_Generic;
} else {
- var.semantic = Tags::FindVertexElementSemantic(rapidjson::AsStringView(*rvSemantic));
+ auto str = rapidjson::AsStringView(*rvSemantic);
+ auto lookup = Metadata::EnumFromString<VertexElementSemantic>(str);
+ var.semantic = lookup.value_or(VES_Generic);
}
}
BRUSSEL_JSON_GET_DEFAULT(value, "OpenGLLocation", int, var.location, 0);
@@ -547,7 +553,7 @@ bool ReadShaderVariable(const rapidjson::Value& value, ShaderVariable& var) {
void WriteShaderMathVariable(rapidjson::Value& value, rapidjson::Document& root, const ShaderMathVariable& var) {
WriteShaderVariable(value, root, var);
- value.AddMember("ScalarType", rapidjson::StringRef(Tags::NameOfGLType(var.scalarType)), root.GetAllocator());
+ value.AddMember("ScalarType", rapidjson::StringRef(Tags::GLTypeToString(var.scalarType)), root.GetAllocator());
value.AddMember("Width", var.width, root.GetAllocator());
value.AddMember("Height", var.height, root.GetAllocator());
value.AddMember("ArrayLength", var.arrayLength, root.GetAllocator());
@@ -558,7 +564,7 @@ bool ReadShaderMathVariable(const rapidjson::Value& value, ShaderMathVariable& v
{
auto rvScalar = rapidjson::GetProperty(value, rapidjson::kStringType, "ScalarType"sv);
if (!rvScalar) return false;
- var.scalarType = Tags::FindGLType(rapidjson::AsStringView(*rvScalar));
+ var.scalarType = Tags::GLTypeFromString(rapidjson::AsStringView(*rvScalar));
}
BRUSSEL_JSON_GET(value, "Width", int, var.width, return false);
BRUSSEL_JSON_GET(value, "Height", int, var.height, return false);