evan 2026.1.4
Evan
Loading...
Searching...
No Matches
RessourceManager.hpp
1/*
2** ETIB PROJECT, 2026
3** xider
4** File description:
5** RessourceManager
6*/
7
8#pragma once
9
10#include <cstdint>
11#include <memory>
12#include <string>
13#include <unordered_map>
14
15#include <utility/ressource_provider.hpp>
16#include <utility/graphic/material.hpp>
17#include <utility/graphic/texture.hpp>
18
19#include <utility/logging/loggable.hpp>
20#include <utility/logging/default_logger.hpp>
21
22#include "GPUMaterial.hpp"
23#include "GPUTexture.hpp"
24#include "GPUShader.hpp"
25
26namespace evan
27{
39 protected utility::logging::Loggable<RessourceManager,
40 utility::logging::DefaultLogger>
41 {
42 public:
58 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
59 std::shared_ptr<DeviceContext> deviceContext);
60
66
84 void init(std::shared_ptr<Renderer> renderer);
85
109 void sync(bool refresh = false);
110
119 void cleanup();
120
130 std::shared_ptr<GPUMaterial> getMaterial(uint32_t id) const;
131
141 std::shared_ptr<GPUTexture> getTexture(uint32_t id) const;
142
152 std::shared_ptr<GPUShader> getShader(uint32_t id) const;
153
162 [[nodiscard]] const std::unordered_map<uint32_t,
163 std::shared_ptr<GPUShader>> &
164 getShaders() const;
165
166 protected:
174 std::shared_ptr<utility::RessourceProvider> _ressourceProvider;
175
186 std::shared_ptr<DeviceContext> _deviceContext;
187
195 std::weak_ptr<Renderer> _renderer;
196
201 std::unordered_map<uint32_t, std::shared_ptr<GPUMaterial>> _materials;
202
207 std::unordered_map<uint32_t, std::shared_ptr<GPUTexture>> _textures;
208
213 std::unordered_map<uint32_t, std::shared_ptr<GPUShader>> _shaders;
214
222
230 bool _synchronized = false;
231 };
232} // namespace evan
The RessourceManager class is responsible for managing GPU resources such as materials and textures.
std::unordered_map< uint32_t, std::shared_ptr< GPUShader > > _shaders
Internal map to store GPU shaders for efficient retrieval based on their unique IDs.
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::shared_ptr< GPUMaterial > getMaterial(uint32_t id) const
Retrieves a shared pointer to the GPUMaterial associated with the given material ID.
const std::unordered_map< uint32_t, std::shared_ptr< GPUShader > > & getShaders() const
Retrieves the map of all GPUShaders managed by the RessourceManager.
void cleanup()
Releases every cached GPU wrapper owned by this manager.
std::shared_ptr< GPUTexture > getTexture(uint32_t id) const
Retrieves a shared pointer to the GPUTexture associated with the given texture ID.
std::unordered_map< uint32_t, std::shared_ptr< GPUTexture > > _textures
Internal map to store GPU textures for efficient retrieval based on their unique IDs.
void init(std::shared_ptr< Renderer > renderer)
Initializes the RessourceManager by synchronizing GPU resources with the materials and textures loade...
uint64_t _syncedVersion
Version of the provider at the last full synchronization pass.
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.
RessourceManager(std::shared_ptr< utility::RessourceProvider > ressourceProvider, std::shared_ptr< DeviceContext > deviceContext)
Constructs a RessourceManager instance with the given resource provider, device context,...
bool _synchronized
Whether at least one full synchronization pass has completed.
~RessourceManager()
Destructs the RessourceManager instance and cleans up GPU resources.
void sync(bool refresh=false)
Synchronizes the GPU resources with the materials and textures loaded from the resource provider.
std::weak_ptr< Renderer > _renderer
Weak pointer to the Renderer instance.
std::shared_ptr< GPUShader > getShader(uint32_t id) const
Retrieves a shared pointer to the GPUShader associated with the given shader ID.
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89