Diligent Engine API Reference
RenderDeviceGLImpl.h
1 /* Copyright 2015-2018 Egor Yusov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12  *
13  * In no event and under no legal theory, whether in tort (including negligence),
14  * contract, or otherwise, unless required by applicable law (such as deliberate
15  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16  * liable for any damages, including any direct, indirect, special, incidental,
17  * or consequential damages of any character arising as a result of this License or
18  * out of the use or inability to use the software (including but not limited to damages
19  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20  * all other commercial damages or losses), even if such Contributor has been advised
21  * of the possibility of such damages.
22  */
23 
24 #pragma once
25 
26 #include "RenderDeviceBase.h"
27 #include "GLContext.h"
28 #include "VAOCache.h"
29 #include "BaseInterfacesGL.h"
30 #include "FBOCache.h"
31 #include "TexRegionRender.h"
32 
33 enum class GPU_VENDOR
34 {
35  UNKNOWN,
36  INTEL,
37  ATI,
38  NVIDIA
39 };
40 
41 struct GPUInfo
42 {
43  GPU_VENDOR Vendor;
44  GPUInfo() :
45  Vendor( GPU_VENDOR::UNKNOWN )
46  {}
47 };
48 
49 namespace Diligent
50 {
51 
53 class RenderDeviceGLImpl : public RenderDeviceBase<IGLDeviceBaseInterface>
54 {
55 public:
57 
58  RenderDeviceGLImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const ContextInitInfo &InitInfo );
60  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
61 
62  void CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBufferLayout, bool bIsDeviceInternal);
63  virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBufferLayout)override final;
64 
65  void CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader, bool bIsDeviceInternal );
66  virtual void CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader)override final;
67 
68  void CreateTexture(const TextureDesc& TexDesc, const TextureData &Data, ITexture **ppTexture, bool bIsDeviceInternal);
69  virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData &Data, ITexture **ppTexture)override final;
70 
71  void CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler, bool bIsDeviceInternal);
72  virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler)override final;
73 
74  void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState, bool bIsDeviceInternal);
75  virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState )override final;
76 
77  virtual void CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc &TexDesc, ITexture **ppTexture)override final;
78 
79  virtual void CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc &BuffDesc, IBuffer **ppBuffer)override final;
80 
81  const GPUInfo& GetGPUInfo(){ return m_GPUInfo; }
82 
83  FBOCache& GetFBOCache(GLContext::NativeGLContextType Context);
84  void OnReleaseTexture(ITexture *pTexture);
85 
86  VAOCache& GetVAOCache(GLContext::NativeGLContextType Context);
87  void OnDestroyPSO(IPipelineState *pPSO);
88  void OnDestroyBuffer(IBuffer *pBuffer);
89 
90 protected:
91  friend class DeviceContextGLImpl;
92  friend class TextureBaseGL;
93  friend class PipelineStateGLImpl;
94  friend class ShaderGLImpl;
95  friend class BufferGLImpl;
96  friend class TextureViewGLImpl;
97  friend class SwapChainGLImpl;
98  friend class GLContextState;
99 
100  // Must be the first member because its constructor initializes OpenGL
101  GLContext m_GLContext;
102 
103  std::unordered_set<String> m_ExtensionStrings;
104 
105  ThreadingTools::LockFlag m_VAOCacheLockFlag;
106  std::unordered_map<GLContext::NativeGLContextType, VAOCache> m_VAOCache;
107 
108  ThreadingTools::LockFlag m_FBOCacheLockFlag;
109  std::unordered_map<GLContext::NativeGLContextType, FBOCache> m_FBOCache;
110 
111  GPUInfo m_GPUInfo;
112 
113  TexRegionRender m_TexRegionRender;
114 
115 private:
116  virtual void TestTextureFormat( TEXTURE_FORMAT TexFormat )override;
117  bool CheckExtension(const Char *ExtensionString);
118  void FlagSupportedTexFormats();
119  void QueryDeviceCaps();
120 };
121 
122 }
TEXTURE_FORMAT
Texture formats.
Definition: GraphicsTypes.h:244
Base implementation of the Diligent::ITextureGL interface.
Definition: TextureBaseGL.h:41
Texture description.
Definition: Texture.h:82
Implementation of the Diligent::IShaderGL interface.
Definition: ShaderGLImpl.h:67
Shader interface.
Definition: Shader.h:288
Describes the buffer initial data.
Definition: Buffer.h:176
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Implementation of the Diligent::IDeviceContextGL interface.
Definition: DeviceContextGLImpl.h:35
Implementation of the Diligent::ITextureViewGL interface.
Definition: TextureViewGLImpl.h:37
Implementation of the render device interface in OpenGL.
Definition: RenderDeviceGLImpl.h:53
Implementation of the Diligent::IPipelineStateGL interface.
Definition: PipelineStateGLImpl.h:39
Describes the initial data to store in the texture.
Definition: Texture.h:243
Sampler description.
Definition: Sampler.h:52
Buffer interface.
Definition: Buffer.h:200
Base implementation of a render device.
Definition: DeviceObjectBase.h:36
Buffer description.
Definition: Buffer.h:57
Implementation of the Diligent::IBufferGL interface.
Definition: BufferGLImpl.h:40
Definition: PipelineState.h:209
Texture sampler interface.
Definition: Sampler.h:180
Pipeline state description.
Definition: PipelineState.h:179
Implementation of the Diligent::ISwapChainGL interface.
Definition: SwapChainGLImpl.h:34
Shader creation attributes.
Definition: Shader.h:204
Texture inteface.
Definition: Texture.h:276