Berserk
GLDevice.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_GLDEVICE_HPP
29 #define BERSERK_GLDEVICE_HPP
30 
31 #include <core/Thread.hpp>
32 #include <rhi/RHIDevice.hpp>
33 #include <rhi/opengl/GLDefs.hpp>
34 
35 #include <functional>
36 
38 
48 class GLDevice final : public RHIDevice {
49 public:
50  using MakeContextCurrentFunc = std::function<void(const Ref<Window> &)>;
51  using SwapBuffersFunc = std::function<void(const Ref<Window> &)>;
52 
53  BRK_API explicit GLDevice(MakeContextCurrentFunc makeCurrentFunc, SwapBuffersFunc swapBuffersFunc);
54  BRK_API ~GLDevice() override;
55 
64  BRK_API Ref<RHIShader> CreateShader(const RHIShaderDesc &desc) override;
68 
69  BRK_API void UpdateResourceSet_RT(const Ref<RHIResourceSet> &set, const RHIResourceSetDesc &desc) override;
70 
73 
85  BRK_API static std::shared_ptr<GLDevice> Make(MakeContextCurrentFunc makeCurrentFunc, SwapBuffersFunc swapBuffersFunc);
86 
87 private:
88  MakeContextCurrentFunc mMakeCurrentFunc;
89  SwapBuffersFunc mSwapBuffersFunc;
90  Thread *mRHIThread = nullptr;
91  Ref<class GLCommandList> mCoreCommandList;
92 };
93 
99 
100 #endif//BERSERK_GLDEVICE_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
GL device implementation.
Definition: GLDevice.hpp:48
BRK_API Ref< RHIShader > CreateShader(const RHIShaderDesc &desc) override
Definition: GLDevice.cpp:222
std::function< void(const Ref< Window > &)> SwapBuffersFunc
Definition: GLDevice.hpp:51
BRK_API Ref< RHIRenderPass > CreateRenderPass(const RHIRenderPassDesc &desc) override
Definition: GLDevice.cpp:226
static BRK_API std::shared_ptr< GLDevice > Make(MakeContextCurrentFunc makeCurrentFunc, SwapBuffersFunc swapBuffersFunc)
CreateFromImage GL RHI device.
Definition: GLDevice.cpp:254
BRK_API SwapBuffersFunc & GetSwapFunc()
Definition: GLDevice.cpp:250
BRK_API Ref< RHISampler > CreateSampler(const RHISamplerDesc &desc) override
Definition: GLDevice.cpp:206
BRK_API ~GLDevice() override
Definition: GLDevice.cpp:177
BRK_API Ref< RHIFramebuffer > CreateFramebuffer(const RHIFramebufferDesc &desc) override
Definition: GLDevice.cpp:218
BRK_API MakeContextCurrentFunc & GetContextFunc()
Definition: GLDevice.cpp:246
BRK_API GLDevice(MakeContextCurrentFunc makeCurrentFunc, SwapBuffersFunc swapBuffersFunc)
Definition: GLDevice.cpp:62
BRK_API Ref< RHICommandList > GetCoreCommandList() override
Definition: GLDevice.cpp:234
BRK_API Ref< RHIIndexBuffer > CreateIndexBuffer(const RHIBufferDesc &desc) override
Definition: GLDevice.cpp:198
BRK_API Ref< RHIVertexDeclaration > CreateVertexDeclaration(const RHIVertexDeclarationDesc &desc) override
Definition: GLDevice.cpp:190
BRK_API Ref< RHITexture > CreateTexture(const RHITextureDesc &desc) override
Definition: GLDevice.cpp:210
BRK_API Ref< RHIResourceSet > CreateResourceSet(const RHIResourceSetDesc &desc) override
Definition: GLDevice.cpp:214
BRK_API Ref< RHIUniformBuffer > CreateUniformBuffer(const RHIBufferDesc &desc) override
Definition: GLDevice.cpp:202
std::function< void(const Ref< Window > &)> MakeContextCurrentFunc
Definition: GLDevice.hpp:50
BRK_API void UpdateResourceSet_RT(const Ref< RHIResourceSet > &set, const RHIResourceSetDesc &desc) override
Definition: GLDevice.cpp:238
BRK_API Ref< RHIGraphicsPipeline > CreateGraphicsPipeline(const RHIGraphicsPipelineDesc &desc) override
Definition: GLDevice.cpp:230
BRK_API Ref< RHIVertexBuffer > CreateVertexBuffer(const RHIBufferDesc &desc) override
Definition: GLDevice.cpp:194
RHI device.
Definition: RHIDevice.hpp:67
Graphics pipeline descriptor.
Definition: RHIGraphicsPipeline.hpp:208
Full render pass descriptor.
Definition: RHIRenderPass.hpp:78
Describes single set of GPU resource for shader.
Definition: RHIResourceSet.hpp:52
Describes input vertex layout.
Represents thread wrapper used to enqueue commands to execute.
Definition: Thread.hpp:54
Definition: GLDevice.cpp:46
RHI device buffer descriptor.
Definition: RHIBuffer.hpp:46
RHI framebuffer descriptor.
Definition: RHIFramebuffer.hpp:61
RHI sample descriptor.
Definition: RHISampler.hpp:46
Shader creation descriptor. Allows create from byteCode.
Definition: RHIShader.hpp:127
RHI Texture primitive descriptor.
Definition: RHITexture.hpp:48