Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
ww3dformat.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 : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/ww3dformat.h $*
26 * *
27 * Original Author:: Nathaniel Hoffman *
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 06/27/02 1:27p $*
32 * *
33 * $Revision:: 12 $*
34 * *
35 * 06/27/02 KM Z Format support *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * Vector4_to_Color - converts a vector4 to the format in format *
39 * Color_to_Vector4 - converts a color in the format described in format to a Vector4 *
40 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41
42#if defined(_MSC_VER)
43#pragma once
44#endif
45
46#ifndef WW3DFORMAT_H
47#define WW3DFORMAT_H
48
49#include "always.h"
50#include "wwstring.h"
51
52class Vector4;
53class Targa;
54
55/*
56** Enum for possible surface formats. This is a small subset of the D3DFORMAT
57** enum which lists the formats supported by DX8; we will add new members to
58** this list as needed (keeping it in the same order as D3DFORMAT).
59** NOTE: Whenever this is changed, formconv.h/.cpp must be modified as well
60** (that contains the code for converting between this and D3DFORMAT)..
61**
62** The format names use the D3DFORMAT conventions:
63** A = Alpha
64** R = Red
65** G = Green
66** B = Blue
67** X = Unused Bits
68** P = Palette
69** L = Luminance
70**
71** Further, the order of the pieces are from MSB first; hence
72** WW3D_FORMAT_A8L8 indicates that the high byte of this two byte
73** format is alpha.
74*/
103
104// depth stencil buffer formats
106{
108 WW3D_ZFORMAT_D16_LOCKABLE, // 16-bit z-buffer bit depth. This is an application-lockable surface format.
109 WW3D_ZFORMAT_D32, // 32-bit z-buffer bit depth.
110 WW3D_ZFORMAT_D15S1, // 16-bit z-buffer bit depth where 15 bits are reserved for the depth channel and 1 bit is reserved for the stencil channel.
111 WW3D_ZFORMAT_D24S8, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
112 WW3D_ZFORMAT_D16, // 16-bit z-buffer bit depth.
113 WW3D_ZFORMAT_D24X8, // 32-bit z-buffer bit depth using 24 bits for the depth channel.
114 WW3D_ZFORMAT_D24X4S4, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
115#ifdef _XBOX
116 WW3D_ZFORMAT_LIN_D24S8,
117 WW3D_ZFORMAT_LIN_F24S8,
118 WW3D_ZFORMAT_LIN_D16,
119 WW3D_ZFORMAT_LIN_F16,
120#endif
122};
123
124// Utility function - not much used otherwise it would use an array.
125// NOTE: when adding values to WW3DFormat add here also (if they have alpha).
126inline bool Has_Alpha(WW3DFormat format) {
127 switch (format) {
131 case WW3D_FORMAT_A8:
133 case WW3D_FORMAT_A8P8:
134 case WW3D_FORMAT_A8L8:
135 case WW3D_FORMAT_A4L4:
136 case WW3D_FORMAT_DXT2:
137 case WW3D_FORMAT_DXT3:
138 case WW3D_FORMAT_DXT4:
139 case WW3D_FORMAT_DXT5:
140 return true;
141 break;
142 default:
143 return false;
144 break;
145 };
146}
147
148inline int Alpha_Bits(WW3DFormat format) {
149 switch (format) {
151 case WW3D_FORMAT_A8:
153 case WW3D_FORMAT_A8P8:
154 case WW3D_FORMAT_A8L8:
155 return 8;
156 break;
158 case WW3D_FORMAT_A4L4:
159 case WW3D_FORMAT_DXT3:
160 case WW3D_FORMAT_DXT4:
161 case WW3D_FORMAT_DXT5:
162 return 4;
163 break;
165 case WW3D_FORMAT_DXT2:
166 return 1;
167 break;
168 default:
169 return 0;
170 break;
171 };
172}
173
174// Color convertion routines
175
176// The color will be returned as an unsigned int always
177// any unused bits will be garbage
178void Vector4_to_Color(unsigned int *outc,const Vector4 &inc,const WW3DFormat format);
179
180// If the format does not support alpha
181// the alpha will be garbage
182void Color_to_Vector4(Vector4* outc,const unsigned int inc,const WW3DFormat format);
183
184// Define matching WW3D format based from Targa header.
185//
186// dest_format - WW3DFormat that can be used as a destination (D3D surface) on current hardware
187// src_format - WW3DFormat that represents the format the bitmap is stored in the targa file.
188// src_bpp - bytes per pixel in the source surface
189// targa - reference to the targa object...
190void Get_WW3D_Format(WW3DFormat& dest_format,WW3DFormat& src_format,unsigned& src_bpp,const Targa& targa);
191
192// The same as above, but doesn't validate the device - only checks the source format.
193void Get_WW3D_Format(WW3DFormat& src_format,unsigned& src_bpp,const Targa& targa);
194
195// Get valid texture format (on current hardware) that is closest to the given format (for instance, 32 bit ARGB8888 would
196// return 16 bit ARGB4444 if the device doesn't support 32 bit textures).
197// Pass false to the second parameter if you don't wish to consider compressed textures on hardware that supports them.
198// The parameter has no effect on hardware that doesn't support compression.
199WW3DFormat Get_Valid_Texture_Format(WW3DFormat format,bool is_compression_allowed);
200
201unsigned Get_Bytes_Per_Pixel(WW3DFormat format);
202
205
206unsigned Get_Num_Depth_Bits(WW3DZFormat zformat);
207unsigned Get_Num_Stencil_Bits(WW3DZFormat zformat);
208
209#endif
Definition TARGA.H:260
bool Has_Alpha(WW3DFormat format)
Definition ww3dformat.h:126
int Alpha_Bits(WW3DFormat format)
Definition ww3dformat.h:148
unsigned Get_Num_Depth_Bits(WW3DZFormat zformat)
void Vector4_to_Color(unsigned int *outc, const Vector4 &inc, const WW3DFormat format)
void Color_to_Vector4(Vector4 *outc, const unsigned int inc, const WW3DFormat format)
unsigned Get_Bytes_Per_Pixel(WW3DFormat format)
WW3DFormat
Definition ww3dformat.h:75
@ WW3D_FORMAT_R5G6B5
Definition ww3dformat.h:80
@ WW3D_FORMAT_X8L8V8U8
Definition ww3dformat.h:95
@ WW3D_FORMAT_DXT3
Definition ww3dformat.h:98
@ WW3D_FORMAT_R3G3B2
Definition ww3dformat.h:84
@ WW3D_FORMAT_L8
Definition ww3dformat.h:90
@ WW3D_FORMAT_DXT2
Definition ww3dformat.h:97
@ WW3D_FORMAT_COUNT
Definition ww3dformat.h:101
@ WW3D_FORMAT_X4R4G4B4
Definition ww3dformat.h:87
@ WW3D_FORMAT_A4L4
Definition ww3dformat.h:92
@ WW3D_FORMAT_P8
Definition ww3dformat.h:89
@ WW3D_FORMAT_X8R8G8B8
Definition ww3dformat.h:79
@ WW3D_FORMAT_A8
Definition ww3dformat.h:85
@ WW3D_FORMAT_DXT5
Definition ww3dformat.h:100
@ WW3D_FORMAT_UNKNOWN
Definition ww3dformat.h:76
@ WW3D_FORMAT_L6V5U5
Definition ww3dformat.h:94
@ WW3D_FORMAT_DXT4
Definition ww3dformat.h:99
@ WW3D_FORMAT_A8R3G3B2
Definition ww3dformat.h:86
@ WW3D_FORMAT_A8P8
Definition ww3dformat.h:88
@ WW3D_FORMAT_R8G8B8
Definition ww3dformat.h:77
@ WW3D_FORMAT_DXT1
Definition ww3dformat.h:96
@ WW3D_FORMAT_A4R4G4B4
Definition ww3dformat.h:83
@ WW3D_FORMAT_A8R8G8B8
Definition ww3dformat.h:78
@ WW3D_FORMAT_A1R5G5B5
Definition ww3dformat.h:82
@ WW3D_FORMAT_X1R5G5B5
Definition ww3dformat.h:81
@ WW3D_FORMAT_U8V8
Definition ww3dformat.h:93
@ WW3D_FORMAT_A8L8
Definition ww3dformat.h:91
unsigned Get_Num_Stencil_Bits(WW3DZFormat zformat)
WW3DFormat Get_Valid_Texture_Format(WW3DFormat format, bool is_compression_allowed)
WW3DZFormat
Definition ww3dformat.h:106
@ WW3D_ZFORMAT_D16_LOCKABLE
Definition ww3dformat.h:108
@ WW3D_ZFORMAT_D24X4S4
Definition ww3dformat.h:114
@ WW3D_ZFORMAT_D32
Definition ww3dformat.h:109
@ WW3D_ZFORMAT_D24X8
Definition ww3dformat.h:113
@ WW3D_ZFORMAT_D24S8
Definition ww3dformat.h:111
@ WW3D_ZFORMAT_UNKNOWN
Definition ww3dformat.h:107
@ WW3D_ZFORMAT_COUNT
Definition ww3dformat.h:121
@ WW3D_ZFORMAT_D16
Definition ww3dformat.h:112
@ WW3D_ZFORMAT_D15S1
Definition ww3dformat.h:110
void Get_WW3D_ZFormat_Name(WW3DZFormat format, StringClass &name)
Get W3D depth stencil format string name.
void Get_WW3D_Format(WW3DFormat &dest_format, WW3DFormat &src_format, unsigned &src_bpp, const Targa &targa)
void Get_WW3D_Format_Name(WW3DFormat format, StringClass &name)