3#include "ResourceBase.h"
5#include "MaterialDefinition.h"
6#include "MaterialPropertyBuffer.h"
7#include "MaterialProperty.h"
8#include "MaterialOptions.h"
9#include "ConstantBuffers.h"
10#include "MeshStreamsLayout.h"
12#include "Rendering/SamplerState.h"
14#include "Foundation/StringView.h"
16#include <glm/vec2.hpp>
17#include <glm/vec3.hpp>
18#include <glm/vec4.hpp>
19#include <glm/mat4x4.hpp>
20#include <glm/gtc/type_ptr.hpp>
29 struct EnginePermutation;
30 struct MaterialInstance;
31 struct RenderPassOptions;
34 void COGSCORE_DLL_API enforcePropertyFlags(
const MaterialProperty & prop,
MaterialPropertyFlags flags,
void * data);
83 static const constexpr size_t NoVariantIndex = size_t(-1);
110 bool isDefaultMaterial()
const {
return materialFlags & MaterialFlags::Default ? true :
false; }
128 bool isPerInstance =
true,
129 bool isArray =
false, uint32_t arraySize = 0)
132 texture.
handle = defaultValue;
133 texture.
sMode = addressMode;
134 texture.tMode = addressMode;
135 texture.uMode = addressMode;
140 auto & textureProperty = textureProperties.emplace_back();
142 textureProperty.key = key;
143 textureProperty.isPerInstance = isPerInstance;
144 textureProperty.name = name;
145 textureProperty.texture = texture;
146 textureProperty.isArray = isArray;
147 textureProperty.arraySize = arraySize;
155 void setProperty(
const StringView& name,
const void* data,
const size_t sizeInBytes);
174 constantBuffers.setProperty(key, value);
187 setProperty(key, value);
198 setProperty(key, value);
209 setProperty(key, value);
220 setProperty(key, value);
231 setProperty(key, value);
242 setProperty(key, value);
245 void setIntProperty(
const VariableKey key,
int value)
247 setProperty(key, value);
250 void setUIntProperty(
const VariableKey key, uint32_t value)
252 setProperty(key, value);
263 setProperty(key, value);
298 return constantBuffers.getPropertyKey(name);
301 VariableKey getFloatKey(
const StringView & name)
const
303 return constantBuffers.getPropertyKey(name);
306 VariableKey getIntKey(
const StringView & name)
const
308 return constantBuffers.getPropertyKey(name);
311 VariableKey getUIntKey(
const StringView & name)
const
313 return constantBuffers.getPropertyKey(name);
316 VariableKey getVec3Key(
const StringView & name)
const
318 return constantBuffers.getPropertyKey(name);
321 VariableKey getVec4Key(
const StringView & name)
const
323 return constantBuffers.getPropertyKey(name);
326 VariableKey getInt4Key(
const StringView& name)
const
328 return constantBuffers.getPropertyKey(name);
331 VariableKey getMat4Key(
const StringView & name)
const
333 return constantBuffers.getPropertyKey(name);
336 VariableKey getVec2Key(
const StringView & name)
const
338 return constantBuffers.getPropertyKey(name);
341 VariableKey getTextureKey(
const StringView & name)
const
343 for (
auto & prop : textureProperties) {
344 if (name == prop.name) {
352 size_t getVariantIndex(
const StringView& key)
const;
354 void setVariant(
size_t index,
int value);
356 void setVariant(
const StringView& key,
int value);
358 MaterialDefinition definition;
360 size_t variantGeneration = 0;
362 std::vector<std::string> permutationKeys;
378 std::vector<EffectInstance> effects;
386 uint16_t materialFlags = MaterialFlags::None;
388 uint64_t enginePermutationMask = 0x1 | 0x2 | 0x3 | 0x4;
390 std::vector<TextureProperty> textureProperties;
395template<>
inline Cogs::StringView getName<Cogs::Core::MaterialFlags::EMaterialFlags>() {
return "MaterialFlags"; }
Provides a weakly referenced view over the contents of a string.
ClipShapeType
Specifices what kind of shape a clip shape has.
TextureDimensions
Texture dimensions.
MaterialDataType
Defines available data types for material properties.
std::string PropertyName
Typedef for property names.
uint16_t VariableKey
Used to lookup material properties.
Contains all Cogs related functionality.
void setChanged(Cogs::Core::Context *context, Cogs::ComponentModel::Component *component, Reflection::FieldId fieldId)
Must be Called after changing a Component field. Mark field changed. Request engine update.
Defines material flags controlling the behavior of Materials when rendering.
EMaterialFlags
Material flags.
@ Override
Override all properties of any inheriting materials.
@ OverrideAlpha
Override alpha of any inheriting materials.
@ Default
Default material.
@ OverrideProperties
Override properties of any inheriting materials.
@ OverrideColor
Override color of any inheriting materials.
@ OverrideTextures
Override textures of any inheriting materials.
@ CustomBucket
Items with this flag should be put in Custom rendering buckets.
@ Sprite
The material is used for sprite rendering only.
@ MasterTransparency
Material contains transparency.
Material instances represent a specialized Material combined with state for all its buffers and prope...
Defines options for rendering using a material instance.
Material resources define the how of geometry rendering (the what is defined by Mesh and Texture reso...
Material & operator=(Material &&other) noexcept=default
Move assign material from other.
void setMaterialFlag(MaterialFlags::EMaterialFlags flag)
Set the given material flag.
void setBoolProperty(const VariableKey key, bool value)
Set the bool property with the given key to value.
Material(Material &&other) noexcept=default
Move construct Material from other.
void unsetMaterialFlag(MaterialFlags::EMaterialFlags flag)
Unset the given material flag.
void setMat4Property(const VariableKey key, glm::mat4 value)
Set the mat4 property with the given key to value.
Material()=default
Constructs a new material.
void setProperty(const VariableKey key, T value)
Set the property value of the property with the given key in the given collection.
void setFloatProperty(const VariableKey key, float value)
Set the float 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 setVec2Property(const VariableKey key, glm::vec2 value)
Set the vec2 property with the given key to value.
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.
void setVec3Property(const VariableKey key, glm::vec3 value)
Set the vec3 property with the given key to value.
MaterialOptions options
Material rendering options.
Base class for engine resources.
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.
FilterMode
Filter modes to specify how texture data is treated when sampled.