Berserk
ShaderCompiler.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_SHADERCOMPILER_HPP
29 #define BERSERK_SHADERCOMPILER_HPP
30 
31 #include <render/shader/Shader.hpp>
32 
33 #include <tinyxml2.hpp>
34 
36 
46 class ShaderCompiler final {
47 public:
53  };
54 
55  BRK_API ShaderCompiler() = default;
56  BRK_API ~ShaderCompiler() = default;
57 
68  BRK_API CompilationResult Compile(const String &filepath, const Ref<ShaderCompileOptions> &options);
69 
70 private:
71  bool ParseShader(tinyxml2::XMLElement *element);
72  bool ParseOptions(tinyxml2::XMLElement *element);
73  bool ParseParams(tinyxml2::XMLElement *element);
74  bool ParseTechniques(tinyxml2::XMLElement *element);
75  bool ParseTechnique(tinyxml2::XMLElement *element);
76  bool ParsePass(tinyxml2::XMLElement *element);
77 
78  static bool ParseParamType(const char *typeName, ShaderParamType &type, RHIShaderDataType &dataType, RHIShaderParamType &paramType);
79 
80 private:
81  CompilationResult mResult;
82 
83  Ref<Shader> mShader;
85  Ref<ShaderParams> mParams;
86  Ref<ShaderTechnique> mTechnique;
87  Ref<ShaderPass> mPass;
88  std::vector<ShaderOption> mAllOptions;
89  std::shared_ptr<ShaderArchetype> mArchetype{};
90  uint32 mPassIndex{};
91 };
92 
98 
99 #endif//BERSERK_SHADERCOMPILER_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint32_t uint32
Definition: Typedefs.hpp:44
Responsible to compile shaders in engine .shader.xml format.
Definition: ShaderCompiler.hpp:46
BRK_API ~ShaderCompiler()=default
BRK_API ShaderCompiler()=default
BRK_API CompilationResult Compile(const String &filepath, const Ref< ShaderCompileOptions > &options)
Compile shader with specified full path and options.
Definition: ShaderCompiler.cpp:35
General types of shader params.
Utf-8 encoded std based default string class.
RHIShaderParamType
Definition: RHIDefs.hpp:106
RHIShaderDataType
Definition: RHIDefs.hpp:83
Definition: GLDevice.cpp:46
Compilation result.
Definition: ShaderCompiler.hpp:49
uint32 line
Definition: ShaderCompiler.hpp:51
Ref< Shader > shader
Definition: ShaderCompiler.hpp:52
String error
Definition: ShaderCompiler.hpp:50