evan 2026.1.4
Evan
Loading...
Searching...
No Matches
evan::RessourceManager Class Reference

The RessourceManager class is responsible for managing GPU resources such as materials and textures. More...

#include <headers/evan/RessourceManager.hpp>

Inheritance diagram for evan::RessourceManager:
Collaboration diagram for evan::RessourceManager:

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ RessourceManager()

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.

Parameters
ressourceProviderA shared pointer to a utility::RessourceProvider instance used to load materials and textures.
deviceContextA shared pointer to a DeviceContext instance used to create GPU resources.
Note
The constructor initializes the resource manager and synchronizes the GPU resources with the loaded materials and textures from the resource provider.

Member Function Documentation

◆ cleanup()

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.

◆ getMaterial()

std::shared_ptr< GPUMaterial > evan::RessourceManager::getMaterial ( uint32_t  id) const

Retrieves a shared pointer to the GPUMaterial associated with the given material ID.

Parameters
idThe unique identifier for the material resource.
Returns
A shared pointer to the corresponding GPUMaterial if found, or nullptr if not found.

◆ getShader()

std::shared_ptr< GPUShader > evan::RessourceManager::getShader ( uint32_t  id) const

Retrieves a shared pointer to the GPUShader associated with the given shader ID.

Parameters
idThe unique identifier for the shader resource.
Returns
A shared pointer to the corresponding GPUShader if found, or nullptr if not found.

◆ getShaders()

const std::unordered_map< uint32_t, std::shared_ptr< GPUShader > > & evan::RessourceManager::getShaders ( ) const

Retrieves the map of all GPUShaders managed by the RessourceManager.

Returns
A const reference to the unordered map where the key is the unique shader ID and the value is a shared pointer to the corresponding GPUShader.

◆ getTexture()

std::shared_ptr< GPUTexture > evan::RessourceManager::getTexture ( uint32_t  id) const

Retrieves a shared pointer to the GPUTexture associated with the given texture ID.

Parameters
idThe unique identifier for the texture resource.
Returns
A shared pointer to the corresponding GPUTexture if found, or nullptr if not found.

◆ init()

void evan::RessourceManager::init ( std::shared_ptr< Renderer >  renderer)

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.

Parameters
rendererA 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.

◆ sync()

void evan::RessourceManager::sync ( bool  refresh = false)

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.

Parameters
refreshA boolean flag indicating whether to refresh existing GPU resources for modified materials and textures. Default is false.
Note
This method should be called whenever there are changes in the loaded materials or textures to ensure that the GPU resources are up to date.
This method binds const references to the provider's live maps. It must run on the same thread as, and never interleaved with, any provider mutation (e.g. font-atlas generation), otherwise iteration would race with map reallocation.

Member Data Documentation

◆ _deviceContext

std::shared_ptr<DeviceContext> evan::RessourceManager::_deviceContext
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.

◆ _materials

std::unordered_map<uint32_t, std::shared_ptr<GPUMaterial> > evan::RessourceManager::_materials
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.

◆ _renderer

std::weak_ptr<Renderer> evan::RessourceManager::_renderer
protected

Weak pointer to the Renderer instance.

A weak pointer is used to avoid a reference cycle between the Renderer (which owns this manager) and this manager (which used to own the Renderer). Lock it where the Renderer is needed.

Definition at line 195 of file RessourceManager.hpp.

◆ _ressourceProvider

std::shared_ptr<utility::RessourceProvider> evan::RessourceManager::_ressourceProvider
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.

◆ _shaders

std::unordered_map<uint32_t, std::shared_ptr<GPUShader> > evan::RessourceManager::_shaders
protected

Internal map to store GPU shaders for efficient retrieval based on their unique IDs.

Definition at line 213 of file RessourceManager.hpp.

◆ _syncedVersion

uint64_t evan::RessourceManager::_syncedVersion = 0
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.

◆ _synchronized

bool evan::RessourceManager::_synchronized = false
protected

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.

◆ _textures

std::unordered_map<uint32_t, std::shared_ptr<GPUTexture> > evan::RessourceManager::_textures
protected

Internal map to store GPU textures for efficient retrieval based on their unique IDs.

Definition at line 207 of file RessourceManager.hpp.


The documentation for this class was generated from the following file: