Diligent Engine  v.2.4.g
TextureViewBase.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 "TextureView.h"
34 #include "DeviceObjectBase.hpp"
35 #include "RefCntAutoPtr.hpp"
36 #include "GraphicsAccessories.hpp"
37 
38 namespace Diligent
39 {
40 
42 
44 template <typename EngineImplTraits>
45 class TextureViewBase : public DeviceObjectBase<typename EngineImplTraits::TextureViewInterface, typename EngineImplTraits::RenderDeviceImplType, TextureViewDesc>
46 {
47 public:
48  // Base interface that this class inherits (ITextureViewD3D12, ITextureViewVk, etc.).
49  using BaseInterface = typename EngineImplTraits::TextureViewInterface;
50 
51  // Render device implementation type (RenderDeviceD3D12Impl, RenderDeviceVkImpl, etc.).
52  using RenderDeviceImplType = typename EngineImplTraits::RenderDeviceImplType;
53 
55 
56 
65  RenderDeviceImplType* pDevice,
66  const TextureViewDesc& ViewDesc,
67  ITexture* pTexture,
68  bool bIsDefaultView) :
69  // Default views are created as part of the texture, so we cannot not keep strong
70  // reference to the texture to avoid cyclic links. Instead, we will attach to the
71  // reference counters of the texture.
72  TDeviceObjectBase(pRefCounters, pDevice, ViewDesc),
73  m_pTexture(pTexture),
74  // For non-default view, we will keep strong reference to texture
75  m_spTexture(bIsDefaultView ? nullptr : pTexture)
76  {}
77 
79 
80 
81  virtual void DILIGENT_CALL_TYPE SetSampler(ISampler* pSampler) override final
82  {
83 #ifdef DILIGENT_DEVELOPMENT
85  LOG_ERROR("Texture view \"", this->m_Desc.Name, "\": a sampler can be attached to a shader resource view only. The view type is ", GetTexViewTypeLiteralName(this->m_Desc.ViewType));
86 #endif
87  m_pSampler = pSampler;
88  }
89 
91  virtual ISampler* DILIGENT_CALL_TYPE GetSampler() override final
92  {
93  return m_pSampler;
94  }
95 
96  const ISampler* GetSampler() const
97  {
98  return m_pSampler;
99  }
100 
102  virtual ITexture* DILIGENT_CALL_TYPE GetTexture() override final
103  {
104  return m_pTexture;
105  }
106 
108  {
109  return m_pTexture;
110  }
111 
112  template <typename TextureType>
113  TextureType* GetTexture()
114  {
115  return ValidatedCast<TextureType>(m_pTexture);
116  }
117 
118  template <typename TextureType>
119  TextureType* GetTexture() const
120  {
121  return ValidatedCast<TextureType>(m_pTexture);
122  }
123 
124 protected:
127 
130 
134 };
135 
136 } // namespace Diligent
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
GraphicsAccessories.hpp
TextureView.h
Diligent::TextureViewBase::TextureViewBase
TextureViewBase(IReferenceCounters *pRefCounters, RenderDeviceImplType *pDevice, const TextureViewDesc &ViewDesc, ITexture *pTexture, bool bIsDefaultView)
Definition: TextureViewBase.hpp:64
Diligent::ISampler
Texture sampler interface.
Definition: Sampler.h:192
DeviceObjectBase.hpp
Diligent::TextureViewBase::GetTexture
TextureType * GetTexture() const
Definition: TextureViewBase.hpp:119
Diligent::TextureViewBase::TDeviceObjectBase
DeviceObjectBase< BaseInterface, RenderDeviceImplType, TextureViewDesc > TDeviceObjectBase
Definition: TextureViewBase.hpp:54
Diligent::TextureViewBase::m_pTexture
ITexture *const m_pTexture
Raw pointer to the texture.
Definition: TextureViewBase.hpp:129
LOG_ERROR
#define LOG_ERROR(...)
Definition: Errors.hpp:76
Diligent::DeviceObjectBase< EngineImplTraits::TextureViewInterface, EngineImplTraits::RenderDeviceImplType, TextureViewDesc >::m_Desc
TextureViewDesc m_Desc
Object description.
Definition: DeviceObjectBase.hpp:182
Diligent::GetTexViewTypeLiteralName
const Char * GetTexViewTypeLiteralName(TEXTURE_VIEW_TYPE ViewType)
Returns the literal name of a texture view type. For instance, for a shader resource view,...
Definition: GraphicsAccessories.cpp:408
Diligent::TextureViewBase::GetSampler
const ISampler * GetSampler() const
Definition: TextureViewBase.hpp:96
Diligent::TextureViewBase::GetTexture
virtual ITexture * GetTexture() override final
Implementation of ITextureView::GetTexture()
Definition: TextureViewBase.hpp:102
Diligent::TextureViewDesc::ViewType
TEXTURE_VIEW_TYPE ViewType
Describes the texture view type, see Diligent::TEXTURE_VIEW_TYPE for details.
Definition: TextureView.h:83
Diligent::TextureViewBase< EngineGLImplTraits >::BaseInterface
typename EngineGLImplTraits ::TextureViewInterface BaseInterface
Definition: TextureViewBase.hpp:49
IMPLEMENT_QUERY_INTERFACE_IN_PLACE
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
Diligent::TextureViewBase
Template class implementing base functionality of the texture view interface.
Definition: TextureViewBase.hpp:45
Diligent::RefCntAutoPtr
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::TextureViewBase::SetSampler
virtual void SetSampler(ISampler *pSampler) override final
Implementation of ITextureView::SetSampler()
Definition: TextureViewBase.hpp:81
Diligent::TextureViewBase::GetSampler
virtual ISampler * GetSampler() override final
Implementation of ITextureView::GetSampler()
Definition: TextureViewBase.hpp:91
Diligent::TextureViewBase::m_pSampler
RefCntAutoPtr< ISampler > m_pSampler
Strong reference to the sampler.
Definition: TextureViewBase.hpp:126
RefCntAutoPtr.hpp
Diligent::TextureViewBase::GetTexture
const ITexture * GetTexture() const
Definition: TextureViewBase.hpp:107
Diligent::TextureViewBase< EngineGLImplTraits >::RenderDeviceImplType
typename EngineGLImplTraits ::RenderDeviceImplType RenderDeviceImplType
Definition: TextureViewBase.hpp:52
Diligent::TextureViewDesc
Texture view description.
Definition: TextureView.h:80
Diligent::TEXTURE_VIEW_SHADER_RESOURCE
@ TEXTURE_VIEW_SHADER_RESOURCE
A texture view will define a shader resource view that will be used as the source for the shader read...
Definition: GraphicsTypes.h:281
Diligent::ITexture
Texture inteface.
Definition: Texture.h:273
Diligent::TextureViewBase::GetTexture
TextureType * GetTexture()
Definition: TextureViewBase.hpp:113
Diligent::TextureViewBase::m_spTexture
RefCntAutoPtr< ITexture > m_spTexture
Strong reference to the texture. Used for non-default views to keep the texture alive.
Definition: TextureViewBase.hpp:133
Diligent::DeviceObjectAttribs::Name
const Char * Name
Object name.
Definition: GraphicsTypes.h:1199
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