evan 2026.1.4
Evan
Loading...
Searching...
No Matches
evan::RenderObject Class Reference

A Renderable object. It is a simple interface between our core renderer and on-top built objects (such as texts, basic shapes and 3d objects) More...

#include <headers/evan/RenderObject.hpp>

Inheritance diagram for evan::RenderObject:
Collaboration diagram for evan::RenderObject:

Public Member Functions

 RenderObject (std::shared_ptr< DeviceContext > deviceContext, const std::map< uint32_t, utility::graphic::Mesh > &rawObjects, const std::string &pipelineLayer)
 Constructor: creates a single renderable object using its meshes and its associated material ID.
 
 ~RenderObject ()
 Destructor for the RenderObject.
 
void destroy (VkDevice device)
 Destroys the GPU resources associated with this RenderObject, such as the GPUMesh instances. This method should be called when the render object is no longer needed to free up GPU resources and prevent memory leaks.
 
void setTransform (const glm::mat4 &transform)
 Sets the model transform on every mesh of this object.
 
bool updateMeshes (const std::map< uint32_t, utility::graphic::Mesh > &rawObjects)
 Updates the meshes of this object in place.
 
const std::vector< std::shared_ptr< GPUMesh > > & getMeshes () const
 Retrieves the vector of GPUMesh instances associated with this RenderObject. Each GPUMesh represents a mesh that will be rendered as part of this object, and contains the necessary GPU resources for rendering.
 
std::string getPipelineLayer () const
 Retrieves the pipeline layer associated with this RenderObject. The pipeline layer is a string that can be used to determine which shader program and rendering configurations should be applied when rendering this object. It can be used to group render objects with similar rendering requirements together for efficient batching and state management in the rendering process.
 

Protected Attributes

std::vector< std::shared_ptr< GPUMesh > > _meshes
 
std::string _pipelineLayer
 

Detailed Description

A Renderable object. It is a simple interface between our core renderer and on-top built objects (such as texts, basic shapes and 3d objects)

Definition at line 29 of file RenderObject.hpp.

Constructor & Destructor Documentation

◆ RenderObject()

evan::RenderObject::RenderObject ( std::shared_ptr< DeviceContext >  deviceContext,
const std::map< uint32_t, utility::graphic::Mesh > &  rawObjects,
const std::string &  pipelineLayer 
)

Constructor: creates a single renderable object using its meshes and its associated material ID.

Parameters
deviceContextA shared pointer to the DeviceContext, which provides access to Vulkan device resources and operations needed for creating GPU resources for the render object.
rawObjectsA map of mesh IDs to utility::graphic::Mesh objects, representing the raw mesh data that will be used to create the GPU meshes for this render object. Each entry in the map corresponds to a mesh that will be rendered as part of this object, and the mesh data will be processed and uploaded to the GPU to create the corresponding GPUMesh instances.
pipelineLayerA string representing the pipeline layer associated with this render object, which can be used to determine which shader program and rendering configurations should be applied when rendering this object. The pipeline layer can be used to group render objects with similar rendering requirements together, allowing for efficient batching and state management in the rendering process.

Member Function Documentation

◆ destroy()

void evan::RenderObject::destroy ( VkDevice  device)

Destroys the GPU resources associated with this RenderObject, such as the GPUMesh instances. This method should be called when the render object is no longer needed to free up GPU resources and prevent memory leaks.

Parameters
deviceThe Vulkan device used for resource management, which is required to clean up GPU resources associated with the GPUMesh instances. It is assumed that the Vulkan device is properly initialized and can be used to manage GPU resources for cleanup.
Note
The method assumes that the GPUMesh instances were created using the same device context and are associated with the provided device for cleanup. It is important to ensure that all GPU resources are properly released to maintain efficient resource usage and prevent memory leaks in the rendering process.

◆ getMeshes()

const std::vector< std::shared_ptr< GPUMesh > > & evan::RenderObject::getMeshes ( ) const

Retrieves the vector of GPUMesh instances associated with this RenderObject. Each GPUMesh represents a mesh that will be rendered as part of this object, and contains the necessary GPU resources for rendering.

Returns
A constant reference to a vector of GPUMesh instances representing the meshes associated with this RenderObject. These GPUMesh instances can be used for rendering operations and contain the necessary GPU resources for rendering the meshes.

◆ getPipelineLayer()

std::string evan::RenderObject::getPipelineLayer ( ) const

Retrieves the pipeline layer associated with this RenderObject. The pipeline layer is a string that can be used to determine which shader program and rendering configurations should be applied when rendering this object. It can be used to group render objects with similar rendering requirements together for efficient batching and state management in the rendering process.

Returns
A string representing the pipeline layer associated with this RenderObject, which can be used to determine rendering configurations for this object during the rendering process.

◆ setTransform()

void evan::RenderObject::setTransform ( const glm::mat4 &  transform)

Sets the model transform on every mesh of this object.

Applies the same model matrix to each GPUMesh owned by this object. The renderer uploads it on every frame, so the transform reaches the vertex shader without touching the vertex data.

Parameters
transformThe 4x4 model matrix applied to every mesh.

◆ updateMeshes()

bool evan::RenderObject::updateMeshes ( const std::map< uint32_t, utility::graphic::Mesh > &  rawObjects)

Updates the meshes of this object in place.

Re-uses the already-allocated GPU vertex buffers whenever the topology (mesh count, vertex count and index count) is unchanged, avoiding buffer creation and destruction. When the topology differs, returns false so the caller can rebuild the object instead.

Parameters
rawObjectsA map of material IDs to the new mesh data, with the same layout used by the constructor.
Returns
True when every mesh was updated in place, false when the topology changed and a rebuild is required.

Member Data Documentation

◆ _meshes

std::vector<std::shared_ptr<GPUMesh> > evan::RenderObject::_meshes
protected

A vector of GPUMesh instances representing the meshes associated with this RenderObject. Each GPUMesh contains the necessary GPU resources for rendering a mesh that is part of this object.

Definition at line 140 of file RenderObject.hpp.

◆ _pipelineLayer

std::string evan::RenderObject::_pipelineLayer
protected

A string representing the pipeline layer associated with this RenderObject, which can be used to determine rendering configurations for this object during the rendering process. The pipeline layer can be used to group render objects with similar rendering requirements together for efficient batching and state management in the rendering process.

Definition at line 145 of file RenderObject.hpp.


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