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
utility::graphic::Material Class Reference

The Material class represents a material that can be used for rendering objects in a graphics application. More...

#include <headers/utility/graphic/material.hpp>

Inheritance diagram for utility::graphic::Material:

Public Member Functions

 Material ()=default
 Constructs an empty Material.
 
 Material (RessourceProvider &ressourceProvider, const std::string &shaderName, const std::vector< File > &textureAssets)
 Constructs a Material object with the specified shader name and texture assets.
 
virtual ~Material ()=default
 Destructs the Material object, releasing any allocated resources.
 
std::shared_ptr< TexturegetTexture (const std::string &name) const
 Retrieves a texture by its name.
 
std::vector< std::shared_ptr< Texture > > getTextures () const
 Retrieves the textures associated with this material.
 
const std::string & getShaderName () const
 Retrieves the shader name associated with this material.
 
AlphaMode getAlphaMode (void) const
 Retrieves the alpha semantics of this material.
 
float getAlphaCutoff (void) const
 Retrieves the alpha cutoff of this material.
 
uint32_t getVersion () const
 Retrieves the version number of the material.
 

Protected Attributes

std::string _shaderName
 The name of the shader associated with this material.
 
std::map< std::string, std::shared_ptr< Texture > > _textures
 A map of texture names to Texture objects associated with this material.
 
uint32_t _version = 0
 A version number for the material, used for tracking changes and updates.
 
AlphaMode _alphaMode = AlphaMode::Opaque
 The alpha semantics of this material.
 
float _alphaCutoff = 0.5f
 The alpha cutoff, only meaningful for AlphaMode::Mask.
 

Detailed Description

The Material class represents a material that can be used for rendering objects in a graphics application.

The Material class manages a shader and its associated textures, allowing for efficient rendering of objects with the specified visual properties. It provides functionality to load textures from file assets and retrieve them for use in rendering operations.

The constructor of the Material class takes a shader name and a vector of File objects representing the textures to be loaded. The textures are loaded using the stb_image library, and the pixel data is stored in Texture objects for later use.

Definition at line 57 of file material.hpp.

Constructor & Destructor Documentation

◆ Material() [1/2]

utility::graphic::Material::Material ( )
default

Constructs an empty Material.

This constructor initializes a Material object without any shader or textures. It can be used when the shader and textures will be set up later, allowing for more flexible material creation and management.

◆ Material() [2/2]

utility::graphic::Material::Material ( RessourceProvider ressourceProvider,
const std::string &  shaderName,
const std::vector< File > &  textureAssets 
)

Constructs a Material object with the specified shader name and texture assets.

This constructor initializes the Material with a shader name and loads the textures from the provided File objects. The textures are loaded using the stb_image library, and the pixel data is stored in Texture objects for later use in rendering operations.

Parameters
ressourceProviderA reference to the RessourceProvider instance.
shaderNameThe name of the shader associated with this material.
textureAssetsA vector of File objects representing the textures to be loaded for this material.
Exceptions
std::runtime_errorif any of the textures fail to load from the provided File objects.

Definition at line 14 of file material.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ getAlphaCutoff()

float utility::graphic::Material::getAlphaCutoff ( void  ) const

Retrieves the alpha cutoff of this material.

The cutoff is only meaningful for AlphaMode::Mask, where a sampled alpha below the cutoff is fully transparent.

Returns
The alpha cutoff, in the [0, 1] range.

Definition at line 62 of file material.cpp.

◆ getAlphaMode()

AlphaMode utility::graphic::Material::getAlphaMode ( void  ) const

Retrieves the alpha semantics of this material.

Consumers use this to select the appropriate rendering behaviour without inferring it from texture types or shader names.

Returns
The AlphaMode of this material.

Definition at line 57 of file material.cpp.

◆ getShaderName()

const std::string & utility::graphic::Material::getShaderName ( ) const

Retrieves the shader name associated with this material.

This method returns the name of the shader that is associated with this material. The shader name is used to identify which shader program should be used when rendering objects that use this material, allowing for proper rendering of the material's visual properties.

Returns
A const reference to a string representing the shader name associated with this material.

Definition at line 52 of file material.cpp.

◆ getTexture()

std::shared_ptr< Texture > utility::graphic::Material::getTexture ( const std::string &  name) const

Retrieves a texture by its name.

This method returns a shared pointer to the Texture object associated with the specified name. If the texture does not exist in the material, it returns a nullptr.

Parameters
nameThe name of the texture to retrieve.
Returns
A shared pointer to the Texture object associated with the specified name, or nullptr if the texture does not exist.

Definition at line 33 of file material.cpp.

◆ getTextures()

std::vector< std::shared_ptr< Texture > > utility::graphic::Material::getTextures ( ) const

Retrieves the textures associated with this material.

This method returns a vector of shared pointers to the Texture objects associated with this material.

Returns
A vector of shared pointers to Texture objects associated with this material.

Definition at line 42 of file material.cpp.

◆ getVersion()

uint32_t utility::graphic::Material::getVersion ( ) const

Retrieves the version number of the material.

This method returns the version number of the material, which is used for tracking changes and updates to the material's properties and resources.

Returns
A const reference to the version number of the material.

Definition at line 67 of file material.cpp.

Member Data Documentation

◆ _alphaCutoff

float utility::graphic::Material::_alphaCutoff = 0.5f
protected

The alpha cutoff, only meaningful for AlphaMode::Mask.

Definition at line 192 of file material.hpp.

◆ _alphaMode

AlphaMode utility::graphic::Material::_alphaMode = AlphaMode::Opaque
protected

The alpha semantics of this material.

Definition at line 187 of file material.hpp.

◆ _shaderName

std::string utility::graphic::Material::_shaderName
protected

The name of the shader associated with this material.

Definition at line 170 of file material.hpp.

◆ _textures

std::map<std::string, std::shared_ptr<Texture> > utility::graphic::Material::_textures
protected

A map of texture names to Texture objects associated with this material.

Definition at line 176 of file material.hpp.

◆ _version

uint32_t utility::graphic::Material::_version = 0
protected

A version number for the material, used for tracking changes and updates.

Definition at line 182 of file material.hpp.


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