23#ifndef VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_DATA_H
24#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_DATA_H
26#include <vclib/algorithms/mesh/import_export/append_replace_to_buffer.h>
27#include <vclib/algorithms/mesh/import_export/export_buffer.h>
28#include <vclib/algorithms/mesh/stat/topology.h>
29#include <vclib/mesh/requirements.h>
30#include <vclib/render/drawable/mesh/mesh_render_info.h>
31#include <vclib/space/complex/tri_poly_index_bimap.h>
79template<
typename MeshRenderDerived>
90 uint nWireframeLines = 0;
95 std::vector<std::pair<uint, uint>> mVertWedgeMap;
99 std::list<uint> mVertsToDuplicate;
105 std::list<std::list<std::pair<uint, uint>>> mFacesToReassign;
131 using enum MRI::Buffers;
136 updateAuxiliaryData(mesh,
btu);
139 updateVerticesData(mesh,
btu);
142 updateFacesData(mesh,
btu);
145 updateEdgesData(mesh,
btu);
148 updateMeshData(mesh,
btu);
151 updateTextureData(mesh,
btu);
162 void swap(MeshRenderData& other)
165 swap(mNumVerts, other.mNumVerts);
166 swap(mNumTris, other.mNumTris);
167 swap(mVertWedgeMap, other.mVertWedgeMap);
168 swap(mVertsToDuplicate, other.mVertsToDuplicate);
169 swap(mFacesToReassign, other.mFacesToReassign);
170 swap(mIndexMap, other.mIndexMap);
171 swap(mBuffersToFill, other.mBuffersToFill);
331 mesh, mVertsToDuplicate, buffer,
fmt);
366 mesh, mVertWedgeMap, mFacesToReassign, buffer);
381 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR, mNumTris);
383 mesh, mVertsToDuplicate, mFacesToReassign, mIndexMap, buffer);
398 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR);
436 mesh, buffer, mIndexMap);
807 const MeshRenderDerived& derived()
const
809 return static_cast<const MeshRenderDerived&
>(*this);
812 void updateAuxiliaryData(
813 const MeshConcept
auto& mesh,
814 MeshRenderInfo::BuffersBitSet btu)
816 using MeshType = MeshRenderDerived::MeshType;
817 using enum MRI::Buffers;
819 if (btu[toUnderlying(VERTICES)] || btu[toUnderlying(WEDGE_TEXCOORDS)] ||
820 btu[toUnderlying(TRIANGLES)]) {
821 mVertWedgeMap.clear();
822 mVertsToDuplicate.clear();
823 mFacesToReassign.clear();
825 if constexpr (HasPerFaceWedgeTexCoords<MeshType>) {
826 if (mesh.isPerFaceWedgeTexCoordsEnabled()) {
827 countVerticesToDuplicateByWedgeTexCoords(
835 mNumVerts = mesh.vertexNumber() + mVertsToDuplicate.size();
838 if constexpr (HasFaces<MeshType>) {
839 if (btu[toUnderlying(TRIANGLES)])
840 mNumTris = countTriangulatedTriangles(mesh);
841 if (btu[toUnderlying(WIREFRAME)])
842 nWireframeLines = countPerFaceVertexReferences(mesh);
845 if constexpr (HasEdges<MeshType>) {
846 if (btu[toUnderlying(EDGES)])
847 mNumEdges = mesh.edgeNumber();
851 void updateVerticesData(
852 const MeshConcept
auto& mesh,
853 MeshRenderInfo::BuffersBitSet btu)
855 using MeshType = MeshRenderDerived::MeshType;
856 using enum MRI::Buffers;
858 if (btu[toUnderlying(VERTICES)]) {
860 derived().setVertexCoordsBuffer(mesh);
864 if (vcl::isPerVertexNormalAvailable(mesh)) {
865 if (btu[toUnderlying(VERT_NORMALS)]) {
867 derived().setVertexNormalsBuffer(mesh);
873 if (vcl::isPerVertexColorAvailable(mesh)) {
874 if (btu[toUnderlying(VERT_COLORS)]) {
876 derived().setVertexColorsBuffer(mesh);
882 if (vcl::isPerVertexTexCoordAvailable(mesh)) {
883 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
885 derived().setVertexTexCoordsBuffer(mesh);
891 void updateFacesData(
892 const MeshConcept
auto& mesh,
893 MeshRenderInfo::BuffersBitSet btu)
895 using MeshType = MeshRenderDerived::MeshType;
896 using enum MRI::Buffers;
899 if (btu[toUnderlying(TRIANGLES)]) {
901 derived().setTriangleIndicesBuffer(mesh);
906 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
908 derived().setWedgeTexCoordsBuffer(mesh);
915 if (btu[toUnderlying(TRI_NORMALS)]) {
917 derived().setTriangleNormalsBuffer(mesh);
924 if (btu[toUnderlying(TRI_COLORS)]) {
926 derived().setTriangleColorsBuffer(mesh);
934 if (vcl::isPerVertexTexCoordAvailable(mesh)) {
935 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
937 derived().setVertexTextureIndicesBuffer(mesh);
944 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
946 derived().setWedgeTextureIndicesBuffer(mesh);
951 if (btu[toUnderlying(WIREFRAME)]) {
953 derived().setWireframeIndicesBuffer(mesh);
958 void updateEdgesData(
959 const MeshConcept
auto& mesh,
960 MeshRenderInfo::BuffersBitSet btu)
962 using MeshType = MeshRenderDerived::MeshType;
963 using enum MRI::Buffers;
966 if (btu[toUnderlying(EDGES)]) {
968 derived().setEdgeIndicesBuffer(mesh);
973 if (btu[toUnderlying(EDGE_NORMALS)]) {
975 derived().setEdgeNormalsBuffer(mesh);
982 if (btu[toUnderlying(EDGE_COLORS)]) {
984 derived().setEdgeColorsBuffer(mesh);
992 const MeshConcept
auto& mesh,
993 MeshRenderInfo::BuffersBitSet btu)
995 using enum MRI::Buffers;
997 if (btu[toUnderlying(MESH_UNIFORMS)]) {
999 derived().setMeshUniforms(mesh);
1003 void updateTextureData(
1004 const MeshConcept
auto& mesh,
1005 MeshRenderInfo::BuffersBitSet btu)
1007 using MeshType = MeshRenderDerived::MeshType;
1008 using enum MRI::Buffers;
1011 if (btu[toUnderlying(TEXTURES)]) {
1013 derived().setTextureUnits(mesh);
The BitSet class allows to treat an integral type as an array of booleans of a guaranteed size.
Definition bit_set.h:53
Format
Color format enumeration.
Definition color.h:77
The MeshRenderData class provides a common interface to automatically update the buffers used to rend...
Definition mesh_render_data.h:81
void fillVertexCoords(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex coordinates of the mesh.
Definition mesh_render_data.h:294
void setTriangleIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of triangle indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:624
void setEdgeIndicesBuffer(const EdgeMeshConcept auto &)
Function that sets the content of edge indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:736
uint numWireframeLines() const
Returns the number of wireframe lines that will be used to render the mesh.
Definition mesh_render_data.h:281
void setVertexColorsBuffer(const MeshConcept auto &)
Function that sets the content of vertex colors buffer and sends the data to the GPU.
Definition mesh_render_data.h:565
void setEdgeNormalsBuffer(const EdgeMeshConcept auto &)
Function that sets the content of edge normals buffer and sends the data to the GPU.
Definition mesh_render_data.h:754
void fillEdgeIndices(const EdgeMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the edge indices of the mesh.
Definition mesh_render_data.h:462
void fillWedgeTextureIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the wedge texture indices of the mesh...
Definition mesh_render_data.h:448
void setEdgeColorsBuffer(const EdgeMeshConcept auto &)
Function that sets the content of edge colors buffer and sends the data to the GPU.
Definition mesh_render_data.h:772
uint numVerts() const
Returns the number of vertices that will be used to render the mesh.
Definition mesh_render_data.h:200
void setTextureUnits(const MeshConcept auto &)
Function that sets the texture units from the mesh and sends the data to the GPU.
Definition mesh_render_data.h:789
void setWedgeTextureIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of wedge texture indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:700
void fillWireframeIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the wireframe indices of the mesh.
Definition mesh_render_data.h:508
void fillEdgeNormals(const EdgeMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the edge normals of the mesh.
Definition mesh_render_data.h:476
void fillTriangleColors(const FaceMeshConcept auto &mesh, auto *buffer, Color::Format fmt)
Given the mesh and a pointer to a buffer, fills the buffer with the triangle colors of the mesh (each...
Definition mesh_render_data.h:410
uint numTris() const
Returns the number of triangles that will be used to render the mesh.
Definition mesh_render_data.h:228
void fillEdgeColors(const EdgeMeshConcept auto &mesh, auto *buffer, Color::Format fmt)
Given the mesh and a pointer to a buffer, fills the buffer with the edge colors of the mesh (each col...
Definition mesh_render_data.h:490
uint numEdges() const
Returns the number of edges that will be used to render the mesh.
Definition mesh_render_data.h:252
void setVertexCoordsBuffer(const MeshConcept auto &)
Function that sets the content of vertex coordinates buffer and sends the data to the GPU.
Definition mesh_render_data.h:529
void setVertexTexCoordsBuffer(const MeshConcept auto &)
Function that sets the content of vertex texture coordinates buffer and sends the data to the GPU.
Definition mesh_render_data.h:583
void fillTriangleNormals(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the triangle normals of the mesh.
Definition mesh_render_data.h:395
void update(const MeshConcept auto &mesh, MRI::BuffersBitSet buffersToUpdate=MRI::BUFFERS_ALL)
Update the buffers used to render the mesh.
Definition mesh_render_data.h:127
void fillVertexTexCoords(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex texcoords of the mesh.
Definition mesh_render_data.h:343
void setTriangleColorsBuffer(const FaceMeshConcept auto &)
Function that sets the content of triangle colors buffer and sends the data to the GPU.
Definition mesh_render_data.h:660
void setVertexTextureIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of vertex texture indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:682
void setVertexNormalsBuffer(const MeshConcept auto &)
Function that sets the content of vertex normals buffer and sends the data to the GPU.
Definition mesh_render_data.h:547
void fillTriangleIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the triangle indices of the mesh.
Definition mesh_render_data.h:378
void setWireframeIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of wireframe indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:718
void fillVertexNormals(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex normals of the mesh.
Definition mesh_render_data.h:309
void fillWedgeTexCoords(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the wedge texcoors of the mesh.
Definition mesh_render_data.h:363
void setMeshUniforms(const MeshConcept auto &)
Function that sets the mesh uniforms from the mesh.
Definition mesh_render_data.h:799
void setWedgeTexCoordsBuffer(const MeshConcept auto &)
Function that sets the content of wedge texture coordinates buffer and sends the data to the GPU.
Definition mesh_render_data.h:606
void fillVertexColors(const MeshConcept auto &mesh, auto *buffer, Color::Format fmt)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex colors of the mesh (each c...
Definition mesh_render_data.h:324
void setTriangleNormalsBuffer(const FaceMeshConcept auto &)
Function that sets the content of triangle normals buffer and sends the data to the GPU.
Definition mesh_render_data.h:642
void fillVertexTextureIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex texture indices of the mes...
Definition mesh_render_data.h:431
The MeshRenderInfo class is a collection of rendering settings for a Mesh.
Definition mesh_render_info.h:61
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The TriPolyIndexBiMap class allows to store a bidirectional mapping between a Polygon Mesh and a Tria...
Definition tri_poly_index_bimap.h:50
The EdgeMeshConcept is evaluated true if the type T is a Mesh (it satisfies the vcl::MeshConcept) and...
Definition mesh_concept.h:209
The FaceMeshConcept is evaluated true if the type T is a Mesh (it satisfies the vcl::MeshConcept) and...
Definition mesh_concept.h:218
HasEdges concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition edge_container.h:131
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:133
Concept that checks if a Mesh has the per Edge Color component.
Definition per_edge.h:97
Concept that checks if a Mesh has the per Edge Normal component.
Definition per_edge.h:142
Concept that checks if a Mesh has the per Face Color component.
Definition per_face.h:111
Concept that checks if a Mesh has the per Face Normal component.
Definition per_face.h:158
Concept that checks if a Mesh has the per Face WedgeTexCoords component.
Definition per_face.h:270
Concept that checks if a Mesh has the per Vertex Color component.
Definition per_vertex.h:98
Concept that checks if a Mesh has the per Vertex Normal component.
Definition per_vertex.h:128
Concept that checks if a Mesh has the per Vertex TexCoord component.
Definition per_vertex.h:174
Concept that checks if a Mesh has the TexturePaths component.
Definition per_mesh.h:112
The Mesh Concept is evaluated to true when the type is a Mesh.
Definition mesh_concept.h:77
void wedgeTexCoordsAsDuplicatedVertexTexCoordsToBuffer(const MeshType &mesh, const std::vector< std::pair< vcl::uint, vcl::uint > > &vertWedgeMap, const std::list< std::list< std::pair< vcl::uint, vcl::uint > > > &facesToReassign, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Export wedge texture coordinates to a buffer of the duplicated vertex texture coordinates.
Definition export_buffer.h:1710
void appendDuplicateVertexCoordsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the coordinates of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:101
void replaceTriangulatedFaceIndicesByVertexDuplicationToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, const std::list< std::list< std::pair< uint, uint > > > &facesToReassign, const TriPolyIndexBiMap &indexMap, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Replace the triangulated face vertex indices in the given buffer with the new indices of the duplicat...
Definition append_replace_to_buffer.h:253
void appendDuplicateVertexColorsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, Color::Representation representation=Color::Representation::INT_0_255, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the colors of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:467
void appendDuplicateVertexNormalsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the normals of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:398
void appendDuplicateVertexTexCoordsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the texture coordinates of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:662
bool isPerEdgeColorAvailable(const MeshType &m)
Returns true if the Color component is available (enabled) in the Edge element of the input mesh m.
Definition edge_requirements.h:214
bool isPerEdgeNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Edge element of the input mesh m.
Definition edge_requirements.h:330
void triangulatedFaceIndicesToBuffer(const MeshType &mesh, auto *buffer, TriPolyIndexBiMap &indexMap=detail::indexMap, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint numTriangles=UINT_NULL, bool getIndicesAsIfContainerCompact=true)
Export into a buffer the vertex indices for each triangle computed by triangulating the faces of a Me...
Definition export_buffer.h:357
void triangulatedFaceWedgeTexCoordIndicesToBuffer(const MeshType &mesh, auto *buffer, const TriPolyIndexBiMap &indexMap)
Export into a buffer the per triangle wedge texture indices of a mesh. Triangles are computed by tria...
Definition export_buffer.h:1649
void edgeIndicesToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, bool getIndicesAsIfContainerCompact=true, uint rowNumber=UINT_NULL)
Export into a buffer the vertex indices for each edge of a Mesh.
Definition export_buffer.h:451
void vertexCoordsToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint rowNumber=UINT_NULL)
Export the vertex coordinates of a mesh to a buffer.
Definition export_buffer.h:101
void wireframeIndicesToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, bool getIndicesAsIfContainerCompact=true, uint rowNumber=UINT_NULL)
Export into a buffer the vertex indices for each edge that composes the wireframe of the Mesh (i....
Definition export_buffer.h:510
bool isPerFaceWedgeTexCoordsAvailable(const MeshType &m)
Returns true if the WedgeTexCoords component is available (enabled) in the Face element of the input ...
Definition face_requirements.h:571
bool isPerFaceNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:330
bool isPerFaceColorAvailable(const MeshType &m)
Returns true if the Color component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:214