GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 of 10, 0 excluded
0.0%
Functions:
0 of 1, 0 excluded
0.0%
Branches:
0 of 11, 0 excluded
0.0%

libs/core/src/eu/core/vertex_layout.h
Line Branch Exec Source
1 #pragma once
2
3 #include <map>
4 #include <set>
5 #include <optional>
6
7 namespace eu::core
8 {
9
10 /** \defgroup vertex-layout Vertex layout
11 * \brief Functions and types related to transforming generic mesh data to renderable data used by shaders.
12 * @{
13 */
14
15 /// Vertex source type, position, normal etc.
16 /// @todo change to include other texture coordinates and custom types that are created from scripts
17 enum class VertexType
18 {
19 // vertex based
20 position2xy,
21 position2xz,
22 position3,
23 normal3,
24 color3,
25 color4,
26 texture2,
27
28 // instance based
29 instance_transform
30 };
31
32
33 constexpr bool is_instance_based(VertexType v)
34 {
35 switch (v)
36 {
37 case VertexType::instance_transform: return true;
38 default: return false;
39 }
40 }
41
42 /// A not-yet-realised binding to a shader variable like `vec3 position`
43 struct VertexElementDescription
44 {
45 VertexType type;
46 std::string name;
47 };
48
49 /// Describes all vertex inputs a shader requires like `[vec3 position, vec3 normal, vec2 uv]`
50 /// \note It's invalid for this to contain duplicates, use \ref find_duplicates to find duplicates
51 using ShaderVertexAttributes = std::vector<VertexElementDescription>;
52
53 std::vector<VertexType> find_duplicates(const ShaderVertexAttributes& items);
54
55 /// A realized VertexElementDescription like `vec3 position` at gl shader position 3
56 struct CompiledVertexElement
57 {
58 VertexType type;
59 std::string name;
60 int index;
61 };
62
63 /// A realized VertexElementDescription without name like `vec3` at gl shader position 3
64 struct CompiledVertexElementNoName
65 {
66 VertexType type;
67 int index;
68 };
69
70 using VertexTypes = std::vector<VertexType>;
71
72 /// A list of CompiledVertexElement (for shader)
73 struct CompiledShaderVertexAttributes
74 {
75 std::vector<CompiledVertexElement> elements;
76 VertexTypes debug_types;
77 };
78
79 /// A list of CompiledVertexLayoutNoNameList (for geom)
80 struct CompiledGeomVertexAttributes
81 {
82 std::vector<CompiledVertexElementNoName> elements;
83 VertexTypes debug_types;
84 };
85
86 /// A mapping of the vertex type (position...) to the actual shader id (for more than one shader)
87 struct CompiledVertexTypeList
88 {
89 std::map<VertexType, int> indices;
90 VertexTypes debug_types;
91 int next_index;
92 };
93
94 /// A property for a shader used in instanced rendering.
95 /// @see \ref compile_shader_layout
96 struct InstanceProp
97 {
98 VertexType type;
99 std::string name;
100 };
101
102 [[nodiscard]]
103 CompiledShaderVertexAttributes compile_shader_layout(
104 const CompiledVertexTypeList& l,
105 const ShaderVertexAttributes& elements,
106 std::optional<InstanceProp> instance_prop,
107 std::optional<int> start_index
108 );
109
110 [[nodiscard]]
111 CompiledGeomVertexAttributes get_geom_layout(const CompiledVertexTypeList& l);
112
113 CompiledVertexTypeList compile_attribute_layouts(
114 const std::vector<VertexType>& base_layout, const std::vector<ShaderVertexAttributes>& descriptions
115 );
116
117 CompiledVertexTypeList compile_attribute_layouts(const std::vector<ShaderVertexAttributes>& descriptions);
118
119 /** @}
120 */
121
122 } // namespace eu::core
123
124 ✗ EU_FMT_ENUM_BEGIN(eu::core::VertexType, "???")
125 ✗ EU_FMT_ENUM_VAL(instance_transform);
126 ✗ EU_FMT_ENUM_VAL(position2xy);
127 ✗ EU_FMT_ENUM_VAL(position2xz);
128 ✗ EU_FMT_ENUM_VAL(position3);
129 ✗ EU_FMT_ENUM_VAL(normal3);
130 ✗ EU_FMT_ENUM_VAL(color3);
131 ✗ EU_FMT_ENUM_VAL(color4);
132 ✗ EU_FMT_ENUM_VAL(texture2);
133 ✗ EU_FMT_ENUM_END()
134