Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
drawable_component.cpp
Go to the documentation of this file.
2
3#include "i_renderer.hpp"
5#include "model_cache.hpp"
6#include "texture_cache.hpp"
7#include "material_cache.hpp"
8#include "material.hpp"
9#include "scene.hpp"
10
11#include <cstring>
12
13namespace rendering_engine
14{
15
17 :
18 mRenderContext(renderContext),
19 mScene(scene),
20 bUpdateOnTick(true)
21{
22}
23
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}
36
38{
39 for (auto& renderBatch : mRenderBatches)
40 {
41 if (renderBatch.renderResources)
42 {
43 renderBatch.renderResources->Shutdown();
44 }
45 }
46 mRenderBatches.clear();
47}
48
50{
51}
52
54{
55 bUpdateOnTick = in;
56}
57
58void DrawableComponent::AddRenderBatch(std::string meshName, std::string materialName)
59{
60 RenderBatch renderBatch;
61 renderBatch.meshName = meshName;
62 renderBatch.materialName = materialName;
63
64 mRenderBatches.push_back(std::move(renderBatch));
65}
66
67
68
69} // namespace rendering_engine
std::vector< RenderBatch > mRenderBatches
virtual void Destroy()
Requests destruction of this drawable.
virtual void Shutdown()
Releases all render resources owned by this drawable.
void AddRenderBatch(std::string meshName, std::string materialName)
virtual void Initialize()
Initializes render resource pointers (material, mesh, etc.). Must be called after setting material an...
DrawableComponent(RenderResourceContext renderContext, Scene &scene)
Constructs the DrawableComponent with a resource context.
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.
Represents a material instance with parameter values, texture bindings, and rendering configuration.
Definition: material.hpp:30
PackedMaterialData PackMaterialParameters()
Packs the current float/vector parameters into a binary buffer and layout metadata.
Definition: material.cpp:39
Manages mesh data in RAM and GPU, including upload and release operations.
std::shared_ptr< MeshDataGpu > GetMeshResources(std::string filename)
Get a shared pointer to the MeshDataGpu for a model.
Base class representing a renderable scene.
Definition: scene.hpp:44
Aggregates pointers to global rendering resource managers.