Cogs.Core
Classes | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Cogs::Core::Material Struct Reference

Material resources define the how of geometry rendering (the what is defined by Mesh and Texture resources). More...

#include <Material.h>

Inheritance diagram for Cogs::Core::Material:
Cogs::Core::ResourceBase

Classes

struct  EffectInstance
 

Public Member Functions

 Material ()=default
 Constructs a new material.
 
 Material (Material &&other) noexcept=default
 Move construct Material from other.
 
Materialoperator= (Material &&other) noexcept=default
 Move assign material from other.
 
void setMaterialFlag (MaterialFlags::EMaterialFlags flag)
 Set the given material flag.
 
void unsetMaterialFlag (MaterialFlags::EMaterialFlags flag)
 Unset the given material flag.
 
bool isDefaultMaterial () const
 
VariableKey addTextureProperty (const PropertyName &name, TextureHandle defaultValue, TextureDimensions dimensions=TextureDimensions::Texture2D, SamplerState::AddressMode addressMode=SamplerState::Wrap, SamplerState::FilterMode filterMode=SamplerState::FilterMode::MinMagMipLinear, bool isPerInstance=true, bool isArray=false, uint32_t arraySize=0)
 Adds a texture property to the material.
 
MaterialDataType getPropertyDataType (const StringView &key)
 Gets data type for the given property. Returns MaterialDataType::Unknown if not found.
 
void setProperty (const StringView &name, const void *data, const size_t sizeInBytes)
 
template<typename T >
void setProperty (const VariableKey key, T value)
 Set the property value of the property with the given key in the given collection.
 
void setVec2Property (const VariableKey key, glm::vec2 value)
 Set the vec2 property with the given key to value.
 
void setVec3Property (const VariableKey key, glm::vec3 value)
 Set the vec3 property with the given key to value.
 
void setVec4Property (const VariableKey key, glm::vec4 value)
 Set the vec4 property with the given key to value.
 
void setInt4Property (const VariableKey key, glm::ivec4 value)
 Set the ivec4 property with the given key to value.
 
void setMat4Property (const VariableKey key, glm::mat4 value)
 Set the mat4 property with the given key to value.
 
void setFloatProperty (const VariableKey key, float value)
 Set the float property with the given key to value.
 
void setIntProperty (const VariableKey key, int value)
 
void setUIntProperty (const VariableKey key, uint32_t value)
 
void setBoolProperty (const VariableKey key, bool value)
 Set the bool property with the given key to value.
 
void setTextureProperty (const VariableKey key, TextureHandle value)
 Set the texture property with the given key to the texture resource held by value.
 
void setTextureAddressMode (const VariableKey key, SamplerState::AddressMode mode)
 Set the address mode used for the texture property with the given key to mode.
 
void setTextureAddressMode (const VariableKey key, SamplerState::AddressMode smode, SamplerState::AddressMode tmode, SamplerState::AddressMode umode)
 Set the address modes used for the texture property with the given key to modes when rendering geometry with this texture and material (X/Y/Z).
 
void setTextureFilterMode (const VariableKey key, SamplerState::FilterMode filterMode)
 Set filtermode used for the texture property.
 
VariableKey getBoolKey (const StringView &name) const
 
VariableKey getFloatKey (const StringView &name) const
 
VariableKey getIntKey (const StringView &name) const
 
VariableKey getUIntKey (const StringView &name) const
 
VariableKey getVec3Key (const StringView &name) const
 
VariableKey getVec4Key (const StringView &name) const
 
VariableKey getInt4Key (const StringView &name) const
 
VariableKey getMat4Key (const StringView &name) const
 
VariableKey getVec2Key (const StringView &name) const
 
VariableKey getTextureKey (const StringView &name) const
 
size_t getVariantIndex (const StringView &key) const
 
void setVariant (size_t index, int value)
 
void setVariant (const StringView &key, int value)
 
