Cogs.Core
|
Material resources define the how of geometry rendering (the what is defined by Mesh and Texture resources). More...
#include <Material.h>
Classes | |
struct | EffectInstance |
Public Member Functions | |
Material ()=default | |
Constructs a new material. | |
Material (Material &&other) noexcept=default | |
Move construct Material from other. | |
Material & | operator= (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) |
![]() | |
ResourceBase ()=default | |
Constructs a new resource base. | |
ResourceBase (const ResourceBase &other)=delete | |
Disable trivial copies of resources. | |
ResourceBase & | operator= (const ResourceBase &other)=delete |
Disable copy-assignment of resources. | |
ResourceBase (ResourceBase &&other) | |
Move constructs a resource base from other. | |
ResourceBase & | operator= (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. | |
RenderResource * | getAttachedResource () const |
Get the attached resource. | |
void | setOwner (IResourceManager *owner) |
Sets the owner of this resource instance. | |
IResourceManager * | getOwner () 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< EffectInstance > | effects |
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< TextureProperty > | textureProperties |
Static Public Attributes | |
static const constexpr size_t | NoVariantIndex = size_t(-1) |
![]() | |
static const uint32_t | NoAttachment = 0xFFFFFFFF |
Constant used to signal no attachment. | |
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.
|
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.
name | Name of the texture as used in the effect. |
defaultValue | Default texture resource to set the texture to when rendering. |
addressMode | Default address mode to use when rendering using this texture. |
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.
|
inline |
Definition at line 296 of file Material.h.
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().
|
inline |
Definition at line 301 of file Material.h.
|
inline |
Definition at line 326 of file Material.h.
|
inline |
Definition at line 306 of file Material.h.
|
inline |
Definition at line 331 of file Material.h.
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.
|
inline |
Definition at line 341 of file Material.h.
|
inline |
Definition at line 311 of file Material.h.
size_t Cogs::Core::Material::getVariantIndex | ( | const StringView & | key | ) | const |
Definition at line 178 of file Material.cpp.
|
inline |
Definition at line 336 of file Material.h.
|
inline |
Definition at line 316 of file Material.h.
|
inline |
Definition at line 321 of file Material.h.
|
inline |
Definition at line 110 of file Material.h.
|
inline |
Set the bool property with the given key to value.
key | Key of the bool property to set. |
value | Value to set the property to. |
Definition at line 261 of file Material.h.
|
inline |
Set the float property with the given key to value.
key | Key of the float property to set. |
value | Value to set the property to. |
Definition at line 240 of file Material.h.
|
inline |
Set the ivec4 property with the given key to value.
key | Key of the vec4 property to set. |
value | Value to set the property to. |
Definition at line 218 of file Material.h.
|
inline |
Definition at line 245 of file Material.h.
|
inline |
Set the mat4 property with the given key to value.
key | Key of the mat4 property to set. |
value | Value to set the property to. |
Definition at line 229 of file Material.h.
|
inline |
Set the given material flag.
flag | Material flag to set. |
Definition at line 101 of file Material.h.
void Cogs::Core::Material::setProperty | ( | const StringView & | name, |
const void * | data, | ||
const size_t | sizeInBytes | ||
) |
Definition at line 243 of file Material.cpp.
|
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.
collection | Collection of properties the property is located in. |
key | Property key used to look up the material property in the collection. |
value | Value to set the property to. |
Collection | Type of the property collection. Inferred from collection. |
T | Type 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().
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.
key | Key to a texture property. |
mode | Address mode to use when rendering geometry with this texture and material. |
Definition at line 142 of file Material.cpp.
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).
key | Key to a texture property. |
smode | S-Address mode to use. |
tmode | T-Address mode to use. |
umode | U-Address mode to use. |
Definition at line 147 of file Material.cpp.
References Cogs::Core::MaterialProperty::dirty, Cogs::setChanged(), and Cogs::Core::TextureWithSampler::sMode.
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().
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.
key | Key of the texture property to set. |
value | Handle 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().
|
inline |
Definition at line 250 of file Material.h.
void Cogs::Core::Material::setVariant | ( | const StringView & | key, |
int | value | ||
) |
Definition at line 213 of file Material.cpp.
void Cogs::Core::Material::setVariant | ( | size_t | index, |
int | value | ||
) |
Definition at line 189 of file Material.cpp.
|
inline |
Set the vec2 property with the given key to value.
key | Key of the vec2 property to set. |
value | Value to set the property to. |
Definition at line 185 of file Material.h.
|
inline |
Set the vec3 property with the given key to value.
key | Key of the vec2 property to set. |
value | Value to set the property to. |
Definition at line 196 of file Material.h.
|
inline |
Set the vec4 property with the given key to value.
key | Key of the vec4 property to set. |
value | Value to set the property to. |
Definition at line 207 of file Material.h.
|
inline |
Unset the given material flag.
flag | Material flag to unset. |
Definition at line 108 of file Material.h.
ConstantBuffers Cogs::Core::Material::constantBuffers |
Definition at line 380 of file Material.h.
MaterialDefinition Cogs::Core::Material::definition |
Definition at line 358 of file Material.h.
std::vector<EffectInstance> Cogs::Core::Material::effects |
Definition at line 378 of file Material.h.
uint64_t Cogs::Core::Material::enginePermutationMask = 0x1 | 0x2 | 0x3 | 0x4 |
Definition at line 388 of file Material.h.
uint16_t Cogs::Core::Material::materialFlags = MaterialFlags::None |
Material flags controlling rendering behavior.
Definition at line 386 of file Material.h.
|
staticconstexpr |
Definition at line 83 of file Material.h.
MaterialOptions Cogs::Core::Material::options |
Material rendering options.
Definition at line 383 of file Material.h.
Referenced by Cogs::Core::SpriteRenderSystem::initialize(), Cogs::Core::TextSystem::initialize(), and Cogs::Core::MaterialInstance::setupInstance().
std::vector<std::string> Cogs::Core::Material::permutationKeys |
Definition at line 362 of file Material.h.
std::vector<TextureProperty> Cogs::Core::Material::textureProperties |
Definition at line 390 of file Material.h.
size_t Cogs::Core::Material::variantGeneration = 0 |
Definition at line 360 of file Material.h.