Berserk
ShaderArchetype.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_SHADERARCHETYPE_HPP
29 #define BERSERK_SHADERARCHETYPE_HPP
30 
31 #include <core/Config.hpp>
32 #include <core/Typedefs.hpp>
34 #include <render/shader/Shader.hpp>
35 
37 
48 public:
50  BRK_API void AddOption(const StringName &option) {
51  auto find = mOptions.find(option);
52  if (find == mOptions.end()) mOptions[option] = mNextOption++;
53  }
54 
57  auto find = mOptions.find(option);
58  if (find != mOptions.end()) return find->second;
59  return mOptions[option] = mNextOption++;
60  }
61 
63  BRK_API bool IsRegistered(const StringName &option) {
64  auto find = mOptions.find(option);
65  return find != mOptions.end();
66  }
67 
68 private:
69  std::unordered_map<StringName, uint32> mOptions;
70  uint32 mNextOption = 0;
71 };
72 
78 public:
80  static constexpr const char *const SHADER_PARAMS_BLOCK = BRK_TEXT("ShaderParams");
81 
83  struct InputData {
90  };
91 
93  struct OutputData {
94  bool failed = false;
99  };
100 
101  BRK_API virtual ~ShaderArchetype() = default;
102  BRK_API virtual const StringName &GetArchetype() const = 0;
103  BRK_API virtual const std::vector<RHIShaderLanguage> &GetSupportedLanguages() const = 0;
104  BRK_API virtual bool IsSupportedLanguage(RHIShaderLanguage language) const;
105  BRK_API virtual void DefineOptions(std::vector<ShaderOption> &options) const = 0;
106  BRK_API virtual void DefineVariation(const ShaderCompileOptions &options, ShaderVariation &variation) = 0;
107  BRK_API virtual void DefineFormat(const ShaderCompileOptions &options, MeshFormat &format) = 0;
108  BRK_API virtual void Process(const InputData &inputData, OutputData &outputData) = 0;
109 };
110 
116 
117 #endif//BERSERK_SHADERARCHETYPE_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_TEXT(text)
Definition: Config.hpp:53
#define BRK_API
Definition: Config.hpp:32
std::uint32_t uint32
Definition: Typedefs.hpp:44
Mask defining mesh format (composed from attributes)
Handles source code pre-processing of shaders with this archetype.
Definition: ShaderArchetype.hpp:77
virtual BRK_API void DefineFormat(const ShaderCompileOptions &options, MeshFormat &format)=0
virtual BRK_API ~ShaderArchetype()=default
virtual BRK_API const std::vector< RHIShaderLanguage > & GetSupportedLanguages() const =0
virtual BRK_API void DefineOptions(std::vector< ShaderOption > &options) const =0
virtual BRK_API void Process(const InputData &inputData, OutputData &outputData)=0
virtual BRK_API void DefineVariation(const ShaderCompileOptions &options, ShaderVariation &variation)=0
virtual BRK_API bool IsSupportedLanguage(RHIShaderLanguage language) const
Definition: ShaderArchetype.cpp:34
static constexpr const char *const SHADER_PARAMS_BLOCK
Definition: ShaderArchetype.hpp:80
virtual BRK_API const StringName & GetArchetype() const =0
Options passed to compile shader.
Definition: Shader.hpp:67
Assist in building variation key from options.
Definition: ShaderArchetype.hpp:47
BRK_API uint32 GetOption(const StringName &option)
Definition: ShaderArchetype.hpp:56
BRK_API void AddOption(const StringName &option)
Definition: ShaderArchetype.hpp:50
BRK_API bool IsRegistered(const StringName &option)
Definition: ShaderArchetype.hpp:63
Describes variation of compiled shader of the single type (max 64 flags)
Cached shared utf-8 string id.
Definition: StringName.hpp:61
Utf-8 encoded std based default string class.
RHIShaderLanguage
Definition: RHIDefs.hpp:127
Definition: GLDevice.cpp:46
Processing input data.
Definition: ShaderArchetype.hpp:83
String fragmentCode
Definition: ShaderArchetype.hpp:87
uint32 passIndex
Definition: ShaderArchetype.hpp:88
String vertexCode
Definition: ShaderArchetype.hpp:86
Ref< ShaderParams > params
Definition: ShaderArchetype.hpp:85
RHIShaderLanguage language
Definition: ShaderArchetype.hpp:89
Ref< ShaderCompileOptions > options
Definition: ShaderArchetype.hpp:84
Processing output data.
Definition: ShaderArchetype.hpp:93
bool failed
Definition: ShaderArchetype.hpp:94
RHIShaderLanguage language
Definition: ShaderArchetype.hpp:96
String fragmentCode
Definition: ShaderArchetype.hpp:98
String vertexCode
Definition: ShaderArchetype.hpp:97
String error
Definition: ShaderArchetype.hpp:95