Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::Material Class Reference

Represents a material instance with parameter values, texture bindings, and rendering configuration. More...

#include <material.hpp>

Public Member Functions

 Material (IRenderer *renderer, MaterialSettings matSettings)
 Constructs a new Material instance. More...
 
 ~Material ()
 
const MaterialSettings GetMaterialSettings () const
 Returns the material's static settings (domain, blend mode, shading model, etc.). More...
 
void InitializeRenderResources ()
 Initializes backend-specific GPU resources associated with this material. More...
 
void ReleaseRenderResources ()
 Releases any GPU resources associated with this material. More...
 
PackedMaterialData PackMaterialParameters ()
 Packs the current float/vector parameters into a binary buffer and layout metadata. More...
 
std::vector< std::string > GetTextures () const
 Returns the list of texture names used by this material. More...
 
IMaterialRenderResourcesGetMaterialRenderResources () const
 Returns the backend-specific GPU handle of the material. More...
 
void SetFloat (const std::string &name, float value)
 Sets a float parameter for the material. More...
 
void SetVec2 (const std::string &name, glm::vec2 value)
 Sets a vec3 parameter for the material. More...
 
void SetVec3 (const std::string &name, glm::vec3 value)
 Sets a vec3 parameter for the material. More...
 
void SetVec4 (const std::string &name, glm::vec4 value)
 Sets a vec4 parameter for the material. More...
 
void AddTexture (const std::string &textureName)
 Adds a texture name to the material's list of used textures. More...
 

Detailed Description

Represents a material instance with parameter values, texture bindings, and rendering configuration.

This class encapsulates both the CPU-side representation of a material (its parameters and textures), and a pointer to its backend-specific GPU resource handle.

Definition at line 29 of file material.hpp.

Constructor & Destructor Documentation

◆ Material()

rendering_engine::Material::Material ( IRenderer renderer,
MaterialSettings  matSettings 
)
explicit

Constructs a new Material instance.

Parameters
rendererPointer to the rendering engine interface.
matSettingsSettings that define the material behavior.

Definition at line 10 of file material.cpp.

11 :
12 mRenderer(renderer),
13 mMaterialSettings(matSettings),
14 mGpuHandle(nullptr),
15 mParameterLayout(matSettings.parameterLayout)
16{}

◆ ~Material()

rendering_engine::Material::~Material ( )

Definition at line 17 of file material.cpp.

18{
19 if (mGpuHandle)
21}
void ReleaseRenderResources()
Releases any GPU resources associated with this material.
Definition: material.cpp:31

Member Function Documentation

◆ AddTexture()

void rendering_engine::Material::AddTexture ( const std::string &  textureName)

Adds a texture name to the material's list of used textures.

Parameters
textureNameName of the texture (e.g., texture ID or resource name).

Definition at line 112 of file material.cpp.

113{
114 mTextures.push_back(textureName);
115}

◆ GetMaterialRenderResources()

IMaterialRenderResources * rendering_engine::Material::GetMaterialRenderResources ( ) const

Returns the backend-specific GPU handle of the material.

Definition at line 87 of file material.cpp.

88{
89 return mGpuHandle.get();
90}

◆ GetMaterialSettings()

const MaterialSettings rendering_engine::Material::GetMaterialSettings ( ) const

Returns the material's static settings (domain, blend mode, shading model, etc.).

Definition at line 22 of file material.cpp.

23{
24 return mMaterialSettings;
25}

◆ GetTextures()

std::vector< std::string > rendering_engine::Material::GetTextures ( ) const

Returns the list of texture names used by this material.

Definition at line 82 of file material.cpp.

83{
84 return mTextures;
85}

◆ InitializeRenderResources()

void rendering_engine::Material::InitializeRenderResources ( )

Initializes backend-specific GPU resources associated with this material.

Must be called after construction and before rendering.

Definition at line 26 of file material.cpp.

27{
28 mGpuHandle = std::unique_ptr<IMaterialRenderResources>(mRenderer->ProvideMaterialRenderResources());
29 mGpuHandle->Initialize(this);
30}
virtual IMaterialRenderResources * ProvideMaterialRenderResources() const =0
Provides access to material-related GPU resources.

◆ PackMaterialParameters()

PackedMaterialData rendering_engine::Material::PackMaterialParameters ( )

Packs the current float/vector parameters into a binary buffer and layout metadata.

This buffer can be uploaded to the GPU as a uniform buffer or push constants.

Returns
PackedMaterialData Struct containing binary data and parameter layout info.

Definition at line 39 of file material.cpp.

40{
41 PackedMaterialData result;
42
43 if (!mParameterLayout)
44 return result;
45
46 // Preallocate full buffer size
47 size_t totalSize = 0;
48 for (const auto& e : *mParameterLayout)
49 totalSize = std::max(totalSize, e.offset + e.size);
50
51 result.buffer.resize(totalSize);
52 result.layout = *mParameterLayout;
53
54 for (const auto& entry : *mParameterLayout)
55 {
56 uint8_t* dst = result.buffer.data() + entry.offset;
57
58 switch (entry.type)
59 {
61 std::memcpy(dst, &mFloatParameters[entry.name], 4);
62 break;
63
65 std::memcpy(dst, &mVec2Parameters[entry.name], 8);
66 break;
67
69 std::memcpy(dst, &mVec3Parameters[entry.name], 12);
70 std::memset(dst + 12, 0, 4); // std140 padding
71 break;
72
74 std::memcpy(dst, &mVec4Parameters[entry.name], 16);
75 break;
76 }
77 }
78
79 return result;
80}

◆ ReleaseRenderResources()

void rendering_engine::Material::ReleaseRenderResources ( )

Releases any GPU resources associated with this material.

Definition at line 31 of file material.cpp.

32{
33 if (!mGpuHandle)
34 return;
35
36 mGpuHandle->Shutdown();
37 mGpuHandle.reset();
38}

◆ SetFloat()

void rendering_engine::Material::SetFloat ( const std::string &  name,
float  value 
)

Sets a float parameter for the material.

Parameters
nameName of the parameter.
valueFloat value to set.

Definition at line 92 of file material.cpp.

93{
94 mFloatParameters[name] = value;
95}

◆ SetVec2()

void rendering_engine::Material::SetVec2 ( const std::string &  name,
glm::vec2  value 
)

Sets a vec3 parameter for the material.

Parameters
nameName of the parameter.
valueglm::vec3 value to set.

Definition at line 97 of file material.cpp.

98{
99 mVec2Parameters[name] = value;
100}

◆ SetVec3()

void rendering_engine::Material::SetVec3 ( const std::string &  name,
glm::vec3  value 
)

Sets a vec3 parameter for the material.

Parameters
nameName of the parameter.
valueglm::vec3 value to set.

Definition at line 102 of file material.cpp.

103{
104 mVec3Parameters[name] = value;
105}

◆ SetVec4()

void rendering_engine::Material::SetVec4 ( const std::string &  name,
glm::vec4  value 
)

Sets a vec4 parameter for the material.

Parameters
nameName of the parameter.
valueglm::vec4 value to set.

Definition at line 107 of file material.cpp.

108{
109 mVec4Parameters[name] = value;
110}

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