Diligent Engine  v.2.4.g
SwapChainBase.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 "RenderDevice.h"
34 #include "DeviceContext.h"
35 #include "SwapChain.h"
36 #include "ObjectBase.hpp"
37 #include "Errors.hpp"
38 #include "RefCntAutoPtr.hpp"
39 
40 namespace Diligent
41 {
42 
44 
50 template <class BaseInterface>
51 class SwapChainBase : public ObjectBase<BaseInterface>
52 {
53 public:
55 
61  IRenderDevice* pDevice,
62  IDeviceContext* pDeviceContext,
63  const SwapChainDesc& SCDesc) :
64  // clang-format off
65  TObjectBase {pRefCounters },
66  m_pRenderDevice {pDevice },
67  m_wpDeviceContext {pDeviceContext },
68  m_SwapChainDesc {SCDesc },
69  m_DesiredPreTransform{SCDesc.PreTransform}
70  // clang-format on
71  {
72  }
73 
74  // clang-format off
75  SwapChainBase (const SwapChainBase&) = delete;
76  SwapChainBase ( SwapChainBase&&) = delete;
77  SwapChainBase& operator = (const SwapChainBase&) = delete;
79  // clang-format on
80 
82  {
83  }
84 
86 
87 
88  virtual const SwapChainDesc& DILIGENT_CALL_TYPE GetDesc() const override final
89  {
90  return m_SwapChainDesc;
91  }
92 
93  virtual void DILIGENT_CALL_TYPE SetMaximumFrameLatency(Uint32 MaxLatency) override
94  {}
95 
96 protected:
97  bool Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFORM NewPreTransform, Int32 Dummy = 0 /*To be different from virtual function*/)
98  {
99  if (NewWidth != 0 && NewHeight != 0 &&
100  (m_SwapChainDesc.Width != NewWidth ||
101  m_SwapChainDesc.Height != NewHeight ||
102  m_DesiredPreTransform != NewPreTransform))
103  {
104  m_SwapChainDesc.Width = NewWidth;
105  m_SwapChainDesc.Height = NewHeight;
106  m_DesiredPreTransform = NewPreTransform;
107  LOG_INFO_MESSAGE("Resizing the swap chain to ", m_SwapChainDesc.Width, "x", m_SwapChainDesc.Height);
108  return true;
109  }
110 
111  return false;
112  }
113 
116 
120 
123 
126 };
127 
128 } // namespace Diligent
ObjectBase.hpp
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::SwapChainBase::m_DesiredPreTransform
SURFACE_TRANSFORM m_DesiredPreTransform
Desired surface pre-transformation.
Definition: SwapChainBase.hpp:125
Diligent::SwapChainDesc::Width
Uint32 Width
The swap chain width. Default value is 0.
Definition: GraphicsTypes.h:1350
Diligent::RefCntWeakPtr
Implementation of weak pointers.
Definition: RefCntAutoPtr.hpp:40
DeviceContext.h
Diligent::SwapChainBase::TObjectBase
ObjectBase< BaseInterface > TObjectBase
Definition: SwapChainBase.hpp:54
Diligent::SwapChainBase::m_wpDeviceContext
RefCntWeakPtr< IDeviceContext > m_wpDeviceContext
Weak references to the immediate device context. The context holds the strong reference to the swap c...
Definition: SwapChainBase.hpp:119
Diligent::ObjectBase
Template class implementing base functionality for an object.
Definition: ObjectBase.hpp:66
Diligent::SwapChainBase::~SwapChainBase
~SwapChainBase()
Definition: SwapChainBase.hpp:81
RenderDevice.h
Diligent::Int32
int32_t Int32
32-bit signed integer
Definition: BasicTypes.h:46
Diligent::SURFACE_TRANSFORM_OPTIMAL
@ SURFACE_TRANSFORM_OPTIMAL
Uset the most optimal surface transform.
Definition: GraphicsTypes.h:1318
Diligent::IRenderDevice
Render device interface.
Definition: RenderDevice.h:75
Diligent::SURFACE_TRANSFORM
SURFACE_TRANSFORM
The transform applied to the image content prior to presentation.
Definition: GraphicsTypes.h:1315
LOG_INFO_MESSAGE
#define LOG_INFO_MESSAGE(...)
Definition: Errors.hpp:124
IMPLEMENT_QUERY_INTERFACE_IN_PLACE
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
Diligent::SwapChainBase::operator=
SwapChainBase & operator=(const SwapChainBase &)=delete
Dummy
n int Dummy
Definition: GenerateMipsCS_inc.h:25
Diligent::RefCntAutoPtr
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::SwapChainBase
Base implementation of the swap chain.
Definition: SwapChainBase.hpp:51
Diligent::SwapChainDesc
Swap chain description.
Definition: GraphicsTypes.h:1347
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::SwapChainBase::Resize
bool Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFORM NewPreTransform, Int32 Dummy=0)
Definition: SwapChainBase.hpp:97
Diligent::SwapChainBase::m_pRenderDevice
RefCntAutoPtr< IRenderDevice > m_pRenderDevice
Strong reference to the render device.
Definition: SwapChainBase.hpp:115
Diligent::SwapChainBase::SetMaximumFrameLatency
virtual void SetMaximumFrameLatency(Uint32 MaxLatency) override
Definition: SwapChainBase.hpp:93
Diligent::SwapChainBase::m_SwapChainDesc
SwapChainDesc m_SwapChainDesc
Swap chain description.
Definition: SwapChainBase.hpp:122
SwapChain.h
Diligent::IDeviceContext
Device context interface.
Definition: DeviceContext.h:1460
RefCntAutoPtr.hpp
Diligent::SwapChainBase::GetDesc
virtual const SwapChainDesc & GetDesc() const override final
Implementation of ISwapChain::GetDesc()
Definition: SwapChainBase.hpp:88
Diligent::SwapChainDesc::Height
Uint32 Height
The swap chain height. Default value is 0.
Definition: GraphicsTypes.h:1353
Diligent::SwapChainBase::SwapChainBase
SwapChainBase(IReferenceCounters *pRefCounters, IRenderDevice *pDevice, IDeviceContext *pDeviceContext, const SwapChainDesc &SCDesc)
Definition: SwapChainBase.hpp:60
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Errors.hpp