aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp664
1 files changed, 332 insertions, 332 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp
index f46d583..0a95b96 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp
@@ -1,332 +1,332 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CD3D8ShaderMaterialRenderer.h" 5#include "CD3D8ShaderMaterialRenderer.h"
6 6
7#include "IrrCompileConfig.h" 7#include "IrrCompileConfig.h"
8#ifdef _IRR_COMPILE_WITH_DIRECT3D_8_ 8#ifdef _IRR_COMPILE_WITH_DIRECT3D_8_
9#include <d3d8.h> 9#include <d3d8.h>
10#include <d3dx8core.h> 10#include <d3dx8core.h>
11#pragma comment (lib, "d3dx8.lib") 11#pragma comment (lib, "d3dx8.lib")
12 12
13#include "IShaderConstantSetCallBack.h" 13#include "IShaderConstantSetCallBack.h"
14#include "IMaterialRendererServices.h" 14#include "IMaterialRendererServices.h"
15#include "IVideoDriver.h" 15#include "IVideoDriver.h"
16#include "os.h" 16#include "os.h"
17 17
18#ifndef _IRR_D3D_NO_SHADER_DEBUGGING 18#ifndef _IRR_D3D_NO_SHADER_DEBUGGING
19#include <stdio.h> 19#include <stdio.h>
20#endif 20#endif
21 21
22namespace irr 22namespace irr
23{ 23{
24namespace video 24namespace video
25{ 25{
26 26
27//! Public constructor 27//! Public constructor
28CD3D8ShaderMaterialRenderer::CD3D8ShaderMaterialRenderer(IDirect3DDevice8* d3ddev, video::IVideoDriver* driver, 28CD3D8ShaderMaterialRenderer::CD3D8ShaderMaterialRenderer(IDirect3DDevice8* d3ddev, video::IVideoDriver* driver,
29 s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, 29 s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram,
30 IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData) 30 IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData)
31: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial), 31: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial),
32 VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData) 32 VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData)
33{ 33{
34 34
35 #ifdef _DEBUG 35 #ifdef _DEBUG
36 setDebugName("CD3D8ShaderMaterialRenderer"); 36 setDebugName("CD3D8ShaderMaterialRenderer");
37 #endif 37 #endif
38 38
39 if (BaseMaterial) 39 if (BaseMaterial)
40 BaseMaterial->grab(); 40 BaseMaterial->grab();
41 41
42 if (CallBack) 42 if (CallBack)
43 CallBack->grab(); 43 CallBack->grab();
44 44
45 init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram, EVT_STANDARD); 45 init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram, EVT_STANDARD);
46} 46}
47 47
48//! constructor only for use by derived classes who want to 48//! constructor only for use by derived classes who want to
49//! create a fall back material for example. 49//! create a fall back material for example.
50CD3D8ShaderMaterialRenderer::CD3D8ShaderMaterialRenderer(IDirect3DDevice8* d3ddev, 50CD3D8ShaderMaterialRenderer::CD3D8ShaderMaterialRenderer(IDirect3DDevice8* d3ddev,
51 video::IVideoDriver* driver, 51 video::IVideoDriver* driver,
52 IShaderConstantSetCallBack* callback, 52 IShaderConstantSetCallBack* callback,
53 IMaterialRenderer* baseMaterial, 53 IMaterialRenderer* baseMaterial,
54 s32 userData) 54 s32 userData)
55: pID3DDevice(d3ddev), Driver(driver), BaseMaterial(baseMaterial), CallBack(callback), 55: pID3DDevice(d3ddev), Driver(driver), BaseMaterial(baseMaterial), CallBack(callback),
56 VertexShader(0), PixelShader(0), UserData(userData) 56 VertexShader(0), PixelShader(0), UserData(userData)
57{ 57{
58 if (BaseMaterial) 58 if (BaseMaterial)
59 BaseMaterial->grab(); 59 BaseMaterial->grab();
60 60
61 if (CallBack) 61 if (CallBack)
62 CallBack->grab(); 62 CallBack->grab();
63} 63}
64 64
65 65
66 66
67//! Destructor 67//! Destructor
68CD3D8ShaderMaterialRenderer::~CD3D8ShaderMaterialRenderer() 68CD3D8ShaderMaterialRenderer::~CD3D8ShaderMaterialRenderer()
69{ 69{
70 if (CallBack) 70 if (CallBack)
71 CallBack->drop(); 71 CallBack->drop();
72 72
73 if (VertexShader) 73 if (VertexShader)
74 pID3DDevice->DeleteVertexShader(VertexShader); 74 pID3DDevice->DeleteVertexShader(VertexShader);
75 75
76 if (PixelShader) 76 if (PixelShader)
77 pID3DDevice->DeletePixelShader(PixelShader); 77 pID3DDevice->DeletePixelShader(PixelShader);
78 78
79 if (BaseMaterial) 79 if (BaseMaterial)
80 BaseMaterial->drop (); 80 BaseMaterial->drop ();
81} 81}
82 82
83 83
84void CD3D8ShaderMaterialRenderer::init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, 84void CD3D8ShaderMaterialRenderer::init(s32& outMaterialTypeNr, const c8* vertexShaderProgram,
85 const c8* pixelShaderProgram, E_VERTEX_TYPE type) 85 const c8* pixelShaderProgram, E_VERTEX_TYPE type)
86{ 86{
87 outMaterialTypeNr = -1; 87 outMaterialTypeNr = -1;
88 88
89 // create vertex shader 89 // create vertex shader
90 if (!createVertexShader(vertexShaderProgram, type)) 90 if (!createVertexShader(vertexShaderProgram, type))
91 return; 91 return;
92 92
93 // create pixel shader 93 // create pixel shader
94 if (!createPixelShader(pixelShaderProgram)) 94 if (!createPixelShader(pixelShaderProgram))
95 return; 95 return;
96 96
97 // register myself as new material 97 // register myself as new material
98 outMaterialTypeNr = Driver->addMaterialRenderer(this); 98 outMaterialTypeNr = Driver->addMaterialRenderer(this);
99} 99}
100 100
101 101
102bool CD3D8ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) 102bool CD3D8ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype)
103{ 103{
104 // call callback to set shader constants 104 // call callback to set shader constants
105 if (CallBack && (VertexShader || PixelShader)) 105 if (CallBack && (VertexShader || PixelShader))
106 CallBack->OnSetConstants(service, UserData); 106 CallBack->OnSetConstants(service, UserData);
107 107
108 return true; 108 return true;
109} 109}
110 110
111 111
112void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial, 112void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
113 bool resetAllRenderstates, video::IMaterialRendererServices* services) 113 bool resetAllRenderstates, video::IMaterialRendererServices* services)
114{ 114{
115 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) 115 if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
116 { 116 {
117 if (VertexShader) 117 if (VertexShader)
118 { 118 {
119 // We do not need to save and reset the old vertex shader, because 119 // We do not need to save and reset the old vertex shader, because
120 // in D3D8, this is mixed up with the fvf, and this is set by the driver 120 // in D3D8, this is mixed up with the fvf, and this is set by the driver
121 // every time. 121 // every time.
122 //pID3DDevice->GetVertexShader(&OldVertexShader); 122 //pID3DDevice->GetVertexShader(&OldVertexShader);
123 123
124 // set new vertex shader 124 // set new vertex shader
125 if (FAILED(pID3DDevice->SetVertexShader(VertexShader))) 125 if (FAILED(pID3DDevice->SetVertexShader(VertexShader)))
126 os::Printer::log("Could not set vertex shader.", ELL_ERROR); 126 os::Printer::log("Could not set vertex shader.", ELL_ERROR);
127 } 127 }
128 128
129 // set new pixel shader 129 // set new pixel shader
130 if (PixelShader) 130 if (PixelShader)
131 { 131 {
132 if (FAILED(pID3DDevice->SetPixelShader(PixelShader))) 132 if (FAILED(pID3DDevice->SetPixelShader(PixelShader)))
133 os::Printer::log("Could not set pixel shader.", ELL_ERROR); 133 os::Printer::log("Could not set pixel shader.", ELL_ERROR);
134 } 134 }
135 135
136 if (BaseMaterial) 136 if (BaseMaterial)
137 BaseMaterial->OnSetMaterial(material, material, true, services); 137 BaseMaterial->OnSetMaterial(material, material, true, services);
138 } 138 }
139 139
140 //let callback know used material 140 //let callback know used material
141 if (CallBack) 141 if (CallBack)
142 CallBack->OnSetMaterial(material); 142 CallBack->OnSetMaterial(material);
143 143
144 services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); 144 services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
145} 145}
146 146
147void CD3D8ShaderMaterialRenderer::OnUnsetMaterial() 147void CD3D8ShaderMaterialRenderer::OnUnsetMaterial()
148{ 148{
149 // We do not need to save and reset the old vertex shader, because 149 // We do not need to save and reset the old vertex shader, because
150 // in D3D8, this is mixed up with the fvf, and this is set by the driver 150 // in D3D8, this is mixed up with the fvf, and this is set by the driver
151 // every time. 151 // every time.
152 // if (VertexShader) 152 // if (VertexShader)
153 // pID3DDevice->SetVertexShader(OldVertexShader); 153 // pID3DDevice->SetVertexShader(OldVertexShader);
154 154
155 if (PixelShader) 155 if (PixelShader)
156 pID3DDevice->SetPixelShader(0); 156 pID3DDevice->SetPixelShader(0);
157 157
158 if (BaseMaterial) 158 if (BaseMaterial)
159 BaseMaterial->OnUnsetMaterial(); 159 BaseMaterial->OnUnsetMaterial();
160} 160}
161 161
162 162
163//! Returns if the material is transparent. The scene managment needs to know this 163//! Returns if the material is transparent. The scene managment needs to know this
164//! for being able to sort the materials by opaque and transparent. 164//! for being able to sort the materials by opaque and transparent.
165bool CD3D8ShaderMaterialRenderer::isTransparent() const 165bool CD3D8ShaderMaterialRenderer::isTransparent() const
166{ 166{
167 return BaseMaterial ? BaseMaterial->isTransparent() : false; 167 return BaseMaterial ? BaseMaterial->isTransparent() : false;
168} 168}
169 169
170bool CD3D8ShaderMaterialRenderer::createPixelShader(const c8* pxsh) 170bool CD3D8ShaderMaterialRenderer::createPixelShader(const c8* pxsh)
171{ 171{
172 if (!pxsh) 172 if (!pxsh)
173 return true; 173 return true;
174 174
175#if defined( _IRR_XBOX_PLATFORM_) 175#if defined( _IRR_XBOX_PLATFORM_)
176 return false; 176 return false;
177#else 177#else
178 // compile shader 178 // compile shader
179 179
180 LPD3DXBUFFER code = 0; 180 LPD3DXBUFFER code = 0;
181 LPD3DXBUFFER errors = 0; 181 LPD3DXBUFFER errors = 0;
182 182
183 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING 183 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING
184 184
185 // compile shader without debug info 185 // compile shader without debug info
186 D3DXAssembleShader(pxsh, (UINT)strlen(pxsh), 0, 0, &code, &errors); 186 D3DXAssembleShader(pxsh, (UINT)strlen(pxsh), 0, 0, &code, &errors);
187 187
188 #else 188 #else
189 189
190 // compile shader and emitt some debug informations to 190 // compile shader and emitt some debug informations to
191 // make it possible to debug the shader in visual studio 191 // make it possible to debug the shader in visual studio
192 192
193 static int irr_dbg_file_nr = 0; 193 static int irr_dbg_file_nr = 0;
194 ++irr_dbg_file_nr; 194 ++irr_dbg_file_nr;
195 char tmp[32]; 195 char tmp[32];
196 sprintf(tmp, "irr_d3d8_dbg_shader_%d.psh", irr_dbg_file_nr); 196 sprintf(tmp, "irr_d3d8_dbg_shader_%d.psh", irr_dbg_file_nr);
197 197
198 FILE* f = fopen(tmp, "wb"); 198 FILE* f = fopen(tmp, "wb");
199 fwrite(pxsh, strlen(pxsh), 1, f); 199 fwrite(pxsh, strlen(pxsh), 1, f);
200 fflush(f); 200 fflush(f);
201 fclose(f); 201 fclose(f);
202 202
203 D3DXAssembleShaderFromFile(tmp, D3DXASM_DEBUG, 0, &code, &errors); 203 D3DXAssembleShaderFromFile(tmp, D3DXASM_DEBUG, 0, &code, &errors);
204 #endif 204 #endif
205 if (errors) 205 if (errors)
206 { 206 {
207 // print out compilation errors. 207 // print out compilation errors.
208 os::Printer::log("Pixel shader compilation failed:", ELL_ERROR); 208 os::Printer::log("Pixel shader compilation failed:", ELL_ERROR);
209 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); 209 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
210 210
211 if (code) 211 if (code)
212 code->Release(); 212 code->Release();
213 213
214 errors->Release(); 214 errors->Release();
215 return false; 215 return false;
216 } 216 }
217 217
218 if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)code->GetBufferPointer(), &PixelShader))) 218 if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)code->GetBufferPointer(), &PixelShader)))
219 { 219 {
220 os::Printer::log("Could not create pixel shader.", ELL_ERROR); 220 os::Printer::log("Could not create pixel shader.", ELL_ERROR);
221 code->Release(); 221 code->Release();
222 return false; 222 return false;
223 } 223 }
224 224
225 code->Release(); 225 code->Release();
226 return true; 226 return true;
227#endif 227#endif
228 228
229} 229}
230 230
231 231
232 232
233bool CD3D8ShaderMaterialRenderer::createVertexShader(const char* vtxsh, E_VERTEX_TYPE type) 233bool CD3D8ShaderMaterialRenderer::createVertexShader(const char* vtxsh, E_VERTEX_TYPE type)
234{ 234{
235 if (!vtxsh) 235 if (!vtxsh)
236 return true; 236 return true;
237 237
238 // compile shader 238 // compile shader
239#if defined( _IRR_XBOX_PLATFORM_) 239#if defined( _IRR_XBOX_PLATFORM_)
240 return false; 240 return false;
241#else 241#else
242 242
243 LPD3DXBUFFER code = 0; 243 LPD3DXBUFFER code = 0;
244 LPD3DXBUFFER errors = 0; 244 LPD3DXBUFFER errors = 0;
245 245
246 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING 246 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING
247 247
248 // compile shader without debug info 248 // compile shader without debug info
249 D3DXAssembleShader(vtxsh, (UINT)strlen(vtxsh), 0, 0, &code, &errors); 249 D3DXAssembleShader(vtxsh, (UINT)strlen(vtxsh), 0, 0, &code, &errors);
250 250
251 #else 251 #else
252 252
253 // compile shader and emitt some debug informations to 253 // compile shader and emitt some debug informations to
254 // make it possible to debug the shader in visual studio 254 // make it possible to debug the shader in visual studio
255 static int irr_dbg_file_nr = 0; 255 static int irr_dbg_file_nr = 0;
256 ++irr_dbg_file_nr; 256 ++irr_dbg_file_nr;
257 char tmp[32]; 257 char tmp[32];
258 sprintf(tmp, "irr_d3d8_dbg_shader_%d.vsh", irr_dbg_file_nr); 258 sprintf(tmp, "irr_d3d8_dbg_shader_%d.vsh", irr_dbg_file_nr);
259 259
260 FILE* f = fopen(tmp, "wb"); 260 FILE* f = fopen(tmp, "wb");
261 fwrite(vtxsh, strlen(vtxsh), 1, f); 261 fwrite(vtxsh, strlen(vtxsh), 1, f);
262 fflush(f); 262 fflush(f);
263 fclose(f); 263 fclose(f);
264 264
265 D3DXAssembleShaderFromFile(tmp, D3DXASM_DEBUG, 0, &code, &errors); 265 D3DXAssembleShaderFromFile(tmp, D3DXASM_DEBUG, 0, &code, &errors);
266 266
267 #endif 267 #endif
268 268
269 269
270 if (errors) 270 if (errors)
271 { 271 {
272 // print out compilation errors. 272 // print out compilation errors.
273 os::Printer::log("Vertex shader compilation failed:", ELL_ERROR); 273 os::Printer::log("Vertex shader compilation failed:", ELL_ERROR);
274 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); 274 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
275 275
276 if (code) 276 if (code)
277 code->Release(); 277 code->Release();
278 278
279 errors->Release(); 279 errors->Release();
280 return false; 280 return false;
281 } 281 }
282 282
283 DWORD* decl = 0; 283 DWORD* decl = 0;
284 284
285 DWORD dwStdDecl[] = 285 DWORD dwStdDecl[] =
286 { 286 {
287 D3DVSD_STREAM(0), 287 D3DVSD_STREAM(0),
288 D3DVSD_REG(0, D3DVSDT_FLOAT3), // position 0 288 D3DVSD_REG(0, D3DVSDT_FLOAT3), // position 0
289 D3DVSD_REG(1, D3DVSDT_FLOAT3), // normal 1 289 D3DVSD_REG(1, D3DVSDT_FLOAT3), // normal 1
290 D3DVSD_REG(2, D3DVSDT_D3DCOLOR ),// color 2 290 D3DVSD_REG(2, D3DVSDT_D3DCOLOR ),// color 2
291 D3DVSD_REG(3, D3DVSDT_FLOAT2 ), // tex1 3 291 D3DVSD_REG(3, D3DVSDT_FLOAT2 ), // tex1 3
292 D3DVSD_REG(4, D3DVSDT_FLOAT2 ), // tex2 4 292 D3DVSD_REG(4, D3DVSDT_FLOAT2 ), // tex2 4
293 D3DVSD_END() 293 D3DVSD_END()
294 }; 294 };
295 295
296 DWORD dwTngtDecl[] = 296 DWORD dwTngtDecl[] =
297 { 297 {
298 D3DVSD_STREAM(0), 298 D3DVSD_STREAM(0),
299 D3DVSD_REG(0 , D3DVSDT_FLOAT3), // position 0 299 D3DVSD_REG(0 , D3DVSDT_FLOAT3), // position 0
300 D3DVSD_REG(1 , D3DVSDT_FLOAT3), // normal 1 300 D3DVSD_REG(1 , D3DVSDT_FLOAT3), // normal 1
301 D3DVSD_REG(2 , D3DVSDT_D3DCOLOR ),// color 2 301 D3DVSD_REG(2 , D3DVSDT_D3DCOLOR ),// color 2
302 D3DVSD_REG(3 , D3DVSDT_FLOAT2 ), // tex1 3 302 D3DVSD_REG(3 , D3DVSDT_FLOAT2 ), // tex1 3
303 D3DVSD_REG(4, D3DVSDT_FLOAT3 ), // tangent 4 303 D3DVSD_REG(4, D3DVSDT_FLOAT3 ), // tangent 4
304 D3DVSD_REG(5, D3DVSDT_FLOAT3 ), // binormal 5 304 D3DVSD_REG(5, D3DVSDT_FLOAT3 ), // binormal 5
305 D3DVSD_END() 305 D3DVSD_END()
306 }; 306 };
307 307
308 if (type == EVT_TANGENTS) 308 if (type == EVT_TANGENTS)
309 decl = dwTngtDecl; 309 decl = dwTngtDecl;
310 else 310 else
311 decl = dwStdDecl; 311 decl = dwStdDecl;
312 312
313 if (FAILED(pID3DDevice->CreateVertexShader(decl, 313 if (FAILED(pID3DDevice->CreateVertexShader(decl,
314 (DWORD*)code->GetBufferPointer(), &VertexShader, 0))) 314 (DWORD*)code->GetBufferPointer(), &VertexShader, 0)))
315 { 315 {
316 os::Printer::log("Could not create vertex shader.", ELL_ERROR); 316 os::Printer::log("Could not create vertex shader.", ELL_ERROR);
317 code->Release(); 317 code->Release();
318 return false; 318 return false;
319 } 319 }
320 320
321 code->Release(); 321 code->Release();
322 return true; 322 return true;
323#endif 323#endif
324} 324}
325 325
326 326
327 327
328} // end namespace video 328} // end namespace video
329} // end namespace irr 329} // end namespace irr
330 330
331#endif // _IRR_COMPILE_WITH_DIRECT3D_8_ 331#endif // _IRR_COMPILE_WITH_DIRECT3D_8_
332 332