Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::Material Class Reference

A collection of key value pairs used to control the behaviour of the rendering system when rendering a single "object.". More...

#include <material.hpp>

Inheritance diagram for ToyMaker::Material:
ToyMaker::Resource< Material > ToyMaker::IResource

Public Member Functions

virtual ~Material ()
 Destroys the material object.
 
 Material ()
 Constructs a new Material object.
 
 Material (const Material &other)
 Material copy constructor.
 
 Material (Material &&other)
 Material move constructor.
 
Materialoperator= (const Material &other)
 Material copy constructor.
 
Materialoperator= (Material &&other)
 Material move constructor.
 
void updateFloatProperty (const std::string &name, float value)
 Updates a float property.
 
float getFloatProperty (const std::string &name)
 Gets a float property.
 
void updateIntProperty (const std::string &name, int value)
 Updates an int property.
 
int getIntProperty (const std::string &name)
 Gets an int property.
 
void updateVec2Property (const std::string &name, const glm::vec2 &value)
 Updates a glm::vec2 property.
 
glm::vec2 getVec2Property (const std::string &name)
 Gets a glm::vec2 property.
 
void updateVec4Property (const std::string &name, const glm::vec4 &value)
 Updates a glm::vec4 property.
 
glm::vec4 getVec4Property (const std::string &name)
 Gets a glm::vec4 property.
 
void updateTextureProperty (const std::string &name, std::shared_ptr< Texture > value)
 Updates a texture property.
 
std::shared_ptr< TexturegetTextureProperty (const std::string &name)
 Gets the texture property of an object.
 
- Public Member Functions inherited from ToyMaker::Resource< Material >
std::string getResourceTypeName_ () const override
 Get the resource type string for this resource.
 
- Public Member Functions inherited from ToyMaker::IResource
virtual ~IResource ()=default
 Destroy the IResource object.
 

Static Public Member Functions

static std::shared_ptr< MaterialApplyOverrides (const nlohmann::json &materialOverrides, std::shared_ptr< Material > material=std::shared_ptr< Material >(new Material{}))
 Overrides various material related properties based on a JSON description of the overrides.
 
static void RegisterFloatProperty (const std::string &name, float defaultValue)
 Registers a project-wide float property.
 
static void RegisterIntProperty (const std::string &name, int defaultValue)
 Registers a project-wide int property.
 
static void RegisterVec4Property (const std::string &name, const glm::vec4 &defaultValue)
 Registers a project-wide glm::vec4 property.
 
static void RegisterVec2Property (const std::string &name, const glm::vec2 &defaultValue)
 Registers a project-wide glm::vec2 property.
 
static void RegisterTextureHandleProperty (const std::string &name, std::shared_ptr< Texture > defaultValue)
 Registers a project-wide texture property.
 
static std::string getResourceTypeName ()
 Gets the resource type string for this object.
 
static void Init ()
 Initializes the material system, to be called at the start of the application before material properties are registered.
 
static void Clear ()
 Clears all of this project's material system properties, to be called prior to application shutdown.
 

Private Member Functions

void destroyResource ()
 Destroys the resources used by this material (say, during destruction).
 
void releaseResource ()
 Releases the resources used by this material so that another material or part of the program can claim it.
 

Private Attributes

std::map< std::string, float > mFloatProperties {}
 All float property overrides used in this Material instance.
 
std::map< std::string, int > mIntProperties {}
 All int property overrides used in this Material instance.
 
std::map< std::string, glm::vec4 > mVec4Properties {}
 All glm::vec4 property overrides used in this Material instance.
 
std::map< std::string, glm::vec2 > mVec2Properties {}
 All glm::vec2 property overrides used in this Material instance.
 
std::map< std::string, std::shared_ptr< Texture > > mTextureProperties {}
 

Static Private Attributes

static MaterialdefaultMaterial { nullptr }
 A material instantiated at the start of the application, intended to hold all of the material properties and their default values.
 

Additional Inherited Members

- Protected Member Functions inherited from ToyMaker::Resource< Material >
 Resource (int explicitlyInitializeMe)
 Construct a new resource object.
 
- Protected Member Functions inherited from ToyMaker::IResource
 IResource ()=default
 Construct a new IResource object.
 
- Static Protected Member Functions inherited from ToyMaker::IResource
template<typename TResource>
static void RegisterResource ()
 Registers this resource as a Resource type with the ResourceDatabase.
 

Detailed Description

A collection of key value pairs used to control the behaviour of the rendering system when rendering a single "object.".

Each key-value pair is a string-type pair declared by the rendering system or its submodules at the start of the application.

While different engines implement materials differently, some common uses for them are:

  • Storing a collection of albedo, specular, normal, and displacement textures associated with a renderable object.
  • Specifying overrides for shader programs at particular points in the rendering pipeline.
  • Specifying the type of rendering queue a renderable object should be sent to (opaque vs transparent)
  • Storing the intensity of some post-processing effects (like exposure, gamma)
  • Storing other miscellaneous data related to a rendering pass (say an albedo color multiplier in the geometry pass, or the number of iterations for a blur shader).
Todo
Not happy with all the redundant code for getters-setters and material property registrators. Maybe replace with a templated version somehow?

