Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
texfcach.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/* $Header: /Commando/Code/ww3d2/texfcach.h 3 3/26/01 10:45a Jani_p $ */
20/***********************************************************************************************
21 *** 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 ***
22 ***********************************************************************************************
23 * *
24 * Project Name : WW3D *
25 * *
26 * $Archive:: /Commando/Code/ww3d2/texfcach.h $*
27 * *
28 * $Author:: Jani_p $*
29 * *
30 * $Modtime:: 3/23/01 11:15a $*
31 * *
32 * $Revision:: 3 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37#if defined(_MSC_VER)
38#pragma once
39#endif
40
41#ifndef TEXTFCACH_H
42#define TEXTFCACH_H
43
44#include "always.h"
45
46#include <assert.h>
47#include <tagblock.h>
48
49#ifdef WW3D_DX8
50
51//#include <srTextureIFace.hpp>
52
53class FileClass;
54//class srColorSurfaceIFace;
55
56class TextureFileCache
57{
58 public:
59 TextureFileCache(const char *fileprefix);
60 virtual ~TextureFileCache();
61
62 virtual void Reset_File();
63
64 // Find texture in the cache. Returns TRUE if texture found inside of cache.
65 int Texture_Exists(const char *fname);
66
67 // Create the initial surface that is based off of the original texture.
68 // The surface is not filled in with texels since we don't convert this.
69 // This will also set TextureHandle up.
70 srColorSurfaceIFace *Load_Original_Texture_Surface(const char *texturename);
71
72 // Given a texture that has been loaded, save it in our file cache.
73 bool Save_Texture(const char *texturename, srTextureIFace::MultiRequest& mreq, srColorSurfaceIFace& origsurface);
74
75 // Load texture data from cache into a multirequest structure.
76 bool Load_Texture(const char *texturename, srTextureIFace::MultiRequest& mreq);
77 //bool TextureFileCache::Load_Texture(const char *texturename, srTextureIFace::MultiRequest& mreq);
78
79 // Check that file is in cache, is not - load and save all mipmap levels
80 bool Validate_Texture(const char* texturename);
81
82 // Load a surface from the file cache, null if does not exist.
83 srColorSurfaceIFace *Get_Surface(const char *texturename, unsigned int reduce_factor);
84
85 protected:
86 struct FileHeader {
87 enum {
88 // Put in date when format is changed.
89 TCF_VERSION = 20000814,
90 };
91
92 // Will change whenever a new file version is made.
93 int Version;
94 };
95
96 // The file format for each texture is as follows:
97 // _TextureBlockHeader {...}
98 // int MipMap[0].Offset
99 // ...
100 // int MipMap[_TextureBlockHeader.NumMipMaps - 1].Offset
101 // int Offset of end of block to get size of last MipMap.
102 // rawdata MipMap[0]
103 // ...
104 // rawdata MipMap[_TextureBlockHeader.NumMipMaps - 1]
105 // End of BLock
106
107 struct TextureBlockHeader
108 {
109 // Time data stamp of file.
110 unsigned long FileTime;
111
112 // Number of mip maps in texture (including first one).
113 int NumMipMaps;
114
115 // Dimensions of first mip map level saved. This is normally the same as
116 // Source* but can be different when certain texture creation methods are done.
117 int LargestWidth;
118 int LargestHeight;
119
120 // Dimensions of original surface/art work.
121 int SourceWidth;
122 int SourceHeight;
123
124 // This is the pixel format used to create the sources original surface.
125 srColorSurfaceIFace::PixelFormat SourcePixelFormat;
126
127 // Pixel format that we have saved in.
128 srColorSurfaceIFace::PixelFormat PixelFormat;
129
130 TextureBlockHeader():NumMipMaps(-1),SourceWidth(-1),SourceHeight(-1),LargestWidth(-1),LargestHeight(-1) {}
131 };
132
133 // Each texture has an offset into the file and it's size when uncompressed.
134 struct OffsetTableType
135 {
136 OffsetTableType() : Offset(0), Size (0) {}
137
138 // Offset of texture in file.
139 int Offset;
140
141 // Size (uncompressed) of texture. The size of the compressed texture
142 // is caclcuated by Texture_Size() below.
143 int Size;
144 };
145 protected:
146 enum {
147 MAX_CACHED_SURFACES = srTextureIFace::MAX_LOD,
148 };
149
150 // Pointer to the low level file managment. TagBlockFile handles the seperation
151 // of the different 'texture files'. This class deals with each seperate 'texture file'.
152 TagBlockFile File;
153
154 // Name of last texture loaded so we know if things need to be thrown away or not.
155 char *CurrentTexture;
156
157 // Handle for current texture in cache. This is created by Open_Texture_Handle().
158 TagBlockHandle *TextureHandle;
159
160 // Header that has been loaded by Open_Texture_Handle().
161 TextureBlockHeader Header;
162
163 // The offset table is loaded into memory when the file is opened.
164 OffsetTableType *Offsets;
165
166 // Cache pointers to data that has already been loaded for this texture.
167 srColorSurface * CachedSurfaces[MAX_CACHED_SURFACES];
168
169 // Number of cached textures we have.
170 int NumCachedTextures;
171
172 protected:
173 // Buffer to compress into and decompress out of.
174// static char *CompressionBuffer;
175// static char *EOCompressionBuffer;
176
177 // This keeps track of number of instances of the TextureFileCache.
178 // This way static variables are only freed when all instances have been deleted.
179// static int Instances;
180
181 // Access to previously cached textures so they do not have to be read off of disk.
182 void Add_Cached_Surface(srColorSurface *surface);
183 srColorSurface *Find_Cached_Surface(int size);
184 srColorSurface *Find_Smallest_Cached_Surface();
185
186 int Texture_Size(int lod) {
187 assert(Offsets);
188 assert(lod < Header.NumMipMaps);
189 return(Offsets[lod].Size);
190 }
191
192 int Compressed_Texture_Size(int lod) {
193 assert(Offsets);
194 assert(lod < Header.NumMipMaps);
195 return(Offsets[lod + 1].Offset - Offsets[lod].Offset);
196 }
197
198 bool Open_Texture_Handle(const char *texturename);
199 void Close_Texture_Handle();
200
201 void Read_Texture(int offsetidx, srColorSurface *surface);
202 srColorSurfaceIFace *Create_First_Texture_As_Surface(srColorSurfaceIFace *surftype);
203
204 static char *_Create_File_Name(const char *fileprefix);
205 static char *_FileNamePtr;
206};
207
208#endif //WW3D_DX8
209
210
211#endif //TEXTFCACH_H
TextureClass * Load_Texture(ChunkLoadClass &cload)
Definition texture.cpp:1051
void Save_Texture(TextureClass *texture, ChunkSaveClass &csave)
Definition texture.cpp:1184