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 "BsCorePrerequisites.h"
6#include "Utility/BsModule.h"
7
8namespace bs
9{
10 /** @addtogroup Material-Internal
11 * @{
12 */
13
14 /**
15 * Interface that provides a method for finding a shader include resource based on the name of the include that was
16 * provided in a shader file.
17 */
18 class BS_CORE_EXPORT IShaderIncludeHandler
19 {
20 public:
21 virtual ~IShaderIncludeHandler() = default;
22
23 /** Attempts to find a shader include resource based on its name. */
24 virtual HShaderInclude findInclude(const String& name) const = 0;
25
26 /** Registers a path in which to look for shader include files, along the default places. */
27 virtual void addSearchPath(const Path& path) { }
28 };
29
30 /**
31 * Implements shader include finding by converting the shader include name into a path that the resource will be loaded
32 * from.
33 */
34 class BS_CORE_EXPORT DefaultShaderIncludeHandler : public IShaderIncludeHandler
35 {
36 public:
37 /** @copydoc IShaderIncludeHandler::findInclude */
38 HShaderInclude findInclude(const String& name) const override;
39 };
40
41 /** A global manager that handles various shader specific operations. */
42 class BS_CORE_EXPORT ShaderManager : public Module <ShaderManager>
43 {
44 public:
45 ShaderManager(const SPtr<IShaderIncludeHandler>& handler) { mIncludeHandler = handler; }
46
47 /**
48 * Attempts to find a shader include based on the include name.
49 *
50 * @note
51 * The name is usually a path to the resource relative to the working folder, but can be other things depending on
52 * active handler.
53 */
54 HShaderInclude findInclude(const String& name) const;
55
56 /** Changes the active include handler that determines how is a shader include name mapped to the actual resource. */
57 void setIncludeHandler(const SPtr<IShaderIncludeHandler>& handler) { mIncludeHandler = handler; }
58
59 /** Registers a path in which to look for shader include files, along the default places. */
60 void addSearchPath(const Path& path);
61 private:
62 SPtr<IShaderIncludeHandler> mIncludeHandler;
63 };
64
65 /** @} */
66}