Berserk
ShaderParams.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_SHADERPARAMS_HPP
29 #define BERSERK_SHADERPARAMS_HPP
30 
31 #include <core/Config.hpp>
32 #include <core/Typedefs.hpp>
34 #include <rhi/RHIDefs.hpp>
35 
36 #include <unordered_map>
37 #include <vector>
38 
40 
50 enum class ShaderParamType : uint8 {
52  Texture,
54  Data,
56  Unknown
57 };
58 
63 struct ShaderParam {
75  uint32 info = 0xffffffff;
82 };
83 
88 class ShaderParams final : public RefCnt {
89 public:
90  static const uint32 INVALID_ID = 0xffffffff;
91 
94  uint32 info = 0xffffffff;
99  };
100 
102  struct DataParamInfo {
105  };
106 
110  };
111 
113  BRK_API explicit ShaderParams(std::vector<ShaderParam> params);
114  BRK_API ~ShaderParams() override = default;
115 
117  BRK_API bool HasParam(const StringName &name) const;
118 
119  BRK_API uint32 GetParamId(const StringName &name) const;
120  BRK_API const ShaderParam *GetParam(const StringName &name) const;
121  BRK_API const ShaderParamLight *GetParamLight(const StringName &name) const;
122  BRK_API const ShaderParam &GetParam(uint32 id) const;
123  BRK_API const ShaderParamLight &GetParamLight(uint32 id) const;
124 
126  BRK_API const std::unordered_map<StringName, uint32> &GetParamLookUp() const { return mParamLookUp; }
128  BRK_API const std::vector<ShaderParam> &GetParams() const { return mParams; }
130  BRK_API const std::vector<ShaderParamLight> &GetParamsLight() const { return mParamsLight; }
132  BRK_API const std::vector<DataParamInfo> &GetDataParamsInfo() const { return mDataParamsInfo; }
134  BRK_API const std::vector<TextureParamInfo> &GetTextureParamsInfo() const { return mTextureParamsInfo; }
136  BRK_API const std::vector<unsigned char> &GetDefaultDataValues() const { return mDefaultDataValues; }
137 
139  uint32 GetDataSize() const { return mDataSize; }
141  uint32 GetTexturesCount() const { return mTexturesCount; }
142 
143 protected:
145  void Build();
147  void InitDefaults();
148 
149 private:
150  std::unordered_map<StringName, uint32> mParamLookUp;
151  std::vector<ShaderParam> mParams;
152  std::vector<ShaderParamLight> mParamsLight;
153  std::vector<DataParamInfo> mDataParamsInfo;
154  std::vector<TextureParamInfo> mTextureParamsInfo;
155  std::vector<unsigned char> mDefaultDataValues;
156  uint32 mDataSize = 0;
157  uint32 mTexturesCount = 0;
158 };
159 
161 
162 #endif//BERSERK_SHADERPARAMS_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint8_t uint8
Definition: Typedefs.hpp:38
std::uint32_t uint32
Definition: Typedefs.hpp:44
Reference counted base object.
Definition: RefCnt.hpp:52
General types of shader params.
Describes layout of shader params for packing by material.
Definition: ShaderParams.hpp:88
Cached shared utf-8 string id.
Definition: StringName.hpp:61
Utf-8 encoded std based default string class.
String defaultValue
Definition: ShaderParams.hpp:71
static const uint32 INVALID_ID
Definition: ShaderParams.hpp:90
uint32 offset
Definition: ShaderParams.hpp:109
void Build()
Definition: ShaderParams.cpp:71
BRK_API const std::vector< DataParamInfo > & GetDataParamsInfo() const
Definition: ShaderParams.hpp:132
BRK_API const std::vector< unsigned char > & GetDefaultDataValues() const
Definition: ShaderParams.hpp:136
BRK_API bool HasParam(const StringName &name) const
Definition: ShaderParams.cpp:42
BRK_API const ShaderParamLight * GetParamLight(const StringName &name) const
Definition: ShaderParams.cpp:56
uint32 GetDataSize() const
Definition: ShaderParams.hpp:139
ShaderParamType type
Definition: ShaderParams.hpp:96
BRK_API const std::vector< TextureParamInfo > & GetTextureParamsInfo() const
Definition: ShaderParams.hpp:134
RHIShaderDataType typeData
Definition: ShaderParams.hpp:79
StringName uiName
Definition: ShaderParams.hpp:67
BRK_API const ShaderParam * GetParam(const StringName &name) const
Definition: ShaderParams.cpp:51
void InitDefaults()
Definition: ShaderParams.cpp:128
uint32 offset
Definition: ShaderParams.hpp:103
ShaderParamType type
Definition: ShaderParams.hpp:77
uint32 info
Definition: ShaderParams.hpp:94
BRK_API ~ShaderParams() override=default
BRK_API const std::vector< ShaderParamLight > & GetParamsLight() const
Definition: ShaderParams.hpp:130
BRK_API const std::unordered_map< StringName, uint32 > & GetParamLookUp() const
Definition: ShaderParams.hpp:126
uint32 size
Definition: ShaderParams.hpp:104
uint32 info
Definition: ShaderParams.hpp:75
RHIShaderParamType typeParam
Definition: ShaderParams.hpp:81
BRK_API ShaderParams(std::vector< ShaderParam > params)
Definition: ShaderParams.cpp:37
uint32 GetTexturesCount() const
Definition: ShaderParams.hpp:141
StringName name
Definition: ShaderParams.hpp:65
String description
Definition: ShaderParams.hpp:69
uint32 arraySize
Definition: ShaderParams.hpp:95
uint32 arraySize
Definition: ShaderParams.hpp:73
RHIShaderDataType typeData
Definition: ShaderParams.hpp:97
RHIShaderParamType typeParam
Definition: ShaderParams.hpp:98
BRK_API const std::vector< ShaderParam > & GetParams() const
Definition: ShaderParams.hpp:128
BRK_API uint32 GetParamId(const StringName &name) const
Definition: ShaderParams.cpp:46
RHIShaderParamType
Definition: RHIDefs.hpp:106
RHIShaderDataType
Definition: RHIDefs.hpp:83
Definition: GLDevice.cpp:46
Describes single param in the shader.
Definition: ShaderParams.hpp:63
Info about raw data param.
Definition: ShaderParams.hpp:102
Definition: ShaderParams.hpp:93
Info about texture data param.
Definition: ShaderParams.hpp:108