Diligent Engine API Reference
BufferViewBase.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 
28 
29 #include "BufferView.h"
30 #include "DeviceObjectBase.h"
31 #include "GraphicsTypes.h"
32 #include "RefCntAutoPtr.h"
33 
34 namespace Diligent
35 {
36 
37 class IRenderDevice;
38 class IBuffer;
39 
41 
45 template<class BaseInterface>
46 class BufferViewBase : public DeviceObjectBase<BaseInterface, BufferViewDesc>
47 {
48 public:
50 
58  BufferViewBase( IReferenceCounters *pRefCounters,
59  IRenderDevice *pDevice,
60  const BufferViewDesc& ViewDesc,
61  IBuffer *pBuffer,
62  bool bIsDefaultView ) :
63  // Default views are created as part of the buffer, so we cannot not keep strong
64  // reference to the buffer to avoid cyclic links. Instead, we will attach to the
65  // reference counters of the buffer.
66  TDeviceObjectBase( pRefCounters, pDevice, ViewDesc),
67  m_pBuffer( pBuffer ),
68  // For non-default view, we will keep strong reference to buffer
69  m_spBuffer(bIsDefaultView ? nullptr : pBuffer)
70  {}
71 
72  IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_BufferView, TDeviceObjectBase )
73 
74 
75  virtual IBuffer* GetBuffer()override final
76  {
77  return m_pBuffer;
78  }
79 
80 protected:
81 
84 
88 };
89 
90 }
IBuffer *const m_pBuffer
Pointer to the buffer.
Definition: BufferViewBase.h:83
Buffer view description.
Definition: BufferView.h:39
Render device interface.
Definition: RenderDevice.h:55
RefCntAutoPtr< IBuffer > m_spBuffer
Strong reference to the buffer. Used for non-default views to keep the buffer alive.
Definition: BufferViewBase.h:87
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Buffer interface.
Definition: Buffer.h:200
virtual IBuffer * GetBuffer() override final
Implementation of IBufferView::GetBuffer()
Definition: BufferViewBase.h:75
Template class that implements reference counting.
Definition: RefCntAutoPtr.h:71
Template class implementing base functionality for a buffer view object.
Definition: BufferViewBase.h:46
BufferViewBase(IReferenceCounters *pRefCounters, IRenderDevice *pDevice, const BufferViewDesc &ViewDesc, IBuffer *pBuffer, bool bIsDefaultView)
Definition: BufferViewBase.h:58
Template class implementing base functionality for a device object.
Definition: DeviceObjectBase.h:42