diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp | 856 |
1 files changed, 428 insertions, 428 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp index 131bdf5..beec3c6 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp | |||
@@ -1,428 +1,428 @@ | |||
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 "CD3D9HLSLMaterialRenderer.h" | 8 | #include "CD3D9HLSLMaterialRenderer.h" |
9 | #include "IShaderConstantSetCallBack.h" | 9 | #include "IShaderConstantSetCallBack.h" |
10 | #include "IVideoDriver.h" | 10 | #include "IVideoDriver.h" |
11 | #include "os.h" | 11 | #include "os.h" |
12 | #include "irrString.h" | 12 | #include "irrString.h" |
13 | 13 | ||
14 | #ifndef _IRR_D3D_NO_SHADER_DEBUGGING | 14 | #ifndef _IRR_D3D_NO_SHADER_DEBUGGING |
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | 18 | ||
19 | namespace irr | 19 | namespace irr |
20 | { | 20 | { |
21 | namespace video | 21 | namespace video |
22 | { | 22 | { |
23 | 23 | ||
24 | 24 | ||
25 | //! Public constructor | 25 | //! Public constructor |
26 | CD3D9HLSLMaterialRenderer::CD3D9HLSLMaterialRenderer(IDirect3DDevice9* d3ddev, | 26 | CD3D9HLSLMaterialRenderer::CD3D9HLSLMaterialRenderer(IDirect3DDevice9* d3ddev, |
27 | video::IVideoDriver* driver, s32& outMaterialTypeNr, | 27 | video::IVideoDriver* driver, s32& outMaterialTypeNr, |
28 | const c8* vertexShaderProgram, | 28 | const c8* vertexShaderProgram, |
29 | const c8* vertexShaderEntryPointName, | 29 | const c8* vertexShaderEntryPointName, |
30 | E_VERTEX_SHADER_TYPE vsCompileTarget, | 30 | E_VERTEX_SHADER_TYPE vsCompileTarget, |
31 | const c8* pixelShaderProgram, | 31 | const c8* pixelShaderProgram, |
32 | const c8* pixelShaderEntryPointName, | 32 | const c8* pixelShaderEntryPointName, |
33 | E_PIXEL_SHADER_TYPE psCompileTarget, | 33 | E_PIXEL_SHADER_TYPE psCompileTarget, |
34 | IShaderConstantSetCallBack* callback, | 34 | IShaderConstantSetCallBack* callback, |
35 | IMaterialRenderer* baseMaterial, | 35 | IMaterialRenderer* baseMaterial, |
36 | s32 userData) | 36 | s32 userData) |
37 | : CD3D9ShaderMaterialRenderer(d3ddev, driver, callback, baseMaterial, userData), | 37 | : CD3D9ShaderMaterialRenderer(d3ddev, driver, callback, baseMaterial, userData), |
38 | VSConstantsTable(0), PSConstantsTable(0) | 38 | VSConstantsTable(0), PSConstantsTable(0) |
39 | { | 39 | { |
40 | 40 | ||
41 | #ifdef _DEBUG | 41 | #ifdef _DEBUG |
42 | setDebugName("CD3D9HLSLMaterialRenderer"); | 42 | setDebugName("CD3D9HLSLMaterialRenderer"); |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | outMaterialTypeNr = -1; | 45 | outMaterialTypeNr = -1; |
46 | 46 | ||
47 | // now create shaders | 47 | // now create shaders |
48 | 48 | ||
49 | if (vsCompileTarget < 0 || vsCompileTarget > EVST_COUNT) | 49 | if (vsCompileTarget < 0 || vsCompileTarget > EVST_COUNT) |
50 | { | 50 | { |
51 | os::Printer::log("Invalid HLSL vertex shader compilation target", ELL_ERROR); | 51 | os::Printer::log("Invalid HLSL vertex shader compilation target", ELL_ERROR); |
52 | return; | 52 | return; |
53 | } | 53 | } |
54 | 54 | ||
55 | if (!createHLSLVertexShader(vertexShaderProgram, | 55 | if (!createHLSLVertexShader(vertexShaderProgram, |
56 | vertexShaderEntryPointName, VERTEX_SHADER_TYPE_NAMES[vsCompileTarget])) | 56 | vertexShaderEntryPointName, VERTEX_SHADER_TYPE_NAMES[vsCompileTarget])) |
57 | return; | 57 | return; |
58 | 58 | ||
59 | if (!createHLSLPixelShader(pixelShaderProgram, | 59 | if (!createHLSLPixelShader(pixelShaderProgram, |
60 | pixelShaderEntryPointName, PIXEL_SHADER_TYPE_NAMES[psCompileTarget])) | 60 | pixelShaderEntryPointName, PIXEL_SHADER_TYPE_NAMES[psCompileTarget])) |
61 | return; | 61 | return; |
62 | 62 | ||
63 | // register myself as new material | 63 | // register myself as new material |
64 | outMaterialTypeNr = Driver->addMaterialRenderer(this); | 64 | outMaterialTypeNr = Driver->addMaterialRenderer(this); |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | //! Destructor | 68 | //! Destructor |
69 | CD3D9HLSLMaterialRenderer::~CD3D9HLSLMaterialRenderer() | 69 | CD3D9HLSLMaterialRenderer::~CD3D9HLSLMaterialRenderer() |
70 | { | 70 | { |
71 | if (VSConstantsTable) | 71 | if (VSConstantsTable) |
72 | VSConstantsTable->Release(); | 72 | VSConstantsTable->Release(); |
73 | 73 | ||
74 | if (PSConstantsTable) | 74 | if (PSConstantsTable) |
75 | PSConstantsTable->Release(); | 75 | PSConstantsTable->Release(); |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | bool CD3D9HLSLMaterialRenderer::createHLSLVertexShader(const char* vertexShaderProgram, | 79 | bool CD3D9HLSLMaterialRenderer::createHLSLVertexShader(const char* vertexShaderProgram, |
80 | const char* shaderEntryPointName, | 80 | const char* shaderEntryPointName, |
81 | const char* shaderTargetName) | 81 | const char* shaderTargetName) |
82 | { | 82 | { |
83 | if (!vertexShaderProgram) | 83 | if (!vertexShaderProgram) |
84 | return true; | 84 | return true; |
85 | 85 | ||
86 | LPD3DXBUFFER buffer = 0; | 86 | LPD3DXBUFFER buffer = 0; |
87 | LPD3DXBUFFER errors = 0; | 87 | LPD3DXBUFFER errors = 0; |
88 | 88 | ||
89 | #ifdef _IRR_D3D_NO_SHADER_DEBUGGING | 89 | #ifdef _IRR_D3D_NO_SHADER_DEBUGGING |
90 | 90 | ||
91 | // compile without debug info | 91 | // compile without debug info |
92 | HRESULT h = stubD3DXCompileShader( | 92 | HRESULT h = stubD3DXCompileShader( |
93 | vertexShaderProgram, | 93 | vertexShaderProgram, |
94 | strlen(vertexShaderProgram), | 94 | strlen(vertexShaderProgram), |
95 | 0, // macros | 95 | 0, // macros |
96 | 0, // no includes | 96 | 0, // no includes |
97 | shaderEntryPointName, | 97 | shaderEntryPointName, |
98 | shaderTargetName, | 98 | shaderTargetName, |
99 | 0, // no flags | 99 | 0, // no flags |
100 | &buffer, | 100 | &buffer, |
101 | &errors, | 101 | &errors, |
102 | &VSConstantsTable); | 102 | &VSConstantsTable); |
103 | 103 | ||
104 | #else | 104 | #else |
105 | 105 | ||
106 | // compile shader and emitt some debug informations to | 106 | // compile shader and emitt some debug informations to |
107 | // make it possible to debug the shader in visual studio | 107 | // make it possible to debug the shader in visual studio |
108 | 108 | ||
109 | static int irr_dbg_hlsl_file_nr = 0; | 109 | static int irr_dbg_hlsl_file_nr = 0; |
110 | ++irr_dbg_hlsl_file_nr; | 110 | ++irr_dbg_hlsl_file_nr; |
111 | char tmp[32]; | 111 | char tmp[32]; |
112 | sprintf(tmp, "irr_d3d9_dbg_hlsl_%d.vsh", irr_dbg_hlsl_file_nr); | 112 | sprintf(tmp, "irr_d3d9_dbg_hlsl_%d.vsh", irr_dbg_hlsl_file_nr); |
113 | 113 | ||
114 | FILE* f = fopen(tmp, "wb"); | 114 | FILE* f = fopen(tmp, "wb"); |
115 | fwrite(vertexShaderProgram, strlen(vertexShaderProgram), 1, f); | 115 | fwrite(vertexShaderProgram, strlen(vertexShaderProgram), 1, f); |
116 | fflush(f); | 116 | fflush(f); |
117 | fclose(f); | 117 | fclose(f); |
118 | 118 | ||
119 | HRESULT h = stubD3DXCompileShaderFromFile( | 119 | HRESULT h = stubD3DXCompileShaderFromFile( |
120 | tmp, | 120 | tmp, |
121 | 0, // macros | 121 | 0, // macros |
122 | 0, // no includes | 122 | 0, // no includes |
123 | shaderEntryPointName, | 123 | shaderEntryPointName, |
124 | shaderTargetName, | 124 | shaderTargetName, |
125 | D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION, | 125 | D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION, |
126 | &buffer, | 126 | &buffer, |
127 | &errors, | 127 | &errors, |
128 | &VSConstantsTable); | 128 | &VSConstantsTable); |
129 | 129 | ||
130 | #endif | 130 | #endif |
131 | 131 | ||
132 | if (FAILED(h)) | 132 | if (FAILED(h)) |
133 | { | 133 | { |
134 | os::Printer::log("HLSL vertex shader compilation failed:", ELL_ERROR); | 134 | os::Printer::log("HLSL vertex shader compilation failed:", ELL_ERROR); |
135 | if (errors) | 135 | if (errors) |
136 | { | 136 | { |
137 | os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); | 137 | os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); |
138 | errors->Release(); | 138 | errors->Release(); |
139 | if (buffer) | 139 | if (buffer) |
140 | buffer->Release(); | 140 | buffer->Release(); |
141 | } | 141 | } |
142 | return false; | 142 | return false; |
143 | } | 143 | } |
144 | 144 | ||
145 | if (errors) | 145 | if (errors) |
146 | errors->Release(); | 146 | errors->Release(); |
147 | 147 | ||
148 | if (buffer) | 148 | if (buffer) |
149 | { | 149 | { |
150 | if (FAILED(pID3DDevice->CreateVertexShader((DWORD*)buffer->GetBufferPointer(), | 150 | if (FAILED(pID3DDevice->CreateVertexShader((DWORD*)buffer->GetBufferPointer(), |
151 | &VertexShader))) | 151 | &VertexShader))) |
152 | { | 152 | { |
153 | os::Printer::log("Could not create hlsl vertex shader.", ELL_ERROR); | 153 | os::Printer::log("Could not create hlsl vertex shader.", ELL_ERROR); |
154 | buffer->Release(); | 154 | buffer->Release(); |
155 | return false; | 155 | return false; |
156 | } | 156 | } |
157 | 157 | ||
158 | buffer->Release(); | 158 | buffer->Release(); |
159 | return true; | 159 | return true; |
160 | } | 160 | } |
161 | 161 | ||
162 | return false; | 162 | return false; |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | bool CD3D9HLSLMaterialRenderer::createHLSLPixelShader(const char* pixelShaderProgram, | 166 | bool CD3D9HLSLMaterialRenderer::createHLSLPixelShader(const char* pixelShaderProgram, |
167 | const char* shaderEntryPointName, | 167 | const char* shaderEntryPointName, |
168 | const char* shaderTargetName) | 168 | const char* shaderTargetName) |
169 | { | 169 | { |
170 | if (!pixelShaderProgram) | 170 | if (!pixelShaderProgram) |
171 | return true; | 171 | return true; |
172 | 172 | ||
173 | LPD3DXBUFFER buffer = 0; | 173 | LPD3DXBUFFER buffer = 0; |
174 | LPD3DXBUFFER errors = 0; | 174 | LPD3DXBUFFER errors = 0; |
175 | 175 | ||
176 | DWORD flags = 0; | 176 | DWORD flags = 0; |
177 | 177 | ||
178 | #ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY | 178 | #ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY |
179 | if (Driver->queryFeature(video::EVDF_VERTEX_SHADER_2_0) || Driver->queryFeature(video::EVDF_VERTEX_SHADER_3_0)) | 179 | if (Driver->queryFeature(video::EVDF_VERTEX_SHADER_2_0) || Driver->queryFeature(video::EVDF_VERTEX_SHADER_3_0)) |
180 | // this one's for newer DX SDKs which don't support ps_1_x anymore | 180 | // this one's for newer DX SDKs which don't support ps_1_x anymore |
181 | // instead they'll silently compile 1_x as 2_x when using this flag | 181 | // instead they'll silently compile 1_x as 2_x when using this flag |
182 | flags |= D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY; | 182 | flags |= D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY; |
183 | #endif | 183 | #endif |
184 | #if defined(_IRR_D3D_USE_LEGACY_HLSL_COMPILER) && defined(D3DXSHADER_USE_LEGACY_D3DX9_31_DLL) | 184 | #if defined(_IRR_D3D_USE_LEGACY_HLSL_COMPILER) && defined(D3DXSHADER_USE_LEGACY_D3DX9_31_DLL) |
185 | #ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY | 185 | #ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY |
186 | else | 186 | else |
187 | #endif | 187 | #endif |
188 | flags |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL; | 188 | flags |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL; |
189 | #endif | 189 | #endif |
190 | 190 | ||
191 | #ifdef _IRR_D3D_NO_SHADER_DEBUGGING | 191 | #ifdef _IRR_D3D_NO_SHADER_DEBUGGING |
192 | 192 | ||
193 | // compile without debug info | 193 | // compile without debug info |
194 | HRESULT h = stubD3DXCompileShader( | 194 | HRESULT h = stubD3DXCompileShader( |
195 | pixelShaderProgram, | 195 | pixelShaderProgram, |
196 | strlen(pixelShaderProgram), | 196 | strlen(pixelShaderProgram), |
197 | 0, // macros | 197 | 0, // macros |
198 | 0, // no includes | 198 | 0, // no includes |
199 | shaderEntryPointName, | 199 | shaderEntryPointName, |
200 | shaderTargetName, | 200 | shaderTargetName, |
201 | flags, | 201 | flags, |
202 | &buffer, | 202 | &buffer, |
203 | &errors, | 203 | &errors, |
204 | &PSConstantsTable); | 204 | &PSConstantsTable); |
205 | 205 | ||
206 | #else | 206 | #else |
207 | 207 | ||
208 | // compile shader and emitt some debug informations to | 208 | // compile shader and emitt some debug informations to |
209 | // make it possible to debug the shader in visual studio | 209 | // make it possible to debug the shader in visual studio |
210 | 210 | ||
211 | static int irr_dbg_hlsl_file_nr = 0; | 211 | static int irr_dbg_hlsl_file_nr = 0; |
212 | ++irr_dbg_hlsl_file_nr; | 212 | ++irr_dbg_hlsl_file_nr; |
213 | char tmp[32]; | 213 | char tmp[32]; |
214 | sprintf(tmp, "irr_d3d9_dbg_hlsl_%d.psh", irr_dbg_hlsl_file_nr); | 214 | sprintf(tmp, "irr_d3d9_dbg_hlsl_%d.psh", irr_dbg_hlsl_file_nr); |
215 | 215 | ||
216 | FILE* f = fopen(tmp, "wb"); | 216 | FILE* f = fopen(tmp, "wb"); |
217 | fwrite(pixelShaderProgram, strlen(pixelShaderProgram), 1, f); | 217 | fwrite(pixelShaderProgram, strlen(pixelShaderProgram), 1, f); |
218 | fflush(f); | 218 | fflush(f); |
219 | fclose(f); | 219 | fclose(f); |
220 | 220 | ||
221 | HRESULT h = stubD3DXCompileShaderFromFile( | 221 | HRESULT h = stubD3DXCompileShaderFromFile( |
222 | tmp, | 222 | tmp, |
223 | 0, // macros | 223 | 0, // macros |
224 | 0, // no includes | 224 | 0, // no includes |
225 | shaderEntryPointName, | 225 | shaderEntryPointName, |
226 | shaderTargetName, | 226 | shaderTargetName, |
227 | flags | D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION, | 227 | flags | D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION, |
228 | &buffer, | 228 | &buffer, |
229 | &errors, | 229 | &errors, |
230 | &PSConstantsTable); | 230 | &PSConstantsTable); |
231 | 231 | ||
232 | #endif | 232 | #endif |
233 | 233 | ||
234 | if (FAILED(h)) | 234 | if (FAILED(h)) |
235 | { | 235 | { |
236 | os::Printer::log("HLSL pixel shader compilation failed:", ELL_ERROR); | 236 | os::Printer::log("HLSL pixel shader compilation failed:", ELL_ERROR); |
237 | if (errors) | 237 | if (errors) |
238 | { | 238 | { |
239 | os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); | 239 | os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR); |
240 | errors->Release(); | 240 | errors->Release(); |
241 | if (buffer) | 241 | if (buffer) |
242 | buffer->Release(); | 242 | buffer->Release(); |
243 | } | 243 | } |
244 | return false; | 244 | return false; |
245 | } | 245 | } |
246 | 246 | ||
247 | if (errors) | 247 | if (errors) |
248 | errors->Release(); | 248 | errors->Release(); |
249 | 249 | ||
250 | if (buffer) | 250 | if (buffer) |
251 | { | 251 | { |
252 | if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)buffer->GetBufferPointer(), | 252 | if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)buffer->GetBufferPointer(), |
253 | &PixelShader))) | 253 | &PixelShader))) |
254 | { | 254 | { |
255 | os::Printer::log("Could not create hlsl pixel shader.", ELL_ERROR); | 255 | os::Printer::log("Could not create hlsl pixel shader.", ELL_ERROR); |
256 | buffer->Release(); | 256 | buffer->Release(); |
257 | return false; | 257 | return false; |
258 | } | 258 | } |
259 | 259 | ||
260 | buffer->Release(); | 260 | buffer->Release(); |
261 | return true; | 261 | return true; |
262 | } | 262 | } |
263 | 263 | ||
264 | return false; | 264 | return false; |
265 | } | 265 | } |
266 | 266 | ||
267 | 267 | ||
268 | bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, | 268 | bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, |
269 | const f32* floats, int count) | 269 | const f32* floats, int count) |
270 | { | 270 | { |
271 | LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; | 271 | LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; |
272 | if (!tbl) | 272 | if (!tbl) |
273 | return false; | 273 | return false; |
274 | 274 | ||
275 | // currently we only support top level parameters. | 275 | // currently we only support top level parameters. |
276 | // Should be enough for the beginning. (TODO) | 276 | // Should be enough for the beginning. (TODO) |
277 | 277 | ||
278 | D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); | 278 | D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); |
279 | if (!hndl) | 279 | if (!hndl) |
280 | { | 280 | { |
281 | core::stringc s = "HLSL Variable to set not found: '"; | 281 | core::stringc s = "HLSL Variable to set not found: '"; |
282 | s += name; | 282 | s += name; |
283 | s += "'. Available variables are:"; | 283 | s += "'. Available variables are:"; |
284 | os::Printer::log(s.c_str(), ELL_WARNING); | 284 | os::Printer::log(s.c_str(), ELL_WARNING); |
285 | printHLSLVariables(tbl); | 285 | printHLSLVariables(tbl); |
286 | return false; | 286 | return false; |
287 | } | 287 | } |
288 | 288 | ||
289 | D3DXCONSTANT_DESC Description; | 289 | D3DXCONSTANT_DESC Description; |
290 | UINT ucount = 1; | 290 | UINT ucount = 1; |
291 | tbl->GetConstantDesc(hndl, &Description, &ucount); | 291 | tbl->GetConstantDesc(hndl, &Description, &ucount); |
292 | 292 | ||
293 | if(Description.RegisterSet != D3DXRS_SAMPLER) | 293 | if(Description.RegisterSet != D3DXRS_SAMPLER) |
294 | { | 294 | { |
295 | HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count); | 295 | HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count); |
296 | if (FAILED(hr)) | 296 | if (FAILED(hr)) |
297 | { | 297 | { |
298 | os::Printer::log("Error setting float array for HLSL variable", ELL_WARNING); | 298 | os::Printer::log("Error setting float array for HLSL variable", ELL_WARNING); |
299 | return false; | 299 | return false; |
300 | } | 300 | } |
301 | } | 301 | } |
302 | 302 | ||
303 | return true; | 303 | return true; |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
307 | bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, | 307 | bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, |
308 | const bool* bools, int count) | 308 | const bool* bools, int count) |
309 | { | 309 | { |
310 | LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; | 310 | LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; |
311 | if (!tbl) | 311 | if (!tbl) |
312 | return false; | 312 | return false; |
313 | 313 | ||
314 | // currently we only support top level parameters. | 314 | // currently we only support top level parameters. |
315 | // Should be enough for the beginning. (TODO) | 315 | // Should be enough for the beginning. (TODO) |
316 | 316 | ||
317 | D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); | 317 | D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); |
318 | if (!hndl) | 318 | if (!hndl) |
319 | { | 319 | { |
320 | core::stringc s = "HLSL Variable to set not found: '"; | 320 | core::stringc s = "HLSL Variable to set not found: '"; |
321 | s += name; | 321 | s += name; |
322 | s += "'. Available variables are:"; | 322 | s += "'. Available variables are:"; |
323 | os::Printer::log(s.c_str(), ELL_WARNING); | 323 | os::Printer::log(s.c_str(), ELL_WARNING); |
324 | printHLSLVariables(tbl); | 324 | printHLSLVariables(tbl); |
325 | return false; | 325 | return false; |
326 | } | 326 | } |
327 | 327 | ||
328 | D3DXCONSTANT_DESC Description; | 328 | D3DXCONSTANT_DESC Description; |
329 | UINT ucount = 1; | 329 | UINT ucount = 1; |
330 | tbl->GetConstantDesc(hndl, &Description, &ucount); | 330 | tbl->GetConstantDesc(hndl, &Description, &ucount); |
331 | 331 | ||
332 | if(Description.RegisterSet != D3DXRS_SAMPLER) | 332 | if(Description.RegisterSet != D3DXRS_SAMPLER) |
333 | { | 333 | { |
334 | HRESULT hr = tbl->SetBoolArray(pID3DDevice, hndl, (BOOL*)bools, count); | 334 | HRESULT hr = tbl->SetBoolArray(pID3DDevice, hndl, (BOOL*)bools, count); |
335 | if (FAILED(hr)) | 335 | if (FAILED(hr)) |
336 | { | 336 | { |
337 | os::Printer::log("Error setting bool array for HLSL variable", ELL_WARNING); | 337 | os::Printer::log("Error setting bool array for HLSL variable", ELL_WARNING); |
338 | return false; | 338 | return false; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | return true; | 342 | return true; |
343 | } | 343 | } |
344 | 344 | ||
345 | 345 | ||
346 | bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, | 346 | bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, |
347 | const s32* ints, int count) | 347 | const s32* ints, int count) |
348 | { | 348 | { |
349 | LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; | 349 | LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; |
350 | if (!tbl) | 350 | if (!tbl) |
351 | return false; | 351 | return false; |
352 | 352 | ||
353 | // currently we only support top level parameters. | 353 | // currently we only support top level parameters. |
354 | // Should be enough for the beginning. (TODO) | 354 | // Should be enough for the beginning. (TODO) |
355 | 355 | ||
356 | D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); | 356 | D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); |
357 | if (!hndl) | 357 | if (!hndl) |
358 | { | 358 | { |
359 | core::stringc s = "HLSL Variable to set not found: '"; | 359 | core::stringc s = "HLSL Variable to set not found: '"; |
360 | s += name; | 360 | s += name; |
361 | s += "'. Available variables are:"; | 361 | s += "'. Available variables are:"; |
362 | os::Printer::log(s.c_str(), ELL_WARNING); | 362 | os::Printer::log(s.c_str(), ELL_WARNING); |
363 | printHLSLVariables(tbl); | 363 | printHLSLVariables(tbl); |
364 | return false; | 364 | return false; |
365 | } | 365 | } |
366 | 366 | ||
367 | D3DXCONSTANT_DESC Description; | 367 | D3DXCONSTANT_DESC Description; |
368 | UINT ucount = 1; | 368 | UINT ucount = 1; |
369 | tbl->GetConstantDesc(hndl, &Description, &ucount); | 369 | tbl->GetConstantDesc(hndl, &Description, &ucount); |
370 | 370 | ||
371 | if(Description.RegisterSet != D3DXRS_SAMPLER) | 371 | if(Description.RegisterSet != D3DXRS_SAMPLER) |
372 | { | 372 | { |
373 | HRESULT hr = tbl->SetIntArray(pID3DDevice, hndl, ints, count); | 373 | HRESULT hr = tbl->SetIntArray(pID3DDevice, hndl, ints, count); |
374 | if (FAILED(hr)) | 374 | if (FAILED(hr)) |
375 | { | 375 | { |
376 | os::Printer::log("Error setting int array for HLSL variable", ELL_WARNING); | 376 | os::Printer::log("Error setting int array for HLSL variable", ELL_WARNING); |
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | return true; | 381 | return true; |
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | bool CD3D9HLSLMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) | 385 | bool CD3D9HLSLMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) |
386 | { | 386 | { |
387 | if (VSConstantsTable) | 387 | if (VSConstantsTable) |
388 | VSConstantsTable->SetDefaults(pID3DDevice); | 388 | VSConstantsTable->SetDefaults(pID3DDevice); |
389 | 389 | ||
390 | return CD3D9ShaderMaterialRenderer::OnRender(service, vtxtype); | 390 | return CD3D9ShaderMaterialRenderer::OnRender(service, vtxtype); |
391 | } | 391 | } |
392 | 392 | ||
393 | 393 | ||
394 | void CD3D9HLSLMaterialRenderer::printHLSLVariables(LPD3DXCONSTANTTABLE table) | 394 | void CD3D9HLSLMaterialRenderer::printHLSLVariables(LPD3DXCONSTANTTABLE table) |
395 | { | 395 | { |
396 | // currently we only support top level parameters. | 396 | // currently we only support top level parameters. |
397 | // Should be enough for the beginning. (TODO) | 397 | // Should be enough for the beginning. (TODO) |
398 | 398 | ||
399 | // print out constant names | 399 | // print out constant names |
400 | D3DXCONSTANTTABLE_DESC tblDesc; | 400 | D3DXCONSTANTTABLE_DESC tblDesc; |
401 | HRESULT hr = table->GetDesc(&tblDesc); | 401 | HRESULT hr = table->GetDesc(&tblDesc); |
402 | if (!FAILED(hr)) | 402 | if (!FAILED(hr)) |
403 | { | 403 | { |
404 | for (int i=0; i<(int)tblDesc.Constants; ++i) | 404 | for (int i=0; i<(int)tblDesc.Constants; ++i) |
405 | { | 405 | { |
406 | D3DXCONSTANT_DESC d; | 406 | D3DXCONSTANT_DESC d; |
407 | UINT n = 1; | 407 | UINT n = 1; |
408 | D3DXHANDLE cHndl = table->GetConstant(NULL, i); | 408 | D3DXHANDLE cHndl = table->GetConstant(NULL, i); |
409 | if (!FAILED(table->GetConstantDesc(cHndl, &d, &n))) | 409 | if (!FAILED(table->GetConstantDesc(cHndl, &d, &n))) |
410 | { | 410 | { |
411 | core::stringc s = " '"; | 411 | core::stringc s = " '"; |
412 | s += d.Name; | 412 | s += d.Name; |
413 | s += "' Registers:[begin:"; | 413 | s += "' Registers:[begin:"; |
414 | s += (int)d.RegisterIndex; | 414 | s += (int)d.RegisterIndex; |
415 | s += ", count:"; | 415 | s += ", count:"; |
416 | s += (int)d.RegisterCount; | 416 | s += (int)d.RegisterCount; |
417 | s += "]"; | 417 | s += "]"; |
418 | os::Printer::log(s.c_str()); | 418 | os::Printer::log(s.c_str()); |
419 | } | 419 | } |
420 | } | 420 | } |
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
424 | 424 | ||
425 | } // end namespace video | 425 | } // end namespace video |
426 | } // end namespace irr | 426 | } // end namespace irr |
427 | 427 | ||
428 | #endif // _IRR_COMPILE_WITH_DIRECT3D_9_ | 428 | #endif // _IRR_COMPILE_WITH_DIRECT3D_9_ |