Visual Computing Library
|
The MeshRenderData class provides a common interface to automatically update the buffers used to render a mesh, with the possibility to update only a subset of the buffers, taking into account different scenarios (e.g., vertex duplication, polygonal faces triangulation) consistently. More...
#include <vclib/render/drawable/mesh/mesh_render_data.h>
Public Member Functions | |
void | update (const MeshConcept auto &mesh, MRI::BuffersBitSet buffersToUpdate=MRI::BUFFERS_ALL) |
Update the buffers used to render the mesh. | |
Protected Member Functions | |
MeshRenderData (MRI::BuffersBitSet buffersToFill) | |
void | swap (MeshRenderData &other) |
uint | numVerts () const |
Returns the number of vertices that will be used to render the mesh. | |
uint | numTris () const |
Returns the number of triangles that will be used to render the mesh. | |
uint | numEdges () const |
Returns the number of edges that will be used to render the mesh. | |
uint | numWireframeLines () const |
Returns the number of wireframe lines that will be used to render the mesh. | |
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. | |
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. | |
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 color is packed in a single uint). | |
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. | |
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. | |
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. | |
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. | |
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 color is packed in a single uint). | |
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 mesh. | |
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. | |
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. | |
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. | |
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 color is packed in a single uint). | |
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. | |
void | setVertexCoordsBuffer (const MeshConcept auto &) |
Function that sets the content of vertex coordinates buffer and sends the data to the GPU. | |
void | setVertexNormalsBuffer (const MeshConcept auto &) |
Function that sets the content of vertex normals buffer and sends the data to the GPU. | |
void | setVertexColorsBuffer (const MeshConcept auto &) |
Function that sets the content of vertex colors buffer and sends the data to the GPU. | |
void | setVertexTexCoordsBuffer (const MeshConcept auto &) |
Function that sets the content of vertex texture coordinates buffer and sends the data to the GPU. | |
void | setWedgeTexCoordsBuffer (const MeshConcept auto &) |
Function that sets the content of wedge texture coordinates buffer and sends the data to the GPU. | |
void | setTriangleIndicesBuffer (const FaceMeshConcept auto &) |
Function that sets the content of triangle indices buffer and sends the data to the GPU. | |
void | setTriangleNormalsBuffer (const FaceMeshConcept auto &) |
Function that sets the content of triangle normals buffer and sends the data to the GPU. | |
void | setTriangleColorsBuffer (const FaceMeshConcept auto &) |
Function that sets the content of triangle colors buffer and sends the data to the GPU. | |
void | setVertexTextureIndicesBuffer (const FaceMeshConcept auto &) |
Function that sets the content of vertex texture indices buffer and sends the data to the GPU. | |
void | setWedgeTextureIndicesBuffer (const FaceMeshConcept auto &) |
Function that sets the content of wedge texture indices buffer and sends the data to the GPU. | |
void | setWireframeIndicesBuffer (const FaceMeshConcept auto &) |
Function that sets the content of wireframe indices buffer and sends the data to the GPU. | |
void | setEdgeIndicesBuffer (const EdgeMeshConcept auto &) |
Function that sets the content of edge indices buffer and sends the data to the GPU. | |
void | setEdgeNormalsBuffer (const EdgeMeshConcept auto &) |
Function that sets the content of edge normals buffer and sends the data to the GPU. | |
void | setEdgeColorsBuffer (const EdgeMeshConcept auto &) |
Function that sets the content of edge colors buffer and sends the data to the GPU. | |
void | setTextureUnits (const MeshConcept auto &) |
Function that sets the texture units from the mesh and sends the data to the GPU. | |
void | setMeshUniforms (const MeshConcept auto &) |
Function that sets the mesh uniforms from the mesh. | |
Private Types | |
using | MRI = MeshRenderInfo |
Private Member Functions | |
MeshRenderDerived & | derived () |
const MeshRenderDerived & | derived () const |
void | updateAuxiliaryData (const MeshConcept auto &mesh, MeshRenderInfo::BuffersBitSet btu) |
void | updateVerticesData (const MeshConcept auto &mesh, MeshRenderInfo::BuffersBitSet btu) |
void | updateFacesData (const MeshConcept auto &mesh, MeshRenderInfo::BuffersBitSet btu) |
void | updateEdgesData (const MeshConcept auto &mesh, MeshRenderInfo::BuffersBitSet btu) |
void | updateMeshData (const MeshConcept auto &mesh, MeshRenderInfo::BuffersBitSet btu) |
void | updateTextureData (const MeshConcept auto &mesh, MeshRenderInfo::BuffersBitSet btu) |
Private Attributes | |
uint | mNumVerts = 0 |
uint | mNumTris = 0 |
uint | mNumEdges = 0 |
uint | nWireframeLines = 0 |
std::vector< std::pair< uint, uint > > | mVertWedgeMap |
std::list< uint > | mVertsToDuplicate |
std::list< std::list< std::pair< uint, uint > > > | mFacesToReassign |
TriPolyIndexBiMap | mIndexMap |
MRI::BuffersBitSet | mBuffersToFill = MRI::BUFFERS_ALL |
The MeshRenderData class provides a common interface to automatically update the buffers used to render a mesh, with the possibility to update only a subset of the buffers, taking into account different scenarios (e.g., vertex duplication, polygonal faces triangulation) consistently.
The class uses the Curiously Recurring Template Pattern (CRTP) to allow this class to call functions to set the buffers (that are managed by the derived class, since they depend on the rendering backend used) when the users requires to update the mesh data (that may be all the data, or a subset).
It also provides a set of protected functions that may be used by the derived class to fill the buffers in a consistent way, managing automatically all the possible scenarios.
The derived class should implement all the functions that set the buffers (the set*(const MeshType& mesh)
member functions listed in this class). If the derived class does not implement one of these functions, the base class will use the default implementation, that does nothing.
An example of implementation in a derived class is the following (assuming that Base
is this class, and MeshType
is the mesh type that will be used to render the mesh). Here we first fill the vertex coordinates to a std::vector:
Refer to the documentation of the functions that set the buffers for more details on how to fill the buffers.
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the edge colors of the mesh (each color is packed in a single uint).
The buffer must be preallocated with the correct size: numEdges()
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the edge indices of the mesh.
The buffer must be preallocated with the correct size: numEdges() * 2
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the edge normals of the mesh.
The buffer must be preallocated with the correct size: numEdges() * 3
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the triangle colors of the mesh (each color is packed in a single uint).
The buffer must be preallocated with the correct size: numTris()
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the triangle indices of the mesh.
The buffer must be preallocated with the correct size: numTris() * 3
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the triangle normals of the mesh.
The buffer must be preallocated with the correct size: numTris() * 3
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the vertex colors of the mesh (each color is packed in a single uint).
The buffer must be preallocated with the correct size: numVerts()
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the vertex coordinates of the mesh.
The buffer must be preallocated with the correct size: numVerts() * 3
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the vertex normals of the mesh.
The buffer must be preallocated with the correct size: numVerts() * 3
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the vertex texcoords of the mesh.
The buffer must be preallocated with the correct size: numVerts() * 2
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the vertex texture indices of the mesh.
Although the vertex texcoords are associated to the vertices in the vclib meshes, for rendering purposes the index of each vertex texcoord is associated to the triangles (that must be triangulated accordingly).
The buffer must be preallocated with the correct size: numTris()
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the wedge texcoors of the mesh.
Although the wedge texcoords are associated to the faces in the vclib meshes, for rendering purposes it is useful to have them associated to the vertices (that must be duplicated accordingly, and only when necessary).
The buffer must be preallocated with the correct size: numVerts() * 2
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the wedge texture indices of the mesh.
The buffer must be preallocated with the correct size: numTris()
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Given the mesh and a pointer to a buffer, fills the buffer with the wireframe indices of the mesh.
The buffer must be preallocated with the correct size: numWireframeLines()
.
[in] | mesh | the input mesh |
[out] | buffer | the buffer to fill |
|
inlineprotected |
Returns the number of edges that will be used to render the mesh.
The number of edges must be used to compute the size of the buffers that will store the edges data (indices, normals, colors, etc).
It can be used along with the functions fillEdge*
provided by this class. A common workflow is the following:
fill*
functions documentation.
|
inlineprotected |
Returns the number of triangles that will be used to render the mesh.
The number of triangles must be used to compute the size of the buffers that will store the triangles data (indices, normals, colors, etc).
It can be used along with the functions fillTriangle*
provided by this class. A common workflow is the following:
fill*
functions documentation.
|
inlineprotected |
Returns the number of vertices that will be used to render the mesh.
The number of vertices must be used to compute the size of the buffers that will store the vertex data (coordinates, normals, colors, etc).
It can be used along with the functions fillVertex*
provided by this class. A common workflow is the following:
fill*
functions documentation.
|
inlineprotected |
Returns the number of wireframe lines that will be used to render the mesh.
The number of wireframe lines must be used to compute the size of the buffers that will store the wireframe data (indices).
It can be used along with the functions fillWireframe*
provided by this class. A common workflow is the following:
fill*
functions documentation.
|
inlineprotected |
Function that sets the content of edge colors buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the edge colors using the numEdges()
and fillEdgeColors()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-edge colors since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of edge indices buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the edge indices using the numEdges() * 2
and fillEdgeIndices()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide edges since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of edge normals buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the edge normals using the numEdges() * 3
and fillEdgeNormals()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-edge normals since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the mesh uniforms from the mesh.
The function should set the uniforms of the mesh (e.g., mesh color, transform) and prepare them to be bound to the shader program.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the texture units from the mesh and sends the data to the GPU.
The function should take the texture from the mesh (loading them if they are not available in the mesh) and send them to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide texture paths, since the function is called only if the mesh has them. However, it is necessary to check whether the mesh has texture images and, in that case, check whether the texture is already loaded.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of triangle colors buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the triangle colors using the numTris()
and fillTriangleColors()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-face colors since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of triangle indices buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the triangle indices using the numTris() * 3
and fillTriangleIndices()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide faces since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of triangle normals buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the triangle normals using the numTris() * 3
and fillTriangleNormals()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-face normals since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of vertex colors buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the vertex colors using the numVerts()
and fillVertexColors()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-vertex colors since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of vertex coordinates buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the vertex coordinates using the numVerts() * 3
and fillVertexCoords()
functions, and then send the data to the GPU using the rendering backend.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of vertex normals buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the vertex normals using the numVerts() * 3
and fillVertexNormals()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-vertex normals since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of vertex texture coordinates buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the vertex texcoords using the numVerts() * 2
and fillVertexTexCoords()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-vertex texcoords since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of vertex texture indices buffer and sends the data to the GPU.
Although the vertex texcoords are associated to the vertices in the vclib meshes, for rendering purposes the index of each vertex texcoord is associated to the triangles (that must be triangulated accordingly).
The function should allocate and fill a cpu buffer to store the vertex texcoord indices using the numTris()
and fillVertexTextureIndices()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-vertex texcoords since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of wedge texture coordinates buffer and sends the data to the GPU.
Although the wedge texcoords are associated to the faces in the vclib meshes, for rendering purposes it is useful to have them associated to the vertices (that must be duplicated accordingly, and only when necessary).
The function should allocate and fill a cpu buffer to store the wedge texcoords using the numVerts() * 2
and fillWedgeTexCoords()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-face wedge texcoords since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of wedge texture indices buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the wedge texcoord indices using the numTris()
and fillWedgeTextureIndices()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide per-face wedge texcoords since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inlineprotected |
Function that sets the content of wireframe indices buffer and sends the data to the GPU.
The function should allocate and fill a cpu buffer to store the wireframe indices using the numWireframeLines() * 2
and fillWireframeIndices()
functions, and then send the data to the GPU using the rendering backend.
There is no need to check whether the Mesh can provide faces since the function is called only if the mesh has them.
See the MeshRenderData class documentation for an example of implementation.
[in] | mesh | the input mesh from which to get the data |
|
inline |
Update the buffers used to render the mesh.
[in] | mesh | the input mesh from which to get the data |
[in] | buffersToUpdate | the buffers that must be updated. By default, all the buffers are updated. |