Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
ddsfile.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// 08/06/02 KM Added cube map and volume texture support
20
21#ifndef DDSFILE_H
22#define DDSFILE_H
23
24#if defined(_MSC_VER)
25#pragma once
26#endif
27
28#include "always.h"
29#include "ww3dformat.h"
30#include "wwstring.h"
31#include "vector3.h"
32
33struct IDirect3DSurface8;
34struct IDirect3DVolume8;
35
36// ----------------------------------------------------------------------------
37//
38// This structure represents the old DX7 color key structure. It is needed
39// LegacyDDSURFACEDESC which is needed when loading DDS files. DO NOT MODIFY!
40//
41// ----------------------------------------------------------------------------
42
48
49// ----------------------------------------------------------------------------
50//
51// This structure represents the old DX7 CAPS2 structure. It is needed
52// LegacyDDSURFACEDESC which is needed when loading DDS files. DO NOT MODIFY!
53//
54// ----------------------------------------------------------------------------
55
57{
58 unsigned Caps;
59 unsigned Caps2;
60 unsigned Caps3;
61 unsigned Caps4;
62};
63
64// ----------------------------------------------------------------------------
65//
66// This structure represents the old DX7 pixel format structure. It is needed
67// LegacyDDSURFACEDESC which is needed when loading DDS files. DO NOT MODIFY!
68//
69// ----------------------------------------------------------------------------
70
72{
73 unsigned Size;
74 unsigned Flags;
75 unsigned FourCC;
76 union
77 {
78 unsigned RGBBitCount;
79 unsigned YUVBitCount;
80 unsigned ZBufferBitDepth;
81 unsigned AlphaBitDepth;
83 unsigned BumpBitCount;
84 };
85 union
86 {
87 unsigned RBitMask;
88 unsigned YBitMask;
91 unsigned BumpDuBitMask;
92 };
93 union
94 {
95 unsigned GBitMask;
96 unsigned UBitMask;
97 unsigned ZBitMask;
98 unsigned BumpDvBitMask;
99 };
100 union
101 {
102 unsigned BBitMask;
103 unsigned VBitMask;
106 };
107 union
108 {
112 unsigned RGBZBitMask;
113 unsigned YUVZBitMask;
114 };
115};
116
117// ----------------------------------------------------------------------------
118//
119// This structure represents the old DX7 surface description structure.
120// It is needed when loading DDS files. DO NOT MODIFY!
121//
122// ----------------------------------------------------------------------------
123
125 unsigned Size;
126 unsigned Flags;
127 unsigned Height;
128 unsigned Width;
129 union
130 {
131 unsigned Pitch;
132 unsigned LinearSize;
133 };
134 union
135 {
137 unsigned Depth; // added depth for volume textures
138 };
139 union
140 {
141 unsigned MipMapCount;
142 unsigned RefreshRate;
143 };
145 unsigned Reserved;
146 void* Surface;
147 union
148 {
151 };
157 unsigned TextureStage;
158};
159
160
167
168// ----------------------------------------------------------------------------
169//
170// Utility class for loading DDS files. Simply create an instance of the class
171// locally, call Load() and use the copy functions to retrieve the surface.
172// The class handles conversion of the surface to equal compressed formats
173// and all non-compressed formats. the compressed DXTn formats can't be cross-
174// converted except for DXT1 which can be converted to DXT2 (this feature is
175// needed as the NVidia cards have problems with DXT1).
176//
177// ----------------------------------------------------------------------------
178
180{
181 unsigned Width;
182 unsigned Height;
183 unsigned Depth;
184 unsigned FullWidth;
185 unsigned FullHeight;
186 unsigned FullDepth;
187 unsigned MipLevels;
188 unsigned long DateTime;
189 unsigned ReductionFactor;
190 unsigned char* DDSMemory;
191 WW3DFormat Format;
192 DDSType Type;
193 unsigned* LevelSizes;
194 unsigned* LevelOffsets;
195 unsigned CubeFaceSize;
196 LegacyDDSURFACEDESC2 SurfaceDesc;
197 char Name[256];
198
199 static unsigned Calculate_DXTC_Surface_Size(unsigned width, unsigned height, WW3DFormat format);
200
201public:
202 // You can pass the name in .tga or .dds format, the class will automatically try and load .dds file.
203 // Note that creating the object will only give you image info - call Load() to load the surfaces.
204 DDSFileClass(const char* name,unsigned reduction_factor);
206
207 unsigned Get_Width(unsigned level) const;
208 unsigned Get_Height(unsigned level) const;
209 unsigned Get_Depth(unsigned level) const;
210 unsigned Get_Full_Width() const { return FullWidth; } // Get the width of level 0 of non-reduced texture
211 unsigned Get_Full_Height() const { return FullHeight; } // Get the height of level 0 of non-reduced texture
212 unsigned Get_Full_Depth() const { return FullDepth; }
213 unsigned long Get_Date_Time() const { return DateTime; }
214
215 unsigned Get_Mip_Level_Count() const { return MipLevels; }
216 const unsigned char* Get_Memory_Pointer(unsigned level) const;
217 unsigned Get_Level_Size(unsigned level) const;
218 WW3DFormat Get_Format() const { return Format; }
219
220 DDSType Get_Type() const { return Type; }
221
222 // Copy pixels to the destination surface.
223 void Copy_Level_To_Surface(unsigned level,IDirect3DSurface8* d3d_surface,const Vector3& hsv_shift=Vector3(0.0f,0.0f,0.0f));
225 unsigned level,
226 WW3DFormat dest_format,
227 unsigned dest_width,
228 unsigned dest_height,
229 unsigned char* dest_surface,
230 unsigned dest_pitch,
231 const Vector3& hsv_shift=Vector3(0.0f,0.0f,0.0f));
232
233 // cube map
234 const unsigned char* Get_CubeMap_Memory_Pointer(unsigned face, unsigned level) const;
236 (
237 unsigned face,
238 unsigned level,
239 WW3DFormat dest_format,
240 unsigned width,
241 unsigned height,
242 unsigned char* surf,
243 unsigned pitch,
244 const Vector3& hsv_shift=Vector3(0.0f,0.0f,0.0f)
245 );
246
247 // volume texture
248 const unsigned char* Get_Volume_Memory_Pointer(unsigned level) const;
250 (
251 unsigned level,
252 unsigned depth,
253 WW3DFormat dest_format,
254 unsigned width,
255 unsigned height,
256 unsigned char* vol,
257 unsigned row_pitch,
258 unsigned slice_pitch,
259 const Vector3& hsv_shift=Vector3(0.0f,0.0f,0.0f)
260 );
261
262 // Get pixel in A8R8G8B8 format. This isn't the fastest possible way of reading data from DDS.
263 unsigned Get_Pixel(unsigned level,unsigned x,unsigned y) const;
264
265// Uncompress one 4x4 block from the compressed image.
266// Returns: true if block contained alpha, false is not
267// Note: Destination can't be DXT or paletted surface!
268 bool Get_4x4_Block(
269 unsigned char* dest_ptr, // Destination surface pointer
270 unsigned dest_pitch, // Destination surface pitch, in bytes
271 WW3DFormat dest_format, // Destination surface format, A8R8G8B8 is fastest
272 unsigned level, // DDS mipmap level to copy from
273 unsigned source_x, // DDS x offset to copy from, must be aligned by 4!
274 unsigned source_y, // DDS y offset to copy from, must be aligned by 4!
275 const Vector3& hsv_shift=Vector3(0.0f,0.0f,0.0f)) const;
276
277 bool Load();
278 bool Is_Available() const { return !!LevelSizes; }
279};
280
281// ----------------------------------------------------------------------------
282
283#endif
unsigned Get_Full_Width() const
Definition ddsfile.h:210
WW3DFormat Get_Format() const
Definition ddsfile.h:218
unsigned long Get_Date_Time() const
Definition ddsfile.h:213
bool Is_Available() const
Definition ddsfile.h:278
const unsigned char * Get_Memory_Pointer(unsigned level) const
Definition ddsfile.cpp:219
DDSFileClass(const char *name, unsigned reduction_factor)
Definition ddsfile.cpp:39
unsigned Get_Full_Depth() const
Definition ddsfile.h:212
unsigned Get_Full_Height() const
Definition ddsfile.h:211
const unsigned char * Get_Volume_Memory_Pointer(unsigned level) const
Definition ddsfile.cpp:691
DDSType Get_Type() const
Definition ddsfile.h:220
unsigned Get_Height(unsigned level) const
Definition ddsfile.cpp:203
unsigned Get_Mip_Level_Count() const
Definition ddsfile.h:215
bool Get_4x4_Block(unsigned char *dest_ptr, unsigned dest_pitch, WW3DFormat dest_format, unsigned level, unsigned source_x, unsigned source_y, const Vector3 &hsv_shift=Vector3(0.0f, 0.0f, 0.0f)) const
Definition ddsfile.cpp:1043
bool Load()
Definition ddsfile.cpp:258
unsigned Get_Width(unsigned level) const
Definition ddsfile.cpp:195
unsigned Get_Depth(unsigned level) const
Definition ddsfile.cpp:211
void Copy_Level_To_Surface(unsigned level, IDirect3DSurface8 *d3d_surface, const Vector3 &hsv_shift=Vector3(0.0f, 0.0f, 0.0f))
Definition ddsfile.cpp:343
unsigned Get_Level_Size(unsigned level) const
Definition ddsfile.cpp:225
const unsigned char * Get_CubeMap_Memory_Pointer(unsigned face, unsigned level) const
Definition ddsfile.cpp:518
unsigned Get_Pixel(unsigned level, unsigned x, unsigned y) const
Definition ddsfile.cpp:913
void Copy_CubeMap_Level_To_Surface(unsigned face, unsigned level, WW3DFormat dest_format, unsigned width, unsigned height, unsigned char *surf, unsigned pitch, const Vector3 &hsv_shift=Vector3(0.0f, 0.0f, 0.0f))
Definition ddsfile.cpp:528
void Copy_Volume_Level_To_Surface(unsigned level, unsigned depth, WW3DFormat dest_format, unsigned width, unsigned height, unsigned char *vol, unsigned row_pitch, unsigned slice_pitch, const Vector3 &hsv_shift=Vector3(0.0f, 0.0f, 0.0f))
Definition ddsfile.cpp:697
DDSType
Definition ddsfile.h:162
@ DDS_TEXTURE
Definition ddsfile.h:163
@ DDS_VOLUME
Definition ddsfile.h:165
@ DDS_CUBEMAP
Definition ddsfile.h:164
unsigned ColorSpaceHighValue
Definition ddsfile.h:46
unsigned ColorSpaceLowValue
Definition ddsfile.h:45
unsigned RBitMask
Definition ddsfile.h:87
unsigned ZBitMask
Definition ddsfile.h:97
unsigned GBitMask
Definition ddsfile.h:95
unsigned ZBufferBitDepth
Definition ddsfile.h:80
unsigned VBitMask
Definition ddsfile.h:103
unsigned YUVBitCount
Definition ddsfile.h:79
unsigned BumpDvBitMask
Definition ddsfile.h:98
unsigned YUVZBitMask
Definition ddsfile.h:113
unsigned LuminanceBitMask
Definition ddsfile.h:90
unsigned LuminanceAlphaBitMask
Definition ddsfile.h:111
unsigned AlphaBitDepth
Definition ddsfile.h:81
unsigned LuminanceBitCount
Definition ddsfile.h:82
unsigned BBitMask
Definition ddsfile.h:102
unsigned UBitMask
Definition ddsfile.h:96
unsigned YUVAlphaBitMask
Definition ddsfile.h:110
unsigned StencilBitMask
Definition ddsfile.h:104
unsigned RGBAlphaBitMask
Definition ddsfile.h:109
unsigned YBitMask
Definition ddsfile.h:88
unsigned BumpLuminanceBitMask
Definition ddsfile.h:105
unsigned FourCC
Definition ddsfile.h:75
unsigned RGBBitCount
Definition ddsfile.h:78
unsigned StencilBitDepth
Definition ddsfile.h:89
unsigned BumpDuBitMask
Definition ddsfile.h:91
unsigned BumpBitCount
Definition ddsfile.h:83
unsigned RGBZBitMask
Definition ddsfile.h:112
unsigned Caps2
Definition ddsfile.h:59
unsigned Caps3
Definition ddsfile.h:60
unsigned Caps4
Definition ddsfile.h:61
unsigned Caps
Definition ddsfile.h:58
LegacyDDCOLORKEY CKSrcBlt
Definition ddsfile.h:154
unsigned BackBufferCount
Definition ddsfile.h:136
unsigned RefreshRate
Definition ddsfile.h:142
unsigned AlphaBitDepth
Definition ddsfile.h:144
unsigned TextureStage
Definition ddsfile.h:157
LegacyDDSCAPS2 Caps
Definition ddsfile.h:156
unsigned LinearSize
Definition ddsfile.h:132
LegacyDDCOLORKEY CKDestOverlay
Definition ddsfile.h:149
LegacyDDPIXELFORMAT PixelFormat
Definition ddsfile.h:155
LegacyDDCOLORKEY CKSrcOverlay
Definition ddsfile.h:153
LegacyDDCOLORKEY CKDestBlt
Definition ddsfile.h:152
unsigned EmptyFaceColor
Definition ddsfile.h:150
unsigned MipMapCount
Definition ddsfile.h:141
WW3DFormat
Definition ww3dformat.h:75