EffectHandle getEffect (size_t code, const MaterialInstance *materialInstance, const MeshStreamsLayout *streamsLayout, const EnginePermutation *enginePermutation, const RenderPassOptions &passOptions, const ClipShapeType clipShape)
 
- Public Member Functions inherited from Cogs::Core::ResourceBase
 ResourceBase ()=default
 Constructs a new resource base.
 
 ResourceBase (const ResourceBase &other)=delete
 Disable trivial copies of resources.
 
ResourceBaseoperator= (const ResourceBase &other)=delete
 Disable copy-assignment of resources.
 
 ResourceBase (ResourceBase &&other)
 Move constructs a resource base from other.
 
ResourceBaseoperator= (ResourceBase &&other)
 Move assign the resource from the given ResourceBase other.
 
 ~ResourceBase ()
 Destructs the resource.
 
void setInitialized ()
 
void setChanged ()
 
bool hasChanged () const
 
void setLoading ()
 
void setLoaded ()
 
void setFailedLoad ()
 
void setActive ()
 
void setResident ()
 
void setProxy ()
 
void setKeepStorage ()
 
bool isInitialized () const
 
bool isLoaded () const
 
bool isActive () const
 
bool isResident () const
 
bool isDependency () const
 
bool isDeleted () const
 
bool isOrphaned () const
 
bool isProxy () const
 
bool hasFailedLoad () const
 
bool hasFailedActivation () const
 
bool keepStorage () const
 
void setType (ResourceTypes type)
 Set the type enumeration of the resource.
 
ResourceTypes getType () const
 Gets the type enumeration of the resource.
 
void setId (ResourceId resourceId)
 Set the resource id of the resource.
 
ResourceId getId () const
 Get the resource id of this instance.
 
void setFlag (ResourceFlags flags)
 Set the given resource flag.
 
void setFlags (ResourceFlags flags)
 
void unsetFlag (ResourceFlags flag)
 Unset the given flag.
 
bool isSet (ResourceFlags flag) const
 Check if the given flag is currently set.
 
ResourceFlags getFlags () const
 Get the current flags of the resource.
 
void attachResource (RenderResource *attachment)
 Attach the given GPU resource to the resource.
 
bool hasAttachedResource () const
 Check if the resource has an attachment.
 
RenderResourcegetAttachedResource () const
 Get the attached resource.
 
void setOwner (IResourceManager *owner)
 Sets the owner of this resource instance.
 
IResourceManagergetOwner () const
 
void setName (const StringView &name)
 Set the user friendly name of the resource.
 
StringView getName () const
 Get the name of the resource.
 
void setSource (const StringView &source)
 
StringView getSource () const
 
void increment ()
 Increments the reference count of the resource.
 
void decrement ()
 Decrement the reference count of the resource.
 
uint32_t referenceCount () const
 Get the current reference count.
 
void incrementGeneration ()
 Increment the generation count.
 
uint32_t getGeneration () const
 Get the generation count.
 
void setSlot (uint32_t slot)
 Sets the slot at which the resource is internally tracked.
 
uint32_t getSlot () const
 Gets the slot where the resource is tracked internally.
 

Public Attributes

MaterialDefinition definition
 
size_t variantGeneration = 0
 
std::vector< std::string > permutationKeys
 
std::vector< EffectInstanceeffects
 
ConstantBuffers constantBuffers
 
MaterialOptions options
 Material rendering options.
 
uint16_t materialFlags = MaterialFlags::None
 Material flags controlling rendering behavior.
 
uint64_t enginePermutationMask = 0x1 | 0x2 | 0x3 | 0x4
 
std::vector< TexturePropertytextureProperties
 

Static Public Attributes

static const constexpr size_t NoVariantIndex = size_t(-1)
 
- Static Public Attributes inherited from Cogs::Core::ResourceBase
static const uint32_t NoAttachment = 0xFFFFFFFF
 Constant used to signal no attachment.
 

Detailed Description

Material resources define the how of geometry rendering (the what is defined by Mesh and Texture resources).

