Diligent Engine  v.2.4.g
TextureUploaderBase.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 
30 #include <vector>
31 
32 #include "TextureUploader.hpp"
33 #include "../../../Common/interface/ObjectBase.hpp"
34 #include "../../../Common/interface/HashUtils.hpp"
35 #include "../../../Common/interface/RefCntAutoPtr.hpp"
36 
37 namespace std
38 {
39 
40 template <>
41 struct hash<Diligent::UploadBufferDesc>
42 {
43  size_t operator()(const Diligent::UploadBufferDesc& Desc) const
44  {
45  return Diligent::ComputeHash(Desc.Width, Desc.Height, Desc.Depth, static_cast<Diligent::Int32>(Desc.Format));
46  }
47 };
48 
49 } // namespace std
50 
51 namespace Diligent
52 {
53 class UploadBufferBase : public ObjectBase<IUploadBuffer>
54 {
55 public:
57  // clang-format off
58  ObjectBase<IUploadBuffer>{pRefCounters},
59  m_Desc {Desc},
61  // clang-format on
62  {
63  }
64 
65  virtual MappedTextureSubresource GetMappedData(Uint32 Mip, Uint32 Slice) override final
66  {
67  VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
68  return m_MappedData[m_Desc.MipLevels * Slice + Mip];
69  }
70  virtual const UploadBufferDesc& GetDesc() const override final { return m_Desc; }
71 
72  void SetMappedData(Uint32 Mip, Uint32 Slice, const MappedTextureSubresource& MappedData)
73  {
74  VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
75  m_MappedData[m_Desc.MipLevels * Slice + Mip] = MappedData;
76  }
77 
78  bool IsMapped(Uint32 Mip, Uint32 Slice) const
79  {
80  VERIFY_EXPR(Mip < m_Desc.MipLevels && Slice < m_Desc.ArraySize);
81  return m_MappedData[m_Desc.MipLevels * Slice + Mip].pData != nullptr;
82  }
83 
84  void Reset()
85  {
86  for (auto& MappedData : m_MappedData)
87  MappedData = MappedTextureSubresource{};
88  }
89 
90 protected:
92  std::vector<MappedTextureSubresource> m_MappedData;
93 };
94 
95 class TextureUploaderBase : public ObjectBase<ITextureUploader>
96 {
97 public:
99  ObjectBase<ITextureUploader>{pRefCounters},
100  m_pDevice{pDevice}
101  {}
102 
103 protected:
105 };
106 
107 } // 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
Diligent::UploadBufferBase::SetMappedData
void SetMappedData(Uint32 Mip, Uint32 Slice, const MappedTextureSubresource &MappedData)
Definition: TextureUploaderBase.hpp:72
Diligent::UploadBufferDesc::ArraySize
Uint32 ArraySize
Definition: TextureUploader.hpp:45
Diligent::UploadBufferBase
Definition: TextureUploaderBase.hpp:53
Diligent::UploadBufferBase::Reset
void Reset()
Definition: TextureUploaderBase.hpp:84
TextureUploader.hpp
Diligent::UploadBufferDesc::MipLevels
Uint32 MipLevels
Definition: TextureUploader.hpp:44
Diligent::TextureUploaderBase
Definition: TextureUploaderBase.hpp:95
Diligent::TextureUploaderBase::TextureUploaderBase
TextureUploaderBase(IReferenceCounters *pRefCounters, IRenderDevice *pDevice, const TextureUploaderDesc Desc)
Definition: TextureUploaderBase.hpp:98
Diligent::MappedTextureSubresource
Definition: Texture.h:245
std::hash< Diligent::UploadBufferDesc >::operator()
size_t operator()(const Diligent::UploadBufferDesc &Desc) const
Definition: TextureUploaderBase.hpp:43
Diligent::ObjectBase
Template class implementing base functionality for an object.
Definition: ObjectBase.hpp:66
Diligent::UploadBufferBase::m_Desc
const UploadBufferDesc m_Desc
Definition: TextureUploaderBase.hpp:91
Diligent::Int32
int32_t Int32
32-bit signed integer
Definition: BasicTypes.h:46
Diligent::IRenderDevice
Render device interface.
Definition: RenderDevice.h:75
Diligent::IUploadBuffer
Definition: TextureUploader.hpp:58
Diligent::UploadBufferBase::GetDesc
virtual const UploadBufferDesc & GetDesc() const override final
Definition: TextureUploaderBase.hpp:70
Diligent::RefCntAutoPtr
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
Diligent::UploadBufferBase::m_MappedData
std::vector< MappedTextureSubresource > m_MappedData
Definition: TextureUploaderBase.hpp:92
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::ComputeHash
std::size_t ComputeHash(const ArgsType &... Args)
Definition: HashUtils.hpp:57
Diligent::UploadBufferBase::UploadBufferBase
UploadBufferBase(IReferenceCounters *pRefCounters, const UploadBufferDesc &Desc)
Definition: TextureUploaderBase.hpp:56
Diligent::UploadBufferDesc::Format
TEXTURE_FORMAT Format
Definition: TextureUploader.hpp:46
Diligent::UploadBufferBase::GetMappedData
virtual MappedTextureSubresource GetMappedData(Uint32 Mip, Uint32 Slice) override final
Definition: TextureUploaderBase.hpp:65
Diligent::TextureUploaderDesc
Texture uploader description.
Definition: TextureUploader.hpp:67
Diligent::UploadBufferDesc::Width
Uint32 Width
Definition: TextureUploader.hpp:41
Diligent::UploadBufferBase::IsMapped
bool IsMapped(Uint32 Mip, Uint32 Slice) const
Definition: TextureUploaderBase.hpp:78
std
Definition: AdvancedMath.hpp:979
VERIFY_EXPR
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
Diligent::ITextureUploader
Asynchronous texture uplader.
Definition: TextureUploader.hpp:79
Diligent::UploadBufferDesc::Height
Uint32 Height
Definition: TextureUploader.hpp:42
Diligent::UploadBufferDesc::Depth
Uint32 Depth
Definition: TextureUploader.hpp:43
Diligent::TextureUploaderBase::m_pDevice
RefCntAutoPtr< IRenderDevice > m_pDevice
Definition: TextureUploaderBase.hpp:104
Diligent::UploadBufferDesc
Upload buffer description.
Definition: TextureUploader.hpp:39
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37