Diligent Engine  v.2.4.g
Texture.h
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 // clang-format off
31 
34 
35 #include "GraphicsTypes.h"
36 #include "DeviceObject.h"
37 #include "TextureView.h"
38 
40 
41 
42 // {A64B0E60-1B5E-4CFD-B880-663A1ADCBE98}
43 static const INTERFACE_ID IID_Texture =
44  {0xa64b0e60, 0x1b5e, 0x4cfd,{0xb8, 0x80, 0x66, 0x3a, 0x1a, 0xdc, 0xbe, 0x98}};
45 
48 
51 
54 
57 
58  union
59  {
62 
65  };
66 
69 
73 
76  Uint32 SampleCount DEFAULT_INITIALIZER(1);
77 
80 
87 
91 
94 
97 
99  Uint64 CommandQueueMask DEFAULT_INITIALIZER(1);
100 
101 
102 #if DILIGENT_CPP_INTERFACE
103  TextureDesc()noexcept{}
104 
106  Uint32 _Width,
107  Uint32 _Height,
108  Uint32 _ArraySizeOrDepth,
109  TEXTURE_FORMAT _Format,
110  Uint32 _MipLevels = TextureDesc{}.MipLevels,
111  Uint32 _SampleCount = TextureDesc{}.SampleCount,
112  USAGE _Usage = TextureDesc{}.Usage,
113  BIND_FLAGS _BindFlags = TextureDesc{}.BindFlags,
114  CPU_ACCESS_FLAGS _CPUAccessFlags = TextureDesc{}.CPUAccessFlags,
117  Uint64 _CommandQueueMask = TextureDesc{}.CommandQueueMask) :
118  Type {_Type },
119  Width {_Width },
120  Height {_Height },
121  ArraySize {_ArraySizeOrDepth},
122  Format {_Format },
123  MipLevels {_MipLevels },
124  SampleCount {_SampleCount },
125  Usage {_Usage },
126  BindFlags {_BindFlags },
127  CPUAccessFlags {_CPUAccessFlags },
128  MiscFlags {_MiscFlags },
129  ClearValue {_ClearValue },
130  CommandQueueMask {_CommandQueueMask}
131  {}
132 
134 
141  bool operator ==(const TextureDesc& RHS)const
142  {
143  // Name is primarily used for debug purposes and does not affect the state.
144  // It is ignored in comparison operation.
145  return // strcmp(Name, RHS.Name) == 0 &&
146  Type == RHS.Type &&
147  Width == RHS.Width &&
148  Height == RHS.Height &&
149  ArraySize == RHS.ArraySize &&
150  Format == RHS.Format &&
151  MipLevels == RHS.MipLevels &&
152  SampleCount == RHS.SampleCount &&
153  Usage == RHS.Usage &&
154  BindFlags == RHS.BindFlags &&
155  CPUAccessFlags == RHS.CPUAccessFlags &&
156  MiscFlags == RHS.MiscFlags &&
157  ClearValue == RHS.ClearValue &&
158  CommandQueueMask == RHS.CommandQueueMask;
159  }
160 #endif
161 };
162 typedef struct TextureDesc TextureDesc;
163 
166 {
169  const void* pData DEFAULT_INITIALIZER(nullptr);
170 
173  struct IBuffer* pSrcBuffer DEFAULT_INITIALIZER(nullptr);
174 
178 
181 
184  Uint32 DepthStride DEFAULT_INITIALIZER(0);
185 
186 
187 #if DILIGENT_CPP_INTERFACE
188 
197  TextureSubResData()noexcept{}
198 
200  TextureSubResData(const void* _pData, Uint32 _Stride, Uint32 _DepthStride = 0)noexcept :
201  pData (_pData),
202  pSrcBuffer (nullptr),
203  SrcOffset (0),
204  Stride (_Stride),
205  DepthStride (_DepthStride)
206  {}
207 
209  TextureSubResData(IBuffer* _pBuffer, Uint32 _SrcOffset, Uint32 _Stride, Uint32 _DepthStride = 0)noexcept :
210  pData {nullptr },
211  pSrcBuffer {_pBuffer },
212  SrcOffset {_SrcOffset },
213  Stride {_Stride },
214  DepthStride {_DepthStride}
215  {}
216 #endif
217 };
219 
222 {
225  TextureSubResData* pSubResources DEFAULT_INITIALIZER(nullptr);
226 
231  Uint32 NumSubresources DEFAULT_INITIALIZER(0);
232 
233 #if DILIGENT_CPP_INTERFACE
234  TextureData() noexcept {}
235 
237  Uint32 _NumSubresources) noexcept :
238  pSubResources {_pSubResources },
239  NumSubresources {_NumSubresources}
240  {}
241 #endif
242 };
243 typedef struct TextureData TextureData;
244 
246 {
247  PVoid pData DEFAULT_INITIALIZER(nullptr);
249  Uint32 DepthStride DEFAULT_INITIALIZER(0);
250 
251 #if DILIGENT_CPP_INTERFACE
253 
255  Uint32 _Stride,
256  Uint32 _DepthStride = 0) noexcept :
257  pData {_pData },
258  Stride {_Stride },
259  DepthStride {_DepthStride}
260  {}
261 #endif
262 };
264 
265 #define DILIGENT_INTERFACE_NAME ITexture
266 #include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
267 
268 #define ITextureInclusiveMethods \
269  IDeviceObjectInclusiveMethods; \
270  ITextureMethods Texture
271 
274 {
275 #if DILIGENT_CPP_INTERFACE
276  virtual const TextureDesc& METHOD(GetDesc)()const override = 0;
278 #endif
279 
281 
299  VIRTUAL void METHOD(CreateView)(THIS_
300  const TextureViewDesc REF ViewDesc,
301  ITextureView** ppView) PURE;
302 
304 
310  VIRTUAL ITextureView* METHOD(GetDefaultView)(THIS_
311  TEXTURE_VIEW_TYPE ViewType) PURE;
312 
313 
315 
319  VIRTUAL void* METHOD(GetNativeHandle)(THIS) PURE;
320 
322 
328  VIRTUAL void METHOD(SetState)(THIS_
329  RESOURCE_STATE State) PURE;
330 
333 };
335 
336 #include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
337 
338 #if DILIGENT_C_INTERFACE
339 
340 // clang-format off
341 
342 # define ITexture_GetDesc(This) (const struct TextureDesc*)IDeviceObject_GetDesc(This)
343 
344 # define ITexture_CreateView(This, ...) CALL_IFACE_METHOD(Texture, CreateView, This, __VA_ARGS__)
345 # define ITexture_GetDefaultView(This, ...) CALL_IFACE_METHOD(Texture, GetDefaultView, This, __VA_ARGS__)
346 # define ITexture_GetNativeHandle(This) CALL_IFACE_METHOD(Texture, GetNativeHandle, This)
347 # define ITexture_SetState(This, ...) CALL_IFACE_METHOD(Texture, SetState, This, __VA_ARGS__)
348 # define ITexture_GetState(This) CALL_IFACE_METHOD(Texture, GetState, This)
349 
350 // clang-format on
351 
352 #endif
353 
354 DILIGENT_END_NAMESPACE // namespace Diligent
DILIGENT_END_INTERFACE
#define DILIGENT_END_INTERFACE
Definition: DefineInterfaceHelperMacros.h:88
Diligent::MISC_TEXTURE_FLAG_NONE
@ MISC_TEXTURE_FLAG_NONE
Definition: GraphicsTypes.h:977
Diligent::INTERFACE_ID
struct INTERFACE_ID INTERFACE_ID
Definition: InterfaceID.h:54
Diligent::TextureDesc::ArraySize
Uint32 ArraySize
For a 1D array or 2D array, number of array slices.
Definition: Texture.h:61
Diligent::CPU_ACCESS_FLAGS
CPU_ACCESS_FLAGS
Allowed CPU access mode flags when mapping a resource.
Definition: GraphicsTypes.h:191
VIRTUAL
#define VIRTUAL
Definition: DefineInterfaceHelperMacros.h:83
Diligent::TextureDesc::Depth
Uint32 Depth
For a 3D texture, number of depth slices.
Definition: Texture.h:64
Diligent::PVoid
void * PVoid
Definition: BasicTypes.h:56
TextureView.h
Diligent::TextureData::TextureData
TextureData(TextureSubResData *_pSubResources, Uint32 _NumSubresources) noexcept
Definition: Texture.h:236
Diligent::TextureDesc
struct TextureDesc TextureDesc
Definition: Texture.h:162
Diligent::TextureDesc::TextureDesc
TextureDesc() noexcept
Definition: Texture.h:103
Diligent::TextureData::TextureData
TextureData() noexcept
Definition: Texture.h:234
Diligent::TextureDesc::Format
TEXTURE_FORMAT Format
Texture format, see Diligent::TEXTURE_FORMAT.
Definition: Texture.h:68
Diligent::OptimizedClearValue
struct OptimizedClearValue OptimizedClearValue
Definition: GraphicsTypes.h:1192
Diligent::TextureSubResData::TextureSubResData
TextureSubResData(const void *_pData, Uint32 _Stride, Uint32 _DepthStride=0) noexcept
Initializes the structure members to perform copy from the CPU memory.
Definition: Texture.h:200
Diligent::USAGE
USAGE
Resource usage.
Definition: GraphicsTypes.h:143
DILIGENT_BEGIN_INTERFACE
#define DILIGENT_BEGIN_INTERFACE(Name, Base)
Definition: CommonDefinitions.h:97
Diligent::Uint64
uint64_t Uint64
64-bit unsigned integer
Definition: BasicTypes.h:50
Diligent::TextureDesc::MiscFlags
MISC_TEXTURE_FLAGS MiscFlags
Miscellaneous flags, see Diligent::MISC_TEXTURE_FLAGS for details.
Definition: Texture.h:93
Diligent::operator==
bool operator==(const Plane3D &p1, const Plane3D &p2)
Definition: AdvancedMath.hpp:442
Diligent::ITextureView
Texture view interface.
Definition: TextureView.h:202
Diligent::MappedTextureSubresource
Definition: Texture.h:245
Diligent::TEXTURE_VIEW_TYPE
TEXTURE_VIEW_TYPE
Texture view type.
Definition: GraphicsTypes.h:274
Diligent::IDeviceObject
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:52
THIS
#define THIS
Definition: DefineInterfaceHelperMacros.h:81
Diligent::IBuffer
Buffer interface.
Definition: Buffer.h:187
Diligent::TEX_FORMAT_UNKNOWN
@ TEX_FORMAT_UNKNOWN
Unknown format.
Definition: GraphicsTypes.h:331
Diligent::MappedTextureSubresource::MappedTextureSubresource
MappedTextureSubresource() noexcept
Definition: Texture.h:252
PURE
#define PURE
Definition: DefineInterfaceHelperMacros.h:85
Diligent::DeviceObjectAttribs
Describes common device object attributes.
Definition: GraphicsTypes.h:1196
Diligent::BIND_FLAGS
BIND_FLAGS
Resource binding flags.
Definition: GraphicsTypes.h:115
Diligent::TextureDesc
Texture description.
Definition: Texture.h:47
DILIGENT_END_NAMESPACE
#define DILIGENT_END_NAMESPACE
Definition: CommonDefinitions.h:86
Diligent::TextureDesc::Width
Uint32 Width
Texture width, in pixels.
Definition: Texture.h:53
CONST
#define CONST
Definition: DefineInterfaceHelperMacros.h:84
DILIGENT_DERIVE
#define DILIGENT_DERIVE(TypeName)
Definition: CommonDefinitions.h:90
Diligent::TextureData
Describes the initial data to store in the texture.
Definition: Texture.h:221
Type
const D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type
Definition: PipelineStateD3D12Impl.cpp:69
Diligent::RESOURCE_DIM_UNDEFINED
@ RESOURCE_DIM_UNDEFINED
Texture type undefined.
Definition: GraphicsTypes.h:258
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
DEFAULT_INITIALIZER
#define DEFAULT_INITIALIZER(x)
Definition: CommonDefinitions.h:93
Diligent::TextureDesc::MipLevels
Uint32 MipLevels
Number of Mip levels in the texture. Multisampled textures can only have 1 Mip level....
Definition: Texture.h:72
Diligent::TextureDesc::TextureDesc
TextureDesc(RESOURCE_DIMENSION _Type, Uint32 _Width, Uint32 _Height, Uint32 _ArraySizeOrDepth, TEXTURE_FORMAT _Format, Uint32 _MipLevels=TextureDesc{}.MipLevels, Uint32 _SampleCount=TextureDesc{}.SampleCount, USAGE _Usage=TextureDesc{}.Usage, BIND_FLAGS _BindFlags=TextureDesc{}.BindFlags, CPU_ACCESS_FLAGS _CPUAccessFlags=TextureDesc{}.CPUAccessFlags, MISC_TEXTURE_FLAGS _MiscFlags=TextureDesc{}.MiscFlags, OptimizedClearValue _ClearValue=TextureDesc{}.ClearValue, Uint64 _CommandQueueMask=TextureDesc{}.CommandQueueMask)
Definition: Texture.h:105
Diligent::MappedTextureSubresource::MappedTextureSubresource
MappedTextureSubresource(PVoid _pData, Uint32 _Stride, Uint32 _DepthStride=0) noexcept
Definition: Texture.h:254
Diligent::TextureSubResData::TextureSubResData
TextureSubResData(IBuffer *_pBuffer, Uint32 _SrcOffset, Uint32 _Stride, Uint32 _DepthStride=0) noexcept
Initializes the structure members to perform copy from the GPU buffer.
Definition: Texture.h:209
DeviceObject.h
Diligent::TEXTURE_FORMAT
TEXTURE_FORMAT
Texture formats.
Definition: GraphicsTypes.h:328
Diligent::TextureDesc::BindFlags
BIND_FLAGS BindFlags
Bind flags, see Diligent::BIND_FLAGS for details. The following bind flags are allowed: Diligent::BI...
Definition: Texture.h:86
REF
#define REF
Definition: DefineGlobalFuncHelperMacros.h:39
METHOD
#define METHOD(Name)
Definition: DefineInterfaceHelperMacros.h:87
Diligent::TextureSubResData::TextureSubResData
TextureSubResData() noexcept
Initializes the structure members with default values.
Definition: Texture.h:197
Diligent::OptimizedClearValue
Defines optimized clear value.
Definition: GraphicsTypes.h:1168
Diligent::BIND_NONE
@ BIND_NONE
Undefined binding.
Definition: GraphicsTypes.h:117
Diligent::TextureDesc::Usage
USAGE Usage
Texture usage. See Diligent::USAGE for details.
Definition: Texture.h:79
DILIGENT_BEGIN_NAMESPACE
#define DILIGENT_BEGIN_NAMESPACE(Name)
Definition: CommonDefinitions.h:82
GraphicsTypes.h
Diligent::TextureDesc::CommandQueueMask
Uint64 CommandQueueMask
Defines which command queues this texture can be used with.
Definition: Texture.h:99
Diligent::RESOURCE_STATE
RESOURCE_STATE
Resource usage state.
Definition: GraphicsTypes.h:2814
Diligent::RESOURCE_DIMENSION
RESOURCE_DIMENSION
Describes resource dimension.
Definition: GraphicsTypes.h:256
Diligent::TextureDesc::Type
RESOURCE_DIMENSION Type
Texture type. See Diligent::RESOURCE_DIMENSION for details.
Definition: Texture.h:50
Diligent::TextureViewDesc
Texture view description.
Definition: TextureView.h:80
Diligent::TextureDesc::CPUAccessFlags
CPU_ACCESS_FLAGS CPUAccessFlags
CPU access flags or 0 if no CPU access is allowed, see Diligent::CPU_ACCESS_FLAGS for details.
Definition: Texture.h:90
Diligent::MISC_TEXTURE_FLAGS
MISC_TEXTURE_FLAGS
Miscellaneous texture flags.
Definition: GraphicsTypes.h:975
Diligent::CPU_ACCESS_NONE
@ CPU_ACCESS_NONE
No CPU access.
Definition: GraphicsTypes.h:193
Diligent::ITexture
Texture inteface.
Definition: Texture.h:273
Diligent::TextureDesc::Height
Uint32 Height
Texture height, in pixels.
Definition: Texture.h:56
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::TextureDesc::SampleCount
Uint32 SampleCount
Number of samples. Only 2D textures or 2D texture arrays can be multisampled.
Definition: Texture.h:76
THIS_
#define THIS_
Definition: DefineInterfaceHelperMacros.h:82
Diligent::TextureSubResData
Describes data for one subresource.
Definition: Texture.h:165
Diligent::TextureDesc::ClearValue
OptimizedClearValue ClearValue
Optimized clear value.
Definition: Texture.h:96
Diligent::USAGE_DEFAULT
@ USAGE_DEFAULT
A resource that requires read and write access by the GPU and can also be occasionally written by the...
Definition: GraphicsTypes.h:156