Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shdbumpspec.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/shdbumpspec.cpp $*
26 * *
27 * $Author:: Kenny_m
28 *
29 * $Modtime:: 5/27/02 2:21p $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#include "dx8fvf.h"
38#include "dx8wrapper.h"
39#include "assetmgr.h"
40
41#include "shdbumpspec.h"
42#include "shd6bumpspec.h"
43#include "shd7bumpspec.h"
44#include "shd8bumpspec.h"
45
46#include "editable.h"
47#include "shdclassids.h"
48#include "shddeffactory.h"
49#include "shdinterface.h"
50
51#include "persistfactory.h"
52#include "wwhack.h"
53
54DECLARE_FORCE_LINK(BumpSpecShader);
56
57// static member
58ShdVersion ShdBumpSpecDefClass::Version;
59
60// Save-Load methods for ShdDefClass
61enum
62{
63 CHUNKID_VARIABLES = 0x16490450,
64
67
73};
74
77 Ambient(1,1,1),
78 Diffuse(1,1,1),
79 Specular(1,1,1),
80 Diffuse_Bumpiness(1,0),
81 Specular_Bumpiness(1,0)
82{
83 NAMED_TEXTURE_FILENAME_PARAM(ShdBumpSpecDefClass, TextureName, "Base and Alpha Gloss Map", "Targa Files", ".tga");
84 NAMED_TEXTURE_FILENAME_PARAM(ShdBumpSpecDefClass, BumpMapName, "Bump Map", "Targa Files", ".tga");
85
89
90 NAMED_EDITABLE_PARAM(ShdBumpSpecDefClass, ParameterClass::TYPE_FLOAT, Diffuse_Bumpiness.X, "Diffuse Bump Scale");
91 NAMED_EDITABLE_PARAM(ShdBumpSpecDefClass, ParameterClass::TYPE_FLOAT, Diffuse_Bumpiness.Y, "Diffuse Bump Bias");
92 NAMED_EDITABLE_PARAM(ShdBumpSpecDefClass, ParameterClass::TYPE_FLOAT, Specular_Bumpiness.X, "Specular Bump Scale");
93 NAMED_EDITABLE_PARAM(ShdBumpSpecDefClass, ParameterClass::TYPE_FLOAT, Specular_Bumpiness.Y, "Specular Bump Bias");
94}
95
97: ShdDefClass(that),
98 Ambient(that.Ambient),
99 Diffuse(that.Diffuse),
100 Specular(that.Specular),
101 Diffuse_Bumpiness(that.Diffuse_Bumpiness),
102 Specular_Bumpiness(that.Specular_Bumpiness)
103{
104 TextureName=that.TextureName;
105 BumpMapName=that.BumpMapName;
106}
107
111
113{
114 return true;
115}
116
118{
119 ShdDefClass::Save(csave);
120
122
123 bool retval = true;
124
125 // only save the file name
126 char fname[_MAX_PATH];
127
128 _splitpath(TextureName,NULL,NULL,fname,NULL);
129 strcat(fname,".tga");
130 TextureName=fname;
131
133
134 _splitpath(BumpMapName,NULL,NULL,fname,NULL);
135 strcat(fname,".tga");
136 BumpMapName=fname;
137
139
140 WRITE_MICRO_CHUNK(csave, VARID_AMBIENT_COLOR, Ambient);
141 WRITE_MICRO_CHUNK(csave, VARID_DIFFUSE_COLOR, Diffuse);
142 WRITE_MICRO_CHUNK(csave, VARID_SPECULAR_COLOR, Specular);
143
144 WRITE_MICRO_CHUNK(csave, VARID_DIFFUSE_BUMPINESS, Diffuse_Bumpiness);
145 WRITE_MICRO_CHUNK(csave, VARID_SPECULAR_BUMPINESS, Specular_Bumpiness);
146
147 csave.End_Chunk();
148
149 return retval;
150}
151
153{
154 ShdDefClass::Load(cload);
155
156 // Loop through all the microchunks that define the variables
157 while (cload.Open_Chunk()) {
158 switch (cload.Cur_Chunk_ID())
159 {
161 while (cload.Open_Micro_Chunk())
162 {
163 switch (cload.Cur_Micro_Chunk_ID())
164 {
167
168 READ_MICRO_CHUNK(cload, VARID_AMBIENT_COLOR, Ambient);
169 READ_MICRO_CHUNK(cload, VARID_DIFFUSE_COLOR, Diffuse);
170 READ_MICRO_CHUNK(cload, VARID_SPECULAR_COLOR, Specular);
171
172 READ_MICRO_CHUNK(cload, VARID_DIFFUSE_BUMPINESS, Diffuse_Bumpiness);
173 READ_MICRO_CHUNK(cload, VARID_SPECULAR_BUMPINESS, Specular_Bumpiness);
174 }
175
176 cload.Close_Micro_Chunk();
177 }
178 break;
179
180 default:
181 break;
182 }
183
184 cload.Close_Chunk();
185 }
186
187 return true;
188}
189
190
192{
193 // select shader version
194 if ((DX8Wrapper::Get_Current_Caps()->Get_Pixel_Shader_Major_Version())==1 &&
195 (DX8Wrapper::Get_Current_Caps()->Get_Pixel_Shader_Minor_Version())>=1)
196 {
197 Version.Set(SHDVER_8);
198 }
199 else if (DX8Wrapper::Get_Current_Caps()->Support_Dot3())
200 {
201 Version.Set(SHDVER_7);
202 }
203 else
204 {
205 Version.Set(SHDVER_6);
206 }
207
208 switch (Version.Get())
209 {
210 case SHDVER_8 : Shd8BumpSpecClass::Init(); break;
211 case SHDVER_7 : Shd7BumpSpecClass::Init(); break;
212 case SHDVER_6 : Shd6BumpSpecClass::Init(); break;
213 }
214}
215
217{
218 switch (Version.Get())
219 {
223 }
224}
225
227{
228 switch (Version.Get())
229 {
230 case SHDVER_8 : return new Shd8BumpSpecClass(this); break;
231 case SHDVER_7 : return new Shd7BumpSpecClass(this); break;
232 case SHDVER_6 : return new Shd6BumpSpecClass(this); break;
233 }
234 return NULL;
235}
236
#define NULL
Definition BaseType.h:92
#define WRITE_MICRO_CHUNK_WWSTRING(csave, id, var)
Definition chunkio.h:309
#define WRITE_MICRO_CHUNK(csave, id, var)
Definition chunkio.h:293
#define READ_MICRO_CHUNK(cload, id, var)
Definition chunkio.h:334
#define READ_MICRO_CHUNK_WWSTRING(cload, id, var)
Definition chunkio.h:351
@ CHUNKID_VARIABLES
bool Close_Micro_Chunk()
Definition chunkio.cpp:585
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
uint32 Cur_Micro_Chunk_ID()
Definition chunkio.cpp:622
bool Open_Chunk()
Definition chunkio.cpp:412
bool Open_Micro_Chunk()
Definition chunkio.cpp:557
bool Begin_Chunk(uint32 id)
Definition chunkio.cpp:108
bool End_Chunk()
Definition chunkio.cpp:148
static const DX8Caps * Get_Current_Caps()
Definition dx8wrapper.h:536
static void Init()
static void Shutdown()
static void Shutdown()
static void Init()
static void Shutdown()
static void Init()
virtual void Init()
virtual ~ShdBumpSpecDefClass()
virtual bool Save(ChunkSaveClass &csave)
Serialize this ShdDef into a chunk saver.
virtual bool Is_Valid_Config(StringClass &message)
virtual void Shutdown()
virtual ShdInterfaceClass * Create() const
virtual bool Load(ChunkLoadClass &cload)
Load this ShdDef from a chunk loader.
ShdDefClass(uint32 class_id)
Definition shddef.cpp:45
virtual bool Load(ChunkLoadClass &cload)
Load this ShdDef from a chunk loader.
Definition shddef.cpp:160
virtual bool Save(ChunkSaveClass &csave)
Serialize this ShdDef into a chunk saver.
Definition shddef.cpp:140
#define NAMED_EDITABLE_PARAM(_class, type, data, name)
Definition editable.h:308
#define NAMED_TEXTURE_FILENAME_PARAM(_class, data, name, desc, extension)
Definition editable.h:326
@ VARID_DIFFUSE_COLOR
@ VARID_AMBIENT_COLOR
@ VARID_TEXTURE_NAME
@ VARID_DIFFUSE_BUMPINESS
@ VARID_BUMP_MAP_NAME
@ VARID_SPECULAR_BUMPINESS
@ VARID_SPECULAR_COLOR
@ SHDDEF_CLASSID_BUMPSPEC
Definition shdclassids.h:51
@ SHDVER_6
Definition shddef.h:52
@ SHDVER_8
Definition shddef.h:54
@ SHDVER_7
Definition shddef.h:53
#define REGISTER_SHDDEF(T, ID, NAME)
#define DECLARE_FORCE_LINK(module)
Definition wwhack.h:48