Class Material

Inheritance Relationships

Base Type

Class Documentation

class Material : public Cacao::Resource

Asset type for rendering materials (technically does not inherit from Asset because baking is not applicable)

Public Types

using ParamValue = std::variant<int, unsigned int, float, bool, glm::ivec2, glm::ivec3, glm::ivec4, glm::uvec2, glm::uvec3, glm::uvec4, glm::vec2, glm::vec3, glm::vec4, glm::mat2, glm::mat3, glm::mat4, std::shared_ptr<Tex2D>, std::shared_ptr<Cubemap>>

A storage type that holds any of the valid material parameter data types.

Public Functions

std::shared_ptr<Shader> GetShader()

Get a handle to the shader used by the material.

Returns:

The current shader

template<typename T>
inline void SetParameter(const std::string &name, const T &value)

Set the value of a material parameter.

Template Parameters:

T – The type of the parameter being set; must be one of the types in ParamValue

Parameters:
  • name – The name of the parameter to set

  • value – The value to store in the parameter

Throws:
  • NonexistentValueException – If the given parameter name is not one in the material

  • BadTypeException – If the type given does not match the parameter type

  • NonexistentValueException – If a texture type is passed and the handle is empty

template<typename T>
inline T GetParameter(const std::string &name)

Set the value of a material parameter.

Template Parameters:

T – The type of the parameter being set; must be one of the types in ParamValue

Parameters:

name – The name of the parameter to set

Throws:
  • NonexistentValueException – If the given parameter name is not one in the material

  • NonexistentValueException – If no value has been set for the given parameter

  • BadTypeException – If the type given does not match the parameter type

Returns:

The current value of the parameter

void SetRenderMode(libcacaoasset::Material::RenderMode mode)

Set the rendering mode.

Parameters:

mode – The new rendering mode

libcacaoasset::Material::RenderMode GetRenderMode()

Get the current rendering mode.

Returns:

The rendering mode

~Material()

Public Static Functions

static std::shared_ptr<Material> Create(std::shared_ptr<Shader> shader, const std::string &addr)

Create a new material based on a shader.

Parameters:
  • shader – The shader asset to use when rendering

  • addr – The resource address to associate with the material

Throws:
  • BadValueException – If the provided shader pointer is an invalid asset

  • BadValueException – If the address is malformed