@@ -142,7 +142,7 @@ namespace SRL::Types
142142
143143 /* * @brief Construct a new empty Attribute
144144 */
145- Attribute () :
145+ constexpr Attribute () :
146146 Visibility(FaceVisibility::SingleSided),
147147 Sort(0 ),
148148 Texture(0 ),
@@ -161,7 +161,7 @@ namespace SRL::Types
161161 * @param type Display type (sprite, polygon, etc)
162162 * @param options Display options (light, gouraud, depth shading)
163163 */
164- Attribute (const FaceVisibility visibility, const SortMode sort, const uint16_t texture, uint16_t color, uint16_t gouraud, uint16_t mode, uint32_t type, uint16_t options) :
164+ constexpr Attribute (const FaceVisibility visibility, const SortMode sort, const uint16_t texture, uint16_t color, uint16_t gouraud, uint16_t mode, uint32_t type, uint16_t options) :
165165 Visibility(visibility),
166166 Sort(sort | (((type) >> 16) & 0x1c) | options),
167167 Texture(texture),
@@ -181,7 +181,7 @@ namespace SRL::Types
181181 * @param type Display type of the quad
182182 * @param option Display options
183183 */
184- Attribute (
184+ constexpr Attribute (
185185 const FaceVisibility visibility,
186186 const SortMode sort,
187187 const uint16_t texture,
@@ -264,13 +264,13 @@ namespace SRL::Types
264264 {
265265 /* * @brief Construct a new Polygon object
266266 */
267- Polygon () : Normal(), Vertices { 0 , 0 , 0 , 0 } { }
267+ constexpr Polygon () : Normal(), Vertices { 0 , 0 , 0 , 0 } { }
268268
269269 /* * @brief Construct a new Polygon object
270270 * @param normal Normal vector
271271 * @param vertices Polygon vertex indicies
272272 */
273- Polygon (const SRL ::Math::Types::Vector3D& normal, const uint16_t vertices[4 ]) : Normal(normal), Vertices { vertices[0 ], vertices[1 ], vertices[2 ], vertices[3 ] } { }
273+ constexpr Polygon (const SRL ::Math::Types::Vector3D& normal, const uint16_t vertices[4 ]) : Normal(normal), Vertices { vertices[0 ], vertices[1 ], vertices[2 ], vertices[3 ] } { }
274274
275275 /* * @brief Normal vector of the polygon
276276 */
@@ -281,46 +281,59 @@ namespace SRL::Types
281281 uint16_t Vertices[4 ];
282282 };
283283
284- /* * @brief 3D mesh
284+ /* * @brief 3D mesh data
285285 */
286- struct Mesh : public SRL ::SGL ::SglType<Mesh , PDATA >
286+ struct MeshData : public SRL ::SGL ::SglType<MeshData , PDATA >
287287 {
288+ /* * @brief Construct a new empty mesh data object
289+ */
290+ constexpr MeshData () { }
291+
288292 /* * @brief Vertices of the mesh
289293 */
290- SRL ::Math::Types::Vector3D *Vertices;
294+ SRL ::Math::Types::Vector3D *Vertices = nullptr ;
291295
292296 /* * @brief Number of vertices of the mesh
293297 */
294- size_t VertexCount;
298+ size_t VertexCount = 0 ;
295299
296300 /* * @brief Mesh faces
297301 */
298- Polygon *Faces;
302+ Polygon *Faces = nullptr ;
299303
300304 /* * @brief Number of faces
301305 */
302- size_t FaceCount;
306+ size_t FaceCount = 0 ;
303307
304308 /* * @brief Face attributes
305309 */
306- Attribute *Attributes;
310+ Attribute *Attributes = nullptr ;
311+ };
307312
313+ /* * @brief 3D managed mesh data
314+ */
315+ struct Mesh : public MeshData
316+ {
308317 /* * @brief Construct a new empty mesh object
309318 */
310- Mesh () : Attributes( nullptr ), FaceCount( 0 ), Faces( nullptr ), VertexCount( 0 ), Vertices( nullptr ) { }
319+ constexpr Mesh () : MeshData( ) { }
311320
312321 /* * @brief Construct a new empty mesh object and initialize its arrays
322+ * @warning This constructor will also allocate Vertices, Faces and Attributes arrays
313323 * @param vertexCount Number of vertices in the mesh
314- * @param polygonCount Number of polygons in the mesh
324+ * @param faceCount Number of faces in the mesh
315325 */
316- Mesh (const size_t & vertexCount, const size_t & polygonCount ) : FaceCount(polygonCount), VertexCount(vertexCount )
326+ Mesh (const size_t & vertexCount, const size_t & faceCount ) : MeshData( )
317327 {
328+ this ->FaceCount = faceCount;
329+ this ->VertexCount = vertexCount;
318330 this ->Vertices = autonew SRL ::Math::Types::Vector3D[vertexCount];
319- this ->Faces = autonew Polygon[polygonCount ];
320- this ->Attributes = autonew Attribute[polygonCount ];
331+ this ->Faces = autonew Polygon[faceCount ];
332+ this ->Attributes = autonew Attribute[faceCount ];
321333 }
322334
323335 /* * @brief Construct a new mesh object from existing data
336+ * @warning When object is deleted, referenced vertices, faces and attributes arrays are deleted as well
324337 * @param vertexCount Number of points
325338 * @param vertices Vertex data
326339 * @param faceCount Number of faces
@@ -331,8 +344,10 @@ namespace SRL::Types
331344 SRL ::Math::Types::Vector3D* vertices,
332345 const size_t & faceCount,
333346 Polygon* faces,
334- Attribute* attributes) : FaceCount(faceCount), VertexCount(vertexCount )
347+ Attribute* attributes) : MeshData( )
335348 {
349+ this ->VertexCount = vertexCount;
350+ this ->FaceCount = faceCount;
336351 this ->Vertices = vertices;
337352 this ->Faces = faces;
338353 this ->Attributes = attributes;
@@ -390,44 +405,55 @@ namespace SRL::Types
390405 }
391406 };
392407
393- /* * @brief 3D smooths mesh
408+ /* * @brief 3D smooth mesh data
394409 */
395- struct SmoothMesh : public SRL ::SGL ::SglType<SmoothMesh , XPDATA >
410+ struct SmoothMeshData : public SRL ::SGL ::SglType<SmoothMeshData , XPDATA >
396411 {
412+ /* * @brief Construct a new empty mesh data object
413+ */
414+ constexpr SmoothMeshData () { }
415+
397416 /* * @brief Vertices of the mesh
398417 */
399- SRL ::Math::Types::Vector3D *Vertices;
418+ SRL ::Math::Types::Vector3D *Vertices = nullptr ;
400419
401420 /* * @brief Number of vertices of the mesh
402421 */
403- size_t VertexCount;
422+ size_t VertexCount = 0 ;
404423
405424 /* * @brief Mesh faces
406425 */
407- Polygon *Faces;
426+ Polygon *Faces = nullptr ;
408427
409428 /* * @brief Number of faces
410429 */
411- size_t FaceCount;
430+ size_t FaceCount = 0 ;
412431
413432 /* * @brief Face attributes
414433 */
415- Attribute *Attributes;
416-
434+ Attribute *Attributes = nullptr ;
435+
417436 /* * @brief Normal vector data for vertices
418437 */
419- SRL ::Math::Types::Vector3D* Normals;
438+ SRL ::Math::Types::Vector3D* Normals = nullptr ;
439+ };
420440
441+ /* * @brief 3D smooth managed mesh
442+ */
443+ struct SmoothMesh : public SmoothMeshData
444+ {
421445 /* * @brief Construct a new empty mesh object
422446 */
423- SmoothMesh () : Normals( nullptr ), Attributes( nullptr ), FaceCount( 0 ), Faces( nullptr ), VertexCount( 0 ), Vertices( nullptr ) { }
447+ constexpr SmoothMesh () : SmoothMeshData( ) { }
424448
425449 /* * @brief Construct a new empty mesh object and initialize its arrays
426450 * @param vertexCount Number of vertices in the mesh
427451 * @param faceCount Number of polygons in the mesh
428452 */
429- SmoothMesh (const size_t & vertexCount, const size_t & faceCount) : FaceCount(faceCount), VertexCount(vertexCount )
453+ SmoothMesh (const size_t & vertexCount, const size_t & faceCount) : SmoothMeshData( )
430454 {
455+ this ->VertexCount = vertexCount;
456+ this ->FaceCount = faceCount;
431457 this ->Vertices = autonew SRL ::Math::Types::Vector3D[vertexCount];
432458 this ->Faces = autonew Polygon[faceCount];
433459 this ->Attributes = autonew Attribute[faceCount];
@@ -447,8 +473,10 @@ namespace SRL::Types
447473 const size_t & faceCount,
448474 Polygon* faces,
449475 Attribute* attributes,
450- SRL ::Math::Types::Vector3D* normals) : FaceCount(faceCount), VertexCount(vertexCount )
476+ SRL ::Math::Types::Vector3D* normals) : SmoothMeshData( )
451477 {
478+ this ->VertexCount = vertexCount;
479+ this ->FaceCount = faceCount;
452480 this ->Vertices = vertices;
453481 this ->Faces = faces;
454482 this ->Attributes = attributes;
0 commit comments