Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shdsimple.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 : WWSHADE *
24 * *
25 * $Archive:: wwshade/shdsimple.cpp $*
26 * *
27 * $Org Author:: Kenny_m
28 *
29 * $Author:: Kenny_m
30 *
31 * $Modtime:: 7/12/02 3:12p $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#include <d3dx8math.h>
40#include "dx8fvf.h"
41#include "dx8wrapper.h"
42#include "assetmgr.h"
43
44#include "shdsimple.h"
45
46#include "editable.h"
47#include "shdclassids.h"
48#include "shddeffactory.h"
49#include "shdinterface.h"
50#include "shdhwshader.h"
51
52#include "persistfactory.h"
53#include "wwhack.h"
54
55DECLARE_FORCE_LINK(SimpleShader);
57
58
59// Save-Load methods for ShdDefClass
60enum
61{
62 CHUNKID_VARIABLES = 0x16490450,
63
65
68};
69
72 Ambient(1,1,1),
73 Diffuse(1,1,1)
74{
75 NAMED_TEXTURE_FILENAME_PARAM(ShdSimpleDefClass, TextureName, "Texture Name", "Targa Files", ".tga");
76
79}
80
82: ShdDefClass(that),
83 Ambient(0,0,0),
84 Diffuse(1,1,1)
85{
86 TextureName=that.TextureName;
87
88 Ambient=that.Ambient;
89 Diffuse=that.Diffuse;
90}
91
95
97{
98 return true;
99}
100
102{
103 ShdDefClass::Save(csave);
104
106
107 bool retval = true;
108
109 // only save the file name
110 char fname[_MAX_PATH];
111
112 _splitpath(TextureName,NULL,NULL,fname,NULL);
113 strcat(fname,".tga");
114 TextureName=fname;
115
117
118 WRITE_MICRO_CHUNK(csave, VARID_AMBIENT_COLOR, Ambient);
119 WRITE_MICRO_CHUNK(csave, VARID_DIFFUSE_COLOR, Diffuse);
120
121 csave.End_Chunk();
122
123 return retval;
124}
125
127{
128 ShdDefClass::Load(cload);
129
130 // Loop through all the microchunks that define the variables
131 while (cload.Open_Chunk()) {
132 switch (cload.Cur_Chunk_ID())
133 {
135 while (cload.Open_Micro_Chunk())
136 {
137 switch (cload.Cur_Micro_Chunk_ID())
138 {
140
141 READ_MICRO_CHUNK(cload, VARID_AMBIENT_COLOR, Ambient);
142 READ_MICRO_CHUNK(cload, VARID_DIFFUSE_COLOR, Diffuse);
143 }
144
145 cload.Close_Micro_Chunk();
146 }
147 break;
148
149 default:
150 break;
151 }
152
153 cload.Close_Chunk();
154 }
155
156 return true;
157}
158
159
164
169
171{
172 return new Shd6SimpleClass(this);
173}
174
175
176
178
182{
184
186 (
187 Definition->Get_Texture_Name()
188 );
189
190 const Vector3& a=Definition->Get_Ambient();
191 Ambient.Set(a.X,a.Y,a.Z,1.0f);
192
193 const Vector3& d=Definition->Get_Diffuse();
194 Diffuse.Set(d.X,d.Y,d.Z,1.0f);
195
196 Material=new D3DMATERIAL8;
197 memset(Material,0,sizeof(D3DMATERIAL8));
198 Material->Ambient.r=a.X; Material->Ambient.g=a.Y; Material->Ambient.b=a.Z;
199 Material->Diffuse.r=d.X; Material->Diffuse.g=d.Y; Material->Diffuse.b=d.Z;
200}
201
206
208{
209}
210
214
215
216/**********************************************************************************************
218
221{
222 // fixed function uses pass through by default
223 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);
224
225 // set vertex shader
227
228 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
229 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
230 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
231
232 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
233
234 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
235 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
236
237 DX8Wrapper::Set_DX8_Render_State(D3DRS_LIGHTING, TRUE);
238
239 DX8Wrapper::Set_DX8_Render_State(D3DRS_AMBIENTMATERIALSOURCE,D3DMCS_MATERIAL);
240 DX8Wrapper::Set_DX8_Render_State(D3DRS_DIFFUSEMATERIALSOURCE,D3DMCS_MATERIAL);
241 DX8Wrapper::Set_DX8_Render_State(D3DRS_SPECULARMATERIALSOURCE,D3DMCS_MATERIAL);
242 DX8Wrapper::Set_DX8_Render_State(D3DRS_EMISSIVEMATERIALSOURCE,D3DMCS_MATERIAL);
243
244}
245
246//**********************************************************************************************
248
255
257{
258 return 1;
259}
260
261unsigned Shd6SimpleClass::Get_Vertex_Size(unsigned stream) const
262{
263 return sizeof(VertexFormatXYZNDUV1);
264}
265
267(
268 unsigned stream,
269 void* dest_buffer,
270 const VertexStreamStruct& vss,
271 unsigned vertex_count
272)
273{
274 VertexFormatXYZNDUV1* verts=(VertexFormatXYZNDUV1*)dest_buffer;
275
276 for (unsigned i=0; i<vertex_count; ++i)
277 {
278 if (vss.Locations)
279 {
280 verts[i].x=vss.Locations[i][0];
281 verts[i].y=vss.Locations[i][1];
282 verts[i].z=vss.Locations[i][2];
283 }
284 else
285 {
286 verts[i].x=0.0f;
287 verts[i].y=0.0f;
288 verts[i].z=0.0f;
289 }
290
291 if (vss.DiffuseInt)
292 {
293 verts[i].diffuse=vss.DiffuseInt[i];
294 }
295 else
296 {
297 verts[i].diffuse=0xffffffff;
298 }
299
300 if (vss.Normals)
301 {
302 verts[i].nx=vss.Normals[i][0];
303 verts[i].ny=vss.Normals[i][1];
304 verts[i].nz=vss.Normals[i][2];
305 }
306 else
307 {
308 verts[i].nx=0.0f;
309 verts[i].ny=0.0f;
310 verts[i].nz=0.0f;
311 }
312
313 if (vss.UV[0])
314 {
315 verts[i].u1=vss.UV[0][i].U;
316 verts[i].v1=vss.UV[0][i].V;
317 }
318 else
319 {
320 verts[i].u1=0.0f;
321 verts[i].v1=0.0f;
322 }
323 }
324}
325
#define NULL
Definition BaseType.h:92
#define TRUE
Definition BaseType.h:109
#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 void Set_Texture(unsigned stage, TextureBaseClass *texture)
static void Set_DX8_Material(const D3DMATERIAL8 *mat)
Definition dx8wrapper.h:849
static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value)
Definition dx8wrapper.h:899
static void Set_Vertex_Shader(DWORD vertex_shader)
Definition dx8wrapper.h:719
static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
Definition dx8wrapper.h:874
Shd6SimpleClass(const ShdDefClass *def)
virtual unsigned Get_Vertex_Size(unsigned stream) const
virtual unsigned Get_Vertex_Stream_Count() const
D3DMATERIAL8 * Material
Definition shdsimple.h:137
static void Init()
virtual void Apply_Instance(int cur_pass, RenderInfoClass &rinfo)
Apply per instance states for 1 pass DX6.
static void Shutdown()
TextureClass * Texture
Definition shdsimple.h:139
virtual ~Shd6SimpleClass()
virtual void Apply_Shared(int cur_pass, RenderInfoClass &rinfo)
Vector4 Ambient
Definition shdsimple.h:141
Vector4 Diffuse
Definition shdsimple.h:142
static Matrix4x4 View_Projection_Matrix
Definition shdsimple.h:135
virtual void Copy_Vertex_Stream(unsigned stream, void *dest_buffer, const VertexStreamStruct &vss, unsigned vertex_count)
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
ShdInterfaceClass(const ShdDefClass *def, int class_id)
Constructor.
const ShdDefClass * Definition
virtual void Init()
virtual ShdInterfaceClass * Create() const
virtual ~ShdSimpleDefClass()
Definition shdsimple.cpp:92
virtual bool Is_Valid_Config(StringClass &message)
Definition shdsimple.cpp:96
virtual bool Load(ChunkLoadClass &cload)
Load this ShdDef from a chunk loader.
virtual bool Save(ChunkSaveClass &csave)
Serialize this ShdDef into a chunk saver.
virtual void Shutdown()
float V
Definition vector2.h:80
float U
Definition vector2.h:75
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
virtual TextureClass * Get_Texture(const char *filename, MipCountType mip_level_count=MIP_LEVELS_ALL, WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN, bool allow_compression=true, TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR, bool allow_reduction=true)
static WW3DAssetManager * Get_Instance(void)
Definition assetmgr.h:205
@ DX8_FVF_XYZNDUV1
Definition dx8fvf.h:63
#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
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
@ VARID_DIFFUSE_COLOR
@ VARID_AMBIENT_COLOR
@ VARID_TEXTURE_NAME
@ SHDDEF_CLASSID_SIMPLE
Definition shdclassids.h:49
#define REGISTER_SHDDEF(T, ID, NAME)
const Vector3 * Normals
const Vector2 * UV[MAX_TEXTURE_STAGES]
const unsigned * DiffuseInt
const Vector3 * Locations
#define DECLARE_FORCE_LINK(module)
Definition wwhack.h:48