Berserk
Shader.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of Berserk Engine project */
3 /* https://github.com/EgorOrachyov/Berserk */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2018 - 2021 Egor Orachyov */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef BERSERK_SHADER_HPP
29 #define BERSERK_SHADER_HPP
30 
31 #include <core/Config.hpp>
32 #include <core/Typedefs.hpp>
37 
38 #include <unordered_set>
39 #include <vector>
40 
42 
53 
58 struct ShaderOption {
61 };
62 
67 class ShaderCompileOptions final : public RefCnt {
68 public:
70  BRK_API ~ShaderCompileOptions() override = default;
71 
72  BRK_API void Set(const StringName &option) { mValues.emplace(option); }
73  BRK_API bool IsSet(const StringName &option) const { return mValues.find(option) != mValues.end(); }
74  BRK_API void Clear() { mValues.clear(); }
75  BRK_API size_t GetCount() const { return mValues.size(); }
76  BRK_API const std::unordered_set<StringName> &Get() const { return mValues; }
77 
78 private:
79  std::unordered_set<StringName> mValues;
80 };
81 
86 class Shader final : public RefCnt {
87 public:
88  BRK_API Shader() = default;
89  BRK_API ~Shader() override = default;
90 
91  BRK_API void SetName(StringName name);
92  BRK_API void SetArchetype(StringName archetype);
93  BRK_API void SetLoadPath(String loadPath);
94  BRK_API void SetDescription(String description);
95  BRK_API void SetVariation(ShaderVariation variation);
96  BRK_API void SetFormat(MeshFormat format);
98  BRK_API void SetTechniques(std::vector<Ref<ShaderTechnique>> techniques);
99  BRK_API void SetAllOptions(std::vector<ShaderOption> options);
100  BRK_API void SetParams(Ref<ShaderParams> params);
101 
104  BRK_API Ref<const ShaderTechnique> FindFirstTechnique(const ShaderTechniqueTags &tags, bool mustBeCompiled = true) const;
105  BRK_API size_t GetTechniquesCount() const { return mTechniques.size(); }
106 
107  BRK_API const StringName &GetName() const { return mName; }
108  BRK_API const StringName &GetArchetype() const { return mArchetype; }
109  BRK_API const String &GetLoadPath() const { return mLoadPath; }
110  BRK_API const String &GetDescription() const { return mDescription; }
111  BRK_API const ShaderVariation &GetVariation() const { return mVariation; }
112  BRK_API const MeshFormat &GetFormat() const { return mFormat; }
113  BRK_API const std::vector<Ref<ShaderTechnique>> &GetTechniques() const { return mTechniques; }
114  BRK_API const std::vector<ShaderOption> &GetAllOptions() const { return mAllOptions; }
115  BRK_API const Ref<ShaderParams> &GetParams() const { return mParams; }
116  BRK_API const Ref<ShaderCompileOptions> &GetOptions() const { return mOptions; }
117 
118 private:
119  StringName mName;
120  StringName mArchetype;
121  String mLoadPath;
122  String mDescription;
123  ShaderVariation mVariation = 0;
124  MeshFormat mFormat;
126  std::vector<Ref<ShaderTechnique>> mTechniques;
127  std::vector<ShaderOption> mAllOptions;
129  Ref<ShaderParams> mParams;
130  Ref<ShaderCompileOptions> mOptions;
131 };
132 
138 
139 #endif//BERSERK_SHADER_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint32_t uint32
Definition: Typedefs.hpp:44
Mask defining mesh format (composed from attributes)
Reference counted base object.
Definition: RefCnt.hpp:52
Options passed to compile shader.
Definition: Shader.hpp:67
BRK_API size_t GetCount() const
Definition: Shader.hpp:75
BRK_API void Clear()
Definition: Shader.hpp:74
BRK_API ShaderCompileOptions()=default
BRK_API ~ShaderCompileOptions() override=default
BRK_API void Set(const StringName &option)
Definition: Shader.hpp:72
BRK_API const std::unordered_set< StringName > & Get() const
Definition: Shader.hpp:76
BRK_API bool IsSet(const StringName &option) const
Definition: Shader.hpp:73
Describes variation of compiled shader of the single type (max 64 flags)
Defines complete rendering flow for the object.
Definition: Shader.hpp:86
BRK_API void SetOptions(Ref< ShaderCompileOptions > options)
Definition: Shader.cpp:56
BRK_API const Ref< ShaderParams > & GetParams() const
Definition: Shader.hpp:115
BRK_API Ref< const ShaderTechnique > FindFirstTechnique(const ShaderTechniqueTags &tags, bool mustBeCompiled=true) const
Definition: Shader.cpp:84
BRK_API void SetLoadPath(String loadPath)
Definition: Shader.cpp:40
BRK_API ~Shader() override=default
BRK_API void SetArchetype(StringName archetype)
Definition: Shader.cpp:36
BRK_API void SetVariation(ShaderVariation variation)
Definition: Shader.cpp:48
BRK_API void SetAllOptions(std::vector< ShaderOption > options)
Definition: Shader.cpp:64
BRK_API Ref< const ShaderTechnique > GetTechnique(const StringName &name) const
Definition: Shader.cpp:72
BRK_API const Ref< ShaderCompileOptions > & GetOptions() const
Definition: Shader.hpp:116
BRK_API const std::vector< ShaderOption > & GetAllOptions() const
Definition: Shader.hpp:114
BRK_API const ShaderVariation & GetVariation() const
Definition: Shader.hpp:111
BRK_API void SetName(StringName name)
Definition: Shader.cpp:32
BRK_API void SetDescription(String description)
Definition: Shader.cpp:44
BRK_API Shader()=default
BRK_API void SetTechniques(std::vector< Ref< ShaderTechnique >> techniques)
Definition: Shader.cpp:60
BRK_API size_t GetTechniquesCount() const
Definition: Shader.hpp:105
BRK_API const StringName & GetName() const
Definition: Shader.hpp:107
BRK_API void SetParams(Ref< ShaderParams > params)
Definition: Shader.cpp:68
BRK_API const String & GetLoadPath() const
Definition: Shader.hpp:109
BRK_API const MeshFormat & GetFormat() const
Definition: Shader.hpp:112
BRK_API const StringName & GetArchetype() const
Definition: Shader.hpp:108
BRK_API void SetFormat(MeshFormat format)
Definition: Shader.cpp:52
BRK_API const String & GetDescription() const
Definition: Shader.hpp:110
BRK_API const std::vector< Ref< ShaderTechnique > > & GetTechniques() const
Definition: Shader.hpp:113
Cached shared utf-8 string id.
Definition: StringName.hpp:61
Utf-8 encoded std based default string class.
Definition: GLDevice.cpp:46
Single option exposed by the shader.
Definition: Shader.hpp:58
String description
Definition: Shader.hpp:60
StringName name
Definition: Shader.hpp:59