Cogs.Core
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Cogs::Core::Mesh Struct Reference

Meshes contain streams of vertex data in addition to index data and options defining geometry used for rendering and picking. More...

#include <Mesh.h>

Inheritance diagram for Cogs::Core::Mesh:
Cogs::Core::ResourceBase

Classes

struct  StreamReference
 Utility structure containing reference to a data stream in a mesh. More...
 

Public Member Functions

 Mesh ()
 Construct a default mesh instance.
 
 Mesh (const Mesh &other)=delete
 Disabled copy constructor since copying Mesh resources naively might incur a performance penalty.
 
Meshoperator= (const Mesh &other) noexcept=delete
 Disabled copy assign since copying Mesh resources naively might incur a performance penalty.
 
 Mesh (Mesh &&other) noexcept=default
 Move construct a Mesh from other.
 
Meshoperator= (Mesh &&other) noexcept=default
 Move assign from other.
 
void setBounds (Geometry::BoundingBox box)
 Set custom bounds for the mesh.
 
void setPositions (std::span< const glm::vec3 > positions)
 Set the position data of the Mesh.
 
void setColors (std::span< const glm::vec4 > colors)
 
void setInstancePositions (std::span< const glm::vec3 > positions)
 
void setInstanceColors (std::span< const glm::vec4 > colors)
 
template<typename Iterator >
void setPositions (Iterator begin, Iterator end)
 Set the position data of the mesh.
 
MappedStream< glm::vec3 > mapPositions (const size_t start, const size_t end)
 Map the position stream for write access, range between start and end.
 
MappedStreamReadOnly< glm::vec3 > mapPositionsReadOnly (const size_t start, const size_t end)
 Map the position stream for read access, range between start and end.
 
void setNormals (std::span< const glm::vec3 > normals)
 Set the normal data of the Mesh.
 
template<typename Iterator >
void setNormals (Iterator begin, Iterator end)
 Set the normal data of the mesh.
 
MappedStream< glm::vec3 > mapNormals (const size_t start, const size_t end)
 Map the normal stream for write access, range between start and end.
 
MappedStreamReadOnly< glm::vec3 > mapNormalsReadOnly (const size_t start, const size_t end)
 Map the normal stream for read access, range between start and end.
 
void setTangents (std::span< const glm::vec3 > tangents)
 Set the tangent data of the Mesh.
 
template<typename Iterator >
void setTangents (Iterator begin, Iterator end)
 Set the tangent data of the mesh.
 
MappedStream< glm::vec3 > mapTangents (const size_t start, const size_t end)
 Map the tangent stream for write access, range between start and end.
 
MappedStreamReadOnly< glm::vec3 > mapTangentsReadOnly (const size_t start, const size_t end)
 Map the tangent stream for read access, range between start and end.
 
void setTexCoords (std::span< const glm::vec2 > texCoords)
 Set the texture coordinate data of the Mesh.
 
template<typename Iterator >
void setTexCoords (Iterator begin, Iterator end)
 Set the texture coordinate data of the mesh.
 
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.
 
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.
 
template<typename Element >
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.
 
void setIndexes (std::span< const uint32_t > collection)
 Set the index data to the collection given.
 
void clearIndexes ()
 Clear all index data, also clearing all sub-meshes.
 
void addSubMesh (std::span< uint32_t > collection, PrimitiveType::EPrimitiveType primitiveType)
 Add a sub-mesh to the Mesh.
 
void setBufferStream (VertexDataType::EVertexDataType type, ResourceBufferHandle buffer, VertexFormatHandle format, uint32_t numElements, uint32_t offset, uint32_t stride)
 
void clearStream (DataStream &stream)
 
void clear ()
 Clear all data from the Mesh, returning it to its initial non-indexed state with no streams and no sub-meshes defined.
 
void setMeshFlag (MeshFlags::EMeshFlags flag)
 Set the given mesh flag.
 
void unsetMeshFlag (MeshFlags::EMeshFlags flag)
 Unset the given mesh flag.
 
constexpr bool isMeshFlagSet (MeshFlags::EMeshFlags flag) const
 Check if the given mesh flag(s) is set.
 
bool boundsDirty () const
 Gets if the mesh bounds need to be updated before use.
 
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.
 
void setIndexData (const uint16_t *data, size_t count)
 
void setIndexData (std::span< const uint32_t > data)
 Convenience method for setting index data from a vector of source data.
 
template<typename Element >
void setVertexData (Element *elements, size_t count)
 Set vertex data.
 
template<typename Element >
void setVertexData (Element *elements, size_t count, VertexFormatHandle format)
 Set vertex data.
 
template<typename Element >
void set (const VertexDataType::EVertexDataType type, VertexFormatHandle format, Element *begin, Element *end)
 Set the data of the vertex stream indexed by type.
 
template<typename Collection >
void set (const VertexDataType::EVertexDataType type, VertexFormatHandle format, const Collection &collection)
 Convenience method for setting vertex data to the stream given by type.
 
