Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
formconv.cpp
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/formconv.cpp $*
26 * *
27 * Original Author:: Nathaniel Hoffman *
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 06/27/02 1:27p $*
32 * *
33 * $Revision:: 3 $*
34 * *
35 * 06/27/02 KM Z Format support *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39#include "formconv.h"
40
42 D3DFMT_UNKNOWN,
43 D3DFMT_R8G8B8,
44 D3DFMT_A8R8G8B8,
45 D3DFMT_X8R8G8B8,
46 D3DFMT_R5G6B5,
47 D3DFMT_X1R5G5B5,
48 D3DFMT_A1R5G5B5,
49 D3DFMT_A4R4G4B4,
50 D3DFMT_R3G3B2,
51 D3DFMT_A8,
52 D3DFMT_A8R3G3B2,
53 D3DFMT_X4R4G4B4,
54 D3DFMT_A8P8,
55 D3DFMT_P8,
56 D3DFMT_L8,
57 D3DFMT_A8L8,
58 D3DFMT_A4L4,
59 D3DFMT_V8U8, // Bumpmap
60 D3DFMT_L6V5U5, // Bumpmap
61 D3DFMT_X8L8V8U8, // Bumpmap
62 D3DFMT_DXT1,
63 D3DFMT_DXT2,
64 D3DFMT_DXT3,
65 D3DFMT_DXT4,
66 D3DFMT_DXT5
67};
68
69// adding depth stencil format conversion
71{
72#ifndef _XBOX
73 D3DFMT_UNKNOWN,
74 D3DFMT_D16_LOCKABLE, // 16-bit z-buffer bit depth. This is an application-lockable surface format.
75 D3DFMT_D32, // 32-bit z-buffer bit depth.
76 D3DFMT_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.
77 D3DFMT_D24S8, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
78 D3DFMT_D16, // 16-bit z-buffer bit depth.
79 D3DFMT_D24X8, // 32-bit z-buffer bit depth using 24 bits for the depth channel.
80 D3DFMT_D24X4S4, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
81#else
82 D3DFMT_UNKNOWN,
83 D3DFMT_D16_LOCKABLE, // 16-bit z-buffer bit depth. This is an application-lockable surface format.
84 D3DFMT_D32, // 32-bit z-buffer bit depth.
85 D3DFMT_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.
86 D3DFMT_D24S8, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 8 bits for the stencil channel.
87 D3DFMT_D16, // 16-bit z-buffer bit depth.
88 D3DFMT_D24X8, // 32-bit z-buffer bit depth using 24 bits for the depth channel.
89 D3DFMT_D24X4S4, // 32-bit z-buffer bit depth using 24 bits for the depth channel and 4 bits for the stencil channel.
90
91 D3DFMT_LIN_D24S8,
92 D3DFMT_LIN_F24S8,
93 D3DFMT_LIN_D16,
94 D3DFMT_LIN_F16
95#endif
96};
97
98
99/*
100#define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_X8L8V8U8 //A4L4
101WW3DFormat D3DFormatToWW3DFormatConversionArray[HIGHEST_SUPPORTED_D3DFORMAT + 1] = {
102 WW3D_FORMAT_UNKNOWN, // 0
103 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
104 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
105 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
106 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
107 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
108 WW3D_FORMAT_R8G8B8, // 20
109 WW3D_FORMAT_A8R8G8B8,
110 WW3D_FORMAT_X8R8G8B8,
111 WW3D_FORMAT_R5G6B5,
112 WW3D_FORMAT_X1R5G5B5,
113 WW3D_FORMAT_A1R5G5B5,
114 WW3D_FORMAT_A4R4G4B4,
115 WW3D_FORMAT_R3G3B2,
116 WW3D_FORMAT_A8,
117 WW3D_FORMAT_A8R3G3B2,
118 WW3D_FORMAT_X4R4G4B4, // 30
119 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
120 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
121 WW3D_FORMAT_UNKNOWN,
122 WW3D_FORMAT_A8P8, // 40
123 WW3D_FORMAT_P8,
124 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
125 WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN, WW3D_FORMAT_UNKNOWN,
126 WW3D_FORMAT_L8, // 50
127 WW3D_FORMAT_A8L8,
128 WW3D_FORMAT_A4L4
129};
130*/
131
132#ifndef _XBOX
133#define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_X8L8V8U8
134#define HIGHEST_SUPPORTED_D3DZFORMAT D3DFMT_D24X4S4
135#else
136#define HIGHEST_SUPPORTED_D3DFORMAT D3DFMT_LIN_R8G8B8A8
137#define HIGHEST_SUPPORTED_D3DZFORMAT D3DFMT_LIN_F16
138#endif
141
142D3DFORMAT WW3DFormat_To_D3DFormat(WW3DFormat ww3d_format) {
143 if (ww3d_format >= WW3D_FORMAT_COUNT) {
144 return D3DFMT_UNKNOWN;
145 } else {
146 return WW3DFormatToD3DFormatConversionArray[(unsigned int)ww3d_format];
147 }
148}
149
151{
152 switch (d3d_format) {
153 // The DXT-codes are created with FOURCC macro and thus can't be placed in the conversion table
154 case D3DFMT_DXT1: return WW3D_FORMAT_DXT1;
155 case D3DFMT_DXT2: return WW3D_FORMAT_DXT2;
156 case D3DFMT_DXT3: return WW3D_FORMAT_DXT3;
157 case D3DFMT_DXT4: return WW3D_FORMAT_DXT4;
158 case D3DFMT_DXT5: return WW3D_FORMAT_DXT5;
159 default:
160 if (d3d_format > HIGHEST_SUPPORTED_D3DFORMAT) {
161 return WW3D_FORMAT_UNKNOWN;
162 } else {
163 return D3DFormatToWW3DFormatConversionArray[(unsigned int)d3d_format];
164 }
165 break;
166 }
167}
168
169//**********************************************************************************************
171
173D3DFORMAT WW3DZFormat_To_D3DFormat(WW3DZFormat ww3d_zformat)
174{
175 if (ww3d_zformat >= WW3D_ZFORMAT_COUNT)
176 {
177 return D3DFMT_UNKNOWN;
178 }
179 else
180 {
181 return WW3DZFormatToD3DFormatConversionArray[(unsigned int)ww3d_zformat];
182 }
183}
184
185//**********************************************************************************************
187
190{
191 if (d3d_format>HIGHEST_SUPPORTED_D3DZFORMAT)
192 {
194 }
195 else
196 {
197 return D3DFormatToWW3DZFormatConversionArray[(unsigned int)d3d_format];
198 }
199}
200
201//**********************************************************************************************
203
207{
208 for (int i=0;i<HIGHEST_SUPPORTED_D3DFORMAT;++i) {
210 }
211
231
232 // init depth stencil conversion
233 for (i=0; i<HIGHEST_SUPPORTED_D3DZFORMAT; i++)
234 {
236 }
237
245#ifdef _XBOX
246 D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_D24S8]=WW3D_ZFORMAT_LIN_D24S8;
247 D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_F24S8]=WW3D_ZFORMAT_LIN_F24S8;
248 D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_D16]=WW3D_ZFORMAT_LIN_D16;
249 D3DFormatToWW3DZFormatConversionArray[D3DFMT_LIN_F16]=WW3D_ZFORMAT_LIN_F16;
250#endif
251};
D3DFORMAT WW3DFormat_To_D3DFormat(WW3DFormat ww3d_format)
Definition formconv.cpp:142
D3DFORMAT WW3DZFormat_To_D3DFormat(WW3DZFormat ww3d_zformat)
Depth Stencil W3D to D3D format conversion.
Definition formconv.cpp:173
#define HIGHEST_SUPPORTED_D3DFORMAT
Definition formconv.cpp:133
WW3DFormat D3DFormatToWW3DFormatConversionArray[HIGHEST_SUPPORTED_D3DFORMAT+1]
Definition formconv.cpp:139
WW3DZFormat D3DFormatToWW3DZFormatConversionArray[HIGHEST_SUPPORTED_D3DZFORMAT+1]
Definition formconv.cpp:140
D3DFORMAT WW3DFormatToD3DFormatConversionArray[WW3D_FORMAT_COUNT]
Definition formconv.cpp:41
WW3DZFormat D3DFormat_To_WW3DZFormat(D3DFORMAT d3d_format)
D3D to Depth Stencil W3D format conversion.
Definition formconv.cpp:189
D3DFORMAT WW3DZFormatToD3DFormatConversionArray[WW3D_ZFORMAT_COUNT]
Definition formconv.cpp:70
#define HIGHEST_SUPPORTED_D3DZFORMAT
Definition formconv.cpp:134
WW3DFormat D3DFormat_To_WW3DFormat(D3DFORMAT d3d_format)
Definition formconv.cpp:150
void Init_D3D_To_WW3_Conversion()
Init format conversion tables.
Definition formconv.cpp:206
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
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