7 #ifndef NAZARA_MATERIAL_HPP 8 #define NAZARA_MATERIAL_HPP 10 #include <Nazara/Prerequesites.hpp> 11 #include <Nazara/Core/Color.hpp> 12 #include <Nazara/Core/ObjectLibrary.hpp> 13 #include <Nazara/Core/ObjectRef.hpp> 14 #include <Nazara/Core/RefCounted.hpp> 15 #include <Nazara/Core/Resource.hpp> 16 #include <Nazara/Core/ResourceLoader.hpp> 17 #include <Nazara/Core/ResourceManager.hpp> 18 #include <Nazara/Core/ResourceParameters.hpp> 19 #include <Nazara/Core/Signal.hpp> 20 #include <Nazara/Core/String.hpp> 21 #include <Nazara/Graphics/Config.hpp> 22 #include <Nazara/Graphics/Enums.hpp> 23 #include <Nazara/Graphics/MaterialPipeline.hpp> 24 #include <Nazara/Renderer/Texture.hpp> 25 #include <Nazara/Renderer/TextureSampler.hpp> 26 #include <Nazara/Renderer/UberShader.hpp> 30 struct NAZARA_GRAPHICS_API MaterialParams : ResourceParameters
32 bool loadAlphaMap =
true;
33 bool loadDiffuseMap =
true;
34 bool loadEmissiveMap =
true;
35 bool loadHeightMap =
true;
36 bool loadNormalMap =
true;
37 bool loadSpecularMap =
true;
38 String shaderName =
"Basic";
45 using MaterialConstRef = ObjectRef<const Material>;
46 using MaterialLibrary = ObjectLibrary<Material>;
47 using MaterialLoader = ResourceLoader<Material, MaterialParams>;
48 using MaterialManager = ResourceManager<Material, MaterialParams>;
49 using MaterialRef = ObjectRef<Material>;
53 friend MaterialLibrary;
61 inline Material(
const MaterialPipelineInfo& pipelineInfo);
66 void Apply(
const MaterialPipeline::Instance& instance)
const;
68 void BuildFromParameters(
const ParameterList& matData,
const MaterialParams& matParams = MaterialParams());
71 inline void Configure(
const MaterialPipelineInfo& pipelineInfo);
72 inline bool Configure(
const String& pipelineName);
74 inline void EnableAlphaTest(
bool alphaTest);
75 inline void EnableBlending(
bool blending);
76 inline void EnableColorWrite(
bool colorWrite);
77 inline void EnableDepthBuffer(
bool depthBuffer);
78 inline void EnableDepthSorting(
bool depthSorting);
79 inline void EnableDepthWrite(
bool depthWrite);
80 inline void EnableFaceCulling(
bool faceCulling);
81 inline void EnableReflectionMapping(
bool reflection);
82 inline void EnableScissorTest(
bool scissorTest);
83 inline void EnableShadowCasting(
bool castShadows);
84 inline void EnableShadowReceive(
bool receiveShadows);
85 inline void EnableStencilTest(
bool stencilTest);
87 inline void EnsurePipelineUpdate()
const;
90 inline float GetAlphaThreshold()
const;
91 inline Color GetAmbientColor()
const;
92 inline RendererComparison GetDepthFunc()
const;
94 inline Color GetDiffuseColor()
const;
95 inline const TextureRef& GetDiffuseMap()
const;
96 inline TextureSampler& GetDiffuseSampler();
97 inline const TextureSampler& GetDiffuseSampler()
const;
98 inline BlendFunc GetDstBlend()
const;
99 inline const TextureRef& GetEmissiveMap()
const;
100 inline FaceSide GetFaceCulling()
const;
101 inline FaceFilling GetFaceFilling()
const;
102 inline const TextureRef& GetHeightMap()
const;
103 inline float GetLineWidth()
const;
104 inline const TextureRef& GetNormalMap()
const;
106 inline const MaterialPipelineInfo& GetPipelineInfo()
const;
107 inline float GetPointSize()
const;
108 inline ReflectionMode GetReflectionMode()
const;
109 inline const UberShader* GetShader()
const;
110 inline float GetShininess()
const;
111 inline Color GetSpecularColor()
const;
112 inline const TextureRef& GetSpecularMap()
const;
113 inline TextureSampler& GetSpecularSampler();
114 inline const TextureSampler& GetSpecularSampler()
const;
115 inline BlendFunc GetSrcBlend()
const;
117 inline bool HasAlphaMap()
const;
118 inline bool HasDepthMaterial()
const;
119 inline bool HasDiffuseMap()
const;
120 inline bool HasEmissiveMap()
const;
121 inline bool HasHeightMap()
const;
122 inline bool HasNormalMap()
const;
123 inline bool HasSpecularMap()
const;
125 inline bool IsAlphaTestEnabled()
const;
126 inline bool IsBlendingEnabled()
const;
127 inline bool IsColorWriteEnabled()
const;
128 inline bool IsDepthBufferEnabled()
const;
129 inline bool IsDepthSortingEnabled()
const;
130 inline bool IsDepthWriteEnabled()
const;
131 inline bool IsFaceCullingEnabled()
const;
132 inline bool IsReflectionMappingEnabled()
const;
133 inline bool IsScissorTestEnabled()
const;
134 inline bool IsStencilTestEnabled()
const;
135 inline bool IsShadowCastingEnabled()
const;
136 inline bool IsShadowReceiveEnabled()
const;
138 inline bool LoadFromFile(
const String& filePath,
const MaterialParams& params = MaterialParams());
139 inline bool LoadFromMemory(
const void* data, std::size_t size,
const MaterialParams& params = MaterialParams());
140 inline bool LoadFromStream(
Stream& stream,
const MaterialParams& params = MaterialParams());
146 inline bool SetAlphaMap(
const String& textureName);
148 inline void SetAlphaThreshold(
float alphaThreshold);
149 inline void SetAmbientColor(
const Color& ambient);
150 inline void SetDepthFunc(RendererComparison depthFunc);
151 inline void SetDepthMaterial(
MaterialRef depthMaterial);
152 inline void SetDiffuseColor(
const Color& diffuse);
153 inline bool SetDiffuseMap(
const String& textureName);
154 inline void SetDiffuseMap(
TextureRef diffuseMap);
155 inline void SetDiffuseSampler(
const TextureSampler& sampler);
156 inline void SetDstBlend(BlendFunc func);
157 inline bool SetEmissiveMap(
const String& textureName);
158 inline void SetEmissiveMap(
TextureRef textureName);
159 inline void SetFaceCulling(FaceSide faceSide);
160 inline void SetFaceFilling(FaceFilling filling);
161 inline bool SetHeightMap(
const String& textureName);
162 inline void SetHeightMap(
TextureRef textureName);
163 inline void SetLineWidth(
float lineWidth);
164 inline bool SetNormalMap(
const String& textureName);
165 inline void SetNormalMap(
TextureRef textureName);
166 inline void SetPointSize(
float pointSize);
167 inline void SetReflectionMode(ReflectionMode reflectionMode);
169 inline bool SetShader(
const String& uberShaderName);
170 inline void SetShininess(
float shininess);
171 inline void SetSpecularColor(
const Color& specular);
172 inline bool SetSpecularMap(
const String& textureName);
173 inline void SetSpecularMap(
TextureRef specularMap);
174 inline void SetSpecularSampler(
const TextureSampler& sampler);
175 inline void SetSrcBlend(BlendFunc func);
180 inline static int GetTextureUnit(TextureMap textureMap);
181 template<
typename... Args>
static MaterialRef New(Args&&... args);
184 NazaraSignal(OnMaterialReflectionModeChange,
const Material* , ReflectionMode );
185 NazaraSignal(OnMaterialRelease,
const Material* );
186 NazaraSignal(OnMaterialReset,
const Material* );
189 void Copy(
const Material& material);
190 inline void InvalidatePipeline();
191 inline void UpdatePipeline()
const;
193 static bool Initialize();
194 static void Uninitialize();
196 Color m_ambientColor;
197 Color m_diffuseColor;
198 Color m_specularColor;
201 MaterialPipelineInfo m_pipelineInfo;
202 ReflectionMode m_reflectionMode;
203 TextureSampler m_diffuseSampler;
204 TextureSampler m_specularSampler;
211 mutable bool m_pipelineUpdated;
212 bool m_shadowCastingEnabled;
213 float m_alphaThreshold;
215 unsigned int m_reflectionSize;
217 static std::array<int, TextureMap_Max + 1> s_textureUnits;
218 static MaterialLibrary::LibraryMap s_library;
219 static MaterialLoader::LoaderList s_loaders;
220 static MaterialManager::ManagerMap s_managerMap;
221 static MaterialManager::ManagerParams s_managerParameters;
226 #include <Nazara/Graphics/Material.inl> 228 #endif // NAZARA_MATERIAL_HPP Core class that represents a color.
Definition: Color.hpp:18
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents the module initializer of Graphics.
Definition: Graphics.hpp:15
Core class that represents a string.
Definition: String.hpp:22
decltype(auto) Apply(F &&fn, Tuple &&t)
Applies the tuple to the function (e.g. calls the function using the tuple content as arguments) ...
Definition: Algorithm.inl:48
Core class that represents a loader of resources.
Definition: ResourceLoader.hpp:23
Core class that represents a resource.
Definition: Resource.hpp:15
Core class that represents a reference with a counter.
Definition: RefCounted.hpp:21
Graphics class that represents a material.
Definition: Material.hpp:51
Core class that represents a list of parameters.
Definition: ParameterList.hpp:18
Core class that represents a resource manager.
Definition: ResourceManager.hpp:18
Graphics class used to contains all rendering states that are not allowed to change individually on r...
Definition: MaterialPipeline.hpp:44
Core class that represents a stream.
Definition: Stream.hpp:19