template<typename Element >
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.
 
template<typename Element >
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.
 
uint8_t * mapStream (const VertexDataType::EVertexDataType type, VertexFormatHandle format, const size_t start, const size_t count, const size_t elementSize, bool resize=false)
 Raw stream mapping method.
 
uint8_t * mapStream (const VertexDataType::EVertexDataType type, const size_t start, const size_t count, const size_t stride, bool resize=false)
 Raw stream mapping method.
 
void unmap (VertexDataType::EVertexDataType type)
 Unmap the stream with the given vertex data type index.
 
void markStreamChanged (VertexDataType::EVertexDataType type)
 Mark stream with the given vertex data type index as changed.
 
DataStreamgetStream (const VertexDataType::EVertexDataType dataType)
 Get the stream corresponding to the given dataType.
 
const DataStreamgetStream (const VertexDataType::EVertexDataType dataType) const
 
DataStreamgetAllocatedStream (const VertexDataType::EVertexDataType dataType)
 
const DataStreamgetAllocatedStream (const VertexDataType::EVertexDataType dataType) const
 
bool hasStream (VertexDataType::EVertexDataType type) const
 Check if the Mesh has a DataStream for the given type.
 
bool isCCW () const
 If triangles in the mesh are specified counter-clockwise, which is the default.
 
bool isIndexed () const
 If the mesh uses indexed geometry.
 
StreamReference getPositionStream ()
 Get the data of the stream containing positions.
 
StreamReference getSemanticStream (ElementSemantic semantic, DataFormat format)
 Get the data of the stream containing data with the given semantic, format and minimum element size.
 
MeshStreamsLayout getStreamsLayout () const
 
uint32_t getCount () const
 Get the vertex count of the mesh.
 
void setCount (size_t count)
 Explicitly set the vertex count of the mesh.
 
uint32_t getInstanceCount () const
 Get the number of instances in this mesh.
 
void setInstanceCount (size_t count)
 Set the number of instances in this mesh.
 
template<typename Datatype >
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.
 
template<typename Datatype >
void copyData (Cogs::Memory::TypedBuffer< Datatype > &output, Cogs::ElementSemantic semantic, DataFormat format)
 
class MeshManagergetManager () const
 
std::span< uint32_t > mapPoseIndexes (uint32_t count)
 
std::span< const uint32_t > getPoseIndexes () const
 
std::span< SubMeshmapSubMeshes (uint32_t count)
 
std::span< SubMeshgetSubMeshes ()
 
std::span< const uint32_t > getIndexes () const
 
std::span< const uint16_t > getIndexesU16 () const
 
bool hasIndexesU16 () const
 
- Public Member Functions inherited from Cogs::Core::ResourceBase
 ResourceBase ()=default
 Constructs a new resource base.
 
 ResourceBase (const ResourceBase &other)=delete
 Disable trivial copies of resources.
 
ResourceBaseoperator= (const ResourceBase &other)=delete
 Disable copy-assignment of resources.
 
 ResourceBase (ResourceBase &&other)
 Move constructs a resource base from other.
 
ResourceBaseoperator= (ResourceBase &&other)
 Move assign the resource from the given ResourceBase other.
 
 ~ResourceBase ()
 Destructs the resource.
 
void setInitialized ()
 
void setChanged ()
 
bool hasChanged () const
 
void setLoading ()
 
void setLoaded ()
 
void setFailedLoad ()
 
void setActive ()
 
void setResident ()
 
void setProxy ()
 
void setKeepStorage ()
 
bool isInitialized () const
 
bool isLoaded () const
 
bool isActive () const
 
bool isResident () const
 
bool isDependency () const
 
bool isDeleted () const
 
bool isOrphaned () const
 
bool isProxy () const
 
bool hasFailedLoad () const
 
bool hasFailedActivation () const
 
bool keepStorage () const
 
void setType (ResourceTypes type)
 Set the type enumeration of the resource.
 
ResourceTypes getType () const
 Gets the type enumeration of the resource.
 
void setId (ResourceId resourceId)
 Set the resource id of the resource.
 
ResourceId getId () const
 Get the resource id of this instance.
 
void setFlag (ResourceFlags flags)
 Set the given resource flag.
 
void setFlags (ResourceFlags flags)
 
void unsetFlag (ResourceFlags flag)
 Unset the given flag.
 
bool isSet (ResourceFlags flag) const
 Check if the given flag is currently set.
 
ResourceFlags getFlags () const
 Get the current flags of the resource.
 
void attachResource (RenderResource *attachment)
 Attach the given GPU resource to the resource.
 
bool hasAttachedResource () const
 Check if the resource has an attachment.
 
RenderResourcegetAttachedResource () const
 Get the attached resource.
 
void setOwner (IResourceManager *owner)
 Sets the owner of this resource instance.
 
IResourceManagergetOwner () const
 
void setName (const StringView &name)
 Set the user friendly name of the resource.
 
StringView getName () const
 Get the name of the resource.
 
