Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
w3dmtl.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 : Max2W3d *
24 * *
25 * $Archive:: /Commando/Code/Tools/max2w3d/w3dmtl.h $*
26 * *
27 * $Author:: Andre_a $*
28 * *
29 * $Modtime:: 12/07/00 2:47p $*
30 * *
31 * $Revision:: 15 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#if defined(_MSC_VER)
38#pragma once
39#endif
40
41#ifndef W3DMTL_H
42#define W3DMTL_H
43
44#include "always.h"
45#include "w3d_file.h"
46#include "vector.h"
47
48class GameMtl;
49class Mtl;
50class ChunkSaveClass;
51
52
53/*
54** W3dMapClass.
55** This class simply ties together the map info and the map filename
56*/
58{
59public:
61 W3dMapClass(const W3dMapClass & that);
62 ~W3dMapClass(void);
63
64 W3dMapClass & operator = (const W3dMapClass & that);
65
66 void Reset(void);
67 void Set_Filename(const char * name);
68 void Set_Anim_Info(const W3dTextureInfoStruct * info);
69 void Set_Anim_Info(int framecount,float framerate);
70
71 char * Filename;
73};
74
75
76/*
77** W3dMaterialClass.
78** This class ties together w3d structures for up to 'MAX_PASSES' material passes.
79** It is typically plugged into the next class (W3dMaterialDescClass) so that
80** duplicate members can detected and shared.
81*/
83{
84public:
85
86 W3dMaterialClass(void);
88
89 enum { MAX_PASSES = 4, MAX_STAGES = 2 };
90
91 void Reset(void);
92
93 /*
94 ** Construction from Max materials
95 */
96 void Init(Mtl * mtl, char *materialColorTexture=NULL);
97 void Init(GameMtl * gamemtl, char *materialColorTexture=NULL);
98
99 /*
100 ** Manual Construction
101 */
102 void Set_Surface_Type(unsigned int type);
103 void Set_Sort_Level(int level);
104 void Set_Pass_Count(int count);
105 void Set_Vertex_Material(const W3dVertexMaterialStruct & vmat,int pass = 0);
106 void Set_Mapper_Args(const char *args_buffer, int pass = 0, int stage = 0);
107 void Set_Shader(const W3dShaderStruct & shader,int pass = 0);
108 void Set_Texture(const W3dMapClass & map,int pass = 0,int stage = 0);
109 void Set_Map_Channel(int pass,int stage,int channel);
110
111 /*
112 ** Inspection
113 */
114 unsigned int Get_Surface_Type(void) const;
115 int Get_Sort_Level(void) const;
116 int Get_Pass_Count(void) const;
117 W3dVertexMaterialStruct * Get_Vertex_Material(int pass = 0) const;
118 const char * Get_Mapper_Args(int pass /*= 0*/, int stage /*= 0*/) const;
119 W3dShaderStruct Get_Shader(int pass = 0) const;
120 W3dMapClass * Get_Texture(int pass = 0,int stage = 0) const;
121 int Get_Map_Channel(int pass = 0,int stage = 0) const;
122
123 bool Is_Multi_Pass_Transparent(void) const;
124
125protected:
126
127 void Free(void);
128
129 unsigned int SurfaceType;
132
138
139};
140
141
142/*
143** W3dMaterialDescClass
144** This class's purpose is to process the set of w3dmaterials used by a mesh into a set
145** of surrender passes with shaders, vertexmaterials, textures. Part of its job is
146** to detect duplicated shaders and vertex materials and remove them.
147*/
149{
150public:
151
152 typedef enum ErrorType
153 {
154 OK = 0, // material description was built successfully
155 INCONSISTENT_PASSES, // material doesn't have same number of passes
156 MULTIPASS_TRANSPARENT, // material is transparent and multi-pass (NO-NO!)
157 INCONSISTENT_SORT_LEVEL, // material doesn't have the same sort level!
158 };
159
162
163 void Reset(void);
164
165 /*
166 ** Interface for adding a material description. The material will be assigned
167 ** an index based on the order at which they are added. Add your materials in
168 ** order, then use their indices to find the remapped vertex materials, textures,
169 ** and shaders...
170 */
171 ErrorType Add_Material(const W3dMaterialClass & mat,const char * name = NULL);
172
173 /*
174 ** Global Information. These methods give access to all of the unique vertex materials,
175 ** shaders, and textures being used.
176 */
177 int Material_Count(void);
178 int Pass_Count(void);
179 int Vertex_Material_Count(void);
180 int Shader_Count(void);
181 int Texture_Count(void);
182 int Get_Sort_Level(void);
183
185 const char * Get_Mapper_Args(int vmat_index, int stage);
186 W3dShaderStruct * Get_Shader(int shader_index);
187 W3dMapClass * Get_Texture(int texture_index);
188
189 /*
190 ** Per-Pass Information. These methods convert a material index and pass index pair into
191 ** an index to the desired vertex material, texture or shader.
192 */
193 int Get_Vertex_Material_Index(int mat_index,int pass);
194 int Get_Shader_Index(int mat_index,int pass);
195 int Get_Texture_Index(int mat_index,int pass,int stage);
196 W3dVertexMaterialStruct * Get_Vertex_Material(int mat_index,int pass);
197 const char * Get_Mapper_Args(int mat_index,int pass,int stage);
198 W3dShaderStruct * Get_Shader(int mat_index,int pass);
199 W3dMapClass * Get_Texture(int mat_index,int pass,int stage);
200 int Get_Map_Channel(int mat_index,int pass,int stage);
201 bool Stage_Needs_Texture_Coordinates(int pass,int stage);
202 bool Pass_Uses_Vertex_Alpha(int pass);
203 bool Pass_Uses_Alpha(int pass);
204
205 /*
206 ** Vertex Material Names. It will be useful to have named vertex materials. I'll keep
207 ** the name of the first material which contained each vertex material as its name. Use
208 ** these functions to get the name associated with a vertex material
209 */
210 const char * Get_Vertex_Material_Name(int mat_index,int pass);
211 const char * Get_Vertex_Material_Name(int vmat_index);
212
213private:
214
215 int Add_Vertex_Material(W3dVertexMaterialStruct * vmat,const char *mapper_args0,const char *mapper_args1,int pass,const char * name);
216 int Add_Shader(const W3dShaderStruct & shader,int pass);
217 int Add_Texture(W3dMapClass * map,int pass,int stage);
218 unsigned long Compute_Crc(const W3dVertexMaterialStruct & vmat,const char *mapper_args0,const char *mapper_args1);
219 unsigned long Compute_Crc(const W3dShaderStruct & shader);
220 unsigned long Compute_Crc(const W3dMapClass & map);
221 unsigned long Add_String_To_Crc(const char *str, unsigned long crc);
222
223 /*
224 ** MaterialRemapClass
225 ** When the user supplies a W3dMaterial to this material description class,
226 ** its sub-parts are installed and an instance of this class is created to
227 ** re-index to each one.
228 */
229 class MaterialRemapClass
230 {
231 public:
232 MaterialRemapClass(void);
233
234 bool operator != (const MaterialRemapClass & that);
235 bool operator == (const MaterialRemapClass & that);
236
237 int PassCount;
238 int VertexMaterialIdx[W3dMaterialClass::MAX_PASSES];
239 int ShaderIdx[W3dMaterialClass::MAX_PASSES];
242 };
243
244 /*
245 ** VertMatClass
246 ** This class encapsulates a vertex material structure and makes it extendable for
247 ** any purposes needed by the plugin code. For example, the pass index is stored
248 ** so that we can prevent "welding" of vertex materials in different passes (since
249 ** this may not be desireable...)
250 */
251 class VertMatClass
252 {
253 public:
254 VertMatClass(void);
255 ~VertMatClass(void);
256
257 VertMatClass & VertMatClass::operator = (const VertMatClass & that);
258 bool operator != (const VertMatClass & that);
259 bool operator == (const VertMatClass & that);
260 void Set_Name(const char * name);
261 void Set_Mapper_Args(const char * args, int stage);
262
263 W3dVertexMaterialStruct Material;
264 char * MapperArgs[W3dMaterialClass::MAX_STAGES]; // note: these strings are new'ed, not malloc'ed (unlike Name)
265 int PassIndex; // using this to prevent joining of vertmats in different passes.
266 int Crc; // crc, used for quick rejection when checking for matches.
267 char * Name; // material name associated with the first occurence of this vmat.
268 };
269
270 /*
271 ** ShadeClass
272 ** Again, simply here to make the shader extendable for any purposes needed by this
273 ** pre-processing code...
274 */
275 class ShadeClass
276 {
277 public:
278 ShadeClass & operator = (const ShadeClass & that) { Shader = that.Shader; Crc = that.Crc; return *this;}
279 bool operator != (const ShadeClass & that) { return !(*this == that); }
280 bool operator == (const ShadeClass & that) { assert(0); return false; }
281
282 W3dShaderStruct Shader;
283 int Crc;
284 };
285
286 /*
287 ** TexClass
288 ** Simply here to allow extra info to be stored with each texture, as needed by this
289 ** pre-processing code...
290 */
291 class TexClass
292 {
293 public:
294 TexClass & operator = (const TexClass & that) { Map = that.Map; Crc = that.Crc; return *this; }
295 bool operator != (const TexClass & that) { return !(*this == that); }
296 bool operator == (const TexClass & that) { assert(0); return false; }
297
298 W3dMapClass Map;
299 int Crc;
300 };
301
302 int PassCount;
303 int SortLevel;
304 DynamicVectorClass < MaterialRemapClass > MaterialRemaps;
305 DynamicVectorClass < ShadeClass > Shaders;
306 DynamicVectorClass < VertMatClass > VertexMaterials;
307 DynamicVectorClass < TexClass > Textures;
308
309};
310
311
312
313#endif
#define NULL
Definition BaseType.h:92
void Set_Anim_Info(const W3dTextureInfoStruct *info)
Definition w3dmtl.cpp:113
~W3dMapClass(void)
Definition w3dmtl.cpp:80
void Set_Filename(const char *name)
Definition w3dmtl.cpp:94
W3dMapClass & operator=(const W3dMapClass &that)
Definition w3dmtl.cpp:71
W3dMapClass(void)
Definition w3dmtl.h:60
char * Filename
Definition w3dmtl.h:71
W3dTextureInfoStruct * AnimInfo
Definition w3dmtl.h:72
void Reset(void)
Definition w3dmtl.cpp:86
void Set_Vertex_Material(const W3dVertexMaterialStruct &vmat, int pass=0)
Definition w3dmtl.cpp:224
void Set_Sort_Level(int level)
Definition w3dmtl.cpp:211
char * MapperArgs[MAX_PASSES][MAX_STAGES]
Definition w3dmtl.h:135
int Get_Sort_Level(void) const
Definition w3dmtl.cpp:284
const char * Get_Mapper_Args(int pass, int stage) const
Definition w3dmtl.cpp:302
W3dMapClass * Textures[MAX_PASSES][MAX_STAGES]
Definition w3dmtl.h:136
void Set_Shader(const W3dShaderStruct &shader, int pass=0)
Definition w3dmtl.cpp:253
void Set_Map_Channel(int pass, int stage, int channel)
Definition w3dmtl.cpp:272
int Get_Pass_Count(void) const
Definition w3dmtl.cpp:289
W3dVertexMaterialStruct * Materials[MAX_PASSES]
Definition w3dmtl.h:134
W3dMapClass * Get_Texture(int pass=0, int stage=0) const
Definition w3dmtl.cpp:319
int Get_Map_Channel(int pass=0, int stage=0) const
Definition w3dmtl.cpp:329
W3dVertexMaterialStruct * Get_Vertex_Material(int pass=0) const
Definition w3dmtl.cpp:294
int MapChannel[MAX_PASSES][MAX_STAGES]
Definition w3dmtl.h:137
void Set_Pass_Count(int count)
Definition w3dmtl.cpp:217
bool Is_Multi_Pass_Transparent(void) const
Definition w3dmtl.cpp:666
unsigned int Get_Surface_Type(void) const
Definition w3dmtl.cpp:279
void Set_Mapper_Args(const char *args_buffer, int pass=0, int stage=0)
Definition w3dmtl.cpp:235
void Reset(void)
Definition w3dmtl.cpp:193
void Free(void)
Definition w3dmtl.cpp:170
unsigned int SurfaceType
Definition w3dmtl.h:129
~W3dMaterialClass(void)
Definition w3dmtl.cpp:165
W3dShaderStruct Shaders[MAX_PASSES]
Definition w3dmtl.h:133
void Init(Mtl *mtl, char *materialColorTexture=NULL)
Definition w3dmtl.cpp:339
W3dShaderStruct Get_Shader(int pass=0) const
Definition w3dmtl.cpp:312
W3dMaterialClass(void)
Definition w3dmtl.cpp:150
void Set_Surface_Type(unsigned int type)
Definition w3dmtl.cpp:206
void Set_Texture(const W3dMapClass &map, int pass=0, int stage=0)
Definition w3dmtl.cpp:261
W3dMapClass * Get_Texture(int texture_index)
Definition w3dmtl.cpp:933
bool Pass_Uses_Vertex_Alpha(int pass)
Definition w3dmtl.cpp:1050
const char * Get_Vertex_Material_Name(int mat_index, int pass)
Definition w3dmtl.cpp:1014
int Pass_Count(void)
Definition w3dmtl.cpp:885
int Vertex_Material_Count(void)
Definition w3dmtl.cpp:890
~W3dMaterialDescClass(void)
Definition w3dmtl.cpp:800
int Get_Vertex_Material_Index(int mat_index, int pass)
Definition w3dmtl.cpp:940
ErrorType Add_Material(const W3dMaterialClass &mat, const char *name=NULL)
Definition w3dmtl.cpp:815
W3dShaderStruct * Get_Shader(int shader_index)
Definition w3dmtl.cpp:926
bool Stage_Needs_Texture_Coordinates(int pass, int stage)
Definition w3dmtl.cpp:1029
int Shader_Count(void)
Definition w3dmtl.cpp:895
int Get_Shader_Index(int mat_index, int pass)
Definition w3dmtl.cpp:949
int Material_Count(void)
Definition w3dmtl.cpp:880
int Get_Sort_Level(void)
Definition w3dmtl.cpp:905
const char * Get_Mapper_Args(int vmat_index, int stage)
Definition w3dmtl.cpp:917
W3dVertexMaterialStruct * Get_Vertex_Material(int vmat_index)
Definition w3dmtl.cpp:910
int Get_Texture_Index(int mat_index, int pass, int stage)
Definition w3dmtl.cpp:958
int Get_Map_Channel(int mat_index, int pass, int stage)
Definition w3dmtl.cpp:1009
bool Pass_Uses_Alpha(int pass)
Definition w3dmtl.cpp:1065
int Texture_Count(void)
Definition w3dmtl.cpp:900