lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::scene::Mesh Class Reference

Represents a 3D mesh with associated vertex array and shader. More...

#include <mesh.hpp>

Public Member Functions

 Mesh (const std::vector< Vertex > &vert, const std::vector< unsigned int > &indices, std::shared_ptr< renderer::Shader > shader)
 Constructor for the Mesh class.
 
 Mesh (std::shared_ptr< renderer::VertexArray > vao, std::shared_ptr< renderer::Shader > shader, unsigned int idx_count)
 Constructor for the Mesh class.
 
 ~Mesh ()=default
 Destructor for the Mesh class.
 
void bind () const
 Binds the mesh for rendering.
 
void unbind () const
 Unbinds the mesh after rendering.
 
void render () const
 Renders the mesh.
 
std::shared_ptr< renderer::VertexArrayget_vertex_array () const
 Getter for vertex array.
 
std::shared_ptr< renderer::Shaderget_shader () const
 Getter for shader.
 
void set_shader (std::shared_ptr< renderer::Shader > shader)
 Setter for shader.
 
unsigned int get_index_count () const
 Getter for index count.
 
const std::vector< Vertex > & get_vertices () const
 Getter for vertices.
 
const std::vector< unsigned int > & get_indices () const
 Getter for indices.
 
bool has_vert_data () const
 Check if the mesh has vertex data.
 
std::shared_ptr< Materialget_material () const
 Retrieve the material associated with the mesh.
 
void set_material (std::shared_ptr< Material > material)
 Sets the material associated to the mesh.
 
const AABBget_bounding_box () const
 Getter for bounding box.
 
const BoundingSphereget_bounding_sphere () const
 Getter for bounding sphere.
 

Static Public Member Functions

static std::shared_ptr< Meshcreate_cube (std::shared_ptr< renderer::Shader > shader, unsigned int subdivs=1)
 Creates a cube mesh.
 
static std::shared_ptr< Meshcreate_quad (std::shared_ptr< renderer::Shader > shader, float width=1.0f, float height=1.0f)
 Creates a quad mesh.
 
static std::shared_ptr< Meshcreate_sphere (std::shared_ptr< renderer::Shader > shader, float radius=0.5f, unsigned int lonsegs=32, unsigned int latsegs=32)
 Creates a sphere mesh.
 

Detailed Description

Represents a 3D mesh with associated vertex array and shader.

The Mesh class encapsulates a vertex array and a shader program used for rendering 3D meshes. It provides access to the underlying vertex array and shader, facilitating the rendering process in a graphics application.

Constructor & Destructor Documentation

◆ Mesh() [1/2]

lmgl::scene::Mesh::Mesh ( const std::vector< Vertex > & vert,
const std::vector< unsigned int > & indices,
std::shared_ptr< renderer::Shader > shader )

Constructor for the Mesh class.

Initializes a Mesh with the provided vertices, indices, and shader.

Parameters
vertVector of Vertex objects defining the mesh geometry.
indicesVector of unsigned integers defining the mesh indices.
shaderShared pointer to the Shader object.

◆ Mesh() [2/2]

lmgl::scene::Mesh::Mesh ( std::shared_ptr< renderer::VertexArray > vao,
std::shared_ptr< renderer::Shader > shader,
unsigned int idx_count )

Constructor for the Mesh class.

Initializes a Mesh with the provided vertex array and shader.

Parameters
vaoShared pointer to the VertexArray object.
shaderShared pointer to the Shader object.
idx_countNumber of indices in the mesh.

Member Function Documentation

◆ bind()

void lmgl::scene::Mesh::bind ( ) const

Binds the mesh for rendering.

Prepares the mesh for rendering by binding the vertex array and shader.

◆ create_cube()

std::shared_ptr< Mesh > lmgl::scene::Mesh::create_cube ( std::shared_ptr< renderer::Shader > shader,
unsigned int subdivs = 1 )
static

Creates a cube mesh.

Generates a cube mesh with the specified shader and subdivisions.

Parameters
shaderShared pointer to the Shader object.
subdivsNumber of subdivisions for the cube (default is 1).
Returns
Shared pointer to the created Mesh object.