void setSource (const StringView &source)
 
StringView getSource () const
 
void increment ()
 Increments the reference count of the resource.
 
void decrement ()
 Decrement the reference count of the resource.
 
uint32_t referenceCount () const
 Get the current reference count.
 
void incrementGeneration ()
 Increment the generation count.
 
uint32_t getGeneration () const
 Get the generation count.
 
void setSlot (uint32_t slot)
 Sets the slot at which the resource is internally tracked.
 
uint32_t getSlot () const
 Gets the slot where the resource is tracked internally.
 

Static Public Member Functions

static constexpr uint16_t toFlag (VertexDataType::EVertexDataType type)
 Convert the given type index to a flag.
 

Static Public Attributes

static constexpr size_t MaxStreams = 16
 Maximum number of data streams contained in a single Mesh resource.
 
static constexpr int NoStream = -1
 Used to indicate no stream.
 
- Static Public Attributes inherited from Cogs::Core::ResourceBase
static const uint32_t NoAttachment = 0xFFFFFFFF
 Constant used to signal no attachment.
 

Detailed Description

Meshes contain streams of vertex data in addition to index data and options defining geometry used for rendering and picking.

Definition at line 264 of file Mesh.h.

Constructor & Destructor Documentation

◆ Mesh() [1/2]

Cogs::Core::Mesh::Mesh ( )

Construct a default mesh instance.

Definition at line 12 of file Mesh.cpp.

References NoStream.

◆ Mesh() [2/2]

Cogs::Core::Mesh::Mesh ( Mesh &&  other)
defaultnoexcept

Move construct a Mesh from other.

The contents of other are all moved into this instance, and the instance moved from is left in an empty, uninitialized state.

Parameters
otherMesh instance to move data from.

Member Function Documentation

◆ addSubMesh()

void Cogs::Core::Mesh::addSubMesh ( std::span< uint32_t >  collection,
PrimitiveType::EPrimitiveType  primitiveType 
)

Add a sub-mesh to the Mesh.

The sub-mesh is added after any existing sub-meshes. If no sub-meshes exist but index data is present, the current index set is defined as the first sub-mesh before adding. If no sub-meshes exist and no index data is present the sub-mesh will be the first of the Mesh resource.

Sub-meshes can be used to partition large meshes into several draw calls, for example using different materials for each sub-mesh.

Parameters
collectionCollection of index data to use for the sub-mesh.
primitiveTypePrimitive type to use when rendering the sub-mesh.
Template Parameters
CollectionType of collection holding index data for the sub-mesh.

Definition at line 189 of file Mesh.cpp.

References Cogs::Core::MeshFlags::Indexed, and Cogs::Core::MeshFlags::IndexesChanged.

◆ boundsDirty()

bool Cogs::Core::Mesh::boundsDirty ( ) const
inline

Gets if the mesh bounds need to be updated before use.

True if any of the mesh data changed, and a bounding box is not set explicitly.

Definition at line 692 of file Mesh.h.

Referenced by Cogs::Core::InstancedMeshRenderSystem::update().

◆ clear()

void Cogs::Core::Mesh::clear ( )

◆ clearIndexes()

void Cogs::Core::Mesh::clearIndexes ( )
inline

Clear all index data, also clearing all sub-meshes.

If the Mesh was flagged as Indexed before the call to clearIndexes(), it will retain this flag after the call. To remove the use of indexes call unsetMeshFlag(MeshFlags::Indexed).

Definition at line 607 of file Mesh.h.

Referenced by Cogs::Core::LoftedCrossSectionsSystem::update().

◆ clearStream()

void Cogs::Core::Mesh::clearStream ( DataStream stream)

Definition at line 17 of file Mesh.cpp.

◆ copyData() [1/2]

template<typename Datatype >
Cogs::Memory::TypedBuffer< Datatype > Cogs::Core::Mesh::copyData ( Cogs::ElementSemantic  semantic,
DataFormat  format 
)
inline

Return a vector with all elements of the given semantic data as a continous buffer.

Parameters
semanticWhich element semantic to copy
formatExpected format of the element
Returns
A continuous vector of element data, or an empty vector if no matching stream is found.

Definition at line 1045 of file Mesh.h.

◆ copyData() [2/2]

template<typename Datatype >
void Cogs::Core::Mesh::copyData ( Cogs::Memory::TypedBuffer< Datatype > &  output,
Cogs::ElementSemantic  semantic,
DataFormat  format 
)
inline

Definition at line 1055 of file Mesh.h.

◆ getAllocatedStream() [1/2]

Cogs::Core::DataStream * Cogs::Core::Mesh::getAllocatedStream ( const VertexDataType::EVertexDataType  dataType)

Definition at line 127 of file Mesh.cpp.

◆ getAllocatedStream() [2/2]

const Cogs::Core::DataStream * Cogs::Core::Mesh::getAllocatedStream ( const VertexDataType::EVertexDataType  dataType) const

Definition at line 118 of file Mesh.cpp.

◆ getCount()

uint32_t Cogs::Core::Mesh::getCount ( ) const
inline

Get the vertex count of the mesh.

If indexed, returns the size of the index array used to render the mesh.

Returns
Number of vertexes to draw for this mesh instance.

Definition at line 1012 of file Mesh.h.

Referenced by Cogs::Core::calculateBounds(), Cogs::Core::generateMeshTangents(), and Cogs::Core::InstancedMeshRenderSystem::update().

◆ getIndexes()

std::span< const uint32_t > Cogs::Core::Mesh::getIndexes ( ) const

Definition at line 260 of file Mesh.cpp.

◆ getIndexesU16()

std::span< const uint16_t > Cogs::Core::Mesh::getIndexesU16 ( ) const

Definition at line 271 of file Mesh.cpp.

◆ getInstanceCount()

uint32_t Cogs::Core::Mesh::getInstanceCount ( ) const
inline

Get the number of instances in this mesh.

Note
Only relevant when MeshFlags::Instanced is set.

Definition at line 1026 of file Mesh.h.

◆ getManager()

Cogs::Core::MeshManager * Cogs::Core::Mesh::getManager ( ) const

Definition at line 167 of file Mesh.cpp.

◆ getPoseIndexes()

std::span< const uint32_t > Cogs::Core::Mesh::getPoseIndexes ( ) const

Definition at line 178 of file Mesh.cpp.

◆ getPositionStream()

Cogs::Core::Mesh::StreamReference Cogs::Core::Mesh::getPositionStream ( )

Get the data of the stream containing positions.

If the Positions stream is used, and has the correct format and element size, this will be returned. If not the remaining streams are checked for position info and returned if present.

Returns
A structure containing a pointer to stream data, the number of elements in the stream, and the stride between each element in bytes.

Definition at line 136 of file Mesh.cpp.

References Cogs::Position.

Referenced by Cogs::Core::MeshCollisionSystem::update().

◆ getSemanticStream()

Cogs::Core::Mesh::StreamReference Cogs::Core::Mesh::getSemanticStream ( ElementSemantic  semantic,
DataFormat  format 
)

Get the data of the stream containing data with the given semantic, format and minimum element size.

Checks all streams and uses the first that contains a matching vertex format.

Returns
A tuple containing a pointer to stream data, the number of elements in the stream, and the stride between each element in bytes.

Definition at line 144 of file Mesh.cpp.

References Cogs::Core::DataStream::format, and Cogs::Core::DataStream::numElements.

Referenced by Cogs::Core::InstancedMeshPicker::pickImpl(), and Cogs::Core::InstancedMeshRenderSystem::update().

◆ getStream() [1/2]

Cogs::Core::DataStream & Cogs::Core::Mesh::getStream ( const VertexDataType::EVertexDataType  dataType)

Get the stream corresponding to the given dataType.

If the stream does not exist, a DataStream is constructed at the given index.

Parameters
dataTypeVertex data stream type to fetch stream for.

Definition at line 85 of file Mesh.cpp.

References Cogs::Core::DataStream::buffer, Cogs::Core::BufferBindFlags::IndexBuffer, Cogs::Core::BufferResource::setBindFlags(), Cogs::Core::DataStream::type, and Cogs::Core::BufferBindFlags::VertexBuffer.

Referenced by Cogs::Core::generateMeshNormals().

◆ getStream() [2/2]

const Cogs::Core::DataStream & Cogs::Core::Mesh::getStream ( const VertexDataType::EVertexDataType  dataType) const

Definition at line 111 of file Mesh.cpp.

◆ getStreamsLayout()

Cogs::Core::MeshStreamsLayout Cogs::Core::Mesh::getStreamsLayout ( ) const

Definition at line 292 of file Mesh.cpp.

◆ getSubMeshes()

std::span< Cogs::Core::SubMesh > Cogs::Core::Mesh::getSubMeshes ( )

Definition at line 250 of file Mesh.cpp.

◆ hasIndexesU16()

bool Cogs::Core::Mesh::hasIndexesU16 ( ) const

Definition at line 282 of file Mesh.cpp.

◆ hasStream()

bool Cogs::Core::Mesh::hasStream ( VertexDataType::EVertexDataType  type) const
inline

Check if the Mesh has a DataStream for the given type.

Parameters
typeVertex data type to check for.
Returns
A boolean indicating if a valid stream was found.

Definition at line 933 of file Mesh.h.

Referenced by Cogs::Core::generateMeshNormals(), and Cogs::Core::generateMeshTangents().

◆ isCCW()

bool Cogs::Core::Mesh::isCCW ( ) const
inline

If triangles in the mesh are specified counter-clockwise, which is the default.

Returns
A boolean indicating true if counter-clockwise, false if clockwise.

Definition at line 943 of file Mesh.h.

Referenced by Cogs::Core::generateMeshNormals(), and Cogs::Core::generateMeshTangents().

◆ isIndexed()

