|
utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
|
The RessourceProvider class is responsible for managing and loading various resources such as fonts, materials, and textures in a graphics application. More...
#include <headers/utility/ressource_provider.hpp>


Public Types | |
| enum class | ShaderType { TEXT_SHADER , MESH_SHADER } |
| Enumeration for different shader types that can be associated with materials. More... | |
Public Member Functions | |
| RessourceProvider (SystemIO &systemInterface, const std::string &basePath="") | |
| Constructs a RessourceProvider object with a reference to a SystemIO instance. | |
| ~RessourceProvider ()=default | |
| Destructs the RessourceProvider object. | |
| const std::map< uint32_t, std::shared_ptr< graphic::Material > > & | getMaterials () const |
| Retrieves a map of loaded materials. | |
| const std::map< uint32_t, std::shared_ptr< graphic::Texture > > & | getTextures () const |
| Retrieves a map of loaded textures. | |
| const std::map< uint32_t, std::shared_ptr< graphic::Model > > & | getModels () const |
| Retrieves a map of loaded models. | |
| const std::map< uint32_t, std::shared_ptr< graphic::Shader > > & | getShaders () const |
| Retrieves a map of loaded shaders. | |
| const std::map< uint32_t, std::shared_ptr< graphic::CodePoints > > & | getCodePoints () const |
| Retrieves a map of loaded code points resources. | |
| uint64_t | version () const noexcept |
| Retrieves a monotonic counter bumped on every mutation of the provider's resource maps. | |
| uint32_t | getShaderID (const std::string &shaderName) const |
| Retrieves the unique shader ID associated with a given shader name. | |
| uint32_t | getMaterialID (const std::string &materialName) |
| Retrieves the unique material ID associated with a given material name. | |
| uint32_t | getDefaultMaterialID () |
| Retrieves the unique ID of the default material. | |
| uint32_t | getMeshMaterialID () |
| Retrieves the unique ID of the mesh material. | |
| std::shared_ptr< graphic::Font > | loadFont (const std::string &path) |
| Loads a font resource from a specified file path. | |
| std::shared_ptr< graphic::Font > | loadFontFromAsset (std::shared_ptr< utility::File > fontAsset) |
| Loads a font resource from a specified asset. | |
| std::shared_ptr< graphic::Font > | loadFontFamilyFromAssets (const std::vector< std::shared_ptr< utility::File > > &fontAssets) |
| Loads a font family resource from a vector of font assets. | |
| std::shared_ptr< graphic::Material > | loadMaterial (const std::string &path, ShaderType shaderType) |
| Loads a material resource from a specified file path. | |
| std::shared_ptr< graphic::Material > | loadMaterialFromAsset (ShaderType shaderType, std::shared_ptr< utility::File > materialAsset) |
| Loads a material resource from a specified asset. | |
| std::shared_ptr< graphic::Texture > | loadTexture (const std::string &path) |
| Loads a texture resource from a specified file path. | |
| std::shared_ptr< graphic::Texture > | loadTextureFromAsset (std::shared_ptr< utility::File > textureAsset) |
| Loads a texture resource from a specified asset. | |
| std::shared_ptr< graphic::Material > | loadImageMaterial (const std::string &path) |
| Loads an image texture and wraps it in a material bound to the default shader. | |
| std::shared_ptr< graphic::Model > | loadModel (const std::string &path, const utility::graphic::PoseF &pose=utility::graphic::PoseF(), const std::string &material="default_material") |
| Loads a model resource from a specified file path. | |
| std::shared_ptr< graphic::Model > | loadModelFromAsset (std::shared_ptr< utility::File > modelAsset, const utility::graphic::PoseF &pose=utility::graphic::PoseF(), const std::string &material="default_material") |
| Loads a model resource from a specified asset. | |
| std::shared_ptr< graphic::Model > | loadModelFromAsset (std::shared_ptr< utility::File > modelAsset, graphic::Model::ModelType type, const utility::graphic::PoseF &pose=utility::graphic::PoseF(), const std::string &material="default_material") |
| Loads a model resource from a specified file path and model type. | |
| std::shared_ptr< graphic::Model > | loadObj (const std::string &path, const utility::graphic::PoseF &pose=utility::graphic::PoseF(), const std::string &material="default_material") |
| Loads an OBJ model resource from a specified file path. | |
| std::shared_ptr< graphic::Model > | loadObjFromAsset (std::shared_ptr< utility::File > modelAsset, const utility::graphic::PoseF &pose=utility::graphic::PoseF(), const std::string &material="default_material") |
| Loads an OBJ model resource from a specified asset. | |
| std::shared_ptr< graphic::Shader > | loadShader (const std::string &vertexPath, const std::string &fragmentPath) |
| Loads a shader resource from specified vertex and fragment shader file paths. | |
| std::shared_ptr< graphic::Shader > | loadShaderFromAssets (std::shared_ptr< utility::File > vertexAsset, std::shared_ptr< utility::File > fragmentAsset) |
| Loads a shader resource from specified vertex and fragment shader assets. | |
| std::shared_ptr< graphic::CodePoints > | loadCodePoints (const std::string &path) |
| Loads a code points resource from a specified file path. | |
| std::shared_ptr< graphic::CodePoints > | loadCodePointsFromAsset (std::shared_ptr< utility::File > codePointsAsset) |
| Loads a code points resource from a specified asset. | |
| std::unique_ptr< sound::AudioSource > | loadAudioSource (const std::string &path) |
| Loads an audio source resource from a specified file path. | |
| std::unique_ptr< sound::AudioSource > | loadAudioSourceFromAsset (std::shared_ptr< utility::File > audioAsset) |
| Loads an audio source resource from a specified asset. | |
Protected Member Functions | |
| std::string | buildShaderPath (const std::string &vertexPath, const std::string &fragmentPath) const |
| Builds a unique shader name based on the vertex and fragment shader file paths. | |
| void | onFontAtlasCreated (const std::string &name, std::shared_ptr< graphic::Texture > atlas) |
| Registers a font texture atlas produced by a Font instance. | |
| void | registerShader (uint32_t id, const std::string &path, const std::string &vertexPath, std::shared_ptr< graphic::Shader > shader) |
| Registers a loaded shader in the internal resource maps and the shader-only lookup index used by getShaderID(). | |
| uint32_t | getNextID () |
| Retrieves the next unique ID for a resource. | |
| void | touch () noexcept |
| Records a mutation of the provider's resource maps. | |
Protected Member Functions inherited from utility::logging::Loggable< RessourceProvider, utility::logging::DefaultLogger > | |
| Loggable (void) | |
| Construct a Loggable with the specified LoggerType. | |
| Loggable (Loggable &&other) noexcept | |
| Move constructor for Loggable. | |
| Loggable & | operator= (Loggable &&other) noexcept |
| Move assignment operator for Loggable. | |
| LoggerType & | getLogger (void) |
| Get the internal logger. | |
| LoggerType & | getLogger (void) const |
| Get the internal logger. | |
| virtual | ~Loggable (void)=default |
| Virtual destructor for proper cleanup. | |
Protected Attributes | |
| uint32_t | _currentID = 1 |
| Internal counter for generating unique IDs for resources. | |
| uint64_t | _version = 0 |
| Monotonic counter bumped on every mutation of the resource maps. | |
| std::map< uint32_t, std::shared_ptr< graphic::Font > > | _fonts |
| Internal maps to store loaded fonts for efficient retrieval. | |
| std::map< uint32_t, std::shared_ptr< graphic::Material > > | _materials |
| Internal map to store loaded materials for efficient retrieval. | |
| std::map< uint32_t, std::shared_ptr< graphic::Texture > > | _textures |
| Internal map to store loaded textures for efficient retrieval. | |
| std::map< uint32_t, std::shared_ptr< graphic::Model > > | _models |
| Internal map to store loaded models for efficient retrieval. | |
| std::map< uint32_t, std::shared_ptr< graphic::Shader > > | _shaders |
| Internal map to store loaded shaders for efficient retrieval. | |
| std::unordered_map< std::string, uint32_t > | _shaderIDs |
| Shader-only index mapping a shader name to its id. | |
| std::map< uint32_t, std::shared_ptr< graphic::CodePoints > > | _codePoints |
| Internal map to store loaded code points resources for efficient retrieval. | |
| std::map< uint32_t, std::shared_ptr< sound::AudioBuffer > > | _audioSources |
| Internal map to store loaded audio buffers for efficient retrieval. | |
| std::unordered_map< std::string, uint32_t > | _elementsIDs |
| Internal map to store resource IDs for efficient lookup based on file paths. | |
| SystemIO & | _systemInterface |
| Reference to the SystemIO instance used for loading assets from file paths. | |
| std::string | _basePath |
| An optional base path to prepend to resource paths when loading resources. | |
| utility::sound::AudioManager | _audioManager |
| Internal audio manager instance for managing audio operations. | |
The RessourceProvider class is responsible for managing and loading various resources such as fonts, materials, and textures in a graphics application.
The RessourceProvider provides methods to load resources from file paths or from asset objects, and it maintains internal maps to store loaded resources for efficient retrieval. It supports loading fonts, materials, and textures, and it can handle different shader types for materials.
Definition at line 36 of file ressource_provider.hpp.
|
strong |
Enumeration for different shader types that can be associated with materials.
This enum defines the types of shaders that can be used when loading materials. It currently includes TEXT_SHADER for text rendering and MESH_SHADER for mesh rendering, allowing for different visual effects based on the shader type used in the material.
Definition at line 50 of file ressource_provider.hpp.
| utility::RessourceProvider::RessourceProvider | ( | SystemIO & | systemInterface, |
| const std::string & | basePath = "" |
||
| ) |
Constructs a RessourceProvider object with a reference to a SystemIO instance.
| systemInterface | A reference to the SystemIO instance used for loading assets from file paths. The RessourceProvider relies on the SystemIO interface to load resources from the filesystem, and this constructor initializes the RessourceProvider with the provided SystemIO instance for asset loading operations. |
| basePath | An optional base path to prepend to resource paths when loading resources. This can be used to specify a common directory for all resources, allowing for more flexible resource management and organization. |
|
protected |
Builds a unique shader name based on the vertex and fragment shader file paths.
This method constructs a unique name for a shader by combining the vertex and fragment shader file paths. The resulting name can be used as a key in the internal map to store and retrieve shader resources efficiently. The method ensures that shaders with the same vertex and fragment paths will have the same name, allowing for proper caching and reuse of shader resources.
| vertexPath | The file path to the vertex shader resource. |
| fragmentPath | The file path to the fragment shader resource. |
| const std::map< uint32_t, std::shared_ptr< graphic::CodePoints > > & utility::RessourceProvider::getCodePoints | ( | ) | const |
Retrieves a map of loaded code points resources.
| uint32_t utility::RessourceProvider::getDefaultMaterialID | ( | ) |
Retrieves the unique ID of the default material.
If the default material is not found, then it creates a new default material with the default shader and returns its ID. The default material is used as a fallback when a specific material is not found for a resource, ensuring that the application can still render objects even if their intended materials are missing or misconfigured.
| uint32_t utility::RessourceProvider::getMaterialID | ( | const std::string & | materialName | ) |
Retrieves the unique material ID associated with a given material name.
| materialName | The name of the material for which to retrieve the ID. |
| const std::map< uint32_t, std::shared_ptr< graphic::Material > > & utility::RessourceProvider::getMaterials | ( | ) | const |
Retrieves a map of loaded materials.
| uint32_t utility::RessourceProvider::getMeshMaterialID | ( | ) |
Retrieves the unique ID of the mesh material.
| const std::map< uint32_t, std::shared_ptr< graphic::Model > > & utility::RessourceProvider::getModels | ( | ) | const |
Retrieves a map of loaded models.
|
protected |
Retrieves the next unique ID for a resource.
This method increments the internal nextID counter and returns the next unique ID for a resource. It is used internally to assign unique IDs to loaded resources such as fonts, materials, textures, and models. The returned ID can be used as a key in the internal maps to store and retrieve resources efficiently.
nextID variable directly. Use this method to ensure that unique IDs are generated correctly and consistently for all resources.| uint32_t utility::RessourceProvider::getShaderID | ( | const std::string & | shaderName | ) | const |
Retrieves the unique shader ID associated with a given shader name.
This method looks up the shader name in an internal map and returns the corresponding shader ID if found. If the shader name is not found, it returns 0, indicating that the shader does not exist in the resource provider.
| shaderName | The name of the shader for which to retrieve the ID. |
| const std::map< uint32_t, std::shared_ptr< graphic::Shader > > & utility::RessourceProvider::getShaders | ( | ) | const |
Retrieves a map of loaded shaders.
| const std::map< uint32_t, std::shared_ptr< graphic::Texture > > & utility::RessourceProvider::getTextures | ( | ) | const |
Retrieves a map of loaded textures.
| std::unique_ptr< sound::AudioSource > utility::RessourceProvider::loadAudioSource | ( | const std::string & | path | ) |
Loads an audio source resource from a specified file path.
| path | The file path to the audio source resource to be loaded. |
| std::unique_ptr< sound::AudioSource > utility::RessourceProvider::loadAudioSourceFromAsset | ( | std::shared_ptr< utility::File > | audioAsset | ) |
Loads an audio source resource from a specified asset.
| audioAsset | A shared pointer to the File object containing the audio source data to be loaded. |
| std::shared_ptr< graphic::CodePoints > utility::RessourceProvider::loadCodePoints | ( | const std::string & | path | ) |
Loads a code points resource from a specified file path.
| path | The file path to the .codepoints file to be loaded. |
| std::shared_ptr< graphic::CodePoints > utility::RessourceProvider::loadCodePointsFromAsset | ( | std::shared_ptr< utility::File > | codePointsAsset | ) |
Loads a code points resource from a specified asset.
| codePointsAsset | A shared pointer to the File object containing the .codepoints data to be loaded. |
| std::shared_ptr< graphic::Font > utility::RessourceProvider::loadFont | ( | const std::string & | path | ) |
Loads a font resource from a specified file path.
| path | The file path to the font resource to be loaded. |
| std::shared_ptr< graphic::Font > utility::RessourceProvider::loadFontFamilyFromAssets | ( | const std::vector< std::shared_ptr< utility::File > > & | fontAssets | ) |
Loads a font family resource from a vector of font assets.
| fontAssets | A vector of shared pointers to File objects containing the font data for the font family to be loaded. |
| std::shared_ptr< graphic::Font > utility::RessourceProvider::loadFontFromAsset | ( | std::shared_ptr< utility::File > | fontAsset | ) |
Loads a font resource from a specified asset.
| fontAsset | A shared pointer to the File object containing the font data to be loaded. |
| std::shared_ptr< graphic::Material > utility::RessourceProvider::loadImageMaterial | ( | const std::string & | path | ) |
Loads an image texture and wraps it in a material bound to the default shader.
This method loads the image at the given path as a texture and creates a material that uses the "default" shader (which samples the albedo texture at binding 1) with the loaded image texture. The material is registered under a deterministic name (image_<path>) so that getMaterialID("image_<path>") resolves and the material can be used with addMesh.
| path | The file path to the image resource to be loaded. |
| std::shared_ptr< graphic::Material > utility::RessourceProvider::loadMaterial | ( | const std::string & | path, |
| ShaderType | shaderType | ||
| ) |
Loads a material resource from a specified file path.
| path | The file path to the material resource to be loaded. |
| shaderType | The type of shader to be associated with the loaded material. |
| std::shared_ptr< graphic::Material > utility::RessourceProvider::loadMaterialFromAsset | ( | ShaderType | shaderType, |
| std::shared_ptr< utility::File > | materialAsset | ||
| ) |
Loads a material resource from a specified asset.
| shaderType | The type of shader to be associated with the loaded material. |
| materialAsset | A shared pointer to the File object containing the material data to be loaded. |
| std::shared_ptr< graphic::Model > utility::RessourceProvider::loadModel | ( | const std::string & | path, |
| const utility::graphic::PoseF & | pose = utility::graphic::PoseF(), |
||
| const std::string & | material = "default_material" |
||
| ) |
Loads a model resource from a specified file path.
| path | The file path to the model resource to be loaded. |
| pose | The initial position and orientation for the model. |
| material | The name of the material to be associated with the loaded model. If not specified, the default material will be used. |
| std::shared_ptr< graphic::Model > utility::RessourceProvider::loadModelFromAsset | ( | std::shared_ptr< utility::File > | modelAsset, |
| const utility::graphic::PoseF & | pose = utility::graphic::PoseF(), |
||
| const std::string & | material = "default_material" |
||
| ) |
Loads a model resource from a specified asset.
| modelAsset | A shared pointer to the File object containing the model data to be loaded. |
| pose | The initial position and orientation for the model. |
| material | The name of the material to be associated with the loaded model. If not specified, the default material will be used. |
| std::shared_ptr< graphic::Model > utility::RessourceProvider::loadModelFromAsset | ( | std::shared_ptr< utility::File > | modelAsset, |
| graphic::Model::ModelType | type, | ||
| const utility::graphic::PoseF & | pose = utility::graphic::PoseF(), |
||
| const std::string & | material = "default_material" |
||
| ) |
Loads a model resource from a specified file path and model type.
| modelAsset | A shared pointer to the File object containing the model data to be loaded. |
| type | The type of the model (e.g., OBJ, FBX, GLTF) to be loaded. |
| pose | The initial position and orientation for the model. |
| material | The name of the material to be associated with the loaded model. If not specified, the default material will be used. |
| std::shared_ptr< graphic::Model > utility::RessourceProvider::loadObj | ( | const std::string & | path, |
| const utility::graphic::PoseF & | pose = utility::graphic::PoseF(), |
||
| const std::string & | material = "default_material" |
||
| ) |
Loads an OBJ model resource from a specified file path.
| path | The file path to the OBJ model resource to be loaded. |
| pose | The initial position and orientation for the model. |
| material | The name of the material to be associated with the loaded OBJ model. If not specified, the default material will be used. |
| std::shared_ptr< graphic::Model > utility::RessourceProvider::loadObjFromAsset | ( | std::shared_ptr< utility::File > | modelAsset, |
| const utility::graphic::PoseF & | pose = utility::graphic::PoseF(), |
||
| const std::string & | material = "default_material" |
||
| ) |
Loads an OBJ model resource from a specified asset.
| modelAsset | A shared pointer to the File object containing the OBJ model data to be loaded. |
| pose | The initial position and orientation for the model. |
| material | The name of the material to be associated with the loaded OBJ model. If not specified, the default material will be used. |
| std::shared_ptr< graphic::Shader > utility::RessourceProvider::loadShader | ( | const std::string & | vertexPath, |
| const std::string & | fragmentPath | ||
| ) |
Loads a shader resource from specified vertex and fragment shader file paths.
| vertexPath | The file path to the vertex shader resource to be loaded. |
| fragmentPath | The file path to the fragment shader resource to be loaded. |
| std::shared_ptr< graphic::Shader > utility::RessourceProvider::loadShaderFromAssets | ( | std::shared_ptr< utility::File > | vertexAsset, |
| std::shared_ptr< utility::File > | fragmentAsset | ||
| ) |
Loads a shader resource from specified vertex and fragment shader assets.
| vertexAsset | A shared pointer to the File object containing the vertex shader data to be loaded. |
| fragmentAsset | A shared pointer to the File object containing the fragment shader data to be loaded. |
| std::shared_ptr< graphic::Texture > utility::RessourceProvider::loadTexture | ( | const std::string & | path | ) |
Loads a texture resource from a specified file path.
| path | The file path to the texture resource to be loaded. |
| std::shared_ptr< graphic::Texture > utility::RessourceProvider::loadTextureFromAsset | ( | std::shared_ptr< utility::File > | textureAsset | ) |
Loads a texture resource from a specified asset.
| textureAsset | A shared pointer to the File object containing the texture data to be loaded. |

|
protected |
Registers a font texture atlas produced by a Font instance.
Adds the atlas to the texture map, lazily creates the matching TextMaterial when it does not exist yet, and records the atlas on that material. Because the atlas updates the contents of an existing material without allocating a new id, this method calls touch() explicitly so that version() reflects the change.
| name | The font face name suffixed with the font size (e.g. "DejaVuSans_16"). |
| atlas | The generated texture atlas. |
|
protected |
Registers a loaded shader in the internal resource maps and the shader-only lookup index used by getShaderID().
The shader is stored under its unique id, its full shader path and its canonical short name (the vertex shader file name without its extension, e.g. "text" for "text.vs"). The index makes lookups deterministic regardless of container iteration order.
| id | The unique id assigned to the shader. |
| path | The full shader path built by buildShaderPath(). |
| vertexPath | The (resolved) vertex shader file path used to derive the canonical short name. |
| shader | The loaded shader to register. |
|
protectednoexcept |
Records a mutation of the provider's resource maps.
Must be called for every change to the resource containers, including in-place content updates that do not allocate a new id (e.g. a font atlas updating an existing TextMaterial).
|
noexcept |
Retrieves a monotonic counter bumped on every mutation of the provider's resource maps.
The counter is incremented both when a new resource is registered (new id) and when an existing resource's contents are updated in place without allocating a new id (e.g. a font atlas updating an existing TextMaterial). Consumers can cache the value and skip their whole synchronization work while it is unchanged.
|
protected |
Internal audio manager instance for managing audio operations.
This member variable holds an instance of the AudioManager that is used for managing audio playback and related operations. It handles the creation and management of audio sources loaded through the resource provider.
Definition at line 661 of file ressource_provider.hpp.
|
protected |
Internal map to store loaded audio buffers for efficient retrieval.
Definition at line 618 of file ressource_provider.hpp.
|
protected |
An optional base path to prepend to resource paths when loading resources.
This member variable holds a base path that can be used to specify a common directory for all resources. When loading resources, the RessourceProvider can prepend this base path to the provided resource paths, allowing for more flexible resource management and organization. This is particularly useful when all resources are stored in a specific directory, as it eliminates the need to provide the full path for each resource when loading them.
Definition at line 651 of file ressource_provider.hpp.
|
protected |
Internal map to store loaded code points resources for efficient retrieval.
Definition at line 612 of file ressource_provider.hpp.
|
protected |
Internal counter for generating unique IDs for resources.
Definition at line 561 of file ressource_provider.hpp.
|
protected |
Internal map to store resource IDs for efficient lookup based on file paths.
Definition at line 624 of file ressource_provider.hpp.
|
protected |
Internal maps to store loaded fonts for efficient retrieval.
Definition at line 575 of file ressource_provider.hpp.
|
protected |
Internal map to store loaded materials for efficient retrieval.
Definition at line 581 of file ressource_provider.hpp.
|
protected |
Internal map to store loaded models for efficient retrieval.
Definition at line 591 of file ressource_provider.hpp.
|
protected |
Shader-only index mapping a shader name to its id.
Keys are the full shader path (e.g. "text.vs_with_text.fs") and the canonical short name (e.g. "text"). Keeping this index separate from _elementsIDs makes getShaderID() an O(1) average lookup and keeps non-shader entries out of shader resolution.
Definition at line 606 of file ressource_provider.hpp.
|
protected |
Internal map to store loaded shaders for efficient retrieval.
Definition at line 596 of file ressource_provider.hpp.
|
protected |
Reference to the SystemIO instance used for loading assets from file paths.
The RessourceProvider relies on the SystemIO interface to load resources from the filesystem, and this member variable holds a reference to the SystemIO instance that is used for asset loading operations. It allows the RessourceProvider to access the necessary functionality of the SystemIO interface to read files and load resources based on file paths provided in the loading methods.
Definition at line 637 of file ressource_provider.hpp.
|
protected |
Internal map to store loaded textures for efficient retrieval.
Definition at line 586 of file ressource_provider.hpp.
|
protected |
Monotonic counter bumped on every mutation of the resource maps.
Definition at line 570 of file ressource_provider.hpp.