![]() |
Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
|
Manages creation, storage, and lifecycle of Material objects within the rendering engine. More...
#include <material_cache.hpp>
Inherits rendering_engine::IRendererObserver.
Public Member Functions | |
| MaterialCache (IRenderer *renderer) | |
| Constructs a MaterialCache and registers it as a renderer observer. | |
| ~MaterialCache () | |
| Destructor. Automatically unregisters from the renderer. | |
| void | CreateBuildInMaterials () |
| Creates built-in materials for testing or demonstration. | |
| void | AddMaterial (MaterialSettings matSettings) |
| Adds a new Material instance using the provided settings. | |
| Material * | GetMaterial (std::string materialName) |
| Retrieves a pointer to a Material instance by name. | |
| void | RemoveMaterial (std::string materialName) |
| Removes a material from the cache. | |
| void | ReleaseAll () |
| Releases all GPU resources associated with cached materials. | |
| Public Member Functions inherited from rendering_engine::IRendererObserver | |
| virtual | ~IRendererObserver ()=default |
| Virtual destructor. | |
Protected Member Functions | |
| void | OnRenderResourcesRelease () override |
| Renderer callback: release all GPU resources (used during device loss/reset). | |
| void | OnRenderResourcesRebuild () override |
| Renderer callback: re-upload or recreate all GPU resources (used after device reset/rebuild). | |
Protected Attributes | |
| IRenderer * | mRenderer |
| std::unordered_map< std::string, std::shared_ptr< Material > > | mMaterials |
Manages creation, storage, and lifecycle of Material objects within the rendering engine.
MaterialCache serves as a centralized system to instantiate, store, and retrieve materials used in the engine. It supports both manually added materials and, in the future, loading materials from JSON definitions.
It observes renderer events (such as swapchain recreation) to reinitialize or release GPU resources tied to materials.
Definition at line 29 of file material_cache.hpp.
| rendering_engine::MaterialCache::MaterialCache | ( | IRenderer * | renderer | ) |
Constructs a MaterialCache and registers it as a renderer observer.
| renderer | Pointer to the renderer interface used for creating GPU resources. |
Definition at line 9 of file material_cache.cpp.
| rendering_engine::MaterialCache::~MaterialCache | ( | ) |
Destructor. Automatically unregisters from the renderer.
Definition at line 16 of file material_cache.cpp.
| void rendering_engine::MaterialCache::AddMaterial | ( | MaterialSettings | matSettings | ) |
Adds a new Material instance using the provided settings.
| matSettings | MaterialSettings struct containing metadata and configuration for the new material. |
If a material with the same name already exists, it will be replaced.
Definition at line 71 of file material_cache.cpp.
| void rendering_engine::MaterialCache::CreateBuildInMaterials | ( | ) |
Creates built-in materials for testing or demonstration.
This is a temporary function to manually define materials in code. In the future, materials will be created by parsing JSON files from a materials folder.
Definition at line 21 of file material_cache.cpp.
| Material * rendering_engine::MaterialCache::GetMaterial | ( | std::string | materialName | ) |
Retrieves a pointer to a Material instance by name.
| materialName | Name of the material to retrieve. |
Definition at line 81 of file material_cache.cpp.
|
overrideprotectedvirtual |
Renderer callback: re-upload or recreate all GPU resources (used after device reset/rebuild).
This method will be called after the device or swapchain is recreated, allowing the observer to re-upload or recreate all necessary resources for rendering.
Implements rendering_engine::IRendererObserver.
Definition at line 113 of file material_cache.cpp.
|
overrideprotectedvirtual |
Renderer callback: release all GPU resources (used during device loss/reset).
This method will be called before any device or swapchain is destroyed, allowing the observer to safely release all handles and deallocate any GPU memory.
Implements rendering_engine::IRendererObserver.
Definition at line 105 of file material_cache.cpp.
| void rendering_engine::MaterialCache::ReleaseAll | ( | ) |
Releases all GPU resources associated with cached materials.
Iterates through every material in the cache and calls their resource release routines, freeing descriptor set layouts, pipelines, and any other backend allocations. Unlike RemoveMaterial, this does not erase the material records themselves from the cache, only their GPU-side resources.
Definition at line 100 of file material_cache.cpp.
| void rendering_engine::MaterialCache::RemoveMaterial | ( | std::string | materialName | ) |
Removes a material from the cache.
| materialName | Name of the material to remove. |
Definition at line 91 of file material_cache.cpp.
|
protected |
Definition at line 106 of file material_cache.hpp.
|
protected |
Definition at line 105 of file material_cache.hpp.