bool Cogs::Core::Mesh::isIndexed ( ) const
inline

If the mesh uses indexed geometry.

Returns
A boolean indicating if the mesh uses indexes geometry.

Definition at line 953 of file Mesh.h.

Referenced by Cogs::Core::generateMeshNormals(), and Cogs::Core::generateMeshTangents().

◆ isMeshFlagSet()

constexpr bool Cogs::Core::Mesh::isMeshFlagSet ( MeshFlags::EMeshFlags  flag) const
inlineconstexpr

Check if the given mesh flag(s) is set.

Parameters
flagMeshFlag(s) to check.
Returns
A boolean indicating if all the flag are set.

Definition at line 683 of file Mesh.h.

◆ map() [1/2]

template<typename Element >
MappedStream< Element > Cogs::Core::Mesh::map ( const VertexDataType::EVertexDataType  type,
VertexFormatHandle  format,
const size_t  count 
)
inline

Maps the data stream corresponding to the given type with the given format and count.

Parameters
typeType index of the mapped stream.
formatPointer to a valid vertex format describing the mapped stream data.
countNumber of elements to map.
Returns
MappedStream instance.
See also
map()

Definition at line 567 of file Mesh.h.

◆ map() [2/2]

template<typename Element >
MappedStream< Element > Cogs::Core::Mesh::map ( const VertexDataType::EVertexDataType  type,
VertexFormatHandle  format,
const size_t  start,
const size_t  count,
bool  resize = false 
)
inline

Maps the data stream corresponding to the given type.

If no stream currently exists for type, a new empty DataStream is created with the corresponding type.

If needed, the stream is resized to be able to hold (start + count) * sizeof(Element) number of bytes.

Parameters
typeType index of the stream to map. If no stream exists for this type, a DataStream is created.
formatPointer to a vertex format describing the data in the stream. Must be alive for as long as the Mesh resource instance is in use. Prefer using formats defined in VertexFormats.
startIndex of the first element in the stream to map.
countNumber of elements to map from the start index.
resizeA boolean indicating if resize is wanted even when the mapped size is smaller than the capacity of the stream. =True to shrink streams to only contain enough storage for the desired mapped range.
Returns
A MappedStream instance containing the mapped data. Automatically unmaps the stream when leaving scope.

Definition at line 836 of file Mesh.h.

◆ mapNormals()

MappedStream< glm::vec3 > Cogs::Core::Mesh::mapNormals ( const size_t  start,
const size_t  end 
)
inline

Map the normal stream for write access, range between start and end.

Parameters
startStarting index to the first normal element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper, automatically unmapping the stream when destructed.
See also
map()

Definition at line 423 of file Mesh.h.

◆ mapNormalsReadOnly()

MappedStreamReadOnly< glm::vec3 > Cogs::Core::Mesh::mapNormalsReadOnly ( const size_t  start,
const size_t  end 
)
inline

Map the normal stream for read access, range between start and end.

Parameters
startStarting index to the first normal element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper.
See also
map()

Definition at line 438 of file Mesh.h.

Referenced by Cogs::Core::generateMeshTangents().

◆ mapPoseIndexes()

std::span< uint32_t > Cogs::Core::Mesh::mapPoseIndexes ( uint32_t  count)

Definition at line 172 of file Mesh.cpp.

◆ mapPositions()

MappedStream< glm::vec3 > Cogs::Core::Mesh::mapPositions ( const size_t  start,
const size_t  end 
)
inline

Map the position stream for write access, range between start and end.

If the range [start, end) extends past the current capacity of the position stream, the stream data is resized to cover the range.

Parameters
startStarting index to the first position element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper, automatically unmapping the stream when destructed.
See also
map()

Definition at line 364 of file Mesh.h.

◆ mapPositionsReadOnly()

MappedStreamReadOnly< glm::vec3 > Cogs::Core::Mesh::mapPositionsReadOnly ( const size_t  start,
const size_t  end 
)
inline

Map the position stream for read access, range between start and end.

If the range [start, end) extends past the current capacity of the position stream, the stream data is resized to cover the range.

Parameters
startStarting index to the first position element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper.
See also
map()

Definition at line 382 of file Mesh.h.

Referenced by Cogs::Core::generateMeshNormals(), and Cogs::Core::generateMeshTangents().

◆ mapReadOnly()

template<typename Element >
MappedStreamReadOnly< Element > Cogs::Core::Mesh::mapReadOnly ( const VertexDataType::EVertexDataType  type,
VertexFormatHandle  format,
const size_t  start,
const size_t  count 
)
inline

Maps the data stream corresponding to the given type for read-only access.

If no stream currently exists for type an invalid stream is returned. Use isValid() member to check.

If stream length is too short an invalid stream is returned.

Parameters
typeType index of the stream to map. If no stream exists for this type, a DataStream is created.
formatPointer to a vertex format describing the data in the stream. Must be alive for as long as the Mesh resource instance is in use. Prefer using formats defined in VertexFormats.
startIndex of the first element in the stream to map.
countNumber of elements to map from the start index.
Returns
A MappedStreamReadOnly instance containing the mapped data.

