Skip to content

Core::Mesh ​

Mesh represents a complete 3D model. More...

#include "Core/Resources/Mesh.h"

Inherits from Core::ManagedResource

Public Classes ​

Name
structMaterial <br>Data class holding basic material information.
structMeshPart <br>Individual part of the bigger mesh containing separate geometry, material and textures.
structTextureSet <br>A set of textures for multi-mapping.

Public Types ​

Name
enumBufferType { STATIC, DYNAMIC, STREAM}
enumDrawType { ARRAYS, ELEMENTS}
enumPrimitiveType { LINES, TRIANGLES}

Public Functions ​

Name
~Mesh() override
voiddispose()
voidrender() const<br>Renders the mesh and all its mesh parts.
voidrenderInstanced(int instances) const
voidrenderMeshPart(const MeshPart & meshPart) const<br>Renders an individual mesh part.
voidrenderMeshPartInstanced(const MeshPart & meshPart, int instances) const
voidupdate(Mesh::PrimitiveType primitiveType, const float * verts, const unsigned int nVertices, const float * colors, const unsigned int nColors)<br>Update mesh vertices and colors.
voidupdate(Mesh::PrimitiveType primitiveType, const float * verts, const unsigned int nVertices, const unsigned int * indices, const unsigned int nIndices, const float * colors, const unsigned int nColors)<br>Update mesh indexed vertices and colors.
Mesh *create(Mesh::PrimitiveType primitiveType, const float * verts, const unsigned int nVertices, const float * colors, const unsigned int nColors, BufferType bufferType =BufferType::STATIC)<br>Create mesh from vertices and colors.
Mesh *create(Mesh::PrimitiveType primitiveType, const float * verts, const unsigned int nVertices, const unsigned int * indices, const unsigned int nIndices, const float * colors, const unsigned int nColors, BufferType bufferType =BufferType::STATIC)<br>Create mesh from indexed vertices and colors; Only fills the color vertex buffer.
Mesh *load(const std::string & path, bool normalize =false, bool minimalLoad =false)<br>Load mesh from a model file using assimp Fills normal, texcoord and tangent vertex buffers.

Public Attributes ​

Name
glm::vec3m_boundingBoxMax <br>Mesh bounding box max, derived from bounding boxes of mesh parts.
glm::vec3m_boundingBoxMin <br>Mesh bounding box min, derived from bounding boxes of mesh parts.
BufferTypem_bufferType
GLuintm_color_vbo
boolm_disposed <br>Whether the mesh has been deallocated.
DrawTypem_drawType
GLuintm_ebo
std::vector< MeshPart >m_meshParts <br>List of mesh parts making up this mesh.
unsigned intm_nIndices <br>count of indices af all the mesh parts together
GLuintm_normal_vbo
boolm_normalized <br>Whether the mesh geometry has been normalized on load.
unsigned intm_nVertices <br>count of vertices af all the mesh parts together
std::stringm_path <br>If applicable, file path to the primary source file.
PrimitiveTypem_primitiveType
GLuintm_tangent_vbo
intm_textureCount <br>Number of loaded textures for this mesh (files or embedded)
std::set< std::string >m_textureFileList <br>List of texture file paths this mesh requires (not including embedded textures)
boolm_useColors <br>Whether the vertex colors vbo is used.
boolm_useNormals <br>Whether the normal vbo is used.
boolm_useTangents <br>Whether the tangent vbo is used.
boolm_useTexcoords <br>Whether the texture coordinates vbo is used.
GLuintm_uv_vbo
GLuintm_vao
GLuintm_vertex_vbo

Friends ​

Name
classResourceManager

Additional inherited members ​

Public Functions inherited from Core::ManagedResource

Name
virtual~ManagedResource() =default

Public Attributes inherited from Core::ManagedResource

Name
size_tm_resourceId <br>Resource ID of an object An identifier used by a ResourceManager.

Detailed Description ​

cpp
class Core::Mesh;

Mesh represents a complete 3D model.

It hold relevant opengl state data and a list of mesh parts that actually make up the model. Each mesh part also holds information about a material and a set of textures. Geometry is immediately passed to OpenGL and not preserved in memory. All geometry data is stored in a set of buffers that are shared among the mesh parts of the mesh.

Can be loaded using assimp with Mesh::load() Or created directly from data using Mesh::create()

Vertex attribute locations are hardcoded and are:

  • location 0 = aPos (vec3)
  • location 1 = aNormal (vec3)
  • location 2 = aTexCoord (vec2)
  • location 3 = aTangent (vec3)
  • location 4 = aColor (vec3)

Normals, TexCoords, Tangents and Colors can be individually disabled

Public Types Documentation ​

enum BufferType ​

EnumeratorValueDescription
STATIC
DYNAMIC
STREAM

enum DrawType ​

EnumeratorValueDescription
ARRAYS
ELEMENTS

enum PrimitiveType ​

EnumeratorValueDescription
LINES
TRIANGLES

Public Functions Documentation ​

function ~Mesh ​

cpp
~Mesh() override

function dispose ​

cpp
void dispose()

function render ​

cpp
void render() const

