Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Formats.hpp
1#pragma once
2
3#include <stdint.h>
4
5namespace Grindstone::GraphicsAPI {
6 enum class TextureWrapMode : uint8_t {
7 Repeat = 0,
8 ClampToEdge,
9 ClampToBorder,
10 MirroredRepeat,
11 MirroredClampToEdge
12 };
13
14 enum class TextureFilter : uint8_t {
15 Nearest = 0,
16 Linear
17 };
18
19 enum class ClearMode : uint8_t {
20 Color = 1,
21 Depth = 2,
22 ColorAndDepth = 3,
23 Stencil = 4,
24 All = 7
25 };
26
27 enum class ColorFormat : uint8_t {
28 Invalid = 0,
29
30 R8,
31 RG8,
32 RGB8,
33 RGBA8,
34
35 R10G10B10A2,
36
37 R16,
38 R32,
39 RG16,
40 RG32,
41 RGB16,
42 RGBA16,
43 RGB32,
44 RGBA32,
45
46 RGB_DXT1,
47 RGBA_DXT1,
48 RGBA_DXT3,
49 RGBA_DXT5,
50
51 SRGB_DXT1,
52 SRGB_ALPHA_DXT1,
53 SRGB_ALPHA_DXT3,
54 SRGB_ALPHA_DXT5,
55
56 BC4,
57 BC6H
58 };
59
60 enum class DepthFormat : uint8_t {
61 None = 0,
62 D16,
63 D24,
64 D32,
65 //D16_STENCIL_8,
66 D24_STENCIL_8,
67 D32_STENCIL_8
68 //FORMAT_STENCIL_8
69 };
70
71 #define SHADER_STAGE_TYPES \
72 GSExpandEntry(Vertex, 1 << 0),\
73 GSExpandEntry(TesselationEvaluation, 1 << 1),\
74 GSExpandEntry(TesselationControl, 1 << 2),\
75 GSExpandEntry(Geometry, 1 << 3),\
76 GSExpandEntry(Fragment, 1 << 4),\
77 GSExpandEntry(Task, 1 << 5),\
78 GSExpandEntry(Mesh, 1 << 6),\
79 GSExpandEntry(Compute, 1 << 7)
80
81 enum class ShaderStage : uint8_t {
82 #define GSExpandEntry(key, bit) key
83 SHADER_STAGE_TYPES,
84 #undef GSExpandEntry
85 GraphicsCount = Compute,
86 Count
87 };
88
89 constexpr uint8_t numShaderGraphicStage = static_cast<uint8_t>(ShaderStage::GraphicsCount);
90 constexpr uint8_t numShaderTotalStage = static_cast<uint8_t>(ShaderStage::Count);
91
92 enum class ShaderStageBit : uint8_t {
93 None = 0,
94#define GSExpandEntry(key, bit) key = bit
95 SHADER_STAGE_TYPES,
96#undef GSExpandEntry
97 AllGraphics = Vertex | TesselationEvaluation | TesselationControl | Geometry | Fragment | Task | Mesh,
98 All = AllGraphics | Compute
99 };
100
101 constexpr const char* shaderStageNames[] = {
102 #define GSExpandEntry(key, bit) #key
103 SHADER_STAGE_TYPES
104 #undef GSExpandEntry
105 };
106
107 inline const char* GetShaderStageName(Grindstone::GraphicsAPI::ShaderStage stage) {
108 uint8_t index = static_cast<uint8_t>(stage);
109 if (index >= static_cast<uint8_t>(ShaderStage::Count)) {
110 return "Invalid";
111 }
112
113 return shaderStageNames[index];
114 }
115
116 enum class BindingType {
117 UniformBuffer,
118 Texture,
119 RenderTexture,
120 DepthTexture,
121 RenderTextureStorageImage
122 };
123
124#define BLEND_OPERATIONS_LIST \
125 GSExpandEntry(None),\
126 GSExpandEntry(Add),\
127 GSExpandEntry(Subtract),\
128 GSExpandEntry(ReverseSubtract),\
129 GSExpandEntry(Minimum),\
130 GSExpandEntry(Maximum),\
131 GSExpandEntry(Zero),\
132 GSExpandEntry(Source),\
133 GSExpandEntry(Destination),\
134 GSExpandEntry(SourceOver),\
135 GSExpandEntry(DestinationOver),\
136 GSExpandEntry(SourceIn),\
137 GSExpandEntry(DestinationIn),\
138 GSExpandEntry(SourceOut),\
139 GSExpandEntry(DestinationOut),\
140 GSExpandEntry(SourceAtop),\
141 GSExpandEntry(DestinationAtop),\
142 GSExpandEntry(XOR),\
143 GSExpandEntry(Multiply),\
144 GSExpandEntry(Screen),\
145 GSExpandEntry(Overlay),\
146 GSExpandEntry(Darken),\
147 GSExpandEntry(Lighten),\
148 GSExpandEntry(ColorDodge),\
149 GSExpandEntry(ColorBurn),\
150 GSExpandEntry(HardLight),\
151 GSExpandEntry(SoftLight),\
152 GSExpandEntry(Difference),\
153 GSExpandEntry(Exclusion),\
154 GSExpandEntry(Invert),\
155 GSExpandEntry(InvertRGB),\
156 GSExpandEntry(LinearDodge),\
157 GSExpandEntry(LinearBurn),\
158 GSExpandEntry(VividLight),\
159 GSExpandEntry(LinearLight),\
160 GSExpandEntry(PinLight),\
161 GSExpandEntry(HardMix),\
162 GSExpandEntry(HSLHue),\
163 GSExpandEntry(HSLSaturation),\
164 GSExpandEntry(HSLColor),\
165 GSExpandEntry(HSLLuminosity),\
166 GSExpandEntry(Plus),\
167 GSExpandEntry(PlusClamped),\
168 GSExpandEntry(PlusClampedAlpha),\
169 GSExpandEntry(PlusDark),\
170 GSExpandEntry(Minus),\
171 GSExpandEntry(MinusClamped),\
172 GSExpandEntry(Contrast),\
173 GSExpandEntry(InvertOVG),\
174 GSExpandEntry(Red),\
175 GSExpandEntry(Green),\
176 GSExpandEntry(Blue)
177
178 enum class BlendOperation : uint8_t {
179#define GSExpandEntry(key) key
180 BLEND_OPERATIONS_LIST,
181#undef GSExpandEntry
182 Count
183 };
184
185 constexpr const char* blendOperationNames[] = {
186 #define GSExpandEntry(key) #key
187 BLEND_OPERATIONS_LIST
188 #undef GSExpandEntry
189 };
190
191 inline const char* GetBlendOperationName(Grindstone::GraphicsAPI::BlendOperation op) {
192 uint8_t index = static_cast<uint8_t>(op);
193 if (index >= static_cast<uint8_t>(BlendOperation::Count)) {
194 return "Invalid";
195 }
196
197 return blendOperationNames[index];
198 }
199
200
201#define BLEND_FACTORS_LIST \
202 GSExpandEntry(Zero),\
203 GSExpandEntry(One),\
204 GSExpandEntry(SrcColor),\
205 GSExpandEntry(OneMinusSrcColor),\
206 GSExpandEntry(DstColor),\
207 GSExpandEntry(OneMinusDstColor),\
208 GSExpandEntry(SrcAlpha),\
209 GSExpandEntry(OneMinusSrcAlpha),\
210 GSExpandEntry(DstAlpha),\
211 GSExpandEntry(OneMinusDstAlpha),\
212 GSExpandEntry(ConstantColor),\
213 GSExpandEntry(OneMinusConstantColor),\
214 GSExpandEntry(ConstantAlpha),\
215 GSExpandEntry(OneMinusConstantAlpha),\
216 GSExpandEntry(SrcAlphaSaturate),\
217 GSExpandEntry(Src1Color),\
218 GSExpandEntry(OneMinusSrc1Color),\
219 GSExpandEntry(Src1Alpha),\
220 GSExpandEntry(OneMinusSrc1Alpha)
221
222 enum class BlendFactor : uint8_t {
223 #define GSExpandEntry(key) key
224 BLEND_FACTORS_LIST,
225 #undef GSExpandEntry
226 Count
227 };
228
229 constexpr const char* blendFactorNames[] = {
230 #define GSExpandEntry(key) #key
231 BLEND_FACTORS_LIST
232 #undef GSExpandEntry
233 };
234
235 inline const char* GetBlendFactorName(Grindstone::GraphicsAPI::BlendFactor factor) {
236 uint8_t index = static_cast<uint8_t>(factor);
237 if (index >= static_cast<uint8_t>(BlendFactor::Count)) {
238 return "Invalid";
239 }
240
241 return blendFactorNames[index];
242 }
243
244 struct BlendData {
245 BlendOperation colorOperation = BlendOperation::None;
246 BlendFactor colorFactorSrc = BlendFactor::One;
247 BlendFactor colorFactorDst = BlendFactor::One;
248
249 BlendOperation alphaOperation = BlendOperation::None;
250 BlendFactor alphaFactorSrc = BlendFactor::One;
251 BlendFactor alphaFactorDst = BlendFactor::One;
252
253 static BlendData NoBlending() {
254 return BlendData{
255 BlendOperation::None,
256 BlendFactor::One,
257 BlendFactor::One,
258
259 BlendOperation::None,
260 BlendFactor::One,
261 BlendFactor::One
262 };
263 };
264
265 static BlendData Additive() {
266 return BlendData{
267 BlendOperation::Add,
268 BlendFactor::One,
269 BlendFactor::One,
270
271 BlendOperation::Add,
272 BlendFactor::One,
273 BlendFactor::One
274 };
275 };
276
277 static BlendData AdditiveAlpha() {
278 return BlendData{
279 BlendOperation::Add,
280 BlendFactor::SrcAlpha,
281 BlendFactor::OneMinusSrcAlpha,
282
283 BlendOperation::Add,
284 BlendFactor::One,
285 BlendFactor::OneMinusSrcAlpha
286 };
287 };
288 };
289
290#define GEOMETRY_TYPES_LIST \
291 GSExpandEntry(Points),\
292 GSExpandEntry(Lines),\
293 GSExpandEntry(LineStrips),\
294 GSExpandEntry(LineLoops),\
295 GSExpandEntry(TriangleStrips),\
296 GSExpandEntry(TriangleFans),\
297 GSExpandEntry(Triangles),\
298 GSExpandEntry(LinesAdjacency),\
299 GSExpandEntry(TrianglesAdjacency),\
300 GSExpandEntry(TriangleStripsAdjacency),\
301 GSExpandEntry(Patches)
302
303 enum class GeometryType : uint8_t {
304 #define GSExpandEntry(key) key
305 GEOMETRY_TYPES_LIST,
306 #undef GSExpandEntry
307 Count
308 };
309
310 constexpr const char* geometryTypeNames[] = {
311 #define GSExpandEntry(key) #key
312 GEOMETRY_TYPES_LIST
313 #undef GSExpandEntry
314 };
315
316 inline const char* GetGeometryTypeName(Grindstone::GraphicsAPI::GeometryType stage) {
317 uint8_t index = static_cast<uint8_t>(stage);
318 if (index >= static_cast<uint8_t>(GeometryType::Count)) {
319 return "Invalid";
320 }
321
322 return geometryTypeNames[index];
323 }
324
325 enum class PolygonFillMode : uint8_t {
326 Point,
327 Line,
328 Fill
329 };
330
331 constexpr const char* polygonFillModeNames[] = {
332 "Point",
333 "Line",
334 "Fill"
335 };
336
337 inline const char* GetPolygonFillModeName(Grindstone::GraphicsAPI::PolygonFillMode mode) {
338 uint8_t index = static_cast<uint8_t>(mode);
339 if (index > static_cast<uint8_t>(PolygonFillMode::Fill)) {
340 return "Invalid";
341 }
342
343 return polygonFillModeNames[index];
344 }
345
346 enum class CompareOperation : uint8_t {
347 Never,
348 Less,
349 Equal,
350 LessOrEqual,
351 Greater,
352 NotEqual,
353 GreaterOrEqual,
354 Always
355 };
356
357 constexpr const char* compareOperationNames[] = {
358 #define GSExpandEntry(key, bit) #key
359 SHADER_STAGE_TYPES
360 #undef GSExpandEntry
361 };
362
363 inline const char* GetCompareOperationName(Grindstone::GraphicsAPI::CompareOperation op) {
364 uint8_t index = static_cast<uint8_t>(op);
365 if (index > static_cast<uint8_t>(CompareOperation::Always)) {
366 return "Invalid";
367 }
368
369 return compareOperationNames[index];
370 }
371
372 enum class ColorMask : uint8_t {
373 None = 0,
374 Red = 0x1,
375 Green = 0x2,
376 Blue = 0x4,
377 Alpha = 0x8,
378
379 RG = Red | Green,
380 RB = Red | Blue,
381 RA = Red | Alpha,
382 GB = Green | Blue,
383 GA = Green | Alpha,
384 BA = Blue | Alpha,
385
386 RGB = Red | Green | Blue,
387 RGA = Red | Green | Alpha,
388 RBA = Red | Blue | Alpha,
389 GBA = Green | Blue | Alpha,
390
391 RGBA = Red | Green | Blue | Alpha
392 };
393
394 constexpr const char* colorMaskNames[] = {
395 "None",
396 "R",
397 "G",
398 "RG",
399 "B",
400 "RB",
401 "GB",
402 "RGB",
403 "A",
404 "RA",
405 "GA",
406 "RGA",
407 "BA",
408 "RBA",
409 "GBA",
410 "RGBA"
411 };
412
413 inline const char* GetColorMaskName(Grindstone::GraphicsAPI::ColorMask colorMask) {
414 uint8_t index = static_cast<uint8_t>(colorMask);
415 if (index > static_cast<uint8_t>(ColorMask::RGBA)) {
416 return "Invalid";
417 }
418
419 return colorMaskNames[index];
420 }
421
422 enum class CullMode : uint8_t {
423 None = 0,
424 Front,
425 Back,
426 Both
427 };
428
429 constexpr const char* cullModeNames[] = {
430 "None",
431 "Front",
432 "Back",
433 "Both"
434 };
435
436 inline const char* GetCullModeName(Grindstone::GraphicsAPI::CullMode cullMode) {
437 uint8_t index = static_cast<uint8_t>(cullMode);
438 if (index > static_cast<uint8_t>(CullMode::Both)) {
439 return "Invalid";
440 }
441
442 return cullModeNames[index];
443 }
444}
445
446inline Grindstone::GraphicsAPI::ShaderStageBit operator~(const Grindstone::GraphicsAPI::ShaderStageBit stages) {
447 using ShaderStageBitType = uint8_t;
448 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(~static_cast<ShaderStageBitType>(stages));
449}
450
451inline Grindstone::GraphicsAPI::ShaderStageBit operator|(const Grindstone::GraphicsAPI::ShaderStageBit a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
452 using ShaderStageBitType = uint8_t;
453 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(static_cast<ShaderStageBitType>(a) | static_cast<ShaderStageBitType>(b));
454}
455
456inline Grindstone::GraphicsAPI::ShaderStageBit operator&(const Grindstone::GraphicsAPI::ShaderStageBit a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
457 using ShaderStageBitType = uint8_t;
458 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(static_cast<ShaderStageBitType>(a) & static_cast<ShaderStageBitType>(b));
459}
460
461inline Grindstone::GraphicsAPI::ShaderStageBit operator^(const Grindstone::GraphicsAPI::ShaderStageBit a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
462 using ShaderStageBitType = uint8_t;
463 return static_cast<Grindstone::GraphicsAPI::ShaderStageBit>(static_cast<ShaderStageBitType>(a) ^ static_cast<ShaderStageBitType>(b));
464}
465
466inline Grindstone::GraphicsAPI::ShaderStageBit& operator|=(Grindstone::GraphicsAPI::ShaderStageBit& a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
467 a = a | b;
468 return a;
469}
470
471inline Grindstone::GraphicsAPI::ShaderStageBit& operator&=(Grindstone::GraphicsAPI::ShaderStageBit& a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
472 a = a & b;
473 return a;
474}
475
476inline Grindstone::GraphicsAPI::ShaderStageBit& operator^=(Grindstone::GraphicsAPI::ShaderStageBit& a, const Grindstone::GraphicsAPI::ShaderStageBit b) {
477 a = a ^ b;
478 return a;
479}
480
481inline Grindstone::GraphicsAPI::ColorMask operator~(const Grindstone::GraphicsAPI::ColorMask stages) {
482 using ColorMaskType = uint8_t;
483 return static_cast<Grindstone::GraphicsAPI::ColorMask>(~static_cast<ColorMaskType>(stages));
484}
485
486inline Grindstone::GraphicsAPI::ColorMask operator|(const Grindstone::GraphicsAPI::ColorMask a, const Grindstone::GraphicsAPI::ColorMask b) {
487 using ColorMaskType = uint8_t;
488 return static_cast<Grindstone::GraphicsAPI::ColorMask>(static_cast<ColorMaskType>(a) | static_cast<ColorMaskType>(b));
489}
490
491inline Grindstone::GraphicsAPI::ColorMask operator&(const Grindstone::GraphicsAPI::ColorMask a, const Grindstone::GraphicsAPI::ColorMask b) {
492 using ColorMaskType = uint8_t;
493 return static_cast<Grindstone::GraphicsAPI::ColorMask>(static_cast<ColorMaskType>(a) & static_cast<ColorMaskType>(b));
494}
495
496inline Grindstone::GraphicsAPI::ColorMask operator^(const Grindstone::GraphicsAPI::ColorMask a, const Grindstone::GraphicsAPI::ColorMask b) {
497 using ColorMaskType = uint8_t;
498 return static_cast<Grindstone::GraphicsAPI::ColorMask>(static_cast<ColorMaskType>(a) ^ static_cast<ColorMaskType>(b));
499}
500
501inline Grindstone::GraphicsAPI::ColorMask& operator|=(Grindstone::GraphicsAPI::ColorMask& a, const Grindstone::GraphicsAPI::ColorMask b) {
502 a = a | b;
503 return a;
504}
505
506inline Grindstone::GraphicsAPI::ColorMask& operator&=(Grindstone::GraphicsAPI::ColorMask& a, const Grindstone::GraphicsAPI::ColorMask b) {
507 a = a & b;
508 return a;
509}
510
511inline Grindstone::GraphicsAPI::ColorMask& operator^=(Grindstone::GraphicsAPI::ColorMask& a, const Grindstone::GraphicsAPI::ColorMask b) {
512 a = a ^ b;
513 return a;
514}
Definition Formats.hpp:244