Definition at line 857 of file Mesh.h.

Referenced by Cogs::Core::SpritePicker::pickCamera().

◆ mapStream() [1/2]

uint8_t * Cogs::Core::Mesh::mapStream ( const VertexDataType::EVertexDataType  type,
const size_t  start,
const size_t  count,
const size_t  stride,
bool  resize = false 
)

Raw stream mapping method.

Must be unmapped using unmap after modification.

Definition at line 61 of file Mesh.cpp.

References Cogs::Core::DataStream::buffer, Cogs::Core::DataStream::numElements, Cogs::Core::BufferResource::resize(), and Cogs::Core::DataStream::stride.

◆ mapStream() [2/2]

uint8_t * Cogs::Core::Mesh::mapStream ( const VertexDataType::EVertexDataType  type,
VertexFormatHandle  format,
const size_t  start,
const size_t  count,
const size_t  elementSize,
bool  resize = false 
)

Raw stream mapping method.

Must be unmapped using unmap after modification. The stream is resize if it is too short. Also resized if different size and resize flag is set.

Definition at line 46 of file Mesh.cpp.

References Cogs::Core::DataStream::format.

◆ mapSubMeshes()

std::span< Cogs::Core::SubMesh > Cogs::Core::Mesh::mapSubMeshes ( uint32_t  count)

Definition at line 241 of file Mesh.cpp.

◆ mapTangents()

MappedStream< glm::vec3 > Cogs::Core::Mesh::mapTangents ( const size_t  start,
const size_t  end 
)
inline

Map the tangent stream for write access, range between start and end.

Parameters
startStarting index to the first tangent element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper, automatically unmapping the stream when destructed.
See also
map()

Definition at line 479 of file Mesh.h.

◆ mapTangentsReadOnly()

MappedStreamReadOnly< glm::vec3 > Cogs::Core::Mesh::mapTangentsReadOnly ( const size_t  start,
const size_t  end 
)
inline

Map the tangent stream for read access, range between start and end.

Parameters
startStarting index to the first tangent element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper.
See also
map()

Definition at line 494 of file Mesh.h.

◆ mapTexCoords()

MappedStream< glm::vec2 > Cogs::Core::Mesh::mapTexCoords ( const size_t  start,
const size_t  end 
)
inline

Map the texture coordinate stream for write access, range between start and end.

Parameters
startStarting index to the first texture coordinate element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper, automatically unmapping the stream when destructed.
See also
map()

Definition at line 535 of file Mesh.h.

◆ mapTexCoordsReadOnly()

MappedStreamReadOnly< glm::vec2 > Cogs::Core::Mesh::mapTexCoordsReadOnly ( const size_t  start,
const size_t  end 
)
inline

Map the texture coordinate stream for read access, range between start and end.

Parameters
startStarting index to the first texture coordinate element to map.
endEnd index one past the last element to map.
Returns
A mapped stream wrapper.
See also
map()

Definition at line 550 of file Mesh.h.

Referenced by Cogs::Core::generateMeshTangents().

◆ markStreamChanged()

void Cogs::Core::Mesh::markStreamChanged ( VertexDataType::EVertexDataType  type)
inline

Mark stream with the given vertex data type index as changed.

Definition at line 908 of file Mesh.h.

◆ operator=()

Mesh & Cogs::Core::Mesh::operator= ( Mesh &&  other)
defaultnoexcept

Move assign from other.

The contents of other are all moved into this instance, and the instance moved from is left in an empty, uninitialized state.

◆ set() [1/2]

template<typename Collection >
void Cogs::Core::Mesh::set ( const VertexDataType::EVertexDataType  type,
VertexFormatHandle  format,
const Collection &  collection 
)
inline

Convenience method for setting vertex data to the stream given by type.

Parameters
typeVertex data stream index to copy data to.
formatPointer to a valid vertex format describing the data in collection.
collectionCollection of vertex data.
Template Parameters
Typeof collection to copy vertex data from. std::span or other continous storage collection (.data + .size)

Definition at line 813 of file Mesh.h.

◆ set() [2/2]

template<typename Element >
void Cogs::Core::Mesh::set ( const VertexDataType::EVertexDataType  type,
VertexFormatHandle  format,
Element *  begin,
Element *  end 
)
inline

Set the data of the vertex stream indexed by type.

The vertex stream is automatically created if needed, and resized to fit the exact contents given.

The data between begin and end is copied into the stream.

Parameters
typeVertex data stream index to set the data to.
formatPointer to a valid vertex format describing the data pointed to by begin.
beginPointer to the first data element to copy.
endPointer one past the last element to copy.
Template Parameters
ElementType of data the begin and end pointers are pointing to.

Definition at line 792 of file Mesh.h.

Referenced by Cogs::Core::MarkerPointSetSystem::update().

◆ setBounds()

void Cogs::Core::Mesh::setBounds ( Geometry::BoundingBox  box)
inline

