Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
textureloader.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : DX8 Texture Manager *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/textureloader.h $*
26 * *
27 * Original Author:: vss_sync *
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 06/27/02 1:27p $*
32 * *
33 * $Revision:: 2 $*
34 * *
35 * 06/27/02 KM Texture class abstraction *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40
41#ifndef TEXTURELOADER_H
42#define TEXTURELOADER_H
43
44#if defined(_MSC_VER)
45#pragma once
46#endif
47
48#include "always.h"
49#include "texture.h"
50
51class StringClass;
52struct IDirect3DTexture8;
54
56{
57public:
58 static void Init(void);
59 static void Deinit(void);
60
61 // Modify given texture size to nearest valid size on current hardware.
62 static void Validate_Texture_Size(unsigned& width, unsigned& height, unsigned& depth);
63
64 static IDirect3DTexture8 * Load_Thumbnail(
65 const StringClass& filename,const Vector3& hsv_shift);
66// WW3DFormat texture_format); // Pass WW3D_FORMAT_UNKNOWN if you don't care
67
68 static IDirect3DSurface8 * Load_Surface_Immediate(
69 const StringClass& filename,
70 WW3DFormat surface_format, // Pass WW3D_FORMAT_UNKNOWN if you don't care
71 bool allow_compression);
72
73 static void Request_Thumbnail(TextureBaseClass* tc);
74
75 // Adds a loading task to the system. The task if processed in a separate
76 // thread as soon as possible. The task will appear in finished tasks list
77 // when it's been completed. The texture will be refreshed on the next
78 // update call after appearing to the finished tasks list.
80
81 // Textures can only be created and locked by the main thread so this function sends a request to the texture
82 // handling system to load the texture immediatelly next time it enters the main thread. If this function
83 // is called from the main thread the texture is loaded immediatelly.
85
86 static void Flush_Pending_Load_Tasks(void);
87 static void Update(void(*network_callback)(void) = NULL);
88
89 // returns true if current thread of execution is allowed to make DX8 calls.
90 static bool Is_DX8_Thread(void);
91
92 static void Suspend_Texture_Load();
93 static void Continue_Texture_Load();
94
95 static void Set_Texture_Inactive_Override_Time(int time_ms) {TextureInactiveOverrideTime = time_ms;}
96
97private:
98 static void Process_Foreground_Load (TextureLoadTaskClass *task);
99 static void Process_Foreground_Thumbnail (TextureLoadTaskClass *task);
100
101 static void Begin_Load_And_Queue (TextureLoadTaskClass *task);
102 static void Load_Thumbnail (TextureBaseClass *tc);
103
104 static bool TextureLoadSuspended;
105
106 // The time in ms before a texture is thrown out.
107 // The default is zero. The scripted movies set this to reduce texture stalls in movies.
108 static int TextureInactiveOverrideTime;
109};
110
124
125
127{
128 // This class implements an unsynchronized, double-linked list of TextureLoadTaskClass
129 // objects, using an embedded list node.
130
131 public:
133
134 // Returns true if list is empty, false otherwise.
135 bool Is_Empty (void) const { return (Root.Next == &Root); }
136
137 // Add a task to beginning of list
138 void Push_Front (TextureLoadTaskClass *task);
139
140 // Add a task to end of list
141 void Push_Back (TextureLoadTaskClass *task);
142
143 // Remove and return a task from beginning of list, or NULL if list is empty.
145
146 // Remove and return a task from end of list, or NULL if list is empty
148
149 // Remove specified task from list, if present
150 void Remove (TextureLoadTaskClass *task);
151
152 private:
153 // This list is implemented using a sentinel node.
155};
156
157
159{
160 // This class added thread-safety to the basic TextureLoadTaskListClass.
161
162 public:
164
165 // See comments above for description of member functions.
166 void Push_Front (TextureLoadTaskClass *task);
167 void Push_Back (TextureLoadTaskClass *task);
170 void Remove (TextureLoadTaskClass *task);
171
172 private:
173 FastCriticalSectionClass CriticalSection;
174};
175
176/*
177** (gth) The allocation system we're using for TextureLoadTaskClass has gotten a little
178** complicated since Kenny added the new task types for Cube and Volume textures. The
179** ::Destroy member is used to return a task to the pool now and must be over-ridden in
180** each derived class to put the task back into the correct free list.
181*/
182
183
185{
186 public:
192
197
207
208
211
213 static void Delete_Free_Pool (void);
214
215 virtual void Destroy (void);
216 virtual void Init (TextureBaseClass *tc, TaskType type, PriorityType priority);
217 virtual void Deinit (void);
218
219 TaskType Get_Type (void) const { return Type; }
220 PriorityType Get_Priority (void) const { return Priority; }
221 StateType Get_State (void) const { return State; }
222
223 WW3DFormat Get_Format (void) const { return Format; }
224 unsigned int Get_Width (void) const { return Width; }
225 unsigned int Get_Height (void) const { return Height; }
226 unsigned int Get_Mip_Level_Count (void) const { return MipLevelCount; }
227 unsigned int Get_Reduction (void) const { return Reduction; }
228
229 unsigned char * Get_Locked_Surface_Ptr (unsigned int level);
230 unsigned int Get_Locked_Surface_Pitch(unsigned int level) const;
231
233 IDirect3DTexture8 * Peek_D3D_Texture (void) { return (IDirect3DTexture8*)D3DTexture; }
234
235 void Set_Type (TaskType t) { Type = t; }
237 void Set_State (StateType s) { State = s; }
238
239 bool Begin_Load (void);
240 bool Load (void);
241 void End_Load (void);
242 void Finish_Load (void);
243 void Apply_Missing_Texture (void);
244
245 protected:
246 virtual bool Begin_Compressed_Load (void);
247 virtual bool Begin_Uncompressed_Load (void);
248
249 virtual bool Load_Compressed_Mipmap (void);
250 virtual bool Load_Uncompressed_Mipmap(void);
251
252 virtual void Lock_Surfaces (void);
253 virtual void Unlock_Surfaces (void);
254
255 void Apply (bool initialize);
256
258 IDirect3DBaseTexture8* D3DTexture;
260
261 unsigned int Width;
262 unsigned int Height;
263 unsigned int MipLevelCount;
264 unsigned int Reduction;
266
269
273};
274
276{
277public:
279
280 virtual void Destroy (void);
281 virtual void Init (TextureBaseClass *tc, TaskType type, PriorityType priority);
282 virtual void Deinit (void);
283
284protected:
285 virtual bool Begin_Compressed_Load (void);
286 virtual bool Begin_Uncompressed_Load (void);
287
288 virtual bool Load_Compressed_Mipmap (void);
289// virtual bool Load_Uncompressed_Mipmap(void);
290
291 virtual void Lock_Surfaces (void);
292 virtual void Unlock_Surfaces (void);
293
294private:
295 unsigned char* Get_Locked_CubeMap_Surface_Pointer(unsigned int face, unsigned int level);
296 unsigned int Get_Locked_CubeMap_Surface_Pitch(unsigned int face, unsigned int level) const;
297
298 IDirect3DCubeTexture8* Peek_D3D_Cube_Texture(void) { return (IDirect3DCubeTexture8*)D3DTexture; }
299
300 unsigned char* LockedCubeSurfacePtr[6][MIP_LEVELS_MAX];
301 unsigned int LockedCubeSurfacePitch[6][MIP_LEVELS_MAX];
302};
303
305{
306public:
308
309 virtual void Destroy (void);
310 virtual void Init (TextureBaseClass *tc, TaskType type, PriorityType priority);
311
312protected:
313 virtual bool Begin_Compressed_Load (void);
314 virtual bool Begin_Uncompressed_Load (void);
315
316 virtual bool Load_Compressed_Mipmap (void);
317// virtual bool Load_Uncompressed_Mipmap(void);
318
319 virtual void Lock_Surfaces (void);
320 virtual void Unlock_Surfaces (void);
321
322private:
323 unsigned char* Get_Locked_Volume_Pointer(unsigned int level);
324 unsigned int Get_Locked_Volume_Row_Pitch(unsigned int level);
325 unsigned int Get_Locked_Volume_Slice_Pitch(unsigned int level);
326
327 IDirect3DVolumeTexture8* Peek_D3D_Volume_Texture(void) { return (IDirect3DVolumeTexture8*)D3DTexture; }
328
329 unsigned int LockedSurfaceSlicePitch[MIP_LEVELS_MAX];
330
331 unsigned int Depth;
332};
333
334#endif
#define NULL
Definition BaseType.h:92
virtual void Unlock_Surfaces(void)
virtual bool Load_Compressed_Mipmap(void)
virtual void Deinit(void)
virtual bool Begin_Uncompressed_Load(void)
virtual void Destroy(void)
virtual void Init(TextureBaseClass *tc, TaskType type, PriorityType priority)
virtual bool Begin_Compressed_Load(void)
virtual void Lock_Surfaces(void)
void Push_Front(TextureLoadTaskClass *task)
void Remove(TextureLoadTaskClass *task)
TextureLoadTaskClass * Pop_Front(void)
TextureLoadTaskClass * Pop_Back(void)
void Push_Back(TextureLoadTaskClass *task)
IDirect3DTexture8 * Peek_D3D_Texture(void)
unsigned int Get_Reduction(void) const
TextureBaseClass * Texture
WW3DFormat Get_Format(void) const
virtual void Deinit(void)
unsigned int Get_Height(void) const
virtual bool Load_Uncompressed_Mipmap(void)
virtual bool Load_Compressed_Mipmap(void)
unsigned int Get_Locked_Surface_Pitch(unsigned int level) const
unsigned int LockedSurfacePitch[MIP_LEVELS_MAX]
static TextureLoadTaskClass * Create(TextureBaseClass *tc, TaskType type, PriorityType priority)
virtual void Init(TextureBaseClass *tc, TaskType type, PriorityType priority)
virtual bool Begin_Compressed_Load(void)
virtual void Destroy(void)
unsigned char * LockedSurfacePtr[MIP_LEVELS_MAX]
void Set_Type(TaskType t)
StateType Get_State(void) const
TaskType Get_Type(void) const
virtual bool Begin_Uncompressed_Load(void)
virtual void Lock_Surfaces(void)
static void Delete_Free_Pool(void)
unsigned int MipLevelCount
PriorityType Get_Priority(void) const
void Apply(bool initialize)
unsigned int Get_Mip_Level_Count(void) const
unsigned char * Get_Locked_Surface_Ptr(unsigned int level)
virtual void Unlock_Surfaces(void)
unsigned int Get_Width(void) const
TextureBaseClass * Peek_Texture(void)
void Set_State(StateType s)
IDirect3DBaseTexture8 * D3DTexture
void Set_Priority(PriorityType p)
TextureLoadTaskClass * Pop_Back(void)
bool Is_Empty(void) const
void Push_Back(TextureLoadTaskClass *task)
void Push_Front(TextureLoadTaskClass *task)
TextureLoadTaskClass * Pop_Front(void)
void Remove(TextureLoadTaskClass *task)
TextureLoadTaskListClass * Get_List(void)
TextureLoadTaskListNodeClass * Prev
TextureLoadTaskListClass * List
TextureLoadTaskListNodeClass * Next
static void Continue_Texture_Load()
static void Set_Texture_Inactive_Override_Time(int time_ms)
static void Validate_Texture_Size(unsigned &width, unsigned &height, unsigned &depth)
static void Request_Background_Loading(TextureBaseClass *tc)
static void Flush_Pending_Load_Tasks(void)
static void Init(void)
static void Suspend_Texture_Load()
static void Request_Thumbnail(TextureBaseClass *tc)
static IDirect3DTexture8 * Load_Thumbnail(const StringClass &filename, const Vector3 &hsv_shift)
static bool Is_DX8_Thread(void)
static void Deinit(void)
static void Request_Foreground_Loading(TextureBaseClass *tc)
static IDirect3DSurface8 * Load_Surface_Immediate(const StringClass &filename, WW3DFormat surface_format, bool allow_compression)
virtual void Unlock_Surfaces(void)
virtual bool Load_Compressed_Mipmap(void)
virtual void Lock_Surfaces(void)
virtual void Init(TextureBaseClass *tc, TaskType type, PriorityType priority)
virtual bool Begin_Compressed_Load(void)
virtual bool Begin_Uncompressed_Load(void)
@ MIP_LEVELS_MAX
struct Update Update
Definition wolapi.h:617
WW3DFormat
Definition ww3dformat.h:75