|
evan 2026.1.4
Evan
|
The RessourceManager class is responsible for managing GPU resources such as materials and textures. More...
#include <headers/evan/RessourceManager.hpp>


Public Member Functions | |
| RessourceManager (std::shared_ptr< utility::RessourceProvider > ressourceProvider, std::shared_ptr< DeviceContext > deviceContext) | |
| Constructs a RessourceManager instance with the given resource provider, device context, and renderer. | |
| ~RessourceManager () | |
| Destructs the RessourceManager instance and cleans up GPU resources. | |
| void | init (std::shared_ptr< Renderer > renderer) |
| Initializes the RessourceManager by synchronizing GPU resources with the materials and textures loaded from the resource provider. | |
| void | sync (bool refresh=false) |
| Synchronizes the GPU resources with the materials and textures loaded from the resource provider. | |
| void | cleanup () |
| Releases every cached GPU wrapper owned by this manager. | |
| std::shared_ptr< GPUMaterial > | getMaterial (uint32_t id) const |
| Retrieves a shared pointer to the GPUMaterial associated with the given material ID. | |
| std::shared_ptr< GPUTexture > | getTexture (uint32_t id) const |
| Retrieves a shared pointer to the GPUTexture associated with the given texture ID. | |
| std::shared_ptr< GPUShader > | getShader (uint32_t id) const |
| Retrieves a shared pointer to the GPUShader associated with the given shader ID. | |
| const std::unordered_map< uint32_t, std::shared_ptr< GPUShader > > & | getShaders () const |
| Retrieves the map of all GPUShaders managed by the RessourceManager. | |
Protected Attributes | |
| std::shared_ptr< utility::RessourceProvider > | _ressourceProvider |
| Internal method to retrieve the next unique ID for a resource. | |
| std::shared_ptr< DeviceContext > | _deviceContext |
| Shared pointer to the DeviceContext used for creating GPU resources. | |
| std::weak_ptr< Renderer > | _renderer |
| Weak pointer to the Renderer instance. | |
| std::unordered_map< uint32_t, std::shared_ptr< GPUMaterial > > | _materials |
| Internal maps to store GPU materials and textures for efficient retrieval based on their unique IDs. | |
| std::unordered_map< uint32_t, std::shared_ptr< GPUTexture > > | _textures |
| Internal map to store GPU textures for efficient retrieval based on their unique IDs. | |
| std::unordered_map< uint32_t, std::shared_ptr< GPUShader > > | _shaders |
| Internal map to store GPU shaders for efficient retrieval based on their unique IDs. | |
| uint64_t | _syncedVersion = 0 |
| Version of the provider at the last full synchronization pass. | |
| bool | _synchronized = false |
| Whether at least one full synchronization pass has completed. | |
The RessourceManager class is responsible for managing GPU resources such as materials and textures.
The RessourceManager interacts with the utility::RessourceProvider to load materials and textures, and it creates corresponding GPU resources (GPUMaterial and GPUTexture) for use in rendering. It maintains internal maps to store these GPU resources for efficient retrieval based on their IDs.
Definition at line 38 of file RessourceManager.hpp.
| evan::RessourceManager::RessourceManager | ( | std::shared_ptr< utility::RessourceProvider > | ressourceProvider, |
| std::shared_ptr< DeviceContext > | deviceContext | ||
| ) |
Constructs a RessourceManager instance with the given resource provider, device context, and renderer.
| ressourceProvider | A shared pointer to a utility::RessourceProvider instance used to load materials and textures. |
| deviceContext | A shared pointer to a DeviceContext instance used to create GPU resources. |
| void evan::RessourceManager::cleanup | ( | ) |
Releases every cached GPU wrapper owned by this manager.
Clears the material, texture and shader caches. With the wrappers being RAII, dropping them destroys their Vulkan resources. Call this explicitly before tearing down the Renderer's descriptor pool so that descriptor sets are freed while the pool is still valid.
| std::shared_ptr< GPUMaterial > evan::RessourceManager::getMaterial | ( | uint32_t | id | ) | const |
Retrieves a shared pointer to the GPUMaterial associated with the given material ID.
| id | The unique identifier for the material resource. |
| const std::unordered_map< uint32_t, std::shared_ptr< GPUShader > > & evan::RessourceManager::getShaders | ( | ) | const |
Retrieves the map of all GPUShaders managed by the RessourceManager.
| std::shared_ptr< GPUTexture > evan::RessourceManager::getTexture | ( | uint32_t | id | ) | const |
Retrieves a shared pointer to the GPUTexture associated with the given texture ID.
| id | The unique identifier for the texture resource. |
Initializes the RessourceManager by synchronizing GPU resources with the materials and textures loaded from the resource provider.
This method should be called after constructing the RessourceManager to ensure that all GPU resources are properly initialized and synchronized with the loaded materials and textures. It may also be called to refresh the GPU resources if there are changes in the loaded materials or textures.
| renderer | A shared pointer to the Renderer instance that may be used for resource initialization and management during the synchronization process. This allows the RessourceManager to interact with the Renderer as needed to ensure that GPU resources are properly set up for rendering operations. |
Synchronizes the GPU resources with the materials and textures loaded from the resource provider.
This method checks the materials and textures loaded in the resource provider and creates corresponding GPU resources for any new materials or textures that have been added since the last synchronization. If the refresh parameter is set to true, it will also destroy and recreate GPU resources for materials and textures that have been modified.
| refresh | A boolean flag indicating whether to refresh existing GPU resources for modified materials and textures. Default is false. |
|
protected |
Shared pointer to the DeviceContext used for creating GPU resources.
This member variable holds a shared pointer to the DeviceContext instance, which provides access to Vulkan device resources and configurations needed for creating GPU materials and textures. It is used throughout the RessourceManager to ensure that GPU resources are created with the correct device context.
Definition at line 186 of file RessourceManager.hpp.
|
protected |
Internal maps to store GPU materials and textures for efficient retrieval based on their unique IDs.
Definition at line 201 of file RessourceManager.hpp.
|
protected |
|
protected |
Internal method to retrieve the next unique ID for a resource.
This method can be used to generate unique IDs for GPU resources based on the materials and textures loaded from the resource provider.
Definition at line 174 of file RessourceManager.hpp.
|
protected |
Internal map to store GPU shaders for efficient retrieval based on their unique IDs.
Definition at line 213 of file RessourceManager.hpp.
|
protected |
Version of the provider at the last full synchronization pass.
Snapshot taken before the pass and stored after it, so a mutation occurring mid-pass stays unseen and triggers another pass next sync.
Definition at line 221 of file RessourceManager.hpp.
Whether at least one full synchronization pass has completed.
Prevents the first sync() from being skipped: the provider starts at version 0, so a bare version comparison would treat it as "already synchronized".
Definition at line 230 of file RessourceManager.hpp.
|
protected |
Internal map to store GPU textures for efficient retrieval based on their unique IDs.
Definition at line 207 of file RessourceManager.hpp.