Set custom bounds for the mesh.

Parameters
boxCustom bounding box to use for culling and other operations on the Mesh.

Definition at line 298 of file Mesh.h.

Referenced by Cogs::Core::SeaCurrentsSystem::initialize(), Cogs::Core::LoftedCrossSectionsSystem::update(), and Cogs::Core::Text3DSystem::update().

◆ setBufferStream()

void Cogs::Core::Mesh::setBufferStream ( VertexDataType::EVertexDataType  type,
ResourceBufferHandle  buffer,
VertexFormatHandle  format,
uint32_t  numElements,
uint32_t  offset,
uint32_t  stride 
)

Definition at line 215 of file Mesh.cpp.

◆ setColors()

void Cogs::Core::Mesh::setColors ( std::span< const glm::vec4 >  colors)
inline

Definition at line 320 of file Mesh.h.

◆ setCount()

void Cogs::Core::Mesh::setCount ( size_t  count)
inline

Explicitly set the vertex count of the mesh.

Explicitly override the number of vertices to draw, normally deduced from index count or buffer size.

Definition at line 1019 of file Mesh.h.

◆ setIndexData() [1/3]

void Cogs::Core::Mesh::setIndexData ( const uint16_t *  data,
size_t  count 
)
inline

Definition at line 718 of file Mesh.h.

◆ setIndexData() [2/3]

void Cogs::Core::Mesh::setIndexData ( const uint32_t *  data,
size_t  count 
)
inline

Convenience method for setting index data from a raw pointer to data and count number of elements.

The index data pointed to will be copied into the internal index data of the Mesh.

Parameters
dataPointer to index data.
countNumber of indexes to copy.

Definition at line 705 of file Mesh.h.

Referenced by Cogs::Core::Text3DSystem::update(), and Cogs::Core::ShapeSystem::update().

◆ setIndexData() [3/3]

void Cogs::Core::Mesh::setIndexData ( std::span< const uint32_t >  data)
inline

Convenience method for setting index data from a vector of source data.

The index data will be moved into the internal index data of the Mesh.

Parameters
datastd::span of index data.

Definition at line 738 of file Mesh.h.

◆ setIndexes()

void Cogs::Core::Mesh::setIndexes ( std::span< const uint32_t >  collection)
inline

Set the index data to the collection given.

Any existing index data is overwritten by the contents of collection. If the index data given is smaller than the previously set index data, any previous data past the size of collection is simply discarded.

Any defined sub-meshes are discarded.

The Mesh is flagged as Indexed when this method is called, even with an empty index collection. To remove the Indexed flag, see unsetMeshFlag().

Parameters
collectionstd::span of index data to set.

Definition at line 596 of file Mesh.h.

Referenced by Cogs::Core::CurtainView::CurtainViewSystem::update().

◆ setInstanceColors()

void Cogs::Core::Mesh::setInstanceColors ( std::span< const glm::vec4 >  colors)
inline

Definition at line 330 of file Mesh.h.

◆ setInstanceCount()

void Cogs::Core::Mesh::setInstanceCount ( size_t  count)
inline

Set the number of instances in this mesh.

Note
Only relevant when MeshFlags::Instanced is set.

Definition at line 1033 of file Mesh.h.

◆ setInstancePositions()

void Cogs::Core::Mesh::setInstancePositions ( std::span< const glm::vec3 >  positions)
inline

Definition at line 325 of file Mesh.h.

◆ setMeshFlag()

void Cogs::Core::Mesh::setMeshFlag ( MeshFlags::EMeshFlags  flag)
inline

Set the given mesh flag.

Parameters
flagMeshFlag to set.

Definition at line 659 of file Mesh.h.

References Cogs::setChanged().

◆ setNormals() [1/2]

template<typename Iterator >
void Cogs::Core::Mesh::setNormals ( Iterator  begin,
Iterator  end 
)
inline

Set the normal data of the mesh.

The data contained between begin and end is copied into the Normals stream of the Mesh.

Parameters
beginIterator to the beginning of the normal data.
endIterator to the end of the normal data.
Template Parameters
IteratorForward iterator to elements consisting of three-component floating point vectors. Must have continpus storage.

Definition at line 408 of file Mesh.h.

◆ setNormals() [2/2]

void Cogs::Core::Mesh::setNormals ( std::span< const glm::vec3 >  normals)
inline

Set the normal data of the Mesh.

Parameters
normalsstd::span of normal data.

Definition at line 392 of file Mesh.h.

Referenced by Cogs::Core::generateMeshNormals(), Cogs::Core::CurtainView::CurtainViewSystem::update(), and Cogs::Core::ShapeSystem::update().

◆ setPositions() [1/2]

template<typename Iterator >
void Cogs::Core::Mesh::setPositions ( Iterator  begin,
Iterator  end 
)
inline

Set the position data of the mesh.

The data contained between begin and end is copied into the Positions stream of the Mesh.

