Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
shdcubemap.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/shdcubemap.cpp $*
26 * *
27 * $Org Author:: Kenny_m
28 *
29 * $Author:: Kenny_m
30 *
31 * $Modtime:: 8/01/02 3:12p $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * Currently unsupported due to cube map texture management needed by W3D
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#include <d3dx8math.h>
41#include "dx8fvf.h"
42#include "dx8wrapper.h"
43#include "assetmgr.h"
44
45#include "shdcubemap.h"
46
47#include "editable.h"
48#include "shdclassids.h"
49#include "shddeffactory.h"
50#include "shdinterface.h"
51#include "shdhwshader.h"
52
53#include "persistfactory.h"
54#include "wwhack.h"
55
56DECLARE_FORCE_LINK(CubeMapShader);
58
59
60// Save-Load methods for ShdDefClass
61enum
62{
63 CHUNKID_VARIABLES = 0x16490470,
64
66
70};
71
74 Ambient(1,1,1),
75 Diffuse(1,1,1),
76 Specular(0,0,0)
77{
78 NAMED_TEXTURE_FILENAME_PARAM(ShdCubeMapDefClass, TextureName, "Texture Name", "Targa Files", ".tga");
79
83}
84
86: ShdDefClass(that),
87 Ambient(that.Ambient),
88 Diffuse(that.Diffuse),
89 Specular(that.Specular)
90{
91 TextureName=that.TextureName;
92}
93
97
99{
100 return true;
101}
102
104{
105 ShdDefClass::Save(csave);
106
108
109 bool retval = true;
110
111 // only save the file name
112 char fname[_MAX_PATH];
113
114 _splitpath(TextureName,NULL,NULL,fname,NULL);
115 strcat(fname,".dds");
116 TextureName=fname;
117
119
120 WRITE_MICRO_CHUNK(csave, VARID_AMBIENT_COLOR, Ambient);
121 WRITE_MICRO_CHUNK(csave, VARID_DIFFUSE_COLOR, Diffuse);
122 WRITE_MICRO_CHUNK(csave, VARID_SPECULAR_COLOR, Specular);
123
124 csave.End_Chunk();
125
126 return retval;
127}
128
130{
131 ShdDefClass::Load(cload);
132
133 // Loop through all the microchunks that define the variables
134 while (cload.Open_Chunk()) {
135 switch (cload.Cur_Chunk_ID())
136 {
138 while (cload.Open_Micro_Chunk())
139 {
140 switch (cload.Cur_Micro_Chunk_ID())
141 {
143
144 READ_MICRO_CHUNK(cload, VARID_AMBIENT_COLOR, Ambient);
145 READ_MICRO_CHUNK(cload, VARID_DIFFUSE_COLOR, Diffuse);
146 READ_MICRO_CHUNK(cload, VARID_SPECULAR_COLOR, Specular);
147 }
148
149 cload.Close_Micro_Chunk();
150 }
151 break;
152
153 default:
154 break;
155 }
156
157 cload.Close_Chunk();
158 }
159
160 return true;
161}
162
163
168
173
175{
176 return new Shd6CubeMapClass(this);
177}
178
179
180
182
186{
188
190 (
191 Definition->Get_Texture_Name(),
194 true,
196 );
197
198 const Vector3& a=Definition->Get_Ambient();
199 Ambient.Set(a.X,a.Y,a.Z,1.0f);
200
201 const Vector3& d=Definition->Get_Diffuse();
202 Diffuse.Set(d.X,d.Y,d.Z,1.0f);
203
204 const Vector3& s=Definition->Get_Specular();
205 Specular.Set(s.X,s.Y,s.Z,1.0f);
206
207 Material=new D3DMATERIAL8;
208 memset(Material,0,sizeof(D3DMATERIAL8));
209 Material->Ambient.r=a.X; Material->Ambient.g=a.Y; Material->Ambient.b=a.Z;
210 Material->Diffuse.r=d.X; Material->Diffuse.g=d.Y; Material->Diffuse.b=d.Z;
211 Material->Specular.r=s.X; Material->Specular.g=s.Y; Material->Specular.b=s.Z;
212 Material->Power=20;
213}
214
219
221{
222}
223
227
228
229/**********************************************************************************************
231
234{
235 // fixed function uses pass through by default
236 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
237
238 // set vertex shader
240
241 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
242 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
243 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
244
245 DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
246
247 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
248 DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
249
250 DX8Wrapper::Set_DX8_Render_State(D3DRS_LIGHTING, TRUE);
251 DX8Wrapper::Set_DX8_Render_State(D3DRS_SPECULARENABLE, TRUE);
252
253 DX8Wrapper::Set_DX8_Render_State(D3DRS_AMBIENTMATERIALSOURCE,D3DMCS_MATERIAL);
254 DX8Wrapper::Set_DX8_Render_State(D3DRS_DIFFUSEMATERIALSOURCE,D3DMCS_MATERIAL);
255 DX8Wrapper::Set_DX8_Render_State(D3DRS_SPECULARMATERIALSOURCE,D3DMCS_MATERIAL);
256 DX8Wrapper::Set_DX8_Render_State(D3DRS_EMISSIVEMATERIALSOURCE,D3DMCS_MATERIAL);
257
259}
260
261//**********************************************************************************************
263
269
271{
272 return 1;
273}
274
275unsigned Shd6CubeMapClass::Get_Vertex_Size(unsigned stream) const
276{
277 return sizeof(VertexFormatXYZNDCUBEMAP);
278}
279
281(
282 unsigned stream,
283 void* dest_buffer,
284 const VertexStreamStruct& vss,
285 unsigned vertex_count
286)
287{
289
290 for (unsigned i=0; i<vertex_count; ++i)
291 {
292 if (vss.Locations)
293 {
294 verts[i].x=vss.Locations[i][0];
295 verts[i].y=vss.Locations[i][1];
296 verts[i].z=vss.Locations[i][2];
297 }
298 else
299 {
300 verts[i].x=0.0f;
301 verts[i].y=0.0f;
302 verts[i].z=0.0f;
303 }
304
305 if (vss.DiffuseInt)
306 {
307 verts[i].diffuse=vss.DiffuseInt[i];
308 }
309 else
310 {
311 verts[i].diffuse=0xffffffff;
312 }
313
314 if (vss.Normals)
315 {
316 verts[i].nx=vss.Normals[i][0];
317 verts[i].ny=vss.Normals[i][1];
318 verts[i].nz=vss.Normals[i][2];
319 }
320 else
321 {
322 verts[i].nx=0.0f;
323 verts[i].ny=0.0f;
324 verts[i].nz=0.0f;
325 }
326 }
327}
328
#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
virtual void Apply_Shared(int cur_pass, RenderInfoClass &rinfo)
static Matrix4x4 View_Projection_Matrix
Definition shdcubemap.h:140
virtual unsigned Get_Vertex_Size(unsigned stream) const
virtual unsigned Get_Vertex_Stream_Count() const
virtual void Copy_Vertex_Stream(unsigned stream, void *dest_buffer, const VertexStreamStruct &vss, unsigned vertex_count)
D3DMATERIAL8 * Material
Definition shdcubemap.h:142
static void Shutdown()
virtual ~Shd6CubeMapClass()
TextureClass * Texture
Definition shdcubemap.h:144
static void Init()
Shd6CubeMapClass(const ShdDefClass *def)
virtual void Apply_Instance(int cur_pass, RenderInfoClass &rinfo)
Apply per instance states for 1 pass DX6.
virtual ~ShdCubeMapDefClass()
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 bool Is_Valid_Config(StringClass &message)
virtual ShdInterfaceClass * Create() const
virtual void Init()
virtual void Shutdown()
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
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_XYZNDCUBEMAP
Definition dx8fvf.h:71
#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
@ VARID_SPECULAR_COLOR
@ SHDDEF_CLASSID_CUBEMAP
Definition shdclassids.h:53
#define REGISTER_SHDDEF(T, ID, NAME)
const Vector3 * Normals
const unsigned * DiffuseInt
const Vector3 * Locations
@ MIP_LEVELS_ALL
@ WW3D_FORMAT_UNKNOWN
Definition ww3dformat.h:76
#define DECLARE_FORCE_LINK(module)
Definition wwhack.h:48