Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
vertmaterial.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/vertmaterial.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 4/27/01 2:22p $*
30 * *
31 * $Revision:: 25 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42#ifndef VERTMATERIAL_H
43#define VERTMATERIAL_H
44
45#include "always.h"
46
47#include "refcount.h"
48#include "vector3.h"
49#include "w3d_file.h"
50#include "meshbuild.h"
51#include "w3derr.h"
52#include "mapper.h"
53#include "wwstring.h"
54
55#include <string.h>
56
57class ChunkLoadClass;
58class ChunkSaveClass;
59
60#define DYN_MAT8
61#ifdef DYN_MAT8
62class DynD3DMATERIAL8;
63#else
64struct _D3DMATERIAL8;
65#endif
66
73{
75
76 friend DX8Wrapper;
77
78public:
79 /*
80 ** Similar to the TextureClass, these enumerations are set up to be exactly the same as
81 ** the surrender material enumerations. Nearly all functions in this class are inline
82 ** so that it will go away since the only purpose of Material Class is to protect our
83 ** application code from the ever-changing surrender...
84 */
86 MAPPING_NONE = -1, // no mapping needed
87 MAPPING_UV = W3DMAPPING_UV, // default, use the u-v values in the model
88 MAPPING_ENVIRONMENT = W3DMAPPING_ENVIRONMENT, // use the environment mapper
89 };
90
91 enum FlagsType {
92 DEPTH_CUE= 0, // enable depth cueing (default = false)
95 };
96
98 MATERIAL = 0, // D3DMCS_MATERIAL - the color source should be taken from the material setting
99 COLOR1, // D3DMCS_COLOR1 - the color should be taken from per-vertex color array 1 (aka D3DFVF_DIFFUSE)
100 COLOR2, // D3DMCS_COLOR2 - the color should be taken from per-vertex color array 2 (aka D3DFVF_SPECULAR)
101 };
102
109
110
114
116 VertexMaterialClass * Clone(void) { VertexMaterialClass * mat = NEW_REF (VertexMaterialClass,()); *mat = *this; return mat;}
117
118 /*
119 ** Name Access
120 */
121 void Set_Name(const char * name)
122 {
123 Name = name;
124 }
125
126 const char * Get_Name(void) const
127 {
128 return Name;
129 }
130
131 /*
132 ** Control over the material flags
133 */
134 void Set_Flag(FlagsType flag,bool onoff)
135 {
136 CRCDirty=true;
137 if (onoff)
138 Flags|=(1<<flag);
139 else
140 Flags&=~(1<<flag);
141 }
143 { return (Flags>>flag) & 0x1; }
144
145 /*
146 ** Basic material properties
147 */
148 float Get_Shininess(void) const;
149 void Set_Shininess(float shin);
150
151 float Get_Opacity(void) const;
152 void Set_Opacity(float o);
153
154 void Get_Ambient(Vector3 * set_color) const;
155 void Set_Ambient(const Vector3 & color);
156 void Set_Ambient(float r,float g,float b);
157
158 void Get_Diffuse(Vector3 * set_color) const;
159 void Set_Diffuse(const Vector3 & color);
160 void Set_Diffuse(float r,float g,float b);
161
162 void Get_Specular(Vector3 * set_color) const;
163 void Set_Specular(const Vector3 & color);
164 void Set_Specular(float r,float g,float b);
165
166 void Get_Emissive(Vector3 * set_color) const;
167 void Set_Emissive(const Vector3 & color);
168 void Set_Emissive(float r,float g,float b);
169
170 void Set_Lighting(bool lighting) { CRCDirty=true; UseLighting=lighting; };
171 bool Get_Lighting() const { return UseLighting; };
172
173 /*
174 ** Color source control. Note that if you set one of the sources to be one of
175 ** the arrays, then the setting in the material is ignored. (i.e. if you
176 ** set the diffuse source to array0, then the diffuse color set into the
177 ** vertex material is ignored.
178 */
181
184
187
188 /*
189 ** UV source control. The DX8 FVF can support up to 8 uv-arrays. The vertex
190 ** material can/must be configured to index to the uv-arrays that you want to
191 ** use for the two texture stages.
192 */
193 void Set_UV_Source(int stage,int array_index);
194 int Get_UV_Source(int stage);
195
196 /*
197 ** Mapper control.
198 */
199 inline void Set_Mapper(TextureMapperClass *mapper,int stage=0);
200 inline TextureMapperClass * Get_Mapper(int stage=0);
201 inline TextureMapperClass * Peek_Mapper(int stage=0);
202 inline void Reset_Mappers(void);
203
204 /*
205 ** Loading and saving to W3D files
206 */
209
211 void Parse_Mapping_Args(const W3dVertexMaterialStruct & vmat,char * mapping0_arg_buffer,char * mapping1_arg_buffer);
212 void Init_From_Material3(const W3dMaterial3Struct & mat3);
213
214 /*
215 ** CRC, used by the loading code to build a list of the unique materials
216 */
217 inline unsigned long Get_CRC(void) const
218 {
219 if (CRCDirty) {
220 CRC=Compute_CRC();
221 CRCDirty=false;
222 }
223
224 return CRC;
225 }
226
227 /*
228 ** Test whether this material is using any mappers which require vertex normals
229 */
230 bool Do_Mappers_Need_Normals(void) const;
231
232 /*
233 ** Test whether this material is using any mappers which are time-variant
234 */
235 bool Are_Mappers_Time_Variant(void) const;
236
237 // Infrastructure to support presets
238 static void Init();
239 static void Shutdown();
240 // TODO: Make Get_Preset const
242
243 void Make_Unique();
244
245private:
246 // We're using the pointer instead of the actual structure
247 // so we don't have to include the d3d header - HY
248#ifdef DYN_MAT8
249 DynD3DMATERIAL8 * MaterialDyn;
250#else
251 _D3DMATERIAL8 * MaterialOld;
252#endif
253 unsigned int Flags;
254 unsigned int AmbientColorSource;
255 unsigned int EmissiveColorSource;
256 unsigned int DiffuseColorSource;
257 StringClass Name;
259 unsigned int UVSource[MeshBuilderClass::MAX_STAGES];
260 unsigned int UniqueID;
261 mutable unsigned long CRC;
262 mutable bool CRCDirty;
263 bool UseLighting;
264
265private:
266 /*
267 ** Apply the render states to D3D
268 */
269 void Apply(void) const;
270 /*
271 ** Apply the render states corresponding to a NULL vetex material to D3D
272 */
273 static void Apply_Null(void);
274 unsigned long VertexMaterialClass::Compute_CRC(void) const;
275
276 static VertexMaterialClass *Presets[PRESET_COUNT];
277};
278
280{
281 CRCDirty=true;
282 REF_PTR_SET(Mapper[stage],mapper);
283}
284
286{
287 if (Mapper[stage]) {
288 Mapper[stage]->Add_Ref();
289 }
290 return Mapper[stage];
291}
292
294{
295 return Mapper[stage];
296}
297
299{
300 for (int stage = 0; stage < MeshBuilderClass::MAX_STAGES; stage++) {
301 if (Mapper[stage]) {
302 Mapper[stage]->Reset();
303 }
304 }
305}
306
308{
309 for (int stage = 0; stage < MeshBuilderClass::MAX_STAGES; stage++) {
310 if (Mapper[stage] && (Mapper[stage]->Needs_Normals())) return true;
311 }
312 return false;
313}
314
316{
317 for (int stage = 0; stage < MeshBuilderClass::MAX_STAGES; stage++) {
318 if (Mapper[stage] && (Mapper[stage]->Is_Time_Variant())) return true;
319 }
320 return false;
321}
322
323#endif //VERTMATERIAL_H
324
#define W3DMAPPING_UV
#define W3DMAPPING_ENVIRONMENT
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
Definition crc.h:59
RefCountClass(void)
Definition refcount.h:108
float Get_Shininess(void) const
void Set_Lighting(bool lighting)
void Parse_W3dVertexMaterialStruct(const W3dVertexMaterialStruct &vmat)
bool Do_Mappers_Need_Normals(void) const
static VertexMaterialClass * Get_Preset(PresetType type)
void Get_Diffuse(Vector3 *set_color) const
WW3DErrorType Save_W3D(ChunkSaveClass &csave)
ColorSourceType Get_Diffuse_Color_Source(void)
ColorSourceType Get_Emissive_Color_Source(void)
TextureMapperClass * Get_Mapper(int stage=0)
void Reset_Mappers(void)
ColorSourceType Get_Ambient_Color_Source(void)
unsigned long Get_CRC(void) const
int Get_Flag(FlagsType flag)
void Parse_Mapping_Args(const W3dVertexMaterialStruct &vmat, char *mapping0_arg_buffer, char *mapping1_arg_buffer)
void Set_Specular(const Vector3 &color)
void Set_Diffuse(const Vector3 &color)
int Get_UV_Source(int stage)
TextureMapperClass * Peek_Mapper(int stage=0)
void Set_Ambient(const Vector3 &color)
void Set_Flag(FlagsType flag, bool onoff)
void Set_Shininess(float shin)
void Set_Emissive(const Vector3 &color)
void Set_Ambient_Color_Source(ColorSourceType src)
void Get_Emissive(Vector3 *set_color) const
bool Are_Mappers_Time_Variant(void) const
void Set_Mapper(TextureMapperClass *mapper, int stage=0)
void Get_Ambient(Vector3 *set_color) const
void Get_Specular(Vector3 *set_color) const
void Set_Emissive_Color_Source(ColorSourceType src)
WW3DErrorType Load_W3D(ChunkLoadClass &cload)
VertexMaterialClass & operator=(const VertexMaterialClass &src)
const char * Get_Name(void) const
void Set_Name(const char *name)
float Get_Opacity(void) const
VertexMaterialClass * Clone(void)
void Init_From_Material3(const W3dMaterial3Struct &mat3)
bool Get_Lighting() const
void Set_Opacity(float o)
void Set_Diffuse_Color_Source(ColorSourceType src)
void Set_UV_Source(int stage, int array_index)
#define REF_PTR_SET(dst, src)
Definition refcount.h:79
#define NEW_REF(C, P)
Definition refcount.h:62
unsigned char flag
Definition vchannel.cpp:273
WW3DErrorType
Definition w3derr.h:51