Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
drawable_component.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2026 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6#pragma once
7
8#include <memory>
9#include <string>
14#include "material_types.hpp"
15
16namespace rendering_engine
17{
18class IRenderer;
19class Material;
20class ModelCache;
21class TextureCache;
22class MaterialCache;
23class MeshDataGpu;
24class Scene;
25
27{
28 std::string meshName;
29 std::string materialName;
30 std::unique_ptr<IRenderResources> renderResources = nullptr;
32};
33
34/**
35 * @class DrawableComponent
36 * @brief Abstract base for all drawable (renderable) objects in the engine.
37 *
38 * Provides core functionality for accessing render resources (meshes, materials, textures)
39 * and defines the initialization, update, and draw lifecycle for renderable entities.
40 *
41 * Derived classes (such as Drawable2D and Drawable3D) implement type-specific behavior for
42 * spatial transforms, camera use, and render submission.
43 *
44 * @note Not copyable or assignable.
45 * @see Drawable2D, Drawable3D
46 */
48{
49public:
50 /**
51 * @brief Constructs the DrawableComponent with a resource context.
52 * @param renderContext Rendering resource context (renderer, caches).
53 */
54 DrawableComponent(RenderResourceContext renderContext, Scene& scene);
55
56 /// Virtual destructor.
57 virtual ~DrawableComponent() = default;
58
59 /**
60 * @brief Initializes render resource pointers (material, mesh, etc.).
61 * Must be called after setting material and mesh names.
62 */
63 virtual void Initialize();
64
65 /**
66 * @brief Updates logic (animation, movement, etc.) for this drawable.
67 * @param deltaTime Time step (seconds).
68 */
69 virtual void Update(float deltaTime) = 0;
70
71 /**
72 * @brief Releases all render resources owned by this drawable.
73 *
74 * Called internally by the Scene during destruction or scene shutdown.
75 * This function must free GPU and CPU-side render resources but must not
76 * remove the drawable from Scene containers.
77 */
78 virtual void Shutdown();
79
80 /**
81 * @brief Requests destruction of this drawable.
82 *
83 * Schedules the drawable for deferred removal via the owning Scene.
84 * The drawable is not destroyed immediately; actual cleanup is performed
85 * at a safe point during the Scene update cycle.
86 *
87 * @note This function must be used instead of deleting the object directly.
88 */
89 virtual void Destroy();
90
91 void UpdateOnTick(bool in);
92
95
96protected:
97 void AddRenderBatch(std::string meshName, std::string materialName);
98
99protected:
102 std::vector<RenderBatch> mRenderBatches;
103
105};
106
107}
108
Abstract base for all drawable (renderable) objects in the engine.
std::vector< RenderBatch > mRenderBatches
virtual ~DrawableComponent()=default
Virtual destructor.
DrawableComponent & operator=(const DrawableComponent &)=delete
DrawableComponent(const DrawableComponent &)=delete
virtual void Update(float deltaTime)=0
Updates logic (animation, movement, etc.) for this drawable.
Base class representing a renderable scene.
Definition: scene.hpp:44
#define RE_API
Contains the raw buffer data and layout metadata of packed material parameters.
std::unique_ptr< IRenderResources > renderResources
Aggregates pointers to global rendering resource managers.