Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
Mesh Class Reference

Mesh represents a drawable collection of vertices, textures, and shader data. It stores vertex data, manages a vertex array object (VAO), and allows attaching multiple textures. The mesh also supports serialization of vertex data into a flat array for GPU uploading. More...

#include <Mesh.h>

Public Member Functions

 Mesh ()
 Default constructor. Initializes an empty mesh.
 
 Mesh (const std::vector< Vertex > &pVertices)
 Constructs a mesh using a list of vertices. Automatically creates a vertex array object using the provided vertex data.
 
void Unload ()
 Unloads the mesh by deleting the vertex array object. This frees GPU resources associated with the mesh.
 
void AddTexture (Texture *pTexture)
 Adds a texture to the mesh. The texture can later be bound during rendering.
 
float * ToVerticeArray ()
 Converts the mesh's vertex data into a flat float array suitable for GPU uploading. Each vertex contributes 8 floats (position [3], normal [3], uv [2]).
 
TextureGetTexture (int index)
 Retrieves a texture attached to the mesh at a specified index.
 
ShaderProgram GetShaderProgram ()
 the shader program currently assigned to the mesh.
 
VertexArrayGetVertexArray ()
 the vertex array object used to render the mesh.
 
void SetShaderProgram (ShaderProgram pShaderProgram)
 the shader program to be used by the mesh for rendering.
 
void SetVertexArray (VertexArray *pVao)
 the vertex array object (VAO) for the mesh. This replaces the current VAO if one exists.
 

Detailed Description

Mesh represents a drawable collection of vertices, textures, and shader data. It stores vertex data, manages a vertex array object (VAO), and allows attaching multiple textures. The mesh also supports serialization of vertex data into a flat array for GPU uploading.

Constructor & Destructor Documentation

◆ Mesh() [1/2]

Mesh::Mesh ( )

Default constructor. Initializes an empty mesh.

◆ Mesh() [2/2]

Mesh::Mesh ( const std::vector< Vertex > & pVertices)

Constructs a mesh using a list of vertices. Automatically creates a vertex array object using the provided vertex data.

Parameters
pVerticesThe list of vertices that make up the mesh geometry.

Member Function Documentation

◆ AddTexture()

void Mesh::AddTexture ( Texture * pTexture)

Adds a texture to the mesh. The texture can later be bound during rendering.

Parameters
pTexturePointer to the texture to add to the mesh.

◆ GetShaderProgram()

ShaderProgram Mesh::GetShaderProgram ( )

the shader program currently assigned to the mesh.

Returns
The shader program used by this mesh.

◆ GetTexture()

Texture * Mesh::GetTexture ( int index)

Retrieves a texture attached to the mesh at a specified index.

Parameters
indexThe index of the texture in the internal texture list.
Returns
Pointer to the texture if it exists, otherwise nullptr.

◆ GetVertexArray()

VertexArray * Mesh::GetVertexArray ( )

the vertex array object used to render the mesh.

Returns
Pointer to the VertexArray object associated with the mesh.

◆ SetShaderProgram()

void Mesh::SetShaderProgram ( ShaderProgram pShaderProgram)

the shader program to be used by the mesh for rendering.

Parameters
pShaderProgramThe shader program to assign.

◆ SetVertexArray()

void Mesh::SetVertexArray ( VertexArray * pVao)

the vertex array object (VAO) for the mesh. This replaces the current VAO if one exists.

Parameters
pVaoPointer to the VertexArray object.

◆ ToVerticeArray()

float * Mesh::ToVerticeArray ( )

Converts the mesh's vertex data into a flat float array suitable for GPU uploading. Each vertex contributes 8 floats (position [3], normal [3], uv [2]).

Returns
Pointer to a newly allocated float array. Caller is responsible for deleting it.

◆ Unload()

void Mesh::Unload ( )

Unloads the mesh by deleting the vertex array object. This frees GPU resources associated with the mesh.


The documentation for this class was generated from the following files: