1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsPrerequisites.h"
6#include "Utility/BsModule.h"
7
8namespace bs
9{
10 /** @addtogroup Renderer-Engine-Internal
11 * @{
12 */
13
14 namespace ct
15 {
16 class RendererMaterialBase;
17 struct RendererMaterialMetaData;
18 }
19
20 /** Initializes and handles all renderer materials. */
21 class BS_EXPORT RendererMaterialManager : public Module<RendererMaterialManager>
22 {
23 /** Information used for initializing a renderer material managed by this module. */
24 struct RendererMaterialData
25 {
26 ct::RendererMaterialMetaData* metaData;
27 const Path shaderPath;
28 };
29
30 public:
31 RendererMaterialManager();
32 ~RendererMaterialManager();
33
34 /** Registers a new material that should be initialized on module start-up. */
35 static void _registerMaterial(ct::RendererMaterialMetaData* metaData, const char* shaderPath);
36
37 /** Returns a set of defines to be used when importing the shader. */
38 static ShaderDefines _getDefines(const Path& shaderPath);
39 private:
40 template<class T>
41 friend class RendererMaterial;
42 friend class ct::RendererMaterialBase;
43
44 /** Initializes all materials on the core thread. */
45 static void initOnCore(const Vector<SPtr<ct::Shader>>& shaders);
46
47 /** Destroys all materials on the core thread. */
48 static void destroyOnCore();
49
50 /** Returns a list in which are all materials managed by this module. */
51 static Vector<RendererMaterialData>& getMaterials();
52
53 /** Returns a mutex used for inter-thread access to the materials list. */
54 static Mutex& getMutex();
55 };
56
57 /** @} */
58}