Parameters
beginIterator to the beginning of the position data.
endIterator to the end of the position data.
Template Parameters
IteratorForward iterator to elements consisting of three-component floating point vectors.

Definition at line 346 of file Mesh.h.

◆ setPositions() [2/2]

void Cogs::Core::Mesh::setPositions ( std::span< const glm::vec3 >  positions)
inline

Set the position data of the Mesh.

Parameters
positionsstd::span of position data.

Definition at line 315 of file Mesh.h.

Referenced by Cogs::Core::SeaCurrentsSystem::initialize(), Cogs::Core::CurtainView::CurtainViewSystem::update(), Cogs::Core::Text3DSystem::update(), and Cogs::Core::ShapeSystem::update().

◆ setTangents() [1/2]

template<typename Iterator >
void Cogs::Core::Mesh::setTangents ( Iterator  begin,
Iterator  end 
)
inline

Set the tangent data of the mesh.

The data contained between begin and end is copied into the Tangents stream of the Mesh.

Parameters
beginIterator to the beginning of the tangent data.
endIterator to the end of the tangent data.
Template Parameters
IteratorForward iterator to elements consisting of three-component floating point vectors.

Definition at line 464 of file Mesh.h.

◆ setTangents() [2/2]

void Cogs::Core::Mesh::setTangents ( std::span< const glm::vec3 >  tangents)
inline

Set the tangent data of the Mesh.

Parameters
tangentsstd::span of tangent data.

Definition at line 448 of file Mesh.h.

Referenced by Cogs::Core::generateMeshTangents().

◆ setTexCoords() [1/2]

template<typename Iterator >
void Cogs::Core::Mesh::setTexCoords ( Iterator  begin,
Iterator  end 
)
inline

Set the texture coordinate data of the mesh.

The data contained between begin and end is copied into the TexCoords0 stream of the Mesh.

Parameters
beginIterator to the beginning of the texture coordinate data.
endIterator to the end of the texture coordinate data.
Template Parameters
IteratorForward iterator to elements consisting of two-component floating point vectors.

Definition at line 520 of file Mesh.h.

◆ setTexCoords() [2/2]

void Cogs::Core::Mesh::setTexCoords ( std::span< const glm::vec2 >  texCoords)
inline

Set the texture coordinate data of the Mesh.

Parameters
texCoordsstd::span of texture coordinate data.

Definition at line 504 of file Mesh.h.

Referenced by Cogs::Core::CurtainView::CurtainViewSystem::update(), Cogs::Core::Text3DSystem::update(), and Cogs::Core::ShapeSystem::update().

◆ setVertexData() [1/2]

template<typename Element >
void Cogs::Core::Mesh::setVertexData ( Element *  elements,
size_t  count 
)
inline

Set vertex data.

The vertex data is considered custom formatted data and is set to the Interleaved0 stream.

Parameters
elementsPointer to the first vertex to copy.
countNumber of elements to copy.
Template Parameters
Typeof vertex to copy from. Must implement static getVertexFormat() method.

Definition at line 754 of file Mesh.h.

◆ setVertexData() [2/2]

template<typename Element >
void Cogs::Core::Mesh::setVertexData ( Element *  elements,
size_t  count,
VertexFormatHandle  format 
)
inline

Set vertex data.

The vertex data is considered custom formatted data and is set to the Interleaved0 stream.

Parameters
elementsPointer to the beginning of the first element to copy.
countNumber of elements to copy.
formatPointer to a valid vertex format describing the data pointed to by elements.
Template Parameters
Elementtype of element elements is pointing to.

Definition at line 771 of file Mesh.h.

◆ toFlag()

static constexpr uint16_t Cogs::Core::Mesh::toFlag ( VertexDataType::EVertexDataType  type)
inlinestaticconstexpr

Convert the given type index to a flag.

Parameters
flagVertex data type index to convert to flag.
Returns
A flag that can be bitwise combined to indicate updated streams.

Definition at line 577 of file Mesh.h.

◆ unmap()

void Cogs::Core::Mesh::unmap ( VertexDataType::EVertexDataType  type)
inline

Unmap the stream with the given vertex data type index.

Flags stream changed.

Parameters
typeVertex data type index.

Definition at line 900 of file Mesh.h.

◆ unsetMeshFlag()

void Cogs::Core::Mesh::unsetMeshFlag ( MeshFlags::EMeshFlags  flag)
inline

Unset the given mesh flag.

Parameters
flagMeshFlag to unset.

Definition at line 671 of file Mesh.h.

Member Data Documentation

◆ MaxStreams

constexpr size_t Cogs::Core::Mesh::MaxStreams = 16
staticconstexpr

Maximum number of data streams contained in a single Mesh resource.

Definition at line 305 of file Mesh.h.

◆ NoStream

constexpr int Cogs::Core::Mesh::NoStream = -1
staticconstexpr

Used to indicate no stream.

Definition at line 308 of file Mesh.h.

Referenced by Mesh().


The documentation for this struct was generated from the following files: