utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
material.cpp
1/*
2** ETIB PROJECT, 2026
3** utility
4** File description:
5** material
6*/
7
8#include <utility/graphic/material.hpp>
9
10#include <utility/ressource_provider.hpp>
11
12namespace utility::graphic
13{
15 const std::string &shaderName,
16 const std::vector<File> &textureAssets)
17 : _shaderName(shaderName)
18 , _version(0)
19 {
20 for (const auto &textureAsset: textureAssets) {
21 auto texture = ressourceProvider.loadTextureFromAsset(
22 std::make_shared<File>(textureAsset));
23
24 if (!texture) {
25 throw std::runtime_error("Failed to load texture asset: "
26 + textureAsset.path());
27 }
28
29 _textures[textureAsset.path()] = texture;
30 }
31 }
32
33 std::shared_ptr<Texture> Material::getTexture(const std::string &name) const
34 {
35 auto it = _textures.find(name);
36 if (it != _textures.end()) {
37 return it->second;
38 }
39 return nullptr;
40 }
41
42 std::vector<std::shared_ptr<Texture>> Material::getTextures() const
43 {
44 std::vector<std::shared_ptr<Texture>> textures;
45 textures.reserve(_textures.size());
46 for (const auto &[_, texture]: _textures) {
47 textures.push_back(texture);
48 }
49 return textures;
50 }
51
52 const std::string &Material::getShaderName() const
53 {
54 return _shaderName;
55 }
56
57 AlphaMode Material::getAlphaMode(void) const
58 {
59 return _alphaMode;
60 }
61
62 float Material::getAlphaCutoff(void) const
63 {
64 return _alphaCutoff;
65 }
66
67 uint32_t Material::getVersion() const
68 {
69 return _version;
70 }
71} // namespace utility::graphic
The RessourceProvider class is responsible for managing and loading various resources such as fonts,...
std::shared_ptr< graphic::Texture > loadTextureFromAsset(std::shared_ptr< utility::File > textureAsset)
Loads a texture resource from a specified asset.
std::string _shaderName
The name of the shader associated with this material.
Definition material.hpp:170
Material()=default
Constructs an empty Material.
std::map< std::string, std::shared_ptr< Texture > > _textures
A map of texture names to Texture objects associated with this material.
Definition material.hpp:176
AlphaMode getAlphaMode(void) const
Retrieves the alpha semantics of this material.
Definition material.cpp:57
float _alphaCutoff
The alpha cutoff, only meaningful for AlphaMode::Mask.
Definition material.hpp:192
const std::string & getShaderName() const
Retrieves the shader name associated with this material.
Definition material.cpp:52
uint32_t _version
A version number for the material, used for tracking changes and updates.
Definition material.hpp:182
std::shared_ptr< Texture > getTexture(const std::string &name) const
Retrieves a texture by its name.
Definition material.cpp:33
std::vector< std::shared_ptr< Texture > > getTextures() const
Retrieves the textures associated with this material.
Definition material.cpp:42
AlphaMode _alphaMode
The alpha semantics of this material.
Definition material.hpp:187
uint32_t getVersion() const
Retrieves the version number of the material.
Definition material.cpp:67
float getAlphaCutoff(void) const
Retrieves the alpha cutoff of this material.
Definition material.cpp:62