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 "Importer/BsImportOptions.h"
7
8namespace bs
9{
10 /** @addtogroup Importer
11 * @{
12 */
13
14 /** Supported types of low-level shading languages. */
15 enum class BS_SCRIPT_EXPORT(m:Importer,n:ShadingLanguageFlags,api:bsf,api:bed) ShadingLanguageFlag
16 {
17 /** High level shading language used by DirectX backend. */
18 HLSL = 1 << 0,
19 /** OpenGL shading language. */
20 GLSL = 1 << 1,
21 /** Variant of GLSL used for Vulkan. */
22 VKSL = 1 << 2,
23 /** Metal shading language. */
24 MSL = 1 << 3,
25 /** Helper entry that includes all languages. */
26 All = HLSL | GLSL | VKSL | MSL
27 };
28
29 using ShadingLanguageFlags = Flags<ShadingLanguageFlag>;
30 BS_FLAGS_OPERATORS(ShadingLanguageFlag)
31
32 /** Contains import options you may use to control how is a shader imported. */
33 class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Importer,api:bsf,api:bed) ShaderImportOptions : public ImportOptions
34 {
35 public:
36 /**
37 * Sets a define and its value. Replaces an existing define if one already exists with the provided name.
38 *
39 * @param[in] define Name of the define.
40 * @param[in] value Value to assign to the define.
41 */
42 BS_SCRIPT_EXPORT()
43 void setDefine(const String& define, const String& value)
44 {
45 mDefines[define] = value;
46 }
47
48 /**
49 * Checks if the define exists and returns its value if it does.
50 *
51 * @param[in] define Name of the define to get the value for.
52 * @param[out] value value of the define. Only defined if the method returns true.
53 * @returns True if the define was found, false otherwise.
54 */
55 BS_SCRIPT_EXPORT()
56 bool getDefine(const String& define, String& value) const
57 {
58 auto iterFind = mDefines.find(define);
59 if(iterFind != mDefines.end())
60 {
61 value = iterFind->second;
62 return true;
63 }
64
65 return false;
66 }
67
68 /**
69 * Checks if the provided define exists.
70 *
71 * @param[in] define Name of the define to check.
72 * @returns True if the define was found, false otherwise.
73 */
74 BS_SCRIPT_EXPORT()
75 bool hasDefine(const String& define) const
76 {
77 auto iterFind = mDefines.find(define);
78 return iterFind != mDefines.end();
79 }
80
81 /**
82 * Unregisters a previously set define.
83 *
84 * @param[in] define Name of the define to unregister.
85 */
86 BS_SCRIPT_EXPORT()
87 void removeDefine(const String& define)
88 {
89 mDefines.erase(define);
90 }
91
92 /** Returns all the set defines and their values. */
93 const UnorderedMap<String, String>& getDefines() const { return mDefines; }
94
95 /**
96 * Flags that control which shading languages should the BSL shader be converted into. This ultimately controls on
97 * which render backends it will be able to run on.
98 */
99 BS_SCRIPT_EXPORT()
100 ShadingLanguageFlags languages = ShadingLanguageFlag::All;
101
102 /************************************************************************/
103 /* SERIALIZATION */
104 /************************************************************************/
105 public:
106 friend class ShaderImportOptionsRTTI;
107 static RTTITypeBase* getRTTIStatic();
108 RTTITypeBase* getRTTI() const override;
109
110 private:
111 UnorderedMap<String, String> mDefines;
112 };
113
114 /** @} */
115}