Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
matinfo.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:: /VSS_Sync/ww3d2/matinfo.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 8/29/01 7:29p $*
30 * *
31 * $Revision:: 11 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42#ifndef MATINFO_H
43#define MATINFO_H
44
45#include "always.h"
46#include "wwdebug.h"
47#include "vector.h"
48#include "vertmaterial.h"
49#include "texture.h"
50#include "shader.h"
51#ifdef _UNIX
52#include "osdep.h"
53#endif
54
55class MeshModelClass;
57
58/***********************************************************************************************
59** MaterialInfoClass
60**
61** This class gives an interface to the "changeable" material parameters inside a
62** W3D render object. Typically, this will include things like the following:
63** - one or more textures,
64** - the vertex material used by the mesh (defines lighting properties, etc)
65**
66** Another purpose of this class is to actually hold onto a ref for each material
67** object that a mesh uses. The "per-triangle" pointer arrays are not ref counted
68** so the material info serves as a place to hold a reference to each material object
69** that the mesh is using.
70**
71***********************************************************************************************/
73{
75public:
76
80 MaterialInfoClass * Clone(void) const;
81
82 void Reset(void) { Free(); }
83 int Vertex_Material_Count(void) const { return VertexMaterials.Count(); }
84 int Texture_Count(void) const { return Textures.Count(); }
85
87 int Add_Texture(TextureClass * tex);
88
89 int Get_Vertex_Material_Index(const char * name);
90 int Get_Texture_Index(const char * name);
91
93 VertexMaterialClass * Get_Vertex_Material(const char * name);
95 VertexMaterialClass * Peek_Vertex_Material(const char * name);
96 void Replace_Material(int index, VertexMaterialClass *newMaterial);
97 void Reset_Texture_Mappers(void);
100
101 TextureClass * Get_Texture(int index);
102 TextureClass * Get_Texture(const char * name);
103 TextureClass * Peek_Texture(int index);
104 TextureClass * Peek_Texture(const char * name);
105 void Replace_Texture(int index, TextureClass *newTexture);
106
107// void Set_Texture_Reduction_Factor(float trf);
108// void Process_Texture_Reduction(void);
109
110private:
111
112 void Free(void);
113
116
117};
118
119
120
121/***********************************************************************************************
122** MaterialRemapperClass
123** This class is used when we need to "remap" all of the material pointers in a mesh
124** to a new set of cloned materials. Basically, it assumes that you are going to initialize
125** it with two identical material info objects (src and dest) and then you can give it pointers
126** to materials in the "src" material info and it will give you back pointers to materials
127** in the "dest" material info class.
128**
129** This class attempts to take advantage of the fact that meshes should normally be sorted
130** with respect to their materials so we shouldn't really be doing a linear search for
131** each remap...
132**
133** Please Note: this class does not hold references to the materials and is meant only to
134** be used in a temporary fashion. Create it, do your conversion, then delete it :-)
135***********************************************************************************************/
137{
138public:
141
144 void Remap_Mesh(const MeshMatDescClass * srcmeshmatdesc, MeshMatDescClass * destmeshmatdesc);
145
146private:
147
148 struct VmatRemapStruct
149 {
151 VertexMaterialClass * Dest;
152 };
153
154 struct TextureRemapStruct
155 {
156 TextureClass * Src;
157 TextureClass * Dest;
158 };
159
160 MaterialInfoClass * SrcMatInfo;
161 MaterialInfoClass * DestMatInfo;
162
163 int TextureCount;
164 TextureRemapStruct * TextureRemaps;
165 int VertexMaterialCount;
166 VmatRemapStruct * VertexMaterialRemaps;
167
168 VertexMaterialClass * LastSrcVmat;
169 VertexMaterialClass * LastDestVmat;
170 TextureClass * LastSrcTex;
171 TextureClass * LastDestTex;
172};
173
174/***********************************************************************************************
175** MaterialCollectorClass
176**
177** This class can be used to collect all of the unique instances of materials from a mesh.
178** Its original motivation is to solve a problem encountered in trying to save a mesh
179** to disk. There are arrays of pointers to vertex materials in the mesh but no record of
180** the set of unique vertex materials (all pointers could point to the same one...) Similar
181** to the remapper, it tries to take advantage of the fact that the materials and textures
182** should be in sorted order to optimize the lookups...
183**
184** NOTE: pointer comparisons are used to determine if the objects are unique. I don't
185** check whether the contents of the objects are identical. (Exporter does this, I assume
186** that if there are two separate objects, they are that way for a reason here.)
187***********************************************************************************************/
223
224
225
227{
228 if (vmat != NULL) {
229 vmat->Add_Ref();
230 }
231 int index = VertexMaterials.Count();
232 VertexMaterials.Add(vmat);
233 return index;
234}
235
237{
238 for (int i=0; i<VertexMaterials.Count(); i++) {
239 if (stricmp(name,VertexMaterials[i]->Get_Name()) == 0) {
240 return i;
241 }
242 }
243 return -1;
244}
245
247{
248 WWASSERT(index >= 0);
249 WWASSERT(index < VertexMaterials.Count());
250 if (VertexMaterials[index]) {
251 VertexMaterials[index]->Add_Ref();
252 }
253 return VertexMaterials[index];
254}
255
257{
258 int index = Get_Vertex_Material_Index(name);
259 if (index == -1) {
260 return NULL;
261 } else {
262 return Get_Vertex_Material(index);
263 }
264}
265
267{
268 WWASSERT(index >= 0);
269 WWASSERT(index < VertexMaterials.Count());
270 return VertexMaterials[index];
271}
272
274{
275 int index = Get_Vertex_Material_Index(name);
276 if (index == -1) {
277 return NULL;
278 } else {
279 return Peek_Vertex_Material(index);
280 }
281}
282
284{
285 REF_PTR_SET(VertexMaterials[index],newMaterial);
286}
287
289{
290 int vmat_count = VertexMaterials.Count();
291 for (int i = 0; i < vmat_count; i++) {
292 VertexMaterials[i]->Reset_Mappers();
293 }
294}
295
297{
298 int vmat_count = VertexMaterials.Count();
299 for (int i = 0; i < vmat_count; i++) {
300 if (VertexMaterials[i]->Are_Mappers_Time_Variant()) return true;
301 }
302 return false;
303}
304
306{
307 int vmat_count = VertexMaterials.Count();
308 for (int i = 0; i < vmat_count; i++) {
309 VertexMaterials[i]->Make_Unique();
310 }
311}
312
314{
315 int index = Get_Texture_Index(name);
316 if (index == -1) {
317 return NULL;
318 } else {
319 return Get_Texture(index);
320 }
321}
322
324{
325 WWASSERT(index >= 0);
326 WWASSERT(index < Textures.Count());
327 return Textures[index];
328}
329
330inline void MaterialInfoClass::Replace_Texture(int index, TextureClass *newTexture)
331{
332 REF_PTR_SET(Textures[index],newTexture);
333}
334
335#endif // MATINFO_H
#define NULL
Definition BaseType.h:92
#define WWASSERT
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
int Find_Vertex_Material(VertexMaterialClass *mat)
Definition matinfo.cpp:421
VertexMaterialClass * LastMaterial
Definition matinfo.h:220
DynamicVectorClass< TextureClass * > Textures
Definition matinfo.h:217
void Add_Shader(ShaderClass shader)
Definition matinfo.cpp:353
int Get_Texture_Count(void)
Definition matinfo.cpp:381
void Collect_Materials(MeshModelClass *mesh)
Definition matinfo.cpp:280
int Get_Vertex_Material_Count(void)
Definition matinfo.cpp:376
TextureClass * Peek_Texture(int i)
Definition matinfo.cpp:391
int Get_Shader_Count(void)
Definition matinfo.cpp:371
TextureClass * LastTexture
Definition matinfo.h:221
VertexMaterialClass * Peek_Vertex_Material(int i)
Definition matinfo.cpp:396
int Find_Shader(const ShaderClass &shader)
Definition matinfo.cpp:401
void Add_Texture(TextureClass *tex)
Definition matinfo.cpp:343
DynamicVectorClass< VertexMaterialClass * > VertexMaterials
Definition matinfo.h:216
void Add_Vertex_Material(VertexMaterialClass *vmat)
Definition matinfo.cpp:361
DynamicVectorClass< ShaderClass > Shaders
Definition matinfo.h:215
ShaderClass LastShader
Definition matinfo.h:219
ShaderClass Peek_Shader(int i)
Definition matinfo.cpp:386
int Find_Texture(TextureClass *tex)
Definition matinfo.cpp:411
bool Has_Time_Variant_Texture_Mappers(void)
Definition matinfo.h:296
void Make_Vertex_Materials_Unique(void)
Definition matinfo.h:305
VertexMaterialClass * Peek_Vertex_Material(int index)
Definition matinfo.h:266
int Add_Vertex_Material(VertexMaterialClass *vmat)
Definition matinfo.h:226
void Replace_Material(int index, VertexMaterialClass *newMaterial)
Definition matinfo.h:283
int Get_Texture_Index(const char *name)
Definition matinfo.cpp:83
void Reset(void)
Definition matinfo.h:82
int Vertex_Material_Count(void) const
Definition matinfo.h:83
TextureClass * Peek_Texture(int index)
Definition matinfo.h:323
int Texture_Count(void) const
Definition matinfo.h:84
TextureClass * Get_Texture(int index)
Definition matinfo.cpp:93
int Get_Vertex_Material_Index(const char *name)
Definition matinfo.h:236
VertexMaterialClass * Get_Vertex_Material(int index)
Definition matinfo.h:246
TextureClass * Peek_Texture(const char *name)
int Add_Texture(TextureClass *tex)
Definition matinfo.cpp:74
void Replace_Texture(int index, TextureClass *newTexture)
Definition matinfo.h:330
MaterialInfoClass * Clone(void) const
Definition matinfo.cpp:69
void Reset_Texture_Mappers(void)
Definition matinfo.h:288
MaterialRemapperClass(MaterialInfoClass *src, MaterialInfoClass *dest)
Definition matinfo.cpp:134
VertexMaterialClass * Remap_Vertex_Material(VertexMaterialClass *src)
Definition matinfo.cpp:201
void Remap_Mesh(const MeshMatDescClass *srcmeshmatdesc, MeshMatDescClass *destmeshmatdesc)
Definition matinfo.cpp:216
TextureClass * Remap_Texture(TextureClass *src)
Definition matinfo.cpp:186
void Add_Ref(void) const
Definition refcount.cpp:171
RefCountClass(void)
Definition refcount.h:108
#define REF_PTR_SET(dst, src)
Definition refcount.h:79