Diligent Engine API Reference
TextureViewBase.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 "TextureView.h"
30 #include "DeviceObjectBase.h"
31 #include "RefCntAutoPtr.h"
32 #include "GraphicsAccessories.h"
33 
34 namespace Diligent
35 {
36 
38 
41 template<class BaseInterface>
42 class TextureViewBase : public DeviceObjectBase<BaseInterface, TextureViewDesc>
43 {
44 public:
46 
47 
55  TextureViewBase( IReferenceCounters *pRefCounters,
56  IRenderDevice *pDevice,
57  const TextureViewDesc& ViewDesc,
58  class ITexture *pTexture,
59  bool bIsDefaultView ) :
60  // Default views are created as part of the texture, so we cannot not keep strong
61  // reference to the texture to avoid cyclic links. Instead, we will attach to the
62  // reference counters of the texture.
63  TDeviceObjectBase( pRefCounters, pDevice, ViewDesc ),
64  m_pTexture( pTexture ),
65  // For non-default view, we will keep strong reference to texture
66  m_spTexture(bIsDefaultView ? nullptr : pTexture)
67  {}
68 
69  IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_TextureView, TDeviceObjectBase )
70 
71 
72  virtual void SetSampler( class ISampler *pSampler )override final
73  {
74  VERIFY( this->m_Desc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "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) );
75  m_pSampler = pSampler;
76  }
77 
79  virtual ISampler* GetSampler()override final
80  {
81  return m_pSampler;
82  }
83 
85  virtual ITexture* GetTexture()override final
86  {
87  return m_pTexture;
88  }
89 
90 protected:
93 
96 
100 };
101 
102 }
ITexture * m_pTexture
Raw pointer to the texture.
Definition: TextureViewBase.h:95
Render device interface.
Definition: RenderDevice.h:55
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
virtual ITexture * GetTexture() override final
Implementation of ITextureView::GetTexture()
Definition: TextureViewBase.h:85
virtual ISampler * GetSampler() override final
Implementation of ITextureView::GetSampler()
Definition: TextureViewBase.h:79
Template class implementing base functionality for a texture view interface.
Definition: TextureViewBase.h:42
virtual void SetSampler(class ISampler *pSampler) override final
Implementation of ITextureView::SetSampler()
Definition: TextureViewBase.h:72
TextureViewBase(IReferenceCounters *pRefCounters, IRenderDevice *pDevice, const TextureViewDesc &ViewDesc, class ITexture *pTexture, bool bIsDefaultView)
Definition: TextureViewBase.h:55
Diligent::RefCntAutoPtr< ISampler > m_pSampler
Strong reference to the sampler.
Definition: TextureViewBase.h:92
Texture view description.
Definition: TextureView.h:55
TEXTURE_VIEW_TYPE ViewType
Describes the texture view type, see Diligent::TEXTURE_VIEW_TYPE for details.
Definition: TextureView.h:58
TextureViewDesc m_Desc
Object description.
Definition: DeviceObjectBase.h:138
Template class that implements reference counting.
Definition: RefCntAutoPtr.h:71
Texture sampler interface.
Definition: Sampler.h:180
Diligent::RefCntAutoPtr< ITexture > m_spTexture
Strong reference to the texture. Used for non-default views to keep the texture alive.
Definition: TextureViewBase.h:99
A texture view will define a shader resource view that will be used as the source for the shader read...
Definition: GraphicsTypes.h:197
Template class implementing base functionality for a device object.
Definition: DeviceObjectBase.h:42
Texture inteface.
Definition: Texture.h:276