Cogs.Core
MaterialProperty.h
1#pragma once
2
3#include "MaterialPropertyBuffer.h"
4#include "Resources/MaterialTypes.h"
5
6#include "Rendering/SamplerState.h"
7
8#include "Foundation/HashFunctions.h"
9
10namespace Cogs::Core
11{
12 enum struct MaterialPropertyFlags : uint8_t
13 {
15 None = 0,
17 sRGB = 1 << 0,
19 Normalized = 1 << 1,
21 PartitionOfUnity = 1 << 2
22 };
23
24 ENABLE_ENUM_FLAGS(MaterialPropertyFlags);
25
33 {
36
38 VariableKey key = NoProperty;
39
41 ConstantBufferKey buffer = NoProperty;
42
45
47 MaterialDataType type = MaterialDataType::Unknown;
48
50 glm::mat4 storage;
51
52 template<typename T>
53 void setDefault(T & t) {
54 static_assert(sizeof(T) <= sizeof(storage));
55 *reinterpret_cast<T *>(&storage) = t;
56 }
57
58 float defaultFloat() const { return *reinterpret_cast<const float *>(&storage); }
59 int defaultInt() const { return *reinterpret_cast<const int *>(&storage); }
60 uint32_t defaultUInt() const { return *reinterpret_cast<const uint32_t *>(&storage); }
61 bool defaultBool() const { return *reinterpret_cast<const bool *>(&storage); }
62
63 glm::vec2 defaultVec2() const { return *reinterpret_cast<const glm::vec2 *>(&storage); }
64 glm::vec3 defaultVec3() const { return *reinterpret_cast<const glm::vec3 *>(&storage); }
65 glm::vec4 defaultVec4() const { return *reinterpret_cast<const glm::vec4 *>(&storage); }
66
68 bool dirty = false;
69
71 bool isPerInstance = true;
72
73 bool isArray = false;
74
75 uint32_t arraySize = 0;
76
78 };
79
84 {
85 Texture2D = 0,
86 TexureCube = 1,
87 Texture3D = 2,
88 Texture2DArray = 3,
89 };
90
92 {
95
100
103
105 TextureDimensions dimensions = TextureDimensions::Texture2D;
106
107 size_t hash(size_t hashValue = Cogs::hash()) const {
108 hashValue = handle.hash(hashValue);
109 hashValue = Cogs::hash(sMode, hashValue);
110 hashValue = Cogs::hash(tMode, hashValue);
111 hashValue = Cogs::hash(uMode, hashValue);
112 hashValue = Cogs::hash(filterMode, hashValue);
113 hashValue = Cogs::hash(dimensions, hashValue);
114
115 return hashValue;
116 }
117 };
118
123 {
124 TextureWithSampler texture;
125 };
126
128 {
130 const TextureProperty * property = nullptr;
131
134
137
139 bool dirty = true;
140
141 size_t hash(size_t hashValue = Cogs::hash()) const {
142 hashValue = Cogs::hash(reinterpret_cast<intptr_t>(property), hashValue);
143 hashValue = Cogs::hash(key, hashValue);
144 hashValue = texture.hash(hashValue);
145 hashValue = Cogs::hash(dirty, hashValue);
146
147 return hashValue;
148 }
149 };
150}
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
TextureDimensions
Texture dimensions.
MaterialDataType
Defines available data types for material properties.
Definition: MaterialTypes.h:20
@ Normalized
Value is a direction vector is subject to normalization.
@ PartitionOfUnity
A set of non-negative weights that sum to one.
@ sRGB
Value is a color and is subject to gamma correction.
std::string PropertyName
Typedef for property names.
uint16_t VariableKey
Used to lookup material properties.
Definition: Resources.h:46
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62
Contains location/size information for a property.
Defines a single material property.
bool dirty
If the property is dirty.
MaterialPropertyDescriptor descriptor
Property descriptor.
bool isPerInstance
If the property is defined per instance or per material.
glm::mat4 storage
Storage for property data. Really a union.
ConstantBufferKey buffer
Key to the buffer the property value is stored in.
VariableKey key
Key of the property, used to index into the property collection the property will be placed into.
PropertyName name
Name of the property, used to reference named uniforms of constant buffer members in shaders.
MaterialDataType type
Type of data held by property.
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.
Property value for texture samplers.
TextureWithSampler texture
Value of the property for the material instance this belongs to.
VariableKey key
Key of the property.
const TextureProperty * property
Pointer to the property this value is for.
bool dirty
If the value has changed since last updated.
SamplerState::FilterMode filterMode
Filter mode to use when rendering with this texture.
SamplerState::AddressMode sMode
Address mode to use when rendering with this texture.
TextureHandle handle
Handle to a texture resource, or TextureHandle::NoHandle if texture should be disabled.
TextureDimensions dimensions
Expected dimensions of the texture property.
AddressMode
Addressing modes to use when sampling textures.
Definition: SamplerState.h:15
@ Wrap
Texture coordinates automatically wrap around to [0, 1] range.
Definition: SamplerState.h:19
FilterMode
Filter modes to specify how texture data is treated when sampled.
Definition: SamplerState.h:31
@ MinMagMipLinear
Linear sampling for both minification and magnification.
Definition: SamplerState.h:35