Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::DrawableComponent Class Referenceabstract

Abstract base for all drawable (renderable) objects in the engine. More...

#include <drawable_component.hpp>

Inherited by rendering_engine::Drawable2D, and rendering_engine::Drawable3D.

Public Member Functions

 DrawableComponent (RenderResourceContext renderContext, Scene &scene)
 Constructs the DrawableComponent with a resource context. More...
 
virtual ~DrawableComponent ()=default
 Virtual destructor. More...
 
virtual void Initialize ()
 Initializes render resource pointers (material, mesh, etc.). Must be called after setting material and mesh names. More...
 
virtual void Update (float deltaTime)=0
 Updates logic (animation, movement, etc.) for this drawable. More...
 
virtual void Shutdown ()
 Releases all render resources owned by this drawable. More...
 
virtual void Destroy ()
 Requests destruction of this drawable. More...
 
void UpdateOnTick (bool in)
 
 DrawableComponent (const DrawableComponent &)=delete
 
DrawableComponentoperator= (const DrawableComponent &)=delete
 

Protected Member Functions

void AddRenderBatch (std::string meshName, std::string materialName)
 

Protected Attributes

RenderResourceContext mRenderContext
 
ScenemScene
 
std::vector< RenderBatchmRenderBatches
 
bool bUpdateOnTick
 

Detailed Description

Abstract base for all drawable (renderable) objects in the engine.

Provides core functionality for accessing render resources (meshes, materials, textures) and defines the initialization, update, and draw lifecycle for renderable entities.

Derived classes (such as Drawable2D and Drawable3D) implement type-specific behavior for spatial transforms, camera use, and render submission.

Note
Not copyable or assignable.
See also
Drawable2D, Drawable3D

Definition at line 47 of file drawable_component.hpp.

Constructor & Destructor Documentation

◆ DrawableComponent() [1/2]

rendering_engine::DrawableComponent::DrawableComponent ( RenderResourceContext  renderContext,
Scene scene 
)

Constructs the DrawableComponent with a resource context.

Parameters
renderContextRendering resource context (renderer, caches).

Definition at line 16 of file drawable_component.cpp.

◆ ~DrawableComponent()

virtual rendering_engine::DrawableComponent::~DrawableComponent ( )
virtualdefault

Virtual destructor.

◆ DrawableComponent() [2/2]

rendering_engine::DrawableComponent::DrawableComponent ( const DrawableComponent )
delete

Member Function Documentation

◆ AddRenderBatch()

void rendering_engine::DrawableComponent::AddRenderBatch ( std::string  meshName,
std::string  materialName 
)
protected

Definition at line 58 of file drawable_component.cpp.

59{
60 RenderBatch renderBatch;
61 renderBatch.meshName = meshName;
62 renderBatch.materialName = materialName;
63
64 mRenderBatches.push_back(std::move(renderBatch));
65}
std::vector< RenderBatch > mRenderBatches

◆ Destroy()

void rendering_engine::DrawableComponent::Destroy ( )
virtual

Requests destruction of this drawable.

Schedules the drawable for deferred removal via the owning Scene. The drawable is not destroyed immediately; actual cleanup is performed at a safe point during the Scene update cycle.

Note
This function must be used instead of deleting the object directly.

Reimplemented in rendering_engine::Drawable2D, and rendering_engine::Drawable3D.

Definition at line 49 of file drawable_component.cpp.

50{
51}

◆ Initialize()

void rendering_engine::DrawableComponent::Initialize ( )
virtual

Initializes render resource pointers (material, mesh, etc.). Must be called after setting material and mesh names.

Reimplemented in rendering_engine::Drawable2D, rendering_engine::Drawable3D, rendering_engine::Quad2D, rendering_engine::Rectangle2D, rendering_engine::Sprite2D, rendering_engine::StaticMesh, and rendering_engine::TextBlock2D.

Definition at line 24 of file drawable_component.cpp.

25{
26 for (auto& renderBatch : mRenderBatches)
27 {
28 renderBatch.renderResources = std::unique_ptr<IRenderResources>(mRenderContext.renderer->ProvideRenderResources());
29 Material* material = mRenderContext.materialCache->GetMaterial(renderBatch.materialName);
30 renderBatch.materialParameters = material->PackMaterialParameters();
31 MeshDataGpu* meshData = mRenderContext.meshCache->GetMeshResources(renderBatch.meshName).get();
32
33 renderBatch.renderResources->Initialize(material, meshData, mRenderContext.textureCache);
34 }
35}
virtual IRenderResources * ProvideRenderResources() const =0
Provides access to the general rendering resource manager.
Material * GetMaterial(std::string materialName)
Retrieves a pointer to a Material instance by name.
PackedMaterialData PackMaterialParameters()
Packs the current float/vector parameters into a binary buffer and layout metadata.
Definition: material.cpp:39
std::shared_ptr< MeshDataGpu > GetMeshResources(std::string filename)
Get a shared pointer to the MeshDataGpu for a model.

◆ operator=()

DrawableComponent & rendering_engine::DrawableComponent::operator= ( const DrawableComponent )
delete

◆ Shutdown()

void rendering_engine::DrawableComponent::Shutdown ( )
virtual

Releases all render resources owned by this drawable.

Called internally by the Scene during destruction or scene shutdown. This function must free GPU and CPU-side render resources but must not remove the drawable from Scene containers.

Definition at line 37 of file drawable_component.cpp.

38{
39 for (auto& renderBatch : mRenderBatches)
40 {
41 if (renderBatch.renderResources)
42 {
43 renderBatch.renderResources->Shutdown();
44 }
45 }
46 mRenderBatches.clear();
47}

◆ Update()

virtual void rendering_engine::DrawableComponent::Update ( float  deltaTime)
pure virtual

Updates logic (animation, movement, etc.) for this drawable.

Parameters
deltaTimeTime step (seconds).

Implemented in rendering_engine::Drawable2D, rendering_engine::Drawable3D, rendering_engine::Quad2D, rendering_engine::Rectangle2D, rendering_engine::Sprite2D, rendering_engine::StaticMesh, and rendering_engine::TextBlock2D.

◆ UpdateOnTick()

void rendering_engine::DrawableComponent::UpdateOnTick ( bool  in)

Definition at line 53 of file drawable_component.cpp.

54{
55 bUpdateOnTick = in;
56}

Member Data Documentation

◆ bUpdateOnTick

bool rendering_engine::DrawableComponent::bUpdateOnTick
protected

Definition at line 104 of file drawable_component.hpp.

◆ mRenderBatches

std::vector<RenderBatch> rendering_engine::DrawableComponent::mRenderBatches
protected

Definition at line 102 of file drawable_component.hpp.

◆ mRenderContext

RenderResourceContext rendering_engine::DrawableComponent::mRenderContext
protected

Definition at line 100 of file drawable_component.hpp.

◆ mScene

Scene& rendering_engine::DrawableComponent::mScene
protected

Definition at line 101 of file drawable_component.hpp.


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