Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::Material Class Reference

Shader + uniform storage that defines how a surface is rendered. More...

#include <Material.h>

Public Member Functions

void SetShaderProgram (const std::shared_ptr< ShaderProgram > &shaderProgram)
 Assign the GLSL program this material will use when drawn.
 
void Bind ()
 Upload all stored parameters to the active ShaderProgram.
 
ShaderProgramGetShaderProgram ()
 Returns the shader program assigned to this material.
 
Uniform Parameter Setters

Store a named uniform value. Uploaded to the GPU in Bind().

void SetParam (const std::string &name, float value)
 Set a float uniform.
 
void SetParam (const std::string &name, float v0, float v1)
 Set a vec2 uniform.
 
void SetParam (const std::string &name, const vec3 &value)
 Set a vec3 uniform.
 
void SetParam (const std::string &name, const vec4 &value)
 Set a vec4 uniform.
 
void SetParam (const std::string &name, const std::shared_ptr< Texture > &texture)
 Set a sampler2D uniform.
 
void SetParam (const std::string &name, const std::vector< glm::mat4 > &matrices)
 Set a mat4[] uniform (e.g. bone palette).
 

Static Public Member Functions

static std::shared_ptr< MaterialLoad (const str &path)
 Load a material from a descriptor file.
 

Detailed Description

Shader + uniform storage that defines how a surface is rendered.

Parameters are stored in typed maps and uploaded to the GPU lazily during Material::Bind(). Between frames, SetParam() calls simply overwrite the stored values without touching the GPU.

Definition at line 53 of file Material.h.

Member Function Documentation

◆ Bind()

void mnd::Material::Bind ( )

Upload all stored parameters to the active ShaderProgram.

Called automatically by RenderQueue::Draw() before each draw call. Binds textures to consecutive texture units starting from 0.

Definition at line 176 of file Material.cpp.

References LOG_WARN.

◆ GetShaderProgram()

ShaderProgram * mnd::Material::GetShaderProgram ( )

Returns the shader program assigned to this material.

Definition at line 14 of file Material.cpp.

◆ Load()

std::shared_ptr< Material > mnd::Material::Load ( const str path)
static

Load a material from a descriptor file.

Parameters
pathPath to the material asset file.
Returns
Shared pointer to the loaded Material.

Definition at line 54 of file Material.cpp.

References mnd::GraphicsAPI::CreateShaderProgram(), mnd::Engine::GetFileSystem(), mnd::Engine::GetGraphicsAPI(), mnd::Engine::GetInstance(), mnd::Texture::Load(), mnd::FileSystem::LoadAssetFileText(), and LOG_ERROR.

Referenced by mnd::MeshComponent::LoadProperties().

◆ SetParam() [1/6]

void mnd::Material::SetParam ( const std::string &  name,
const std::shared_ptr< Texture > &  texture 
)

Set a sampler2D uniform.

Definition at line 44 of file Material.cpp.

◆ SetParam() [2/6]

void mnd::Material::SetParam ( const std::string &  name,
const std::vector< glm::mat4 > &  matrices 
)

Set a mat4[] uniform (e.g. bone palette).

Definition at line 49 of file Material.cpp.

◆ SetParam() [3/6]

void mnd::Material::SetParam ( const std::string &  name,
const vec3 value 
)

Set a vec3 uniform.

Definition at line 34 of file Material.cpp.

◆ SetParam() [4/6]

void mnd::Material::SetParam ( const std::string &  name,
const vec4 value 
)

Set a vec4 uniform.

Definition at line 39 of file Material.cpp.

◆ SetParam() [5/6]

void mnd::Material::SetParam ( const std::string &  name,
float  v0,
float  v1 
)

Set a vec2 uniform.

Definition at line 29 of file Material.cpp.

◆ SetParam() [6/6]

void mnd::Material::SetParam ( const std::string &  name,
float  value 
)

Set a float uniform.

Definition at line 24 of file Material.cpp.

◆ SetShaderProgram()

void mnd::Material::SetShaderProgram ( const std::shared_ptr< ShaderProgram > &  shaderProgram)

Assign the GLSL program this material will use when drawn.

Parameters
shaderProgramCompiled shader; falls back to the default if unset.

Definition at line 19 of file Material.cpp.


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