Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
meshmatdesc.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/meshmatdesc.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Greg_h $*
30 * *
31 * $Modtime:: 1/18/02 3:08p $*
32 * *
33 * $Revision:: 14 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#ifndef MESHMATDESC_H
40#define MESHMATDESC_H
41
42#include "always.h"
43#include "vector2.h"
44#include "vector3.h"
45#include "vector3i.h"
46#include "vector4.h"
47#include "sharebuf.h"
48#include "shader.h"
49#include "vertmaterial.h"
50
51class MatBufferClass;
52class TexBufferClass;
53class UVBufferClass;
54class TextureClass;
55class MeshModelClass;
56
62{
64public:
65
66 enum
67 {
72 };
73
74 MeshMatDescClass(void);
77 void Reset(int polycount,int vertcount,int passcount);
79
80 /*
81 ** Initialize the alternate material description by copying the default materials
82 ** and overriding the entries that exist in the alternate_desc
83 */
84 void Init_Alternate(MeshMatDescClass & def_mat_desc,MeshMatDescClass & alternate_desc);
85 bool Is_Empty(void);
86
87 /*
88 ** Counts, make sure the vertex and polygon counts match the parent mesh.
89 */
90 void Set_Pass_Count(int passes) { PassCount = passes; }
91 int Get_Pass_Count(void) const { return PassCount; }
92 void Set_Vertex_Count(int vertcount) { VertexCount = vertcount; }
93 int Get_Vertex_Count(void) const { return VertexCount; }
94 void Set_Polygon_Count(int polycount) { PolyCount = polycount; }
95 int Get_Polygon_Count(void) const { return PolyCount; }
96
97 /*
98 ** Material Interface
99 */
100 Vector2 * Get_UV_Array(int pass,int stage);
101 void Install_UV_Array(int pass,int stage,Vector2 * uvs,int count);
102 void Set_UV_Source(int pass,int stage,int sourceindex);
103 int Get_UV_Source(int pass,int stage);
104
105 int Get_UV_Array_Count(void);
106 Vector2 * Get_UV_Array_By_Index(int index, bool create = true);
107
108 unsigned* Get_DCG_Array(int pass);
109 unsigned* Get_DIG_Array(int pass);
114 unsigned * Get_Color_Array(int array,bool create = true);
115
116 void Set_Single_Material(VertexMaterialClass * vmat,int pass=0);
117 void Set_Single_Texture(TextureClass * tex,int pass=0,int stage=0);
118 void Set_Single_Shader(ShaderClass shader,int pass=0);
119
120 /*
121 ** the "Get" functions add a reference before returning the pointer (if appropriate)
122 */
123 VertexMaterialClass * Get_Single_Material(int pass=0) const;
124 TextureClass * Get_Single_Texture(int pass=0,int stage=0) const;
125 ShaderClass Get_Single_Shader(int pass=0) const;
126
127 /*
128 ** the "Peek" functions just return the pointer and it's the caller's responsibility to
129 ** maintain a reference to an object with a reference to the data
130 */
131 VertexMaterialClass * Peek_Single_Material(int pass=0) const;
132 TextureClass * Peek_Single_Texture(int pass=0,int stage=0) const;
133
134 void Set_Material(int vidx,VertexMaterialClass * vmat,int pass=0);
135 void Set_Shader(int pidx,ShaderClass shader,int pass=0);
136 void Set_Texture(int pidx,TextureClass * tex,int pass=0,int stage=0);
137
138 /*
139 ** Queries for determining whether this model has per-polygon arrays of Materials, Shaders, or Textures
140 */
141 bool Has_Material_Array(int pass) const;
142 bool Has_Shader_Array(int pass) const;
143 bool Has_Texture_Array(int pass,int stage) const;
144
145 /*
146 ** Determine whether this material description contains data for the specified category
147 */
148 bool Has_UV(int pass,int stage) { return UVSource[pass][stage] != -1; }
149 bool Has_Color_Array(int array) { return ColorArray[array] != NULL; }
150
151 bool Has_Texture_Data(int pass,int stage) { return (Texture[pass][stage] != NULL) || (TextureArray[pass][stage] != NULL); }
152 bool Has_Shader_Data(int pass) { return (Shader[pass] != NullShader) || (ShaderArray[pass] != NULL); }
153 bool Has_Material_Data(int pass) { return (Material[pass] != NULL) || (MaterialArray[pass] != NULL); }
154
155 /*
156 ** "Get" functions for Materials, Textures, and Shaders when there are more than one (per-polygon or per-vertex)
157 */
158 VertexMaterialClass * Get_Material(int vidx,int pass=0) const;
159 TextureClass * Get_Texture(int pidx,int pass=0,int stage=0) const;
160 ShaderClass Get_Shader(int pidx,int pass=0) const;
161
162 /*
163 ** "Peek" functions for Materials and Textures when there are more than one (per-polygon or per-vertex)
164 */
165 VertexMaterialClass * Peek_Material(int vidx,int pass=0) const;
166 TextureClass * Peek_Texture(int pidx,int pass=0,int stage=0) const;
167
168 /*
169 ** Access to the arrays
170 */
171 TexBufferClass * Get_Texture_Array(int pass,int stage,bool create = true);
172 MatBufferClass * Get_Material_Array(int pass,bool create = true);
173 ShaderClass * Get_Shader_Array(int pass,bool create = true);
174
175 void Make_UV_Array_Unique(int pass,int stage);
176 void Make_Color_Array_Unique(int index);
177
178 /*
179 ** Post-Load processing, configures all materials to use the correct passes and
180 ** material color sources, etc.
181 */
182 void Post_Load_Process(bool enable_lighting = true,MeshModelClass * parent = NULL);
184
185 /*
186 ** Do any of the vertex materials require vertex normals?
187 */
188 bool Do_Mappers_Need_Normals(void);
189
190 static ShaderClass NullShader; // Used to mark no shader data
191
192protected:
193
194 void Configure_Material(VertexMaterialClass * mtl,int pass,bool lighting_enabled);
195 void Disable_Backface_Culling(void);
196 void Delete_Pass(int pass);
197
201
202 // u-v coordinates
205
206 // vertex color arrays, we support two arrays: each can only be used on the
207 // first pass.
211
212 // default textures, shader, vmat
216
217 // array textures, shaders, vmats
221
222 friend class MeshModelClass;
223};
224
225
232class MatBufferClass : public ShareBufferClass < VertexMaterialClass * >
233{
235public:
236 MatBufferClass(int count, const char* msg) : ShareBufferClass<VertexMaterialClass *>(count, msg) { Clear(); }
237 MatBufferClass(const MatBufferClass & that);
238 ~MatBufferClass(void);
239
240 void Set_Element(int index,VertexMaterialClass * mat);
241 VertexMaterialClass * Get_Element(int index);
243
244private:
245 // not implemented
246 MatBufferClass & operator = (const MatBufferClass & that);
247};
248
254class TexBufferClass : public ShareBufferClass < TextureClass * >
255{
257public:
258 TexBufferClass(int count, const char* msg) : ShareBufferClass<TextureClass *>(count, msg) { Clear(); }
259 TexBufferClass(const TexBufferClass & that);
260 ~TexBufferClass(void);
261
262 void Set_Element(int index,TextureClass * mat);
263 TextureClass * Get_Element(int index);
264 TextureClass * Peek_Element(int index);
265
266private:
267 // not implemented
268 TexBufferClass & operator = (const TexBufferClass & that);
269};
270
276class UVBufferClass : public ShareBufferClass < Vector2 >
277{
279public:
280 UVBufferClass(int count, const char* msg) : ShareBufferClass<Vector2>(count, msg), CRC(0xFFFFFFFF) { }
281 UVBufferClass(const UVBufferClass & that);
282
283 bool operator == (const UVBufferClass & that);
284 bool Is_Equal_To(const UVBufferClass & that);
285
286 void Update_CRC(void);
287 unsigned int Get_CRC(void) { return CRC; }
288
289private:
290 unsigned int CRC;
291
292 // not implemented
293 UVBufferClass & operator = (const UVBufferClass & that);
294};
295
296/*********************************************************************************************************
297**
298** MeshMatDescClass Inline Functions
299** These functions manage the data associated with the material description for the mesh. Since there
300** can be an alternate material description, these functions are encapsulated into MatDescClass.
301**
302*********************************************************************************************************/
303
304inline Vector2 * MeshMatDescClass::Get_UV_Array(int pass,int stage)
305{
306 if (UVSource[pass][stage] == -1) {
307 return NULL;
308 }
309 if (UV[UVSource[pass][stage]] != NULL) {
310 return UV[UVSource[pass][stage]]->Get_Array();
311 }
312 return NULL;
313}
314
315inline void MeshMatDescClass::Set_UV_Source(int pass,int stage,int sourceindex)
316{
317 WWASSERT(pass >= 0);
318 WWASSERT(pass < MAX_PASSES);
319 WWASSERT(stage >= 0);
320 WWASSERT(stage < MAX_TEX_STAGES);
321 UVSource[pass][stage] = sourceindex;
322}
323
324inline int MeshMatDescClass::Get_UV_Source(int pass,int stage)
325{
326 WWASSERT(pass >= 0);
327 WWASSERT(pass < MAX_PASSES);
328 WWASSERT(stage >= 0);
329 WWASSERT(stage < MAX_TEX_STAGES);
330 return UVSource[pass][stage];
331}
332
334{
335 int count = 0;
336 while ((UV[count] != NULL) && (count < MAX_UV_ARRAYS)) {
337 count++;
338 }
339 return count;
340}
341
342inline Vector2 * MeshMatDescClass::Get_UV_Array_By_Index(int index, bool create)
343{
344 WWASSERT((index >= 0)&&(index < MAX_UV_ARRAYS));
345
346 if (create && !UV[index]) {
347 UV[index] = NEW_REF(UVBufferClass,(VertexCount, "MeshMatDescClass::UV"));
348 }
349 if (UV[index] != NULL) {
350 return UV[index]->Get_Array();
351 }
352 return NULL;
353}
354
355inline unsigned* MeshMatDescClass::Get_DCG_Array(int pass)
356{
357 WWASSERT(pass >= 0);
358 WWASSERT(pass < MAX_PASSES);
359 switch (DCGSource[pass]) {
361 return NULL;
362 break;
364 if (ColorArray[0]) {
365 return ColorArray[0]->Get_Array();
366 } else {
367 return NULL;
368 }
369 break;
371 if (ColorArray[1]) {
372 return ColorArray[1]->Get_Array();
373 } else {
374 return NULL;
375 }
376 break;
377 default:
378 WWASSERT(0);
379 return(NULL);
380 break;
381 };
382}
383
384inline unsigned * MeshMatDescClass::Get_DIG_Array(int pass)
385{
386 WWASSERT(pass >= 0);
387 WWASSERT(pass < MAX_PASSES);
388 switch (DIGSource[pass]) {
390 return NULL;
391 break;
393 if (ColorArray[0]) {
394 return ColorArray[0]->Get_Array();
395 } else {
396 return NULL;
397 }
398 break;
400 if (ColorArray[1]) {
401 return ColorArray[1]->Get_Array();
402 } else {
403 return NULL;
404 }
405 break;
406 default:
407 WWASSERT(0);
408 return(NULL);
409 break;
410 };
411}
412
414{
415 DCGSource[pass] = source;
416}
417
419{
420 DIGSource[pass] = source;
421}
422
427
432
433inline unsigned * MeshMatDescClass::Get_Color_Array(int index,bool create)
434{
435 if (create && !ColorArray[index]) {
436 ColorArray[index] = NEW_REF(ShareBufferClass<unsigned>,(VertexCount, "MeshMatDescClass::ColorArray"));
437 }
438 if (ColorArray[index]) {
439 return ColorArray[index]->Get_Array();
440 }
441 return NULL;
442}
443
445{
446 if (Material[pass]) {
447 Material[pass]->Add_Ref();
448 }
449 return Material[pass];
450}
451
453{
454 return Material[pass];
455}
456
457inline TextureClass * MeshMatDescClass::Peek_Single_Texture(int pass,int stage) const
458{
459 return Texture[pass][stage];
460}
461
463{
464 return Shader[pass];
465}
466
467inline bool MeshMatDescClass::Has_Material_Array(int pass) const
468{
469 return (MaterialArray[pass] != NULL);
470}
471
472inline bool MeshMatDescClass::Has_Shader_Array(int pass) const
473{
474 return (ShaderArray[pass] != NULL);
475}
476
477inline bool MeshMatDescClass::Has_Texture_Array(int pass,int stage) const
478{
479 return (TextureArray[pass][stage] != NULL);
480}
481
483{
484 for (int pass = 0; pass < PassCount; pass++) {
485 Shader[pass].Set_Cull_Mode(ShaderClass::CULL_MODE_DISABLE);
486 if (ShaderArray[pass]) {
487 for (int tri = 0; tri < ShaderArray[pass]->Get_Count(); tri++) {
488 ShaderArray[pass]->Get_Element(tri).Set_Cull_Mode(ShaderClass::CULL_MODE_DISABLE);
489 }
490 }
491 }
492}
493
494#endif //MESHMATDESC_H
495
#define NULL
Definition BaseType.h:92
#define WWASSERT
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
Definition crc.h:59
VertexMaterialClass * Peek_Element(int index)
VertexMaterialClass * Get_Element(int index)
void Set_Element(int index, VertexMaterialClass *mat)
MatBufferClass(int count, const char *msg)
TextureClass * Texture[MAX_PASSES][MAX_TEX_STAGES]
int Get_Pass_Count(void) const
Definition meshmatdesc.h:91
VertexMaterialClass * Peek_Material(int vidx, int pass=0) const
friend class MeshModelClass
unsigned * Get_Color_Array(int array, bool create=true)
void Install_UV_Array(int pass, int stage, Vector2 *uvs, int count)
TexBufferClass * TextureArray[MAX_PASSES][MAX_TEX_STAGES]
VertexMaterialClass * Material[MAX_PASSES]
MatBufferClass * Get_Material_Array(int pass, bool create=true)
void Set_Texture(int pidx, TextureClass *tex, int pass=0, int stage=0)
ShareBufferClass< ShaderClass > * ShaderArray[MAX_PASSES]
bool Has_Texture_Data(int pass, int stage)
ShaderClass Shader[MAX_PASSES]
int Get_UV_Source(int pass, int stage)
Vector2 * Get_UV_Array_By_Index(int index, bool create=true)
void Delete_Pass(int pass)
VertexMaterialClass * Get_Single_Material(int pass=0) const
VertexMaterialClass::ColorSourceType Get_DIG_Source(int pass)
Vector2 * Get_UV_Array(int pass, int stage)
TextureClass * Get_Single_Texture(int pass=0, int stage=0) const
bool Has_UV(int pass, int stage)
void Reset(int polycount, int vertcount, int passcount)
void Set_Single_Texture(TextureClass *tex, int pass=0, int stage=0)
void Set_Shader(int pidx, ShaderClass shader, int pass=0)
int Get_Vertex_Count(void) const
Definition meshmatdesc.h:93
VertexMaterialClass::ColorSourceType DCGSource[MAX_PASSES]
bool Has_Shader_Array(int pass) const
TextureClass * Get_Texture(int pidx, int pass=0, int stage=0) const
void Configure_Material(VertexMaterialClass *mtl, int pass, bool lighting_enabled)
unsigned * Get_DCG_Array(int pass)
ShaderClass Get_Shader(int pidx, int pass=0) const
void Set_Vertex_Count(int vertcount)
Definition meshmatdesc.h:92
void Disable_Lighting(void)
static ShaderClass NullShader
unsigned * Get_DIG_Array(int pass)
TexBufferClass * Get_Texture_Array(int pass, int stage, bool create=true)
ShaderClass * Get_Shader_Array(int pass, bool create=true)
int Get_UV_Array_Count(void)
VertexMaterialClass * Peek_Single_Material(int pass=0) const
int Get_Polygon_Count(void) const
Definition meshmatdesc.h:95
void Post_Load_Process(bool enable_lighting=true, MeshModelClass *parent=NULL)
UVBufferClass * UV[MAX_UV_ARRAYS]
bool Has_Texture_Array(int pass, int stage) const
MeshMatDescClass & operator=(const MeshMatDescClass &that)
void Make_Color_Array_Unique(int index)
void Set_UV_Source(int pass, int stage, int sourceindex)
MatBufferClass * MaterialArray[MAX_PASSES]
bool Has_Shader_Data(int pass)
VertexMaterialClass * Get_Material(int vidx, int pass=0) const
bool Do_Mappers_Need_Normals(void)
bool Has_Color_Array(int array)
void Set_Pass_Count(int passes)
Definition meshmatdesc.h:90
void Set_Material(int vidx, VertexMaterialClass *vmat, int pass=0)
void Init_Alternate(MeshMatDescClass &def_mat_desc, MeshMatDescClass &alternate_desc)
void Make_UV_Array_Unique(int pass, int stage)
void Set_Single_Material(VertexMaterialClass *vmat, int pass=0)
TextureClass * Peek_Single_Texture(int pass=0, int stage=0) const
VertexMaterialClass::ColorSourceType Get_DCG_Source(int pass)
bool Has_Material_Data(int pass)
TextureClass * Peek_Texture(int pidx, int pass=0, int stage=0) const
bool Is_Empty(void)
void Disable_Backface_Culling(void)
ShaderClass Get_Single_Shader(int pass=0) const
void Set_DCG_Source(int pass, VertexMaterialClass::ColorSourceType source)
void Set_Polygon_Count(int polycount)
Definition meshmatdesc.h:94
void Set_DIG_Source(int pass, VertexMaterialClass::ColorSourceType source)
void Set_Single_Shader(ShaderClass shader, int pass=0)
VertexMaterialClass::ColorSourceType DIGSource[MAX_PASSES]
ShareBufferClass< unsigned > * ColorArray[2]
bool Has_Material_Array(int pass) const
int UVSource[MAX_PASSES][MAX_TEX_STAGES]
@ CULL_MODE_DISABLE
Definition shader.h:158
ShareBufferClass(int count, const char *msg)
Definition sharebuf.h:91
TextureClass * Get_Element(int index)
TexBufferClass(int count, const char *msg)
void Set_Element(int index, TextureClass *mat)
TextureClass * Peek_Element(int index)
void Update_CRC(void)
unsigned int Get_CRC(void)
UVBufferClass(int count, const char *msg)
bool operator==(const UVBufferClass &that)
bool Is_Equal_To(const UVBufferClass &that)
MSG msg
Definition patch.cpp:409
#define NEW_REF(C, P)
Definition refcount.h:62