◆ create_quad()

std::shared_ptr< Mesh > lmgl::scene::Mesh::create_quad ( std::shared_ptr< renderer::Shader > shader,
float width = 1.0f,
float height = 1.0f )
static

Creates a quad mesh.

Generates a quad mesh with the specified shader, width, and height.

Parameters
shaderShared pointer to the Shader object.
widthWidth of the quad (default is 1.0f).
heightHeight of the quad (default is 1.0f).
Returns
Shared pointer to the created Mesh object.

◆ create_sphere()

std::shared_ptr< Mesh > lmgl::scene::Mesh::create_sphere ( std::shared_ptr< renderer::Shader > shader,
float radius = 0.5f,
unsigned int lonsegs = 32,
unsigned int latsegs = 32 )
static

Creates a sphere mesh.

Generates a sphere mesh with the specified shader, radius, and segmentation.

Parameters
shaderShared pointer to the Shader object.
radiusRadius of the sphere (default is 0.5f).
lonsegsNumber of longitudinal segments (default is 32).
latsegsNumber of latitudinal segments (default is 32).
Returns
Shared pointer to the created Mesh object.

◆ get_bounding_box()

const AABB & lmgl::scene::Mesh::get_bounding_box ( ) const
inline

Getter for bounding box.

Provides access to the axis-aligned bounding box of the mesh.

Returns
Constant reference to the AABB object.

◆ get_bounding_sphere()

const BoundingSphere & lmgl::scene::Mesh::get_bounding_sphere ( ) const
inline

Getter for bounding sphere.

Provides access to the bounding sphere of the mesh.

Returns
Constant reference to the BoundingSphere object.

◆ get_index_count()

unsigned int lmgl::scene::Mesh::get_index_count ( ) const
inline

Getter for index count.

Provides the number of indices in the mesh.

Returns
Number of indices as an unsigned int.

◆ get_indices()

const std::vector< unsigned int > & lmgl::scene::Mesh::get_indices ( ) const
inline

Getter for indices.

Provides access to the vector of indices defining the mesh geometry.

Returns
Constant reference to the vector of unsigned int indices.

◆ get_material()

std::shared_ptr< Material > lmgl::scene::Mesh::get_material ( ) const
inline

Retrieve the material associated with the mesh.

Returns
the material associated to the mesh.

◆ get_shader()

std::shared_ptr< renderer::Shader > lmgl::scene::Mesh::get_shader ( ) const
inline

Getter for shader.

Provides access to the shader associated with the mesh.

Returns
Shared pointer to the Shader object.

◆ get_vertex_array()

std::shared_ptr< renderer::VertexArray > lmgl::scene::Mesh::get_vertex_array ( ) const
inline

Getter for vertex array.

Provides access to the vertex array associated with the mesh.

Returns
Shared pointer to the VertexArray object.

◆ get_vertices()

const std::vector< Vertex > & lmgl::scene::Mesh::get_vertices ( ) const
inline

Getter for vertices.

Provides access to the vector of vertices defining the mesh geometry.

Returns
Constant reference to the vector of Vertex objects.

◆ has_vert_data()

bool lmgl::scene::Mesh::has_vert_data ( ) const
inline

Check if the mesh has vertex data.

Determines if the mesh contains valid vertex and index data.

Returns
True if both vertices and indices are present, false otherwise.

◆ render()

void lmgl::scene::Mesh::render ( ) const

Renders the mesh.

Issues the draw call to render the mesh using the associated vertex array and shader.

◆ set_material()

void lmgl::scene::Mesh::set_material ( std::shared_ptr< Material > material)
inline

Sets the material associated to the mesh.

Parameters
materialThe new material to set.

◆ set_shader()

void lmgl::scene::Mesh::set_shader ( std::shared_ptr< renderer::Shader > shader)
inline

Setter for shader.

Sets the shader associated with the mesh.

Parameters
shaderShared pointer to the Shader object.

◆ unbind()

void lmgl::scene::Mesh::unbind ( ) const

Unbinds the mesh after rendering.

Cleans up after rendering by unbinding the vertex array and shader.


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