Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Material.inl
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#ifndef DVD_MATERIAL_INL_
33#define DVD_MATERIAL_INL_
34
35namespace Divide {
36
37inline void Material::lockInstancesForRead() const noexcept
38{
39 _instanceLock.lock_shared();
40}
41
42inline void Material::unlockInstancesForRead() const noexcept
43{
44 _instanceLock.unlock_shared();
45}
46
47inline void Material::lockInstancesForWrite() const noexcept
48{
49 _instanceLock.lock();
50}
51
52inline void Material::unlockInstancesForWrite() const noexcept
53{
54 _instanceLock.unlock();
55}
56
58{
59 return _instances;
60}
61
63{
65 return getInstancesLocked();
66}
67
68inline Handle<Texture> Material::getTexture(const TextureSlot textureUsage) const
69{
71 return _textures[to_U32(textureUsage)]._ptr;
72}
73
74inline bool Material::hasTransparency() const noexcept
75{
76 return properties().translucencySource() != TranslucencySource::COUNT &&
77 properties().overrides().transparencyEnabled();
78}
79
80inline bool Material::isReflective() const noexcept
81{
82 return properties().metallic() > 0.05f &&
83 properties().roughness() < 0.99f;
84}
85
86inline bool Material::isRefractive() const noexcept
87{
88 return hasTransparency() &&
89 properties().isRefractive();
90}
91
93{
94 return _shaderInfo[to_base(renderStagePass._stage)][to_base(renderStagePass._passType)][to_base(renderStagePass._variant)];
95}
96
97inline const ShaderProgramInfo& Material::shaderInfo(const RenderStagePass renderStagePass) const
98{
99 return _shaderInfo[to_base(renderStagePass._stage)][to_base(renderStagePass._passType)][to_base(renderStagePass._variant)];
100}
101
102inline void Material::addShaderDefine(const ShaderType type, const string& define, const bool addPrefix = true)
103{
104 if (type != ShaderType::COUNT)
105 {
106 addShaderDefineInternal(type, define, addPrefix);
107 }
108 else
109 {
110 for (U8 i = 0u; i < to_U8(ShaderType::COUNT); ++i)
111 {
112 addShaderDefine(static_cast<ShaderType>(i), define, addPrefix);
113 }
114 }
115}
116
118{
119 return _textures[to_base(usage)];
120}
121
122inline void Material::addShaderDefineInternal(const ShaderType type, const string& define, bool addPrefix)
123{
124 ModuleDefines& defines = _extraShaderDefines[to_base(type)];
125
126 if (!eastl::any_of(eastl::cbegin(defines),
127 eastl::cend(defines),
128 [&define, addPrefix](const ModuleDefine& it)
129 {
130 return it._addPrefix == addPrefix &&
131 it._define.compare(define.c_str()) == 0;
132 }))
133 {
134 defines.emplace_back(define, addPrefix);
135 }
136}
137
138inline const ModuleDefines& Material::shaderDefines(const ShaderType type) const
139{
140 assert(type != ShaderType::COUNT);
141 return _extraShaderDefines[to_base(type)];
142}
143
144}; //namespace Divide
145
146#endif //DVD_MATERIAL_INL_
Handle< Texture > getTexture(TextureSlot textureUsage) const
Definition: Material.inl:68
SharedMutex _textureLock
Definition: Material.h:374
void unlockInstancesForWrite() const noexcept
Definition: Material.inl:52
bool hasTransparency() const noexcept
Definition: Material.inl:74
const TextureInfo & getTextureInfo(TextureSlot usage) const
Definition: Material.inl:117
void addShaderDefine(ShaderType type, const string &define, bool addPrefix)
Definition: Material.inl:102
void lockInstancesForRead() const noexcept
Definition: Material.inl:37
std::array< TextureInfo, to_base(TextureSlot::COUNT)> _textures
Definition: Material.h:379
void addShaderDefineInternal(ShaderType type, const string &define, bool addPrefix)
Definition: Material.inl:122
vector< Handle< Material > > _instances
Definition: Material.h:377
bool isReflective() const noexcept
Definition: Material.inl:80
SharedMutex _instanceLock
Definition: Material.h:376
std::array< ModuleDefines, to_base(ShaderType::COUNT)> _extraShaderDefines
Definition: Material.h:373
ShaderProgramInfo & shaderInfo(RenderStagePass renderStagePass)
Definition: Material.inl:92
bool isRefractive() const noexcept
Definition: Material.inl:86
StatePassesPerStage< ShaderProgramInfo > _shaderInfo
Definition: Material.h:370
const ModuleDefines & shaderDefines(ShaderType type) const
Definition: Material.inl:138
const vector< Handle< Material > > & getInstancesLocked() const noexcept
Definition: Material.inl:57
const vector< Handle< Material > > & getInstances() const
Definition: Material.inl:62
void lockInstancesForWrite() const noexcept
Definition: Material.inl:47
void unlockInstancesForRead() const noexcept
Definition: Material.inl:42
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U32 to_U32(const T value)
uint8_t U8
vector< ModuleDefine > ModuleDefines
eastl::vector< Type > vector
Definition: Vector.h:42
std::shared_lock< mutex > SharedLock
Definition: SharedMutex.h:49
constexpr U8 to_U8(const T value)
ShaderType
Available shader stages.
TextureSlot
Definition: Material.h:76
constexpr auto to_base(const Type value) -> Type
RenderPassType _passType