Berserk
GLResourceSet.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_GLRESOURCESET_HPP
29 #define BERSERK_GLRESOURCESET_HPP
30 
31 #include <rhi/RHIResourceSet.hpp>
32 #include <rhi/opengl/GLDefs.hpp>
33 #include <rhi/opengl/GLShader.hpp>
34 
35 #include <unordered_map>
36 
38 
49 public:
50  BRK_API uint32 GetSlot(uint32 location);
51  BRK_API void Clear();
52 
53 private:
54  static const uint32 UNUSED_SLOT = 0xffffffff;
55  struct Slot {
56  uint32 index = UNUSED_SLOT;
57  };
58 
59 private:
60  std::unordered_map<uint32, Slot> mBoundSlots;
61  uint32 mNextSlot = 0;
62 };
63 
68 class GLResourceSet final : public RHIResourceSet {
69 public:
73 
74  BRK_API explicit GLResourceSet(const RHIResourceSetDesc &desc);
75  BRK_API ~GLResourceSet() override = default;
76 
77  BRK_API void Update(const RHIResourceSetDesc &desc);
78  BRK_API void Bind(GLResourceBindingState &state, const Ref<GLShader> &shader) const;
79 
80  const std::vector<TextureBinding> &GetTextures() const { return mTextures; }
81  const std::vector<SamplerBinding> &GetSamplers() const { return mSamplers; }
82  const std::vector<BufferBinding> &GetBuffers() const { return mBuffers; }
83 
84 private:
85  std::vector<TextureBinding> mTextures;
86  std::vector<SamplerBinding> mSamplers;
87  std::vector<BufferBinding> mBuffers;
88 };
89 
95 
96 #endif//BERSERK_GLRESOURCESET_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint32_t uint32
Definition: Typedefs.hpp:44
Auxiliary class used to bind textures and samplers to pipeline.
Definition: GLResourceSet.hpp:48
BRK_API void Clear()
Definition: GLResourceSet.cpp:43
BRK_API uint32 GetSlot(uint32 location)
Definition: GLResourceSet.cpp:37
GL set of pipeline resources.
Definition: GLResourceSet.hpp:68
BRK_API void Bind(GLResourceBindingState &state, const Ref< GLShader > &shader) const
Definition: GLResourceSet.cpp:58
BRK_API GLResourceSet(const RHIResourceSetDesc &desc)
Definition: GLResourceSet.cpp:48
BRK_API void Update(const RHIResourceSetDesc &desc)
Definition: GLResourceSet.cpp:52
const std::vector< TextureBinding > & GetTextures() const
Definition: GLResourceSet.hpp:80
BRK_API ~GLResourceSet() override=default
const std::vector< BufferBinding > & GetBuffers() const
Definition: GLResourceSet.hpp:82
const std::vector< SamplerBinding > & GetSamplers() const
Definition: GLResourceSet.hpp:81
Describes single set of GPU resource for shader.
Definition: RHIResourceSet.hpp:52
Set of resource ready to be bound to the pipeline.
Definition: RHIResourceSet.hpp:111
Definition: GLDevice.cpp:46
Definition: RHIResourceSet.hpp:66
Definition: RHIResourceSet.hpp:60
Definition: RHIResourceSet.hpp:54