forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.h
More file actions
476 lines (376 loc) · 15.6 KB
/
Copy pathtexture.h
File metadata and controls
476 lines (376 loc) · 15.6 KB
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
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/***********************************************************************************************
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
***********************************************************************************************
* *
* Project Name : WW3D *
* *
* $Archive:: /Commando/Code/ww3d2/texture.h $*
* *
* $Org Author:: Jani_p $*
* *
* Author : Kenny Mitchell *
* *
* $Modtime:: 08/05/02 1:27p $*
* *
* $Revision:: 46 $*
* *
* 05/16/02 KM Base texture class to abstract major texture types, e.g. 3d, z, cube, etc.
* 06/27/02 KM Texture class abstraction *
* 08/05/02 KM Texture class redesign (revisited)
*---------------------------------------------------------------------------------------------*
* Functions: *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#pragma once
#include "always.h"
#include "chunkio.h"
#include "surfaceclass.h"
#include "ww3dformat.h"
#include "wwstring.h"
#include "vector3.h"
#include "texturefilter.h"
struct IDirect3DBaseTexture8;
struct IDirect3DTexture8;
struct IDirect3DCubeTexture8;
struct IDirect3DVolumeTexture8;
class DX8Wrapper;
class TextureLoader;
class LoaderThreadClass;
class TextureLoadTaskClass;
class TextureClass;
class CubeTextureClass;
class VolumeTextureClass;
class TextureBaseClass : public RefCountClass
{
friend class TextureLoader;
friend class LoaderThreadClass;
friend class DX8TextureTrackerClass; //(gth) so it can call Poke_Texture,
friend class DX8ZTextureTrackerClass;
public:
enum PoolType
{
POOL_DEFAULT=0,
POOL_MANAGED,
POOL_SYSTEMMEM
};
enum TexAssetType
{
TEX_REGULAR,
TEX_CUBEMAP,
TEX_VOLUME
};
// base constructor for derived classes
TextureBaseClass
(
unsigned width,
unsigned height,
MipCountType mip_level_count=MIP_LEVELS_ALL,
PoolType pool=POOL_MANAGED,
bool rendertarget=false,
bool reducible=true
);
virtual ~TextureBaseClass() override;
virtual TexAssetType Get_Asset_Type() const=0;
// Names
void Set_Texture_Name(const char * name);
void Set_Full_Path(const char * path) { FullPath = path; }
const StringClass& Get_Texture_Name() const { return Name; }
const StringClass& Get_Full_Path() const { if (FullPath.Is_Empty ()) return Name; return FullPath; }
unsigned Get_ID() const { return texture_id; } // Each textrure has a unique id
// The number of Mip levels in the texture
unsigned int Get_Mip_Level_Count() const
{
return MipLevelCount;
}
// Note! Width and Height may be zero and may change if texture uses mipmaps
int Get_Width() const
{
return Width;
}
int Get_Height() const
{
return Height;
}
// Time, after which the texture is invalidated if not used. Set to zero to indicate infinite.
// Time is in milliseconds.
void Set_Inactivation_Time(unsigned time) { InactivationTime=time; }
int Get_Inactivation_Time() const { return InactivationTime; }
// Texture priority affects texture management and caching.
unsigned int Get_Priority();
unsigned int Set_Priority(unsigned int priority); // Returns previous priority
// Debug utility functions for returning the texture memory usage
virtual unsigned Get_Texture_Memory_Usage() const=0;
bool Is_Initialized() const { return Initialized; }
bool Is_Lightmap() const { return IsLightmap; }
bool Is_Procedural() const { return IsProcedural; }
bool Is_Reducible() const { return IsReducible; } //can texture be reduced in resolution for LOD purposes?
static int _Get_Total_Locked_Surface_Size();
static int _Get_Total_Texture_Size();
static int _Get_Total_Lightmap_Texture_Size();
static int _Get_Total_Procedural_Texture_Size();
static int _Get_Total_Locked_Surface_Count();
static int _Get_Total_Texture_Count();
static int _Get_Total_Lightmap_Texture_Count();
static int _Get_Total_Procedural_Texture_Count();
virtual void Init()=0;
// This utility function processes the texture reduction (used during rendering)
void Invalidate();
// texture accessors (dx8)
IDirect3DBaseTexture8 *Peek_D3D_Base_Texture() const;
void Set_D3D_Base_Texture(IDirect3DBaseTexture8* tex);
PoolType Get_Pool() const { return Pool; }
bool Is_Missing_Texture();
// Support for self managed textures
bool Is_Dirty() { WWASSERT(Pool==POOL_DEFAULT); return Dirty; };
void Set_Dirty() { WWASSERT(Pool==POOL_DEFAULT); Dirty=true; }
void Clean() { Dirty=false; };
void Set_HSV_Shift(const Vector3 &hsv_shift);
const Vector3& Get_HSV_Shift() { return HSVShift; }
bool Is_Compression_Allowed() const { return IsCompressionAllowed; }
unsigned Get_Reduction() const;
// Background texture loader will call this when texture has been loaded
virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false)=0; // If the parameter is true, the texture will be flagged as initialised
MipCountType MipLevelCount;
// Inactivate textures that haven't been used in a while. Pass zero to use textures'
// own inactive times (default). In urgent need to free up texture memory, try
// calling with relatively small (just few seconds) time override to free up everything
// but the currently used textures.
static void Invalidate_Old_Unused_Textures(unsigned inactive_time_override);
// Apply this texture's settings into D3D
virtual void Apply(unsigned int stage)=0;
// Apply a Null texture's settings into D3D
static void Apply_Null(unsigned int stage);
virtual TextureClass* As_TextureClass() { return nullptr; }
virtual CubeTextureClass* As_CubeTextureClass() { return nullptr; }
virtual VolumeTextureClass* As_VolumeTextureClass() { return nullptr; }
IDirect3DTexture8* Peek_D3D_Texture() const { return (IDirect3DTexture8*)Peek_D3D_Base_Texture(); }
IDirect3DVolumeTexture8* Peek_D3D_VolumeTexture() const { return (IDirect3DVolumeTexture8*)Peek_D3D_Base_Texture(); }
IDirect3DCubeTexture8* Peek_D3D_CubeTexture() const { return (IDirect3DCubeTexture8*)Peek_D3D_Base_Texture(); }
protected:
void Load_Locked_Surface();
void Poke_Texture(IDirect3DBaseTexture8* tex) { D3DTexture = tex; }
bool Initialized;
// For debug purposes the texture sets this true if it is a lightmap texture
bool IsLightmap;
bool IsCompressionAllowed;
bool IsProcedural;
bool IsReducible;
unsigned InactivationTime; // In milliseconds
unsigned ExtendedInactivationTime; // This is set by the engine, if needed
unsigned LastInactivationSyncTime;
mutable unsigned LastAccessed;
// If this is non-zero, the texture will have a hue shift done at the next init (this
// value should only be changed by Set_HSV_Shift() function, which also invalidates the
// texture).
Vector3 HSVShift;
int Width;
int Height;
private:
// Direct3D texture object
IDirect3DBaseTexture8 *D3DTexture;
// Name
StringClass Name;
StringClass FullPath;
// Unique id
unsigned texture_id;
// Support for self-managed textures
PoolType Pool;
bool Dirty;
friend class TextureLoadTaskClass;
friend class CubeTextureLoadTaskClass;
friend class VolumeTextureLoadTaskClass;
TextureLoadTaskClass* TextureLoadTask;
TextureLoadTaskClass* ThumbnailLoadTask;
};
/*************************************************************************
** TextureClass
**
** This is our regular texture class. For legacy reasons it contains some
** information beyond the D3D texture itself, such as texture addressing
** modes.
**
*************************************************************************/
class TextureClass : public W3DMPO, public TextureBaseClass
{
W3DMPO_GLUE(TextureClass)
// friend DX8Wrapper;
public:
// Create texture with desired height, width and format.
TextureClass
(
unsigned width,
unsigned height,
WW3DFormat format,
MipCountType mip_level_count=MIP_LEVELS_ALL,
PoolType pool=POOL_MANAGED,
bool rendertarget=false,
bool allow_reduction=true
);
// Create texture from a file. If format is specified the texture is converted to that format.
// Note that the format must be supported by the current device and that a texture can't exist
// in the system with the same name in multiple formats.
TextureClass
(
const char *name,
const char *full_path=nullptr,
MipCountType mip_level_count=MIP_LEVELS_ALL,
WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN,
bool allow_compression=true,
bool allow_reduction=true
);
// Create texture from a surface.
TextureClass
(
SurfaceClass *surface,
MipCountType mip_level_count=MIP_LEVELS_ALL
);
TextureClass(IDirect3DBaseTexture8* d3d_texture);
// default constructors for derived classes (cube & vol)
TextureClass
(
unsigned width,
unsigned height,
MipCountType mip_level_count=MIP_LEVELS_ALL,
PoolType pool=POOL_MANAGED,
bool rendertarget=false,
WW3DFormat format=WW3D_FORMAT_UNKNOWN,
bool allow_reduction=true
)
: TextureBaseClass(width,height,mip_level_count,pool,rendertarget,allow_reduction), TextureFormat(format), Filter(mip_level_count) { }
virtual TexAssetType Get_Asset_Type() const override { return TEX_REGULAR; }
virtual void Init() override;
// Background texture loader will call this when texture has been loaded
virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false) override; // If the parameter is true, the texture will be flagged as initialised
// Get the surface of one of the mipmap levels (defaults to highest-resolution one)
SurfaceClass *Get_Surface_Level(unsigned int level = 0);
IDirect3DSurface8 *Get_D3D_Surface_Level(unsigned int level = 0);
void Get_Level_Description( SurfaceClass::SurfaceDescription & desc, unsigned int level = 0 );
TextureFilterClass& Get_Filter() { return Filter; }
WW3DFormat Get_Texture_Format() const { return TextureFormat; }
virtual void Apply(unsigned int stage) override;
virtual unsigned Get_Texture_Memory_Usage() const override;
virtual TextureClass* As_TextureClass() override { return this; }
protected:
WW3DFormat TextureFormat;
// legacy
TextureFilterClass Filter;
};
class ZTextureClass : public TextureBaseClass
{
public:
// Create a z texture with desired height, width and format
ZTextureClass
(
unsigned width,
unsigned height,
WW3DZFormat zformat,
MipCountType mip_level_count=MIP_LEVELS_ALL,
PoolType pool=POOL_MANAGED
);
WW3DZFormat Get_Texture_Format() const { return DepthStencilTextureFormat; }
virtual TexAssetType Get_Asset_Type() const override { return TEX_REGULAR; }
virtual void Init() override {}
// Background texture loader will call this when texture has been loaded
virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false) override; // If the parameter is true, the texture will be flagged as initialised
virtual void Apply(unsigned int stage) override;
IDirect3DSurface8 *Get_D3D_Surface_Level(unsigned int level = 0);
virtual unsigned Get_Texture_Memory_Usage() const override;
private:
WW3DZFormat DepthStencilTextureFormat;
};
class CubeTextureClass : public TextureClass
{
public:
// Create texture with desired height, width and format.
CubeTextureClass
(
unsigned width,
unsigned height,
WW3DFormat format,
MipCountType mip_level_count=MIP_LEVELS_ALL,
PoolType pool=POOL_MANAGED,
bool rendertarget=false,
bool allow_reduction=true
);
// Create texture from a file. If format is specified the texture is converted to that format.
// Note that the format must be supported by the current device and that a texture can't exist
// in the system with the same name in multiple formats.
CubeTextureClass
(
const char *name,
const char *full_path=nullptr,
MipCountType mip_level_count=MIP_LEVELS_ALL,
WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN,
bool allow_compression=true,
bool allow_reduction=true
);
// Create texture from a surface.
CubeTextureClass
(
SurfaceClass *surface,
MipCountType mip_level_count=MIP_LEVELS_ALL
);
CubeTextureClass(IDirect3DBaseTexture8* d3d_texture);
virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false) override; // If the parameter is true, the texture will be flagged as initialised
virtual TexAssetType Get_Asset_Type() const override { return TEX_CUBEMAP; }
virtual CubeTextureClass* As_CubeTextureClass() override { return this; }
};
class VolumeTextureClass : public TextureClass
{
public:
// Create texture with desired height, width and format.
VolumeTextureClass
(
unsigned width,
unsigned height,
unsigned depth,
WW3DFormat format,
MipCountType mip_level_count=MIP_LEVELS_ALL,
PoolType pool=POOL_MANAGED,
bool rendertarget=false,
bool allow_reduction=true
);
// Create texture from a file. If format is specified the texture is converted to that format.
// Note that the format must be supported by the current device and that a texture can't exist
// in the system with the same name in multiple formats.
VolumeTextureClass
(
const char *name,
const char *full_path=nullptr,
MipCountType mip_level_count=MIP_LEVELS_ALL,
WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN,
bool allow_compression=true,
bool allow_reduction=true
);
// Create texture from a surface.
VolumeTextureClass
(
SurfaceClass *surface,
MipCountType mip_level_count=MIP_LEVELS_ALL
);
VolumeTextureClass(IDirect3DBaseTexture8* d3d_texture);
virtual void Apply_New_Surface(IDirect3DBaseTexture8* tex, bool initialized, bool disable_auto_invalidation = false) override; // If the parameter is true, the texture will be flagged as initialised
virtual TexAssetType Get_Asset_Type() const override { return TEX_VOLUME; }
virtual VolumeTextureClass* As_VolumeTextureClass() override { return this; }
protected:
int Depth;
};
// Utility functions for loading and saving texture descriptions from/to W3D files
TextureClass *Load_Texture(ChunkLoadClass & cload);
void Save_Texture(TextureClass * texture, ChunkSaveClass & csave);