ImFusion SDK 4.3
MeshGl Class Reference

#include <ImFusion/Mesh/Rendering/MeshGl.h>

Stores vertex and texture data of a Mesh on the GPU so that it can be rendered using OpenGL. More...

+ Inheritance diagram for MeshGl:

Detailed Description

Stores vertex and texture data of a Mesh on the GPU so that it can be rendered using OpenGL.

A MeshGl instance is always bound to a parent Mesh instance for which it provides OpenGL buffers and textures with the same data as its parent CPU counterpart. It uses signals to monitor the parent for changes so that the data on the GPU is updated when necessary.

Instances of this class serve as main input to the render() function of MeshRendererXyz classes. MeshGl provides a set of OpenGL VertexBuffers with individual attributes for the vertex positions, colors, texture coordinates, normals, as well as per-face and per-vertex indices and labels. They are split up into separate buffers and only computed lazily on-demand so that you can mix and match because different renderers require only an individual subset of these vertex attributes. All VertexBuffers share the same underlying primitive layout and are supposed to be rendered directly as GL::Primitive::Triangles without a GL::IndexBuffer.

Use a GL::VertexArrayObject to combine them into a single rendering call, e.g.:

// select either per-face or per-vertex normals
const GL::VertexBuffer* normalsBuffer = (useFaceNormals ? &meshGl.perFaceNormalsBuffer() : &meshGl.perVertexNormalsBuffer());
// combine the buffer with vertex positions and colors with the previously selected normals buffer
// - vertex positions will end up as vertex attribute 0
// - normals will end up as vertex attribute 1
// - colors will end up as vertex attribute 2
// - texture coordinates will be dropped
vao.setAttributes({{&meshGl.positionColorTexCoordBuffer(), {0, 2, -1}}, {normalsBuffer, {1}}});
// draw the mesh
Wrapper around an OpenGL Vertex Array Object (VAO) to define the vertex attribute specification for r...
Definition VertexBuffer.h:212
void setAttributes(const VertexBuffer &vbo, const IndexBuffer *ibo=nullptr)
Configure the VAO with the current attribute configuration of the vertex buffer and an optional index...
void draw(Primitive mode) const
Renders a single primitive using all vertices of the previously bound VBOs/IBO.
Specialization of Buffer to store vertex array data.
Definition VertexBuffer.h:59
@ Triangles
Vertices 0, 1, and 2 form a triangle. Vertices 3, 4, and 5 form a triangle. And so on.
Definition Types.h:71
See also
MeshRendererSurface, MeshRendererIntersection, MeshRendererNormals, MeshRendererOutline

Public Member Functions

 MeshGl (const Mesh &parentMesh)
 
const Meshmesh () const
 Returns the underlying parent mesh.
 
const std::vector< vec3f > & customPerVertexColors () const
 Returns an optional list of custom per-vertex colors to use in positionColorTexCoordBuffer() instead of the ones in the parent Mesh.
 
void setCustomPerVertexColors (const std::vector< vec3f > &colors)
 Set an optional list of custom per-vertex colors to use in positionColorTexCoordBuffer() instead of the ones in the parent Mesh.
 
const GL::VertexBufferpositionColorTexCoordBuffer () const
 Returns a vertex buffer with the following data:
 
const GL::VertexBufferperVertexNormalsBuffer () const
 Returns a vertex buffer with a single attribute containing the per-vertex normals.
 
const GL::VertexBufferperFaceNormalsBuffer () const
 Returns a vertex buffer with a single attribute containing the per-face normals.
 
const GL::VertexBufferfaceIndexLabelBuffer () const
 Returns a vertex buffer with the following data:
 
const GL::VertexBuffervertexIndexLabelBuffer () const
 Returns a vertex buffer with the following data:
 
const GlImagecolorTexture () const
 Returns the optional color texture in case the mesh is textured.
 
const GlImagefaceLabelTexture () const
 Returns the LUT for face labels.
 
const GlImagevertexLabelTexture () const
 Returns the LUT for vertex labels.
 
bool isDirty () const
 
- Public Member Functions inherited from SignalReceiver
 SignalReceiver ()=default
 Default constructor.
 
 SignalReceiver (const SignalReceiver &other)
 Copy constructor, does not copy any existing signal connections from other.
 
SignalReceiveroperator= (SignalReceiver rhs)
 Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs.
 
virtual ~SignalReceiver ()
 Virtual destructor disconnects from all connected signals.
 

Additional Inherited Members

- Protected Member Functions inherited from SignalReceiver
void disconnectAll ()
 Disconnects all existing connections.
 

Member Function Documentation

◆ setCustomPerVertexColors()

void setCustomPerVertexColors ( const std::vector< vec3f > & colors)

Set an optional list of custom per-vertex colors to use in positionColorTexCoordBuffer() instead of the ones in the parent Mesh.

The number of provided colors must match the number of vertices of the parent mesh.

◆ positionColorTexCoordBuffer()

const GL::VertexBuffer & positionColorTexCoordBuffer ( ) const

Returns a vertex buffer with the following data:

  • attribute 0: vertex positions
  • attribute 1: vertex colors (if present)
  • attribute 2: vertex texture coordinates (if present)

◆ faceIndexLabelBuffer()

const GL::VertexBuffer & faceIndexLabelBuffer ( ) const

Returns a vertex buffer with the following data:

  • attribute 0: face index
  • attribute 1: face label

◆ vertexIndexLabelBuffer()

const GL::VertexBuffer & vertexIndexLabelBuffer ( ) const

Returns a vertex buffer with the following data:

  • attribute 0: vertex index
  • attribute 1: vertex label

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close