Materials contain a handle to an Effect resource to use when rendering, and a set of properties, options and flags to control the input to the shader stages using the effect.

A material is made up of the effect handle, and a set of property buffers containing material properties to apply to the material when rendering. On platforms with the required support, the property buffers are initialized to the same layout as constant buffers in the shaders, making simple transfer of material properties to the GPU possible in the renderer. On legacy platforms, regular per-uniform transfer is used.

In addition the material contains options to control how the rendering behavior of the material, such as turning on/off blending, depth writes and depth testing.

Definition at line 81 of file Material.h.

Member Function Documentation

◆ addTextureProperty()

VariableKey Cogs::Core::Material::addTextureProperty ( const PropertyName name,
TextureHandle  defaultValue,
TextureDimensions  dimensions = TextureDimensions::Texture2D,
SamplerState::AddressMode  addressMode = SamplerState::Wrap,
SamplerState::FilterMode  filterMode = SamplerState::FilterMode::MinMagMipLinear,
bool  isPerInstance = true,
bool  isArray = false,
uint32_t  arraySize = 0 
)
inline

Adds a texture property to the material.

The name given must correspond to a texture binding found in the effect used by the material.

Parameters
nameName of the texture as used in the effect.
defaultValueDefault texture resource to set the texture to when rendering.
addressModeDefault address mode to use when rendering using this texture.
Returns
A property key used to get or set the property value.

Definition at line 123 of file Material.h.

References Cogs::Core::TextureWithSampler::dimensions, Cogs::Core::TextureWithSampler::filterMode, Cogs::Core::TextureWithSampler::handle, and Cogs::Core::TextureWithSampler::sMode.

◆ getBoolKey()

VariableKey Cogs::Core::Material::getBoolKey ( const StringView name) const
inline

Definition at line 296 of file Material.h.

◆ getEffect()

Cogs::Core::EffectHandle Cogs::Core::Material::getEffect ( size_t  code,
const MaterialInstance materialInstance,
const MeshStreamsLayout streamsLayout,
const EnginePermutation enginePermutation,
const RenderPassOptions passOptions,
const ClipShapeType  clipShape 
)

Get effect for a material variant with a given permutation/variant/streamlayout combo.

Definition at line 223 of file Material.cpp.

References Cogs::Core::MaterialManager::loadMaterialVariant().

Referenced by Cogs::Core::RenderMaterial::getBinding().

◆ getFloatKey()

VariableKey Cogs::Core::Material::getFloatKey ( const StringView name) const
inline

Definition at line 301 of file Material.h.

◆ getInt4Key()

VariableKey Cogs::Core::Material::getInt4Key ( const StringView name) const
inline

Definition at line 326 of file Material.h.

◆ getIntKey()

VariableKey Cogs::Core::Material::getIntKey ( const StringView name) const
inline

Definition at line 306 of file Material.h.

◆ getMat4Key()

VariableKey Cogs::Core::Material::getMat4Key ( const StringView name) const
inline

Definition at line 331 of file Material.h.

◆ getPropertyDataType()

MaterialDataType Cogs::Core::Material::getPropertyDataType ( const StringView key)

Gets data type for the given property. Returns MaterialDataType::Unknown if not found.

Definition at line 130 of file Material.cpp.

◆ getTextureKey()

VariableKey Cogs::Core::Material::getTextureKey ( const StringView name) const
inline

Definition at line 341 of file Material.h.

◆ getUIntKey()

VariableKey Cogs::Core::Material::getUIntKey ( const StringView name) const
inline

Definition at line 311 of file Material.h.

◆ getVariantIndex()

size_t Cogs::Core::Material::getVariantIndex ( const StringView key) const

Definition at line 178 of file Material.cpp.

◆ getVec2Key()

VariableKey Cogs::Core::Material::getVec2Key ( const StringView name) const
inline

Definition at line 336 of file Material.h.

◆ getVec3Key()

