Diligent Engine  v.2.4.g
BufferGLImpl.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 "BufferBase.hpp"
32 #include "BufferViewGLImpl.hpp" // Required by BufferBase
33 #include "GLObjectWrapper.hpp"
35 #include "GLContextState.hpp"
36 
37 namespace Diligent
38 {
39 
41 class BufferGLImpl final : public BufferBase<EngineGLImplTraits>, public AsyncWritableResource
42 {
43 public:
45 
46  BufferGLImpl(IReferenceCounters* pRefCounters,
47  FixedBlockMemoryAllocator& BuffViewObjMemAllocator,
48  RenderDeviceGLImpl* pDeviceGL,
49  const BufferDesc& BuffDesc,
50  GLContextState& CtxState,
51  const BufferData* pBuffData,
52  bool bIsDeviceInternal);
53 
54  BufferGLImpl(IReferenceCounters* pRefCounters,
55  FixedBlockMemoryAllocator& BuffViewObjMemAllocator,
56  class RenderDeviceGLImpl* pDeviceGL,
57  const BufferDesc& BuffDesc,
58  GLContextState& CtxState,
59  GLuint GLHandle,
60  bool bIsDeviceInternal);
61 
62  ~BufferGLImpl();
63 
65  virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override;
66 
67  void UpdateData(GLContextState& CtxState, Uint32 Offset, Uint32 Size, const void* pData);
68  void CopyData(GLContextState& CtxState, BufferGLImpl& SrcBufferGL, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size);
69  void Map(GLContextState& CtxState, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData);
70  void MapRange(GLContextState& CtxState, MAP_TYPE MapType, Uint32 MapFlags, Uint32 Offset, Uint32 Length, PVoid& pMappedData);
71  void Unmap(GLContextState& CtxState);
72 
73  __forceinline void BufferMemoryBarrier(MEMORY_BARRIER RequiredBarriers, GLContextState& GLContextState);
74 
75  const GLObjectWrappers::GLBufferObj& GetGLHandle() { return m_GlBuffer; }
76 
78  virtual GLuint DILIGENT_CALL_TYPE GetGLBufferHandle() override final { return GetGLHandle(); }
79 
81  virtual void* DILIGENT_CALL_TYPE GetNativeHandle() override final
82  {
83  return reinterpret_cast<void*>(static_cast<size_t>(GetGLBufferHandle()));
84  }
85 
86 private:
87  virtual void CreateViewInternal(const struct BufferViewDesc& ViewDesc, IBufferView** ppView, bool bIsDefaultView) override;
88 
89  friend class DeviceContextGLImpl;
90  friend class VAOCache;
91 
93  const Uint32 m_BindTarget;
94  const GLenum m_GLUsageHint;
95 };
96 
98 {
99 #if GL_ARB_shader_image_load_store
100 # ifdef DILIGENT_DEBUG
101  {
102  constexpr auto BufferBarriers = MEMORY_BARRIER_ALL_BUFFER_BARRIERS;
103  VERIFY((RequiredBarriers & BufferBarriers) != 0, "At least one buffer memory barrier flag should be set");
104  VERIFY((RequiredBarriers & ~BufferBarriers) == 0, "Inappropriate buffer memory barrier flag");
105  }
106 # endif
107 
108  GLState.EnsureMemoryBarrier(RequiredBarriers, this);
109 #endif
110 }
111 
112 } // namespace Diligent
Diligent::BufferViewDesc
Buffer view description.
Definition: BufferView.h:88
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::PVoid
void * PVoid
Definition: BasicTypes.h:56
Diligent::MEMORY_BARRIER_ALL_BUFFER_BARRIERS
@ MEMORY_BARRIER_ALL_BUFFER_BARRIERS
Definition: AsyncWritableResource.hpp:50
Diligent::BufferGLImpl::CreateViewInternal
virtual void CreateViewInternal(const struct BufferViewDesc &ViewDesc, IBufferView **ppView, bool bIsDefaultView) override
Definition: BufferGLImpl.cpp:350
Diligent::IObject
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
GLContextState.hpp
BufferBase.hpp
Diligent::DeviceContextGLImpl
Device context implementation in OpenGL backend.
Definition: DeviceContextGLImpl.hpp:51
Diligent::BufferGLImpl::GetGLHandle
const GLObjectWrappers::GLBufferObj & GetGLHandle()
Definition: BufferGLImpl.hpp:75
Length
Uint32 Length
Definition: DXBCUtils.cpp:59
Diligent::BufferGLImpl::QueryInterface
virtual void QueryInterface(const INTERFACE_ID &IID, IObject **ppInterface) override
Queries the specific interface, see IObject::QueryInterface() for details.
Diligent::AsyncWritableResource
Definition: AsyncWritableResource.hpp:76
Diligent::BufferGLImpl::Map
void Map(GLContextState &CtxState, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData)
Definition: BufferGLImpl.cpp:267
Diligent::BufferBase
Template class implementing base functionality of the buffer object.
Definition: BufferBase.hpp:59
Diligent::INTERFACE_ID
Unique interface identifier.
Definition: InterfaceID.h:37
Diligent::BufferGLImpl::CopyData
void CopyData(GLContextState &CtxState, BufferGLImpl &SrcBufferGL, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)
Definition: BufferGLImpl.cpp:241
Diligent::VAOCache
Definition: VAOCache.hpp:47
Diligent::BufferGLImpl::BufferGLImpl
BufferGLImpl(IReferenceCounters *pRefCounters, FixedBlockMemoryAllocator &BuffViewObjMemAllocator, RenderDeviceGLImpl *pDeviceGL, const BufferDesc &BuffDesc, GLContextState &CtxState, const BufferData *pBuffData, bool bIsDeviceInternal)
Definition: BufferGLImpl.cpp:72
Diligent::BufferGLImpl::GetNativeHandle
virtual void * GetNativeHandle() override final
Implementation of IBuffer::GetNativeHandle() in OpenGL backend.
Definition: BufferGLImpl.hpp:81
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::GLContextState::EnsureMemoryBarrier
void EnsureMemoryBarrier(MEMORY_BARRIER RequiredBarriers, class AsyncWritableResource *pRes=nullptr)
Definition: GLContextState.cpp:383
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
BufferViewGLImpl.hpp
Diligent::MEMORY_BARRIER
MEMORY_BARRIER
Definition: AsyncWritableResource.hpp:33
Diligent::RenderDeviceGLImpl
Render device implementation in OpenGL backend.
Definition: RenderDeviceGLImpl.hpp:45
Diligent::BufferGLImpl
Buffer object implementation in OpenGL backend.
Definition: BufferGLImpl.hpp:41
Diligent::BufferGLImpl::Unmap
void Unmap(GLContextState &CtxState)
Definition: BufferGLImpl.cpp:333
EngineGLImplTraits.hpp
Diligent::BufferDesc
Buffer description.
Definition: Buffer.h:74
Diligent::BufferGLImpl::GetGLBufferHandle
virtual GLuint GetGLBufferHandle() override final
Implementation of IBufferGL::GetGLBufferHandle().
Definition: BufferGLImpl.hpp:78
AsyncWritableResource.hpp
GLObjectWrappers::GLObjWrapper
Definition: GLObjectWrapper.hpp:36
Diligent::BufferGLImpl::BufferMemoryBarrier
__forceinline void BufferMemoryBarrier(MEMORY_BARRIER RequiredBarriers, GLContextState &GLContextState)
Definition: BufferGLImpl.hpp:97
Diligent::GLContextState
Definition: GLContextState.hpp:39
VERIFY
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
Diligent::FixedBlockMemoryAllocator
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.hpp:56
Diligent::BufferGLImpl::MapRange
void MapRange(GLContextState &CtxState, MAP_TYPE MapType, Uint32 MapFlags, Uint32 Offset, Uint32 Length, PVoid &pMappedData)
Definition: BufferGLImpl.cpp:272
Diligent::BufferGLImpl::UpdateData
void UpdateData(GLContextState &CtxState, Uint32 Offset, Uint32 Size, const void *pData)
Definition: BufferGLImpl.cpp:221
Diligent::IBufferView
Buffer view interface.
Definition: BufferView.h:155
Diligent::MAP_TYPE
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:206
Diligent::BufferData
Describes the buffer initial data.
Definition: Buffer.h:155
Diligent::BufferGLImpl::~BufferGLImpl
~BufferGLImpl()
Definition: BufferGLImpl.cpp:214
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
GLObjectWrapper.hpp