Diligent Engine  v.2.4.g
TextureBaseGL.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 "EngineGLImplTraits.hpp"
31 #include "TextureBase.hpp"
32 #include "TextureViewGLImpl.hpp" // Required by TextureBase
33 #include "GLObjectWrapper.hpp"
35 #include "GLContextState.hpp"
36 
37 namespace Diligent
38 {
39 
41 class TextureBaseGL : public TextureBase<EngineGLImplTraits>, public AsyncWritableResource
42 {
43 public:
46 
47  TextureBaseGL(IReferenceCounters* pRefCounters,
48  FixedBlockMemoryAllocator& TexViewObjAllocator,
49  RenderDeviceGLImpl* pDeviceGL,
50  const TextureDesc& TexDesc,
51  GLenum BindTarget,
52  const TextureData* pInitData = nullptr,
53  bool bIsDeviceInternal = false);
54 
55  TextureBaseGL(IReferenceCounters* pRefCounters,
56  FixedBlockMemoryAllocator& TexViewObjAllocator,
57  RenderDeviceGLImpl* pDeviceGL,
58  GLContextState& GLState,
59  const TextureDesc& TexDesc,
60  GLuint GLTextureHandle,
61  GLenum BindTarget,
62  bool bIsDeviceInternal);
63 
66  TextureBaseGL(IReferenceCounters* pRefCounters,
67  FixedBlockMemoryAllocator& TexViewObjAllocator,
68  RenderDeviceGLImpl* pDeviceGL,
69  const TextureDesc& TexDesc,
70  bool bIsDeviceInternal);
71 
73 
74  virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override;
75 
77 
79  virtual GLenum DILIGENT_CALL_TYPE GetBindTarget() const override final { return m_BindTarget; }
80 
81  GLenum GetGLTexFormat() const { return m_GLTexFormat; }
82 
83  __forceinline void TextureMemoryBarrier(MEMORY_BARRIER RequiredBarriers, class GLContextState& GLContextState);
84 
85  virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, GLenum AttachmentPoint) = 0;
86 
87  void CopyData(DeviceContextGLImpl* pDeviceCtxGL,
88  TextureBaseGL* pSrcTextureGL,
89  Uint32 SrcMipLevel,
90  Uint32 SrcSlice,
91  const Box* pSrcBox,
92  Uint32 DstMipLevel,
93  Uint32 DstSlice,
94  Uint32 DstX,
95  Uint32 DstY,
96  Uint32 DstZ);
97 
99  virtual GLuint DILIGENT_CALL_TYPE GetGLTextureHandle() override final { return GetGLHandle(); }
100 
102  virtual void* DILIGENT_CALL_TYPE GetNativeHandle() override final
103  {
104  return reinterpret_cast<void*>(static_cast<size_t>(GetGLTextureHandle()));
105  }
106 
107  virtual void UpdateData(class GLContextState& CtxState,
108  Uint32 MipLevel,
109  Uint32 Slice,
110  const Box& DstBox,
111  const TextureSubResData& SubresData) = 0;
112 
113  static constexpr Uint32 PBOOffsetAlignment = 4;
114 
116  {
117  return m_pPBO;
118  }
119 
120 protected:
121  virtual void CreateViewInternal(const struct TextureViewDesc& ViewDesc,
122  ITextureView** ppView,
123  bool bIsDefaultView) override;
124 
125  void SetDefaultGLParameters();
126 
128  RefCntAutoPtr<IBuffer> m_pPBO; // For staging textures
129  const GLenum m_BindTarget;
130  const GLenum m_GLTexFormat;
131  //Uint32 m_uiMapTarget;
132 };
133 
135 {
136 #if GL_ARB_shader_image_load_store
137 # ifdef DILIGENT_DEBUG
138  {
139  constexpr Uint32 TextureBarriers = MEMORY_BARRIER_ALL_TEXTURE_BARRIERS;
140  VERIFY((RequiredBarriers & TextureBarriers) != 0, "At least one texture memory barrier flag should be set");
141  VERIFY((RequiredBarriers & ~TextureBarriers) == 0, "Inappropriate texture memory barrier flag");
142  }
143 # endif
144 
145  GLContextState.EnsureMemoryBarrier(RequiredBarriers, this);
146 #endif
147 }
148 
149 } // namespace Diligent
Diligent::TextureBaseGL::CreateViewInternal
virtual void CreateViewInternal(const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView) override
Definition: TextureBaseGL.cpp:352
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::TextureBaseGL::QueryInterface
virtual void QueryInterface(const INTERFACE_ID &IID, IObject **ppInterface) override
Diligent::TextureBaseGL::TextureBaseGL
TextureBaseGL(IReferenceCounters *pRefCounters, FixedBlockMemoryAllocator &TexViewObjAllocator, RenderDeviceGLImpl *pDeviceGL, const TextureDesc &TexDesc, GLenum BindTarget, const TextureData *pInitData=nullptr, bool bIsDeviceInternal=false)
Definition: TextureBaseGL.cpp:44
Diligent::TextureBaseGL::AttachToFramebuffer
virtual void AttachToFramebuffer(const struct TextureViewDesc &ViewDesc, GLenum AttachmentPoint)=0
Diligent::TextureViewGLImpl
Texture view implementation in OpenGL backend.
Definition: TextureViewGLImpl.hpp:38
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
GLContextState.hpp
Diligent::DeviceContextGLImpl
Device context implementation in OpenGL backend.
Definition: DeviceContextGLImpl.hpp:51
Diligent::TextureBaseGL::GetPBO
IBuffer * GetPBO()
Definition: TextureBaseGL.hpp:115
Diligent::TextureBaseGL::GetNativeHandle
virtual void * GetNativeHandle() override final
Implementation of ITexture::GetNativeHandle() in OpenGL backend.
Definition: TextureBaseGL.hpp:102
Diligent::ITextureView
Texture view interface.
Definition: TextureView.h:202
Diligent::AsyncWritableResource
Definition: AsyncWritableResource.hpp:76
Diligent::TextureBaseGL::GetBindTarget
virtual GLenum GetBindTarget() const override final
Implementation of ITextureGL::GetBindTarget().
Definition: TextureBaseGL.hpp:79
Diligent::Box
Box.
Definition: GraphicsTypes.h:2407
Diligent::TextureBaseGL::PBOOffsetAlignment
static constexpr Uint32 PBOOffsetAlignment
Definition: TextureBaseGL.hpp:113
Diligent::TextureBaseGL::GetGLHandle
const GLObjectWrappers::GLTextureObj & GetGLHandle() const
Definition: TextureBaseGL.hpp:76
Diligent::INTERFACE_ID
Unique interface identifier.
Definition: InterfaceID.h:37
Diligent::IBuffer
Buffer interface.
Definition: Buffer.h:187
Diligent::TextureDesc
Texture description.
Definition: Texture.h:47
Diligent::TextureBaseGL::m_GLTexFormat
const GLenum m_GLTexFormat
Definition: TextureBaseGL.hpp:130
Diligent::RefCntAutoPtr
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
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::GLContextState::EnsureMemoryBarrier
void EnsureMemoryBarrier(MEMORY_BARRIER RequiredBarriers, class AsyncWritableResource *pRes=nullptr)
Definition: GLContextState.cpp:383
Diligent::TextureBaseGL
Base implementation of a texture object in OpenGL backend.
Definition: TextureBaseGL.hpp:41
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::TextureBase
Base implementation of the ITexture interface.
Definition: TextureBase.hpp:71
Diligent::MEMORY_BARRIER
MEMORY_BARRIER
Definition: AsyncWritableResource.hpp:33
Diligent::TextureBaseGL::GetGLTextureHandle
virtual GLuint GetGLTextureHandle() override final
Implementation of ITextureGL::GetGLTextureHandle().
Definition: TextureBaseGL.hpp:99
Diligent::RenderDeviceGLImpl
Render device implementation in OpenGL backend.
Definition: RenderDeviceGLImpl.hpp:45
Diligent::TextureBaseGL::TextureMemoryBarrier
__forceinline void TextureMemoryBarrier(MEMORY_BARRIER RequiredBarriers, class GLContextState &GLContextState)
Definition: TextureBaseGL.hpp:134
Diligent::TextureBaseGL::CopyData
void CopyData(DeviceContextGLImpl *pDeviceCtxGL, TextureBaseGL *pSrcTextureGL, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, Uint32 DstMipLevel, Uint32 DstSlice, Uint32 DstX, Uint32 DstY, Uint32 DstZ)
Definition: TextureBaseGL.cpp:520
Diligent::TextureBaseGL::GetGLTexFormat
GLenum GetGLTexFormat() const
Definition: TextureBaseGL.hpp:81
EngineGLImplTraits.hpp
Diligent::MEMORY_BARRIER_ALL_TEXTURE_BARRIERS
@ MEMORY_BARRIER_ALL_TEXTURE_BARRIERS
Definition: AsyncWritableResource.hpp:67
AsyncWritableResource.hpp
Diligent::TextureBaseGL::UpdateData
virtual void UpdateData(class GLContextState &CtxState, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData)=0
Definition: TextureBaseGL.cpp:499
GLObjectWrappers::GLObjWrapper
Definition: GLObjectWrapper.hpp:36
TextureViewGLImpl.hpp
Diligent::GLContextState
Definition: GLContextState.hpp:39
Diligent::TextureBaseGL::m_BindTarget
const GLenum m_BindTarget
Definition: TextureBaseGL.hpp:129
VERIFY
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
Diligent::FixedBlockMemoryAllocator
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.hpp:56
Diligent::TextureViewDesc
Texture view description.
Definition: TextureView.h:80
TextureBase.hpp
Diligent::TextureBaseGL::m_pPBO
RefCntAutoPtr< IBuffer > m_pPBO
Definition: TextureBaseGL.hpp:128
Diligent::TextureBaseGL::~TextureBaseGL
~TextureBaseGL()
Definition: TextureBaseGL.cpp:339
Diligent::TextureBaseGL::SetDefaultGLParameters
void SetDefaultGLParameters()
Definition: TextureBaseGL.cpp:650
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::TextureBaseGL::m_GlTexture
GLObjectWrappers::GLTextureObj m_GlTexture
Definition: TextureBaseGL.hpp:127
Diligent::TextureSubResData
Describes data for one subresource.
Definition: Texture.h:165
GLObjectWrapper.hpp