Diligent Engine  v.2.4.g
BufferViewBase.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 
32 
33 #include "BufferView.h"
34 #include "DeviceObjectBase.hpp"
35 #include "GraphicsTypes.h"
36 #include "RefCntAutoPtr.hpp"
37 
38 namespace Diligent
39 {
40 
42 
44 template <typename EngineImplTraits>
45 class BufferViewBase : public DeviceObjectBase<typename EngineImplTraits::BufferViewInterface, typename EngineImplTraits::RenderDeviceImplType, BufferViewDesc>
46 {
47 public:
48  // Base interface that this class inherits (IBufferViewD3D12, IBufferViewVk, etc.).
49  using BaseInterface = typename EngineImplTraits::BufferViewInterface;
50 
51  // Render device implementation type (RenderDeviceD3D12Impl, RenderDeviceVkImpl, etc.).
52  using RenderDeviceImplType = typename EngineImplTraits::RenderDeviceImplType;
53 
54  // Buffer implementation type (BufferD3D12Impl, BufferVkImpl, etc.).
55  using BufferImplType = typename EngineImplTraits::BufferImplType;
56 
58 
67  RenderDeviceImplType* pDevice,
68  const BufferViewDesc& ViewDesc,
69  IBuffer* pBuffer,
70  bool bIsDefaultView) :
71  // Default views are created as part of the buffer, so we cannot not keep strong
72  // reference to the buffer to avoid cyclic links. Instead, we will attach to the
73  // reference counters of the buffer.
74  TDeviceObjectBase(pRefCounters, pDevice, ViewDesc),
75  m_pBuffer{pBuffer},
76  // For non-default view, we will keep strong reference to buffer
77  m_spBuffer{bIsDefaultView ? nullptr : pBuffer}
78  {}
79 
81 
82 
83  virtual IBuffer* DILIGENT_CALL_TYPE GetBuffer() const override final
84  {
85  return m_pBuffer;
86  }
87 
88  template <typename BufferType>
89  BufferType* GetBuffer()
90  {
91  return ValidatedCast<BufferType>(m_pBuffer);
92  }
93 
94  template <typename BufferType>
95  BufferType* GetBuffer() const
96  {
97  return ValidatedCast<BufferType>(m_pBuffer);
98  }
99 
100 protected:
103 
107 };
108 
109 } // 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
DeviceObjectBase.hpp
Diligent::BufferViewBase::m_spBuffer
RefCntAutoPtr< IBuffer > m_spBuffer
Strong reference to the buffer. Used for non-default views to keep the buffer alive.
Definition: BufferViewBase.hpp:106
Diligent::BufferViewBase< EngineGLImplTraits >::BufferImplType
typename EngineGLImplTraits ::BufferImplType BufferImplType
Definition: BufferViewBase.hpp:55
Diligent::BufferViewBase::m_pBuffer
IBuffer *const m_pBuffer
Pointer to the buffer.
Definition: BufferViewBase.hpp:102
Diligent::IBuffer
Buffer interface.
Definition: Buffer.h:187
Diligent::BufferViewBase::GetBuffer
virtual IBuffer * GetBuffer() const override final
Implementation of IBufferView::GetBuffer()
Definition: BufferViewBase.hpp:83
Diligent::BufferViewBase< EngineGLImplTraits >::BaseInterface
typename EngineGLImplTraits ::BufferViewInterface BaseInterface
Definition: BufferViewBase.hpp:49
Diligent::BufferViewBase::GetBuffer
BufferType * GetBuffer()
Definition: BufferViewBase.hpp:89
IMPLEMENT_QUERY_INTERFACE_IN_PLACE
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
Diligent::BufferViewBase< EngineGLImplTraits >::RenderDeviceImplType
typename EngineGLImplTraits ::RenderDeviceImplType RenderDeviceImplType
Definition: BufferViewBase.hpp:52
Diligent::RefCntAutoPtr
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::BufferViewBase::BufferViewBase
BufferViewBase(IReferenceCounters *pRefCounters, RenderDeviceImplType *pDevice, const BufferViewDesc &ViewDesc, IBuffer *pBuffer, bool bIsDefaultView)
Definition: BufferViewBase.hpp:66
BufferView.h
Diligent::BufferViewBase::TDeviceObjectBase
DeviceObjectBase< BaseInterface, RenderDeviceImplType, BufferViewDesc > TDeviceObjectBase
Definition: BufferViewBase.hpp:57
Diligent::BufferViewBase
Template class implementing base functionality of the buffer view object.
Definition: BufferViewBase.hpp:45
RefCntAutoPtr.hpp
GraphicsTypes.h
Diligent::BufferViewBase::GetBuffer
BufferType * GetBuffer() const
Definition: BufferViewBase.hpp:95
Diligent::DeviceObjectBase
Template class implementing base functionality of the device object.
Definition: DeviceObjectBase.hpp:45
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37