This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
/
ITexture.h
476 lines (421 loc) · 12.9 KB
/
ITexture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_ITEXTURE_H
#define CRYINCLUDE_CRYCOMMON_ITEXTURE_H
#pragma once
#include "Cry_Math.h"
#include "Cry_Color.h"
#include "Tarray.h"
#include <CryEngineAPI.h>
class CTexture;
#ifndef COMPILER_SUPPORTS_ENUM_SPECIFICATION
# if defined(_MSC_VER)
# define COMPILER_SUPPORTS_ENUM_SPECIFICATION 1
# else
# define COMPILER_SUPPORTS_ENUM_SPECIFICATION 0
# endif
#endif
#if COMPILER_SUPPORTS_ENUM_SPECIFICATION
enum ETEX_Type : uint8
#else
typedef uint8 ETEX_Type;
enum eTEX_Type
#endif
{
eTT_1D = 0,
eTT_2D,
eTT_3D,
eTT_Cube,
eTT_CubeArray,
eTT_Dyn2D,
eTT_User,
eTT_NearestCube,
eTT_2DArray,
eTT_2DMS,
eTT_Auto2D,
eTT_MaxTexType, // not used
};
// Texture formats
#if COMPILER_SUPPORTS_ENUM_SPECIFICATION
enum ETEX_Format : uint8
#else
typedef uint8 ETEX_Format;
enum eTEX_Format
#endif
{
eTF_Unknown = 0,
eTF_R8G8B8A8S,
eTF_R8G8B8A8 = 2, // may be saved into file
eTF_A8 = 4,
eTF_R8,
eTF_R8S,
eTF_R16,
eTF_R16F,
eTF_R32F,
eTF_R8G8,
eTF_R8G8S,
eTF_R16G16,
eTF_R16G16S,
eTF_R16G16F,
eTF_R11G11B10F,
eTF_R10G10B10A2,
eTF_R16G16B16A16,
eTF_R16G16B16A16S,
eTF_R16G16B16A16F,
eTF_R32G32B32A32F,
eTF_CTX1,
eTF_BC1 = 22, // may be saved into file
eTF_BC2 = 23, // may be saved into file
eTF_BC3 = 24, // may be saved into file
eTF_BC4U, // 3Dc+
eTF_BC4S,
eTF_BC5U, // 3Dc
eTF_BC5S,
eTF_BC6UH,
eTF_BC6SH,
eTF_BC7,
eTF_R9G9B9E5,
// hardware depth buffers
eTF_D16,
eTF_D24S8,
eTF_D32F,
eTF_D32FS8,
// only available as hardware format under DX11.1 with DXGI 1.2
eTF_B5G6R5,
eTF_B5G5R5,
eTF_B4G4R4A4,
// only available as hardware format under OpenGL
eTF_EAC_R11,
eTF_EAC_RG11,
eTF_ETC2,
eTF_ETC2A,
// only available as hardware format under DX9
eTF_A8L8,
eTF_L8,
eTF_L8V8U8,
eTF_B8G8R8,
eTF_L8V8U8X8,
eTF_B8G8R8X8,
eTF_B8G8R8A8,
eTF_PVRTC2,
eTF_PVRTC4,
eTF_ASTC_4x4,
eTF_ASTC_5x4,
eTF_ASTC_5x5,
eTF_ASTC_6x5,
eTF_ASTC_6x6,
eTF_ASTC_8x5,
eTF_ASTC_8x6,
eTF_ASTC_8x8,
eTF_ASTC_10x5,
eTF_ASTC_10x6,
eTF_ASTC_10x8,
eTF_ASTC_10x10,
eTF_ASTC_12x10,
eTF_ASTC_12x12,
// add R16 unsigned int format for hardware that do not support float point rendering
eTF_R16U,
eTF_R16G16U,
eTF_R10G10B10A2UI,
eTF_MaxFormat // unused, must be always the last in the list
};
#if COMPILER_SUPPORTS_ENUM_SPECIFICATION
enum ETEX_TileMode : uint8
#else
typedef uint8 ETEX_TileMode;
enum eTEX_TileMode
#endif
{
eTM_None = 0,
eTM_LinearPadded,
eTM_Optimal,
};
enum ETextureFlags
{
FT_NOMIPS = 0x00000001,
FT_TEX_NORMAL_MAP = 0x00000002,
FT_TEX_WAS_NOT_PRE_TILED = 0x00000004,
FT_USAGE_DEPTHSTENCIL = 0x00000008,
FT_USAGE_ALLOWREADSRGB = 0x00000010,
FT_FILESINGLE = 0x00000020, // suppress loading of additional files like _DDNDIF (faster, RC can tag the file for that)
FT_TEX_FONT = 0x00000040,
FT_HAS_ATTACHED_ALPHA = 0x00000080,
FT_USAGE_UNORDERED_ACCESS = 0x00000100,
FT_USAGE_READBACK = 0x00000200,
FT_USAGE_MSAA = 0x00000400,
FT_FORCE_MIPS = 0x00000800,
FT_USAGE_RENDERTARGET = 0x00001000,
FT_USAGE_DYNAMIC = 0x00002000,
FT_STAGE_READBACK = 0x00004000,
FT_STAGE_UPLOAD = 0x00008000,
FT_DONT_RELEASE = 0x00010000,
FT_ASYNC_PREPARE = 0x00020000,
FT_DONT_STREAM = 0x00040000,
FT_USAGE_PREDICATED_TILING = 0x00080000,
FT_FAILED = 0x00100000,
FT_FROMIMAGE = 0x00200000,
FT_STATE_CLAMP = 0x00400000,
FT_USAGE_ATLAS = 0x00800000,
FT_ALPHA = 0x01000000,
FT_REPLICATE_TO_ALL_SIDES = 0x02000000,
FT_KEEP_LOWRES_SYSCOPY = 0x04000000, // keep low res copy in system memory for voxelization on CPU
FT_SPLITTED = 0x08000000, // for split dds files
FT_USE_HTILE = 0x10000000,
FT_IGNORE_PRECACHE = 0x20000000,
FT_COMPOSITE = 0x40000000,
FT_USAGE_UAV_RWTEXTURE = 0x80000000,
};
struct SDepthTexture;
struct STextureStreamingStats
{
STextureStreamingStats(bool bComputeTexturesPerFrame)
: bComputeReuquiredTexturesPerFrame(bComputeTexturesPerFrame)
{
nMaxPoolSize = 0;
nCurrentPoolSize = 0;
nStreamedTexturesSize = 0;
nStaticTexturesSize = 0;
nThroughput = 0;
nNumTexturesPerFrame = 0;
nRequiredStreamedTexturesSize = 0;
nRequiredStreamedTexturesCount = 0;
bPoolOverflow = false;
bPoolOverflowTotally = false;
fPoolFragmentation = 0.0f;
}
size_t nMaxPoolSize;
size_t nCurrentPoolSize;
size_t nStreamedTexturesSize;
size_t nStaticTexturesSize;
uint32 nNumTexturesPerFrame;
size_t nThroughput;
size_t nRequiredStreamedTexturesSize;
uint32 nRequiredStreamedTexturesCount;
float fPoolFragmentation;
uint32 bPoolOverflow : 1;
uint32 bPoolOverflowTotally : 1;
const bool bComputeReuquiredTexturesPerFrame;
};
//////////////////////////////////////////////////////////////////////
// Texture object interface
class ITexture
{
protected:
virtual ~ITexture() {}
public:
// <interfuscator:shuffle>
virtual int AddRef() = 0;
virtual int Release() = 0;
virtual int ReleaseForce() = 0;
virtual void ApplyTexture(int nTUnit, int nState = -1) = 0;
virtual const char* GetName() const = 0;
virtual const int GetWidth() const = 0;
virtual const int GetHeight() const = 0;
virtual const int GetDepth() const = 0;
virtual const int GetTextureID() const = 0;
virtual const uint32 GetFlags() const = 0;
virtual const int GetNumMips() const = 0;
virtual const int GetRequiredMip() const = 0;
virtual const int GetDeviceDataSize() const = 0;
virtual const int GetDataSize() const = 0;
virtual const ETEX_Type GetTextureType() const = 0;
// Sets the texture type of the texture to be used before the texture is loaded.
// Once the texture is loaded the type from the file will overwrite whatever
// value was set here.
virtual void SetTextureType(ETEX_Type type) = 0;
virtual const bool IsTextureLoaded() const = 0;
virtual void PrecacheAsynchronously(float fMipFactor, int nFlags, int nUpdateId, int nCounter = 1) = 0;
virtual uint8* GetData32(int nSide = 0, int nLevel = 0, uint8* pDst = NULL, ETEX_Format eDstFormat = eTF_R8G8B8A8) = 0;
virtual bool SetFilter(int nFilter) = 0; // FILTER_ flags
virtual void SetClamp(bool bEnable) = 0; // Texture addressing set
virtual float GetAvgBrightness() const = 0;
virtual int StreamCalculateMipsSigned(float fMipFactor) const = 0;
virtual int GetStreamableMipNumber() const = 0;
virtual int GetStreamableMemoryUsage(int nStartMip) const = 0;
virtual int GetMinLoadedMip() const = 0;
using StagingHook = AZStd::function<bool(void*, uint32, uint32)>;
virtual void Readback(AZ::u32 subresourceIndex, StagingHook callback) = 0;
virtual bool Reload() = 0;
// Used for debugging/profiling.
virtual const char* GetFormatName() const = 0;
virtual const char* GetTypeName() const = 0;
virtual const bool IsStreamedVirtual() const = 0;
virtual const bool IsShared() const = 0;
virtual const bool IsStreamable() const = 0;
virtual bool IsStreamedIn(const int nMinPrecacheRoundIds[2]) const = 0;
virtual const int GetAccessFrameId() const = 0;
virtual const ETEX_Format GetTextureDstFormat() const = 0;
virtual const ETEX_Format GetTextureSrcFormat() const = 0;
virtual bool IsPostponed() const = 0;
virtual const bool IsParticularMipStreamed(float fMipFactor) const = 0;
// get low res system memory (used for CPU voxelization)
virtual const ColorB* GetLowResSystemCopy(uint16& nWidth, uint16& nHeight, int** ppLowResSystemCopyAtlasId) { return 0; }
// </interfuscator:shuffle>
void GetMemoryUsage(ICrySizer* pSizer) const
{
COMPILE_TIME_ASSERT(eTT_MaxTexType <= 255);
COMPILE_TIME_ASSERT(eTF_MaxFormat <= 255);
/*LATER*/
}
virtual void SetKeepSystemCopy(const bool bKeepSystemCopy) = 0;
};
struct STextureLoadData
{
void* m_pData;
size_t m_DataSize;
int m_Width;
int m_Height;
ETEX_Format m_Format;
int m_NumMips;
int m_nFlags;
ITexture* m_pTexture;
STextureLoadData()
: m_pData(nullptr)
, m_Width(0)
, m_Height(0)
, m_Format(eTF_Unknown)
, m_NumMips(0)
, m_nFlags(0)
, m_pTexture(nullptr)
{
}
~STextureLoadData()
{
if (m_pData)
{
free(m_pData);
}
}
};
struct ITextureLoadHandler
{
virtual ~ITextureLoadHandler() {}
virtual bool LoadTextureData(const char* path, STextureLoadData& loadData) = 0;
virtual bool SupportsExtension(const char* ext) const = 0;
virtual void Update() = 0;
};
//=========================================================================================
class IDynTexture
{
public:
enum
{
fNeedRegenerate = 1ul << 0,
};
// <interfuscator:shuffle>
virtual ~IDynTexture(){}
virtual void Release() = 0;
virtual void GetSubImageRect(uint32& nX, uint32& nY, uint32& nWidth, uint32& nHeight) = 0;
virtual void GetImageRect(uint32& nX, uint32& nY, uint32& nWidth, uint32& nHeight) = 0;
virtual int GetTextureID() = 0;
virtual void Lock() = 0;
virtual void UnLock() = 0;
virtual int GetWidth() = 0;
virtual int GetHeight() = 0;
virtual bool IsValid() = 0;
virtual uint8 GetFlags() const = 0;
virtual void SetFlags(uint8 flags) {}
virtual bool Update(int nNewWidth, int nNewHeight) = 0;
virtual void Apply(int nTUnit, int nTS = -1) = 0;
virtual bool ClearRT() = 0;
virtual bool SetRT(int nRT, bool bPush, struct SDepthTexture* pDepthSurf, bool bScreenVP = false) = 0;
virtual bool SetRectStates() = 0;
virtual bool RestoreRT(int nRT, bool bPop) = 0;
virtual ITexture* GetTexture() = 0;
virtual void SetUpdateMask() = 0;
virtual void ResetUpdateMask() = 0;
virtual bool IsSecondFrame() = 0;
virtual bool GetImageData32(uint8* pData, int nDataSize) { return 0; }
// </interfuscator:shuffle>
};
// Animating Texture sequence definition
struct STexAnim
{
int m_nRefCount;
TArray<CTexture*> m_TexPics;
int m_Rand;
int m_NumAnimTexs;
bool m_bLoop;
float m_Time;
int Size()
{
int nSize = sizeof(STexAnim);
nSize += m_TexPics.GetMemoryUsage();
return nSize;
}
void Release()
{
long refCnt = CryInterlockedDecrement(&m_nRefCount);
if (refCnt > 0)
{
return;
}
delete this;
}
void AddRef()
{
CryInterlockedIncrement(&m_nRefCount);
}
STexAnim()
{
m_nRefCount = 1;
m_Rand = 0;
m_NumAnimTexs = 0;
m_bLoop = false;
m_Time = 0.0f;
}
~STexAnim()
{
for (uint32 i = 0; i < m_TexPics.Num(); i++)
{
ITexture* pTex = (ITexture*) m_TexPics[i];
SAFE_RELEASE(pTex);
}
m_TexPics.Free();
}
STexAnim& operator = (const STexAnim& sl)
{
// make sure not same object
if (this == &sl)
{
return *this;
}
for (uint32 i = 0; i < m_TexPics.Num(); i++)
{
ITexture* pTex = (ITexture*)m_TexPics[i];
SAFE_RELEASE(pTex);
}
m_TexPics.Free();
for (uint32 i = 0; i < sl.m_TexPics.Num(); i++)
{
ITexture* pTex = (ITexture*)sl.m_TexPics[i];
if (pTex)
{
pTex->AddRef();
}
m_TexPics.AddElem(sl.m_TexPics[i]);
}
m_Rand = sl.m_Rand;
m_NumAnimTexs = sl.m_NumAnimTexs;
m_bLoop = sl.m_bLoop;
m_Time = sl.m_Time;
return *this;
}
};
struct STexComposition
{
_smart_ptr<ITexture> pTexture;
uint16 nSrcSlice;
uint16 nDstSlice;
};
#endif // CRYINCLUDE_CRYCOMMON_ITEXTURE_H