Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/Graphics/GraphicsEngine/interface/Texture.h Source File

Diligent Engine API Reference

Texture.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 "DeviceObject.h"
30
31 namespace Diligent
32 {
33
34 // {A64B0E60-1B5E-4CFD-B880-663A1ADCBE98}
35 static constexpr INTERFACE_ID IID_Texture =
36 { 0xa64b0e60, 0x1b5e, 0x4cfd, { 0xb8, 0x80, 0x66, 0x3a, 0x1a, 0xdc, 0xbe, 0x98 } };
37
39 struct DepthStencilClearValue
40 {
42 Float32 Depth;
44 Uint8 Stencil;
45 DepthStencilClearValue() :
46 Depth(1.f),
47 Stencil(0)
48 {}
49 };
50
52 struct OptimizedClearValue
53 {
55 TEXTURE_FORMAT Format;
57 Float32 Color[ 4 ];
59 DepthStencilClearValue DepthStencil;
60 OptimizedClearValue() :
61 Format(TEX_FORMAT_UNKNOWN)
62 {
63 Color[0] = 0;
64 Color[1] = 0;
65 Color[2] = 0;
66 Color[3] = 0;
67 }
68
69 bool operator == (const OptimizedClearValue& rhs)const
70 {
71 return Format == rhs.Format &&
72 Color[0] == rhs.Color[0] &&
73 Color[1] == rhs.Color[1] &&
74 Color[2] == rhs.Color[2] &&
75 Color[3] == rhs.Color[3] &&
76 DepthStencil.Depth == rhs.DepthStencil.Depth &&
77 DepthStencil.Stencil == rhs.DepthStencil.Stencil;
78 }
79 };
80
82 struct TextureDesc : DeviceObjectAttribs
83 {
85 RESOURCE_DIMENSION Type;
86
88 Uint32 Width;
89
91 Uint32 Height;
92 union
93 {
95 Uint32 ArraySize;
96
98 Uint32 Depth;
99 };
100
102 TEXTURE_FORMAT Format;
103
106 Uint32 MipLevels;
107
110 Uint32 SampleCount;
111
113 USAGE Usage;
114
120 Uint32 BindFlags;
121
124 Uint32 CPUAccessFlags;
125
126
128 Uint32 MiscFlags;
129
131 OptimizedClearValue ClearValue;
132
134
149 TextureDesc() :
150 Type(RESOURCE_DIM_UNDEFINED),
151 Width(0),
152 Height(0),
153 ArraySize(1),
154 Format(TEX_FORMAT_UNKNOWN),
155 MipLevels(1),
156 SampleCount(1),
157 Usage(USAGE_DEFAULT),
158 BindFlags(0),
159 CPUAccessFlags(0),
160 MiscFlags(0)
161 {
162 }
163
165
172 bool operator ==(const TextureDesc& RHS)const
173 {
174 // Name is primarily used for debug purposes and does not affect the state.
175 // It is ignored in comparison operation.
176 return // strcmp(Name, RHS.Name) == 0 &&
177 Type == RHS.Type &&
178 Width == RHS.Width &&
179 Height == RHS.Height &&
180 ArraySize == RHS.ArraySize &&
181 Format == RHS.Format &&
182 MipLevels == RHS.MipLevels &&
183 SampleCount == RHS.SampleCount &&
184 Usage == RHS.Usage &&
185 BindFlags == RHS.BindFlags &&
186 CPUAccessFlags == RHS.CPUAccessFlags &&
187 MiscFlags == RHS.MiscFlags &&
188 ClearValue == RHS.ClearValue;
189 }
190 };
191
193 struct TextureSubResData
194 {
197 const void* pData;
198
201 class IBuffer *pSrcBuffer;
202
204 Uint32 Stride;
205
208 Uint32 DepthStride;
209
211
218 TextureSubResData():
219 pData(nullptr),
220 pSrcBuffer(nullptr),
221 Stride(0),
222 DepthStride(0)
223 {}
224
226 TextureSubResData(void *_pData, Uint32 _Stride, Uint32 _DepthStride=0) :
227 pData(_pData),
228 pSrcBuffer(nullptr),
229 Stride(_Stride),
230 DepthStride(_DepthStride)
231 {}
232
234 TextureSubResData(IBuffer *_pBuffer, Uint32 _Stride, Uint32 _DepthStride=0) :
235 pData(nullptr),
236 pSrcBuffer(_pBuffer),
237 Stride(_Stride),
238 DepthStride(_DepthStride)
239 {}
240 };
241
243 struct TextureData
244 {
247 TextureSubResData *pSubResources;
248
253 Uint32 NumSubresources;
254
256
262 TextureData() :
263 pSubResources(nullptr),
264 NumSubresources(0)
265 {}
266 };
267
268 struct MappedTextureSubresource
269 {
270 PVoid pData = nullptr;
271 Uint32 Stride = 0;
272 Uint32 DepthStride = 0;
273 };
274
276 class ITexture : public IDeviceObject
277 {
278 public:
280 virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0;
281
283 virtual const TextureDesc& GetDesc()const = 0;
284
286
304 virtual void CreateView(const struct TextureViewDesc &ViewDesc, class ITextureView **ppView) = 0;
305
307
313 virtual ITextureView* GetDefaultView( TEXTURE_VIEW_TYPE ViewType ) = 0;
314
316
322 virtual void UpdateData( class IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData ) = 0;
323
325
339 virtual void CopyData(IDeviceContext *pContext,
340 ITexture *pSrcTexture,
341 Uint32 SrcMipLevel,
342 Uint32 SrcSlice,
343 const Box *pSrcBox,
344 Uint32 DstMipLevel,
345 Uint32 DstSlice,
346 Uint32 DstX,
347 Uint32 DstY,
348 Uint32 DstZ) = 0;
349
351 virtual void Map( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData ) = 0;
353 virtual void Unmap( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags ) = 0;
354
356
360 virtual void* GetNativeHandle() = 0;
361 };
362
363 }
Diligent::TEXTURE_FORMAT
TEXTURE_FORMAT
Texture formats.
Definition: GraphicsTypes.h:244
Diligent::ITexture::UpdateData
virtual void UpdateData(class IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData)=0
Updates the data in the texture.
Diligent::TextureDesc
Texture description.
Definition: Texture.h:82
Diligent::TEXTURE_VIEW_TYPE
TEXTURE_VIEW_TYPE
Texture view type.
Definition: GraphicsTypes.h:190
Diligent::IDeviceObject
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:40
Diligent::TextureDesc::MiscFlags
Uint32 MiscFlags
Miscellaneous flags, see Diligent::MISC_TEXTURE_FLAG for details.
Definition: Texture.h:128
Diligent::TEX_FORMAT_UNKNOWN
Unknown format.
Definition: GraphicsTypes.h:247
Diligent::ITexture::GetDesc
virtual const TextureDesc & GetDesc() const =0
Returns the texture description used to create the object.
Diligent::TextureDesc::Depth
Uint32 Depth
For a 3D texture, number of depth slices.
Definition: Texture.h:98
Diligent
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Diligent::TextureSubResData::TextureSubResData
TextureSubResData(void *_pData, Uint32 _Stride, Uint32 _DepthStride=0)
Initializes the structure members to perform copy from the CPU memory.
Definition: Texture.h:226
Diligent::ITexture::CopyData
virtual void CopyData(IDeviceContext *pContext, ITexture *pSrcTexture, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, Uint32 DstMipLevel, Uint32 DstSlice, Uint32 DstX, Uint32 DstY, Uint32 DstZ)=0
Copies data from another texture.
Diligent::TextureSubResData::pSrcBuffer
class IBuffer * pSrcBuffer
Pointer to the GPU buffer that contains subresource data. If provided, pData must be null...
Definition: Texture.h:201
Diligent::TextureSubResData
Describes data for one subresource.
Definition: Texture.h:193
Diligent::TextureDesc::Format
TEXTURE_FORMAT Format
Texture format, see Diligent::TEXTURE_FORMAT.
Definition: Texture.h:102
Diligent::TextureSubResData::DepthStride
Uint32 DepthStride
For 3D textures, depth slice stride in bytes.
Definition: Texture.h:208
Diligent::ITexture::Unmap
virtual void Unmap(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags)=0
Unmap the textute - not implemented yet.
Diligent::TextureDesc::TextureDesc
TextureDesc()
Initializes the structure members with default values.
Definition: Texture.h:149
Diligent::TextureDesc::operator==
bool operator==(const TextureDesc &RHS) const
Tests if two structures are equivalent.
Definition: Texture.h:172
Diligent::OptimizedClearValue::Format
TEXTURE_FORMAT Format
Format.
Definition: Texture.h:55
Diligent::TextureDesc::MipLevels
Uint32 MipLevels
Number of Mip levels in the texture. Multisampled textures can only have 1 Mip level. Specify 0 to generate full mipmap chain.
Definition: Texture.h:106
Diligent::TextureDesc::Width
Uint32 Width
Texture width, in pixels.
Definition: Texture.h:88
Diligent::DepthStencilClearValue::Depth
Float32 Depth
Depth clear value.
Definition: Texture.h:42
Diligent::TextureDesc::SampleCount
Uint32 SampleCount
Number of samples. Only 2D textures or 2D texture arrays can be multisampled.
Definition: Texture.h:110
Diligent::TextureData
Describes the initial data to store in the texture.
Definition: Texture.h:243
Diligent::TextureSubResData::TextureSubResData
TextureSubResData()
Initializes the structure members with default values.
Definition: Texture.h:218
Diligent::IBuffer
Buffer interface.
Definition: Buffer.h:200
Diligent::ITexture::Map
virtual void Map(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData)=0
Map the texture - not implemented yet.
Diligent::IDeviceContext
Device context interface.
Definition: DeviceContext.h:443
Diligent::TextureDesc::CPUAccessFlags
Uint32 CPUAccessFlags
CPU access flags or 0 if no CPU access is allowed, see Diligent::CPU_ACCESS_FLAG for details...
Definition: Texture.h:124
Diligent::ITexture::GetNativeHandle
virtual void * GetNativeHandle()=0
Returns native texture handle specific to the underlying graphics API.
Diligent::Box
Box.
Definition: GraphicsTypes.h:1005
Diligent::ITexture::GetDefaultView
virtual ITextureView * GetDefaultView(TEXTURE_VIEW_TYPE ViewType)=0
Returns the pointer to the default view.
Diligent::USAGE_DEFAULT
A resource that requires read and write access by the GPU and can also be occasionally written by the...
Definition: GraphicsTypes.h:95
Diligent::ITextureView
Texture view interface.
Definition: TextureView.h:163
Diligent::ITexture::QueryInterface
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface)=0
Queries the specific interface, see IObject::QueryInterface() for details.
Diligent::TextureDesc::Usage
USAGE Usage
Texture usage. See Diligent::USAGE for details.
Definition: Texture.h:113
Diligent::TextureViewDesc
Texture view description.
Definition: TextureView.h:55
Diligent::DepthStencilClearValue::Stencil
Uint8 Stencil
Stencil clear value.
Definition: Texture.h:44
Diligent::ITexture::CreateView
virtual void CreateView(const struct TextureViewDesc &ViewDesc, class ITextureView **ppView)=0
Creates a new texture view.
Diligent::TextureDesc::ArraySize
Uint32 ArraySize
For a 1D array or 2D array, number of array slices.
Definition: Texture.h:95
Diligent::USAGE
USAGE
Resource usage.
Definition: GraphicsTypes.h:84
Diligent::DepthStencilClearValue
Defines optimized depth-stencil clear value.
Definition: Texture.h:39
Diligent::OptimizedClearValue
Defines optimized clear value.
Definition: Texture.h:52
Diligent::RESOURCE_DIMENSION
RESOURCE_DIMENSION
Describes resource dimension.
Definition: GraphicsTypes.h:172
Diligent::OptimizedClearValue::Color
Float32 Color[4]
Render target clear value.
Definition: Texture.h:57
Diligent::TextureDesc::ClearValue
OptimizedClearValue ClearValue
Optimized clear value.
Definition: Texture.h:131
Diligent::TextureDesc::Type
RESOURCE_DIMENSION Type
Texture type. See Diligent::RESOURCE_DIMENSION for details.
Definition: Texture.h:85
Diligent::TextureData::NumSubresources
Uint32 NumSubresources
Number of elements in pSubResources array. NumSubresources must exactly match the number of subresour...
Definition: Texture.h:253
Diligent::TextureSubResData::TextureSubResData
TextureSubResData(IBuffer *_pBuffer, Uint32 _Stride, Uint32 _DepthStride=0)
Initializes the structure members to perform copy from the GPU buffer.
Definition: Texture.h:234
Diligent::DeviceObjectAttribs
Describes common device object attributes.
Definition: GraphicsTypes.h:900
Diligent::TextureSubResData::pData
const void * pData
Pointer to the subresource data in CPU memory. If provided, pSrcBuffer must be null.
Definition: Texture.h:197
Diligent::TextureDesc::Height
Uint32 Height
Texture height, in pixels.
Definition: Texture.h:91
Diligent::RESOURCE_DIM_UNDEFINED
Texture type undefined.
Definition: GraphicsTypes.h:174
Diligent::TextureData::TextureData
TextureData()
Initializes the structure members with default values.
Definition: Texture.h:262
Diligent::MAP_TYPE
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125
Diligent::TextureDesc::BindFlags
Uint32 BindFlags
Bind flags, see Diligent::BIND_FLAGS for details. The following bind flags are allowed: Diligent::BI...
Definition: Texture.h:120
Diligent::ITexture
Texture inteface.
Definition: Texture.h:276
Diligent::TextureData::pSubResources
TextureSubResData * pSubResources
Pointer to the array of the TextureSubResData elements containing information about each subresource...
Definition: Texture.h:247
Diligent::OptimizedClearValue::DepthStencil
DepthStencilClearValue DepthStencil
Depth stencil clear value.
Definition: Texture.h:59
Diligent::TextureSubResData::Stride
Uint32 Stride
For 2D and 3D textures, row stride in bytes.
Definition: Texture.h:204