Constructor & Destructor Documentation

◆ Material() [1/2]

Material::Material ( const Material & other)

Material copy constructor.

Parameters
otherMaterial being copied from.

◆ Material() [2/2]

Material::Material ( Material && other)

Material move constructor.

Parameters
otherMaterial whose resources are being claimed.

Member Function Documentation

◆ ApplyOverrides()

std::shared_ptr< Material > Material::ApplyOverrides ( const nlohmann::json & materialOverrides,
std::shared_ptr< Material > material = std::shared_ptr<Material>(new Material{}) )
static

Overrides various material related properties based on a JSON description of the overrides.

Here is an example of material overrides for a model resource defined in a scene file:

{
"method": "fromFile",
"name": "SwallowModel_One",
"parameters": {
"path": "data/models/UrSwallow.obj",
"material_overrides": {
"0": [
{
"name": "colorMultiplier",
"type": "vec4",
"value": [0.05, 0.05, 0.05, 1.0]
}
],
"1": [
{
"name": "colorMultiplier",
"type": "vec4",
"value": [0.05, 0.05, 0.05, 1.0]
}
]
}
},
"type": "StaticModel"
}
Parameters
materialOverridesThe material property overrides for an object in JSON.
materialA reference to the material on which the overrides are applied.
Returns
std::shared_ptr<Material> The material with its properties overridden.

◆ getFloatProperty()

float Material::getFloatProperty ( const std::string & name)

Gets a float property.

Parameters
nameThe name of the property.
Returns
float Its value.

◆ getIntProperty()

int Material::getIntProperty ( const std::string & name)

Gets an int property.

Parameters
nameThe name of the property.
Returns
int Its value.

◆ getResourceTypeName()

static std::string ToyMaker::Material::getResourceTypeName ( )
inlinestatic

Gets the resource type string for this object.

Returns
std::string This object's resource type string.

◆ getTextureProperty()

std::shared_ptr< Texture > Material::getTextureProperty ( const std::string & name)

Gets the texture property of an object.

Parameters
nameThe name of the property.
Returns
std::shared_ptr<Texture> Its value.

◆ getVec2Property()

glm::vec2 Material::getVec2Property ( const std::string & name)

Gets a glm::vec2 property.

Parameters
nameThe name of the property.
Returns
glm::vec2 Its value.

◆ getVec4Property()

glm::vec4 Material::getVec4Property ( const std::string & name)

Gets a glm::vec4 property.

Parameters
nameThe name of the property.
Returns
glm::vec4 Its value.

◆ operator=() [1/2]

Material & Material::operator= ( const Material & other)

Material copy constructor.

Parameters
otherMaterial being copied from.
Returns
Material& A reference to this material after the copy.

◆ operator=() [2/2]

Material & Material::operator= ( Material && other)

Material move constructor.

Parameters
otherMaterial whose resources are being claimed.
Returns
Material& A reference to this material after the copy.

◆ RegisterFloatProperty()

void Material::RegisterFloatProperty ( const std::string & name,
float defaultValue )
static

Registers a project-wide float property.

Parameters
nameThe name of the property.
defaultValueIts initial value.

◆ RegisterIntProperty()

void Material::RegisterIntProperty ( const std::string & name,
int defaultValue )
static

Registers a project-wide int property.

Parameters
nameThe name of the property.
defaultValueIts initial value.

◆ RegisterTextureHandleProperty()

void Material::RegisterTextureHandleProperty ( const std::string & name,
std::shared_ptr< Texture > defaultValue )
static

Registers a project-wide texture property.

Parameters
nameThe name of the property.
defaultValueIts initial value.

◆ RegisterVec2Property()

void Material::RegisterVec2Property ( const std::string & name,
const glm::vec2 & defaultValue )
static

Registers a project-wide glm::vec2 property.

Parameters
nameThe name of the property.
defaultValueIts initial value.

◆ RegisterVec4Property()

void Material::RegisterVec4Property ( const std::string & name,
const glm::vec4 & defaultValue )
static

Registers a project-wide glm::vec4 property.

Parameters
nameThe name of the property.
defaultValueIts initial value.

◆ updateFloatProperty()

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

Updates a float property.

Parameters
nameThe name of the property.
valueThe override value.

◆ updateIntProperty()

void Material::updateIntProperty ( const std::string & name,
int value )

Updates an int property.

Parameters
nameThe name of the property
valueThe override value.

◆ updateTextureProperty()

void Material::updateTextureProperty ( const std::string & name,
std::shared_ptr< Texture > value )

Updates a texture property.

Parameters
nameThe name of the property.
valueThe override value.

◆ updateVec2Property()

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

Updates a glm::vec2 property.

Parameters
nameThe name of the property.
valueThe override value.

◆ updateVec4Property()

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

Updates a glm::vec4 property.

Parameters
nameThe name of the property.
valueThe override value.

Member Data Documentation

◆ defaultMaterial

Material * Material::defaultMaterial { nullptr }
staticprivate

A material instantiated at the start of the application, intended to hold all of the material properties and their default values.

This same material is used to determine whether, when updateXProperty or getXProperty are called, the call is legal.


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