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);
346 mesh, mVertsToDuplicate, buffer,
fmt);
381 mesh, mVertWedgeMap, mFacesToReassign, buffer);
396 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR, mNumTris);
398 mesh, mVertsToDuplicate, mFacesToReassign, mIndexMap, buffer);
413 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR);
451 mesh, buffer, mIndexMap);
822 const MeshRenderDerived& derived()
const
824 return static_cast<const MeshRenderDerived&
>(*this);
827 void updateAuxiliaryData(
828 const MeshConcept
auto& mesh,
829 MeshRenderInfo::BuffersBitSet btu)
831 using MeshType = MeshRenderDerived::MeshType;
832 using enum MRI::Buffers;
834 if (btu[toUnderlying(VERTICES)] || btu[toUnderlying(WEDGE_TEXCOORDS)] ||
835 btu[toUnderlying(TRIANGLES)]) {
836 mVertWedgeMap.clear();
837 mVertsToDuplicate.clear();
838 mFacesToReassign.clear();
840 if constexpr (HasPerFaceWedgeTexCoords<MeshType>) {
841 if (mesh.isPerFaceWedgeTexCoordsEnabled()) {
850 mNumVerts = mesh.vertexNumber() + mVertsToDuplicate.size();
853 if constexpr (HasFaces<MeshType>) {
854 if (btu[toUnderlying(TRIANGLES)])
856 if (btu[toUnderlying(WIREFRAME)])
860 if constexpr (HasEdges<MeshType>) {
861 if (btu[toUnderlying(EDGES)])
862 mNumEdges = mesh.edgeNumber();
866 void updateVerticesData(
867 const MeshConcept
auto& mesh,
868 MeshRenderInfo::BuffersBitSet btu)
870 using MeshType = MeshRenderDerived::MeshType;
871 using enum MRI::Buffers;
873 if (btu[toUnderlying(VERTICES)]) {
875 derived().setVertexPositionsBuffer(mesh);
879 if (vcl::isPerVertexNormalAvailable(mesh)) {
880 if (btu[toUnderlying(VERT_NORMALS)]) {
882 derived().setVertexNormalsBuffer(mesh);
888 if (vcl::isPerVertexColorAvailable(mesh)) {
889 if (btu[toUnderlying(VERT_COLORS)]) {
891 derived().setVertexColorsBuffer(mesh);
897 if (vcl::isPerVertexTexCoordAvailable(mesh)) {
898 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
900 derived().setVertexTexCoordsBuffer(mesh);
906 void updateFacesData(
907 const MeshConcept
auto& mesh,
908 MeshRenderInfo::BuffersBitSet btu)
910 using MeshType = MeshRenderDerived::MeshType;
911 using enum MRI::Buffers;
914 if (btu[toUnderlying(TRIANGLES)]) {
916 derived().setTriangleIndicesBuffer(mesh);
921 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
923 derived().setWedgeTexCoordsBuffer(mesh);
930 if (btu[toUnderlying(TRI_NORMALS)]) {
932 derived().setTriangleNormalsBuffer(mesh);
939 if (btu[toUnderlying(TRI_COLORS)]) {
941 derived().setTriangleColorsBuffer(mesh);
949 if (vcl::isPerVertexTexCoordAvailable(mesh)) {
950 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
952 derived().setVertexTextureIndicesBuffer(mesh);
959 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
961 derived().setWedgeTextureIndicesBuffer(mesh);
966 if (btu[toUnderlying(WIREFRAME)]) {
968 derived().setWireframeIndicesBuffer(mesh);
973 void updateEdgesData(
974 const MeshConcept
auto& mesh,
975 MeshRenderInfo::BuffersBitSet btu)
977 using MeshType = MeshRenderDerived::MeshType;
978 using enum MRI::Buffers;
981 if (btu[toUnderlying(EDGES)]) {
983 derived().setEdgeIndicesBuffer(mesh);
988 if (btu[toUnderlying(EDGE_NORMALS)]) {
990 derived().setEdgeNormalsBuffer(mesh);
997 if (btu[toUnderlying(EDGE_COLORS)]) {
999 derived().setEdgeColorsBuffer(mesh);
1006 void updateMeshData(
1007 const MeshConcept
auto& mesh,
1008 MeshRenderInfo::BuffersBitSet btu)
1010 using enum MRI::Buffers;
1012 if (btu[toUnderlying(MESH_UNIFORMS)]) {
1014 derived().setMeshUniforms(mesh);
1018 void updateTextureData(
1019 const MeshConcept
auto& mesh,
1020 MeshRenderInfo::BuffersBitSet btu)
1022 using MeshType = MeshRenderDerived::MeshType;
1023 using enum MRI::Buffers;
1026 if (btu[toUnderlying(TEXTURES)]) {
1028 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:52
A class representing a box in N-dimensional space.
Definition box.h:46
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 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:639
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:751
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:580
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:769
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:477
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:463
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:787
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:804
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:715
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:523
void fillVertexPositions(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex positions of the mesh.
Definition mesh_render_data.h:294
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:491
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:425
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:505
uint numEdges() const
Returns the number of edges that will be used to render the mesh.
Definition mesh_render_data.h:252
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:598
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:410
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:358
void fillVertexQuadIndices(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex quad indices of the mesh (...
Definition mesh_render_data.h:310
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:675
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:697
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:562
void setVertexPositionsBuffer(const MeshConcept auto &)
Function that sets the content of vertex positions buffer and sends the data to the GPU.
Definition mesh_render_data.h:544
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:393
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:733
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:324
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:378
void setMeshUniforms(const MeshConcept auto &)
Function that sets the mesh uniforms from the mesh.
Definition mesh_render_data.h:814
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:621
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:339
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:657
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:446
The MeshRenderInfo class is a collection of rendering settings for a Mesh.
Definition mesh_render_info.h:61
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 edge_requirements.h:58
The FaceMeshConcept is evaluated true if the type T is a Mesh (it satisfies the vcl::MeshConcept) and...
Definition face_requirements.h:70
HasEdges concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition edge_container.h:1064
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:1389
Concept that checks if a Mesh has the per Edge Color component.
Definition edge_requirements.h:118
Concept that checks if a Mesh has the per Edge Normal component.
Definition edge_requirements.h:163
Concept that checks if a Mesh has the per Face Color component.
Definition face_requirements.h:141
Concept that checks if a Mesh has the per Face Normal component.
Definition face_requirements.h:188
Concept that checks if a Mesh has the per Face WedgeTexCoords component.
Definition face_requirements.h:300
Concept that checks if a Mesh has the per Vertex Color component.
Definition vertex_requirements.h:110
Concept that checks if a Mesh has the per Vertex Normal component.
Definition vertex_requirements.h:140
Concept that checks if a Mesh has the per Vertex TexCoord component.
Definition vertex_requirements.h:186
Concept that checks if a Mesh has the TexturePaths component.
Definition mesh_requirements.h:105
A concept that checks whether a class is (inherits from) a Mesh class.
Definition mesh.h:2167
void appendDuplicateVertexPositionsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the positions of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:100
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:1756
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:252
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:466
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:397
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:661
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:370
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:486
void vertexPositionsToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint rowNumber=UINT_NULL)
Export the vertex positions of a mesh to a buffer.
Definition export_buffer.h:100
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:403
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:1695
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:497
void vertexQuadIndicesToBuffer(const MeshType &mesh, auto *buffer)
Export the indices of a quad per vertex to a buffer.
Definition export_buffer.h:142
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:556
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:833
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:592
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:476
uint countVerticesToDuplicateByWedgeTexCoords(const MeshType &mesh, std::vector< std::pair< uint, uint > > &vertWedgeMap=detail::dummyVectorOfPairs, std::list< uint > &vertsToDuplicate=detail::dummyUintList, std::list< std::list< std::pair< uint, uint > > > &facesToReassign=detail::dummyListOfLists)
This function counts the number of vertices that must be duplicated in a mesh to have a unique texcoo...
Definition topology.h:279
uint countPerFaceVertexReferences(const FaceMeshConcept auto &mesh)
Count the number of references to vertices in the mesh faces.
Definition topology.h:182
uint countTriangulatedTriangles(const FaceMeshConcept auto &mesh)
Counts the number of resulting triangles if the input mesh would be triangulated by splitting each fa...
Definition topology.h:239