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 
40 {
42  Float32 Depth;
44  Uint8 Stencil;
46  Depth(1.f),
47  Stencil(0)
48  {}
49 };
50 
53 {
57  Float32 Color[ 4 ];
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] &&
78  }
79 };
80 
83 {
86 
88  Uint32 Width;
89 
91  Uint32 Height;
92  union
93  {
95  Uint32 ArraySize;
96 
98  Uint32 Depth;
99  };
100 
103 
106  Uint32 MipLevels;
107 
110  Uint32 SampleCount;
111 
114 
120  Uint32 BindFlags;
121 
125 
126 
128  Uint32 MiscFlags;
129 
132 
134 
151  Width(0),
152  Height(0),
153  ArraySize(1),
155  MipLevels(1),
156  SampleCount(1),
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 &&
187  MiscFlags == RHS.MiscFlags &&
188  ClearValue == RHS.ClearValue;
189  }
190 };
191 
194 {
197  const void* pData;
198 
202 
204  Uint32 Stride;
205 
208  Uint32 DepthStride;
209 
211 
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 
244 {
248 
254 
256 
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 }
TEXTURE_FORMAT
Texture formats.
Definition: GraphicsTypes.h:244
virtual void UpdateData(class IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData)=0
Updates the data in the texture.
Texture description.
Definition: Texture.h:82
TEXTURE_VIEW_TYPE
Texture view type.
Definition: GraphicsTypes.h:190
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:40
Uint32 MiscFlags
Miscellaneous flags, see Diligent::MISC_TEXTURE_FLAG for details.
Definition: Texture.h:128
Unknown format.
Definition: GraphicsTypes.h:247
virtual const TextureDesc & GetDesc() const =0
Returns the texture description used to create the object.
Uint32 Depth
For a 3D texture, number of depth slices.
Definition: Texture.h:98
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
TextureSubResData(void *_pData, Uint32 _Stride, Uint32 _DepthStride=0)
Initializes the structure members to perform copy from the CPU memory.
Definition: Texture.h:226
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.
class IBuffer * pSrcBuffer
Pointer to the GPU buffer that contains subresource data. If provided, pData must be null...
Definition: Texture.h:201
Describes data for one subresource.
Definition: Texture.h:193
TEXTURE_FORMAT Format
Texture format, see Diligent::TEXTURE_FORMAT.
Definition: Texture.h:102
Uint32 DepthStride
For 3D textures, depth slice stride in bytes.
Definition: Texture.h:208
virtual void Unmap(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags)=0
Unmap the textute - not implemented yet.
TextureDesc()
Initializes the structure members with default values.
Definition: Texture.h:149
bool operator==(const TextureDesc &RHS) const
Tests if two structures are equivalent.
Definition: Texture.h:172
TEXTURE_FORMAT Format
Format.
Definition: Texture.h:55
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
Uint32 Width
Texture width, in pixels.
Definition: Texture.h:88
Float32 Depth
Depth clear value.
Definition: Texture.h:42
Uint32 SampleCount
Number of samples. Only 2D textures or 2D texture arrays can be multisampled.
Definition: Texture.h:110
Describes the initial data to store in the texture.
Definition: Texture.h:243
TextureSubResData()
Initializes the structure members with default values.
Definition: Texture.h:218
Buffer interface.
Definition: Buffer.h:200
virtual void Map(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData)=0
Map the texture - not implemented yet.
Device context interface.
Definition: DeviceContext.h:443
Uint32 CPUAccessFlags
CPU access flags or 0 if no CPU access is allowed, see Diligent::CPU_ACCESS_FLAG for details...
Definition: Texture.h:124
virtual void * GetNativeHandle()=0
Returns native texture handle specific to the underlying graphics API.
Box.
Definition: GraphicsTypes.h:1005
virtual ITextureView * GetDefaultView(TEXTURE_VIEW_TYPE ViewType)=0
Returns the pointer to the default view.
A resource that requires read and write access by the GPU and can also be occasionally written by the...
Definition: GraphicsTypes.h:95
Texture view interface.
Definition: TextureView.h:163
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface)=0
Queries the specific interface, see IObject::QueryInterface() for details.
USAGE Usage
Texture usage. See Diligent::USAGE for details.
Definition: Texture.h:113
Texture view description.
Definition: TextureView.h:55
Uint8 Stencil
Stencil clear value.
Definition: Texture.h:44
virtual void CreateView(const struct TextureViewDesc &ViewDesc, class ITextureView **ppView)=0
Creates a new texture view.
Uint32 ArraySize
For a 1D array or 2D array, number of array slices.
Definition: Texture.h:95
USAGE
Resource usage.
Definition: GraphicsTypes.h:84
Defines optimized depth-stencil clear value.
Definition: Texture.h:39
Defines optimized clear value.
Definition: Texture.h:52
RESOURCE_DIMENSION
Describes resource dimension.
Definition: GraphicsTypes.h:172
Float32 Color[4]
Render target clear value.
Definition: Texture.h:57
OptimizedClearValue ClearValue
Optimized clear value.
Definition: Texture.h:131
RESOURCE_DIMENSION Type
Texture type. See Diligent::RESOURCE_DIMENSION for details.
Definition: Texture.h:85
Uint32 NumSubresources
Number of elements in pSubResources array. NumSubresources must exactly match the number of subresour...
Definition: Texture.h:253
TextureSubResData(IBuffer *_pBuffer, Uint32 _Stride, Uint32 _DepthStride=0)
Initializes the structure members to perform copy from the GPU buffer.
Definition: Texture.h:234
Describes common device object attributes.
Definition: GraphicsTypes.h:900
const void * pData
Pointer to the subresource data in CPU memory. If provided, pSrcBuffer must be null.
Definition: Texture.h:197
Uint32 Height
Texture height, in pixels.
Definition: Texture.h:91
Texture type undefined.
Definition: GraphicsTypes.h:174
TextureData()
Initializes the structure members with default values.
Definition: Texture.h:262
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125
Uint32 BindFlags
Bind flags, see Diligent::BIND_FLAGS for details. The following bind flags are allowed: Diligent::BI...
Definition: Texture.h:120
Texture inteface.
Definition: Texture.h:276
TextureSubResData * pSubResources
Pointer to the array of the TextureSubResData elements containing information about each subresource...
Definition: Texture.h:247
DepthStencilClearValue DepthStencil
Depth stencil clear value.
Definition: Texture.h:59
Uint32 Stride
For 2D and 3D textures, row stride in bytes.
Definition: Texture.h:204