![]() |
Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
|
Manages loading, caching, and GPU residency of all model/mesh resources. More...
#include <model_cache.hpp>
Inherits rendering_engine::IRendererObserver.
Public Member Functions | |
| ModelCache (IRenderer *renderer) | |
| Construct a ModelCache and register it with the given renderer. | |
| ~ModelCache () | |
| Destructor. Releases all resources and unregisters observer. | |
| void | LoadModelsFromFolder (std::string pathToFolder) |
| Load all models found in the specified folder into RAM. | |
| void | LoadModelsFromPackage () |
| Load all models from the packed asset container. | |
| void | CreateQuad2D () |
| Creates a built-in 2D quad mesh. | |
| std::string | UploadModelToRAM (std::string path) |
| Load a single model from file into RAM. | |
| std::string | UploadModelToRAM (std::string fileName, std::vector< uint8_t > const &fileBytes) |
| Load a single model into RAM from a raw file buffer. | |
| void | UploadModelToGPU (std::string filename) |
| Upload a cached model's mesh data to the GPU. | |
| void | ReleaseModelFromGPU (std::string filename) |
| Release a model's mesh data from GPU memory. | |
| void | ReleaseAllFromGPU () |
| Release all model mesh data from GPU memory. | |
| void | ReleaseAll () |
| Remove all models from both GPU and RAM, clearing the cache. | |
| std::shared_ptr< MeshDataGpu > | GetMeshResources (std::string filename) |
| Get a shared pointer to the MeshDataGpu for a model. | |
| IMeshRenderResources * | GetMeshRenderResources (std::string filename) |
| Get the IMeshRenderResources interface for a model's GPU resources. | |
| size_t | GetSizeInRAM () const |
| Get the total size (in bytes) of all models loaded in RAM. | |
| size_t | GetSizeInGPU () const |
| Get the total size (in bytes) of all models currently resident on GPU. | |
| 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< MeshDataGpu > > | mModels |
| size_t | mTotalSizeRAM |
| size_t | mTotalSizeGPU |
Manages loading, caching, and GPU residency of all model/mesh resources.
Responsible for importing model files into RAM, uploading mesh data to GPU memory, and managing the lifetime and statistics of all managed models in the rendering engine. Also observes renderer resource lifecycle events (release/rebuild).
Definition at line 27 of file model_cache.hpp.
| rendering_engine::ModelCache::ModelCache | ( | IRenderer * | renderer | ) |
Construct a ModelCache and register it with the given renderer.
| renderer | Pointer to the owning IRenderer implementation. |
Definition at line 10 of file model_cache.cpp.
| rendering_engine::ModelCache::~ModelCache | ( | ) |
Destructor. Releases all resources and unregisters observer.
Definition at line 19 of file model_cache.cpp.
| void rendering_engine::ModelCache::CreateQuad2D | ( | ) |
Creates a built-in 2D quad mesh.
This helper is used by 2D systems (e.g., UI, sprites) to create a reusable quad mesh without external model files.
Definition at line 67 of file model_cache.cpp.
| IMeshRenderResources * rendering_engine::ModelCache::GetMeshRenderResources | ( | std::string | filename | ) |
Get the IMeshRenderResources interface for a model's GPU resources.
| filename | The model's cache key (filename without extension). |
Definition at line 190 of file model_cache.cpp.
| std::shared_ptr< MeshDataGpu > rendering_engine::ModelCache::GetMeshResources | ( | std::string | filename | ) |
Get a shared pointer to the MeshDataGpu for a model.
| filename | The model's cache key (filename without extension). |
Definition at line 180 of file model_cache.cpp.
|
inline |
Get the total size (in bytes) of all models currently resident on GPU.
Definition at line 205 of file model_cache.cpp.
|
inline |
Get the total size (in bytes) of all models loaded in RAM.
Definition at line 200 of file model_cache.cpp.
| void rendering_engine::ModelCache::LoadModelsFromFolder | ( | std::string | pathToFolder | ) |
Load all models found in the specified folder into RAM.
| pathToFolder | Path to the directory containing model files. |
Definition at line 24 of file model_cache.cpp.
| void rendering_engine::ModelCache::LoadModelsFromPackage | ( | ) |
Load all models from the packed asset container.
This function behaves similarly to LoadModelsFromFolder(), but instead retrieves model files from the packed asset system created by the Packaging Tool. Each packed file is read into memory and processed via UploadModelToRAM(std::string, const std::vector<uint8_t>&).
Only file entries located under the virtual folder: "Models/" are considered.
The resulting MeshDataGpu objects remain cached and ready for GPU upload.
Definition at line 41 of file model_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 215 of file model_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 210 of file model_cache.cpp.
| void rendering_engine::ModelCache::ReleaseAll | ( | ) |
Remove all models from both GPU and RAM, clearing the cache.
Definition at line 173 of file model_cache.cpp.
| void rendering_engine::ModelCache::ReleaseAllFromGPU | ( | ) |
Release all model mesh data from GPU memory.
Definition at line 164 of file model_cache.cpp.
| void rendering_engine::ModelCache::ReleaseModelFromGPU | ( | std::string | filename | ) |
Release a model's mesh data from GPU memory.
| filename | The model's cache key (filename without extension). |
Definition at line 148 of file model_cache.cpp.
| void rendering_engine::ModelCache::UploadModelToGPU | ( | std::string | filename | ) |
Upload a cached model's mesh data to the GPU.
| filename | The model's cache key (filename without extension). |
Definition at line 129 of file model_cache.cpp.
| std::string rendering_engine::ModelCache::UploadModelToRAM | ( | std::string | fileName, |
| std::vector< uint8_t > const & | fileBytes ) |
Load a single model into RAM from a raw file buffer.
This overload is used when the model originates from a packed asset archive or any virtual filesystem source rather than the OS filesystem.
| fileName | Cache key (typically relative virtual path, e.g. "Models/cube.fbx"). |
| fileBytes | Raw contents of the model file. |
Definition at line 109 of file model_cache.cpp.
| std::string rendering_engine::ModelCache::UploadModelToRAM | ( | std::string | path | ) |
Load a single model from file into RAM.
| path | Path to the model file. |
Definition at line 78 of file model_cache.cpp.
|
protected |
Definition at line 150 of file model_cache.hpp.
|
protected |
Definition at line 149 of file model_cache.hpp.
|
protected |
Definition at line 153 of file model_cache.hpp.
|
protected |
Definition at line 152 of file model_cache.hpp.