Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
vertex.h
1#ifndef OE_SCENE_VERTEX_H
2#define OE_SCENE_VERTEX_H
3
4#include <glm/vec2.hpp>
5#include <glm/vec3.hpp>
6#include <glm/vec4.hpp>
7
8namespace oe::scene
9{
13 typedef uint32_t index_t;
14
18 template<typename T>
19 concept IsSimpleVertex = requires(T t)
20 {
21 {t.position} -> std::same_as<glm::vec3&>;
22 };
23
27 template<typename T>
28 concept IsComplexVertex = requires(T t)
29 {
30 {t.position} -> std::same_as<glm::vec3&>;
31 {t.tex_coords_0} -> std::same_as<glm::vec2&>;
32 {t.normal} -> std::same_as<glm::vec3&>;
33 };
34
38 template<typename T>
39 concept IsVertexWithTangents = requires(T t)
40 {
41 {t.normal} -> std::same_as<glm::vec3&>;
42 {t.tangent} -> std::same_as<glm::vec3&>;
43 {t.bitangent} -> std::same_as<glm::vec3&>;
44 };
45
49 template<typename T>
50 concept IsVertexWithTexcoords = requires(T t)
51 {
52 {t.tex_coords_0} -> std::same_as<glm::vec2&>;
53 {t.tex_coords_1} -> std::same_as<glm::vec2&>;
54 };
55
59 template<typename T>
60 concept IsSkinnedVertex = requires(T t)
61 {
62 {t.bones} -> std::same_as<glm::ivec4&>;
63 {t.weights} -> std::same_as<glm::vec4&>;
64 };
65
69 struct Vertex
70 {
72 glm::vec3 position = glm::vec3(0.0);
73
75 glm::vec2 tex_coords_0 = glm::vec2(0.0);
76
78 glm::vec2 tex_coords_1 = glm::vec2(0.0);
79
81 glm::vec4 color = glm::vec4(1.0);
82
84 glm::vec3 normal = glm::vec3(0.0);
85
87 glm::vec3 tangent = glm::vec3(0.0);
88
93 glm::vec3 bitangent = glm::vec3(0.0);
94
95 bool operator==(const Vertex& other) const
96 {
97 return this->position == other.position;
98 }
99
100 friend Vertex operator*(const Vertex& lhs, const float ratio)
101 {
102 return Vertex({
103 .position = lhs.position * ratio,
104 .tex_coords_0 = lhs.tex_coords_0 * ratio,
105 .tex_coords_1 = lhs.tex_coords_1 * ratio,
106 .color = lhs.color * ratio,
107 .normal = lhs.normal * ratio,
108 .tangent = lhs.tangent * ratio,
109 .bitangent = lhs.bitangent * ratio
110 });
111 }
112
113 friend Vertex operator*(const float ratio, const Vertex& rhs)
114 {
115 // Use above "operator*" because 'Vertex multiplication by a ratio' is commutative
116 return rhs * ratio;
117 }
118
119 friend Vertex operator+(const Vertex& lhs, const Vertex& rhs)
120 {
121 return Vertex({
122 .position = lhs.position + rhs.position,
123 .tex_coords_0 = lhs.tex_coords_0 + rhs.tex_coords_0,
124 .tex_coords_1 = lhs.tex_coords_1 + rhs.tex_coords_1,
125 .color = lhs.color + rhs.color,
126 .normal = lhs.normal + rhs.normal,
127 .tangent = lhs.tangent + rhs.tangent,
128 .bitangent = lhs.bitangent + rhs.bitangent
129 });
130 }
131 };
132
137 {
139 glm::vec3 position = glm::vec3(0.0);
140
142 glm::vec2 tex_coords_0 = glm::vec2(0.0);
143
145 glm::vec2 tex_coords_1 = glm::vec2(0.0);
146
148 glm::vec4 color = glm::vec4(1.0);
149
151 glm::vec3 normal = glm::vec3(0.0);
152
154 glm::vec3 tangent = glm::vec3(0.0);
155
160 glm::vec3 bitangent = glm::vec3(0.0);
161
163 glm::ivec4 bones = glm::ivec4(0);
164
166 glm::vec4 weights = glm::vec4(0.0);
167
168 bool operator==(const Vertex& other) const
169 {
170 return this->position == other.position;
171 }
172
173 friend SkinnedVertex operator*(const SkinnedVertex& lhs, const float ratio)
174 {
175 return SkinnedVertex({
176 .position = lhs.position * ratio,
177 .tex_coords_0 = lhs.tex_coords_1 * ratio,
178 .tex_coords_1 = lhs.tex_coords_1 * ratio,
179 .color = lhs.color * ratio,
180 .normal = lhs.normal * ratio,
181 .tangent = lhs.tangent * ratio,
182 .bitangent = lhs.bitangent * ratio
183 });
184 }
185
186 friend SkinnedVertex operator*(const float ratio, const SkinnedVertex& rhs)
187 {
188 // Use above "operator*" because 'Vertex multiplication by a ratio' is commutative
189 return rhs * ratio;
190 }
191
192 friend SkinnedVertex operator+(const SkinnedVertex& lhs, const SkinnedVertex& rhs)
193 {
194 return SkinnedVertex({
195 .position = lhs.position + rhs.position,
196 .tex_coords_0 = lhs.tex_coords_0 + rhs.tex_coords_0,
197 .tex_coords_1 = lhs.tex_coords_1 + rhs.tex_coords_1,
198 .color = lhs.color + rhs.color,
199 .normal = lhs.normal + rhs.normal,
200 .tangent = lhs.tangent + rhs.tangent,
201 .bitangent = lhs.bitangent + rhs.bitangent
202 });
203 }
204 };
205}
206
207#endif
Definition vertex.h:28
Definition vertex.h:19
Definition vertex.h:60
Definition vertex.h:39
Definition vertex.h:50
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19
uint32_t index_t
Definition vertex.h:13
Definition vertex.h:137
glm::vec4 weights
Definition vertex.h:166
glm::vec3 bitangent
Definition vertex.h:160
glm::ivec4 bones
Definition vertex.h:163
glm::vec4 color
Definition vertex.h:148
glm::vec3 position
Definition vertex.h:139
glm::vec2 tex_coords_1
Definition vertex.h:145
glm::vec2 tex_coords_0
Definition vertex.h:142
glm::vec3 tangent
Definition vertex.h:154
glm::vec3 normal
Definition vertex.h:151
Definition vertex.h:70
glm::vec2 tex_coords_0
Definition vertex.h:75
glm::vec3 tangent
Definition vertex.h:87
glm::vec3 bitangent
Definition vertex.h:93
glm::vec3 normal
Definition vertex.h:84
glm::vec2 tex_coords_1
Definition vertex.h:78
glm::vec3 position
Definition vertex.h:72
glm::vec4 color
Definition vertex.h:81