Berserk
GLCommandList.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_GLCOMMANDLIST_HPP
29 #define BERSERK_GLCOMMANDLIST_HPP
30 
31 #include <rhi/RHICommandList.hpp>
32 #include <rhi/RHIDefs.hpp>
33 #include <rhi/opengl/GLDefs.hpp>
38 
39 #include <array>
40 
42 
52 class GLCommandList final : public RHICommandList {
53 public:
54  BRK_API GLCommandList() = default;
55  BRK_API ~GLCommandList() override = default;
56 
57  BRK_API void UpdateVertexBuffer(const Ref<RHIVertexBuffer> &buffer, uint32 byteOffset, uint32 byteSize, const Ref<Data> &data) override;
58  BRK_API void UpdateIndexBuffer(const Ref<RHIIndexBuffer> &buffer, uint32 byteOffset, uint32 byteSize, const Ref<Data> &data) override;
59  BRK_API void UpdateUniformBuffer(const Ref<RHIUniformBuffer> &buffer, uint32 byteOffset, uint32 byteSize, const Ref<Data> &data) override;
60  BRK_API void UpdateTexture2D(const Ref<RHITexture> &texture, uint32 mipLevel, const Rect2u &region, const Ref<Data> &data) override;
61  BRK_API void UpdateTexture2DArray(const Ref<RHITexture> &texture, uint32 arrayIndex, uint32 mipLevel, const Rect2u &region, const Ref<Data> &data) override;
62  BRK_API void UpdateTextureCube(const Ref<RHITexture> &texture, RHITextureCubemapFace face, uint32 mipLevel, const Rect2u &region, const Ref<Data> &data) override;
63  BRK_API void GenerateMipMaps(const Ref<RHITexture> &texture) override;
64 
65  BRK_API void BeginRenderPass(const Ref<RHIRenderPass> &renderPass, const RHIRenderPassBeginInfo &beginInfo) override;
66  BRK_API void BindGraphicsPipeline(const Ref<RHIGraphicsPipeline> &pipeline) override;
67  BRK_API void BindVertexBuffers(const std::vector<Ref<RHIVertexBuffer>> &buffers) override;
68  BRK_API void BindIndexBuffer(const Ref<RHIIndexBuffer> &buffer, RHIIndexType indexType) override;
69  BRK_API void BindResourceSet(const Ref<RHIResourceSet> &resourceSet, uint32 set) override;
70  BRK_API void Draw(uint32 verticesCount, uint32 baseVertex, uint32 instancesCount) override;
71  BRK_API void DrawIndexed(uint32 indexCount, uint32 baseVertex, uint32 instanceCount) override;
72  BRK_API void EndRenderPass() override;
73 
74  BRK_API void SwapBuffers(const Ref<Window> &window) override;
75  BRK_API void Submit() override;
76 
77 private:
78  void PipelineCleanUp();
79 
80 private:
81  GLResourceBindingState mResourceBindingState;
82  GLRenderPassStateVars mStateVars;
83  GLVaoCache mVaoCache;
84 
85  std::array<Ref<GLResourceSet>, RHILimits::MAX_RESOURCE_SETS> mSets;
86  Ref<GLGraphicsPipeline> mGraphicsPipeline;
87  Ref<GLRenderPass> mRenderPass;
88  Ref<GLShader> mShader;
89  GLVaoDescriptor mVaoDesc;
90  GLuint mCurrentVao = GL_NONE;
91  GLenum mIndexType = GL_NONE;
92  GLenum mPrimitivesType = GL_NONE;
93 
94  bool mInRenderPass = false;
95  bool mPipelineBound = false;
96  bool mNeedUpdateVao = true;
97 
98  size_t mSubmitCount = 0;
99 };
100 
106 
107 #endif//BERSERK_GLCOMMANDLIST_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint32_t uint32
Definition: Typedefs.hpp:44
GL command list implementation (wrapper for context)
Definition: GLCommandList.hpp:52
BRK_API void BindVertexBuffers(const std::vector< Ref< RHIVertexBuffer >> &buffers) override
Definition: GLCommandList.cpp:115
BRK_API void BindResourceSet(const Ref< RHIResourceSet > &resourceSet, uint32 set) override
Definition: GLCommandList.cpp:134
BRK_API void BindIndexBuffer(const Ref< RHIIndexBuffer > &buffer, RHIIndexType indexType) override
Definition: GLCommandList.cpp:125
BRK_API void SwapBuffers(const Ref< Window > &window) override
Definition: GLCommandList.cpp:182
BRK_API void GenerateMipMaps(const Ref< RHITexture > &texture) override
Definition: GLCommandList.cpp:83
BRK_API void DrawIndexed(uint32 indexCount, uint32 baseVertex, uint32 instanceCount) override
Definition: GLCommandList.cpp:158
BRK_API void UpdateIndexBuffer(const Ref< RHIIndexBuffer > &buffer, uint32 byteOffset, uint32 byteSize, const Ref< Data > &data) override
Definition: GLCommandList.cpp:49
BRK_API GLCommandList()=default
BRK_API void BindGraphicsPipeline(const Ref< RHIGraphicsPipeline > &pipeline) override
Definition: GLCommandList.cpp:100
BRK_API void UpdateVertexBuffer(const Ref< RHIVertexBuffer > &buffer, uint32 byteOffset, uint32 byteSize, const Ref< Data > &data) override
Definition: GLCommandList.cpp:45
BRK_API void Submit() override
Definition: GLCommandList.cpp:189
BRK_API void BeginRenderPass(const Ref< RHIRenderPass > &renderPass, const RHIRenderPassBeginInfo &beginInfo) override
Definition: GLCommandList.cpp:91
BRK_API void UpdateTextureCube(const Ref< RHITexture > &texture, RHITextureCubemapFace face, uint32 mipLevel, const Rect2u &region, const Ref< Data > &data) override
Definition: GLCommandList.cpp:78
BRK_API void UpdateUniformBuffer(const Ref< RHIUniformBuffer > &buffer, uint32 byteOffset, uint32 byteSize, const Ref< Data > &data) override
Definition: GLCommandList.cpp:53
BRK_API void EndRenderPass() override
Definition: GLCommandList.cpp:173
BRK_API void UpdateTexture2D(const Ref< RHITexture > &texture, uint32 mipLevel, const Rect2u &region, const Ref< Data > &data) override
Definition: GLCommandList.cpp:68
BRK_API ~GLCommandList() override=default
BRK_API void Draw(uint32 verticesCount, uint32 baseVertex, uint32 instancesCount) override
Definition: GLCommandList.cpp:143
BRK_API void UpdateTexture2DArray(const Ref< RHITexture > &texture, uint32 arrayIndex, uint32 mipLevel, const Rect2u &region, const Ref< Data > &data) override
Definition: GLCommandList.cpp:73
Auxiliary class used to bind textures and samplers to pipeline.
Definition: GLResourceSet.hpp:48
Cache of opengl vertex array objects.
Definition: GLVaoCache.hpp:119
Command list for commands capturing and submission.
Definition: RHICommandList.hpp:54
RHI pass info to begin (initial targets clear values)
Definition: RHIRenderPass.hpp:100
Generic vector class for an N dimensional space base on type T.
Definition: TVecN.hpp:55
RHITextureCubemapFace
Definition: RHIDefs.hpp:177
RHIIndexType
Definition: RHIDefs.hpp:57
Definition: GLDevice.cpp:46
GL render pass shared state variables for context management.
Definition: GLRenderPass.hpp:45
Descriptor of vertex array object.
Definition: GLVaoCache.hpp:51
static const uint32 MAX_RESOURCE_SETS
Definition: RHIDefs.hpp:341