VariableKey Cogs::Core::Material::getVec3Key ( const StringView name) const
inline

Definition at line 316 of file Material.h.

◆ getVec4Key()

VariableKey Cogs::Core::Material::getVec4Key ( const StringView name) const
inline

Definition at line 321 of file Material.h.

◆ isDefaultMaterial()

bool Cogs::Core::Material::isDefaultMaterial ( ) const
inline

Definition at line 110 of file Material.h.

◆ setBoolProperty()

void Cogs::Core::Material::setBoolProperty ( const VariableKey  key,
bool  value 
)
inline

Set the bool property with the given key to value.

Parameters
keyKey of the bool property to set.
valueValue to set the property to.

Definition at line 261 of file Material.h.

◆ setFloatProperty()

void Cogs::Core::Material::setFloatProperty ( const VariableKey  key,
float  value 
)
inline

Set the float property with the given key to value.

Parameters
keyKey of the float property to set.
valueValue to set the property to.

Definition at line 240 of file Material.h.

◆ setInt4Property()

void Cogs::Core::Material::setInt4Property ( const VariableKey  key,
glm::ivec4  value 
)
inline

Set the ivec4 property with the given key to value.

Parameters
keyKey of the vec4 property to set.
valueValue to set the property to.

Definition at line 218 of file Material.h.

◆ setIntProperty()

void Cogs::Core::Material::setIntProperty ( const VariableKey  key,
int  value 
)
inline

Definition at line 245 of file Material.h.

◆ setMat4Property()

void Cogs::Core::Material::setMat4Property ( const VariableKey  key,
glm::mat4  value 
)
inline

Set the mat4 property with the given key to value.

Parameters
keyKey of the mat4 property to set.
valueValue to set the property to.

Definition at line 229 of file Material.h.

◆ setMaterialFlag()

void Cogs::Core::Material::setMaterialFlag ( MaterialFlags::EMaterialFlags  flag)
inline

Set the given material flag.

Parameters
flagMaterial flag to set.

Definition at line 101 of file Material.h.

◆ setProperty() [1/2]

void Cogs::Core::Material::setProperty ( const StringView name,
const void *  data,
const size_t  sizeInBytes 
)

Definition at line 243 of file Material.cpp.

◆ setProperty() [2/2]

template<typename T >
void Cogs::Core::Material::setProperty ( const VariableKey  key,
value 
)
inline

Set the property value of the property with the given key in the given collection.

Setting a property triggers resending the properties to the renderer before using this material for rendering.

Parameters
collectionCollection of properties the property is located in.
keyProperty key used to look up the material property in the collection.
valueValue to set the property to.
Template Parameters
CollectionType of the property collection. Inferred from collection.
TType of the value to set the property to. Inferred from value. Must be the same as the value type of the properties contained in collection.

Definition at line 172 of file Material.h.

References Cogs::setChanged().

◆ setTextureAddressMode() [1/2]

void Cogs::Core::Material::setTextureAddressMode ( const VariableKey  key,
SamplerState::AddressMode  mode 
)

Set the address mode used for the texture property with the given key to mode.

Parameters
keyKey to a texture property.
modeAddress mode to use when rendering geometry with this texture and material.

Definition at line 142 of file Material.cpp.

◆ setTextureAddressMode() [2/2]

void Cogs::Core::Material::setTextureAddressMode ( const VariableKey  key,
SamplerState::AddressMode  smode,
SamplerState::AddressMode  tmode,
SamplerState::AddressMode  umode 
)

Set the address modes used for the texture property with the given key to modes when rendering geometry with this texture and material (X/Y/Z).

Parameters
keyKey to a texture property.
smodeS-Address mode to use.
tmodeT-Address mode to use.
umodeU-Address mode to use.

Definition at line 147 of file Material.cpp.

References Cogs::Core::MaterialProperty::dirty, Cogs::setChanged(), and Cogs::Core::TextureWithSampler::sMode.

◆ setTextureFilterMode()

