CPP-TOOLBOX
Loading...
Searching...
No Matches
draw_info.hpp
Go to the documentation of this file.
1#ifndef DRAW_INFO_HPP
2#define DRAW_INFO_HPP
3
4#include <glm/glm.hpp>
5#include <string>
6#include <vector>
8
9// NOTE: draw info is a namespace containing representations of data that eventually will land on the GPU
10namespace draw_info {
11
12template <typename T>
13concept IVPLike = requires(T t) {
14 // Must have these data members
15 { t.xyz_positions } -> std::convertible_to<std::vector<glm::vec3>>;
16 { t.indices } -> std::convertible_to<std::vector<unsigned int>>;
17 { t.id } -> std::convertible_to<unsigned int>;
18
19 { t.transform };
20 { t.buffer_modification_tracker };
21};
22
23// NOTE: for every draw info object, we only ever create one if we want to draw it to the screen, additionally something
24// can only get drawn to the screen if its geometry gets buffered onto the graphics card. In the client code we provide
25// this class that keeps track of if we've modified the draw info class on the cpu side of things, then while rendering
26// we can check this flag and then rebuffer the "dirty" information automatically.
28 public:
29 void just_modified() { has_been_modified_since_last_buffered_ = true; }
31 has_data_in_buffer_ = true;
32 has_been_modified_since_last_buffered_ = false;
33 }
34
35 void free_buffered_data() { has_data_in_buffer_ = false; }
36 bool has_data_in_buffer() { return has_data_in_buffer_; }
37
39 if (has_data_in_buffer_) {
40 return has_been_modified_since_last_buffered_;
41 } else {
42 // NOTE: if there's no data in the buffer yet, then it has not been modified since last buffering because
43 // there was no last buffering.
44 return false;
45 }
46 }
47 std::string to_string() const {
48 return "BufferModificationTracker { " + std::string("has_data_in_buffer = ") +
49 (has_data_in_buffer_ ? "true" : "false") + ", " +
50 std::string("has_been_modified_since_last_buffered_ = ") +
51 (has_been_modified_since_last_buffered_ ? "true" : "false") + " }";
52 }
53
54 private:
55 bool has_data_in_buffer_ = false;
56 bool has_been_modified_since_last_buffered_ = false;
57};
58
59class IVPNormals;
60
62 public:
64 IndexedVertexPositions(std::vector<unsigned int> indices, std::vector<glm::vec3> xyz_positions, int id = -1)
66
68
70 int id;
71 std::vector<unsigned int> indices;
72 std::vector<glm::vec3> xyz_positions;
73
75
76 friend std::ostream &operator<<(std::ostream &os, const IndexedVertexPositions &ivp) {
77 os << "IndexedVertexPositions("
78 << "indices.size=" << ivp.indices.size() << ", "
79 << "xyz_positions.size=" << ivp.xyz_positions.size() << ", "
80 << "transform=" << ivp.transform << ")";
81 return os;
82 }
83};
84
85class IVPNormals { // IVP with normals
86 public:
87 IVPNormals() : id(-1) {};
88 IVPNormals(std::vector<unsigned int> indices, std::vector<glm::vec3> xyz_positions, std::vector<glm::vec3> normals,
89 int id = -1)
92 int id;
93 std::vector<unsigned int> indices;
94 std::vector<glm::vec3> xyz_positions;
95 std::vector<glm::vec3> normals;
96
98
99 friend std::ostream &operator<<(std::ostream &os, const IVPNormals &ivp) {
100 os << "IndexedVertexPositions("
101 << "indices.size=" << ivp.indices.size() << ", "
102 << "xyz_positions.size=" << ivp.xyz_positions.size() << ", "
103 << "normals.size=" << ivp.normals.size() << ", "
104 << "transform=" << ivp.transform << ")";
105 return os;
106 }
107};
108
109IndexedVertexPositions ivpn_to_ivpn(const IVPNormals &ivpn);
110
112 public:
114 TransformedIVPGroup(std::vector<IndexedVertexPositions> ivps, int id) : ivps(std::move(ivps)), id(id) {}
115 int id;
116 std::vector<IndexedVertexPositions> ivps;
118};
119
120class IVPColor { // IVPSC
121 public:
122 IVPColor() : id(-1) {};
123
125 : IVPColor(ivp, std::vector<glm::vec3>(ivp.xyz_positions.size(), color), ivp.id) {}
126
129
130 IVPColor(std::vector<unsigned int> indices, std::vector<glm::vec3> xyz_positions, std::vector<glm::vec3> rgb_colors,
131 int id = -1)
133
134 // TODO: remove
136 int id;
137 std::vector<unsigned int> indices;
138 std::vector<glm::vec3> xyz_positions;
139 std::vector<glm::vec3> rgb_colors;
140
142};
143
145 public:
146 IVPNColor(IVPNormals ivpn, glm::vec3 color)
147 : IVPNColor(ivpn, std::vector<glm::vec3>(ivpn.xyz_positions.size(), color)) {}
148
149 IVPNColor(IVPNormals ivpn, std::vector<glm::vec3> rgb_colors)
151 id(ivpn.id), rgb_colors(rgb_colors) {};
152 IVPNColor(std::vector<unsigned int> indices, std::vector<glm::vec3> xyz_positions, std::vector<glm::vec3> normals,
153 std::vector<glm::vec3> colors, int id = -1)
156 int id;
157 std::vector<unsigned int> indices;
158 std::vector<glm::vec3> xyz_positions;
159 std::vector<glm::vec3> normals;
160 std::vector<glm::vec3> rgb_colors;
161
163
164 friend std::ostream &operator<<(std::ostream &os, const IVPNColor &ivp) {
165 os << "IndexedVertexPositions("
166 << "indices.size=" << ivp.indices.size() << ", "
167 << "xyz_positions.size=" << ivp.xyz_positions.size() << ", "
168 << "normals.size=" << ivp.normals.size() << ", "
169 << "rgb_colors.size=" << ivp.rgb_colors.size() << ", "
170 << "transform=" << ivp.transform << ")";
171 return os;
172 }
173};
174
175class IVPTextured { // IVPT
176 public:
177 IVPTextured(std::vector<unsigned int> indices, std::vector<glm::vec3> xyz_positions,
178 std::vector<glm::vec2> texture_coordinates, const std::string &texture = "",
181 texture_path(texture), id(id) {};
182 // TODO: remove this just make a new class for it wrapping like the tig
184 int id;
185 std::vector<unsigned int> indices;
186 std::vector<glm::vec3> xyz_positions;
187 std::vector<glm::vec2> texture_coordinates;
188 std::string texture_path;
189
191};
192
193class IVPNTextured { // IVP Normals
194 public:
195 IVPNTextured(std::vector<unsigned int> indices, std::vector<glm::vec3> xyz_positions,
196 std::vector<glm::vec3> normals, std::vector<glm::vec2> texture_coordinates,
197 const std::string &texture = "")
199 texture_path(texture) {};
201 std::vector<unsigned int> indices;
202 std::vector<glm::vec3> xyz_positions;
203 std::vector<glm::vec3> normals;
204 std::vector<glm::vec2> texture_coordinates;
205 std::string texture_path;
206
208};
209
210class IVPTexturePacked { // IVPTP
211 public:
219
228
229 // TODO: remove these instead rely on TransformedIVPTPGroup, do this change later
231 int id;
232 std::vector<unsigned int> indices;
233 std::vector<glm::vec3> xyz_positions;
234 // NOTE: the reason these exists is sometimes the packed textures change mid game and then you would have to
235 // recmopute the packed texture coordinates, and these will be used for that purpose
236 std::vector<glm::vec2> original_texture_coordinates;
237 std::vector<glm::vec2> packed_texture_coordinates;
240 std::string texture_path;
241
243};
244
245// TODO: batcher_draw_info_integration
247 public:
249 TransformedIVPTPGroup(std::vector<IVPTexturePacked> ivptp, int id) : ivptps(std::move(ivptp)), id(id) {}
250
251 std::vector<IVPTexturePacked> ivptps;
252 int id;
254
255 void regenerate_ids(IDGenerator &tig_id_generator, IDGenerator &ivptp_id_generator) {
256 id = tig_id_generator.get_id();
257 for (auto &ivptp : ivptps) {
258 ivptp.id = ivptp_id_generator.get_id();
259 }
260 }
261};
262
263class IVPNTexturePacked { // IVPTP
264 public:
275 std::vector<unsigned int> indices;
276 std::vector<glm::vec3> xyz_positions;
277 std::vector<glm::vec3> normals;
278 // the reason we need this is so that we can regenerate based on the original ones
279 std::vector<glm::vec2> original_texture_coordinates;
280 std::vector<glm::vec2> packed_texture_coordinates;
283 std::string texture_path;
284
286};
287
291
293
294 void add_bone_data(unsigned int BoneID, float Weight);
295};
296
298 public:
299 IVPNTRigged(std::vector<unsigned int> indices, std::vector<glm::vec3> xyz_positions, std::vector<glm::vec3> normals,
300 std::vector<glm::vec2> texture_coordinates, const std::string &texture,
301 std::vector<VertexBoneData> bone_data, int id)
303 texture_path(texture), bone_data(bone_data), id(id) {};
305 std::vector<unsigned int> indices;
306 std::vector<glm::vec3> xyz_positions;
307 std::vector<glm::vec3> normals;
308 std::vector<glm::vec2> texture_coordinates;
309 std::string texture_path;
310 std::vector<VertexBoneData> bone_data;
311 int id;
312};
313
314// packed version of the above
316 public:
327 std::vector<unsigned int> indices;
328 std::vector<glm::vec3> xyz_positions;
329 std::vector<glm::vec3> normals;
330 std::vector<glm::vec2> packed_texture_coordinates;
333 std::string texture;
334 std::vector<VertexBoneData> bone_data;
335};
336
337struct BoneInfo {
338 // this transformation puts the local orgin at the start (tail) of the bone and makes the bone sit on an axis so
339 // that when transformations are applied it works correctly, note that it is not recursive in any sense, it
340 // literally just puts it in the correct position not relative to a parent bone or anything like that
341
342 // another name for this is the inverase bind pose because the bind pose transformation takes a bone and puts it
343 // at the origin to be read for application of transformations, and this matrix is the inverse of that
344
345 // A quick thing to jog your memory could be that it "brings the bone joint back to the origin"
346
347 // Note that bones don't really exist, they only exist by the mapping of vertex to bone id's and then knowing
348 // the mapping for each bone,
349
350 // Questions for myself: what is a bone tip? it just shows what the rotation and scale is visually, based on a
351 // (0, 0, 1) bone tip you can compute where the tip would be based on the scale and so on I think... but then
352 // again bones can be larger and have no scaled in them right so then what? it might just be to compute during
353 // the auto weighting process maybe check assimp if that data is stored in there if a bone is positioned at
354 // position (x, y, z) and then we have a vertex at (x, y + 1, z + 1) then its new position becomes (0, 1, 1)
355 // that is it is positioned relative to the bones origin
357 // this transoformation takes a vertex in local space, and moves it to its animated position in local space
359
361};
362
364 public:
366 TransformedIVPNTPRGroup(std::vector<IVPNTPRigged> ivpntprs, int id) : ivpntprs(std::move(ivpntprs)), id(id) {}
367 int id;
368 std::vector<IVPNTPRigged> ivpntprs;
370};
371
374
375std::vector<IndexedVertexPositions>
376extract_indexed_vertex_positions_vector(const std::vector<IVPTextured> &ivp_textured_vector);
377std::vector<IndexedVertexPositions>
378extract_indexed_vertex_positions_vector(const std::vector<IVPTexturePacked> &ivp_texture_packed_vector);
379
380} // namespace draw_info
381
382#endif // DRAW_INFO_HPP
static int get_id()
Retrieves the next unique ID.
Definition unique_id_generator.cpp:6
Definition unique_id_generator.hpp:10
virtual int get_id()=0
Definition transform.hpp:16
Definition draw_info.hpp:27
bool has_been_modified_since_last_buffering() const
Definition draw_info.hpp:38
bool has_data_in_buffer()
Definition draw_info.hpp:36
void just_modified()
Definition draw_info.hpp:29
void free_buffered_data()
Definition draw_info.hpp:35
void just_buffered_data()
Definition draw_info.hpp:30
std::string to_string() const
Definition draw_info.hpp:47
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:138
Transform transform
Definition draw_info.hpp:135
std::vector< unsigned int > indices
Definition draw_info.hpp:137
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:141
IVPColor(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec3 > rgb_colors, int id=-1)
Definition draw_info.hpp:130
std::vector< glm::vec3 > rgb_colors
Definition draw_info.hpp:139
IVPColor(draw_info::IndexedVertexPositions ivp, std::vector< glm::vec3 > rgb_colors, int id=-1)
Definition draw_info.hpp:127
IVPColor()
Definition draw_info.hpp:122
IVPColor(draw_info::IndexedVertexPositions ivp, glm::vec3 color)
Definition draw_info.hpp:124
int id
Definition draw_info.hpp:136
IVPNColor(IVPNormals ivpn, std::vector< glm::vec3 > rgb_colors)
Definition draw_info.hpp:149
std::vector< unsigned int > indices
Definition draw_info.hpp:157
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:162
Transform transform
Definition draw_info.hpp:155
friend std::ostream & operator<<(std::ostream &os, const IVPNColor &ivp)
Definition draw_info.hpp:164
std::vector< glm::vec3 > normals
Definition draw_info.hpp:159
IVPNColor(IVPNormals ivpn, glm::vec3 color)
Definition draw_info.hpp:146
std::vector< glm::vec3 > rgb_colors
Definition draw_info.hpp:160
int id
Definition draw_info.hpp:156
IVPNColor(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec3 > normals, std::vector< glm::vec3 > colors, int id=-1)
Definition draw_info.hpp:152
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:158
int packed_texture_bounding_box_index
Definition draw_info.hpp:332
std::vector< unsigned int > indices
Definition draw_info.hpp:327
int packed_texture_index
Definition draw_info.hpp:331
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:328
std::vector< VertexBoneData > bone_data
Definition draw_info.hpp:334
std::vector< glm::vec3 > normals
Definition draw_info.hpp:329
std::vector< glm::vec2 > packed_texture_coordinates
Definition draw_info.hpp:330
std::string texture
Definition draw_info.hpp:333
Transform transform
Definition draw_info.hpp:325
IVPNTPRigged(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec3 > normals, std::vector< glm::vec2 > packed_texture_coordinates, int packed_texture_index, int packed_texture_bounding_box_index, const std::string &texture, std::vector< VertexBoneData > bone_data)
Definition draw_info.hpp:317
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:306
std::vector< VertexBoneData > bone_data
Definition draw_info.hpp:310
std::vector< unsigned int > indices
Definition draw_info.hpp:305
std::vector< glm::vec2 > texture_coordinates
Definition draw_info.hpp:308
IVPNTRigged(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec3 > normals, std::vector< glm::vec2 > texture_coordinates, const std::string &texture, std::vector< VertexBoneData > bone_data, int id)
Definition draw_info.hpp:299
Transform transform
Definition draw_info.hpp:304
std::string texture_path
Definition draw_info.hpp:309
std::vector< glm::vec3 > normals
Definition draw_info.hpp:307
int id
Definition draw_info.hpp:311
IVPNTexturePacked(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec3 > normals, std::vector< glm::vec2 > original_texture_coordinates, std::vector< glm::vec2 > packed_texture_coordinates, int packed_texture_index, int packed_texture_bounding_box_index, const std::string &texture)
Definition draw_info.hpp:265
int packed_texture_index
Definition draw_info.hpp:281
std::vector< glm::vec2 > original_texture_coordinates
Definition draw_info.hpp:279
std::string texture_path
Definition draw_info.hpp:283
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:276
std::vector< glm::vec3 > normals
Definition draw_info.hpp:277
std::vector< glm::vec2 > packed_texture_coordinates
Definition draw_info.hpp:280
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:285
Transform transform
Definition draw_info.hpp:273
int packed_texture_bounding_box_index
Definition draw_info.hpp:282
std::vector< unsigned int > indices
Definition draw_info.hpp:275
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:202
std::string texture_path
Definition draw_info.hpp:205
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:207
Transform transform
Definition draw_info.hpp:200
IVPNTextured(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec3 > normals, std::vector< glm::vec2 > texture_coordinates, const std::string &texture="")
Definition draw_info.hpp:195
std::vector< glm::vec3 > normals
Definition draw_info.hpp:203
std::vector< unsigned int > indices
Definition draw_info.hpp:201
std::vector< glm::vec2 > texture_coordinates
Definition draw_info.hpp:204
Definition draw_info.hpp:85
Transform transform
Definition draw_info.hpp:91
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:94
int id
Definition draw_info.hpp:92
IVPNormals()
Definition draw_info.hpp:87
std::vector< glm::vec3 > normals
Definition draw_info.hpp:95
std::vector< unsigned int > indices
Definition draw_info.hpp:93
friend std::ostream & operator<<(std::ostream &os, const IVPNormals &ivp)
Definition draw_info.hpp:99
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:97
IVPNormals(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec3 > normals, int id=-1)
Definition draw_info.hpp:88
Definition draw_info.hpp:210
std::string texture_path
Definition draw_info.hpp:240
std::vector< glm::vec2 > packed_texture_coordinates
Definition draw_info.hpp:237
int packed_texture_bounding_box_index
Definition draw_info.hpp:239
int id
Definition draw_info.hpp:231
IVPTexturePacked(const IndexedVertexPositions &ivp, std::vector< glm::vec2 > original_texture_coordinates, std::vector< glm::vec2 > packed_texture_coordinates, int packed_texture_index, int packed_texture_bounding_box_index, const std::string &texture, int id=GlobalUIDGenerator::get_id())
Definition draw_info.hpp:220
std::vector< unsigned int > indices
Definition draw_info.hpp:232
Transform transform
Definition draw_info.hpp:230
int packed_texture_index
Definition draw_info.hpp:238
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:242
std::vector< glm::vec2 > original_texture_coordinates
Definition draw_info.hpp:236
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:233
IVPTexturePacked(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec2 > original_texture_coordinates, std::vector< glm::vec2 > packed_texture_coordinates, int packed_texture_index, int packed_texture_bounding_box_index, const std::string &texture, int id=-1)
Definition draw_info.hpp:212
Definition draw_info.hpp:175
IVPTextured(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, std::vector< glm::vec2 > texture_coordinates, const std::string &texture="", int id=GlobalUIDGenerator::get_id())
Definition draw_info.hpp:177
std::string texture_path
Definition draw_info.hpp:188
std::vector< unsigned int > indices
Definition draw_info.hpp:185
std::vector< glm::vec2 > texture_coordinates
Definition draw_info.hpp:187
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:186
Transform transform
Definition draw_info.hpp:183
int id
Definition draw_info.hpp:184
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:190
Definition draw_info.hpp:61
std::vector< unsigned int > indices
Definition draw_info.hpp:71
BufferModificationTracker buffer_modification_tracker
Definition draw_info.hpp:74
IndexedVertexPositions()
Definition draw_info.hpp:63
friend std::ostream & operator<<(std::ostream &os, const IndexedVertexPositions &ivp)
Definition draw_info.hpp:76
Transform transform
Definition draw_info.hpp:69
IndexedVertexPositions(std::vector< unsigned int > indices, std::vector< glm::vec3 > xyz_positions, int id=-1)
Definition draw_info.hpp:64
int id
Definition draw_info.hpp:70
std::vector< glm::vec3 > xyz_positions
Definition draw_info.hpp:72
TransformedIVPGroup(std::vector< IndexedVertexPositions > ivps, int id)
Definition draw_info.hpp:114
std::vector< IndexedVertexPositions > ivps
Definition draw_info.hpp:116
TransformedIVPGroup()
Definition draw_info.hpp:113
int id
Definition draw_info.hpp:115
Transform transform
Definition draw_info.hpp:117
TransformedIVPNTPRGroup()
Definition draw_info.hpp:365
int id
Definition draw_info.hpp:367
std::vector< IVPNTPRigged > ivpntprs
Definition draw_info.hpp:368
TransformedIVPNTPRGroup(std::vector< IVPNTPRigged > ivpntprs, int id)
Definition draw_info.hpp:366
Transform transform
Definition draw_info.hpp:369
TransformedIVPTPGroup()
Definition draw_info.hpp:248
TransformedIVPTPGroup(std::vector< IVPTexturePacked > ivptp, int id)
Definition draw_info.hpp:249
std::vector< IVPTexturePacked > ivptps
Definition draw_info.hpp:251
void regenerate_ids(IDGenerator &tig_id_generator, IDGenerator &ivptp_id_generator)
Definition draw_info.hpp:255
Transform transform
Definition draw_info.hpp:253
int id
Definition draw_info.hpp:252
Definition draw_info.hpp:13
@ T
Definition input_state.hpp:73
@ t
Definition input_state.hpp:46
Definition colors.hpp:6
Definition draw_info.cpp:3
std::vector< IndexedVertexPositions > extract_indexed_vertex_positions_vector(const std::vector< IVPTextured > &ivp_textured_vector)
Definition draw_info.cpp:19
IndexedVertexPositions extract_indexed_vertex_positions(const IVPTextured &ivp_textured)
Definition draw_info.cpp:10
IndexedVertexPositions ivpn_to_ivpn(const IVPNormals &ivpn)
Definition draw_info.cpp:8
Definition glm_printing.hpp:28
Definition hashing.hpp:8
glm::mat4 local_space_to_bone_space_in_bind_pose_transformation
Definition draw_info.hpp:356
BoneInfo(const glm::mat4 &lstbst)
Definition draw_info.hpp:360
glm::mat4 local_space_animated_transform_upto_this_bone
Definition draw_info.hpp:358
VertexBoneData()
Definition draw_info.hpp:292
unsigned int indices_of_bones_that_affect_this_vertex[4]
Definition draw_info.hpp:289
float weight_value_of_this_vertex_wrt_bone[4]
Definition draw_info.hpp:290
void add_bone_data(unsigned int BoneID, float Weight)
Definition draw_info.cpp:44