aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CD3D9ShaderMaterialRenderer.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/CD3D9ShaderMaterialRenderer.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 '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp1080
1 files changed, 540 insertions, 540 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp
index 7d2f76e..04faadf 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp
@@ -1,540 +1,540 @@
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 "IrrCompileConfig.h" 5#include "IrrCompileConfig.h"
6#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_ 6#ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
7 7
8#include "CD3D9ShaderMaterialRenderer.h" 8#include "CD3D9ShaderMaterialRenderer.h"
9#include "IShaderConstantSetCallBack.h" 9#include "IShaderConstantSetCallBack.h"
10#include "IMaterialRendererServices.h" 10#include "IMaterialRendererServices.h"
11#include "IVideoDriver.h" 11#include "IVideoDriver.h"
12#include "os.h" 12#include "os.h"
13#include "irrString.h" 13#include "irrString.h"
14 14
15#ifndef _IRR_D3D_NO_SHADER_DEBUGGING 15#ifndef _IRR_D3D_NO_SHADER_DEBUGGING
16#include <stdio.h> 16#include <stdio.h>
17#endif 17#endif
18 18
19 19
20namespace irr 20namespace irr
21{ 21{
22namespace video 22namespace video
23{ 23{
24 24
25//! Public constructor 25//! Public constructor
26CD3D9ShaderMaterialRenderer::CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev, video::IVideoDriver* driver, 26CD3D9ShaderMaterialRenderer::CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev, video::IVideoDriver* driver,
27 s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, 27 s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram,
28 IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData) 28 IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData)
29: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial), 29: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial),
30 VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData) 30 VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData)
31{ 31{
32 #ifdef _DEBUG 32 #ifdef _DEBUG
33 setDebugName("CD3D9ShaderMaterialRenderer"); 33 setDebugName("CD3D9ShaderMaterialRenderer");
34 #endif 34 #endif
35 35
36 if (BaseMaterial) 36 if (BaseMaterial)
37 BaseMaterial->grab(); 37 BaseMaterial->grab();
38 38
39 if (CallBack) 39 if (CallBack)
40 CallBack->grab(); 40 CallBack->grab();
41 41
42 init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram); 42 init(outMaterialTypeNr, vertexShaderProgram, pixelShaderProgram);
43} 43}
44 44
45 45
46//! constructor only for use by derived classes who want to 46//! constructor only for use by derived classes who want to
47//! create a fall back material for example. 47//! create a fall back material for example.
48CD3D9ShaderMaterialRenderer::CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev, 48CD3D9ShaderMaterialRenderer::CD3D9ShaderMaterialRenderer(IDirect3DDevice9* d3ddev,
49 video::IVideoDriver* driver, 49 video::IVideoDriver* driver,
50 IShaderConstantSetCallBack* callback, 50 IShaderConstantSetCallBack* callback,
51 IMaterialRenderer* baseMaterial, s32 userData) 51 IMaterialRenderer* baseMaterial, s32 userData)
52: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial), 52: pID3DDevice(d3ddev), Driver(driver), CallBack(callback), BaseMaterial(baseMaterial),
53 VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData) 53 VertexShader(0), OldVertexShader(0), PixelShader(0), UserData(userData)
54{ 54{
55 #ifdef _DEBUG 55 #ifdef _DEBUG
56 setDebugName("CD3D9ShaderMaterialRenderer"); 56 setDebugName("CD3D9ShaderMaterialRenderer");
57 #endif 57 #endif
58 58
59 if (BaseMaterial) 59 if (BaseMaterial)
60 BaseMaterial->grab(); 60 BaseMaterial->grab();
61 61
62 if (CallBack) 62 if (CallBack)
63 CallBack->grab(); 63 CallBack->grab();
64} 64}
65 65
66 66
67void CD3D9ShaderMaterialRenderer::init(s32& outMaterialTypeNr, 67void CD3D9ShaderMaterialRenderer::init(s32& outMaterialTypeNr,
68 const c8* vertexShaderProgram, const c8* pixelShaderProgram) 68 const c8* vertexShaderProgram, const c8* pixelShaderProgram)
69{ 69{
70 outMaterialTypeNr = -1; 70 outMaterialTypeNr = -1;
71 71
72 // create vertex shader 72 // create vertex shader
73 if (!createVertexShader(vertexShaderProgram)) 73 if (!createVertexShader(vertexShaderProgram))
74 return; 74 return;
75 75
76 // create pixel shader 76 // create pixel shader
77 if (!createPixelShader(pixelShaderProgram)) 77 if (!createPixelShader(pixelShaderProgram))
78 return; 78 return;
79 79
80 // register myself as new material 80 // register myself as new material
81 outMaterialTypeNr = Driver->addMaterialRenderer(this); 81 outMaterialTypeNr = Driver->addMaterialRenderer(this);
82} 82}
83 83
84 84
85//! Destructor 85//! Destructor
86CD3D9ShaderMaterialRenderer::~CD3D9ShaderMaterialRenderer() 86CD3D9ShaderMaterialRenderer::~CD3D9ShaderMaterialRenderer()
87{ 87{
88 if (CallBack) 88 if (CallBack)
89 CallBack->drop(); 89 CallBack->drop();
90 90
91 if (VertexShader) 91 if (VertexShader)
92 VertexShader->Release(); 92 VertexShader->Release();
93 93
94 if (PixelShader) 94 if (PixelShader)
95 PixelShader->Release(); 95 PixelShader->Release();
96 96
97 if (BaseMaterial) 97 if (BaseMaterial)
98 BaseMaterial->drop(); 98 BaseMaterial->drop();
99} 99}
100 100
101 101
102bool CD3D9ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) 102bool CD3D9ShaderMaterialRenderer::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 CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial, 112void CD3D9ShaderMaterialRenderer::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 // save old vertex shader 119 // save old vertex shader
120 pID3DDevice->GetVertexShader(&OldVertexShader); 120 pID3DDevice->GetVertexShader(&OldVertexShader);
121 121
122 // set new vertex shader 122 // set new vertex shader
123 if (FAILED(pID3DDevice->SetVertexShader(VertexShader))) 123 if (FAILED(pID3DDevice->SetVertexShader(VertexShader)))
124 os::Printer::log("Could not set vertex shader.", ELL_WARNING); 124 os::Printer::log("Could not set vertex shader.", ELL_WARNING);
125 } 125 }
126 126
127 // set new pixel shader 127 // set new pixel shader
128 if (PixelShader) 128 if (PixelShader)
129 { 129 {
130 if (FAILED(pID3DDevice->SetPixelShader(PixelShader))) 130 if (FAILED(pID3DDevice->SetPixelShader(PixelShader)))
131 os::Printer::log("Could not set pixel shader.", ELL_WARNING); 131 os::Printer::log("Could not set pixel shader.", ELL_WARNING);
132 } 132 }
133 133
134 if (BaseMaterial) 134 if (BaseMaterial)
135 BaseMaterial->OnSetMaterial(material, material, true, services); 135 BaseMaterial->OnSetMaterial(material, material, true, services);
136 } 136 }
137 137
138 //let callback know used material 138 //let callback know used material
139 if (CallBack) 139 if (CallBack)
140 CallBack->OnSetMaterial(material); 140 CallBack->OnSetMaterial(material);
141 141
142 services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); 142 services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
143} 143}
144 144
145 145
146void CD3D9ShaderMaterialRenderer::OnUnsetMaterial() 146void CD3D9ShaderMaterialRenderer::OnUnsetMaterial()
147{ 147{
148 if (VertexShader) 148 if (VertexShader)
149 pID3DDevice->SetVertexShader(OldVertexShader); 149 pID3DDevice->SetVertexShader(OldVertexShader);
150 150
151 if (PixelShader) 151 if (PixelShader)
152 pID3DDevice->SetPixelShader(0); 152 pID3DDevice->SetPixelShader(0);
153 153
154 if (BaseMaterial) 154 if (BaseMaterial)
155 BaseMaterial->OnUnsetMaterial(); 155 BaseMaterial->OnUnsetMaterial();
156} 156}
157 157
158 158
159//! Returns if the material is transparent. The scene managment needs to know this 159//! Returns if the material is transparent. The scene managment needs to know this
160//! for being able to sort the materials by opaque and transparent. 160//! for being able to sort the materials by opaque and transparent.
161bool CD3D9ShaderMaterialRenderer::isTransparent() const 161bool CD3D9ShaderMaterialRenderer::isTransparent() const
162{ 162{
163 return BaseMaterial ? BaseMaterial->isTransparent() : false; 163 return BaseMaterial ? BaseMaterial->isTransparent() : false;
164} 164}
165 165
166 166
167bool CD3D9ShaderMaterialRenderer::createPixelShader(const c8* pxsh) 167bool CD3D9ShaderMaterialRenderer::createPixelShader(const c8* pxsh)
168{ 168{
169 if (!pxsh) 169 if (!pxsh)
170 return true; 170 return true;
171 171
172 // compile shader 172 // compile shader
173 173
174 LPD3DXBUFFER code = 0; 174 LPD3DXBUFFER code = 0;
175 LPD3DXBUFFER errors = 0; 175 LPD3DXBUFFER errors = 0;
176 176
177 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING 177 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING
178 178
179 // compile shader without debug info 179 // compile shader without debug info
180 stubD3DXAssembleShader(pxsh, (UINT)strlen(pxsh), 0, 0, 0, &code, &errors); 180 stubD3DXAssembleShader(pxsh, (UINT)strlen(pxsh), 0, 0, 0, &code, &errors);
181 #else 181 #else
182 182
183 // compile shader and emitt some debug informations to 183 // compile shader and emitt some debug informations to
184 // make it possible to debug the shader in visual studio 184 // make it possible to debug the shader in visual studio
185 185
186 static int irr_dbg_file_nr = 0; 186 static int irr_dbg_file_nr = 0;
187 ++irr_dbg_file_nr; 187 ++irr_dbg_file_nr;
188 char tmp[32]; 188 char tmp[32];
189 sprintf(tmp, "irr_d3d9_dbg_shader_%d.psh", irr_dbg_file_nr); 189 sprintf(tmp, "irr_d3d9_dbg_shader_%d.psh", irr_dbg_file_nr);
190 190
191 FILE* f = fopen(tmp, "wb"); 191 FILE* f = fopen(tmp, "wb");
192 fwrite(pxsh, strlen(pxsh), 1, f); 192 fwrite(pxsh, strlen(pxsh), 1, f);
193 fflush(f); 193 fflush(f);
194 fclose(f); 194 fclose(f);
195 195
196 stubD3DXAssembleShaderFromFile(tmp, 0, 0, D3DXSHADER_DEBUG, &code, &errors); 196 stubD3DXAssembleShaderFromFile(tmp, 0, 0, D3DXSHADER_DEBUG, &code, &errors);
197 197
198 #endif 198 #endif
199 199
200 200
201 if (errors) 201 if (errors)
202 { 202 {
203 // print out compilation errors. 203 // print out compilation errors.
204 os::Printer::log("Pixel shader compilation failed:", ELL_ERROR); 204 os::Printer::log("Pixel shader compilation failed:", ELL_ERROR);
205 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); 205 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
206 206
207 if (code) 207 if (code)
208 code->Release(); 208 code->Release();
209 209
210 errors->Release(); 210 errors->Release();
211 return false; 211 return false;
212 } 212 }
213 213
214 if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)code->GetBufferPointer(), &PixelShader))) 214 if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)code->GetBufferPointer(), &PixelShader)))
215 { 215 {
216 os::Printer::log("Could not create pixel shader.", ELL_ERROR); 216 os::Printer::log("Could not create pixel shader.", ELL_ERROR);
217 code->Release(); 217 code->Release();
218 return false; 218 return false;
219 } 219 }
220 220
221 code->Release(); 221 code->Release();
222 return true; 222 return true;
223} 223}
224 224
225 225
226bool CD3D9ShaderMaterialRenderer::createVertexShader(const char* vtxsh) 226bool CD3D9ShaderMaterialRenderer::createVertexShader(const char* vtxsh)
227{ 227{
228 if (!vtxsh) 228 if (!vtxsh)
229 return true; 229 return true;
230 230
231 // compile shader 231 // compile shader
232 232
233 LPD3DXBUFFER code = 0; 233 LPD3DXBUFFER code = 0;
234 LPD3DXBUFFER errors = 0; 234 LPD3DXBUFFER errors = 0;
235 235
236 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING 236 #ifdef _IRR_D3D_NO_SHADER_DEBUGGING
237 237
238 // compile shader without debug info 238 // compile shader without debug info
239 stubD3DXAssembleShader(vtxsh, (UINT)strlen(vtxsh), 0, 0, 0, &code, &errors); 239 stubD3DXAssembleShader(vtxsh, (UINT)strlen(vtxsh), 0, 0, 0, &code, &errors);
240 240
241 #else 241 #else
242 242
243 // compile shader and emitt some debug informations to 243 // compile shader and emitt some debug informations to
244 // make it possible to debug the shader in visual studio 244 // make it possible to debug the shader in visual studio
245 245
246 static int irr_dbg_file_nr = 0; 246 static int irr_dbg_file_nr = 0;
247 ++irr_dbg_file_nr; 247 ++irr_dbg_file_nr;
248 char tmp[32]; 248 char tmp[32];
249 sprintf(tmp, "irr_d3d9_dbg_shader_%d.vsh", irr_dbg_file_nr); 249 sprintf(tmp, "irr_d3d9_dbg_shader_%d.vsh", irr_dbg_file_nr);
250 250
251 FILE* f = fopen(tmp, "wb"); 251 FILE* f = fopen(tmp, "wb");
252 fwrite(vtxsh, strlen(vtxsh), 1, f); 252 fwrite(vtxsh, strlen(vtxsh), 1, f);
253 fflush(f); 253 fflush(f);
254 fclose(f); 254 fclose(f);
255 255
256 stubD3DXAssembleShaderFromFile(tmp, 0, 0, D3DXSHADER_DEBUG, &code, &errors); 256 stubD3DXAssembleShaderFromFile(tmp, 0, 0, D3DXSHADER_DEBUG, &code, &errors);
257 257
258 #endif 258 #endif
259 259
260 if (errors) 260 if (errors)
261 { 261 {
262 // print out compilation errors. 262 // print out compilation errors.
263 os::Printer::log("Vertex shader compilation failed:", ELL_ERROR); 263 os::Printer::log("Vertex shader compilation failed:", ELL_ERROR);
264 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); 264 os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
265 265
266 if (code) 266 if (code)
267 code->Release(); 267 code->Release();
268 268
269 errors->Release(); 269 errors->Release();
270 return false; 270 return false;
271 } 271 }
272 272
273 if (!code || FAILED(pID3DDevice->CreateVertexShader((DWORD*)code->GetBufferPointer(), &VertexShader))) 273 if (!code || FAILED(pID3DDevice->CreateVertexShader((DWORD*)code->GetBufferPointer(), &VertexShader)))
274 { 274 {
275 os::Printer::log("Could not create vertex shader.", ELL_ERROR); 275 os::Printer::log("Could not create vertex shader.", ELL_ERROR);
276 if (code) 276 if (code)
277 code->Release(); 277 code->Release();
278 return false; 278 return false;
279 } 279 }
280 280
281 code->Release(); 281 code->Release();
282 return true; 282 return true;
283} 283}
284 284
285 285
286HRESULT CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader(LPCSTR pSrcData, 286HRESULT CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader(LPCSTR pSrcData,
287 UINT SrcDataLen, CONST D3DXMACRO* pDefines, 287 UINT SrcDataLen, CONST D3DXMACRO* pDefines,
288 LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXBUFFER* ppShader, 288 LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXBUFFER* ppShader,
289 LPD3DXBUFFER* ppErrorMsgs) 289 LPD3DXBUFFER* ppErrorMsgs)
290{ 290{
291 // Because Irrlicht needs to be able to start up even without installed d3d dlls, it 291 // Because Irrlicht needs to be able to start up even without installed d3d dlls, it
292 // needs to load external d3d dlls manually. examples for the dlls are: 292 // needs to load external d3d dlls manually. examples for the dlls are:
293 // SDK dll name D3DX_SDK_VERSION 293 // SDK dll name D3DX_SDK_VERSION
294 // Summer 2004: no dll 22 294 // Summer 2004: no dll 22
295 // February 2005: d3dx9_24.dll 24 295 // February 2005: d3dx9_24.dll 24
296 // April 2005: d3dx9_25.dll 25 296 // April 2005: d3dx9_25.dll 25
297 // June 2005: d3dx9_26.dll 26 297 // June 2005: d3dx9_26.dll 26
298 // August 2005: d3dx9_27.dll 27 298 // August 2005: d3dx9_27.dll 27
299 // October 2005, 299 // October 2005,
300 // December 2005: d3dx9_28.dll 28 300 // December 2005: d3dx9_28.dll 28
301 301
302 #if ( D3DX_SDK_VERSION < 24 ) 302 #if ( D3DX_SDK_VERSION < 24 )
303 // directly link functions, old d3d sdks didn't try to load external dlls 303 // directly link functions, old d3d sdks didn't try to load external dlls
304 // when linking to the d3dx9.lib 304 // when linking to the d3dx9.lib
305 #ifdef _MSC_VER 305 #ifdef _MSC_VER
306 #pragma comment (lib, "d3dx9.lib") 306 #pragma comment (lib, "d3dx9.lib")
307 #endif 307 #endif
308 308
309 // invoke static linked function 309 // invoke static linked function
310 return D3DXAssembleShader(pSrcData, SrcDataLen, pDefines, pInclude, 310 return D3DXAssembleShader(pSrcData, SrcDataLen, pDefines, pInclude,
311 Flags, ppShader, ppErrorMsgs); 311 Flags, ppShader, ppErrorMsgs);
312 #else 312 #else
313 { 313 {
314 // try to load shader functions from the dll and print error if failed. 314 // try to load shader functions from the dll and print error if failed.
315 315
316 // D3DXAssembleShader signature 316 // D3DXAssembleShader signature
317 typedef HRESULT (WINAPI *AssembleShaderFunction)(LPCSTR pSrcData, UINT SrcDataLen, 317 typedef HRESULT (WINAPI *AssembleShaderFunction)(LPCSTR pSrcData, UINT SrcDataLen,
318 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, 318 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude,
319 DWORD Flags, LPD3DXBUFFER* ppShader, 319 DWORD Flags, LPD3DXBUFFER* ppShader,
320 LPD3DXBUFFER* ppErrorMsgs); 320 LPD3DXBUFFER* ppErrorMsgs);
321 321
322 static bool LoadFailed = false; 322 static bool LoadFailed = false;
323 static AssembleShaderFunction pFn = 0; 323 static AssembleShaderFunction pFn = 0;
324 324
325 if (!pFn && !LoadFailed) 325 if (!pFn && !LoadFailed)
326 { 326 {
327 // try to load dll 327 // try to load dll
328 io::path strDllName = "d3dx9_"; 328 io::path strDllName = "d3dx9_";
329 strDllName += (int)D3DX_SDK_VERSION; 329 strDllName += (int)D3DX_SDK_VERSION;
330 strDllName += ".dll"; 330 strDllName += ".dll";
331 331
332 HMODULE hMod = LoadLibrary(strDllName.c_str()); 332 HMODULE hMod = LoadLibrary(strDllName.c_str());
333 if (hMod) 333 if (hMod)
334 pFn = (AssembleShaderFunction)GetProcAddress(hMod, "D3DXAssembleShader"); 334 pFn = (AssembleShaderFunction)GetProcAddress(hMod, "D3DXAssembleShader");
335 335
336 if (!pFn) 336 if (!pFn)
337 { 337 {
338 LoadFailed = true; 338 LoadFailed = true;
339 os::Printer::log("Could not load shader function D3DXAssembleShader from dll, shaders disabled", 339 os::Printer::log("Could not load shader function D3DXAssembleShader from dll, shaders disabled",
340 strDllName.c_str(), ELL_ERROR); 340 strDllName.c_str(), ELL_ERROR);
341 } 341 }
342 } 342 }
343 343
344 if (pFn) 344 if (pFn)
345 { 345 {
346 // call already loaded function 346 // call already loaded function
347 return (*pFn)(pSrcData, SrcDataLen, pDefines, pInclude, Flags, ppShader, ppErrorMsgs); 347 return (*pFn)(pSrcData, SrcDataLen, pDefines, pInclude, Flags, ppShader, ppErrorMsgs);
348 } 348 }
349 } 349 }
350 #endif // D3DX_SDK_VERSION < 24 350 #endif // D3DX_SDK_VERSION < 24
351 351
352 return 0; 352 return 0;
353} 353}
354 354
355 355
356HRESULT CD3D9ShaderMaterialRenderer::stubD3DXAssembleShaderFromFile(LPCSTR pSrcFile, 356HRESULT CD3D9ShaderMaterialRenderer::stubD3DXAssembleShaderFromFile(LPCSTR pSrcFile,
357 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, 357 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags,
358 LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs) 358 LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs)
359{ 359{
360 // wondering what I'm doing here? 360 // wondering what I'm doing here?
361 // see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader() 361 // see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader()
362 362
363 #if ( D3DX_SDK_VERSION < 24 ) 363 #if ( D3DX_SDK_VERSION < 24 )
364 // directly link functions, old d3d sdks didn't try to load external dlls 364 // directly link functions, old d3d sdks didn't try to load external dlls
365 // when linking to the d3dx9.lib 365 // when linking to the d3dx9.lib
366 #ifdef _MSC_VER 366 #ifdef _MSC_VER
367 #pragma comment (lib, "d3dx9.lib") 367 #pragma comment (lib, "d3dx9.lib")
368 #endif 368 #endif
369 369
370 // invoke static linked function 370 // invoke static linked function
371 return D3DXAssembleShaderFromFileA(pSrcFile, pDefines, pInclude, Flags, 371 return D3DXAssembleShaderFromFileA(pSrcFile, pDefines, pInclude, Flags,
372 ppShader, ppErrorMsgs); 372 ppShader, ppErrorMsgs);
373 #else 373 #else
374 { 374 {
375 // try to load shader functions from the dll and print error if failed. 375 // try to load shader functions from the dll and print error if failed.
376 376
377 // D3DXAssembleShaderFromFileA signature 377 // D3DXAssembleShaderFromFileA signature
378 typedef HRESULT (WINAPI *AssembleShaderFromFileFunction)(LPCSTR pSrcFile, 378 typedef HRESULT (WINAPI *AssembleShaderFromFileFunction)(LPCSTR pSrcFile,
379 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, 379 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, DWORD Flags,
380 LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs); 380 LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs);
381 381
382 static bool LoadFailed = false; 382 static bool LoadFailed = false;
383 static AssembleShaderFromFileFunction pFn = 0; 383 static AssembleShaderFromFileFunction pFn = 0;
384 384
385 if (!pFn && !LoadFailed) 385 if (!pFn && !LoadFailed)
386 { 386 {
387 // try to load dll 387 // try to load dll
388 io::path strDllName = "d3dx9_"; 388 io::path strDllName = "d3dx9_";
389 strDllName += (int)D3DX_SDK_VERSION; 389 strDllName += (int)D3DX_SDK_VERSION;
390 strDllName += ".dll"; 390 strDllName += ".dll";
391 391
392 HMODULE hMod = LoadLibrary(strDllName.c_str()); 392 HMODULE hMod = LoadLibrary(strDllName.c_str());
393 if (hMod) 393 if (hMod)
394 pFn = (AssembleShaderFromFileFunction)GetProcAddress(hMod, "D3DXAssembleShaderFromFileA"); 394 pFn = (AssembleShaderFromFileFunction)GetProcAddress(hMod, "D3DXAssembleShaderFromFileA");
395 395
396 if (!pFn) 396 if (!pFn)
397 { 397 {
398 LoadFailed = true; 398 LoadFailed = true;
399 os::Printer::log("Could not load shader function D3DXAssembleShaderFromFileA from dll, shaders disabled", 399 os::Printer::log("Could not load shader function D3DXAssembleShaderFromFileA from dll, shaders disabled",
400 strDllName.c_str(), ELL_ERROR); 400 strDllName.c_str(), ELL_ERROR);
401 } 401 }
402 } 402 }
403 403
404 if (pFn) 404 if (pFn)
405 { 405 {
406 // call already loaded function 406 // call already loaded function
407 return (*pFn)(pSrcFile, pDefines, pInclude, Flags, ppShader, ppErrorMsgs); 407 return (*pFn)(pSrcFile, pDefines, pInclude, Flags, ppShader, ppErrorMsgs);
408 } 408 }
409 } 409 }
410 #endif // D3DX_SDK_VERSION < 24 410 #endif // D3DX_SDK_VERSION < 24
411 411
412 return 0; 412 return 0;
413} 413}
414 414
415 415
416HRESULT CD3D9ShaderMaterialRenderer::stubD3DXCompileShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines, 416HRESULT CD3D9ShaderMaterialRenderer::stubD3DXCompileShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines,
417 LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, 417 LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
418 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, 418 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader,
419 LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable) 419 LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable)
420{ 420{
421 // wondering what I'm doing here? 421 // wondering what I'm doing here?
422 // see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader() 422 // see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader()
423 423
424 #if ( D3DX_SDK_VERSION < 24 ) 424 #if ( D3DX_SDK_VERSION < 24 )
425 // directly link functions, old d3d sdks didn't try to load external dlls 425 // directly link functions, old d3d sdks didn't try to load external dlls
426 // when linking to the d3dx9.lib 426 // when linking to the d3dx9.lib
427 #ifdef _MSC_VER 427 #ifdef _MSC_VER
428 #pragma comment (lib, "d3dx9.lib") 428 #pragma comment (lib, "d3dx9.lib")
429 #endif 429 #endif
430 430
431 // invoke static linked function 431 // invoke static linked function
432 return D3DXCompileShader(pSrcData, SrcDataLen, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable); 432 return D3DXCompileShader(pSrcData, SrcDataLen, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
433 #else 433 #else
434 { 434 {
435 // try to load shader functions from the dll and print error if failed. 435 // try to load shader functions from the dll and print error if failed.
436 436
437 // D3DXCompileShader 437 // D3DXCompileShader
438 typedef HRESULT (WINAPI *D3DXCompileShaderFunction)(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines, 438 typedef HRESULT (WINAPI *D3DXCompileShaderFunction)(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO* pDefines,
439 LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, 439 LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
440 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, 440 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader,
441 LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable); 441 LPD3DXBUFFER* ppErrorMsgs, LPD3DXCONSTANTTABLE* ppConstantTable);
442 442
443 static bool LoadFailed = false; 443 static bool LoadFailed = false;
444 static D3DXCompileShaderFunction pFn = 0; 444 static D3DXCompileShaderFunction pFn = 0;
445 445
446 if (!pFn && !LoadFailed) 446 if (!pFn && !LoadFailed)
447 { 447 {
448 // try to load dll 448 // try to load dll
449 io::path strDllName = "d3dx9_"; 449 io::path strDllName = "d3dx9_";
450 strDllName += (int)D3DX_SDK_VERSION; 450 strDllName += (int)D3DX_SDK_VERSION;
451 strDllName += ".dll"; 451 strDllName += ".dll";
452 452
453 HMODULE hMod = LoadLibrary(strDllName.c_str()); 453 HMODULE hMod = LoadLibrary(strDllName.c_str());
454 if (hMod) 454 if (hMod)
455 pFn = (D3DXCompileShaderFunction)GetProcAddress(hMod, "D3DXCompileShader"); 455 pFn = (D3DXCompileShaderFunction)GetProcAddress(hMod, "D3DXCompileShader");
456 456
457 if (!pFn) 457 if (!pFn)
458 { 458 {
459 LoadFailed = true; 459 LoadFailed = true;
460 os::Printer::log("Could not load shader function D3DXCompileShader from dll, shaders disabled", 460 os::Printer::log("Could not load shader function D3DXCompileShader from dll, shaders disabled",
461 strDllName.c_str(), ELL_ERROR); 461 strDllName.c_str(), ELL_ERROR);
462 } 462 }
463 } 463 }
464 464
465 if (pFn) 465 if (pFn)
466 { 466 {
467 // call already loaded function 467 // call already loaded function
468 return (*pFn)(pSrcData, SrcDataLen, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable); 468 return (*pFn)(pSrcData, SrcDataLen, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
469 } 469 }
470 } 470 }
471 #endif // D3DX_SDK_VERSION < 24 471 #endif // D3DX_SDK_VERSION < 24
472 472
473 return 0; 473 return 0;
474} 474}
475 475
476HRESULT CD3D9ShaderMaterialRenderer::stubD3DXCompileShaderFromFile(LPCSTR pSrcFile, CONST D3DXMACRO* pDefines, 476HRESULT CD3D9ShaderMaterialRenderer::stubD3DXCompileShaderFromFile(LPCSTR pSrcFile, CONST D3DXMACRO* pDefines,
477 LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, 477 LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
478 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs, 478 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs,
479 LPD3DXCONSTANTTABLE* ppConstantTable) 479 LPD3DXCONSTANTTABLE* ppConstantTable)
480{ 480{
481 // wondering what I'm doing here? 481 // wondering what I'm doing here?
482 // see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader() 482 // see comment in CD3D9ShaderMaterialRenderer::stubD3DXAssembleShader()
483 483
484 #if ( D3DX_SDK_VERSION < 24 ) 484 #if ( D3DX_SDK_VERSION < 24 )
485 // directly link functions, old d3d sdks didn't try to load external dlls 485 // directly link functions, old d3d sdks didn't try to load external dlls
486 // when linking to the d3dx9.lib 486 // when linking to the d3dx9.lib
487 #ifdef _MSC_VER 487 #ifdef _MSC_VER
488 #pragma comment (lib, "d3dx9.lib") 488 #pragma comment (lib, "d3dx9.lib")
489 #endif 489 #endif
490 490
491 // invoke static linked function 491 // invoke static linked function
492 return D3DXCompileShaderFromFileA(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable); 492 return D3DXCompileShaderFromFileA(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
493 #else 493 #else
494 { 494 {
495 // try to load shader functions from the dll and print error if failed. 495 // try to load shader functions from the dll and print error if failed.
496 496
497 // D3DXCompileShaderFromFileA 497 // D3DXCompileShaderFromFileA
498 typedef HRESULT (WINAPI *D3DXCompileShaderFromFileFunction)(LPCSTR pSrcFile, 498 typedef HRESULT (WINAPI *D3DXCompileShaderFromFileFunction)(LPCSTR pSrcFile,
499 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, 499 CONST D3DXMACRO* pDefines, LPD3DXINCLUDE pInclude, LPCSTR pFunctionName,
500 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs, 500 LPCSTR pProfile, DWORD Flags, LPD3DXBUFFER* ppShader, LPD3DXBUFFER* ppErrorMsgs,
501 LPD3DXCONSTANTTABLE* ppConstantTable); 501 LPD3DXCONSTANTTABLE* ppConstantTable);
502 502
503 static bool LoadFailed = false; 503 static bool LoadFailed = false;
504 static D3DXCompileShaderFromFileFunction pFn = 0; 504 static D3DXCompileShaderFromFileFunction pFn = 0;
505 505
506 if (!pFn && !LoadFailed) 506 if (!pFn && !LoadFailed)
507 { 507 {
508 // try to load dll 508 // try to load dll
509 io::path strDllName = "d3dx9_"; 509 io::path strDllName = "d3dx9_";
510 strDllName += (int)D3DX_SDK_VERSION; 510 strDllName += (int)D3DX_SDK_VERSION;
511 strDllName += ".dll"; 511 strDllName += ".dll";
512 512
513 HMODULE hMod = LoadLibrary(strDllName.c_str()); 513 HMODULE hMod = LoadLibrary(strDllName.c_str());
514 if (hMod) 514 if (hMod)
515 pFn = (D3DXCompileShaderFromFileFunction)GetProcAddress(hMod, "D3DXCompileShaderFromFileA"); 515 pFn = (D3DXCompileShaderFromFileFunction)GetProcAddress(hMod, "D3DXCompileShaderFromFileA");
516 516
517 if (!pFn) 517 if (!pFn)
518 { 518 {
519 LoadFailed = true; 519 LoadFailed = true;
520 os::Printer::log("Could not load shader function D3DXCompileShaderFromFileA from dll, shaders disabled", 520 os::Printer::log("Could not load shader function D3DXCompileShaderFromFileA from dll, shaders disabled",
521 strDllName.c_str(), ELL_ERROR); 521 strDllName.c_str(), ELL_ERROR);
522 } 522 }
523 } 523 }
524 524
525 if (pFn) 525 if (pFn)
526 { 526 {
527 // call already loaded function 527 // call already loaded function
528 return (*pFn)(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable); 528 return (*pFn)(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable);
529 } 529 }
530 } 530 }
531 #endif // D3DX_SDK_VERSION < 24 531 #endif // D3DX_SDK_VERSION < 24
532 532
533 return 0; 533 return 0;
534} 534}
535 535
536 536
537} // end namespace video 537} // end namespace video
538} // end namespace irr 538} // end namespace irr
539 539
540#endif // _IRR_COMPILE_WITH_DIRECT3D_9_ 540#endif // _IRR_COMPILE_WITH_DIRECT3D_9_