void Cogs::Core::Material::setTextureFilterMode ( const VariableKey  key,
SamplerState::FilterMode  filterMode 
)

Set filtermode used for the texture property.

Definition at line 164 of file Material.cpp.

References Cogs::Core::MaterialProperty::dirty, Cogs::Core::TextureWithSampler::filterMode, and Cogs::setChanged().

◆ setTextureProperty()

void Cogs::Core::Material::setTextureProperty ( const VariableKey  key,
TextureHandle  value 
)

Set the texture property with the given key to the texture resource held by value.

Parameters
keyKey of the texture property to set.
valueHandle to a Texture resource to use. If NoHandle, no texture is passed to the effect.

Definition at line 116 of file Material.cpp.

References Cogs::Core::MaterialProperty::dirty, Cogs::Core::TextureWithSampler::handle, and Cogs::setChanged().

◆ setUIntProperty()

void Cogs::Core::Material::setUIntProperty ( const VariableKey  key,
uint32_t  value 
)
inline

Definition at line 250 of file Material.h.

◆ setVariant() [1/2]

void Cogs::Core::Material::setVariant ( const StringView key,
int  value 
)

Definition at line 213 of file Material.cpp.

◆ setVariant() [2/2]

void Cogs::Core::Material::setVariant ( size_t  index,
int  value 
)

Definition at line 189 of file Material.cpp.

◆ setVec2Property()

void Cogs::Core::Material::setVec2Property ( const VariableKey  key,
glm::vec2  value 
)
inline

Set the vec2 property with the given key to value.

Parameters
keyKey of the vec2 property to set.
valueValue to set the property to.

Definition at line 185 of file Material.h.

◆ setVec3Property()

void Cogs::Core::Material::setVec3Property ( const VariableKey  key,
glm::vec3  value 
)
inline

Set the vec3 property with the given key to value.

Parameters
keyKey of the vec2 property to set.
valueValue to set the property to.

Definition at line 196 of file Material.h.

◆ setVec4Property()

void Cogs::Core::Material::setVec4Property ( const VariableKey  key,
glm::vec4  value 
)
inline

Set the vec4 property with the given key to value.

Parameters
keyKey of the vec4 property to set.
valueValue to set the property to.

Definition at line 207 of file Material.h.

◆ unsetMaterialFlag()

void Cogs::Core::Material::unsetMaterialFlag ( MaterialFlags::EMaterialFlags  flag)
inline

Unset the given material flag.

Parameters
flagMaterial flag to unset.

Definition at line 108 of file Material.h.

Member Data Documentation

◆ constantBuffers

ConstantBuffers Cogs::Core::Material::constantBuffers

Definition at line 380 of file Material.h.

◆ definition

MaterialDefinition Cogs::Core::Material::definition

Definition at line 358 of file Material.h.

◆ effects

std::vector<EffectInstance> Cogs::Core::Material::effects

Definition at line 378 of file Material.h.

◆ enginePermutationMask

uint64_t Cogs::Core::Material::enginePermutationMask = 0x1 | 0x2 | 0x3 | 0x4

Definition at line 388 of file Material.h.

◆ materialFlags

uint16_t Cogs::Core::Material::materialFlags = MaterialFlags::None

Material flags controlling rendering behavior.

Definition at line 386 of file Material.h.

◆ NoVariantIndex

const constexpr size_t Cogs::Core::Material::NoVariantIndex = size_t(-1)
staticconstexpr

Definition at line 83 of file Material.h.

◆ options

MaterialOptions Cogs::Core::Material::options

◆ permutationKeys

std::vector<std::string> Cogs::Core::Material::permutationKeys

Definition at line 362 of file Material.h.

◆ textureProperties

std::vector<TextureProperty> Cogs::Core::Material::textureProperties

Definition at line 390 of file Material.h.

◆ variantGeneration

size_t Cogs::Core::Material::variantGeneration = 0

Definition at line 360 of file Material.h.


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