Diligent Engine  v.2.4.g
RenderDeviceGLImpl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 #include <memory>
31 
32 #include "EngineGLImplTraits.hpp"
33 #include "RenderDeviceBase.hpp"
34 #include "GLContext.hpp"
35 #include "VAOCache.hpp"
36 #include "BaseInterfacesGL.h"
37 #include "FBOCache.hpp"
38 #include "TexRegionRender.hpp"
39 
40 namespace Diligent
41 {
42 
44 // RenderDeviceGLESImpl is inherited from RenderDeviceGLImpl
45 class RenderDeviceGLImpl : public RenderDeviceBase<EngineGLImplTraits>
46 {
47 public:
49 
51  IMemoryAllocator& RawMemAllocator,
52  IEngineFactory* pEngineFactory,
53  const EngineGLCreateInfo& InitAttribs,
54  const SwapChainDesc* pSCDesc = nullptr) noexcept(false);
56 
57  virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override;
58 
60  void CreateBuffer(const BufferDesc& BuffDesc,
61  const BufferData* pBuffData,
62  IBuffer** ppBuffer,
63  bool bIsDeviceInternal);
64  virtual void DILIGENT_CALL_TYPE CreateBuffer(const BufferDesc& BuffDesc,
65  const BufferData* BuffData,
66  IBuffer** ppBuffer) override final;
67 
70  IShader** ppShader,
71  bool bIsDeviceInternal);
73  IShader** ppShader) override final;
74 
76  void CreateTexture(const TextureDesc& TexDesc,
77  const TextureData* pData,
78  ITexture** ppTexture,
79  bool bIsDeviceInternal);
80  virtual void DILIGENT_CALL_TYPE CreateTexture(const TextureDesc& TexDesc,
81  const TextureData* Data,
82  ITexture** ppTexture) override final;
83 
86  ISampler** ppSampler,
87  bool bIsDeviceInternal);
89  ISampler** ppSampler) override final;
90 
93  IPipelineState** ppPipelineState) override final;
94 
97  IPipelineState** ppPipelineState) override final;
98 
101  IPipelineState** ppPipelineState) override final;
102 
104  IPipelineState** ppPipelineState,
105  bool bIsDeviceInternal);
107  IPipelineState** ppPipelineState,
108  bool bIsDeviceInternal);
109 
111  virtual void DILIGENT_CALL_TYPE CreateFence(const FenceDesc& Desc, IFence** ppFence) override final;
112 
114  virtual void DILIGENT_CALL_TYPE CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) override final;
115 
117  virtual void DILIGENT_CALL_TYPE CreateRenderPass(const RenderPassDesc& Desc,
118  IRenderPass** ppRenderPass) override final;
119 
121  virtual void DILIGENT_CALL_TYPE CreateFramebuffer(const FramebufferDesc& Desc,
122  IFramebuffer** ppFramebuffer) override final;
123 
125  virtual void DILIGENT_CALL_TYPE CreateBLAS(const BottomLevelASDesc& Desc,
126  IBottomLevelAS** ppBLAS) override final;
127 
129  virtual void DILIGENT_CALL_TYPE CreateTLAS(const TopLevelASDesc& Desc,
130  ITopLevelAS** ppTLAS) override final;
131 
133  virtual void DILIGENT_CALL_TYPE CreateSBT(const ShaderBindingTableDesc& Desc,
134  IShaderBindingTable** ppSBT) override final;
135 
138  IPipelineResourceSignature** ppSignature) override final;
139 
141  IPipelineResourceSignature** ppSignature,
142  bool IsDeviceInternal);
143 
146  Uint32 GLBindTarget,
147  const TextureDesc& TexDesc,
148  RESOURCE_STATE InitialState,
149  ITexture** ppTexture) override final;
150 
152  virtual void DILIGENT_CALL_TYPE CreateBufferFromGLHandle(Uint32 GLHandle,
153  const BufferDesc& BuffDesc,
154  RESOURCE_STATE InitialState,
155  IBuffer** ppBuffer) override final;
156 
158  virtual void DILIGENT_CALL_TYPE CreateDummyTexture(const TextureDesc& TexDesc,
159  RESOURCE_STATE InitialState,
160  ITexture** ppTexture) override final;
161 
163  virtual void DILIGENT_CALL_TYPE ReleaseStaleResources(bool ForceRelease = false) override final {}
164 
166  virtual void DILIGENT_CALL_TYPE IdleGPU() override final;
167 
168  FBOCache& GetFBOCache(GLContext::NativeGLContextType Context);
169  void OnReleaseTexture(ITexture* pTexture);
170 
171  VAOCache& GetVAOCache(GLContext::NativeGLContextType Context);
173  void OnDestroyBuffer(BufferGLImpl& Buffer);
174 
175  size_t GetCommandQueueCount() const { return 1; }
176  Uint64 GetCommandQueueMask() const { return Uint64{1}; }
177 
178  void InitTexRegionRender();
179 
181  {
186  };
187  const DeviceLimits& GetDeviceLimits() const { return m_DeviceLimits; }
188 
189 protected:
190  friend class DeviceContextGLImpl;
191  friend class TextureBaseGL;
192  friend class PipelineStateGLImpl;
193  friend class ShaderGLImpl;
194  friend class BufferGLImpl;
195  friend class TextureViewGLImpl;
196  friend class SwapChainGLImpl;
197  friend class GLContextState;
198 
199  // Must be the first member because its constructor initializes OpenGL
201 
202  std::unordered_set<String> m_ExtensionStrings;
203 
205  std::unordered_map<GLContext::NativeGLContextType, VAOCache> m_VAOCache;
206 
208  std::unordered_map<GLContext::NativeGLContextType, FBOCache> m_FBOCache;
209 
210  std::unique_ptr<TexRegionRender> m_pTexRegionRender;
211 
212 private:
213  virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final;
214  bool CheckExtension(const Char* ExtensionString);
215  void FlagSupportedTexFormats();
216 
217  int m_ShowDebugGLOutput = 1;
218 
219  DeviceLimits m_DeviceLimits = {};
220 };
221 
222 } // namespace Diligent
Diligent::RenderDeviceGLImpl::CreatePipelineResourceSignature
virtual void CreatePipelineResourceSignature(const PipelineResourceSignatureDesc &Desc, IPipelineResourceSignature **ppSignature) override final
Implementation of IRenderDevice::CreatePipelineResourceSignature() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:773
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::ShaderGLImpl
Shader object implementation in OpenGL backend.
Definition: ShaderGLImpl.hpp:39
Diligent::GraphicsPipelineStateCreateInfo
Graphics pipeline state creation attributes.
Definition: PipelineState.h:397
Diligent::Char
char Char
Definition: BasicTypes.h:64
Diligent::RenderDeviceGLImpl::m_ExtensionStrings
std::unordered_set< String > m_ExtensionStrings
Definition: RenderDeviceGLImpl.hpp:202
Diligent::SamplerDesc
Sampler description.
Definition: Sampler.h:58
Diligent::RenderDeviceGLImpl::CreateComputePipelineState
virtual void CreateComputePipelineState(const ComputePipelineStateCreateInfo &PSOCreateInfo, IPipelineState **ppPipelineState) override final
Implementation of IRenderDevice::CreateComputePipelineState() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:738
Diligent::ISampler
Texture sampler interface.
Definition: Sampler.h:192
Diligent::RayTracingPipelineStateCreateInfo
Ray tracing pipeline state description.
Definition: PipelineState.h:443
Diligent::IPipelineResourceSignature
Pipeline resource signature interface.
Definition: PipelineResourceSignature.h:226
Diligent::RenderDeviceGLImpl::GetVAOCache
VAOCache & GetVAOCache(GLContext::NativeGLContextType Context)
Definition: RenderDeviceGLImpl.cpp:1278
Diligent::PipelineResourceSignatureDesc
Pipeline resource signature description.
Definition: PipelineResourceSignature.h:166
Diligent::IShaderBindingTable
Shader binding table interface.
Definition: ShaderBindingTable.h:93
Diligent::TopLevelASDesc
Top-level AS description.
Definition: TopLevelAS.h:49
Diligent::IPipelineState
Pipeline state interface.
Definition: PipelineState.h:505
Diligent::QueryDesc
Query description.
Definition: Query.h:150
ThreadingTools::LockFlag
Definition: LockHelper.hpp:36
Diligent::RenderDeviceGLImpl::CreateBLAS
virtual void CreateBLAS(const BottomLevelASDesc &Desc, IBottomLevelAS **ppBLAS) override final
Implementation of IRenderDevice::CreateBLAS() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:786
Diligent::RenderDeviceGLImpl::DeviceLimits::MaxUniformBlocks
GLint MaxUniformBlocks
Definition: RenderDeviceGLImpl.hpp:182
Diligent::TextureViewGLImpl
Texture view implementation in OpenGL backend.
Definition: TextureViewGLImpl.hpp:38
Diligent::IShader
Shader interface.
Definition: Shader.h:428
Diligent::RenderDeviceGLImpl::CreateFence
virtual void CreateFence(const FenceDesc &Desc, IFence **ppFence) override final
Implementation of IRenderDevice::CreateFence() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:749
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
Diligent::Uint64
uint64_t Uint64
64-bit unsigned integer
Definition: BasicTypes.h:50
Diligent::DeviceContextGLImpl
Device context implementation in OpenGL backend.
Definition: DeviceContextGLImpl.hpp:51
Diligent::FBOCache
Definition: FBOCache.hpp:42
Diligent::RenderDeviceGLImpl::TestTextureFormat
virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final
Definition: RenderDeviceGLImpl.cpp:1037
Diligent::ITopLevelAS
Top-level AS interface.
Definition: TopLevelAS.h:151
Diligent::RenderDeviceGLImpl::m_FBOCacheLockFlag
ThreadingTools::LockFlag m_FBOCacheLockFlag
Definition: RenderDeviceGLImpl.hpp:207
Diligent::RenderDeviceGLImpl::CreateRayTracingPipelineState
virtual void CreateRayTracingPipelineState(const RayTracingPipelineStateCreateInfo &PSOCreateInfo, IPipelineState **ppPipelineState) override final
Implementation of IRenderDevice::CreateRayTracingPipelineState() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:743
Diligent::IFramebuffer
Framebuffer interface.
Definition: Framebuffer.h:73
Diligent::RenderDeviceGLImpl::GetDeviceLimits
const DeviceLimits & GetDeviceLimits() const
Definition: RenderDeviceGLImpl.hpp:187
Diligent::RenderDeviceGLImpl::CreateTexture
void CreateTexture(const TextureDesc &TexDesc, const TextureData *pData, ITexture **ppTexture, bool bIsDeviceInternal)
Implementation of IRenderDevice::CreateTexture() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:575
Diligent::RenderPassDesc
Render pass description.
Definition: RenderPass.h:341
Diligent::RenderDeviceGLImpl::GetCommandQueueMask
Uint64 GetCommandQueueMask() const
Definition: RenderDeviceGLImpl.hpp:176
Diligent::RenderDeviceGLImpl::GetFBOCache
FBOCache & GetFBOCache(GLContext::NativeGLContextType Context)
Definition: RenderDeviceGLImpl.cpp:1265
Diligent::RenderDeviceGLImpl::CreateTLAS
virtual void CreateTLAS(const TopLevelASDesc &Desc, ITopLevelAS **ppTLAS) override final
Implementation of IRenderDevice::CreateTLAS() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:793
Diligent::RenderDeviceGLImpl::m_GLContext
GLContext m_GLContext
Definition: RenderDeviceGLImpl.hpp:200
Diligent::RenderDeviceGLImpl::ReleaseStaleResources
virtual void ReleaseStaleResources(bool ForceRelease=false) override final
Implementation of IRenderDevice::ReleaseStaleResources() in OpenGL backend.
Definition: RenderDeviceGLImpl.hpp:163
Diligent::ShaderCreateInfo
Shader creation attributes.
Definition: Shader.h:241
Diligent::RenderDeviceGLImpl::CreateGraphicsPipelineState
virtual void CreateGraphicsPipelineState(const GraphicsPipelineStateCreateInfo &PSOCreateInfo, IPipelineState **ppPipelineState) override final
Implementation of IRenderDevice::CreateGraphicsPipelineState() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:733
Diligent::INTERFACE_ID
Unique interface identifier.
Definition: InterfaceID.h:37
Diligent::IBuffer
Buffer interface.
Definition: Buffer.h:187
BaseInterfacesGL.h
RenderDeviceBase.hpp
Diligent::RenderDeviceGLImpl::m_VAOCacheLockFlag
ThreadingTools::LockFlag m_VAOCacheLockFlag
Definition: RenderDeviceGLImpl.hpp:204
Diligent::RenderDeviceGLImpl::QueryInterface
virtual void QueryInterface(const INTERFACE_ID &IID, IObject **ppInterface) override
Diligent::ShaderBindingTableDesc
Shader binding table description.
Definition: ShaderBindingTable.h:50
Diligent::VAOCache
Definition: VAOCache.hpp:47
Diligent::RenderDeviceGLImpl::CreateBuffer
void CreateBuffer(const BufferDesc &BuffDesc, const BufferData *pBuffData, IBuffer **ppBuffer, bool bIsDeviceInternal)
Implementation of IRenderDevice::CreateBuffer() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:541
Diligent::RenderDeviceGLImpl::CreateDummyTexture
virtual void CreateDummyTexture(const TextureDesc &TexDesc, RESOURCE_STATE InitialState, ITexture **ppTexture) override final
Implementation of IRenderDeviceGL::CreateDummyTexture().
Definition: RenderDeviceGLImpl.cpp:691
Diligent::TextureDesc
Texture description.
Definition: Texture.h:47
Diligent::RenderDeviceGLImpl::CreateQuery
virtual void CreateQuery(const QueryDesc &Desc, IQuery **ppQuery) override final
Implementation of IRenderDevice::CreateQuery() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:754
Diligent::RenderDeviceGLImpl::DeviceLimits::MaxTextureUnits
GLint MaxTextureUnits
Definition: RenderDeviceGLImpl.hpp:183
Diligent::RenderDeviceGLImpl::CreateRenderPass
virtual void CreateRenderPass(const RenderPassDesc &Desc, IRenderPass **ppRenderPass) override final
Implementation of IRenderDevice::CreateRenderPass() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:759
VAOCache.hpp
Diligent::RenderDeviceGLImpl::CreateTextureFromGLHandle
virtual void CreateTextureFromGLHandle(Uint32 GLHandle, Uint32 GLBindTarget, const TextureDesc &TexDesc, RESOURCE_STATE InitialState, ITexture **ppTexture) override final
Implementation of IRenderDeviceGL::CreateTextureFromGLHandle().
Definition: RenderDeviceGLImpl.cpp:636
Diligent::RenderDeviceGLImpl::OnReleaseTexture
void OnReleaseTexture(ITexture *pTexture)
Definition: RenderDeviceGLImpl.cpp:1271
Diligent::RenderDeviceGLImpl::m_pTexRegionRender
std::unique_ptr< TexRegionRender > m_pTexRegionRender
Definition: RenderDeviceGLImpl.hpp:210
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::TextureData
Describes the initial data to store in the texture.
Definition: Texture.h:221
Diligent::RenderDeviceGLImpl::OnDestroyBuffer
void OnDestroyBuffer(BufferGLImpl &Buffer)
Definition: RenderDeviceGLImpl.cpp:1291
Diligent::ComputePipelineStateCreateInfo
Compute pipeline state description.
Definition: PipelineState.h:427
Diligent::PipelineStateGLImpl
Pipeline state object implementation in OpenGL backend.
Definition: PipelineStateGLImpl.hpp:45
Diligent::TextureBaseGL
Base implementation of a texture object in OpenGL backend.
Definition: TextureBaseGL.hpp:41
Diligent::SwapChainDesc
Swap chain description.
Definition: GraphicsTypes.h:1347
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::RenderDeviceGLImpl::CreateSampler
void CreateSampler(const SamplerDesc &SamplerDesc, ISampler **ppSampler, bool bIsDeviceInternal)
Implementation of IRenderDevice::CreateSampler() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:713
Diligent::RenderDeviceGLImpl::GetCommandQueueCount
size_t GetCommandQueueCount() const
Definition: RenderDeviceGLImpl.hpp:175
Diligent::RenderDeviceGLImpl::CreateBufferFromGLHandle
virtual void CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc &BuffDesc, RESOURCE_STATE InitialState, IBuffer **ppBuffer) override final
Implementation of IRenderDeviceGL::CreateBufferFromGLHandle().
Definition: RenderDeviceGLImpl.cpp:554
Diligent::GLContext
Definition: GLContextAndroid.hpp:36
Diligent::EngineGLCreateInfo
Attributes of the OpenGL-based engine implementation.
Definition: GraphicsTypes.h:2015
Diligent::SwapChainGLImpl
Swap chain implementation in OpenGL backend.
Definition: SwapChainGLImpl.hpp:38
Diligent::RenderDeviceGLImpl::CreateSBT
virtual void CreateSBT(const ShaderBindingTableDesc &Desc, IShaderBindingTable **ppSBT) override final
Implementation of IRenderDevice::CreateSBT() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:800
Diligent::RenderDeviceGLImpl
Render device implementation in OpenGL backend.
Definition: RenderDeviceGLImpl.hpp:45
Diligent::RenderDeviceGLImpl::OnDestroyPSO
void OnDestroyPSO(PipelineStateGLImpl &PSO)
Definition: RenderDeviceGLImpl.cpp:1284
Diligent::BufferGLImpl
Buffer object implementation in OpenGL backend.
Definition: BufferGLImpl.hpp:41
Diligent::RenderDeviceGLImpl::DeviceLimits
Definition: RenderDeviceGLImpl.hpp:180
Diligent::TEXTURE_FORMAT
TEXTURE_FORMAT
Texture formats.
Definition: GraphicsTypes.h:328
EngineGLImplTraits.hpp
Diligent::RenderDeviceGLImpl::IdleGPU
virtual void IdleGPU() override final
Implementation of IRenderDevice::IdleGPU() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:1298
Diligent::BufferDesc
Buffer description.
Definition: Buffer.h:74
Diligent::RenderDeviceGLImpl::RenderDeviceGLImpl
RenderDeviceGLImpl(IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, IEngineFactory *pEngineFactory, const EngineGLCreateInfo &InitAttribs, const SwapChainDesc *pSCDesc=nullptr) noexcept(false)
Definition: RenderDeviceGLImpl.cpp:136
Diligent::IMemoryAllocator
Base interface for a raw memory allocator.
Definition: MemoryAllocator.h:41
Diligent::RenderDeviceGLImpl::InitTexRegionRender
void InitTexRegionRender()
Definition: RenderDeviceGLImpl.cpp:536
GLContext.hpp
FBOCache.hpp
Diligent::IFence
Fence interface.
Definition: Fence.h:62
Diligent::RenderDeviceGLImpl::CreateShader
void CreateShader(const ShaderCreateInfo &ShaderCreateInfo, IShader **ppShader, bool bIsDeviceInternal)
Implementation of IRenderDevice::CreateShader() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:565
Diligent::RenderDeviceGLImpl::DeviceLimits::MaxStorageBlock
GLint MaxStorageBlock
Definition: RenderDeviceGLImpl.hpp:184
Diligent::IQuery
Query interface.
Definition: Query.h:177
Diligent::FramebufferDesc
Framebuffer description.
Definition: Framebuffer.h:46
Diligent::GLContextState
Definition: GLContextState.hpp:39
Diligent::IBottomLevelAS
Bottom-level AS interface.
Definition: BottomLevelAS.h:207
TexRegionRender.hpp
Diligent::RenderDeviceGLImpl::DeviceLimits::MaxImagesUnits
GLint MaxImagesUnits
Definition: RenderDeviceGLImpl.hpp:185
Diligent::RenderDeviceGLImpl::m_VAOCache
std::unordered_map< GLContext::NativeGLContextType, VAOCache > m_VAOCache
Definition: RenderDeviceGLImpl.hpp:205
Diligent::RESOURCE_STATE
RESOURCE_STATE
Resource usage state.
Definition: GraphicsTypes.h:2814
Diligent::BufferData
Describes the buffer initial data.
Definition: Buffer.h:155
Diligent::BottomLevelASDesc
Bottom-level AS description.
Definition: BottomLevelAS.h:145
Diligent::RenderDeviceGLImpl::CreateFramebuffer
virtual void CreateFramebuffer(const FramebufferDesc &Desc, IFramebuffer **ppFramebuffer) override final
Implementation of IRenderDevice::CreateFramebuffer() in OpenGL backend.
Definition: RenderDeviceGLImpl.cpp:764
Diligent::IEngineFactory
Engine factory base interface.
Definition: EngineFactory.h:60
Diligent::FenceDesc
Fence description.
Definition: Fence.h:43
Diligent::RenderDeviceGLImpl::m_FBOCache
std::unordered_map< GLContext::NativeGLContextType, FBOCache > m_FBOCache
Definition: RenderDeviceGLImpl.hpp:208
Diligent::ITexture
Texture inteface.
Definition: Texture.h:273
Diligent::IRenderPass
Render pass interface.
Definition: RenderPass.h:369
Diligent::RenderDeviceBase
Base implementation of a render device.
Definition: RenderDeviceBase.hpp:185
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37