Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Token.hpp
1#pragma once
2
3#include <string_view>
4#include <filesystem>
5#include <vector>
6#include <map>
7
8#include <Common/Graphics/Formats.hpp>
9
10#include "ParameterType.hpp"
11
12#define TOKEN_LIST \
13E(Invalid)\
14E(EndOfFile)\
15E(Include)\
16E(Parameters)\
17E(Abstract)\
18E(ComputeSet)\
19E(PipelineSet)\
20E(Clones)\
21E(Inherits)\
22E(ShaderBlock)\
23E(RequiresBlocks)\
24E(RenderQueue)\
25E(CommentMultiLine)\
26E(Comment)\
27E(Identifier)\
28E(String)\
29E(Number)\
30E(Boolean)\
31E(Colon)\
32E(SemiColon)\
33E(Comma)\
34E(OpenSquareBrace)\
35E(CloseSquareBrace)\
36E(OpenCurly)\
37E(CloseCurly)\
38E(OpenParenthesis)\
39E(CloseParenthesis)\
40E(ShaderHlsl)\
41E(ShaderGlsl)\
42E(Name)\
43E(Properties)\
44E(Configuration)\
45E(Pass)\
46E(StageKey)\
47E(ShaderEntrypoint)\
48E(RendererTags)\
49E(PassTags)\
50E(Attachments)\
51E(ColorMask)\
52E(GeometryTypeKey)\
53E(FillModeKey)\
54E(CullModeKey)\
55E(DepthBiasKey)\
56E(DepthWriteKey)\
57E(DepthTestKey)\
58E(DepthClampKey)\
59E(DepthCompareOpKey)\
60E(BlendColorKey)\
61E(BlendAlphaKey)\
62E(StageValue)\
63E(GeometryTypeValue)\
64E(FillModeValue)\
65E(CullModeValue)\
66E(CompareOperationValue)\
67E(BlendOperationValue)\
68E(BlendFactorValue)\
69E(BlendPresetKey)\
70E(BlendPresetValue)\
71E(Parameter)
72
73enum class Token : uint8_t {
74#define E(val) val,
75 TOKEN_LIST
76#undef E
77};
78
79constexpr const char* tokenStrings[] = {
80#define E(val) #val,
81 TOKEN_LIST
82#undef E
83};
84
85enum class BlendPreset : uint8_t {
86 Opaque,
87 Translucent,
88 Additive,
89 Multiplicative,
90 Premultiply
91};
92
93class TokenData {
94public:
95 union Data {
96 std::string_view string;
97 bool boolean;
98 float number;
99 Grindstone::GraphicsAPI::GeometryType geometryType;
100 Grindstone::GraphicsAPI::PolygonFillMode polygonFillMode;
101 Grindstone::GraphicsAPI::CullMode cullMode;
102 Grindstone::GraphicsAPI::CompareOperation compareOperation;
103 Grindstone::GraphicsAPI::BlendOperation blendOperation;
104 Grindstone::GraphicsAPI::BlendFactor blendFactor;
105 Grindstone::GraphicsAPI::ShaderStage shaderStage;
106 BlendPreset blendPreset;
107 ParameterType parameterType;
108
109 Data() : boolean(false) {}
110 Data(bool boolean) : boolean(boolean) {}
111 Data(float number) : number(number) {}
112 Data(std::string_view string) : string(string) {}
113 Data(Grindstone::GraphicsAPI::CullMode cullMode) : cullMode(cullMode) {}
114 Data(Grindstone::GraphicsAPI::CompareOperation compareOperation) : compareOperation(compareOperation) {}
115 Data(Grindstone::GraphicsAPI::BlendOperation blendOperation) : blendOperation(blendOperation) {}
116 Data(Grindstone::GraphicsAPI::BlendFactor blendFactor) : blendFactor(blendFactor) {}
117 Data(Grindstone::GraphicsAPI::GeometryType geometryType) : geometryType(geometryType) {}
118 Data(Grindstone::GraphicsAPI::PolygonFillMode polygonFillMode) : polygonFillMode(polygonFillMode) {}
119 Data(Grindstone::GraphicsAPI::ShaderStage shaderStage) : shaderStage(shaderStage) {}
120 Data(BlendPreset blendPreset) : blendPreset(blendPreset) {}
121 Data(ParameterType parameterType) : parameterType(parameterType) {}
122 };
123
124 Token token;
125 Data data;
126 const std::filesystem::path& path;
127 uint32_t line;
128 uint32_t column;
129
130 TokenData(Token token, const std::filesystem::path& path, uint32_t line, uint32_t column) noexcept;
131 TokenData(Token token, Data data, const std::filesystem::path& path, uint32_t line, uint32_t column) noexcept;
132 TokenData(const TokenData& other) noexcept;
133 TokenData(TokenData&& other) noexcept;
134
135 static TokenData CommentMultiLine(std::string_view string, const std::filesystem::path& path, uint32_t line, uint32_t column);
136 static TokenData Comment(std::string_view string, const std::filesystem::path& path, uint32_t line, uint32_t column);
137 static TokenData Identifier(std::string_view string, const std::filesystem::path& path, uint32_t line, uint32_t column);
138 static TokenData String(std::string_view string, const std::filesystem::path& path, uint32_t line, uint32_t column);
139 static TokenData Boolean(bool boolean, const std::filesystem::path& path, uint32_t line, uint32_t column);
140 static TokenData Number(float number, const std::filesystem::path& path, uint32_t line, uint32_t column);
141 static TokenData ShaderGlsl(std::string_view string, const std::filesystem::path& path, uint32_t line, uint32_t column);
142 static TokenData ShaderHlsl(std::string_view string, const std::filesystem::path& path, uint32_t line, uint32_t column);
143 static TokenData GeometryTypeValue(Grindstone::GraphicsAPI::GeometryType mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
144 static TokenData FillModeValue(Grindstone::GraphicsAPI::PolygonFillMode mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
145 static TokenData CullModeValue(Grindstone::GraphicsAPI::CullMode mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
146 static TokenData CompareOperationValue(Grindstone::GraphicsAPI::CompareOperation mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
147 static TokenData BlendOperationValue(Grindstone::GraphicsAPI::BlendOperation mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
148 static TokenData BlendFactorValue(Grindstone::GraphicsAPI::BlendFactor mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
149 static TokenData ShaderStageValue(Grindstone::GraphicsAPI::ShaderStage mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
150 static TokenData BlendPresetValue(BlendPreset mode, const std::filesystem::path& path, uint32_t line, uint32_t column);
151 static TokenData Parameter(ParameterType parameterType, const std::filesystem::path& path, uint32_t line, uint32_t column);
152};
153
154using TokenList = std::vector<TokenData>;
155
156extern std::map<std::string_view, Token> stringToTokenMap;
157
Definition Token.hpp:95