Renders the mesh and all its mesh parts.

For more control over rendering you can iterate through individual meshParts and use renderMeshPart()

function renderInstanced ​

cpp
void renderInstanced(
    int instances
) const

function renderMeshPart ​

cpp
void renderMeshPart(
    const MeshPart & meshPart
) const

Renders an individual mesh part.

Parameters:

  • meshPart The mesh part to render.

Note that prior to calling this method the mesh's VAO needs to be bound!

function renderMeshPartInstanced ​

cpp
void renderMeshPartInstanced(
    const MeshPart & meshPart,
    int instances
) const

function update ​

cpp
void update(
    Mesh::PrimitiveType primitiveType,
    const float * verts,
    const unsigned int nVertices,
    const float * colors,
    const unsigned int nColors
)

Update mesh vertices and colors.

Only fills the color vertex buffer.

function update ​

cpp
void update(
    Mesh::PrimitiveType primitiveType,
    const float * verts,
    const unsigned int nVertices,
    const unsigned int * indices,
    const unsigned int nIndices,
    const float * colors,
    const unsigned int nColors
)

Update mesh indexed vertices and colors.

Only fills the color vertex buffer.

function create ​

cpp
static Mesh * create(
    Mesh::PrimitiveType primitiveType,
    const float * verts,
    const unsigned int nVertices,
    const float * colors,
    const unsigned int nColors,
    BufferType bufferType =BufferType::STATIC
)

Create mesh from vertices and colors.

Return: Pointer to the new Mesh object (newly allocated, to be managed externally)

Only fills the color vertex buffer.

function create ​

cpp
static Mesh * create(
    Mesh::PrimitiveType primitiveType,
    const float * verts,
    const unsigned int nVertices,
    const unsigned int * indices,
    const unsigned int nIndices,
    const float * colors,
    const unsigned int nColors,
    BufferType bufferType =BufferType::STATIC
)

Create mesh from indexed vertices and colors; Only fills the color vertex buffer.

Return: Pointer to the new Mesh object (newly allocated, to be managed externally)

function load ​

cpp
static Mesh * load(
    const std::string & path,
    bool normalize =false,
    bool minimalLoad =false
)

Load mesh from a model file using assimp Fills normal, texcoord and tangent vertex buffers.

Parameters:

  • path Path to the model file.
  • minimalLoad If true, only the bare minimum of the model is loaded. Used to quickly aquire basic information from assimp without actually meaning to use the mesh.

Return: Pointer to the new Mesh object (newly allocated, to be managed externally)

Public Attributes Documentation ​

variable m_boundingBoxMax ​

cpp
glm::vec3 m_boundingBoxMax {0.0f};

Mesh bounding box max, derived from bounding boxes of mesh parts.

variable m_boundingBoxMin ​

cpp
glm::vec3 m_boundingBoxMin {0.0f};

Mesh bounding box min, derived from bounding boxes of mesh parts.

variable m_bufferType ​

cpp
BufferType m_bufferType {BufferType::STATIC};

variable m_color_vbo ​

cpp
GLuint m_color_vbo;

variable m_disposed ​

cpp
bool m_disposed {false};

Whether the mesh has been deallocated.

variable m_drawType ​

cpp
DrawType m_drawType;

variable m_ebo ​

cpp
GLuint m_ebo;

variable m_meshParts ​

cpp
std::vector< MeshPart > m_meshParts;

List of mesh parts making up this mesh.

variable m_nIndices ​

cpp
unsigned int m_nIndices {0};

count of indices af all the mesh parts together

variable m_normal_vbo ​

cpp
GLuint m_normal_vbo;

variable m_normalized ​

cpp
bool m_normalized {false};

Whether the mesh geometry has been normalized on load.

variable m_nVertices ​

cpp
unsigned int m_nVertices {0};

count of vertices af all the mesh parts together

variable m_path ​

cpp
std::string m_path;

If applicable, file path to the primary source file.

variable m_primitiveType ​

cpp
PrimitiveType m_primitiveType;

variable m_tangent_vbo ​

cpp
GLuint m_tangent_vbo;

variable m_textureCount ​

cpp
int m_textureCount {0};

Number of loaded textures for this mesh (files or embedded)

variable m_textureFileList ​

cpp
std::set< std::string > m_textureFileList;

List of texture file paths this mesh requires (not including embedded textures)

variable m_useColors ​

cpp
bool m_useColors {false};

Whether the vertex colors vbo is used.

variable m_useNormals ​

cpp
bool m_useNormals {false};

Whether the normal vbo is used.

variable m_useTangents ​

cpp
bool m_useTangents {false};

Whether the tangent vbo is used.

variable m_useTexcoords ​

cpp
bool m_useTexcoords {false};

Whether the texture coordinates vbo is used.

variable m_uv_vbo ​

cpp
GLuint m_uv_vbo;

variable m_vao ​

cpp
GLuint m_vao;

variable m_vertex_vbo ​

cpp
GLuint m_vertex_vbo;

Friends ​

friend ResourceManager ​

cpp
friend class ResourceManager(
    ResourceManager 
);

Updated on 2026-09-11 at 21:24:26 +0000