winemac: Fix the logic for checking if a view is already in the intended z-order.
[wine.git] / dlls / d3dx9_36 / effect.c
blob77724062402597bc747b232f277af1375996fff6
1 /*
2 * Copyright 2010 Christian Costa
3 * Copyright 2011 Rico Schüller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3dx9_private.h"
24 #include "d3dcompiler.h"
26 /* Constants for special INT/FLOAT conversation */
27 #define INT_FLOAT_MULTI 255.0f
28 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
30 #define INITIAL_PARAM_TABLE_SIZE 16
32 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
34 enum STATE_CLASS
36 SC_LIGHTENABLE,
37 SC_FVF,
38 SC_LIGHT,
39 SC_MATERIAL,
40 SC_NPATCHMODE,
41 SC_PIXELSHADER,
42 SC_RENDERSTATE,
43 SC_SETSAMPLER,
44 SC_SAMPLERSTATE,
45 SC_TEXTURE,
46 SC_TEXTURESTAGE,
47 SC_TRANSFORM,
48 SC_VERTEXSHADER,
49 SC_SHADERCONST,
50 SC_UNKNOWN,
53 enum MATERIAL_TYPE
55 MT_DIFFUSE,
56 MT_AMBIENT,
57 MT_SPECULAR,
58 MT_EMISSIVE,
59 MT_POWER,
62 enum LIGHT_TYPE
64 LT_TYPE,
65 LT_DIFFUSE,
66 LT_SPECULAR,
67 LT_AMBIENT,
68 LT_POSITION,
69 LT_DIRECTION,
70 LT_RANGE,
71 LT_FALLOFF,
72 LT_ATTENUATION0,
73 LT_ATTENUATION1,
74 LT_ATTENUATION2,
75 LT_THETA,
76 LT_PHI,
79 enum SHADER_CONSTANT_TYPE
81 SCT_VSFLOAT,
82 SCT_VSBOOL,
83 SCT_VSINT,
84 SCT_PSFLOAT,
85 SCT_PSBOOL,
86 SCT_PSINT,
89 enum STATE_TYPE
91 ST_CONSTANT,
92 ST_PARAMETER,
93 ST_FXLC,
94 ST_ARRAY_SELECTOR,
97 struct d3dx_object
99 UINT size;
100 void *data;
101 struct d3dx_parameter *param;
104 struct d3dx_state
106 UINT operation;
107 UINT index;
108 enum STATE_TYPE type;
109 struct d3dx_parameter parameter;
112 struct d3dx_sampler
114 UINT state_count;
115 struct d3dx_state *states;
118 struct d3dx_pass
120 char *name;
121 UINT state_count;
122 UINT annotation_count;
124 struct d3dx_state *states;
125 struct d3dx_parameter *annotations;
128 struct d3dx_technique
130 char *name;
131 UINT pass_count;
132 UINT annotation_count;
134 struct d3dx_parameter *annotations;
135 struct d3dx_pass *passes;
137 struct IDirect3DStateBlock9 *saved_state;
140 struct param_table
142 struct d3dx_parameter **table;
143 unsigned int count, size;
146 struct d3dx9_base_effect
148 struct ID3DXEffectImpl *effect;
150 UINT parameter_count;
151 UINT technique_count;
152 UINT object_count;
154 struct d3dx_parameter *parameters;
155 struct d3dx_technique *techniques;
156 struct d3dx_object *objects;
158 struct param_table param_table;
161 struct ID3DXEffectImpl
163 ID3DXEffect ID3DXEffect_iface;
164 LONG ref;
166 struct d3dx9_base_effect base_effect;
168 struct ID3DXEffectStateManager *manager;
169 struct IDirect3DDevice9 *device;
170 struct ID3DXEffectPool *pool;
171 struct d3dx_technique *active_technique;
172 struct d3dx_pass *active_pass;
173 BOOL started;
174 DWORD flags;
177 struct ID3DXEffectCompilerImpl
179 ID3DXEffectCompiler ID3DXEffectCompiler_iface;
180 LONG ref;
182 struct d3dx9_base_effect base_effect;
185 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *parameters,
186 const char *name);
187 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
188 const char *data, const char **ptr, struct d3dx_object *objects);
189 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child);
191 typedef BOOL (*walk_parameter_dep_func)(void *data, struct d3dx_parameter *param);
193 static const struct
195 enum STATE_CLASS class;
196 UINT op;
197 const char *name;
199 state_table[] =
201 /* Render sates */
202 {SC_RENDERSTATE, D3DRS_ZENABLE, "D3DRS_ZENABLE"}, /* 0x0 */
203 {SC_RENDERSTATE, D3DRS_FILLMODE, "D3DRS_FILLMODE"},
204 {SC_RENDERSTATE, D3DRS_SHADEMODE, "D3DRS_SHADEMODE"},
205 {SC_RENDERSTATE, D3DRS_ZWRITEENABLE, "D3DRS_ZWRITEENABLE"},
206 {SC_RENDERSTATE, D3DRS_ALPHATESTENABLE, "D3DRS_ALPHATESTENABLE"},
207 {SC_RENDERSTATE, D3DRS_LASTPIXEL, "D3DRS_LASTPIXEL"},
208 {SC_RENDERSTATE, D3DRS_SRCBLEND, "D3DRS_SRCBLEND"},
209 {SC_RENDERSTATE, D3DRS_DESTBLEND, "D3DRS_DESTBLEND"},
210 {SC_RENDERSTATE, D3DRS_CULLMODE, "D3DRS_CULLMODE"},
211 {SC_RENDERSTATE, D3DRS_ZFUNC, "D3DRS_ZFUNC"},
212 {SC_RENDERSTATE, D3DRS_ALPHAREF, "D3DRS_ALPHAREF"},
213 {SC_RENDERSTATE, D3DRS_ALPHAFUNC, "D3DRS_ALPHAFUNC"},
214 {SC_RENDERSTATE, D3DRS_DITHERENABLE, "D3DRS_DITHERENABLE"},
215 {SC_RENDERSTATE, D3DRS_ALPHABLENDENABLE, "D3DRS_ALPHABLENDENABLE"},
216 {SC_RENDERSTATE, D3DRS_FOGENABLE, "D3DRS_FOGENABLE"},
217 {SC_RENDERSTATE, D3DRS_SPECULARENABLE, "D3DRS_SPECULARENABLE"},
218 {SC_RENDERSTATE, D3DRS_FOGCOLOR, "D3DRS_FOGCOLOR"}, /* 0x10 */
219 {SC_RENDERSTATE, D3DRS_FOGTABLEMODE, "D3DRS_FOGTABLEMODE"},
220 {SC_RENDERSTATE, D3DRS_FOGSTART, "D3DRS_FOGSTART"},
221 {SC_RENDERSTATE, D3DRS_FOGEND, "D3DRS_FOGEND"},
222 {SC_RENDERSTATE, D3DRS_FOGDENSITY, "D3DRS_FOGDENSITY"},
223 {SC_RENDERSTATE, D3DRS_RANGEFOGENABLE, "D3DRS_RANGEFOGENABLE"},
224 {SC_RENDERSTATE, D3DRS_STENCILENABLE, "D3DRS_STENCILENABLE"},
225 {SC_RENDERSTATE, D3DRS_STENCILFAIL, "D3DRS_STENCILFAIL"},
226 {SC_RENDERSTATE, D3DRS_STENCILZFAIL, "D3DRS_STENCILZFAIL"},
227 {SC_RENDERSTATE, D3DRS_STENCILPASS, "D3DRS_STENCILPASS"},
228 {SC_RENDERSTATE, D3DRS_STENCILFUNC, "D3DRS_STENCILFUNC"},
229 {SC_RENDERSTATE, D3DRS_STENCILREF, "D3DRS_STENCILREF"},
230 {SC_RENDERSTATE, D3DRS_STENCILMASK, "D3DRS_STENCILMASK"},
231 {SC_RENDERSTATE, D3DRS_STENCILWRITEMASK, "D3DRS_STENCILWRITEMASK"},
232 {SC_RENDERSTATE, D3DRS_TEXTUREFACTOR, "D3DRS_TEXTUREFACTOR"},
233 {SC_RENDERSTATE, D3DRS_WRAP0, "D3DRS_WRAP0"},
234 {SC_RENDERSTATE, D3DRS_WRAP1, "D3DRS_WRAP1"}, /* 0x20 */
235 {SC_RENDERSTATE, D3DRS_WRAP2, "D3DRS_WRAP2"},
236 {SC_RENDERSTATE, D3DRS_WRAP3, "D3DRS_WRAP3"},
237 {SC_RENDERSTATE, D3DRS_WRAP4, "D3DRS_WRAP4"},
238 {SC_RENDERSTATE, D3DRS_WRAP5, "D3DRS_WRAP5"},
239 {SC_RENDERSTATE, D3DRS_WRAP6, "D3DRS_WRAP6"},
240 {SC_RENDERSTATE, D3DRS_WRAP7, "D3DRS_WRAP7"},
241 {SC_RENDERSTATE, D3DRS_WRAP8, "D3DRS_WRAP8"},
242 {SC_RENDERSTATE, D3DRS_WRAP9, "D3DRS_WRAP9"},
243 {SC_RENDERSTATE, D3DRS_WRAP10, "D3DRS_WRAP10"},
244 {SC_RENDERSTATE, D3DRS_WRAP11, "D3DRS_WRAP11"},
245 {SC_RENDERSTATE, D3DRS_WRAP12, "D3DRS_WRAP12"},
246 {SC_RENDERSTATE, D3DRS_WRAP13, "D3DRS_WRAP13"},
247 {SC_RENDERSTATE, D3DRS_WRAP14, "D3DRS_WRAP14"},
248 {SC_RENDERSTATE, D3DRS_WRAP15, "D3DRS_WRAP15"},
249 {SC_RENDERSTATE, D3DRS_CLIPPING, "D3DRS_CLIPPING"},
250 {SC_RENDERSTATE, D3DRS_LIGHTING, "D3DRS_LIGHTING"}, /* 0x30 */
251 {SC_RENDERSTATE, D3DRS_AMBIENT, "D3DRS_AMBIENT"},
252 {SC_RENDERSTATE, D3DRS_FOGVERTEXMODE, "D3DRS_FOGVERTEXMODE"},
253 {SC_RENDERSTATE, D3DRS_COLORVERTEX, "D3DRS_COLORVERTEX"},
254 {SC_RENDERSTATE, D3DRS_LOCALVIEWER, "D3DRS_LOCALVIEWER"},
255 {SC_RENDERSTATE, D3DRS_NORMALIZENORMALS, "D3DRS_NORMALIZENORMALS"},
256 {SC_RENDERSTATE, D3DRS_DIFFUSEMATERIALSOURCE, "D3DRS_DIFFUSEMATERIALSOURCE"},
257 {SC_RENDERSTATE, D3DRS_SPECULARMATERIALSOURCE, "D3DRS_SPECULARMATERIALSOURCE"},
258 {SC_RENDERSTATE, D3DRS_AMBIENTMATERIALSOURCE, "D3DRS_AMBIENTMATERIALSOURCE"},
259 {SC_RENDERSTATE, D3DRS_EMISSIVEMATERIALSOURCE, "D3DRS_EMISSIVEMATERIALSOURCE"},
260 {SC_RENDERSTATE, D3DRS_VERTEXBLEND, "D3DRS_VERTEXBLEND"},
261 {SC_RENDERSTATE, D3DRS_CLIPPLANEENABLE, "D3DRS_CLIPPLANEENABLE"},
262 {SC_RENDERSTATE, D3DRS_POINTSIZE, "D3DRS_POINTSIZE"},
263 {SC_RENDERSTATE, D3DRS_POINTSIZE_MIN, "D3DRS_POINTSIZE_MIN"},
264 {SC_RENDERSTATE, D3DRS_POINTSIZE_MAX, "D3DRS_POINTSIZE_MAX"},
265 {SC_RENDERSTATE, D3DRS_POINTSPRITEENABLE, "D3DRS_POINTSPRITEENABLE"},
266 {SC_RENDERSTATE, D3DRS_POINTSCALEENABLE, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
267 {SC_RENDERSTATE, D3DRS_POINTSCALE_A, "D3DRS_POINTSCALE_A"},
268 {SC_RENDERSTATE, D3DRS_POINTSCALE_B, "D3DRS_POINTSCALE_B"},
269 {SC_RENDERSTATE, D3DRS_POINTSCALE_C, "D3DRS_POINTSCALE_C"},
270 {SC_RENDERSTATE, D3DRS_MULTISAMPLEANTIALIAS, "D3DRS_MULTISAMPLEANTIALIAS"},
271 {SC_RENDERSTATE, D3DRS_MULTISAMPLEMASK, "D3DRS_MULTISAMPLEMASK"},
272 {SC_RENDERSTATE, D3DRS_PATCHEDGESTYLE, "D3DRS_PATCHEDGESTYLE"},
273 {SC_RENDERSTATE, D3DRS_DEBUGMONITORTOKEN, "D3DRS_DEBUGMONITORTOKEN"},
274 {SC_RENDERSTATE, D3DRS_INDEXEDVERTEXBLENDENABLE, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
275 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE, "D3DRS_COLORWRITEENABLE"},
276 {SC_RENDERSTATE, D3DRS_TWEENFACTOR, "D3DRS_TWEENFACTOR"},
277 {SC_RENDERSTATE, D3DRS_BLENDOP, "D3DRS_BLENDOP"},
278 {SC_RENDERSTATE, D3DRS_POSITIONDEGREE, "D3DRS_POSITIONDEGREE"},
279 {SC_RENDERSTATE, D3DRS_NORMALDEGREE, "D3DRS_NORMALDEGREE"},
280 {SC_RENDERSTATE, D3DRS_SCISSORTESTENABLE, "D3DRS_SCISSORTESTENABLE"},
281 {SC_RENDERSTATE, D3DRS_SLOPESCALEDEPTHBIAS, "D3DRS_SLOPESCALEDEPTHBIAS"},
282 {SC_RENDERSTATE, D3DRS_ANTIALIASEDLINEENABLE, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
283 {SC_RENDERSTATE, D3DRS_MINTESSELLATIONLEVEL, "D3DRS_MINTESSELLATIONLEVEL"},
284 {SC_RENDERSTATE, D3DRS_MAXTESSELLATIONLEVEL, "D3DRS_MAXTESSELLATIONLEVEL"},
285 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_X, "D3DRS_ADAPTIVETESS_X"},
286 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Y, "D3DRS_ADAPTIVETESS_Y"},
287 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Z, "D3DRS_ADAPTIVETESS_Z"},
288 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_W, "D3DRS_ADAPTIVETESS_W"},
289 {SC_RENDERSTATE, D3DRS_ENABLEADAPTIVETESSELLATION, "D3DRS_ENABLEADAPTIVETESSELLATION"},
290 {SC_RENDERSTATE, D3DRS_TWOSIDEDSTENCILMODE, "D3DRS_TWOSIDEDSTENCILMODE"},
291 {SC_RENDERSTATE, D3DRS_CCW_STENCILFAIL, "D3DRS_CCW_STENCILFAIL"},
292 {SC_RENDERSTATE, D3DRS_CCW_STENCILZFAIL, "D3DRS_CCW_STENCILZFAIL"},
293 {SC_RENDERSTATE, D3DRS_CCW_STENCILPASS, "D3DRS_CCW_STENCILPASS"},
294 {SC_RENDERSTATE, D3DRS_CCW_STENCILFUNC, "D3DRS_CCW_STENCILFUNC"},
295 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE1, "D3DRS_COLORWRITEENABLE1"},
296 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE2, "D3DRS_COLORWRITEENABLE2"},
297 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE3, "D3DRS_COLORWRITEENABLE3"},
298 {SC_RENDERSTATE, D3DRS_BLENDFACTOR, "D3DRS_BLENDFACTOR"}, /* 0x60 */
299 {SC_RENDERSTATE, D3DRS_SRGBWRITEENABLE, "D3DRS_SRGBWRITEENABLE"},
300 {SC_RENDERSTATE, D3DRS_DEPTHBIAS, "D3DRS_DEPTHBIAS"},
301 {SC_RENDERSTATE, D3DRS_SEPARATEALPHABLENDENABLE, "D3DRS_SEPARATEALPHABLENDENABLE"},
302 {SC_RENDERSTATE, D3DRS_SRCBLENDALPHA, "D3DRS_SRCBLENDALPHA"},
303 {SC_RENDERSTATE, D3DRS_DESTBLENDALPHA, "D3DRS_DESTBLENDALPHA"},
304 {SC_RENDERSTATE, D3DRS_BLENDOPALPHA, "D3DRS_BLENDOPALPHA"},
305 /* Texture stages */
306 {SC_TEXTURESTAGE, D3DTSS_COLOROP, "D3DTSS_COLOROP"},
307 {SC_TEXTURESTAGE, D3DTSS_COLORARG0, "D3DTSS_COLORARG0"},
308 {SC_TEXTURESTAGE, D3DTSS_COLORARG1, "D3DTSS_COLORARG1"},
309 {SC_TEXTURESTAGE, D3DTSS_COLORARG2, "D3DTSS_COLORARG2"},
310 {SC_TEXTURESTAGE, D3DTSS_ALPHAOP, "D3DTSS_ALPHAOP"},
311 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG0, "D3DTSS_ALPHAARG0"},
312 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG1, "D3DTSS_ALPHAARG1"},
313 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG2, "D3DTSS_ALPHAARG2"},
314 {SC_TEXTURESTAGE, D3DTSS_RESULTARG, "D3DTSS_RESULTARG"},
315 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT00, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
316 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT01, "D3DTSS_BUMPENVMAT01"},
317 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT10, "D3DTSS_BUMPENVMAT10"},
318 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT11, "D3DTSS_BUMPENVMAT11"},
319 {SC_TEXTURESTAGE, D3DTSS_TEXCOORDINDEX, "D3DTSS_TEXCOORDINDEX"},
320 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLSCALE, "D3DTSS_BUMPENVLSCALE"},
321 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLOFFSET, "D3DTSS_BUMPENVLOFFSET"},
322 {SC_TEXTURESTAGE, D3DTSS_TEXTURETRANSFORMFLAGS, "D3DTSS_TEXTURETRANSFORMFLAGS"},
323 {SC_TEXTURESTAGE, D3DTSS_CONSTANT, "D3DTSS_CONSTANT"},
324 /* NPatchMode */
325 {SC_NPATCHMODE, 0, "NPatchMode"},
326 /* FVF */
327 {SC_FVF, 0, "FVF"},
328 /* Transform */
329 {SC_TRANSFORM, D3DTS_PROJECTION, "D3DTS_PROJECTION"},
330 {SC_TRANSFORM, D3DTS_VIEW, "D3DTS_VIEW"},
331 {SC_TRANSFORM, D3DTS_WORLD, "D3DTS_WORLD"},
332 {SC_TRANSFORM, D3DTS_TEXTURE0, "D3DTS_TEXTURE0"},
333 /* Material */
334 {SC_MATERIAL, MT_DIFFUSE, "MaterialDiffuse"},
335 {SC_MATERIAL, MT_AMBIENT, "MaterialAmbient"}, /* 0x80 */
336 {SC_MATERIAL, MT_SPECULAR, "MaterialSpecular"},
337 {SC_MATERIAL, MT_EMISSIVE, "MaterialEmissive"},
338 {SC_MATERIAL, MT_POWER, "MaterialPower"},
339 /* Light */
340 {SC_LIGHT, LT_TYPE, "LightType"},
341 {SC_LIGHT, LT_DIFFUSE, "LightDiffuse"},
342 {SC_LIGHT, LT_SPECULAR, "LightSpecular"},
343 {SC_LIGHT, LT_AMBIENT, "LightAmbient"},
344 {SC_LIGHT, LT_POSITION, "LightPosition"},
345 {SC_LIGHT, LT_DIRECTION, "LightDirection"},
346 {SC_LIGHT, LT_RANGE, "LightRange"},
347 {SC_LIGHT, LT_FALLOFF, "LightFallOff"},
348 {SC_LIGHT, LT_ATTENUATION0, "LightAttenuation0"},
349 {SC_LIGHT, LT_ATTENUATION1, "LightAttenuation1"},
350 {SC_LIGHT, LT_ATTENUATION2, "LightAttenuation2"},
351 {SC_LIGHT, LT_THETA, "LightTheta"},
352 {SC_LIGHT, LT_PHI, "LightPhi"}, /* 0x90 */
353 /* Ligthenable */
354 {SC_LIGHTENABLE, 0, "LightEnable"},
355 /* Vertexshader */
356 {SC_VERTEXSHADER, 0, "Vertexshader"},
357 /* Pixelshader */
358 {SC_PIXELSHADER, 0, "Pixelshader"},
359 /* Shader constants */
360 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstantF"},
361 {SC_SHADERCONST, SCT_VSBOOL, "VertexShaderConstantB"},
362 {SC_SHADERCONST, SCT_VSINT, "VertexShaderConstantI"},
363 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant"},
364 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant1"},
365 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant2"},
366 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant3"},
367 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant4"},
368 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstantF"},
369 {SC_SHADERCONST, SCT_PSBOOL, "PixelShaderConstantB"},
370 {SC_SHADERCONST, SCT_PSINT, "PixelShaderConstantI"},
371 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant"},
372 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant1"}, /* 0xa0 */
373 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant2"},
374 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant3"},
375 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant4"},
376 /* Texture */
377 {SC_TEXTURE, 0, "Texture"},
378 /* Sampler states */
379 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSU, "AddressU"},
380 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSV, "AddressV"},
381 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSW, "AddressW"},
382 {SC_SAMPLERSTATE, D3DSAMP_BORDERCOLOR, "BorderColor"},
383 {SC_SAMPLERSTATE, D3DSAMP_MAGFILTER, "MagFilter"},
384 {SC_SAMPLERSTATE, D3DSAMP_MINFILTER, "MinFilter"},
385 {SC_SAMPLERSTATE, D3DSAMP_MIPFILTER, "MipFilter"},
386 {SC_SAMPLERSTATE, D3DSAMP_MIPMAPLODBIAS, "MipMapLodBias"},
387 {SC_SAMPLERSTATE, D3DSAMP_MAXMIPLEVEL, "MaxMipLevel"},
388 {SC_SAMPLERSTATE, D3DSAMP_MAXANISOTROPY, "MaxAnisotropy"},
389 {SC_SAMPLERSTATE, D3DSAMP_SRGBTEXTURE, "SRGBTexture"},
390 {SC_SAMPLERSTATE, D3DSAMP_ELEMENTINDEX, "ElementIndex"}, /* 0xb0 */
391 {SC_SAMPLERSTATE, D3DSAMP_DMAPOFFSET, "DMAPOffset"},
392 /* Set sampler */
393 {SC_SETSAMPLER, 0, "Sampler"},
396 static inline void read_dword(const char **ptr, DWORD *d)
398 memcpy(d, *ptr, sizeof(*d));
399 *ptr += sizeof(*d);
402 static void skip_dword_unknown(const char **ptr, unsigned int count)
404 unsigned int i;
405 DWORD d;
407 FIXME("Skipping %u unknown DWORDs:\n", count);
408 for (i = 0; i < count; ++i)
410 read_dword(ptr, &d);
411 FIXME("\t0x%08x\n", d);
415 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
417 return parameter ? parameter->handle : NULL;
420 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
422 return (D3DXHANDLE) technique;
425 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
427 return (D3DXHANDLE) pass;
430 static struct d3dx_technique *get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
432 UINT i;
434 if (!name) return NULL;
436 for (i = 0; i < base->technique_count; ++i)
438 if (!strcmp(base->techniques[i].name, name))
439 return &base->techniques[i];
442 return NULL;
445 static struct d3dx_technique *get_valid_technique(struct d3dx9_base_effect *base, D3DXHANDLE technique)
447 unsigned int i;
449 for (i = 0; i < base->technique_count; ++i)
451 if (get_technique_handle(&base->techniques[i]) == technique)
452 return &base->techniques[i];
455 return get_technique_by_name(base, technique);
458 static struct d3dx_pass *get_valid_pass(struct d3dx9_base_effect *base, D3DXHANDLE pass)
460 unsigned int i, k;
462 for (i = 0; i < base->technique_count; ++i)
464 struct d3dx_technique *technique = &base->techniques[i];
466 for (k = 0; k < technique->pass_count; ++k)
468 if (get_pass_handle(&technique->passes[k]) == pass)
469 return &technique->passes[k];
473 return NULL;
476 static struct d3dx_parameter *get_valid_parameter(struct d3dx9_base_effect *base, D3DXHANDLE parameter)
478 struct d3dx_parameter **handle_param = (struct d3dx_parameter **)parameter;
480 if (handle_param >= base->param_table.table && handle_param < base->param_table.table + base->param_table.count)
481 return *handle_param;
483 return get_parameter_by_name(base, NULL, parameter);
486 static void free_state(struct d3dx_state *state)
488 free_parameter(&state->parameter, FALSE, FALSE);
491 static void free_object(struct d3dx_object *object)
493 HeapFree(GetProcessHeap(), 0, object->data);
496 static void free_sampler(struct d3dx_sampler *sampler)
498 UINT i;
500 for (i = 0; i < sampler->state_count; ++i)
502 free_state(&sampler->states[i]);
504 HeapFree(GetProcessHeap(), 0, sampler->states);
507 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child)
509 unsigned int i;
511 TRACE("Free parameter %p, name %s, type %s, child %s\n", param, param->name,
512 debug_d3dxparameter_type(param->type), child ? "yes" : "no");
514 if (param->param_eval)
516 d3dx_free_param_eval(param->param_eval);
517 param->param_eval = NULL;
520 if (param->annotations)
522 for (i = 0; i < param->annotation_count; ++i)
523 free_parameter(&param->annotations[i], FALSE, FALSE);
524 HeapFree(GetProcessHeap(), 0, param->annotations);
525 param->annotations = NULL;
528 if (param->members)
530 unsigned int count = param->element_count ? param->element_count : param->member_count;
532 for (i = 0; i < count; ++i)
533 free_parameter(&param->members[i], param->element_count != 0, TRUE);
534 HeapFree(GetProcessHeap(), 0, param->members);
535 param->members = NULL;
538 if (param->class == D3DXPC_OBJECT && !param->element_count)
540 switch (param->type)
542 case D3DXPT_STRING:
543 HeapFree(GetProcessHeap(), 0, *(char **)param->data);
544 break;
546 case D3DXPT_TEXTURE:
547 case D3DXPT_TEXTURE1D:
548 case D3DXPT_TEXTURE2D:
549 case D3DXPT_TEXTURE3D:
550 case D3DXPT_TEXTURECUBE:
551 case D3DXPT_PIXELSHADER:
552 case D3DXPT_VERTEXSHADER:
553 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
554 break;
556 case D3DXPT_SAMPLER:
557 case D3DXPT_SAMPLER1D:
558 case D3DXPT_SAMPLER2D:
559 case D3DXPT_SAMPLER3D:
560 case D3DXPT_SAMPLERCUBE:
561 free_sampler((struct d3dx_sampler *)param->data);
562 break;
564 default:
565 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
566 break;
570 if (!child)
572 HeapFree(GetProcessHeap(), 0, param->data);
575 /* only the parent has to release name and semantic */
576 if (!element)
578 HeapFree(GetProcessHeap(), 0, param->name);
579 HeapFree(GetProcessHeap(), 0, param->semantic);
583 static void free_pass(struct d3dx_pass *pass)
585 unsigned int i;
587 TRACE("Free pass %p\n", pass);
589 if (!pass)
590 return;
592 if (pass->annotations)
594 for (i = 0; i < pass->annotation_count; ++i)
595 free_parameter(&pass->annotations[i], FALSE, FALSE);
596 HeapFree(GetProcessHeap(), 0, pass->annotations);
597 pass->annotations = NULL;
600 if (pass->states)
602 for (i = 0; i < pass->state_count; ++i)
603 free_state(&pass->states[i]);
604 HeapFree(GetProcessHeap(), 0, pass->states);
605 pass->states = NULL;
608 HeapFree(GetProcessHeap(), 0, pass->name);
609 pass->name = NULL;
612 static void free_technique(struct d3dx_technique *technique)
614 unsigned int i;
616 TRACE("Free technique %p\n", technique);
618 if (!technique)
619 return;
621 if (technique->saved_state)
623 IDirect3DStateBlock9_Release(technique->saved_state);
624 technique->saved_state = NULL;
627 if (technique->annotations)
629 for (i = 0; i < technique->annotation_count; ++i)
630 free_parameter(&technique->annotations[i], FALSE, FALSE);
631 HeapFree(GetProcessHeap(), 0, technique->annotations);
632 technique->annotations = NULL;
635 if (technique->passes)
637 for (i = 0; i < technique->pass_count; ++i)
638 free_pass(&technique->passes[i]);
639 HeapFree(GetProcessHeap(), 0, technique->passes);
640 technique->passes = NULL;
643 HeapFree(GetProcessHeap(), 0, technique->name);
644 technique->name = NULL;
647 static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
649 unsigned int i;
651 TRACE("base %p.\n", base);
653 HeapFree(GetProcessHeap(), 0, base->param_table.table);
655 if (base->parameters)
657 for (i = 0; i < base->parameter_count; ++i)
658 free_parameter(&base->parameters[i], FALSE, FALSE);
659 HeapFree(GetProcessHeap(), 0, base->parameters);
660 base->parameters = NULL;
663 if (base->techniques)
665 for (i = 0; i < base->technique_count; ++i)
666 free_technique(&base->techniques[i]);
667 HeapFree(GetProcessHeap(), 0, base->techniques);
668 base->techniques = NULL;
671 if (base->objects)
673 for (i = 0; i < base->object_count; ++i)
675 free_object(&base->objects[i]);
677 HeapFree(GetProcessHeap(), 0, base->objects);
678 base->objects = NULL;
682 static void free_effect(struct ID3DXEffectImpl *effect)
684 TRACE("Free effect %p\n", effect);
686 d3dx9_base_effect_cleanup(&effect->base_effect);
688 if (effect->pool)
690 effect->pool->lpVtbl->Release(effect->pool);
693 if (effect->manager)
695 IUnknown_Release(effect->manager);
698 IDirect3DDevice9_Release(effect->device);
701 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
703 TRACE("Free effect compiler %p\n", compiler);
705 d3dx9_base_effect_cleanup(&compiler->base_effect);
708 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
710 UINT i;
712 for (i = 0; i < 4; ++i)
714 if (i < param->columns)
715 set_number((FLOAT *)vector + i, D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
716 else
717 ((FLOAT *)vector)[i] = 0.0f;
721 static void set_vector(struct d3dx_parameter *param, const D3DXVECTOR4 *vector)
723 UINT i;
725 for (i = 0; i < param->columns; ++i)
727 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
731 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix, BOOL transpose)
733 UINT i, k;
735 for (i = 0; i < 4; ++i)
737 for (k = 0; k < 4; ++k)
739 FLOAT *tmp = transpose ? (FLOAT *)&matrix->u.m[k][i] : (FLOAT *)&matrix->u.m[i][k];
741 if ((i < param->rows) && (k < param->columns))
742 set_number(tmp, D3DXPT_FLOAT, (DWORD *)param->data + i * param->columns + k, param->type);
743 else
744 *tmp = 0.0f;
749 static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
751 UINT i, k;
753 if (param->type == D3DXPT_FLOAT)
755 if (param->columns == 4)
756 memcpy(param->data, matrix->u.m, param->rows * 4 * sizeof(float));
757 else
758 for (i = 0; i < param->rows; ++i)
759 memcpy((float *)param->data + i * param->columns, matrix->u.m + i, param->columns * sizeof(float));
760 return;
763 for (i = 0; i < param->rows; ++i)
765 for (k = 0; k < param->columns; ++k)
767 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
768 &matrix->u.m[i][k], D3DXPT_FLOAT);
773 static void set_matrix_transpose(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
775 UINT i, k;
777 for (i = 0; i < param->rows; ++i)
779 for (k = 0; k < param->columns; ++k)
781 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
782 &matrix->u.m[k][i], D3DXPT_FLOAT);
787 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, const char *name)
789 UINT element;
790 struct d3dx_parameter *temp_parameter;
791 const char *part;
793 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
795 if (!name || !*name) return NULL;
797 element = atoi(name);
798 part = strchr(name, ']') + 1;
800 /* check for empty [] && element range */
801 if ((part - name) > 1 && parameter->element_count > element)
803 temp_parameter = &parameter->members[element];
805 switch (*part++)
807 case '.':
808 return get_parameter_by_name(NULL, temp_parameter, part);
810 case '@':
811 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
813 case '\0':
814 TRACE("Returning parameter %p\n", temp_parameter);
815 return temp_parameter;
817 default:
818 FIXME("Unhandled case \"%c\"\n", *--part);
819 break;
823 TRACE("Parameter not found\n");
824 return NULL;
827 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *annotations,
828 const char *name)
830 UINT i, length;
831 struct d3dx_parameter *temp_parameter;
832 const char *part;
834 TRACE("count %u, annotations %p, name %s\n", count, annotations, debugstr_a(name));
836 if (!name || !*name) return NULL;
838 length = strcspn( name, "[.@" );
839 part = name + length;
841 for (i = 0; i < count; ++i)
843 temp_parameter = &annotations[i];
845 if (!strcmp(temp_parameter->name, name))
847 TRACE("Returning annotation %p\n", temp_parameter);
848 return temp_parameter;
850 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
852 switch (*part++)
854 case '.':
855 return get_parameter_by_name(NULL, temp_parameter, part);
857 case '[':
858 return get_parameter_element_by_name(temp_parameter, part);
860 default:
861 FIXME("Unhandled case \"%c\"\n", *--part);
862 break;
867 TRACE("Annotation not found\n");
868 return NULL;
871 struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
872 struct d3dx_parameter *parameter, const char *name)
874 UINT i, count, length;
875 struct d3dx_parameter *temp_parameter;
876 struct d3dx_parameter *parameters;
877 const char *part;
879 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
881 if (!name || !*name) return NULL;
883 if (!parameter)
885 count = base->parameter_count;
886 parameters = base->parameters;
888 else
890 count = parameter->member_count;
891 parameters = parameter->members;
894 length = strcspn( name, "[.@" );
895 part = name + length;
897 for (i = 0; i < count; i++)
899 temp_parameter = &parameters[i];
901 if (!strcmp(temp_parameter->name, name))
903 TRACE("Returning parameter %p\n", temp_parameter);
904 return temp_parameter;
906 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
908 switch (*part++)
910 case '.':
911 return get_parameter_by_name(NULL, temp_parameter, part);
913 case '@':
914 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
916 case '[':
917 return get_parameter_element_by_name(temp_parameter, part);
919 default:
920 FIXME("Unhandled case \"%c\"\n", *--part);
921 break;
926 TRACE("Parameter not found\n");
927 return NULL;
930 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
932 return (0xfeff0000 | ((major) << 8) | (minor));
935 static HRESULT d3dx9_base_effect_get_desc(struct d3dx9_base_effect *base, D3DXEFFECT_DESC *desc)
937 if (!desc)
939 WARN("Invalid argument specified.\n");
940 return D3DERR_INVALIDCALL;
943 FIXME("partial stub!\n");
945 /* TODO: add creator and function count. */
946 desc->Creator = NULL;
947 desc->Functions = 0;
948 desc->Parameters = base->parameter_count;
949 desc->Techniques = base->technique_count;
951 return D3D_OK;
954 static HRESULT d3dx9_base_effect_get_parameter_desc(struct d3dx9_base_effect *base,
955 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
957 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
959 if (!desc || !param)
961 WARN("Invalid argument specified.\n");
962 return D3DERR_INVALIDCALL;
965 desc->Name = param->name;
966 desc->Semantic = param->semantic;
967 desc->Class = param->class;
968 desc->Type = param->type;
969 desc->Rows = param->rows;
970 desc->Columns = param->columns;
971 desc->Elements = param->element_count;
972 desc->Annotations = param->annotation_count;
973 desc->StructMembers = param->member_count;
974 desc->Flags = param->flags;
975 desc->Bytes = param->bytes;
977 return D3D_OK;
980 static HRESULT d3dx9_base_effect_get_technique_desc(struct d3dx9_base_effect *base,
981 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
983 struct d3dx_technique *tech = technique ? get_valid_technique(base, technique) : &base->techniques[0];
985 if (!desc || !tech)
987 WARN("Invalid argument specified.\n");
988 return D3DERR_INVALIDCALL;
991 desc->Name = tech->name;
992 desc->Passes = tech->pass_count;
993 desc->Annotations = tech->annotation_count;
995 return D3D_OK;
998 static HRESULT d3dx9_base_effect_get_pass_desc(struct d3dx9_base_effect *base,
999 D3DXHANDLE pass, D3DXPASS_DESC *desc)
1001 struct d3dx_pass *p = get_valid_pass(base, pass);
1003 if (!desc || !p)
1005 WARN("Invalid argument specified.\n");
1006 return D3DERR_INVALIDCALL;
1009 desc->Name = p->name;
1010 desc->Annotations = p->annotation_count;
1012 FIXME("Pixel shader and vertex shader are not supported, yet.\n");
1013 desc->pVertexShaderFunction = NULL;
1014 desc->pPixelShaderFunction = NULL;
1016 return D3D_OK;
1019 static HRESULT d3dx9_base_effect_get_function_desc(struct d3dx9_base_effect *base,
1020 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1022 FIXME("stub!\n");
1024 return E_NOTIMPL;
1027 static D3DXHANDLE d3dx9_base_effect_get_parameter(struct d3dx9_base_effect *base,
1028 D3DXHANDLE parameter, UINT index)
1030 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1032 if (!parameter)
1034 if (index < base->parameter_count)
1036 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1037 return get_parameter_handle(&base->parameters[index]);
1040 else
1042 if (param && !param->element_count && index < param->member_count)
1044 TRACE("Returning parameter %p.\n", &param->members[index]);
1045 return get_parameter_handle(&param->members[index]);
1049 WARN("Parameter not found.\n");
1051 return NULL;
1054 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_name(struct d3dx9_base_effect *base,
1055 D3DXHANDLE parameter, const char *name)
1057 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1058 D3DXHANDLE handle;
1060 if (!name)
1062 handle = get_parameter_handle(param);
1063 TRACE("Returning parameter %p.\n", handle);
1064 return handle;
1067 handle = get_parameter_handle(get_parameter_by_name(base, param, name));
1068 TRACE("Returning parameter %p.\n", handle);
1070 return handle;
1073 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_semantic(struct d3dx9_base_effect *base,
1074 D3DXHANDLE parameter, const char *semantic)
1076 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1077 struct d3dx_parameter *temp_param;
1078 UINT i;
1080 if (!parameter)
1082 for (i = 0; i < base->parameter_count; ++i)
1084 temp_param = &base->parameters[i];
1086 if (!temp_param->semantic)
1088 if (!semantic)
1090 TRACE("Returning parameter %p\n", temp_param);
1091 return get_parameter_handle(temp_param);
1093 continue;
1096 if (!strcasecmp(temp_param->semantic, semantic))
1098 TRACE("Returning parameter %p\n", temp_param);
1099 return get_parameter_handle(temp_param);
1103 else if (param)
1105 for (i = 0; i < param->member_count; ++i)
1107 temp_param = &param->members[i];
1109 if (!temp_param->semantic)
1111 if (!semantic)
1113 TRACE("Returning parameter %p\n", temp_param);
1114 return get_parameter_handle(temp_param);
1116 continue;
1119 if (!strcasecmp(temp_param->semantic, semantic))
1121 TRACE("Returning parameter %p\n", temp_param);
1122 return get_parameter_handle(temp_param);
1127 WARN("Parameter not found.\n");
1129 return NULL;
1132 static D3DXHANDLE d3dx9_base_effect_get_parameter_element(struct d3dx9_base_effect *base,
1133 D3DXHANDLE parameter, UINT index)
1135 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1137 if (!param)
1139 if (index < base->parameter_count)
1141 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1142 return get_parameter_handle(&base->parameters[index]);
1145 else
1147 if (index < param->element_count)
1149 TRACE("Returning parameter %p.\n", &param->members[index]);
1150 return get_parameter_handle(&param->members[index]);
1154 WARN("Parameter not found.\n");
1156 return NULL;
1159 static D3DXHANDLE d3dx9_base_effect_get_technique(struct d3dx9_base_effect *base, UINT index)
1161 if (index >= base->technique_count)
1163 WARN("Invalid argument specified.\n");
1164 return NULL;
1167 TRACE("Returning technique %p.\n", &base->techniques[index]);
1169 return get_technique_handle(&base->techniques[index]);
1172 static D3DXHANDLE d3dx9_base_effect_get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
1174 struct d3dx_technique *tech = get_technique_by_name(base, name);
1176 if (tech)
1178 D3DXHANDLE t = get_technique_handle(tech);
1179 TRACE("Returning technique %p\n", t);
1180 return t;
1183 WARN("Technique not found.\n");
1185 return NULL;
1188 static D3DXHANDLE d3dx9_base_effect_get_pass(struct d3dx9_base_effect *base,
1189 D3DXHANDLE technique, UINT index)
1191 struct d3dx_technique *tech = get_valid_technique(base, technique);
1193 if (tech && index < tech->pass_count)
1195 TRACE("Returning pass %p\n", &tech->passes[index]);
1196 return get_pass_handle(&tech->passes[index]);
1199 WARN("Pass not found.\n");
1201 return NULL;
1204 static D3DXHANDLE d3dx9_base_effect_get_pass_by_name(struct d3dx9_base_effect *base,
1205 D3DXHANDLE technique, const char *name)
1207 struct d3dx_technique *tech = get_valid_technique(base, technique);
1209 if (tech && name)
1211 unsigned int i;
1213 for (i = 0; i < tech->pass_count; ++i)
1215 struct d3dx_pass *pass = &tech->passes[i];
1217 if (!strcmp(pass->name, name))
1219 TRACE("Returning pass %p\n", pass);
1220 return get_pass_handle(pass);
1225 WARN("Pass not found.\n");
1227 return NULL;
1230 static D3DXHANDLE d3dx9_base_effect_get_function(struct d3dx9_base_effect *base, UINT index)
1232 FIXME("stub!\n");
1234 return NULL;
1237 static D3DXHANDLE d3dx9_base_effect_get_function_by_name(struct d3dx9_base_effect *base, const char *name)
1239 FIXME("stub!\n");
1241 return NULL;
1244 static UINT get_annotation_from_object(struct d3dx9_base_effect *base,
1245 D3DXHANDLE object, struct d3dx_parameter **annotations)
1247 struct d3dx_parameter *param = get_valid_parameter(base, object);
1248 struct d3dx_pass *pass = get_valid_pass(base, object);
1249 struct d3dx_technique *technique = get_valid_technique(base, object);
1251 if (pass)
1253 *annotations = pass->annotations;
1254 return pass->annotation_count;
1256 else if (technique)
1258 *annotations = technique->annotations;
1259 return technique->annotation_count;
1261 else if (param)
1263 *annotations = param->annotations;
1264 return param->annotation_count;
1266 else
1268 FIXME("Functions are not handled, yet!\n");
1269 return 0;
1273 static D3DXHANDLE d3dx9_base_effect_get_annotation(struct d3dx9_base_effect *base,
1274 D3DXHANDLE object, UINT index)
1276 struct d3dx_parameter *annotations = NULL;
1277 UINT annotation_count = 0;
1279 annotation_count = get_annotation_from_object(base, object, &annotations);
1281 if (index < annotation_count)
1283 TRACE("Returning parameter %p\n", &annotations[index]);
1284 return get_parameter_handle(&annotations[index]);
1287 WARN("Annotation not found.\n");
1289 return NULL;
1292 static D3DXHANDLE d3dx9_base_effect_get_annotation_by_name(struct d3dx9_base_effect *base,
1293 D3DXHANDLE object, const char *name)
1295 struct d3dx_parameter *annotation = NULL;
1296 struct d3dx_parameter *annotations = NULL;
1297 UINT annotation_count = 0;
1299 if (!name)
1301 WARN("Invalid argument specified\n");
1302 return NULL;
1305 annotation_count = get_annotation_from_object(base, object, &annotations);
1307 annotation = get_annotation_by_name(annotation_count, annotations, name);
1308 if (annotation)
1310 TRACE("Returning parameter %p\n", annotation);
1311 return get_parameter_handle(annotation);
1314 WARN("Annotation not found.\n");
1316 return NULL;
1319 static HRESULT d3dx9_base_effect_set_value(struct d3dx9_base_effect *base,
1320 D3DXHANDLE parameter, const void *data, UINT bytes)
1322 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1324 if (!param)
1326 WARN("Invalid parameter %p specified\n", parameter);
1327 return D3DERR_INVALIDCALL;
1330 /* samplers don't touch data */
1331 if (param->class == D3DXPC_OBJECT && is_param_type_sampler(param->type))
1333 TRACE("Sampler: returning E_FAIL\n");
1334 return E_FAIL;
1337 if (data && param->bytes <= bytes)
1339 switch (param->type)
1341 case D3DXPT_TEXTURE:
1342 case D3DXPT_TEXTURE1D:
1343 case D3DXPT_TEXTURE2D:
1344 case D3DXPT_TEXTURE3D:
1345 case D3DXPT_TEXTURECUBE:
1347 unsigned int i;
1349 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1351 IUnknown *unk = ((IUnknown **)data)[i];
1352 if (unk)
1353 IUnknown_AddRef(unk);
1355 unk = ((IUnknown **)param->data)[i];
1356 if (unk)
1357 IUnknown_Release(unk);
1360 /* fallthrough */
1361 case D3DXPT_VOID:
1362 case D3DXPT_BOOL:
1363 case D3DXPT_INT:
1364 case D3DXPT_FLOAT:
1365 TRACE("Copy %u bytes\n", param->bytes);
1366 memcpy(param->data, data, param->bytes);
1367 break;
1369 default:
1370 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1371 break;
1374 return D3D_OK;
1377 WARN("Invalid argument specified\n");
1379 return D3DERR_INVALIDCALL;
1382 static HRESULT d3dx9_base_effect_get_value(struct d3dx9_base_effect *base,
1383 D3DXHANDLE parameter, void *data, UINT bytes)
1385 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1387 if (!param)
1389 WARN("Invalid parameter %p specified\n", parameter);
1390 return D3DERR_INVALIDCALL;
1393 /* samplers don't touch data */
1394 if (param->class == D3DXPC_OBJECT && is_param_type_sampler(param->type))
1396 TRACE("Sampler: returning E_FAIL\n");
1397 return E_FAIL;
1400 if (data && param->bytes <= bytes)
1402 TRACE("Type %s\n", debug_d3dxparameter_type(param->type));
1404 switch (param->type)
1406 case D3DXPT_VOID:
1407 case D3DXPT_BOOL:
1408 case D3DXPT_INT:
1409 case D3DXPT_FLOAT:
1410 case D3DXPT_STRING:
1411 break;
1413 case D3DXPT_VERTEXSHADER:
1414 case D3DXPT_PIXELSHADER:
1415 case D3DXPT_TEXTURE:
1416 case D3DXPT_TEXTURE1D:
1417 case D3DXPT_TEXTURE2D:
1418 case D3DXPT_TEXTURE3D:
1419 case D3DXPT_TEXTURECUBE:
1421 UINT i;
1423 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1425 IUnknown *unk = ((IUnknown **)param->data)[i];
1426 if (unk) IUnknown_AddRef(unk);
1428 break;
1431 default:
1432 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1433 break;
1436 TRACE("Copy %u bytes\n", param->bytes);
1437 memcpy(data, param->data, param->bytes);
1438 return D3D_OK;
1441 WARN("Parameter not found.\n");
1443 return D3DERR_INVALIDCALL;
1446 static HRESULT d3dx9_base_effect_set_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL b)
1448 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1450 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1452 set_number(param->data, param->type, &b, D3DXPT_BOOL);
1453 return D3D_OK;
1456 WARN("Parameter not found.\n");
1458 return D3DERR_INVALIDCALL;
1461 static HRESULT d3dx9_base_effect_get_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL *b)
1463 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1465 if (b && param && !param->element_count && param->rows == 1 && param->columns == 1)
1467 set_number(b, D3DXPT_BOOL, param->data, param->type);
1468 TRACE("Returning %s\n", *b ? "TRUE" : "FALSE");
1469 return D3D_OK;
1472 WARN("Parameter not found.\n");
1474 return D3DERR_INVALIDCALL;
1477 static HRESULT d3dx9_base_effect_set_bool_array(struct d3dx9_base_effect *base,
1478 D3DXHANDLE parameter, const BOOL *b, UINT count)
1480 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1482 if (param)
1484 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1486 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1488 switch (param->class)
1490 case D3DXPC_SCALAR:
1491 case D3DXPC_VECTOR:
1492 case D3DXPC_MATRIX_ROWS:
1493 for (i = 0; i < size; ++i)
1495 /* don't crop the input, use D3DXPT_INT instead of D3DXPT_BOOL */
1496 set_number((DWORD *)param->data + i, param->type, &b[i], D3DXPT_INT);
1498 return D3D_OK;
1500 case D3DXPC_OBJECT:
1501 case D3DXPC_STRUCT:
1502 break;
1504 default:
1505 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1506 break;
1510 WARN("Parameter not found.\n");
1512 return D3DERR_INVALIDCALL;
1515 static HRESULT d3dx9_base_effect_get_bool_array(struct d3dx9_base_effect *base,
1516 D3DXHANDLE parameter, BOOL *b, UINT count)
1518 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1520 if (b && param && (param->class == D3DXPC_SCALAR
1521 || param->class == D3DXPC_VECTOR
1522 || param->class == D3DXPC_MATRIX_ROWS
1523 || param->class == D3DXPC_MATRIX_COLUMNS))
1525 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1527 for (i = 0; i < size; ++i)
1529 set_number(&b[i], D3DXPT_BOOL, (DWORD *)param->data + i, param->type);
1531 return D3D_OK;
1534 WARN("Parameter not found.\n");
1536 return D3DERR_INVALIDCALL;
1539 static HRESULT d3dx9_base_effect_set_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT n)
1541 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1543 if (param && !param->element_count)
1545 if (param->rows == 1 && param->columns == 1)
1547 set_number(param->data, param->type, &n, D3DXPT_INT);
1548 return D3D_OK;
1552 * Split the value, if parameter is a vector with dimension 3 or 4.
1554 if (param->type == D3DXPT_FLOAT &&
1555 ((param->class == D3DXPC_VECTOR && param->columns != 2) ||
1556 (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1558 TRACE("Vector fixup\n");
1560 *(FLOAT *)param->data = ((n & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1561 ((FLOAT *)param->data)[1] = ((n & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1562 ((FLOAT *)param->data)[2] = (n & 0xff) * INT_FLOAT_MULTI_INVERSE;
1563 if (param->rows * param->columns > 3)
1565 ((FLOAT *)param->data)[3] = ((n & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1567 return D3D_OK;
1571 WARN("Parameter not found.\n");
1573 return D3DERR_INVALIDCALL;
1576 static HRESULT d3dx9_base_effect_get_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT *n)
1578 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1580 if (n && param && !param->element_count)
1582 if (param->columns == 1 && param->rows == 1)
1584 set_number(n, D3DXPT_INT, param->data, param->type);
1585 TRACE("Returning %i\n", *n);
1586 return D3D_OK;
1589 if (param->type == D3DXPT_FLOAT &&
1590 ((param->class == D3DXPC_VECTOR && param->columns != 2)
1591 || (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1593 TRACE("Vector fixup\n");
1595 /* all components (3,4) are clamped (0,255) and put in the INT */
1596 *n = (INT)(min(max(0.0f, *((FLOAT *)param->data + 2)), 1.0f) * INT_FLOAT_MULTI);
1597 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 1)), 1.0f) * INT_FLOAT_MULTI)) << 8;
1598 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 0)), 1.0f) * INT_FLOAT_MULTI)) << 16;
1599 if (param->columns * param->rows > 3)
1601 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 3)), 1.0f) * INT_FLOAT_MULTI)) << 24;
1604 TRACE("Returning %i\n", *n);
1605 return D3D_OK;
1609 WARN("Parameter not found.\n");
1611 return D3DERR_INVALIDCALL;
1614 static HRESULT d3dx9_base_effect_set_int_array(struct d3dx9_base_effect *base,
1615 D3DXHANDLE parameter, const INT *n, UINT count)
1617 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1619 if (param)
1621 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1623 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1625 switch (param->class)
1627 case D3DXPC_SCALAR:
1628 case D3DXPC_VECTOR:
1629 case D3DXPC_MATRIX_ROWS:
1630 for (i = 0; i < size; ++i)
1632 set_number((DWORD *)param->data + i, param->type, &n[i], D3DXPT_INT);
1634 return D3D_OK;
1636 case D3DXPC_OBJECT:
1637 case D3DXPC_STRUCT:
1638 break;
1640 default:
1641 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1642 break;
1646 WARN("Parameter not found.\n");
1648 return D3DERR_INVALIDCALL;
1651 static HRESULT d3dx9_base_effect_get_int_array(struct d3dx9_base_effect *base,
1652 D3DXHANDLE parameter, INT *n, UINT count)
1654 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1656 if (n && param && (param->class == D3DXPC_SCALAR
1657 || param->class == D3DXPC_VECTOR
1658 || param->class == D3DXPC_MATRIX_ROWS
1659 || param->class == D3DXPC_MATRIX_COLUMNS))
1661 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1663 for (i = 0; i < size; ++i)
1665 set_number(&n[i], D3DXPT_INT, (DWORD *)param->data + i, param->type);
1667 return D3D_OK;
1670 WARN("Parameter not found.\n");
1672 return D3DERR_INVALIDCALL;
1675 static HRESULT d3dx9_base_effect_set_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float f)
1677 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1679 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1681 set_number((DWORD *)param->data, param->type, &f, D3DXPT_FLOAT);
1682 return D3D_OK;
1685 WARN("Parameter not found.\n");
1687 return D3DERR_INVALIDCALL;
1690 static HRESULT d3dx9_base_effect_get_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float *f)
1692 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1694 if (f && param && !param->element_count && param->columns == 1 && param->rows == 1)
1696 set_number(f, D3DXPT_FLOAT, (DWORD *)param->data, param->type);
1697 TRACE("Returning %f\n", *f);
1698 return D3D_OK;
1701 WARN("Parameter not found.\n");
1703 return D3DERR_INVALIDCALL;
1706 static HRESULT d3dx9_base_effect_set_float_array(struct d3dx9_base_effect *base,
1707 D3DXHANDLE parameter, const float *f, UINT count)
1709 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1711 if (param)
1713 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1715 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1717 switch (param->class)
1719 case D3DXPC_SCALAR:
1720 case D3DXPC_VECTOR:
1721 case D3DXPC_MATRIX_ROWS:
1722 for (i = 0; i < size; ++i)
1724 set_number((DWORD *)param->data + i, param->type, &f[i], D3DXPT_FLOAT);
1726 return D3D_OK;
1728 case D3DXPC_OBJECT:
1729 case D3DXPC_STRUCT:
1730 break;
1732 default:
1733 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1734 break;
1738 WARN("Parameter not found.\n");
1740 return D3DERR_INVALIDCALL;
1743 static HRESULT d3dx9_base_effect_get_float_array(struct d3dx9_base_effect *base,
1744 D3DXHANDLE parameter, float *f, UINT count)
1746 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1748 if (f && param && (param->class == D3DXPC_SCALAR
1749 || param->class == D3DXPC_VECTOR
1750 || param->class == D3DXPC_MATRIX_ROWS
1751 || param->class == D3DXPC_MATRIX_COLUMNS))
1753 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1755 for (i = 0; i < size; ++i)
1757 set_number(&f[i], D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
1759 return D3D_OK;
1762 WARN("Parameter not found.\n");
1764 return D3DERR_INVALIDCALL;
1767 static HRESULT d3dx9_base_effect_set_vector(struct d3dx9_base_effect *base,
1768 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
1770 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1772 if (param && !param->element_count)
1774 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1776 switch (param->class)
1778 case D3DXPC_SCALAR:
1779 case D3DXPC_VECTOR:
1780 if (param->type == D3DXPT_INT && param->bytes == 4)
1782 DWORD tmp;
1784 TRACE("INT fixup\n");
1785 tmp = (DWORD)(max(min(vector->z, 1.0f), 0.0f) * INT_FLOAT_MULTI);
1786 tmp += ((DWORD)(max(min(vector->y, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 8;
1787 tmp += ((DWORD)(max(min(vector->x, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 16;
1788 tmp += ((DWORD)(max(min(vector->w, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 24;
1790 *(INT *)param->data = tmp;
1791 return D3D_OK;
1793 if (param->type == D3DXPT_FLOAT)
1795 memcpy(param->data, vector, param->columns * sizeof(float));
1796 return D3D_OK;
1799 set_vector(param, vector);
1800 return D3D_OK;
1802 case D3DXPC_MATRIX_ROWS:
1803 case D3DXPC_OBJECT:
1804 case D3DXPC_STRUCT:
1805 break;
1807 default:
1808 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1809 break;
1813 WARN("Parameter not found.\n");
1815 return D3DERR_INVALIDCALL;
1818 static HRESULT d3dx9_base_effect_get_vector(struct d3dx9_base_effect *base,
1819 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
1821 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1823 if (vector && param && !param->element_count)
1825 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1827 switch (param->class)
1829 case D3DXPC_SCALAR:
1830 case D3DXPC_VECTOR:
1831 if (param->type == D3DXPT_INT && param->bytes == 4)
1833 TRACE("INT fixup\n");
1834 vector->x = (((*(INT *)param->data) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1835 vector->y = (((*(INT *)param->data) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1836 vector->z = ((*(INT *)param->data) & 0xff) * INT_FLOAT_MULTI_INVERSE;
1837 vector->w = (((*(INT *)param->data) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1838 return D3D_OK;
1840 get_vector(param, vector);
1841 return D3D_OK;
1843 case D3DXPC_MATRIX_ROWS:
1844 case D3DXPC_OBJECT:
1845 case D3DXPC_STRUCT:
1846 break;
1848 default:
1849 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1850 break;
1854 WARN("Parameter not found.\n");
1856 return D3DERR_INVALIDCALL;
1859 static HRESULT d3dx9_base_effect_set_vector_array(struct d3dx9_base_effect *base,
1860 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
1862 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1864 if (param && param->element_count && param->element_count >= count)
1866 UINT i;
1868 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1870 switch (param->class)
1872 case D3DXPC_VECTOR:
1873 if (param->type == D3DXPT_FLOAT)
1875 if (param->columns == 4)
1876 memcpy(param->data, vector, count * 4 * sizeof(float));
1877 else
1878 for (i = 0; i < count; ++i)
1879 memcpy((float *)param->data + param->columns * i, vector + i,
1880 param->columns * sizeof(float));
1881 return D3D_OK;
1884 for (i = 0; i < count; ++i)
1886 set_vector(&param->members[i], &vector[i]);
1888 return D3D_OK;
1890 case D3DXPC_SCALAR:
1891 case D3DXPC_MATRIX_ROWS:
1892 case D3DXPC_OBJECT:
1893 case D3DXPC_STRUCT:
1894 break;
1896 default:
1897 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1898 break;
1902 WARN("Parameter not found.\n");
1904 return D3DERR_INVALIDCALL;
1907 static HRESULT d3dx9_base_effect_get_vector_array(struct d3dx9_base_effect *base,
1908 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
1910 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1912 if (!count) return D3D_OK;
1914 if (vector && param && count <= param->element_count)
1916 UINT i;
1918 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1920 switch (param->class)
1922 case D3DXPC_VECTOR:
1923 for (i = 0; i < count; ++i)
1925 get_vector(&param->members[i], &vector[i]);
1927 return D3D_OK;
1929 case D3DXPC_SCALAR:
1930 case D3DXPC_MATRIX_ROWS:
1931 case D3DXPC_OBJECT:
1932 case D3DXPC_STRUCT:
1933 break;
1935 default:
1936 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1937 break;
1941 WARN("Parameter not found.\n");
1943 return D3DERR_INVALIDCALL;
1946 static HRESULT d3dx9_base_effect_set_matrix(struct d3dx9_base_effect *base,
1947 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
1949 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1951 if (param && !param->element_count)
1953 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1955 switch (param->class)
1957 case D3DXPC_MATRIX_ROWS:
1958 set_matrix(param, matrix);
1959 return D3D_OK;
1961 case D3DXPC_SCALAR:
1962 case D3DXPC_VECTOR:
1963 case D3DXPC_OBJECT:
1964 case D3DXPC_STRUCT:
1965 break;
1967 default:
1968 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1969 break;
1973 WARN("Parameter not found.\n");
1975 return D3DERR_INVALIDCALL;
1978 static HRESULT d3dx9_base_effect_get_matrix(struct d3dx9_base_effect *base,
1979 D3DXHANDLE parameter, D3DXMATRIX *matrix)
1981 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1983 if (matrix && param && !param->element_count)
1985 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1987 switch (param->class)
1989 case D3DXPC_MATRIX_ROWS:
1990 get_matrix(param, matrix, FALSE);
1991 return D3D_OK;
1993 case D3DXPC_SCALAR:
1994 case D3DXPC_VECTOR:
1995 case D3DXPC_OBJECT:
1996 case D3DXPC_STRUCT:
1997 break;
1999 default:
2000 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2001 break;
2005 WARN("Parameter not found.\n");
2007 return D3DERR_INVALIDCALL;
2010 static HRESULT d3dx9_base_effect_set_matrix_array(struct d3dx9_base_effect *base,
2011 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2013 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2015 if (param && param->element_count >= count)
2017 UINT i;
2019 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2021 switch (param->class)
2023 case D3DXPC_MATRIX_ROWS:
2024 for (i = 0; i < count; ++i)
2026 set_matrix(&param->members[i], &matrix[i]);
2028 return D3D_OK;
2030 case D3DXPC_SCALAR:
2031 case D3DXPC_VECTOR:
2032 case D3DXPC_OBJECT:
2033 case D3DXPC_STRUCT:
2034 break;
2036 default:
2037 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2038 break;
2042 WARN("Parameter not found.\n");
2044 return D3DERR_INVALIDCALL;
2047 static HRESULT d3dx9_base_effect_get_matrix_array(struct d3dx9_base_effect *base,
2048 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2050 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2052 if (!count) return D3D_OK;
2054 if (matrix && param && count <= param->element_count)
2056 UINT i;
2058 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2060 switch (param->class)
2062 case D3DXPC_MATRIX_ROWS:
2063 for (i = 0; i < count; ++i)
2065 get_matrix(&param->members[i], &matrix[i], FALSE);
2067 return D3D_OK;
2069 case D3DXPC_SCALAR:
2070 case D3DXPC_VECTOR:
2071 case D3DXPC_OBJECT:
2072 case D3DXPC_STRUCT:
2073 break;
2075 default:
2076 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2077 break;
2081 WARN("Parameter not found.\n");
2083 return D3DERR_INVALIDCALL;
2086 static HRESULT d3dx9_base_effect_set_matrix_pointer_array(struct d3dx9_base_effect *base,
2087 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2089 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2091 if (param && count <= param->element_count)
2093 UINT i;
2095 switch (param->class)
2097 case D3DXPC_MATRIX_ROWS:
2098 for (i = 0; i < count; ++i)
2100 set_matrix(&param->members[i], matrix[i]);
2102 return D3D_OK;
2104 case D3DXPC_SCALAR:
2105 case D3DXPC_VECTOR:
2106 case D3DXPC_OBJECT:
2107 break;
2109 default:
2110 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2111 break;
2115 WARN("Parameter not found.\n");
2117 return D3DERR_INVALIDCALL;
2120 static HRESULT d3dx9_base_effect_get_matrix_pointer_array(struct d3dx9_base_effect *base,
2121 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2123 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2125 if (!count) return D3D_OK;
2127 if (param && matrix && count <= param->element_count)
2129 UINT i;
2131 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2133 switch (param->class)
2135 case D3DXPC_MATRIX_ROWS:
2136 for (i = 0; i < count; ++i)
2138 get_matrix(&param->members[i], matrix[i], FALSE);
2140 return D3D_OK;
2142 case D3DXPC_SCALAR:
2143 case D3DXPC_VECTOR:
2144 case D3DXPC_OBJECT:
2145 break;
2147 default:
2148 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2149 break;
2153 WARN("Parameter not found.\n");
2155 return D3DERR_INVALIDCALL;
2158 static HRESULT d3dx9_base_effect_set_matrix_transpose(struct d3dx9_base_effect *base,
2159 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2161 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2163 if (param && !param->element_count)
2165 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2167 switch (param->class)
2169 case D3DXPC_MATRIX_ROWS:
2170 set_matrix_transpose(param, matrix);
2171 return D3D_OK;
2173 case D3DXPC_SCALAR:
2174 case D3DXPC_VECTOR:
2175 case D3DXPC_OBJECT:
2176 case D3DXPC_STRUCT:
2177 break;
2179 default:
2180 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2181 break;
2185 WARN("Parameter not found.\n");
2187 return D3DERR_INVALIDCALL;
2190 static HRESULT d3dx9_base_effect_get_matrix_transpose(struct d3dx9_base_effect *base,
2191 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2193 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2195 if (matrix && param && !param->element_count)
2197 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2199 switch (param->class)
2201 case D3DXPC_SCALAR:
2202 case D3DXPC_VECTOR:
2203 get_matrix(param, matrix, FALSE);
2204 return D3D_OK;
2206 case D3DXPC_MATRIX_ROWS:
2207 get_matrix(param, matrix, TRUE);
2208 return D3D_OK;
2210 case D3DXPC_OBJECT:
2211 case D3DXPC_STRUCT:
2212 break;
2214 default:
2215 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2216 break;
2220 WARN("Parameter not found.\n");
2222 return D3DERR_INVALIDCALL;
2225 static HRESULT d3dx9_base_effect_set_matrix_transpose_array(struct d3dx9_base_effect *base,
2226 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2228 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2230 if (param && param->element_count >= count)
2232 UINT i;
2234 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2236 switch (param->class)
2238 case D3DXPC_MATRIX_ROWS:
2239 for (i = 0; i < count; ++i)
2241 set_matrix_transpose(&param->members[i], &matrix[i]);
2243 return D3D_OK;
2245 case D3DXPC_SCALAR:
2246 case D3DXPC_VECTOR:
2247 case D3DXPC_OBJECT:
2248 case D3DXPC_STRUCT:
2249 break;
2251 default:
2252 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2253 break;
2257 WARN("Parameter not found.\n");
2259 return D3DERR_INVALIDCALL;
2262 static HRESULT d3dx9_base_effect_get_matrix_transpose_array(struct d3dx9_base_effect *base,
2263 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2265 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2267 if (!count) return D3D_OK;
2269 if (matrix && param && count <= param->element_count)
2271 UINT i;
2273 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2275 switch (param->class)
2277 case D3DXPC_MATRIX_ROWS:
2278 for (i = 0; i < count; ++i)
2280 get_matrix(&param->members[i], &matrix[i], TRUE);
2282 return D3D_OK;
2284 case D3DXPC_SCALAR:
2285 case D3DXPC_VECTOR:
2286 case D3DXPC_OBJECT:
2287 case D3DXPC_STRUCT:
2288 break;
2290 default:
2291 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2292 break;
2296 WARN("Parameter not found.\n");
2298 return D3DERR_INVALIDCALL;
2301 static HRESULT d3dx9_base_effect_set_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2302 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2304 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2306 if (param && count <= param->element_count)
2308 UINT i;
2310 switch (param->class)
2312 case D3DXPC_MATRIX_ROWS:
2313 for (i = 0; i < count; ++i)
2315 set_matrix_transpose(&param->members[i], matrix[i]);
2317 return D3D_OK;
2319 case D3DXPC_SCALAR:
2320 case D3DXPC_VECTOR:
2321 case D3DXPC_OBJECT:
2322 break;
2324 default:
2325 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2326 break;
2330 WARN("Parameter not found.\n");
2332 return D3DERR_INVALIDCALL;
2335 static HRESULT d3dx9_base_effect_get_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2336 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2338 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2340 if (!count) return D3D_OK;
2342 if (matrix && param && count <= param->element_count)
2344 UINT i;
2346 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2348 switch (param->class)
2350 case D3DXPC_MATRIX_ROWS:
2351 for (i = 0; i < count; ++i)
2353 get_matrix(&param->members[i], matrix[i], TRUE);
2355 return D3D_OK;
2357 case D3DXPC_SCALAR:
2358 case D3DXPC_VECTOR:
2359 case D3DXPC_OBJECT:
2360 break;
2362 default:
2363 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2364 break;
2368 WARN("Parameter not found.\n");
2370 return D3DERR_INVALIDCALL;
2373 static HRESULT d3dx9_base_effect_set_string(struct d3dx9_base_effect *base,
2374 D3DXHANDLE parameter, const char *string)
2376 FIXME("stub!\n");
2378 return E_NOTIMPL;
2381 static HRESULT d3dx9_base_effect_get_string(struct d3dx9_base_effect *base,
2382 D3DXHANDLE parameter, const char **string)
2384 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2386 if (string && param && !param->element_count && param->type == D3DXPT_STRING)
2388 *string = *(const char **)param->data;
2389 TRACE("Returning %s.\n", debugstr_a(*string));
2390 return D3D_OK;
2393 WARN("Parameter not found.\n");
2395 return D3DERR_INVALIDCALL;
2398 static HRESULT d3dx9_base_effect_set_texture(struct d3dx9_base_effect *base,
2399 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
2401 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2403 if (param && !param->element_count &&
2404 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2405 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2406 || param->type == D3DXPT_TEXTURECUBE))
2408 struct IDirect3DBaseTexture9 *oltexture = *(struct IDirect3DBaseTexture9 **)param->data;
2410 if (texture == oltexture)
2411 return D3D_OK;
2413 if (texture) IDirect3DBaseTexture9_AddRef(texture);
2414 if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
2416 *(struct IDirect3DBaseTexture9 **)param->data = texture;
2418 return D3D_OK;
2421 WARN("Parameter not found.\n");
2423 return D3DERR_INVALIDCALL;
2426 static HRESULT d3dx9_base_effect_get_texture(struct d3dx9_base_effect *base,
2427 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
2429 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2431 if (texture && param && !param->element_count &&
2432 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2433 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2434 || param->type == D3DXPT_TEXTURECUBE))
2436 *texture = *(struct IDirect3DBaseTexture9 **)param->data;
2437 if (*texture) IDirect3DBaseTexture9_AddRef(*texture);
2438 TRACE("Returning %p\n", *texture);
2439 return D3D_OK;
2442 WARN("Parameter not found.\n");
2444 return D3DERR_INVALIDCALL;
2447 static HRESULT d3dx9_base_effect_get_pixel_shader(struct d3dx9_base_effect *base,
2448 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
2450 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2452 if (shader && param && !param->element_count && param->type == D3DXPT_PIXELSHADER)
2454 if ((*shader = *(struct IDirect3DPixelShader9 **)param->data))
2455 IDirect3DPixelShader9_AddRef(*shader);
2456 TRACE("Returning %p.\n", *shader);
2457 return D3D_OK;
2460 WARN("Parameter not found.\n");
2462 return D3DERR_INVALIDCALL;
2465 static HRESULT d3dx9_base_effect_get_vertex_shader(struct d3dx9_base_effect *base,
2466 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
2468 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2470 if (shader && param && !param->element_count && param->type == D3DXPT_VERTEXSHADER)
2472 if ((*shader = *(struct IDirect3DVertexShader9 **)param->data))
2473 IDirect3DVertexShader9_AddRef(*shader);
2474 TRACE("Returning %p.\n", *shader);
2475 return D3D_OK;
2478 WARN("Parameter not found.\n");
2480 return D3DERR_INVALIDCALL;
2483 static HRESULT d3dx9_base_effect_set_array_range(struct d3dx9_base_effect *base,
2484 D3DXHANDLE parameter, UINT start, UINT end)
2486 FIXME("stub!\n");
2488 return E_NOTIMPL;
2491 static HRESULT d3dx9_get_param_value_ptr(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2492 struct d3dx_state *state, void **param_value, struct d3dx_parameter **out_param)
2494 struct d3dx_parameter *param = &state->parameter;
2496 *param_value = NULL;
2497 *out_param = NULL;
2499 switch (state->type)
2501 case ST_PARAMETER:
2502 param = param->referenced_param;
2503 /* fallthrough */
2504 case ST_CONSTANT:
2505 *out_param = param;
2506 *param_value = param->data;
2507 return D3D_OK;
2508 case ST_ARRAY_SELECTOR:
2510 unsigned int array_idx;
2511 static const struct d3dx_parameter array_idx_param =
2512 {NULL, NULL, NULL, D3DXPC_SCALAR, D3DXPT_INT, 1, 1, 0, 0, 0, 0, sizeof(array_idx)};
2513 HRESULT hr;
2515 if (!param->param_eval)
2517 FIXME("Preshader structure is null.\n");
2518 return D3DERR_INVALIDCALL;
2520 if (FAILED(hr = d3dx_evaluate_parameter(param->param_eval, &array_idx_param, &array_idx)))
2521 return hr;
2523 param = param->referenced_param;
2524 TRACE("Array index %u.\n", array_idx);
2525 if (array_idx >= param->element_count)
2527 ERR("Computed array index %u is out of bound %u.\n", array_idx, param->element_count);
2528 return D3DERR_INVALIDCALL;
2530 param = &param->members[array_idx];
2532 *param_value = param->data;
2533 *out_param = param;
2534 return D3D_OK;
2536 case ST_FXLC:
2537 if (param->param_eval)
2539 *out_param = param;
2540 *param_value = param->data;
2541 return d3dx_evaluate_parameter(param->param_eval, param, *param_value);
2543 else
2545 FIXME("No preshader for FXLC parameter.\n");
2546 return D3DERR_INVALIDCALL;
2549 return E_NOTIMPL;
2552 static void d3dx9_set_light_parameter(enum LIGHT_TYPE op, D3DLIGHT9 *light, void *value)
2554 static const struct
2556 unsigned int offset;
2557 const char *name;
2559 light_tbl[] =
2561 {FIELD_OFFSET(D3DLIGHT9, Type), "LC_TYPE"},
2562 {FIELD_OFFSET(D3DLIGHT9, Diffuse), "LT_DIFFUSE"},
2563 {FIELD_OFFSET(D3DLIGHT9, Specular), "LT_SPECULAR"},
2564 {FIELD_OFFSET(D3DLIGHT9, Ambient), "LT_AMBIENT"},
2565 {FIELD_OFFSET(D3DLIGHT9, Position), "LT_POSITION"},
2566 {FIELD_OFFSET(D3DLIGHT9, Direction), "LT_DIRECTION"},
2567 {FIELD_OFFSET(D3DLIGHT9, Range), "LT_RANGE"},
2568 {FIELD_OFFSET(D3DLIGHT9, Falloff), "LT_FALLOFF"},
2569 {FIELD_OFFSET(D3DLIGHT9, Attenuation0), "LT_ATTENUATION0"},
2570 {FIELD_OFFSET(D3DLIGHT9, Attenuation1), "LT_ATTENUATION1"},
2571 {FIELD_OFFSET(D3DLIGHT9, Attenuation2), "LT_ATTENUATION2"},
2572 {FIELD_OFFSET(D3DLIGHT9, Theta), "LT_THETA"},
2573 {FIELD_OFFSET(D3DLIGHT9, Phi), "LT_PHI"}
2575 switch (op)
2577 case LT_TYPE:
2578 TRACE("LT_TYPE %u.\n", *(D3DLIGHTTYPE *)value);
2579 light->Type = *(D3DLIGHTTYPE *)value;
2580 break;
2581 case LT_DIFFUSE:
2582 case LT_SPECULAR:
2583 case LT_AMBIENT:
2585 D3DCOLORVALUE c = *(D3DCOLORVALUE *)value;
2587 TRACE("%s (%.8e %.8e %.8e %.8e).\n", light_tbl[op].name, c.r, c.g, c.b, c.a);
2588 *(D3DCOLORVALUE *)((BYTE *)light + light_tbl[op].offset) = c;
2589 break;
2591 case LT_POSITION:
2592 case LT_DIRECTION:
2594 D3DVECTOR v = *(D3DVECTOR *)value;
2596 TRACE("%s (%.8e %.8e %.8e).\n", light_tbl[op].name, v.x, v.y, v.z);
2597 *(D3DVECTOR *)((BYTE *)light + light_tbl[op].offset) = v;
2598 break;
2600 case LT_RANGE:
2601 case LT_FALLOFF:
2602 case LT_ATTENUATION0:
2603 case LT_ATTENUATION1:
2604 case LT_ATTENUATION2:
2605 case LT_THETA:
2606 case LT_PHI:
2608 float v = *(float *)value;
2609 TRACE("%s %.8e.\n", light_tbl[op].name, v);
2610 *(float *)((BYTE *)light + light_tbl[op].offset) = v;
2611 break;
2613 default:
2614 WARN("Unknown light parameter %u.\n", op);
2615 break;
2619 static void d3dx9_set_material_parameter(enum MATERIAL_TYPE op, D3DMATERIAL9 *material, void *value)
2621 static const struct
2623 unsigned int offset;
2624 const char *name;
2626 material_tbl[] =
2628 {FIELD_OFFSET(D3DMATERIAL9, Diffuse), "MT_DIFFUSE"},
2629 {FIELD_OFFSET(D3DMATERIAL9, Ambient), "MT_AMBIENT"},
2630 {FIELD_OFFSET(D3DMATERIAL9, Specular), "MT_SPECULAR"},
2631 {FIELD_OFFSET(D3DMATERIAL9, Emissive), "MT_EMISSIVE"},
2632 {FIELD_OFFSET(D3DMATERIAL9, Power), "MT_POWER"}
2635 switch (op)
2637 case MT_POWER:
2639 float v = *(float *)value;
2641 TRACE("%s %.8e.\n", material_tbl[op].name, v);
2642 material->Power = v;
2643 break;
2645 case MT_DIFFUSE:
2646 case MT_AMBIENT:
2647 case MT_SPECULAR:
2648 case MT_EMISSIVE:
2650 D3DCOLORVALUE c = *(D3DCOLORVALUE *)value;
2652 TRACE("%s, value (%.8e %.8e %.8e %.8e).\n", material_tbl[op].name, c.r, c.g, c.b, c.a);
2653 *(D3DCOLORVALUE *)((BYTE *)material + material_tbl[op].offset) = c;
2654 break;
2656 default:
2657 WARN("Unknown material parameter %u.\n", op);
2658 break;
2662 static HRESULT d3dx_set_shader_const_state(IDirect3DDevice9 *device, enum SHADER_CONSTANT_TYPE op, UINT index,
2663 struct d3dx_parameter *param, void *value_ptr)
2665 static const struct
2667 D3DXPARAMETER_TYPE type;
2668 UINT elem_size;
2669 const char *name;
2671 const_tbl[] =
2673 {D3DXPT_FLOAT, sizeof(float) * 4, "SCT_VSFLOAT"},
2674 {D3DXPT_BOOL, sizeof(BOOL), "SCT_VSBOOL"},
2675 {D3DXPT_INT, sizeof(int) * 4, "SCT_VSINT"},
2676 {D3DXPT_FLOAT, sizeof(float) * 4, "SCT_PSFLOAT"},
2677 {D3DXPT_BOOL, sizeof(BOOL), "SCT_PSBOOL"},
2678 {D3DXPT_INT, sizeof(int) * 4, "SCT_PSINT"},
2680 unsigned int element_count;
2682 if (op < 0 || op > SCT_PSINT)
2684 FIXME("Unknown op %u.\n", op);
2685 return D3DERR_INVALIDCALL;
2687 element_count = param->bytes / const_tbl[op].elem_size;
2688 TRACE("%s, index %u, element_count %u.\n", const_tbl[op].name, index, element_count);
2689 if (param->type != const_tbl[op].type)
2691 FIXME("Unexpected param type %u.\n", param->type);
2692 return D3DERR_INVALIDCALL;
2694 if (param->bytes % const_tbl[op].elem_size != 0)
2696 FIXME("Unexpected param size %u, rows %u, cols %u.\n", param->bytes, param->rows, param->columns);
2697 return D3DERR_INVALIDCALL;
2700 switch (op)
2702 case SCT_VSFLOAT:
2703 return IDirect3DDevice9_SetVertexShaderConstantF(device, index, (const float *)value_ptr, element_count);
2704 case SCT_VSBOOL:
2705 return IDirect3DDevice9_SetVertexShaderConstantB(device, index, (const BOOL *)value_ptr, element_count);
2706 case SCT_VSINT:
2707 return IDirect3DDevice9_SetVertexShaderConstantI(device, index, (const int *)value_ptr, element_count);
2708 case SCT_PSFLOAT:
2709 return IDirect3DDevice9_SetPixelShaderConstantF(device, index, (const float *)value_ptr, element_count);
2710 case SCT_PSBOOL:
2711 return IDirect3DDevice9_SetPixelShaderConstantB(device, index, (const BOOL *)value_ptr, element_count);
2712 case SCT_PSINT:
2713 return IDirect3DDevice9_SetPixelShaderConstantI(device, index, (const int *)value_ptr, element_count);
2715 return D3D_OK;
2718 static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2719 struct d3dx_state *state, unsigned int parent_index);
2721 static HRESULT d3dx_set_shader_constants(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2722 struct d3dx_parameter *param, BOOL vs)
2724 IDirect3DDevice9 *device = effect->device;
2725 HRESULT hr, ret;
2726 struct d3dx_parameter **params;
2727 D3DXCONSTANT_DESC *cdesc;
2728 unsigned int parameters_count;
2729 unsigned int i, j;
2731 if (!param->param_eval)
2733 FIXME("param_eval structure is null.\n");
2734 return D3DERR_INVALIDCALL;
2736 if (FAILED(hr = d3dx_param_eval_set_shader_constants(device, param->param_eval)))
2737 return hr;
2738 params = param->param_eval->shader_inputs.inputs_param;
2739 cdesc = param->param_eval->shader_inputs.inputs;
2740 parameters_count = param->param_eval->shader_inputs.input_count;
2741 ret = D3D_OK;
2742 for (i = 0; i < parameters_count; ++i)
2744 if (params[i] && params[i]->class == D3DXPC_OBJECT && is_param_type_sampler(params[i]->type))
2746 struct d3dx_sampler *sampler;
2748 sampler = (struct d3dx_sampler *)params[i]->data;
2749 TRACE("sampler %s, register index %u, state count %u.\n", debugstr_a(params[i]->name),
2750 cdesc[i].RegisterIndex, sampler->state_count);
2751 for (j = 0; j < sampler->state_count; ++j)
2753 if (FAILED(hr = d3dx9_apply_state(effect, pass, &sampler->states[j],
2754 cdesc[i].RegisterIndex + (vs ? D3DVERTEXTEXTURESAMPLER0 : 0))))
2755 ret = hr;
2759 return ret;
2762 static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2763 struct d3dx_state *state, unsigned int parent_index)
2765 IDirect3DDevice9 *device = effect->device;
2766 struct d3dx_parameter *param;
2767 void *param_value;
2768 HRESULT hr;
2770 TRACE("operation %u, index %u, type %u.\n", state->operation, state->index, state->type);
2771 if (FAILED(hr = d3dx9_get_param_value_ptr(effect, pass, state, &param_value, &param)))
2772 /* Native d3dx returns D3D_OK from BeginPass or Commit involving out of bounds array
2773 * access and does not touch affected state. */
2774 return D3D_OK;
2776 switch (state_table[state->operation].class)
2778 case SC_RENDERSTATE:
2779 TRACE("%s, operation %u, value %u.\n", state_table[state->operation].name,
2780 state_table[state->operation].op, *(DWORD *)param_value);
2781 return IDirect3DDevice9_SetRenderState(device, state_table[state->operation].op, *(DWORD *)param_value);
2782 case SC_FVF:
2783 TRACE("%s, value %#x.\n", state_table[state->operation].name, *(DWORD *)param_value);
2784 return IDirect3DDevice9_SetFVF(device, *(DWORD *)param_value);
2785 case SC_TEXTURE:
2787 UINT unit;
2789 unit = parent_index == ~0u ? state->index : parent_index;
2790 TRACE("%s, unit %u, value %p.\n", state_table[state->operation].name, unit,
2791 *(IDirect3DBaseTexture9 **)param_value);
2792 return IDirect3DDevice9_SetTexture(device, unit, *(IDirect3DBaseTexture9 **)param_value);
2794 case SC_TEXTURESTAGE:
2795 TRACE("%s, stage %u, value %u.\n", state_table[state->operation].name, state->index, *(DWORD *)param_value);
2796 return IDirect3DDevice9_SetTextureStageState(device, state->index,
2797 state_table[state->operation].op, *(DWORD *)param_value);
2798 case SC_SETSAMPLER:
2800 struct d3dx_sampler *sampler;
2801 HRESULT ret, hr;
2802 unsigned int i;
2804 sampler = (struct d3dx_sampler *)param_value;
2805 TRACE("%s, sampler %u, applying %u states.\n", state_table[state->operation].name, state->index,
2806 sampler->state_count);
2807 ret = D3D_OK;
2808 for (i = 0; i < sampler->state_count; i++)
2810 if (FAILED(hr = d3dx9_apply_state(effect, pass, &sampler->states[i], state->index)))
2811 ret = hr;
2813 return ret;
2815 case SC_SAMPLERSTATE:
2817 UINT sampler;
2819 sampler = parent_index == ~0u ? state->index : parent_index;
2820 TRACE("%s, sampler %u, value %u.\n", state_table[state->operation].name, sampler, *(DWORD *)param_value);
2821 return IDirect3DDevice9_SetSamplerState(device, sampler, state_table[state->operation].op,
2822 *(DWORD *)param_value);
2824 case SC_VERTEXSHADER:
2825 TRACE("%s, shader %p.\n", state_table[state->operation].name, *(IDirect3DVertexShader9 **)param_value);
2826 if (FAILED(hr = IDirect3DDevice9_SetVertexShader(device, *(IDirect3DVertexShader9 **)param_value)))
2827 ERR("Could not set vertex shader, hr %#x.\n", hr);
2828 else if (*(IDirect3DVertexShader9 **)param_value)
2829 hr = d3dx_set_shader_constants(effect, pass, param, TRUE);
2830 return hr;
2831 case SC_PIXELSHADER:
2832 TRACE("%s, shader %p.\n", state_table[state->operation].name, *(IDirect3DPixelShader9 **)param_value);
2833 if (FAILED(hr = IDirect3DDevice9_SetPixelShader(device, *(IDirect3DPixelShader9 **)param_value)))
2834 ERR("Could not set pixel shader, hr %#x.\n", hr);
2835 else if (*(IDirect3DPixelShader9 **)param_value)
2836 hr = d3dx_set_shader_constants(effect, pass, param, FALSE);
2837 return hr;
2838 case SC_TRANSFORM:
2839 TRACE("%s, state %u.\n", state_table[state->operation].name, state->index);
2840 return IDirect3DDevice9_SetTransform(device, state_table[state->operation].op + state->index,
2841 (D3DMATRIX *)param_value);
2842 case SC_LIGHTENABLE:
2843 TRACE("%s, index %u, value %u.\n", state_table[state->operation].name, state->index, *(BOOL *)param_value);
2844 return IDirect3DDevice9_LightEnable(device, state->index, *(BOOL *)param_value);
2845 case SC_LIGHT:
2847 D3DLIGHT9 light;
2849 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
2850 state_table[state->operation].op);
2851 if (FAILED(hr = IDirect3DDevice9_GetLight(device, state->index, &light)))
2853 WARN("Could not get light, hr %#x.\n", hr);
2854 memset(&light, 0, sizeof(light));
2856 d3dx9_set_light_parameter(state_table[state->operation].op, &light, param_value);
2857 return IDirect3DDevice9_SetLight(device, state->index, &light);
2859 case SC_MATERIAL:
2861 D3DMATERIAL9 material;
2863 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
2864 state_table[state->operation].op);
2865 if (FAILED(hr = IDirect3DDevice9_GetMaterial(device, &material)))
2867 WARN("Could not get material, hr %#x.\n", hr);
2868 memset(&material, 0, sizeof(material));
2870 d3dx9_set_material_parameter(state_table[state->operation].op, &material, param_value);
2871 return IDirect3DDevice9_SetMaterial(device, &material);
2873 case SC_NPATCHMODE:
2874 TRACE("%s, nsegments %f.\n", state_table[state->operation].name, *(float *)param_value);
2875 return IDirect3DDevice9_SetNPatchMode(device, *(float *)param_value);
2876 case SC_SHADERCONST:
2877 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
2878 state_table[state->operation].op);
2879 return d3dx_set_shader_const_state(device, state_table[state->operation].op, state->index,
2880 param, param_value);
2881 default:
2882 FIXME("%s not handled.\n", state_table[state->operation].name);
2883 break;
2885 return D3D_OK;
2888 static HRESULT d3dx9_apply_pass_states(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass)
2890 unsigned int i;
2891 HRESULT ret;
2893 TRACE("effect %p, pass %p, state_count %u.\n", effect, pass, pass->state_count);
2895 ret = D3D_OK;
2896 for (i = 0; i < pass->state_count; i++)
2898 HRESULT hr;
2900 if (FAILED(hr = d3dx9_apply_state(effect, pass, &pass->states[i], ~0u)))
2902 WARN("Error applying state, hr %#x.\n", hr);
2903 ret = hr;
2906 return ret;
2909 static inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
2911 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
2914 /*** IUnknown methods ***/
2915 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
2917 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
2919 if (IsEqualGUID(riid, &IID_IUnknown) ||
2920 IsEqualGUID(riid, &IID_ID3DXEffect))
2922 iface->lpVtbl->AddRef(iface);
2923 *object = iface;
2924 return S_OK;
2927 ERR("Interface %s not found\n", debugstr_guid(riid));
2929 return E_NOINTERFACE;
2932 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
2934 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2936 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
2938 return InterlockedIncrement(&This->ref);
2941 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
2943 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2944 ULONG ref = InterlockedDecrement(&This->ref);
2946 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
2948 if (!ref)
2950 free_effect(This);
2951 HeapFree(GetProcessHeap(), 0, This);
2954 return ref;
2957 /*** ID3DXBaseEffect methods ***/
2958 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
2960 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2962 TRACE("iface %p, desc %p.\n", iface, desc);
2964 return d3dx9_base_effect_get_desc(&effect->base_effect, desc);
2967 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface,
2968 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
2970 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2972 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
2974 return d3dx9_base_effect_get_parameter_desc(&effect->base_effect, parameter, desc);
2977 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface,
2978 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
2980 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2982 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
2984 return d3dx9_base_effect_get_technique_desc(&effect->base_effect, technique, desc);
2987 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
2989 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2991 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
2993 return d3dx9_base_effect_get_pass_desc(&effect->base_effect, pass, desc);
2996 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
2998 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3000 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
3002 return d3dx9_base_effect_get_function_desc(&effect->base_effect, shader, desc);
3005 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
3007 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3009 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3011 return d3dx9_base_effect_get_parameter(&effect->base_effect, parameter, index);
3014 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface,
3015 D3DXHANDLE parameter, const char *name)
3017 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3019 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
3021 return d3dx9_base_effect_get_parameter_by_name(&effect->base_effect, parameter, name);
3024 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface,
3025 D3DXHANDLE parameter, const char *semantic)
3027 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3029 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
3031 return d3dx9_base_effect_get_parameter_by_semantic(&effect->base_effect, parameter, semantic);
3034 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
3036 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3038 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3040 return d3dx9_base_effect_get_parameter_element(&effect->base_effect, parameter, index);
3043 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
3045 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3047 TRACE("iface %p, index %u.\n", iface, index);
3049 return d3dx9_base_effect_get_technique(&effect->base_effect, index);
3052 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, const char *name)
3054 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3056 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3058 return d3dx9_base_effect_get_technique_by_name(&effect->base_effect, name);
3061 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
3063 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3065 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
3067 return d3dx9_base_effect_get_pass(&effect->base_effect, technique, index);
3070 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface,
3071 D3DXHANDLE technique, const char *name)
3073 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3075 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
3077 return d3dx9_base_effect_get_pass_by_name(&effect->base_effect, technique, name);
3080 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
3082 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3084 TRACE("iface %p, index %u.\n", iface, index);
3086 return d3dx9_base_effect_get_function(&effect->base_effect, index);
3089 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, const char *name)
3091 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3093 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3095 return d3dx9_base_effect_get_function_by_name(&effect->base_effect, name);
3098 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
3100 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3102 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
3104 return d3dx9_base_effect_get_annotation(&effect->base_effect, object, index);
3107 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface,
3108 D3DXHANDLE object, const char *name)
3110 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3112 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
3114 return d3dx9_base_effect_get_annotation_by_name(&effect->base_effect, object, name);
3117 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface,
3118 D3DXHANDLE parameter, const void *data, UINT bytes)
3120 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3122 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3124 return d3dx9_base_effect_set_value(&effect->base_effect, parameter, data, bytes);
3127 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface,
3128 D3DXHANDLE parameter, void *data, UINT bytes)
3130 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3132 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3134 return d3dx9_base_effect_get_value(&effect->base_effect, parameter, data, bytes);
3137 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
3139 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3141 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
3143 return d3dx9_base_effect_set_bool(&effect->base_effect, parameter, b);
3146 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
3148 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3150 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
3152 return d3dx9_base_effect_get_bool(&effect->base_effect, parameter, b);
3155 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface,
3156 D3DXHANDLE parameter, const BOOL *b, UINT count)
3158 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3160 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3162 return d3dx9_base_effect_set_bool_array(&effect->base_effect, parameter, b, count);
3165 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface,
3166 D3DXHANDLE parameter, BOOL *b, UINT count)
3168 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3170 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3172 return d3dx9_base_effect_get_bool_array(&effect->base_effect, parameter, b, count);
3175 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
3177 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3179 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
3181 return d3dx9_base_effect_set_int(&effect->base_effect, parameter, n);
3184 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
3186 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3188 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
3190 return d3dx9_base_effect_get_int(&effect->base_effect, parameter, n);
3193 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface,
3194 D3DXHANDLE parameter, const INT *n, UINT count)
3196 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3198 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3200 return d3dx9_base_effect_set_int_array(&effect->base_effect, parameter, n, count);
3203 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface,
3204 D3DXHANDLE parameter, INT *n, UINT count)
3206 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3208 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3210 return d3dx9_base_effect_get_int_array(&effect->base_effect, parameter, n, count);
3213 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float f)
3215 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3217 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
3219 return d3dx9_base_effect_set_float(&effect->base_effect, parameter, f);
3222 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float *f)
3224 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3226 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
3228 return d3dx9_base_effect_get_float(&effect->base_effect, parameter, f);
3231 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface,
3232 D3DXHANDLE parameter, const float *f, UINT count)
3234 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3236 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3238 return d3dx9_base_effect_set_float_array(&effect->base_effect, parameter, f, count);
3241 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface,
3242 D3DXHANDLE parameter, float *f, UINT count)
3244 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3246 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3248 return d3dx9_base_effect_get_float_array(&effect->base_effect, parameter, f, count);
3251 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface,
3252 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
3254 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3256 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3258 return d3dx9_base_effect_set_vector(&effect->base_effect, parameter, vector);
3261 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface,
3262 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
3264 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3266 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3268 return d3dx9_base_effect_get_vector(&effect->base_effect, parameter, vector);
3271 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface,
3272 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
3274 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3276 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3278 return d3dx9_base_effect_set_vector_array(&effect->base_effect, parameter, vector, count);
3281 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface,
3282 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
3284 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3286 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3288 return d3dx9_base_effect_get_vector_array(&effect->base_effect, parameter, vector, count);
3291 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface,
3292 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3294 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3296 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3298 return d3dx9_base_effect_set_matrix(&effect->base_effect, parameter, matrix);
3301 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface,
3302 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3304 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3306 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3308 return d3dx9_base_effect_get_matrix(&effect->base_effect, parameter, matrix);
3311 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface,
3312 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3314 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3316 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3318 return d3dx9_base_effect_set_matrix_array(&effect->base_effect, parameter, matrix, count);
3321 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface,
3322 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3324 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3326 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3328 return d3dx9_base_effect_get_matrix_array(&effect->base_effect, parameter, matrix, count);
3331 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface,
3332 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3334 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3336 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3338 return d3dx9_base_effect_set_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
3341 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface,
3342 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3344 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3346 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3348 return d3dx9_base_effect_get_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
3351 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface,
3352 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3354 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3356 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3358 return d3dx9_base_effect_set_matrix_transpose(&effect->base_effect, parameter, matrix);
3361 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface,
3362 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3364 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3366 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3368 return d3dx9_base_effect_get_matrix_transpose(&effect->base_effect, parameter, matrix);
3371 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface,
3372 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3374 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3376 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3378 return d3dx9_base_effect_set_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
3381 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface,
3382 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3384 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3386 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3388 return d3dx9_base_effect_get_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
3391 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface,
3392 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3394 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3396 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3398 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
3401 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface,
3402 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3404 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3406 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3408 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
3411 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char *string)
3413 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3415 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
3417 return d3dx9_base_effect_set_string(&effect->base_effect, parameter, string);
3420 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char **string)
3422 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3424 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
3426 return d3dx9_base_effect_get_string(&effect->base_effect, parameter, string);
3429 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(struct ID3DXEffect *iface,
3430 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
3432 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3434 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3436 return d3dx9_base_effect_set_texture(&effect->base_effect, parameter, texture);
3439 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(struct ID3DXEffect *iface,
3440 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
3442 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3444 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3446 return d3dx9_base_effect_get_texture(&effect->base_effect, parameter, texture);
3449 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface,
3450 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
3452 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3454 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3456 return d3dx9_base_effect_get_pixel_shader(&effect->base_effect, parameter, shader);
3459 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(struct ID3DXEffect *iface,
3460 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
3462 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3464 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3466 return d3dx9_base_effect_get_vertex_shader(&effect->base_effect, parameter, shader);
3469 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3471 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3473 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
3475 return d3dx9_base_effect_set_array_range(&effect->base_effect, parameter, start, end);
3478 /*** ID3DXEffect methods ***/
3479 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, ID3DXEffectPool **pool)
3481 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3483 TRACE("iface %p, pool %p\n", This, pool);
3485 if (!pool)
3487 WARN("Invalid argument supplied.\n");
3488 return D3DERR_INVALIDCALL;
3491 if (This->pool)
3493 This->pool->lpVtbl->AddRef(This->pool);
3496 *pool = This->pool;
3498 TRACE("Returning pool %p\n", *pool);
3500 return S_OK;
3503 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3505 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3506 struct d3dx9_base_effect *base = &This->base_effect;
3507 struct d3dx_technique *tech = get_valid_technique(base, technique);
3509 TRACE("iface %p, technique %p\n", This, technique);
3511 if (tech)
3513 This->active_technique = tech;
3514 TRACE("Technique %p\n", tech);
3515 return D3D_OK;
3518 WARN("Technique not found.\n");
3520 return D3DERR_INVALIDCALL;
3523 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3525 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3527 TRACE("iface %p\n", This);
3529 return get_technique_handle(This->active_technique);
3532 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3534 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3536 FIXME("(%p)->(%p): stub\n", This, technique);
3538 return D3D_OK;
3541 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3543 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3545 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3547 return E_NOTIMPL;
3550 static BOOL walk_parameter_dep(struct d3dx_parameter *param, walk_parameter_dep_func param_func,
3551 void *data);
3553 static BOOL walk_param_eval_dep(struct d3dx_param_eval *param_eval, walk_parameter_dep_func param_func,
3554 void *data)
3556 struct d3dx_parameter **params;
3557 unsigned int i, param_count;
3559 if (!param_eval)
3560 return FALSE;
3562 params = param_eval->shader_inputs.inputs_param;
3563 param_count = param_eval->shader_inputs.input_count;
3564 for (i = 0; i < param_count; ++i)
3566 if (walk_parameter_dep(params[i], param_func, data))
3567 return TRUE;
3570 params = param_eval->pres.inputs.inputs_param;
3571 param_count = param_eval->pres.inputs.input_count;
3572 for (i = 0; i < param_count; ++i)
3574 if (walk_parameter_dep(params[i], param_func, data))
3575 return TRUE;
3577 return FALSE;
3580 static BOOL walk_state_dep(struct d3dx_state *state, walk_parameter_dep_func param_func,
3581 void *data)
3583 if (state->type == ST_CONSTANT && is_param_type_sampler(state->parameter.type))
3585 if (walk_parameter_dep(&state->parameter, param_func, data))
3586 return TRUE;
3588 else if (state->type == ST_ARRAY_SELECTOR || state->type == ST_PARAMETER)
3590 if (walk_parameter_dep(state->parameter.referenced_param, param_func, data))
3591 return TRUE;
3593 return walk_param_eval_dep(state->parameter.param_eval, param_func, data);
3596 static BOOL walk_parameter_dep(struct d3dx_parameter *param, walk_parameter_dep_func param_func,
3597 void *data)
3599 unsigned int i;
3600 unsigned int member_count;
3602 if (param_func(data, param))
3603 return TRUE;
3605 if (walk_param_eval_dep(param->param_eval, param_func, data))
3606 return TRUE;
3608 if (param->class == D3DXPC_OBJECT && is_param_type_sampler(param->type))
3610 struct d3dx_sampler *sampler;
3612 sampler = (struct d3dx_sampler *)param->data;
3613 for (i = 0; i < sampler->state_count; ++i)
3615 if (walk_state_dep(&sampler->states[i], param_func, data))
3616 return TRUE;
3618 return FALSE;
3621 member_count = param->element_count ? param->element_count : param->member_count;
3622 for (i = 0; i < member_count; ++i)
3624 if (walk_param_eval_dep(param->members[i].param_eval, param_func, data))
3625 return TRUE;
3628 return FALSE;
3631 static BOOL compare_param_ptr(void *param_comp, struct d3dx_parameter *param)
3633 return param_comp == param;
3636 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
3638 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3639 unsigned int i, j;
3640 struct d3dx_parameter *param = get_valid_parameter(&effect->base_effect, parameter);
3641 struct d3dx_technique *tech = get_valid_technique(&effect->base_effect, technique);
3642 struct d3dx_pass *pass;
3644 TRACE("iface %p, parameter %p, technique %p.\n", iface, parameter, technique);
3645 TRACE("param %p, name %s, tech %p.\n", param, param ? debugstr_a(param->name) : "", tech);
3646 if (!tech || !param)
3647 return FALSE;
3649 for (i = 0; i < tech->pass_count; ++i)
3651 pass = &tech->passes[i];
3652 for (j = 0; j < pass->state_count; ++j)
3654 if (walk_state_dep(&pass->states[j], compare_param_ptr, param))
3656 TRACE("Returning TRUE.\n");
3657 return TRUE;
3661 TRACE("Returning FALSE.\n");
3662 return FALSE;
3665 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
3667 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3668 struct d3dx_technique *technique = effect->active_technique;
3670 TRACE("iface %p, passes %p, flags %#x.\n", iface, passes, flags);
3672 if (passes && technique)
3674 if (flags & ~(D3DXFX_DONOTSAVESTATE | D3DXFX_DONOTSAVESAMPLERSTATE | D3DXFX_DONOTSAVESHADERSTATE))
3675 WARN("Invalid flags (%#x) specified.\n", flags);
3677 if (effect->manager || flags & D3DXFX_DONOTSAVESTATE)
3679 TRACE("State capturing disabled.\n");
3681 else
3683 HRESULT hr;
3684 unsigned int i;
3686 if (!technique->saved_state)
3688 if (FAILED(hr = IDirect3DDevice9_BeginStateBlock(effect->device)))
3689 ERR("BeginStateBlock failed, hr %#x.\n", hr);
3690 for (i = 0; i < technique->pass_count; i++)
3691 d3dx9_apply_pass_states(effect, &technique->passes[i]);
3692 if (FAILED(hr = IDirect3DDevice9_EndStateBlock(effect->device, &technique->saved_state)))
3693 ERR("EndStateBlock failed, hr %#x.\n", hr);
3695 if (FAILED(hr = IDirect3DStateBlock9_Capture(technique->saved_state)))
3696 ERR("StateBlock Capture failed, hr %#x.\n", hr);
3699 *passes = technique->pass_count;
3700 effect->started = TRUE;
3701 effect->flags = flags;
3703 return D3D_OK;
3706 WARN("Invalid argument supplied.\n");
3708 return D3DERR_INVALIDCALL;
3711 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
3713 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3714 struct d3dx_technique *technique = effect->active_technique;
3716 TRACE("iface %p, pass %u\n", effect, pass);
3718 if (technique && pass < technique->pass_count && !effect->active_pass)
3720 effect->active_pass = &technique->passes[pass];
3721 return d3dx9_apply_pass_states(effect, effect->active_pass);
3724 WARN("Invalid argument supplied.\n");
3726 return D3DERR_INVALIDCALL;
3729 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect *iface)
3731 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3733 TRACE("iface %p.\n", iface);
3735 if (!effect->active_pass)
3737 WARN("Called without an active pass.\n");
3738 return D3D_OK;
3740 /* TODO: apply only changed states */
3741 return d3dx9_apply_pass_states(effect, effect->active_pass);
3744 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
3746 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3748 TRACE("iface %p\n", This);
3750 if (This->active_pass)
3752 This->active_pass = NULL;
3753 return D3D_OK;
3756 WARN("Invalid call.\n");
3758 return D3DERR_INVALIDCALL;
3761 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect *iface)
3763 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3764 struct d3dx_technique *technique = effect->active_technique;
3766 TRACE("iface %p.\n", iface);
3768 if (!effect->started)
3769 return D3D_OK;
3771 if (effect->manager || effect->flags & D3DXFX_DONOTSAVESTATE)
3773 TRACE("State restoring disabled.\n");
3775 else
3777 HRESULT hr;
3779 if (technique && technique->saved_state)
3781 if (FAILED(hr = IDirect3DStateBlock9_Apply(technique->saved_state)))
3782 ERR("State block apply failed, hr %#x.\n", hr);
3784 else
3785 ERR("No saved state.\n");
3788 effect->started = FALSE;
3790 return D3D_OK;
3793 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, struct IDirect3DDevice9 **device)
3795 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3797 TRACE("iface %p, device %p\n", This, device);
3799 if (!device)
3801 WARN("Invalid argument supplied.\n");
3802 return D3DERR_INVALIDCALL;
3805 IDirect3DDevice9_AddRef(This->device);
3807 *device = This->device;
3809 TRACE("Returning device %p\n", *device);
3811 return S_OK;
3814 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
3816 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3818 FIXME("(%p)->(): stub\n", This);
3820 return E_NOTIMPL;
3823 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(ID3DXEffect* iface)
3825 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3827 FIXME("(%p)->(): stub\n", This);
3829 return E_NOTIMPL;
3832 static HRESULT WINAPI ID3DXEffectImpl_SetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager *manager)
3834 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3836 TRACE("iface %p, manager %p\n", This, manager);
3838 if (manager) IUnknown_AddRef(manager);
3839 if (This->manager) IUnknown_Release(This->manager);
3841 This->manager = manager;
3843 return D3D_OK;
3846 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager **manager)
3848 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3850 TRACE("iface %p, manager %p\n", This, manager);
3852 if (!manager)
3854 WARN("Invalid argument supplied.\n");
3855 return D3DERR_INVALIDCALL;
3858 if (This->manager) IUnknown_AddRef(This->manager);
3859 *manager = This->manager;
3861 return D3D_OK;
3864 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
3866 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3868 FIXME("(%p)->(): stub\n", This);
3870 return E_NOTIMPL;
3873 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
3875 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3877 FIXME("(%p)->(): stub\n", This);
3879 return NULL;
3882 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3884 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3886 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3888 return E_NOTIMPL;
3891 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3893 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3895 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3897 return E_NOTIMPL;
3900 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect *iface,
3901 struct IDirect3DDevice9 *device, struct ID3DXEffect **effect)
3903 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3905 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
3907 return E_NOTIMPL;
3910 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect *iface,
3911 D3DXHANDLE parameter, const void *data, UINT byte_offset, UINT bytes)
3913 FIXME("iface %p, parameter %p, data %p, byte_offset %u, bytes %u stub!\n",
3914 iface, parameter, data, byte_offset, bytes);
3916 return E_NOTIMPL;
3919 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
3921 /*** IUnknown methods ***/
3922 ID3DXEffectImpl_QueryInterface,
3923 ID3DXEffectImpl_AddRef,
3924 ID3DXEffectImpl_Release,
3925 /*** ID3DXBaseEffect methods ***/
3926 ID3DXEffectImpl_GetDesc,
3927 ID3DXEffectImpl_GetParameterDesc,
3928 ID3DXEffectImpl_GetTechniqueDesc,
3929 ID3DXEffectImpl_GetPassDesc,
3930 ID3DXEffectImpl_GetFunctionDesc,
3931 ID3DXEffectImpl_GetParameter,
3932 ID3DXEffectImpl_GetParameterByName,
3933 ID3DXEffectImpl_GetParameterBySemantic,
3934 ID3DXEffectImpl_GetParameterElement,
3935 ID3DXEffectImpl_GetTechnique,
3936 ID3DXEffectImpl_GetTechniqueByName,
3937 ID3DXEffectImpl_GetPass,
3938 ID3DXEffectImpl_GetPassByName,
3939 ID3DXEffectImpl_GetFunction,
3940 ID3DXEffectImpl_GetFunctionByName,
3941 ID3DXEffectImpl_GetAnnotation,
3942 ID3DXEffectImpl_GetAnnotationByName,
3943 ID3DXEffectImpl_SetValue,
3944 ID3DXEffectImpl_GetValue,
3945 ID3DXEffectImpl_SetBool,
3946 ID3DXEffectImpl_GetBool,
3947 ID3DXEffectImpl_SetBoolArray,
3948 ID3DXEffectImpl_GetBoolArray,
3949 ID3DXEffectImpl_SetInt,
3950 ID3DXEffectImpl_GetInt,
3951 ID3DXEffectImpl_SetIntArray,
3952 ID3DXEffectImpl_GetIntArray,
3953 ID3DXEffectImpl_SetFloat,
3954 ID3DXEffectImpl_GetFloat,
3955 ID3DXEffectImpl_SetFloatArray,
3956 ID3DXEffectImpl_GetFloatArray,
3957 ID3DXEffectImpl_SetVector,
3958 ID3DXEffectImpl_GetVector,
3959 ID3DXEffectImpl_SetVectorArray,
3960 ID3DXEffectImpl_GetVectorArray,
3961 ID3DXEffectImpl_SetMatrix,
3962 ID3DXEffectImpl_GetMatrix,
3963 ID3DXEffectImpl_SetMatrixArray,
3964 ID3DXEffectImpl_GetMatrixArray,
3965 ID3DXEffectImpl_SetMatrixPointerArray,
3966 ID3DXEffectImpl_GetMatrixPointerArray,
3967 ID3DXEffectImpl_SetMatrixTranspose,
3968 ID3DXEffectImpl_GetMatrixTranspose,
3969 ID3DXEffectImpl_SetMatrixTransposeArray,
3970 ID3DXEffectImpl_GetMatrixTransposeArray,
3971 ID3DXEffectImpl_SetMatrixTransposePointerArray,
3972 ID3DXEffectImpl_GetMatrixTransposePointerArray,
3973 ID3DXEffectImpl_SetString,
3974 ID3DXEffectImpl_GetString,
3975 ID3DXEffectImpl_SetTexture,
3976 ID3DXEffectImpl_GetTexture,
3977 ID3DXEffectImpl_GetPixelShader,
3978 ID3DXEffectImpl_GetVertexShader,
3979 ID3DXEffectImpl_SetArrayRange,
3980 /*** ID3DXEffect methods ***/
3981 ID3DXEffectImpl_GetPool,
3982 ID3DXEffectImpl_SetTechnique,
3983 ID3DXEffectImpl_GetCurrentTechnique,
3984 ID3DXEffectImpl_ValidateTechnique,
3985 ID3DXEffectImpl_FindNextValidTechnique,
3986 ID3DXEffectImpl_IsParameterUsed,
3987 ID3DXEffectImpl_Begin,
3988 ID3DXEffectImpl_BeginPass,
3989 ID3DXEffectImpl_CommitChanges,
3990 ID3DXEffectImpl_EndPass,
3991 ID3DXEffectImpl_End,
3992 ID3DXEffectImpl_GetDevice,
3993 ID3DXEffectImpl_OnLostDevice,
3994 ID3DXEffectImpl_OnResetDevice,
3995 ID3DXEffectImpl_SetStateManager,
3996 ID3DXEffectImpl_GetStateManager,
3997 ID3DXEffectImpl_BeginParameterBlock,
3998 ID3DXEffectImpl_EndParameterBlock,
3999 ID3DXEffectImpl_ApplyParameterBlock,
4000 ID3DXEffectImpl_DeleteParameterBlock,
4001 ID3DXEffectImpl_CloneEffect,
4002 ID3DXEffectImpl_SetRawValue
4005 static inline struct ID3DXEffectCompilerImpl *impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler *iface)
4007 return CONTAINING_RECORD(iface, struct ID3DXEffectCompilerImpl, ID3DXEffectCompiler_iface);
4010 /*** IUnknown methods ***/
4011 static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler *iface, REFIID riid, void **object)
4013 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
4015 if (IsEqualGUID(riid, &IID_IUnknown) ||
4016 IsEqualGUID(riid, &IID_ID3DXEffectCompiler))
4018 iface->lpVtbl->AddRef(iface);
4019 *object = iface;
4020 return S_OK;
4023 ERR("Interface %s not found\n", debugstr_guid(riid));
4025 return E_NOINTERFACE;
4028 static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface)
4030 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4032 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
4034 return InterlockedIncrement(&This->ref);
4037 static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface)
4039 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4040 ULONG ref = InterlockedDecrement(&This->ref);
4042 TRACE("iface %p: Release from %u\n", iface, ref + 1);
4044 if (!ref)
4046 free_effect_compiler(This);
4047 HeapFree(GetProcessHeap(), 0, This);
4050 return ref;
4053 /*** ID3DXBaseEffect methods ***/
4054 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler *iface, D3DXEFFECT_DESC *desc)
4056 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4058 TRACE("iface %p, desc %p.\n", iface, desc);
4060 return d3dx9_base_effect_get_desc(&compiler->base_effect, desc);
4063 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler *iface,
4064 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
4066 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4068 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
4070 return d3dx9_base_effect_get_parameter_desc(&compiler->base_effect, parameter, desc);
4073 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler *iface,
4074 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
4076 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4078 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
4080 return d3dx9_base_effect_get_technique_desc(&compiler->base_effect, technique, desc);
4083 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler *iface,
4084 D3DXHANDLE pass, D3DXPASS_DESC *desc)
4086 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4088 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
4090 return d3dx9_base_effect_get_pass_desc(&compiler->base_effect, pass, desc);
4093 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler *iface,
4094 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
4096 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4098 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
4100 return d3dx9_base_effect_get_function_desc(&compiler->base_effect, shader, desc);
4103 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler *iface,
4104 D3DXHANDLE parameter, UINT index)
4106 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4108 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
4110 return d3dx9_base_effect_get_parameter(&compiler->base_effect, parameter, index);
4113 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler *iface,
4114 D3DXHANDLE parameter, const char *name)
4116 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4118 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
4120 return d3dx9_base_effect_get_parameter_by_name(&compiler->base_effect, parameter, name);
4123 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler *iface,
4124 D3DXHANDLE parameter, const char *semantic)
4126 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4128 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
4130 return d3dx9_base_effect_get_parameter_by_semantic(&compiler->base_effect, parameter, semantic);
4133 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler *iface,
4134 D3DXHANDLE parameter, UINT index)
4136 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4138 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
4140 return d3dx9_base_effect_get_parameter_element(&compiler->base_effect, parameter, index);
4143 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler *iface, UINT index)
4145 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4147 TRACE("iface %p, index %u.\n", iface, index);
4149 return d3dx9_base_effect_get_technique(&compiler->base_effect, index);
4152 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler *iface, const char *name)
4154 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4156 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4158 return d3dx9_base_effect_get_technique_by_name(&compiler->base_effect, name);
4161 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler *iface, D3DXHANDLE technique, UINT index)
4163 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4165 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
4167 return d3dx9_base_effect_get_pass(&compiler->base_effect, technique, index);
4170 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler *iface,
4171 D3DXHANDLE technique, const char *name)
4173 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4175 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
4177 return d3dx9_base_effect_get_pass_by_name(&compiler->base_effect, technique, name);
4180 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler *iface, UINT index)
4182 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4184 TRACE("iface %p, index %u.\n", iface, index);
4186 return d3dx9_base_effect_get_function(&compiler->base_effect, index);
4189 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler *iface, const char *name)
4191 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4193 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4195 return d3dx9_base_effect_get_function_by_name(&compiler->base_effect, name);
4198 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler *iface,
4199 D3DXHANDLE object, UINT index)
4201 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4203 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
4205 return d3dx9_base_effect_get_annotation(&compiler->base_effect, object, index);
4208 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler *iface,
4209 D3DXHANDLE object, const char *name)
4211 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4213 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
4215 return d3dx9_base_effect_get_annotation_by_name(&compiler->base_effect, object, name);
4218 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler *iface,
4219 D3DXHANDLE parameter, const void *data, UINT bytes)
4221 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4223 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
4225 return d3dx9_base_effect_set_value(&compiler->base_effect, parameter, data, bytes);
4228 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler *iface,
4229 D3DXHANDLE parameter, void *data, UINT bytes)
4231 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4233 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
4235 return d3dx9_base_effect_get_value(&compiler->base_effect, parameter, data, bytes);
4238 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL b)
4240 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4242 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
4244 return d3dx9_base_effect_set_bool(&compiler->base_effect, parameter, b);
4247 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b)
4249 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4251 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
4253 return d3dx9_base_effect_get_bool(&compiler->base_effect, parameter, b);
4256 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler *iface,
4257 D3DXHANDLE parameter, const BOOL *b, UINT count)
4259 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4261 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
4263 return d3dx9_base_effect_set_bool_array(&compiler->base_effect, parameter, b, count);
4266 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler *iface,
4267 D3DXHANDLE parameter, BOOL *b, UINT count)
4269 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4271 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
4273 return d3dx9_base_effect_get_bool_array(&compiler->base_effect, parameter, b, count);
4276 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT n)
4278 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4280 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
4282 return d3dx9_base_effect_set_int(&compiler->base_effect, parameter, n);
4285 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n)
4287 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4289 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
4291 return d3dx9_base_effect_get_int(&compiler->base_effect, parameter, n);
4294 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler *iface,
4295 D3DXHANDLE parameter, const INT *n, UINT count)
4297 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4299 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
4301 return d3dx9_base_effect_set_int_array(&compiler->base_effect, parameter, n, count);
4304 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler *iface,
4305 D3DXHANDLE parameter, INT *n, UINT count)
4307 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4309 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
4311 return d3dx9_base_effect_get_int_array(&compiler->base_effect, parameter, n, count);
4314 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float f)
4316 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4318 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
4320 return d3dx9_base_effect_set_float(&compiler->base_effect, parameter, f);
4323 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float *f)
4325 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4327 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
4329 return d3dx9_base_effect_get_float(&compiler->base_effect, parameter, f);
4332 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler *iface,
4333 D3DXHANDLE parameter, const float *f, UINT count)
4335 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4337 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
4339 return d3dx9_base_effect_set_float_array(&compiler->base_effect, parameter, f, count);
4342 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler *iface,
4343 D3DXHANDLE parameter, float *f, UINT count)
4345 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4347 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
4349 return d3dx9_base_effect_get_float_array(&compiler->base_effect, parameter, f, count);
4352 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler *iface,
4353 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
4355 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4357 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
4359 return d3dx9_base_effect_set_vector(&compiler->base_effect, parameter, vector);
4362 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler *iface,
4363 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
4365 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4367 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
4369 return d3dx9_base_effect_get_vector(&compiler->base_effect, parameter, vector);
4372 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler *iface,
4373 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
4375 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4377 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
4379 return d3dx9_base_effect_set_vector_array(&compiler->base_effect, parameter, vector, count);
4382 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler *iface,
4383 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
4385 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4387 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
4389 return d3dx9_base_effect_get_vector_array(&compiler->base_effect, parameter, vector, count);
4392 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler *iface,
4393 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
4395 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4397 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4399 return d3dx9_base_effect_set_matrix(&compiler->base_effect, parameter, matrix);
4402 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler *iface,
4403 D3DXHANDLE parameter, D3DXMATRIX *matrix)
4405 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4407 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4409 return d3dx9_base_effect_get_matrix(&compiler->base_effect, parameter, matrix);
4412 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler *iface,
4413 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
4415 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4417 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4419 return d3dx9_base_effect_set_matrix_array(&compiler->base_effect, parameter, matrix, count);
4422 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler *iface,
4423 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4425 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4427 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4429 return d3dx9_base_effect_get_matrix_array(&compiler->base_effect, parameter, matrix, count);
4432 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler *iface,
4433 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
4435 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4437 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4439 return d3dx9_base_effect_set_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
4442 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler *iface,
4443 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4445 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4447 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4449 return d3dx9_base_effect_get_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
4452 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler *iface,
4453 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
4455 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4457 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4459 return d3dx9_base_effect_set_matrix_transpose(&compiler->base_effect, parameter, matrix);
4462 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler *iface,
4463 D3DXHANDLE parameter, D3DXMATRIX *matrix)
4465 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4467 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4469 return d3dx9_base_effect_get_matrix_transpose(&compiler->base_effect, parameter, matrix);
4472 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler *iface,
4473 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
4475 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4477 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4479 return d3dx9_base_effect_set_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
4482 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler *iface,
4483 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4485 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4487 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4489 return d3dx9_base_effect_get_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
4492 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
4493 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
4495 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4497 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4499 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
4502 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
4503 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4505 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4507 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4509 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
4512 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler *iface,
4513 D3DXHANDLE parameter, const char *string)
4515 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4517 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
4519 return d3dx9_base_effect_set_string(&compiler->base_effect, parameter, string);
4522 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler *iface,
4523 D3DXHANDLE parameter, const char **string)
4525 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4527 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
4529 return d3dx9_base_effect_get_string(&compiler->base_effect, parameter, string);
4532 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetTexture(struct ID3DXEffectCompiler *iface,
4533 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
4535 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4537 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
4539 return d3dx9_base_effect_set_texture(&compiler->base_effect, parameter, texture);
4542 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTexture(struct ID3DXEffectCompiler *iface,
4543 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
4545 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4547 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
4549 return d3dx9_base_effect_get_texture(&compiler->base_effect, parameter, texture);
4552 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler *iface,
4553 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
4555 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4557 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4559 return d3dx9_base_effect_get_pixel_shader(&compiler->base_effect, parameter, shader);
4562 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVertexShader(struct ID3DXEffectCompiler *iface,
4563 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
4565 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4567 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4569 return d3dx9_base_effect_get_vertex_shader(&compiler->base_effect, parameter, shader);
4572 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler *iface,
4573 D3DXHANDLE parameter, UINT start, UINT end)
4575 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4577 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
4579 return d3dx9_base_effect_set_array_range(&compiler->base_effect, parameter, start, end);
4582 /*** ID3DXEffectCompiler methods ***/
4583 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL literal)
4585 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4587 FIXME("iface %p, parameter %p, literal %u\n", This, parameter, literal);
4589 return E_NOTIMPL;
4592 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *literal)
4594 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4596 FIXME("iface %p, parameter %p, literal %p\n", This, parameter, literal);
4598 return E_NOTIMPL;
4601 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler *iface, DWORD flags,
4602 ID3DXBuffer **effect, ID3DXBuffer **error_msgs)
4604 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4606 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub\n", This, flags, effect, error_msgs);
4608 return E_NOTIMPL;
4611 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler *iface, D3DXHANDLE function,
4612 const char *target, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_msgs,
4613 ID3DXConstantTable **constant_table)
4615 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4617 FIXME("iface %p, function %p, target %p, flags %#x, shader %p, error_msgs %p, constant_table %p stub\n",
4618 This, function, target, flags, shader, error_msgs, constant_table);
4620 return E_NOTIMPL;
4623 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
4625 /*** IUnknown methods ***/
4626 ID3DXEffectCompilerImpl_QueryInterface,
4627 ID3DXEffectCompilerImpl_AddRef,
4628 ID3DXEffectCompilerImpl_Release,
4629 /*** ID3DXBaseEffect methods ***/
4630 ID3DXEffectCompilerImpl_GetDesc,
4631 ID3DXEffectCompilerImpl_GetParameterDesc,
4632 ID3DXEffectCompilerImpl_GetTechniqueDesc,
4633 ID3DXEffectCompilerImpl_GetPassDesc,
4634 ID3DXEffectCompilerImpl_GetFunctionDesc,
4635 ID3DXEffectCompilerImpl_GetParameter,
4636 ID3DXEffectCompilerImpl_GetParameterByName,
4637 ID3DXEffectCompilerImpl_GetParameterBySemantic,
4638 ID3DXEffectCompilerImpl_GetParameterElement,
4639 ID3DXEffectCompilerImpl_GetTechnique,
4640 ID3DXEffectCompilerImpl_GetTechniqueByName,
4641 ID3DXEffectCompilerImpl_GetPass,
4642 ID3DXEffectCompilerImpl_GetPassByName,
4643 ID3DXEffectCompilerImpl_GetFunction,
4644 ID3DXEffectCompilerImpl_GetFunctionByName,
4645 ID3DXEffectCompilerImpl_GetAnnotation,
4646 ID3DXEffectCompilerImpl_GetAnnotationByName,
4647 ID3DXEffectCompilerImpl_SetValue,
4648 ID3DXEffectCompilerImpl_GetValue,
4649 ID3DXEffectCompilerImpl_SetBool,
4650 ID3DXEffectCompilerImpl_GetBool,
4651 ID3DXEffectCompilerImpl_SetBoolArray,
4652 ID3DXEffectCompilerImpl_GetBoolArray,
4653 ID3DXEffectCompilerImpl_SetInt,
4654 ID3DXEffectCompilerImpl_GetInt,
4655 ID3DXEffectCompilerImpl_SetIntArray,
4656 ID3DXEffectCompilerImpl_GetIntArray,
4657 ID3DXEffectCompilerImpl_SetFloat,
4658 ID3DXEffectCompilerImpl_GetFloat,
4659 ID3DXEffectCompilerImpl_SetFloatArray,
4660 ID3DXEffectCompilerImpl_GetFloatArray,
4661 ID3DXEffectCompilerImpl_SetVector,
4662 ID3DXEffectCompilerImpl_GetVector,
4663 ID3DXEffectCompilerImpl_SetVectorArray,
4664 ID3DXEffectCompilerImpl_GetVectorArray,
4665 ID3DXEffectCompilerImpl_SetMatrix,
4666 ID3DXEffectCompilerImpl_GetMatrix,
4667 ID3DXEffectCompilerImpl_SetMatrixArray,
4668 ID3DXEffectCompilerImpl_GetMatrixArray,
4669 ID3DXEffectCompilerImpl_SetMatrixPointerArray,
4670 ID3DXEffectCompilerImpl_GetMatrixPointerArray,
4671 ID3DXEffectCompilerImpl_SetMatrixTranspose,
4672 ID3DXEffectCompilerImpl_GetMatrixTranspose,
4673 ID3DXEffectCompilerImpl_SetMatrixTransposeArray,
4674 ID3DXEffectCompilerImpl_GetMatrixTransposeArray,
4675 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray,
4676 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray,
4677 ID3DXEffectCompilerImpl_SetString,
4678 ID3DXEffectCompilerImpl_GetString,
4679 ID3DXEffectCompilerImpl_SetTexture,
4680 ID3DXEffectCompilerImpl_GetTexture,
4681 ID3DXEffectCompilerImpl_GetPixelShader,
4682 ID3DXEffectCompilerImpl_GetVertexShader,
4683 ID3DXEffectCompilerImpl_SetArrayRange,
4684 /*** ID3DXEffectCompiler methods ***/
4685 ID3DXEffectCompilerImpl_SetLiteral,
4686 ID3DXEffectCompilerImpl_GetLiteral,
4687 ID3DXEffectCompilerImpl_CompileEffect,
4688 ID3DXEffectCompilerImpl_CompileShader,
4691 static HRESULT d3dx9_parse_sampler(struct d3dx9_base_effect *base, struct d3dx_sampler *sampler,
4692 const char *data, const char **ptr, struct d3dx_object *objects)
4694 HRESULT hr;
4695 UINT i;
4697 read_dword(ptr, &sampler->state_count);
4698 TRACE("Count: %u\n", sampler->state_count);
4700 sampler->states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler->states) * sampler->state_count);
4701 if (!sampler->states)
4703 ERR("Out of memory\n");
4704 return E_OUTOFMEMORY;
4707 for (i = 0; i < sampler->state_count; ++i)
4709 hr = d3dx9_parse_state(base, &sampler->states[i], data, ptr, objects);
4710 if (hr != D3D_OK)
4712 WARN("Failed to parse state %u\n", i);
4713 goto err_out;
4717 return D3D_OK;
4719 err_out:
4721 for (i = 0; i < sampler->state_count; ++i)
4723 free_state(&sampler->states[i]);
4725 HeapFree(GetProcessHeap(), 0, sampler->states);
4726 sampler->states = NULL;
4728 return hr;
4731 static HRESULT d3dx9_parse_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4732 void *value, const char *data, const char **ptr, struct d3dx_object *objects)
4734 unsigned int i;
4735 HRESULT hr;
4736 UINT old_size = 0;
4738 if (param->element_count)
4740 param->data = value;
4742 for (i = 0; i < param->element_count; ++i)
4744 struct d3dx_parameter *member = &param->members[i];
4746 hr = d3dx9_parse_value(base, member, value ? (char *)value + old_size : NULL, data, ptr, objects);
4747 if (hr != D3D_OK)
4749 WARN("Failed to parse value %u\n", i);
4750 return hr;
4753 old_size += member->bytes;
4756 return D3D_OK;
4759 switch(param->class)
4761 case D3DXPC_SCALAR:
4762 case D3DXPC_VECTOR:
4763 case D3DXPC_MATRIX_ROWS:
4764 case D3DXPC_MATRIX_COLUMNS:
4765 param->data = value;
4766 break;
4768 case D3DXPC_STRUCT:
4769 param->data = value;
4771 for (i = 0; i < param->member_count; ++i)
4773 struct d3dx_parameter *member = &param->members[i];
4775 hr = d3dx9_parse_value(base, member, (char *)value + old_size, data, ptr, objects);
4776 if (hr != D3D_OK)
4778 WARN("Failed to parse value %u\n", i);
4779 return hr;
4782 old_size += member->bytes;
4784 break;
4786 case D3DXPC_OBJECT:
4787 switch (param->type)
4789 case D3DXPT_STRING:
4790 case D3DXPT_TEXTURE:
4791 case D3DXPT_TEXTURE1D:
4792 case D3DXPT_TEXTURE2D:
4793 case D3DXPT_TEXTURE3D:
4794 case D3DXPT_TEXTURECUBE:
4795 case D3DXPT_PIXELSHADER:
4796 case D3DXPT_VERTEXSHADER:
4797 read_dword(ptr, &param->object_id);
4798 TRACE("Id: %u\n", param->object_id);
4799 objects[param->object_id].param = param;
4800 param->data = value;
4801 break;
4803 case D3DXPT_SAMPLER:
4804 case D3DXPT_SAMPLER1D:
4805 case D3DXPT_SAMPLER2D:
4806 case D3DXPT_SAMPLER3D:
4807 case D3DXPT_SAMPLERCUBE:
4809 struct d3dx_sampler *sampler;
4811 sampler = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler));
4812 if (!sampler)
4813 return E_OUTOFMEMORY;
4815 hr = d3dx9_parse_sampler(base, sampler, data, ptr, objects);
4816 if (hr != D3D_OK)
4818 HeapFree(GetProcessHeap(), 0, sampler);
4819 WARN("Failed to parse sampler\n");
4820 return hr;
4823 param->data = sampler;
4824 break;
4827 default:
4828 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4829 break;
4831 break;
4833 default:
4834 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4835 break;
4838 return D3D_OK;
4841 static HRESULT d3dx9_parse_init_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4842 const char *data, const char *ptr, struct d3dx_object *objects)
4844 UINT size = param->bytes;
4845 HRESULT hr;
4846 void *value = NULL;
4848 TRACE("param size: %u\n", size);
4850 if (size)
4852 value = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4853 if (!value)
4855 ERR("Failed to allocate data memory.\n");
4856 return E_OUTOFMEMORY;
4859 switch(param->class)
4861 case D3DXPC_OBJECT:
4862 break;
4864 case D3DXPC_SCALAR:
4865 case D3DXPC_VECTOR:
4866 case D3DXPC_MATRIX_ROWS:
4867 case D3DXPC_MATRIX_COLUMNS:
4868 case D3DXPC_STRUCT:
4869 TRACE("Data: %s.\n", debugstr_an(ptr, size));
4870 memcpy(value, ptr, size);
4871 break;
4873 default:
4874 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4875 break;
4879 hr = d3dx9_parse_value(base, param, value, data, &ptr, objects);
4880 if (hr != D3D_OK)
4882 WARN("Failed to parse value\n");
4883 HeapFree(GetProcessHeap(), 0, value);
4884 return hr;
4887 return D3D_OK;
4890 static HRESULT d3dx9_parse_name(char **name, const char *ptr)
4892 DWORD size;
4894 read_dword(&ptr, &size);
4895 TRACE("Name size: %#x\n", size);
4897 if (!size)
4899 return D3D_OK;
4902 *name = HeapAlloc(GetProcessHeap(), 0, size);
4903 if (!*name)
4905 ERR("Failed to allocate name memory.\n");
4906 return E_OUTOFMEMORY;
4909 TRACE("Name: %s.\n", debugstr_an(ptr, size));
4910 memcpy(*name, ptr, size);
4912 return D3D_OK;
4915 static HRESULT d3dx9_copy_data(struct d3dx9_base_effect *base, unsigned int object_id, const char **ptr)
4917 struct d3dx_object *object = &base->objects[object_id];
4919 if (object->size || object->data)
4921 if (object_id)
4922 FIXME("Overwriting object id %u!\n", object_id);
4923 else
4924 TRACE("Overwriting object id 0.\n");
4926 HeapFree(GetProcessHeap(), 0, object->data);
4927 object->data = NULL;
4930 read_dword(ptr, &object->size);
4931 TRACE("Data size: %#x.\n", object->size);
4933 if (!object->size)
4934 return D3D_OK;
4936 object->data = HeapAlloc(GetProcessHeap(), 0, object->size);
4937 if (!object->data)
4939 ERR("Failed to allocate object memory.\n");
4940 return E_OUTOFMEMORY;
4943 TRACE("Data: %s.\n", debugstr_an(*ptr, object->size));
4944 memcpy(object->data, *ptr, object->size);
4946 *ptr += ((object->size + 3) & ~3);
4948 return D3D_OK;
4951 static void add_param_to_table(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
4953 struct param_table *table = &base->param_table;
4955 if (table->count >= table->size)
4957 unsigned int new_size;
4958 struct d3dx_parameter **new_alloc;
4960 if (!table->size)
4962 new_size = INITIAL_PARAM_TABLE_SIZE;
4963 new_alloc = HeapAlloc(GetProcessHeap(), 0, sizeof(*table->table) * new_size);
4964 if (!new_alloc)
4966 ERR("Out of memory.\n");
4967 return;
4970 else
4972 new_size = table->size * 2;
4973 new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * new_size);
4974 if (!new_alloc)
4976 ERR("Out of memory.\n");
4977 return;
4980 table->table = new_alloc;
4981 table->size = new_size;
4984 table->table[table->count++] = param;
4987 static void sync_param_handles(struct d3dx9_base_effect *base)
4989 struct param_table *table = &base->param_table;
4990 struct d3dx_parameter **new_alloc;
4991 unsigned int i;
4993 if (table->count)
4995 new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * table->count);
4996 if (new_alloc)
4997 table->table = new_alloc;
4998 else
4999 ERR("Out of memory.\n");
5002 for (i = 0; i < table->count; ++i)
5003 table->table[i]->handle = (D3DXHANDLE)&table->table[i];
5006 static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
5007 const char *data, const char **ptr, struct d3dx_parameter *parent, UINT flags)
5009 DWORD offset;
5010 HRESULT hr;
5011 UINT i;
5013 param->flags = flags;
5015 if (!parent)
5017 read_dword(ptr, (DWORD *)&param->type);
5018 TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
5020 read_dword(ptr, (DWORD *)&param->class);
5021 TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
5023 read_dword(ptr, &offset);
5024 TRACE("Type name offset: %#x\n", offset);
5025 hr = d3dx9_parse_name(&param->name, data + offset);
5026 if (hr != D3D_OK)
5028 WARN("Failed to parse name\n");
5029 goto err_out;
5032 read_dword(ptr, &offset);
5033 TRACE("Type semantic offset: %#x\n", offset);
5034 hr = d3dx9_parse_name(&param->semantic, data + offset);
5035 if (hr != D3D_OK)
5037 WARN("Failed to parse semantic\n");
5038 goto err_out;
5041 read_dword(ptr, &param->element_count);
5042 TRACE("Elements: %u\n", param->element_count);
5044 switch (param->class)
5046 case D3DXPC_VECTOR:
5047 read_dword(ptr, &param->columns);
5048 TRACE("Columns: %u\n", param->columns);
5050 read_dword(ptr, &param->rows);
5051 TRACE("Rows: %u\n", param->rows);
5053 /* sizeof(DWORD) * rows * columns */
5054 param->bytes = 4 * param->rows * param->columns;
5055 break;
5057 case D3DXPC_SCALAR:
5058 case D3DXPC_MATRIX_ROWS:
5059 case D3DXPC_MATRIX_COLUMNS:
5060 read_dword(ptr, &param->rows);
5061 TRACE("Rows: %u\n", param->rows);
5063 read_dword(ptr, &param->columns);
5064 TRACE("Columns: %u\n", param->columns);
5066 /* sizeof(DWORD) * rows * columns */
5067 param->bytes = 4 * param->rows * param->columns;
5068 break;
5070 case D3DXPC_STRUCT:
5071 read_dword(ptr, &param->member_count);
5072 TRACE("Members: %u\n", param->member_count);
5073 break;
5075 case D3DXPC_OBJECT:
5076 switch (param->type)
5078 case D3DXPT_STRING:
5079 case D3DXPT_PIXELSHADER:
5080 case D3DXPT_VERTEXSHADER:
5081 case D3DXPT_TEXTURE:
5082 case D3DXPT_TEXTURE1D:
5083 case D3DXPT_TEXTURE2D:
5084 case D3DXPT_TEXTURE3D:
5085 case D3DXPT_TEXTURECUBE:
5086 param->bytes = sizeof(void *);
5087 break;
5089 case D3DXPT_SAMPLER:
5090 case D3DXPT_SAMPLER1D:
5091 case D3DXPT_SAMPLER2D:
5092 case D3DXPT_SAMPLER3D:
5093 case D3DXPT_SAMPLERCUBE:
5094 param->bytes = 0;
5095 break;
5097 default:
5098 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5099 break;
5101 break;
5103 default:
5104 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
5105 break;
5108 else
5110 /* elements */
5111 param->type = parent->type;
5112 param->class = parent->class;
5113 param->name = parent->name;
5114 param->semantic = parent->semantic;
5115 param->element_count = 0;
5116 param->annotation_count = 0;
5117 param->member_count = parent->member_count;
5118 param->bytes = parent->bytes;
5119 param->rows = parent->rows;
5120 param->columns = parent->columns;
5123 if (param->element_count)
5125 unsigned int param_bytes = 0;
5126 const char *save_ptr = *ptr;
5128 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->element_count);
5129 if (!param->members)
5131 ERR("Out of memory\n");
5132 hr = E_OUTOFMEMORY;
5133 goto err_out;
5136 for (i = 0; i < param->element_count; ++i)
5138 *ptr = save_ptr;
5140 add_param_to_table(base, &param->members[i]);
5141 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, param, flags);
5142 if (hr != D3D_OK)
5144 WARN("Failed to parse member %u\n", i);
5145 goto err_out;
5148 param_bytes += param->members[i].bytes;
5151 param->bytes = param_bytes;
5153 else if (param->member_count)
5155 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->member_count);
5156 if (!param->members)
5158 ERR("Out of memory\n");
5159 hr = E_OUTOFMEMORY;
5160 goto err_out;
5163 for (i = 0; i < param->member_count; ++i)
5165 add_param_to_table(base, &param->members[i]);
5166 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, NULL, flags);
5167 if (hr != D3D_OK)
5169 WARN("Failed to parse member %u\n", i);
5170 goto err_out;
5173 param->bytes += param->members[i].bytes;
5176 return D3D_OK;
5178 err_out:
5180 if (param->members)
5182 unsigned int count = param->element_count ? param->element_count : param->member_count;
5184 for (i = 0; i < count; ++i)
5185 free_parameter(&param->members[i], param->element_count != 0, TRUE);
5186 HeapFree(GetProcessHeap(), 0, param->members);
5187 param->members = NULL;
5190 if (!parent)
5192 HeapFree(GetProcessHeap(), 0, param->name);
5193 HeapFree(GetProcessHeap(), 0, param->semantic);
5195 param->name = NULL;
5196 param->semantic = NULL;
5198 return hr;
5201 static HRESULT d3dx9_parse_effect_annotation(struct d3dx9_base_effect *base, struct d3dx_parameter *anno,
5202 const char *data, const char **ptr, struct d3dx_object *objects)
5204 DWORD offset;
5205 const char *ptr2;
5206 HRESULT hr;
5208 anno->flags = D3DX_PARAMETER_ANNOTATION;
5210 read_dword(ptr, &offset);
5211 TRACE("Typedef offset: %#x\n", offset);
5212 ptr2 = data + offset;
5213 hr = d3dx9_parse_effect_typedef(base, anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
5214 if (hr != D3D_OK)
5216 WARN("Failed to parse type definition\n");
5217 return hr;
5220 read_dword(ptr, &offset);
5221 TRACE("Value offset: %#x\n", offset);
5222 hr = d3dx9_parse_init_value(base, anno, data, data + offset, objects);
5223 if (hr != D3D_OK)
5225 WARN("Failed to parse value\n");
5226 return hr;
5229 return D3D_OK;
5232 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
5233 const char *data, const char **ptr, struct d3dx_object *objects)
5235 DWORD offset;
5236 const char *ptr2;
5237 HRESULT hr;
5239 state->type = ST_CONSTANT;
5241 read_dword(ptr, &state->operation);
5242 TRACE("Operation: %#x (%s)\n", state->operation, state_table[state->operation].name);
5244 read_dword(ptr, &state->index);
5245 TRACE("Index: %#x\n", state->index);
5247 read_dword(ptr, &offset);
5248 TRACE("Typedef offset: %#x\n", offset);
5249 ptr2 = data + offset;
5250 hr = d3dx9_parse_effect_typedef(base, &state->parameter, data, &ptr2, NULL, 0);
5251 if (hr != D3D_OK)
5253 WARN("Failed to parse type definition\n");
5254 goto err_out;
5257 read_dword(ptr, &offset);
5258 TRACE("Value offset: %#x\n", offset);
5259 hr = d3dx9_parse_init_value(base, &state->parameter, data, data + offset, objects);
5260 if (hr != D3D_OK)
5262 WARN("Failed to parse value\n");
5263 goto err_out;
5266 return D3D_OK;
5268 err_out:
5270 free_parameter(&state->parameter, FALSE, FALSE);
5272 return hr;
5275 static HRESULT d3dx9_parse_effect_parameter(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
5276 const char *data, const char **ptr, struct d3dx_object *objects)
5278 DWORD offset;
5279 HRESULT hr;
5280 unsigned int i;
5281 const char *ptr2;
5283 read_dword(ptr, &offset);
5284 TRACE("Typedef offset: %#x\n", offset);
5285 ptr2 = data + offset;
5287 read_dword(ptr, &offset);
5288 TRACE("Value offset: %#x\n", offset);
5290 read_dword(ptr, &param->flags);
5291 TRACE("Flags: %#x\n", param->flags);
5293 read_dword(ptr, &param->annotation_count);
5294 TRACE("Annotation count: %u\n", param->annotation_count);
5296 hr = d3dx9_parse_effect_typedef(base, param, data, &ptr2, NULL, param->flags);
5297 if (hr != D3D_OK)
5299 WARN("Failed to parse type definition\n");
5300 return hr;
5303 hr = d3dx9_parse_init_value(base, param, data, data + offset, objects);
5304 if (hr != D3D_OK)
5306 WARN("Failed to parse value\n");
5307 return hr;
5310 if (param->annotation_count)
5312 param->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5313 sizeof(*param->annotations) * param->annotation_count);
5314 if (!param->annotations)
5316 ERR("Out of memory\n");
5317 hr = E_OUTOFMEMORY;
5318 goto err_out;
5321 for (i = 0; i < param->annotation_count; ++i)
5323 add_param_to_table(base, &param->annotations[i]);
5324 hr = d3dx9_parse_effect_annotation(base, &param->annotations[i], data, ptr, objects);
5325 if (hr != D3D_OK)
5327 WARN("Failed to parse annotation\n");
5328 goto err_out;
5333 return D3D_OK;
5335 err_out:
5337 if (param->annotations)
5339 for (i = 0; i < param->annotation_count; ++i)
5340 free_parameter(&param->annotations[i], FALSE, FALSE);
5341 HeapFree(GetProcessHeap(), 0, param->annotations);
5342 param->annotations = NULL;
5345 return hr;
5348 static HRESULT d3dx9_parse_effect_pass(struct d3dx9_base_effect *base, struct d3dx_pass *pass,
5349 const char *data, const char **ptr, struct d3dx_object *objects)
5351 DWORD offset;
5352 HRESULT hr;
5353 unsigned int i;
5354 struct d3dx_state *states = NULL;
5355 char *name = NULL;
5357 read_dword(ptr, &offset);
5358 TRACE("Pass name offset: %#x\n", offset);
5359 hr = d3dx9_parse_name(&name, data + offset);
5360 if (hr != D3D_OK)
5362 WARN("Failed to parse name\n");
5363 goto err_out;
5366 read_dword(ptr, &pass->annotation_count);
5367 TRACE("Annotation count: %u\n", pass->annotation_count);
5369 read_dword(ptr, &pass->state_count);
5370 TRACE("State count: %u\n", pass->state_count);
5372 if (pass->annotation_count)
5374 pass->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5375 sizeof(*pass->annotations) * pass->annotation_count);
5376 if (!pass->annotations)
5378 ERR("Out of memory\n");
5379 hr = E_OUTOFMEMORY;
5380 goto err_out;
5383 for (i = 0; i < pass->annotation_count; ++i)
5385 add_param_to_table(base, &pass->annotations[i]);
5386 hr = d3dx9_parse_effect_annotation(base, &pass->annotations[i], data, ptr, objects);
5387 if (hr != D3D_OK)
5389 WARN("Failed to parse annotation %u\n", i);
5390 goto err_out;
5395 if (pass->state_count)
5397 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * pass->state_count);
5398 if (!states)
5400 ERR("Out of memory\n");
5401 hr = E_OUTOFMEMORY;
5402 goto err_out;
5405 for (i = 0; i < pass->state_count; ++i)
5407 hr = d3dx9_parse_state(base, &states[i], data, ptr, objects);
5408 if (hr != D3D_OK)
5410 WARN("Failed to parse annotation %u\n", i);
5411 goto err_out;
5416 pass->name = name;
5417 pass->states = states;
5419 return D3D_OK;
5421 err_out:
5423 if (pass->annotations)
5425 for (i = 0; i < pass->annotation_count; ++i)
5426 free_parameter(&pass->annotations[i], FALSE, FALSE);
5427 HeapFree(GetProcessHeap(), 0, pass->annotations);
5428 pass->annotations = NULL;
5431 if (states)
5433 for (i = 0; i < pass->state_count; ++i)
5435 free_state(&states[i]);
5437 HeapFree(GetProcessHeap(), 0, states);
5440 HeapFree(GetProcessHeap(), 0, name);
5442 return hr;
5445 static HRESULT d3dx9_parse_effect_technique(struct d3dx9_base_effect *base, struct d3dx_technique *technique,
5446 const char *data, const char **ptr, struct d3dx_object *objects)
5448 DWORD offset;
5449 HRESULT hr;
5450 unsigned int i;
5451 char *name = NULL;
5453 read_dword(ptr, &offset);
5454 TRACE("Technique name offset: %#x\n", offset);
5455 hr = d3dx9_parse_name(&name, data + offset);
5456 if (hr != D3D_OK)
5458 WARN("Failed to parse name\n");
5459 goto err_out;
5462 read_dword(ptr, &technique->annotation_count);
5463 TRACE("Annotation count: %u\n", technique->annotation_count);
5465 read_dword(ptr, &technique->pass_count);
5466 TRACE("Pass count: %u\n", technique->pass_count);
5468 if (technique->annotation_count)
5470 technique->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5471 sizeof(*technique->annotations) * technique->annotation_count);
5472 if (!technique->annotations)
5474 ERR("Out of memory\n");
5475 hr = E_OUTOFMEMORY;
5476 goto err_out;
5479 for (i = 0; i < technique->annotation_count; ++i)
5481 add_param_to_table(base, &technique->annotations[i]);
5482 hr = d3dx9_parse_effect_annotation(base, &technique->annotations[i], data, ptr, objects);
5483 if (hr != D3D_OK)
5485 WARN("Failed to parse annotation %u\n", i);
5486 goto err_out;
5491 if (technique->pass_count)
5493 technique->passes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5494 sizeof(*technique->passes) * technique->pass_count);
5495 if (!technique->passes)
5497 ERR("Out of memory\n");
5498 hr = E_OUTOFMEMORY;
5499 goto err_out;
5502 for (i = 0; i < technique->pass_count; ++i)
5504 hr = d3dx9_parse_effect_pass(base, &technique->passes[i], data, ptr, objects);
5505 if (hr != D3D_OK)
5507 WARN("Failed to parse pass %u\n", i);
5508 goto err_out;
5513 technique->name = name;
5515 return D3D_OK;
5517 err_out:
5519 if (technique->passes)
5521 for (i = 0; i < technique->pass_count; ++i)
5522 free_pass(&technique->passes[i]);
5523 HeapFree(GetProcessHeap(), 0, technique->passes);
5524 technique->passes = NULL;
5527 if (technique->annotations)
5529 for (i = 0; i < technique->annotation_count; ++i)
5530 free_parameter(&technique->annotations[i], FALSE, FALSE);
5531 HeapFree(GetProcessHeap(), 0, technique->annotations);
5532 technique->annotations = NULL;
5535 HeapFree(GetProcessHeap(), 0, name);
5537 return hr;
5540 static HRESULT d3dx9_create_object(struct d3dx9_base_effect *base, struct d3dx_object *object)
5542 struct d3dx_parameter *param = object->param;
5543 struct IDirect3DDevice9 *device = base->effect->device;
5544 HRESULT hr;
5546 if (*(char **)param->data)
5547 ERR("Parameter data already allocated.\n");
5549 switch (param->type)
5551 case D3DXPT_STRING:
5552 *(char **)param->data = HeapAlloc(GetProcessHeap(), 0, object->size);
5553 if (!*(char **)param->data)
5555 ERR("Out of memory.\n");
5556 return E_OUTOFMEMORY;
5558 memcpy(*(char **)param->data, object->data, object->size);
5559 break;
5560 case D3DXPT_VERTEXSHADER:
5561 if (FAILED(hr = IDirect3DDevice9_CreateVertexShader(device, object->data,
5562 (IDirect3DVertexShader9 **)param->data)))
5564 WARN("Failed to create vertex shader.\n");
5565 return hr;
5567 break;
5568 case D3DXPT_PIXELSHADER:
5569 if (FAILED(hr = IDirect3DDevice9_CreatePixelShader(device, object->data,
5570 (IDirect3DPixelShader9 **)param->data)))
5572 WARN("Failed to create pixel shader.\n");
5573 return hr;
5575 break;
5576 default:
5577 break;
5579 return D3D_OK;
5582 static HRESULT d3dx9_parse_array_selector(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
5584 DWORD string_size;
5585 struct d3dx_object *object = &base->objects[param->object_id];
5586 char *ptr = object->data;
5587 HRESULT ret;
5589 TRACE("Parsing array entry selection state for parameter %p.\n", param);
5591 string_size = *(DWORD *)ptr;
5592 param->referenced_param = get_parameter_by_name(base, NULL, ptr + 4);
5593 if (param->referenced_param)
5595 TRACE("Mapping to parameter %s.\n", debugstr_a(param->referenced_param->name));
5597 else
5599 FIXME("Referenced parameter %s not found.\n", ptr + 4);
5600 return D3DXERR_INVALIDDATA;
5602 TRACE("Unknown DWORD: 0x%.8x.\n", *(DWORD *)(ptr + string_size));
5604 if (string_size % sizeof(DWORD))
5605 FIXME("Unaligned string_size %u.\n", string_size);
5606 d3dx_create_param_eval(base, (DWORD *)(ptr + string_size) + 1, object->size - (string_size + sizeof(DWORD)),
5607 D3DXPT_INT, &param->param_eval);
5608 ret = D3D_OK;
5609 param = param->referenced_param;
5610 if (param->type == D3DXPT_VERTEXSHADER || param->type == D3DXPT_PIXELSHADER)
5612 unsigned int i;
5614 for (i = 0; i < param->element_count; i++)
5616 if (param->members[i].type != param->type)
5618 FIXME("Unexpected member parameter type %u, expected %u.\n", param->members[i].type, param->type);
5619 return D3DXERR_INVALIDDATA;
5621 if (!param->members[i].param_eval)
5623 TRACE("Creating preshader for object %u.\n", param->members[i].object_id);
5624 object = &base->objects[param->members[i].object_id];
5625 d3dx_create_param_eval(base, object->data, object->size, param->type, &param->members[i].param_eval);
5629 return ret;
5632 static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *data, const char **ptr)
5634 DWORD technique_index;
5635 DWORD index, state_index, usage, element_index;
5636 struct d3dx_state *state;
5637 struct d3dx_parameter *param;
5638 struct d3dx_object *object;
5639 HRESULT hr = E_FAIL;
5641 read_dword(ptr, &technique_index);
5642 TRACE("technique_index: %u\n", technique_index);
5644 read_dword(ptr, &index);
5645 TRACE("index: %u\n", index);
5647 read_dword(ptr, &element_index);
5648 TRACE("element_index: %u\n", element_index);
5650 read_dword(ptr, &state_index);
5651 TRACE("state_index: %u\n", state_index);
5653 read_dword(ptr, &usage);
5654 TRACE("usage: %u\n", usage);
5656 if (technique_index == 0xffffffff)
5658 struct d3dx_parameter *parameter;
5659 struct d3dx_sampler *sampler;
5661 if (index >= base->parameter_count)
5663 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index, base->parameter_count);
5664 return E_FAIL;
5667 parameter = &base->parameters[index];
5668 if (element_index != 0xffffffff)
5670 if (element_index >= parameter->element_count && parameter->element_count != 0)
5672 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index, parameter->element_count);
5673 return E_FAIL;
5676 if (parameter->element_count != 0) parameter = &parameter->members[element_index];
5679 sampler = parameter->data;
5680 if (state_index >= sampler->state_count)
5682 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, sampler->state_count);
5683 return E_FAIL;
5686 state = &sampler->states[state_index];
5688 else
5690 struct d3dx_technique *technique;
5691 struct d3dx_pass *pass;
5693 if (technique_index >= base->technique_count)
5695 FIXME("Index out of bounds: technique_index %u >= technique_count %u\n", technique_index, base->technique_count);
5696 return E_FAIL;
5699 technique = &base->techniques[technique_index];
5700 if (index >= technique->pass_count)
5702 FIXME("Index out of bounds: index %u >= pass_count %u\n", index, technique->pass_count);
5703 return E_FAIL;
5706 pass = &technique->passes[index];
5707 if (state_index >= pass->state_count)
5709 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, pass->state_count);
5710 return E_FAIL;
5713 state = &pass->states[state_index];
5716 TRACE("State operation %#x (%s).\n", state->operation, state_table[state->operation].name);
5717 param = &state->parameter;
5718 TRACE("Using object id %u.\n", param->object_id);
5719 object = &base->objects[param->object_id];
5721 TRACE("Usage %u: class %s, type %s.\n", usage, debug_d3dxparameter_class(param->class),
5722 debug_d3dxparameter_type(param->type));
5723 switch (usage)
5725 case 0:
5726 switch (param->type)
5728 case D3DXPT_VERTEXSHADER:
5729 case D3DXPT_PIXELSHADER:
5730 state->type = ST_CONSTANT;
5731 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
5732 return hr;
5734 if (object->data)
5736 if (FAILED(hr = d3dx9_create_object(base, object)))
5737 return hr;
5738 d3dx_create_param_eval(base, object->data, object->size, param->type, &param->param_eval);
5740 break;
5742 case D3DXPT_BOOL:
5743 case D3DXPT_INT:
5744 case D3DXPT_FLOAT:
5745 case D3DXPT_STRING:
5746 state->type = ST_FXLC;
5747 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
5748 return hr;
5749 d3dx_create_param_eval(base, object->data, object->size, param->type, &param->param_eval);
5750 break;
5752 default:
5753 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5754 break;
5756 break;
5758 case 1:
5759 state->type = ST_PARAMETER;
5760 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
5761 return hr;
5763 TRACE("Looking for parameter %s.\n", debugstr_a(object->data));
5764 param->referenced_param = get_parameter_by_name(base, NULL, object->data);
5765 if (param->referenced_param)
5767 struct d3dx_parameter *refpar = param->referenced_param;
5769 TRACE("Mapping to parameter %p, having object id %u.\n", refpar, refpar->object_id);
5770 if (refpar->type == D3DXPT_VERTEXSHADER || refpar->type == D3DXPT_PIXELSHADER)
5772 struct d3dx_object *refobj = &base->objects[refpar->object_id];
5774 if (!refpar->param_eval)
5775 d3dx_create_param_eval(base, refobj->data, refobj->size,
5776 refpar->type, &refpar->param_eval);
5779 else
5781 FIXME("Referenced parameter %s not found.\n", (char *)object->data);
5782 return D3DXERR_INVALIDDATA;
5784 break;
5786 case 2:
5787 state->type = ST_ARRAY_SELECTOR;
5788 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
5789 return hr;
5790 hr = d3dx9_parse_array_selector(base, param);
5791 break;
5793 default:
5794 FIXME("Unknown usage %x\n", usage);
5795 break;
5798 return hr;
5801 static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *data, UINT data_size, DWORD start)
5803 const char *ptr = data + start;
5804 UINT stringcount, resourcecount;
5805 HRESULT hr;
5806 UINT i;
5808 read_dword(&ptr, &base->parameter_count);
5809 TRACE("Parameter count: %u\n", base->parameter_count);
5811 read_dword(&ptr, &base->technique_count);
5812 TRACE("Technique count: %u\n", base->technique_count);
5814 skip_dword_unknown(&ptr, 1);
5816 read_dword(&ptr, &base->object_count);
5817 TRACE("Object count: %u\n", base->object_count);
5819 base->objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*base->objects) * base->object_count);
5820 if (!base->objects)
5822 ERR("Out of memory\n");
5823 hr = E_OUTOFMEMORY;
5824 goto err_out;
5827 if (base->parameter_count)
5829 base->parameters = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5830 sizeof(*base->parameters) * base->parameter_count);
5831 if (!base->parameters)
5833 ERR("Out of memory\n");
5834 hr = E_OUTOFMEMORY;
5835 goto err_out;
5838 for (i = 0; i < base->parameter_count; ++i)
5840 add_param_to_table(base, &base->parameters[i]);
5841 hr = d3dx9_parse_effect_parameter(base, &base->parameters[i], data, &ptr, base->objects);
5842 if (hr != D3D_OK)
5844 WARN("Failed to parse parameter %u\n", i);
5845 goto err_out;
5850 if (base->technique_count)
5852 base->techniques = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5853 sizeof(*base->techniques) * base->technique_count);
5854 if (!base->techniques)
5856 ERR("Out of memory\n");
5857 hr = E_OUTOFMEMORY;
5858 goto err_out;
5861 for (i = 0; i < base->technique_count; ++i)
5863 TRACE("Parsing technique %u.\n", i);
5864 hr = d3dx9_parse_effect_technique(base, &base->techniques[i], data, &ptr, base->objects);
5865 if (hr != D3D_OK)
5867 WARN("Failed to parse technique %u\n", i);
5868 goto err_out;
5873 sync_param_handles(base);
5875 read_dword(&ptr, &stringcount);
5876 TRACE("String count: %u\n", stringcount);
5878 read_dword(&ptr, &resourcecount);
5879 TRACE("Resource count: %u\n", resourcecount);
5881 for (i = 0; i < stringcount; ++i)
5883 DWORD id;
5885 read_dword(&ptr, &id);
5886 TRACE("Id: %u\n", id);
5888 if (FAILED(hr = d3dx9_copy_data(base, id, &ptr)))
5889 goto err_out;
5891 if (base->objects[id].data)
5893 if (FAILED(hr = d3dx9_create_object(base, &base->objects[id])))
5894 goto err_out;
5898 for (i = 0; i < resourcecount; ++i)
5900 TRACE("parse resource %u\n", i);
5902 hr = d3dx9_parse_resource(base, data, &ptr);
5903 if (hr != D3D_OK)
5905 WARN("Failed to parse resource %u\n", i);
5906 goto err_out;
5910 return D3D_OK;
5912 err_out:
5914 if (base->techniques)
5916 for (i = 0; i < base->technique_count; ++i)
5917 free_technique(&base->techniques[i]);
5918 HeapFree(GetProcessHeap(), 0, base->techniques);
5919 base->techniques = NULL;
5922 if (base->parameters)
5924 for (i = 0; i < base->parameter_count; ++i)
5926 free_parameter(&base->parameters[i], FALSE, FALSE);
5928 HeapFree(GetProcessHeap(), 0, base->parameters);
5929 base->parameters = NULL;
5932 if (base->objects)
5934 for (i = 0; i < base->object_count; ++i)
5936 free_object(&base->objects[i]);
5938 HeapFree(GetProcessHeap(), 0, base->objects);
5939 base->objects = NULL;
5942 return hr;
5945 static HRESULT d3dx9_base_effect_init(struct d3dx9_base_effect *base,
5946 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
5947 UINT eflags, ID3DBlob **errors, struct ID3DXEffectImpl *effect)
5949 DWORD tag, offset;
5950 const char *ptr = data;
5951 HRESULT hr;
5952 ID3DBlob *bytecode = NULL, *temp_errors = NULL;
5954 TRACE("base %p, data %p, data_size %lu, effect %p\n", base, data, data_size, effect);
5956 base->effect = effect;
5958 read_dword(&ptr, &tag);
5959 TRACE("Tag: %x\n", tag);
5961 if (tag != d3dx9_effect_version(9, 1))
5963 TRACE("HLSL ASCII effect, trying to compile it.\n");
5964 hr = D3DCompile(data, data_size, NULL, defines, include,
5965 "main", "fx_2_0", 0, eflags, &bytecode, &temp_errors);
5966 if (FAILED(hr))
5968 WARN("Failed to compile ASCII effect.\n");
5969 if (bytecode)
5970 ID3D10Blob_Release(bytecode);
5971 if (temp_errors)
5972 TRACE("%s\n", (char *)ID3D10Blob_GetBufferPointer(temp_errors));
5973 if (errors)
5974 *errors = temp_errors;
5975 else if (temp_errors)
5976 ID3D10Blob_Release(temp_errors);
5977 return hr;
5979 if (!bytecode)
5981 FIXME("No output from effect compilation.\n");
5982 return D3DERR_INVALIDCALL;
5984 if (errors)
5985 *errors = temp_errors;
5986 else if (temp_errors)
5987 ID3D10Blob_Release(temp_errors);
5989 ptr = ID3D10Blob_GetBufferPointer(bytecode);
5990 read_dword(&ptr, &tag);
5991 TRACE("Tag: %x\n", tag);
5994 read_dword(&ptr, &offset);
5995 TRACE("Offset: %x\n", offset);
5997 hr = d3dx9_parse_effect(base, ptr, data_size, offset);
5998 if (bytecode)
5999 ID3D10Blob_Release(bytecode);
6000 if (hr != D3D_OK)
6002 FIXME("Failed to parse effect.\n");
6003 return hr;
6006 return D3D_OK;
6009 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, struct IDirect3DDevice9 *device,
6010 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
6011 UINT eflags, ID3DBlob **error_messages, struct ID3DXEffectPool *pool)
6013 HRESULT hr;
6015 TRACE("effect %p, device %p, data %p, data_size %lu, pool %p\n", effect, device, data, data_size, pool);
6017 effect->ID3DXEffect_iface.lpVtbl = &ID3DXEffect_Vtbl;
6018 effect->ref = 1;
6020 if (pool) pool->lpVtbl->AddRef(pool);
6021 effect->pool = pool;
6023 IDirect3DDevice9_AddRef(device);
6024 effect->device = device;
6026 if (FAILED(hr = d3dx9_base_effect_init(&effect->base_effect, data, data_size, defines, include,
6027 eflags, error_messages, effect)))
6029 FIXME("Failed to parse effect, hr %#x.\n", hr);
6030 free_effect(effect);
6031 return hr;
6034 /* initialize defaults - check because of unsupported ascii effects */
6035 if (effect->base_effect.techniques)
6037 effect->active_technique = &effect->base_effect.techniques[0];
6038 effect->active_pass = NULL;
6041 return D3D_OK;
6044 HRESULT WINAPI D3DXCreateEffectEx(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
6045 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skip_constants, DWORD flags,
6046 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
6048 struct ID3DXEffectImpl *object;
6049 HRESULT hr;
6051 TRACE("device %p, srcdata %p, srcdatalen %u, defines %p, include %p,"
6052 " skip_constants %p, flags %#x, pool %p, effect %p, compilation_errors %p.\n",
6053 device, srcdata, srcdatalen, defines, include,
6054 skip_constants, flags, pool, effect, compilation_errors);
6056 if (compilation_errors)
6057 *compilation_errors = NULL;
6059 if (!device || !srcdata)
6060 return D3DERR_INVALIDCALL;
6062 if (!srcdatalen)
6063 return E_FAIL;
6065 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
6066 if (!effect)
6067 return D3D_OK;
6069 if (skip_constants)
6070 FIXME("skip_constants is not NULL, not supported yet.\n");
6072 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6073 if (!object)
6074 return E_OUTOFMEMORY;
6076 hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
6077 (ID3DInclude *)include, flags, (ID3DBlob **)compilation_errors, pool);
6078 if (FAILED(hr))
6080 WARN("Failed to create effect object.\n");
6081 HeapFree(GetProcessHeap(), 0, object);
6082 return hr;
6085 *effect = &object->ID3DXEffect_iface;
6087 TRACE("Created ID3DXEffect %p\n", object);
6089 return D3D_OK;
6092 HRESULT WINAPI D3DXCreateEffect(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
6093 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6094 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
6096 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device, srcdata, srcdatalen, defines,
6097 include, flags, pool, effect, compilation_errors);
6099 return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
6102 static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler,
6103 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
6104 UINT eflags, ID3DBlob **error_messages)
6106 HRESULT hr;
6108 TRACE("effect %p, data %p, data_size %lu\n", compiler, data, data_size);
6110 compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
6111 compiler->ref = 1;
6113 if (FAILED(hr = d3dx9_base_effect_init(&compiler->base_effect, data, data_size, defines,
6114 include, eflags, error_messages, NULL)))
6116 FIXME("Failed to parse effect, hr %#x.\n", hr);
6117 free_effect_compiler(compiler);
6118 return hr;
6121 return D3D_OK;
6124 HRESULT WINAPI D3DXCreateEffectCompiler(const char *srcdata, UINT srcdatalen, const D3DXMACRO *defines,
6125 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **compiler, ID3DXBuffer **parse_errors)
6127 struct ID3DXEffectCompilerImpl *object;
6128 HRESULT hr;
6130 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
6131 srcdata, srcdatalen, defines, include, flags, compiler, parse_errors);
6133 if (!srcdata || !compiler)
6135 WARN("Invalid arguments supplied\n");
6136 return D3DERR_INVALIDCALL;
6139 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6140 if (!object)
6141 return E_OUTOFMEMORY;
6143 hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
6144 (ID3DInclude *)include, flags, (ID3DBlob **)parse_errors);
6145 if (FAILED(hr))
6147 WARN("Failed to initialize effect compiler\n");
6148 HeapFree(GetProcessHeap(), 0, object);
6149 return hr;
6152 *compiler = &object->ID3DXEffectCompiler_iface;
6154 TRACE("Created ID3DXEffectCompiler %p\n", object);
6156 return D3D_OK;
6159 struct ID3DXEffectPoolImpl
6161 ID3DXEffectPool ID3DXEffectPool_iface;
6162 LONG ref;
6165 static inline struct ID3DXEffectPoolImpl *impl_from_ID3DXEffectPool(ID3DXEffectPool *iface)
6167 return CONTAINING_RECORD(iface, struct ID3DXEffectPoolImpl, ID3DXEffectPool_iface);
6170 /*** IUnknown methods ***/
6171 static HRESULT WINAPI ID3DXEffectPoolImpl_QueryInterface(ID3DXEffectPool *iface, REFIID riid, void **object)
6173 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
6175 if (IsEqualGUID(riid, &IID_IUnknown) ||
6176 IsEqualGUID(riid, &IID_ID3DXEffectPool))
6178 iface->lpVtbl->AddRef(iface);
6179 *object = iface;
6180 return S_OK;
6183 WARN("Interface %s not found\n", debugstr_guid(riid));
6185 return E_NOINTERFACE;
6188 static ULONG WINAPI ID3DXEffectPoolImpl_AddRef(ID3DXEffectPool *iface)
6190 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
6192 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
6194 return InterlockedIncrement(&This->ref);
6197 static ULONG WINAPI ID3DXEffectPoolImpl_Release(ID3DXEffectPool *iface)
6199 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
6200 ULONG ref = InterlockedDecrement(&This->ref);
6202 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
6204 if (!ref)
6205 HeapFree(GetProcessHeap(), 0, This);
6207 return ref;
6210 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl =
6212 /*** IUnknown methods ***/
6213 ID3DXEffectPoolImpl_QueryInterface,
6214 ID3DXEffectPoolImpl_AddRef,
6215 ID3DXEffectPoolImpl_Release
6218 HRESULT WINAPI D3DXCreateEffectPool(ID3DXEffectPool **pool)
6220 struct ID3DXEffectPoolImpl *object;
6222 TRACE("(%p)\n", pool);
6224 if (!pool)
6225 return D3DERR_INVALIDCALL;
6227 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6228 if (!object)
6229 return E_OUTOFMEMORY;
6231 object->ID3DXEffectPool_iface.lpVtbl = &ID3DXEffectPool_Vtbl;
6232 object->ref = 1;
6234 *pool = &object->ID3DXEffectPool_iface;
6236 return S_OK;
6239 HRESULT WINAPI D3DXCreateEffectFromFileExW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
6240 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
6241 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6243 void *buffer;
6244 HRESULT ret;
6245 DWORD size;
6247 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6248 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6249 device, debugstr_w(srcfile), defines, include, debugstr_a(skipconstants),
6250 flags, pool, effect, compilationerrors);
6252 if (!device || !srcfile)
6253 return D3DERR_INVALIDCALL;
6255 ret = map_view_of_file(srcfile, &buffer, &size);
6257 if (FAILED(ret))
6258 return D3DXERR_INVALIDDATA;
6260 ret = D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6261 UnmapViewOfFile(buffer);
6263 return ret;
6266 HRESULT WINAPI D3DXCreateEffectFromFileExA(struct IDirect3DDevice9 *device, const char *srcfile,
6267 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
6268 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6270 WCHAR *srcfileW;
6271 HRESULT ret;
6272 DWORD len;
6274 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6275 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6276 device, debugstr_a(srcfile), defines, include, debugstr_a(skipconstants),
6277 flags, pool, effect, compilationerrors);
6279 if (!srcfile)
6280 return D3DERR_INVALIDCALL;
6282 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6283 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6284 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6286 ret = D3DXCreateEffectFromFileExW(device, srcfileW, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6287 HeapFree(GetProcessHeap(), 0, srcfileW);
6289 return ret;
6292 HRESULT WINAPI D3DXCreateEffectFromFileW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
6293 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
6294 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6296 TRACE("(void): relay\n");
6297 return D3DXCreateEffectFromFileExW(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6300 HRESULT WINAPI D3DXCreateEffectFromFileA(struct IDirect3DDevice9 *device, const char *srcfile,
6301 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
6302 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6304 TRACE("(void): relay\n");
6305 return D3DXCreateEffectFromFileExA(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6308 HRESULT WINAPI D3DXCreateEffectFromResourceExW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6309 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
6310 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6312 HRSRC resinfo;
6313 void *buffer;
6314 DWORD size;
6316 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6317 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6318 device, srcmodule, debugstr_w(srcresource), defines, include, debugstr_a(skipconstants),
6319 flags, pool, effect, compilationerrors);
6321 if (!device)
6322 return D3DERR_INVALIDCALL;
6324 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
6325 return D3DXERR_INVALIDDATA;
6327 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6328 return D3DXERR_INVALIDDATA;
6330 return D3DXCreateEffectEx(device, buffer, size, defines, include,
6331 skipconstants, flags, pool, effect, compilationerrors);
6334 HRESULT WINAPI D3DXCreateEffectFromResourceExA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6335 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
6336 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6338 HRSRC resinfo;
6339 void *buffer;
6340 DWORD size;
6342 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6343 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6344 device, srcmodule, debugstr_a(srcresource), defines, include, debugstr_a(skipconstants),
6345 flags, pool, effect, compilationerrors);
6347 if (!device)
6348 return D3DERR_INVALIDCALL;
6350 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
6351 return D3DXERR_INVALIDDATA;
6353 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6354 return D3DXERR_INVALIDDATA;
6356 return D3DXCreateEffectEx(device, buffer, size, defines, include,
6357 skipconstants, flags, pool, effect, compilationerrors);
6360 HRESULT WINAPI D3DXCreateEffectFromResourceW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6361 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6362 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6364 TRACE("(void): relay\n");
6365 return D3DXCreateEffectFromResourceExW(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6368 HRESULT WINAPI D3DXCreateEffectFromResourceA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6369 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6370 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6372 TRACE("(void): relay\n");
6373 return D3DXCreateEffectFromResourceExA(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6376 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(const WCHAR *srcfile, const D3DXMACRO *defines,
6377 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6379 void *buffer;
6380 HRESULT ret;
6381 DWORD size;
6383 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6384 debugstr_w(srcfile), defines, include, flags, effectcompiler, parseerrors);
6386 if (!srcfile)
6387 return D3DERR_INVALIDCALL;
6389 ret = map_view_of_file(srcfile, &buffer, &size);
6391 if (FAILED(ret))
6392 return D3DXERR_INVALIDDATA;
6394 ret = D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6395 UnmapViewOfFile(buffer);
6397 return ret;
6400 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(const char *srcfile, const D3DXMACRO *defines,
6401 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6403 WCHAR *srcfileW;
6404 HRESULT ret;
6405 DWORD len;
6407 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6408 debugstr_a(srcfile), defines, include, flags, effectcompiler, parseerrors);
6410 if (!srcfile)
6411 return D3DERR_INVALIDCALL;
6413 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6414 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6415 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6417 ret = D3DXCreateEffectCompilerFromFileW(srcfileW, defines, include, flags, effectcompiler, parseerrors);
6418 HeapFree(GetProcessHeap(), 0, srcfileW);
6420 return ret;
6423 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule, const char *srcresource,
6424 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
6425 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6427 HRSRC resinfo;
6428 void *buffer;
6429 DWORD size;
6431 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6432 srcmodule, debugstr_a(srcresource), defines, include, flags, effectcompiler, parseerrors);
6434 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
6435 return D3DXERR_INVALIDDATA;
6437 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6438 return D3DXERR_INVALIDDATA;
6440 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6443 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule, const WCHAR *srcresource,
6444 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
6445 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6447 HRSRC resinfo;
6448 void *buffer;
6449 DWORD size;
6451 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6452 srcmodule, debugstr_w(srcresource), defines, include, flags, effectcompiler, parseerrors);
6454 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
6455 return D3DXERR_INVALIDDATA;
6457 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6458 return D3DXERR_INVALIDDATA;
6460 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6463 HRESULT WINAPI D3DXDisassembleEffect(ID3DXEffect *effect, BOOL enable_color_code, ID3DXBuffer **disassembly)
6465 FIXME("(%p, %u, %p): stub\n", effect, enable_color_code, disassembly);
6467 return D3DXERR_INVALIDDATA;