Cogs.Core
Mesh.h
1#pragma once
2
3#include "VertexFormats.h"
4#include "MeshStreamsLayout.h"
5#include "ResourceBase.h"
6#include "Resources.h"
7
8#include "Rendering/Common.h"
9#include "Rendering/VertexFormat.h"
10
11#include "Foundation/Geometry/BoundingBox.hpp"
12#include "Foundation/Memory/MemoryBuffer.h"
13
14#include <array>
15#include <cstdint>
16#include <span>
17#include <vector>
18
19namespace Cogs::Core
20{
23 {
25 enum EVertexDataType : uint8_t
26 {
28 Positions = 0,
29 Normals,
30 Tangents,
31 Bitangents,
32 TexCoords0,
33 TexCoords1,
34 TexCoords2,
35 Colors0,
36 Colors1,
37 Colors2,
38 Colors3,
39 Interleaved0,
40 Interleaved1,
41 LastVertexType,
42 Indexes = LastVertexType,
43 PoseIndexes,
44 SubMeshes,
45 Reserved
47 };
48 };
49
51 struct MeshFlags
52 {
54 enum EMeshFlags : uint16_t
55 {
57 None = 0x0000,
65 Indexed = 0x0008,
68 Skinned = 0x0100,
70 Instanced = 0x200,
71 };
72 };
73
80 {
82 DataStream() = default;
83
85 DataStream(const DataStream & other) = delete;
86
88 DataStream(DataStream && other) = default;
89
90 COGSCORE_DLL_API void * data();
91 COGSCORE_DLL_API const void * data() const;
92
93 COGSCORE_DLL_API size_t size() const;
94
97
100
102 uint32_t offset = 0;
103
105 uint32_t stride = 0;
106
108 uint32_t numElements = 0;
109
111 VertexDataType::EVertexDataType type = VertexDataType::Reserved;
112 };
113
124 template<typename Element>
125 struct [[nodiscard]] MappedStream final
126 {
135 MappedStream(struct Mesh * mesh, Element * data, VertexDataType::EVertexDataType type)
136 : data(data), mesh(mesh), type(type) {}
137
139 MappedStream(MappedStream & other) = delete;
140
143 : data(other.data), mesh(other.mesh), type(other.type)
144 {
145 other.data = nullptr;
146 other.mesh = nullptr;
147 }
148
155
164 [[nodiscard]] constexpr Element & operator[](const size_t index)
165 {
166 return data[index];
167 }
168
169 [[nodiscard]] constexpr const Element & operator[](const size_t index) const
170 {
171 return data[index];
172 }
173
175 [[nodiscard]] constexpr bool isValid() const { return data != nullptr; }
176
177 [[nodiscard]] constexpr VertexDataType::EVertexDataType getDataType() const { return type; }
178
180 Element * data;
181
182 private:
184 struct Mesh * mesh;
185
188 };
189
195 template<typename Element>
196 struct [[nodiscard]] MappedStreamReadOnly final
197 {
198 MappedStreamReadOnly() = default;
199
208 MappedStreamReadOnly(struct Mesh* mesh, const Element* data, VertexDataType::EVertexDataType type)
209 : data(data), mesh(mesh), type(type) {}
210
212 [[nodiscard]] bool isValid() const { return data != nullptr; }
213
222 [[nodiscard]] constexpr const Element& operator[](const size_t index) const
223 {
224 return data[index];
225 }
226
227 [[nodiscard]] VertexDataType::EVertexDataType getDataType() const { return type; }
228
230 const Element* data = nullptr;
231
232 private:
234 struct Mesh* mesh = nullptr;
235
237 VertexDataType::EVertexDataType type = VertexDataType::EVertexDataType::Reserved;
238 };
239
241 inline bool isLine(PrimitiveType::EPrimitiveType primitiveType) { return primitiveType == PrimitiveType::LineList; }
242
248 struct SubMesh
249 {
251 uint32_t startIndex;
252
254 uint32_t numIndexes;
255
258 };
259
264 struct COGSCORE_DLL_API Mesh : public ResourceBase
265 {
267 Mesh();
268
270 Mesh(const Mesh & other) = delete;
271
273 Mesh & operator=(const Mesh& other) noexcept = delete;
274
283 Mesh(Mesh && other) noexcept = default;
284
291 Mesh & operator=(Mesh && other) noexcept = default;
292
298 void setBounds(Geometry::BoundingBox box)
299 {
300 boundingBox = box;
301 setMeshFlag(MeshFlags::BoundingBoxSet);
302 }
303
305 static constexpr size_t MaxStreams = 16;
306
308 static constexpr int NoStream = -1;
309
315 void setPositions(std::span<const glm::vec3> positions)
316 {
317 set(VertexDataType::Positions, VertexFormats::Pos3f, positions);
318 }
319
320 void setColors(std::span<const glm::vec4> colors)
321 {
322 set(VertexDataType::Colors0, VertexFormats::Color4f, colors);
323 }
324
325 void setInstancePositions(std::span<const glm::vec3> positions)
326 {
327 set(VertexDataType::Positions, VertexFormats::InstancePos3f, positions);
328 }
329
330 void setInstanceColors(std::span<const glm::vec4> colors)
331 {
332 set(VertexDataType::Colors0, VertexFormats::InstanceColor4f, colors);
333 }
334
345 template<typename Iterator>
346 void setPositions(Iterator begin, Iterator end)
347 {
348 set(VertexDataType::Positions, VertexFormats::Pos3f, begin, end);
349 }
350
364 [[nodiscard]] MappedStream<glm::vec3> mapPositions(const size_t start, const size_t end)
365 {
366 return map<glm::vec3>(VertexDataType::Positions, VertexFormats::Pos3f, start, end-start);
367 }
368
382 [[nodiscard]] MappedStreamReadOnly<glm::vec3> mapPositionsReadOnly(const size_t start, const size_t end)
383 {
384 return mapReadOnly<glm::vec3>(VertexDataType::Positions, VertexFormats::Pos3f, start, end - start);
385 }
386
392 void setNormals(std::span<const glm::vec3> normals)
393 {
394 set(VertexDataType::Normals, VertexFormats::Norm3f, normals);
395 }
396
407 template<typename Iterator>
408 void setNormals(Iterator begin, Iterator end)
409 {
410 set(VertexDataType::Normals, VertexFormats::Norm3f, begin, end);
411 }
412
423 [[nodiscard]] MappedStream<glm::vec3> mapNormals(const size_t start, const size_t end)
424 {
425 return map<glm::vec3>(VertexDataType::Normals, VertexFormats::Norm3f, start, end-start);
426 }
427
438 [[nodiscard]] MappedStreamReadOnly<glm::vec3> mapNormalsReadOnly(const size_t start, const size_t end)
439 {
440 return mapReadOnly<glm::vec3>(VertexDataType::Normals, VertexFormats::Norm3f, start, end - start);
441 }
442
448 void setTangents(std::span<const glm::vec3> tangents)
449 {
450 set(VertexDataType::Tangents, VertexFormats::Tang3f, tangents);
451 }
452
463 template<typename Iterator>
464 void setTangents(Iterator begin, Iterator end)
465 {
466 set(VertexDataType::Tangents, VertexFormats::Tang3f, begin, end);
467 }
468
479 [[nodiscard]] MappedStream<glm::vec3> mapTangents(const size_t start, const size_t end)
480 {
481 return map<glm::vec3>(VertexDataType::Tangents, VertexFormats::Tang3f, start, end-start);
482 }
483
494 [[nodiscard]] MappedStreamReadOnly<glm::vec3> mapTangentsReadOnly(const size_t start, const size_t end)
495 {
496 return mapReadOnly<glm::vec3>(VertexDataType::Tangents, VertexFormats::Tang3f, start, end - start);
497 }
498
504 void setTexCoords(std::span<const glm::vec2> texCoords)
505 {
506 set(VertexDataType::TexCoords0, VertexFormats::Tex2f, texCoords);
507 }
508
519 template<typename Iterator>
520 void setTexCoords(Iterator begin, Iterator end)
521 {
522 set(VertexDataType::TexCoords0, VertexFormats::Tex2f, begin, end);
523 }
524
535 [[nodiscard]] MappedStream<glm::vec2> mapTexCoords(const size_t start, const size_t end)
536 {
537 return map<glm::vec2>(VertexDataType::TexCoords0, VertexFormats::Tex2f, start, end-start);
538 }
539
550 [[nodiscard]] MappedStreamReadOnly<glm::vec2> mapTexCoordsReadOnly(const size_t start, const size_t end)
551 {
552 return mapReadOnly<glm::vec2>(VertexDataType::TexCoords0, VertexFormats::Tex2f, start, end - start);
553 }
554
566 template<typename Element>
567 [[nodiscard]] MappedStream<Element> map(const VertexDataType::EVertexDataType type, VertexFormatHandle format, const size_t count)
568 {
569 return map<Element>(type, format, 0, count);
570 }
571
577 static constexpr uint16_t toFlag(VertexDataType::EVertexDataType type)
578 {
579 return (0x1 << type);
580 }
581
596 void setIndexes(std::span<const uint32_t> collection)
597 {
598 setIndexData(collection.data(), collection.size());
599 }
600
608 {
609 if (isIndexed()) {
610 auto & stream = getStream(VertexDataType::Indexes);
611 clearStream(stream);
612 setMeshFlag(MeshFlags::IndexesChanged);
613 unsetMeshFlag(MeshFlags::Indexed);
614 }
615 if (hasStream(VertexDataType::SubMeshes)) {
616 DataStream& subMeshes = getStream(VertexDataType::SubMeshes);
617 clearStream(subMeshes);
618 }
619 submeshCount = 0;
620 }
621
637 void addSubMesh(std::span<uint32_t> collection, PrimitiveType::EPrimitiveType primitiveType);
638
639 void setBufferStream(VertexDataType::EVertexDataType type,
641 VertexFormatHandle format,
642 uint32_t numElements,
643 uint32_t offset,
644 uint32_t stride);
645
646 void clearStream(DataStream & stream);
647
652 void clear();
653
660 {
661 meshFlags |= flag;
662
663 setChanged();
664 }
665
672 {
673 meshFlags &= ~flag;
674 }
675
683 [[nodiscard]] constexpr bool isMeshFlagSet(MeshFlags::EMeshFlags flag) const
684 {
685 return (meshFlags & flag) == flag;
686 }
687
692 [[nodiscard]] bool boundsDirty() const
693 {
694 return (isMeshFlagSet(MeshFlags::IndexesChanged) || isMeshFlagSet(MeshFlags::StreamsChanged)) && !isMeshFlagSet(MeshFlags::BoundingBoxSet);
695 }
696
705 void setIndexData(const uint32_t * data, size_t count)
706 {
707 clearIndexes();
708
709 auto streamData = mapStream(VertexDataType::Indexes, 0, count, sizeof(uint32_t), true);
710 memcpy(streamData, data, sizeof(uint32_t) * count);
711
712 this->count = static_cast<uint32_t>(count);
713
714 setMeshFlag(MeshFlags::Indexed);
715 setMeshFlag(MeshFlags::IndexesChanged);
716 }
717
718 void setIndexData(const uint16_t * data, size_t count)
719 {
720 clearIndexes();
721
722 auto streamData = mapStream(VertexDataType::Indexes, 0, count, sizeof(uint16_t), true);
723 memcpy(streamData, data, sizeof(uint16_t) * count);
724
725 this->count = static_cast<uint32_t>(count);
726
727 setMeshFlag(MeshFlags::Indexed);
728 setMeshFlag(MeshFlags::IndexesChanged);
729 }
730
738 void setIndexData(std::span<const uint32_t> data)
739 {
740 setIndexData(data.data(), data.size());
741 }
742
753 template<typename Element>
754 void setVertexData(Element * elements, size_t count)
755 {
756 setVertexData(elements, count, Element::getVertexFormat());
757 }
758
770 template<typename Element>
771 void setVertexData(Element * elements, size_t count, VertexFormatHandle format)
772 {
773 this->count = static_cast<uint32_t>(count);
774
775 set(VertexDataType::Interleaved0, format, elements, elements + count);
776 }
777
791 template<typename Element>
792 void set(const VertexDataType::EVertexDataType type, VertexFormatHandle format, Element * begin, Element * end)
793 {
794 const size_t count = end - begin;
795 auto mapped = map<typename std::remove_const<Element>::type>(type, format, 0, end - begin, true);
796
797 for (size_t i = 0; i < count; ++i) {
798 mapped[i] = *begin++;
799 }
800 setMeshFlag(MeshFlags::StreamsChanged);
801 }
802
812 template<typename Collection>
813 void set(const VertexDataType::EVertexDataType type, VertexFormatHandle format, const Collection& collection)
814 {
815 set(type, format, collection.data(), collection.data() + collection.size());
816 }
817
835 template<typename Element>
836 [[nodiscard]] MappedStream<Element> map(const VertexDataType::EVertexDataType type, VertexFormatHandle format, const size_t start, const size_t count, bool resize = false)
837 {
838 void* stream = mapStream(type, format, start, count, sizeof(Element), resize);
839 return MappedStream<Element>{ this, static_cast<Element *>(stream), type };
840 }
841
856 template<typename Element>
858 VertexFormatHandle format,
859 const size_t start,
860 const size_t count)
861 {
862 if (!hasStream(type))
864
865 // Check length
866 const Cogs::Core::DataStream& stream = getStream(type);
867 if (stream.size() < (start + count))
869
870 bool resize = false;
871 void* streamData = mapStream(type, format, start, count, sizeof(Element), resize);
872 return MappedStreamReadOnly<Element>{ this, static_cast<Element*>(streamData), type };
873 }
874
879 [[nodiscard]] uint8_t * mapStream(const VertexDataType::EVertexDataType type,
880 VertexFormatHandle format,
881 const size_t start,
882 const size_t count,
883 const size_t elementSize,
884 bool resize = false);
885
889 [[nodiscard]] uint8_t * mapStream(const VertexDataType::EVertexDataType type,
890 const size_t start,
891 const size_t count,
892 const size_t stride,
893 bool resize = false);
894
901 {
902 markStreamChanged(type);
903 }
904
909 {
910 streamsUpdated |= Mesh::toFlag(type);
911 setMeshFlag(MeshFlags::StreamsChanged);
912 }
913
921 [[nodiscard]] DataStream & getStream(const VertexDataType::EVertexDataType dataType);
922 [[nodiscard]] const DataStream & getStream(const VertexDataType::EVertexDataType dataType) const;
923 [[nodiscard]] DataStream * getAllocatedStream(const VertexDataType::EVertexDataType dataType);
924 [[nodiscard]] const DataStream * getAllocatedStream(const VertexDataType::EVertexDataType dataType) const;
925
933 [[nodiscard]] bool hasStream(VertexDataType::EVertexDataType type) const
934 {
935 return streamIndexes[type] != NoStream;
936 }
937
943 [[nodiscard]] bool isCCW() const
944 {
945 return !isMeshFlagSet(MeshFlags::ClockwiseWinding);
946 }
947
953 [[nodiscard]] bool isIndexed() const
954 {
955 return isMeshFlagSet(MeshFlags::Indexed);
956 }
957
959 struct StreamReference final
960 {
962 template<typename T>
963 [[nodiscard]]
964 inline T& getDataAt(uint32_t index) {
965 return *reinterpret_cast<T*>(ptr + index * stride);
966 }
967
969 template<typename T>
970 [[nodiscard]]
971 inline const T& getDataAt(const size_t index) const {
972 return *reinterpret_cast<const T*>(ptr + index * stride);
973 }
974
976 [[nodiscard]]
977 constexpr bool isValid() const { return ptr != nullptr; }
978
979 uint8_t* ptr = nullptr;
980 uint32_t count = 0;
981 uint32_t stride = 0;
982 };
983
992 [[nodiscard]] StreamReference getPositionStream();
993
1001 [[nodiscard]] StreamReference getSemanticStream(ElementSemantic semantic, DataFormat format);
1002
1003 [[nodiscard]] MeshStreamsLayout getStreamsLayout() const;
1004
1012 [[nodiscard]] uint32_t getCount() const { return count; }
1013
1019 void setCount(size_t count) { this->count = static_cast<uint32_t>(count); setMeshFlag(MeshFlags::StreamsChanged); setMeshFlag(MeshFlags::IndexesChanged); }
1020
1026 [[nodiscard]] uint32_t getInstanceCount() const { return instanceCount; }
1027
1033 void setInstanceCount(size_t count) { instanceCount = static_cast<uint16_t>(count); setMeshFlag(MeshFlags::StreamsChanged); setMeshFlag(MeshFlags::IndexesChanged); }
1034
1044 template<typename Datatype>
1045 [[nodiscard]] Cogs::Memory::TypedBuffer<Datatype> copyData(Cogs::ElementSemantic semantic, DataFormat format)
1046 {
1048
1049 copyData(output, semantic, format);
1050
1051 return output;
1052 }
1053
1054 template<typename Datatype>
1055 void copyData(Cogs::Memory::TypedBuffer<Datatype>& output, Cogs::ElementSemantic semantic, DataFormat format)
1056 {
1057 if (streams.size()) {
1058 auto[rawData, count, stride] = getSemanticStream(semantic, format);
1059
1060 output.resize(count, false);
1061
1062 for (size_t i = 0; i < count; ++i) {
1063 output[i] = *reinterpret_cast<const Datatype *>(rawData + i * stride);
1064 }
1065 } else {
1066 output.clear();
1067 }
1068 }
1069
1070 [[nodiscard]]
1071 class MeshManager * getManager() const;
1072
1073 [[nodiscard]]
1074 std::span<uint32_t> mapPoseIndexes(uint32_t count);
1075 [[nodiscard]]
1076 std::span<const uint32_t> getPoseIndexes() const;
1077
1078 std::span<SubMesh> mapSubMeshes(uint32_t count);
1079 [[nodiscard]]
1080 std::span<SubMesh> getSubMeshes();
1081
1082 [[nodiscard]]
1083 std::span<const uint32_t> getIndexes() const;
1084 [[nodiscard]]
1085 std::span<const uint16_t> getIndexesU16() const;
1086
1087 [[nodiscard]]
1088 bool hasIndexesU16() const;
1089
1091 std::vector<DataStream> streams;
1092
1094 std::array<int8_t, static_cast<size_t>(VertexDataType::Reserved)> streamIndexes;
1095
1096 Geometry::BoundingBox boundingBox;
1097
1098 uint16_t streamsUpdated = 0;
1099 uint16_t submeshCount = 0;
1100 uint16_t meshFlags = MeshFlags::None;
1101 PrimitiveType::EPrimitiveType primitiveType = PrimitiveType::TriangleList;
1102
1103 private:
1104 uint32_t count = 0;
1105 uint16_t instanceCount = 0;
1107 };
1108
1109 template<typename Element>
1111 {
1112 if (mesh) {
1113 mesh->unmap(type);
1114 }
1115 }
1116}
1117
1118#include "MeshHelper.h"
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ Normals
Render world-space surface normals.
bool isLine(PrimitiveType::EPrimitiveType primitiveType)
Check if the given primitive type represents lines.
Definition: Mesh.h:241
void setChanged(Cogs::Core::Context *context, Cogs::ComponentModel::Component *component, Reflection::FieldId fieldId)
Must be Called after changing a Component field. Mark field changed. Request engine update.
Definition: FieldSetter.h:25
ElementSemantic
Element semantics used to map data to the shader stage.
Definition: VertexFormat.h:14
Contains a stream of data used by Mesh resources.
Definition: Mesh.h:80
uint32_t numElements
Number of elements of the type given by format contained in data.
Definition: Mesh.h:108
uint32_t offset
Byte offset from the start of the buffer.
Definition: Mesh.h:102
VertexFormatHandle format
A pointer to the format describing the contents of the byte buffer.
Definition: Mesh.h:99
DataStream()=default
Construct a default data stream.
VertexDataType::EVertexDataType type
Type index used to index streams in a Mesh resource.
Definition: Mesh.h:111
uint32_t stride
Element stride.
Definition: Mesh.h:105
Cogs::Core::ResourceBufferHandle buffer
Data buffer.
Definition: Mesh.h:96
DataStream(DataStream &&other)=default
Move construct the data stream from other.
DataStream(const DataStream &other)=delete
Disable copy constructing data streams.
Wrapper for read-only access to mapped stream data.
Definition: Mesh.h:197
bool isValid() const
Returns true if stream mapping successful.
Definition: Mesh.h:212
MappedStreamReadOnly(struct Mesh *mesh, const Element *data, VertexDataType::EVertexDataType type)
Constructs a MappedStreamReadOnly from the given mesh for readonly access to the mesh stream.
Definition: Mesh.h:208
constexpr const Element & operator[](const size_t index) const
Access the Element at the given index.
Definition: Mesh.h:222
Wrapper for mapped stream data automatically updating the Mesh resource mapped from when destructed.
Definition: Mesh.h:126
constexpr bool isValid() const
Returns true if stream mapping successful.
Definition: Mesh.h:175
MappedStream(MappedStream &&other)
Move construct the wrapper from other.
Definition: Mesh.h:142
Element * data
Pointer to the element data mapped from the Mesh data stream.
Definition: Mesh.h:180
~MappedStream()
Destructs the mapped stream wrapper.
Definition: Mesh.h:1110
VertexDataType::EVertexDataType type
Type index of the mesh data stream.
Definition: Mesh.h:187
MappedStream(struct Mesh *mesh, Element *data, VertexDataType::EVertexDataType type)
Constructs a MappedStream from the given mesh for updating the mesh.
Definition: Mesh.h:135
constexpr Element & operator[](const size_t index)
Access the Element at the given index.
Definition: Mesh.h:164
MappedStream(MappedStream &other)=delete
Disabled copy constructor.
struct Mesh * mesh
Pointer to the mapped mesh.
Definition: Mesh.h:184
Defines mesh flags controlling the behavior of Mesh resources.
Definition: Mesh.h:52
EMeshFlags
Mesh flags.
Definition: Mesh.h:55
@ Instanced
Mesh contains instance data.
Definition: Mesh.h:70
@ StreamsChanged
One or more of the data streams in the mesh changed.
Definition: Mesh.h:59
@ None
No flags.
Definition: Mesh.h:57
@ IndexesChanged
The index data of the mesh changed.
Definition: Mesh.h:61
@ Indexed
The mesh should be drawn indexed, using index data to order the triangle vertexes.
Definition: Mesh.h:65
@ BoundingBoxSet
Custom bounding box set, no automatic calculation of bounds should be performed.
Definition: Mesh.h:67
@ ClockwiseWinding
The mesh uses clockwise winding order for it's triangles as opposed to the counter-clockwise default.
Definition: Mesh.h:63
Utility structure containing reference to a data stream in a mesh.
Definition: Mesh.h:960
const T & getDataAt(const size_t index) const
Gets const reference to data at given index. No index or data type checking.
Definition: Mesh.h:971
T & getDataAt(uint32_t index)
Gets reference to data at given index. No index or data type checking.
Definition: Mesh.h:964
constexpr bool isValid() const
Checks if the stream is valid.
Definition: Mesh.h:977
Meshes contain streams of vertex data in addition to index data and options defining geometry used fo...
Definition: Mesh.h:265
MappedStream< glm::vec3 > mapTangents(const size_t start, const size_t end)
Map the tangent stream for write access, range between start and end.
Definition: Mesh.h:479
void setTangents(Iterator begin, Iterator end)
Set the tangent data of the mesh.
Definition: Mesh.h:464
void setVertexData(Element *elements, size_t count, VertexFormatHandle format)
Set vertex data.
Definition: Mesh.h:771
MappedStream< glm::vec2 > mapTexCoords(const size_t start, const size_t end)
Map the texture coordinate stream for write access, range between start and end.
Definition: Mesh.h:535
void unmap(VertexDataType::EVertexDataType type)
Unmap the stream with the given vertex data type index.
Definition: Mesh.h:900
void markStreamChanged(VertexDataType::EVertexDataType type)
Mark stream with the given vertex data type index as changed.
Definition: Mesh.h:908
Mesh & operator=(Mesh &&other) noexcept=default
Move assign from other.
Mesh & operator=(const Mesh &other) noexcept=delete
Disabled copy assign since copying Mesh resources naively might incur a performance penalty.
void setTangents(std::span< const glm::vec3 > tangents)
Set the tangent data of the Mesh.
Definition: Mesh.h:448
void setIndexes(std::span< const uint32_t > collection)
Set the index data to the collection given.
Definition: Mesh.h:596
MappedStreamReadOnly< Element > mapReadOnly(const VertexDataType::EVertexDataType type, VertexFormatHandle format, const size_t start, const size_t count)
Maps the data stream corresponding to the given type for read-only access.
Definition: Mesh.h:857
bool isCCW() const
If triangles in the mesh are specified counter-clockwise, which is the default.
Definition: Mesh.h:943
void setTexCoords(std::span< const glm::vec2 > texCoords)
Set the texture coordinate data of the Mesh.
Definition: Mesh.h:504
Mesh(Mesh &&other) noexcept=default
Move construct a Mesh from other.
void setIndexData(const uint32_t *data, size_t count)
Convenience method for setting index data from a raw pointer to data and count number of elements.
Definition: Mesh.h:705
void set(const VertexDataType::EVertexDataType type, VertexFormatHandle format, const Collection &collection)
Convenience method for setting vertex data to the stream given by type.
Definition: Mesh.h:813
void setBounds(Geometry::BoundingBox box)
Set custom bounds for the mesh.
Definition: Mesh.h:298
uint32_t getInstanceCount() const
Get the number of instances in this mesh.
Definition: Mesh.h:1026
Cogs::Memory::TypedBuffer< Datatype > copyData(Cogs::ElementSemantic semantic, DataFormat format)
Return a vector with all elements of the given semantic data as a continous buffer.
Definition: Mesh.h:1045
void setPositions(Iterator begin, Iterator end)
Set the position data of the mesh.
Definition: Mesh.h:346
bool isIndexed() const
If the mesh uses indexed geometry.
Definition: Mesh.h:953
constexpr bool isMeshFlagSet(MeshFlags::EMeshFlags flag) const
Check if the given mesh flag(s) is set.
Definition: Mesh.h:683
void clearIndexes()
Clear all index data, also clearing all sub-meshes.
Definition: Mesh.h:607
void set(const VertexDataType::EVertexDataType type, VertexFormatHandle format, Element *begin, Element *end)
Set the data of the vertex stream indexed by type.
Definition: Mesh.h:792
bool hasStream(VertexDataType::EVertexDataType type) const
Check if the Mesh has a DataStream for the given type.
Definition: Mesh.h:933
void setTexCoords(Iterator begin, Iterator end)
Set the texture coordinate data of the mesh.
Definition: Mesh.h:520
MappedStream< glm::vec3 > mapPositions(const size_t start, const size_t end)
Map the position stream for write access, range between start and end.
Definition: Mesh.h:364
MappedStreamReadOnly< glm::vec3 > mapNormalsReadOnly(const size_t start, const size_t end)
Map the normal stream for read access, range between start and end.
Definition: Mesh.h:438
void setInstanceCount(size_t count)
Set the number of instances in this mesh.
Definition: Mesh.h:1033
void setNormals(std::span< const glm::vec3 > normals)
Set the normal data of the Mesh.
Definition: Mesh.h:392
MappedStream< Element > map(const VertexDataType::EVertexDataType type, VertexFormatHandle format, const size_t start, const size_t count, bool resize=false)
Maps the data stream corresponding to the given type.
Definition: Mesh.h:836
void unsetMeshFlag(MeshFlags::EMeshFlags flag)
Unset the given mesh flag.
Definition: Mesh.h:671
void setIndexData(std::span< const uint32_t > data)
Convenience method for setting index data from a vector of source data.
Definition: Mesh.h:738
MappedStream< glm::vec3 > mapNormals(const size_t start, const size_t end)
Map the normal stream for write access, range between start and end.
Definition: Mesh.h:423
bool boundsDirty() const
Gets if the mesh bounds need to be updated before use.
Definition: Mesh.h:692
void setMeshFlag(MeshFlags::EMeshFlags flag)
Set the given mesh flag.
Definition: Mesh.h:659
void setVertexData(Element *elements, size_t count)
Set vertex data.
Definition: Mesh.h:754
MappedStreamReadOnly< glm::vec3 > mapTangentsReadOnly(const size_t start, const size_t end)
Map the tangent stream for read access, range between start and end.
Definition: Mesh.h:494
void setNormals(Iterator begin, Iterator end)
Set the normal data of the mesh.
Definition: Mesh.h:408
void setCount(size_t count)
Explicitly set the vertex count of the mesh.
Definition: Mesh.h:1019
MappedStreamReadOnly< glm::vec3 > mapPositionsReadOnly(const size_t start, const size_t end)
Map the position stream for read access, range between start and end.
Definition: Mesh.h:382
uint32_t getCount() const
Get the vertex count of the mesh.
Definition: Mesh.h:1012
MappedStreamReadOnly< glm::vec2 > mapTexCoordsReadOnly(const size_t start, const size_t end)
Map the texture coordinate stream for read access, range between start and end.
Definition: Mesh.h:550
void setPositions(std::span< const glm::vec3 > positions)
Set the position data of the Mesh.
Definition: Mesh.h:315
static constexpr uint16_t toFlag(VertexDataType::EVertexDataType type)
Convert the given type index to a flag.
Definition: Mesh.h:577
MappedStream< Element > map(const VertexDataType::EVertexDataType type, VertexFormatHandle format, const size_t count)
Maps the data stream corresponding to the given type with the given format and count.
Definition: Mesh.h:567
Mesh(const Mesh &other)=delete
Disabled copy constructor since copying Mesh resources naively might incur a performance penalty.
Base class for engine resources.
Definition: ResourceBase.h:107
Defines a sub-mesh of a Mesh resource.
Definition: Mesh.h:249
PrimitiveType::EPrimitiveType primitiveType
Primitive type to use when drawing the sub-mesh.
Definition: Mesh.h:257
uint32_t startIndex
Start index of the sub-mesh in the index array of the Mesh.
Definition: Mesh.h:251
uint32_t numIndexes
Number of indexes to draw for the sub-mesh.
Definition: Mesh.h:254
Defines vertex data types used to track streams in Mesh instances.
Definition: Mesh.h:23
EVertexDataType
Contains data types.
Definition: Mesh.h:26
EPrimitiveType
Primitive type enumeration.
Definition: Common.h:114
@ LineList
List of lines.
Definition: Common.h:120