regedit: Check if any hex data exists before attempting to parse it.
[wine.git] / dlls / d3dx9_36 / effect.c
blobe9b139e8237d5abd98ae0ea283b030406250538c
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 static const char parameter_magic_string[4] = {'@', '!', '#', '\xFF'};
32 #define PARAMETER_FLAG_SHARED 1
34 #define INITIAL_POOL_SIZE 16
36 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
38 enum STATE_CLASS
40 SC_LIGHTENABLE,
41 SC_FVF,
42 SC_LIGHT,
43 SC_MATERIAL,
44 SC_NPATCHMODE,
45 SC_PIXELSHADER,
46 SC_RENDERSTATE,
47 SC_SETSAMPLER,
48 SC_SAMPLERSTATE,
49 SC_TEXTURE,
50 SC_TEXTURESTAGE,
51 SC_TRANSFORM,
52 SC_VERTEXSHADER,
53 SC_SHADERCONST,
54 SC_UNKNOWN,
57 enum MATERIAL_TYPE
59 MT_DIFFUSE,
60 MT_AMBIENT,
61 MT_SPECULAR,
62 MT_EMISSIVE,
63 MT_POWER,
66 enum LIGHT_TYPE
68 LT_TYPE,
69 LT_DIFFUSE,
70 LT_SPECULAR,
71 LT_AMBIENT,
72 LT_POSITION,
73 LT_DIRECTION,
74 LT_RANGE,
75 LT_FALLOFF,
76 LT_ATTENUATION0,
77 LT_ATTENUATION1,
78 LT_ATTENUATION2,
79 LT_THETA,
80 LT_PHI,
83 enum SHADER_CONSTANT_TYPE
85 SCT_VSFLOAT,
86 SCT_VSBOOL,
87 SCT_VSINT,
88 SCT_PSFLOAT,
89 SCT_PSBOOL,
90 SCT_PSINT,
93 enum STATE_TYPE
95 ST_CONSTANT,
96 ST_PARAMETER,
97 ST_FXLC,
98 ST_ARRAY_SELECTOR,
101 struct d3dx_object
103 UINT size;
104 void *data;
105 struct d3dx_parameter *param;
108 struct d3dx_state
110 UINT operation;
111 UINT index;
112 enum STATE_TYPE type;
113 struct d3dx_parameter parameter;
116 struct d3dx_sampler
118 UINT state_count;
119 struct d3dx_state *states;
122 struct d3dx_pass
124 char *name;
125 UINT state_count;
126 UINT annotation_count;
128 struct d3dx_state *states;
129 struct d3dx_parameter *annotations;
131 ULONG64 update_version;
134 struct d3dx_technique
136 char *name;
137 UINT pass_count;
138 UINT annotation_count;
140 struct d3dx_parameter *annotations;
141 struct d3dx_pass *passes;
143 struct IDirect3DStateBlock9 *saved_state;
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 d3dx_effect_pool *pool;
159 DWORD flags;
161 ULONG64 version_counter;
164 struct ID3DXEffectImpl
166 ID3DXEffect ID3DXEffect_iface;
167 LONG ref;
169 struct d3dx9_base_effect base_effect;
171 struct ID3DXEffectStateManager *manager;
172 struct IDirect3DDevice9 *device;
173 struct ID3DXEffectPool *pool;
174 struct d3dx_technique *active_technique;
175 struct d3dx_pass *active_pass;
176 BOOL started;
177 DWORD begin_flags;
179 D3DLIGHT9 current_light[8];
180 BOOL light_updated[8];
181 D3DMATERIAL9 current_material;
182 BOOL material_updated;
185 #define INITIAL_SHARED_DATA_SIZE 4
187 struct d3dx_effect_pool
189 ID3DXEffectPool ID3DXEffectPool_iface;
190 LONG refcount;
192 struct d3dx_shared_data *shared_data;
193 unsigned int size;
195 ULONG64 version_counter;
198 struct ID3DXEffectCompilerImpl
200 ID3DXEffectCompiler ID3DXEffectCompiler_iface;
201 LONG ref;
203 struct d3dx9_base_effect base_effect;
206 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *parameters,
207 const char *name);
208 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
209 const char *data, const char **ptr, struct d3dx_object *objects);
210 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child);
212 typedef BOOL (*walk_parameter_dep_func)(void *data, struct d3dx_parameter *param);
214 static const struct
216 enum STATE_CLASS class;
217 UINT op;
218 const char *name;
220 state_table[] =
222 /* Render states */
223 {SC_RENDERSTATE, D3DRS_ZENABLE, "D3DRS_ZENABLE"}, /* 0x0 */
224 {SC_RENDERSTATE, D3DRS_FILLMODE, "D3DRS_FILLMODE"},
225 {SC_RENDERSTATE, D3DRS_SHADEMODE, "D3DRS_SHADEMODE"},
226 {SC_RENDERSTATE, D3DRS_ZWRITEENABLE, "D3DRS_ZWRITEENABLE"},
227 {SC_RENDERSTATE, D3DRS_ALPHATESTENABLE, "D3DRS_ALPHATESTENABLE"},
228 {SC_RENDERSTATE, D3DRS_LASTPIXEL, "D3DRS_LASTPIXEL"},
229 {SC_RENDERSTATE, D3DRS_SRCBLEND, "D3DRS_SRCBLEND"},
230 {SC_RENDERSTATE, D3DRS_DESTBLEND, "D3DRS_DESTBLEND"},
231 {SC_RENDERSTATE, D3DRS_CULLMODE, "D3DRS_CULLMODE"},
232 {SC_RENDERSTATE, D3DRS_ZFUNC, "D3DRS_ZFUNC"},
233 {SC_RENDERSTATE, D3DRS_ALPHAREF, "D3DRS_ALPHAREF"},
234 {SC_RENDERSTATE, D3DRS_ALPHAFUNC, "D3DRS_ALPHAFUNC"},
235 {SC_RENDERSTATE, D3DRS_DITHERENABLE, "D3DRS_DITHERENABLE"},
236 {SC_RENDERSTATE, D3DRS_ALPHABLENDENABLE, "D3DRS_ALPHABLENDENABLE"},
237 {SC_RENDERSTATE, D3DRS_FOGENABLE, "D3DRS_FOGENABLE"},
238 {SC_RENDERSTATE, D3DRS_SPECULARENABLE, "D3DRS_SPECULARENABLE"},
239 {SC_RENDERSTATE, D3DRS_FOGCOLOR, "D3DRS_FOGCOLOR"}, /* 0x10 */
240 {SC_RENDERSTATE, D3DRS_FOGTABLEMODE, "D3DRS_FOGTABLEMODE"},
241 {SC_RENDERSTATE, D3DRS_FOGSTART, "D3DRS_FOGSTART"},
242 {SC_RENDERSTATE, D3DRS_FOGEND, "D3DRS_FOGEND"},
243 {SC_RENDERSTATE, D3DRS_FOGDENSITY, "D3DRS_FOGDENSITY"},
244 {SC_RENDERSTATE, D3DRS_RANGEFOGENABLE, "D3DRS_RANGEFOGENABLE"},
245 {SC_RENDERSTATE, D3DRS_STENCILENABLE, "D3DRS_STENCILENABLE"},
246 {SC_RENDERSTATE, D3DRS_STENCILFAIL, "D3DRS_STENCILFAIL"},
247 {SC_RENDERSTATE, D3DRS_STENCILZFAIL, "D3DRS_STENCILZFAIL"},
248 {SC_RENDERSTATE, D3DRS_STENCILPASS, "D3DRS_STENCILPASS"},
249 {SC_RENDERSTATE, D3DRS_STENCILFUNC, "D3DRS_STENCILFUNC"},
250 {SC_RENDERSTATE, D3DRS_STENCILREF, "D3DRS_STENCILREF"},
251 {SC_RENDERSTATE, D3DRS_STENCILMASK, "D3DRS_STENCILMASK"},
252 {SC_RENDERSTATE, D3DRS_STENCILWRITEMASK, "D3DRS_STENCILWRITEMASK"},
253 {SC_RENDERSTATE, D3DRS_TEXTUREFACTOR, "D3DRS_TEXTUREFACTOR"},
254 {SC_RENDERSTATE, D3DRS_WRAP0, "D3DRS_WRAP0"},
255 {SC_RENDERSTATE, D3DRS_WRAP1, "D3DRS_WRAP1"}, /* 0x20 */
256 {SC_RENDERSTATE, D3DRS_WRAP2, "D3DRS_WRAP2"},
257 {SC_RENDERSTATE, D3DRS_WRAP3, "D3DRS_WRAP3"},
258 {SC_RENDERSTATE, D3DRS_WRAP4, "D3DRS_WRAP4"},
259 {SC_RENDERSTATE, D3DRS_WRAP5, "D3DRS_WRAP5"},
260 {SC_RENDERSTATE, D3DRS_WRAP6, "D3DRS_WRAP6"},
261 {SC_RENDERSTATE, D3DRS_WRAP7, "D3DRS_WRAP7"},
262 {SC_RENDERSTATE, D3DRS_WRAP8, "D3DRS_WRAP8"},
263 {SC_RENDERSTATE, D3DRS_WRAP9, "D3DRS_WRAP9"},
264 {SC_RENDERSTATE, D3DRS_WRAP10, "D3DRS_WRAP10"},
265 {SC_RENDERSTATE, D3DRS_WRAP11, "D3DRS_WRAP11"},
266 {SC_RENDERSTATE, D3DRS_WRAP12, "D3DRS_WRAP12"},
267 {SC_RENDERSTATE, D3DRS_WRAP13, "D3DRS_WRAP13"},
268 {SC_RENDERSTATE, D3DRS_WRAP14, "D3DRS_WRAP14"},
269 {SC_RENDERSTATE, D3DRS_WRAP15, "D3DRS_WRAP15"},
270 {SC_RENDERSTATE, D3DRS_CLIPPING, "D3DRS_CLIPPING"},
271 {SC_RENDERSTATE, D3DRS_LIGHTING, "D3DRS_LIGHTING"}, /* 0x30 */
272 {SC_RENDERSTATE, D3DRS_AMBIENT, "D3DRS_AMBIENT"},
273 {SC_RENDERSTATE, D3DRS_FOGVERTEXMODE, "D3DRS_FOGVERTEXMODE"},
274 {SC_RENDERSTATE, D3DRS_COLORVERTEX, "D3DRS_COLORVERTEX"},
275 {SC_RENDERSTATE, D3DRS_LOCALVIEWER, "D3DRS_LOCALVIEWER"},
276 {SC_RENDERSTATE, D3DRS_NORMALIZENORMALS, "D3DRS_NORMALIZENORMALS"},
277 {SC_RENDERSTATE, D3DRS_DIFFUSEMATERIALSOURCE, "D3DRS_DIFFUSEMATERIALSOURCE"},
278 {SC_RENDERSTATE, D3DRS_SPECULARMATERIALSOURCE, "D3DRS_SPECULARMATERIALSOURCE"},
279 {SC_RENDERSTATE, D3DRS_AMBIENTMATERIALSOURCE, "D3DRS_AMBIENTMATERIALSOURCE"},
280 {SC_RENDERSTATE, D3DRS_EMISSIVEMATERIALSOURCE, "D3DRS_EMISSIVEMATERIALSOURCE"},
281 {SC_RENDERSTATE, D3DRS_VERTEXBLEND, "D3DRS_VERTEXBLEND"},
282 {SC_RENDERSTATE, D3DRS_CLIPPLANEENABLE, "D3DRS_CLIPPLANEENABLE"},
283 {SC_RENDERSTATE, D3DRS_POINTSIZE, "D3DRS_POINTSIZE"},
284 {SC_RENDERSTATE, D3DRS_POINTSIZE_MIN, "D3DRS_POINTSIZE_MIN"},
285 {SC_RENDERSTATE, D3DRS_POINTSIZE_MAX, "D3DRS_POINTSIZE_MAX"},
286 {SC_RENDERSTATE, D3DRS_POINTSPRITEENABLE, "D3DRS_POINTSPRITEENABLE"},
287 {SC_RENDERSTATE, D3DRS_POINTSCALEENABLE, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
288 {SC_RENDERSTATE, D3DRS_POINTSCALE_A, "D3DRS_POINTSCALE_A"},
289 {SC_RENDERSTATE, D3DRS_POINTSCALE_B, "D3DRS_POINTSCALE_B"},
290 {SC_RENDERSTATE, D3DRS_POINTSCALE_C, "D3DRS_POINTSCALE_C"},
291 {SC_RENDERSTATE, D3DRS_MULTISAMPLEANTIALIAS, "D3DRS_MULTISAMPLEANTIALIAS"},
292 {SC_RENDERSTATE, D3DRS_MULTISAMPLEMASK, "D3DRS_MULTISAMPLEMASK"},
293 {SC_RENDERSTATE, D3DRS_PATCHEDGESTYLE, "D3DRS_PATCHEDGESTYLE"},
294 {SC_RENDERSTATE, D3DRS_DEBUGMONITORTOKEN, "D3DRS_DEBUGMONITORTOKEN"},
295 {SC_RENDERSTATE, D3DRS_INDEXEDVERTEXBLENDENABLE, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
296 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE, "D3DRS_COLORWRITEENABLE"},
297 {SC_RENDERSTATE, D3DRS_TWEENFACTOR, "D3DRS_TWEENFACTOR"},
298 {SC_RENDERSTATE, D3DRS_BLENDOP, "D3DRS_BLENDOP"},
299 {SC_RENDERSTATE, D3DRS_POSITIONDEGREE, "D3DRS_POSITIONDEGREE"},
300 {SC_RENDERSTATE, D3DRS_NORMALDEGREE, "D3DRS_NORMALDEGREE"},
301 {SC_RENDERSTATE, D3DRS_SCISSORTESTENABLE, "D3DRS_SCISSORTESTENABLE"},
302 {SC_RENDERSTATE, D3DRS_SLOPESCALEDEPTHBIAS, "D3DRS_SLOPESCALEDEPTHBIAS"},
303 {SC_RENDERSTATE, D3DRS_ANTIALIASEDLINEENABLE, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
304 {SC_RENDERSTATE, D3DRS_MINTESSELLATIONLEVEL, "D3DRS_MINTESSELLATIONLEVEL"},
305 {SC_RENDERSTATE, D3DRS_MAXTESSELLATIONLEVEL, "D3DRS_MAXTESSELLATIONLEVEL"},
306 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_X, "D3DRS_ADAPTIVETESS_X"},
307 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Y, "D3DRS_ADAPTIVETESS_Y"},
308 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Z, "D3DRS_ADAPTIVETESS_Z"},
309 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_W, "D3DRS_ADAPTIVETESS_W"},
310 {SC_RENDERSTATE, D3DRS_ENABLEADAPTIVETESSELLATION, "D3DRS_ENABLEADAPTIVETESSELLATION"},
311 {SC_RENDERSTATE, D3DRS_TWOSIDEDSTENCILMODE, "D3DRS_TWOSIDEDSTENCILMODE"},
312 {SC_RENDERSTATE, D3DRS_CCW_STENCILFAIL, "D3DRS_CCW_STENCILFAIL"},
313 {SC_RENDERSTATE, D3DRS_CCW_STENCILZFAIL, "D3DRS_CCW_STENCILZFAIL"},
314 {SC_RENDERSTATE, D3DRS_CCW_STENCILPASS, "D3DRS_CCW_STENCILPASS"},
315 {SC_RENDERSTATE, D3DRS_CCW_STENCILFUNC, "D3DRS_CCW_STENCILFUNC"},
316 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE1, "D3DRS_COLORWRITEENABLE1"},
317 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE2, "D3DRS_COLORWRITEENABLE2"},
318 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE3, "D3DRS_COLORWRITEENABLE3"},
319 {SC_RENDERSTATE, D3DRS_BLENDFACTOR, "D3DRS_BLENDFACTOR"}, /* 0x60 */
320 {SC_RENDERSTATE, D3DRS_SRGBWRITEENABLE, "D3DRS_SRGBWRITEENABLE"},
321 {SC_RENDERSTATE, D3DRS_DEPTHBIAS, "D3DRS_DEPTHBIAS"},
322 {SC_RENDERSTATE, D3DRS_SEPARATEALPHABLENDENABLE, "D3DRS_SEPARATEALPHABLENDENABLE"},
323 {SC_RENDERSTATE, D3DRS_SRCBLENDALPHA, "D3DRS_SRCBLENDALPHA"},
324 {SC_RENDERSTATE, D3DRS_DESTBLENDALPHA, "D3DRS_DESTBLENDALPHA"},
325 {SC_RENDERSTATE, D3DRS_BLENDOPALPHA, "D3DRS_BLENDOPALPHA"},
326 /* Texture stages */
327 {SC_TEXTURESTAGE, D3DTSS_COLOROP, "D3DTSS_COLOROP"},
328 {SC_TEXTURESTAGE, D3DTSS_COLORARG0, "D3DTSS_COLORARG0"},
329 {SC_TEXTURESTAGE, D3DTSS_COLORARG1, "D3DTSS_COLORARG1"},
330 {SC_TEXTURESTAGE, D3DTSS_COLORARG2, "D3DTSS_COLORARG2"},
331 {SC_TEXTURESTAGE, D3DTSS_ALPHAOP, "D3DTSS_ALPHAOP"},
332 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG0, "D3DTSS_ALPHAARG0"},
333 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG1, "D3DTSS_ALPHAARG1"},
334 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG2, "D3DTSS_ALPHAARG2"},
335 {SC_TEXTURESTAGE, D3DTSS_RESULTARG, "D3DTSS_RESULTARG"},
336 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT00, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
337 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT01, "D3DTSS_BUMPENVMAT01"},
338 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT10, "D3DTSS_BUMPENVMAT10"},
339 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT11, "D3DTSS_BUMPENVMAT11"},
340 {SC_TEXTURESTAGE, D3DTSS_TEXCOORDINDEX, "D3DTSS_TEXCOORDINDEX"},
341 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLSCALE, "D3DTSS_BUMPENVLSCALE"},
342 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLOFFSET, "D3DTSS_BUMPENVLOFFSET"},
343 {SC_TEXTURESTAGE, D3DTSS_TEXTURETRANSFORMFLAGS, "D3DTSS_TEXTURETRANSFORMFLAGS"},
344 {SC_TEXTURESTAGE, D3DTSS_CONSTANT, "D3DTSS_CONSTANT"},
345 /* NPatchMode */
346 {SC_NPATCHMODE, 0, "NPatchMode"},
347 /* FVF */
348 {SC_FVF, 0, "FVF"},
349 /* Transform */
350 {SC_TRANSFORM, D3DTS_PROJECTION, "D3DTS_PROJECTION"},
351 {SC_TRANSFORM, D3DTS_VIEW, "D3DTS_VIEW"},
352 {SC_TRANSFORM, D3DTS_WORLD, "D3DTS_WORLD"},
353 {SC_TRANSFORM, D3DTS_TEXTURE0, "D3DTS_TEXTURE0"},
354 /* Material */
355 {SC_MATERIAL, MT_DIFFUSE, "MaterialDiffuse"},
356 {SC_MATERIAL, MT_AMBIENT, "MaterialAmbient"}, /* 0x80 */
357 {SC_MATERIAL, MT_SPECULAR, "MaterialSpecular"},
358 {SC_MATERIAL, MT_EMISSIVE, "MaterialEmissive"},
359 {SC_MATERIAL, MT_POWER, "MaterialPower"},
360 /* Light */
361 {SC_LIGHT, LT_TYPE, "LightType"},
362 {SC_LIGHT, LT_DIFFUSE, "LightDiffuse"},
363 {SC_LIGHT, LT_SPECULAR, "LightSpecular"},
364 {SC_LIGHT, LT_AMBIENT, "LightAmbient"},
365 {SC_LIGHT, LT_POSITION, "LightPosition"},
366 {SC_LIGHT, LT_DIRECTION, "LightDirection"},
367 {SC_LIGHT, LT_RANGE, "LightRange"},
368 {SC_LIGHT, LT_FALLOFF, "LightFallOff"},
369 {SC_LIGHT, LT_ATTENUATION0, "LightAttenuation0"},
370 {SC_LIGHT, LT_ATTENUATION1, "LightAttenuation1"},
371 {SC_LIGHT, LT_ATTENUATION2, "LightAttenuation2"},
372 {SC_LIGHT, LT_THETA, "LightTheta"},
373 {SC_LIGHT, LT_PHI, "LightPhi"}, /* 0x90 */
374 /* Lightenable */
375 {SC_LIGHTENABLE, 0, "LightEnable"},
376 /* Vertexshader */
377 {SC_VERTEXSHADER, 0, "Vertexshader"},
378 /* Pixelshader */
379 {SC_PIXELSHADER, 0, "Pixelshader"},
380 /* Shader constants */
381 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstantF"},
382 {SC_SHADERCONST, SCT_VSBOOL, "VertexShaderConstantB"},
383 {SC_SHADERCONST, SCT_VSINT, "VertexShaderConstantI"},
384 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant"},
385 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant1"},
386 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant2"},
387 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant3"},
388 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant4"},
389 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstantF"},
390 {SC_SHADERCONST, SCT_PSBOOL, "PixelShaderConstantB"},
391 {SC_SHADERCONST, SCT_PSINT, "PixelShaderConstantI"},
392 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant"},
393 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant1"}, /* 0xa0 */
394 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant2"},
395 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant3"},
396 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant4"},
397 /* Texture */
398 {SC_TEXTURE, 0, "Texture"},
399 /* Sampler states */
400 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSU, "AddressU"},
401 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSV, "AddressV"},
402 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSW, "AddressW"},
403 {SC_SAMPLERSTATE, D3DSAMP_BORDERCOLOR, "BorderColor"},
404 {SC_SAMPLERSTATE, D3DSAMP_MAGFILTER, "MagFilter"},
405 {SC_SAMPLERSTATE, D3DSAMP_MINFILTER, "MinFilter"},
406 {SC_SAMPLERSTATE, D3DSAMP_MIPFILTER, "MipFilter"},
407 {SC_SAMPLERSTATE, D3DSAMP_MIPMAPLODBIAS, "MipMapLodBias"},
408 {SC_SAMPLERSTATE, D3DSAMP_MAXMIPLEVEL, "MaxMipLevel"},
409 {SC_SAMPLERSTATE, D3DSAMP_MAXANISOTROPY, "MaxAnisotropy"},
410 {SC_SAMPLERSTATE, D3DSAMP_SRGBTEXTURE, "SRGBTexture"},
411 {SC_SAMPLERSTATE, D3DSAMP_ELEMENTINDEX, "ElementIndex"}, /* 0xb0 */
412 {SC_SAMPLERSTATE, D3DSAMP_DMAPOFFSET, "DMAPOffset"},
413 /* Set sampler */
414 {SC_SETSAMPLER, 0, "Sampler"},
417 static inline void read_dword(const char **ptr, DWORD *d)
419 memcpy(d, *ptr, sizeof(*d));
420 *ptr += sizeof(*d);
423 static void skip_dword_unknown(const char **ptr, unsigned int count)
425 unsigned int i;
426 DWORD d;
428 WARN("Skipping %u unknown DWORDs:\n", count);
429 for (i = 0; i < count; ++i)
431 read_dword(ptr, &d);
432 WARN("\t0x%08x\n", d);
436 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
438 return (D3DXHANDLE)parameter;
441 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
443 return (D3DXHANDLE)technique;
446 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
448 return (D3DXHANDLE)pass;
451 static struct d3dx_technique *get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
453 UINT i;
455 if (!name) return NULL;
457 for (i = 0; i < base->technique_count; ++i)
459 if (!strcmp(base->techniques[i].name, name))
460 return &base->techniques[i];
463 return NULL;
466 static struct d3dx_technique *get_valid_technique(struct d3dx9_base_effect *base, D3DXHANDLE technique)
468 unsigned int i;
470 for (i = 0; i < base->technique_count; ++i)
472 if (get_technique_handle(&base->techniques[i]) == technique)
473 return &base->techniques[i];
476 return get_technique_by_name(base, technique);
479 static struct d3dx_pass *get_valid_pass(struct d3dx9_base_effect *base, D3DXHANDLE pass)
481 unsigned int i, k;
483 for (i = 0; i < base->technique_count; ++i)
485 struct d3dx_technique *technique = &base->techniques[i];
487 for (k = 0; k < technique->pass_count; ++k)
489 if (get_pass_handle(&technique->passes[k]) == pass)
490 return &technique->passes[k];
494 return NULL;
497 static struct d3dx_parameter *get_valid_parameter(struct d3dx9_base_effect *base, D3DXHANDLE parameter)
499 struct d3dx_parameter *handle_param = (struct d3dx_parameter *)parameter;
501 if (handle_param && !strncmp(handle_param->magic_string, parameter_magic_string,
502 sizeof(parameter_magic_string)))
503 return handle_param;
505 return base->flags & D3DXFX_LARGEADDRESSAWARE ? NULL : get_parameter_by_name(base, NULL, parameter);
508 static void free_state(struct d3dx_state *state)
510 free_parameter(&state->parameter, FALSE, FALSE);
513 static void free_object(struct d3dx_object *object)
515 HeapFree(GetProcessHeap(), 0, object->data);
518 static void free_sampler(struct d3dx_sampler *sampler)
520 UINT i;
522 for (i = 0; i < sampler->state_count; ++i)
524 free_state(&sampler->states[i]);
526 HeapFree(GetProcessHeap(), 0, sampler->states);
529 static void d3dx_pool_release_shared_parameter(struct d3dx_parameter *param);
531 static void free_parameter_data(struct d3dx_parameter *param, BOOL child)
533 if (!param->data)
534 return;
535 if (param->class == D3DXPC_OBJECT && !param->element_count)
537 switch (param->type)
539 case D3DXPT_STRING:
540 HeapFree(GetProcessHeap(), 0, *(char **)param->data);
541 break;
543 case D3DXPT_TEXTURE:
544 case D3DXPT_TEXTURE1D:
545 case D3DXPT_TEXTURE2D:
546 case D3DXPT_TEXTURE3D:
547 case D3DXPT_TEXTURECUBE:
548 case D3DXPT_PIXELSHADER:
549 case D3DXPT_VERTEXSHADER:
550 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
551 break;
553 case D3DXPT_SAMPLER:
554 case D3DXPT_SAMPLER1D:
555 case D3DXPT_SAMPLER2D:
556 case D3DXPT_SAMPLER3D:
557 case D3DXPT_SAMPLERCUBE:
558 free_sampler((struct d3dx_sampler *)param->data);
559 break;
561 default:
562 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
563 break;
566 if (!child)
567 HeapFree(GetProcessHeap(), 0, param->data);
570 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child)
572 unsigned int i;
574 TRACE("Free parameter %p, name %s, type %s, element %#x, child %#x.\n", param, param->name,
575 debug_d3dxparameter_type(param->type), element, child);
577 if (param->param_eval)
578 d3dx_free_param_eval(param->param_eval);
580 if (param->annotations)
582 for (i = 0; i < param->annotation_count; ++i)
583 free_parameter(&param->annotations[i], FALSE, FALSE);
584 HeapFree(GetProcessHeap(), 0, param->annotations);
587 d3dx_pool_release_shared_parameter(param);
589 if (param->members)
591 unsigned int count = param->element_count ? param->element_count : param->member_count;
593 for (i = 0; i < count; ++i)
594 free_parameter(&param->members[i], param->element_count != 0, TRUE);
595 HeapFree(GetProcessHeap(), 0, param->members);
598 free_parameter_data(param, child);
600 /* only the parent has to release name and semantic */
601 if (!element)
603 HeapFree(GetProcessHeap(), 0, param->name);
604 HeapFree(GetProcessHeap(), 0, param->semantic);
608 static void free_pass(struct d3dx_pass *pass)
610 unsigned int i;
612 TRACE("Free pass %p\n", pass);
614 if (!pass)
615 return;
617 if (pass->annotations)
619 for (i = 0; i < pass->annotation_count; ++i)
620 free_parameter(&pass->annotations[i], FALSE, FALSE);
621 HeapFree(GetProcessHeap(), 0, pass->annotations);
622 pass->annotations = NULL;
625 if (pass->states)
627 for (i = 0; i < pass->state_count; ++i)
628 free_state(&pass->states[i]);
629 HeapFree(GetProcessHeap(), 0, pass->states);
630 pass->states = NULL;
633 HeapFree(GetProcessHeap(), 0, pass->name);
634 pass->name = NULL;
637 static void free_technique(struct d3dx_technique *technique)
639 unsigned int i;
641 TRACE("Free technique %p\n", technique);
643 if (!technique)
644 return;
646 if (technique->saved_state)
648 IDirect3DStateBlock9_Release(technique->saved_state);
649 technique->saved_state = NULL;
652 if (technique->annotations)
654 for (i = 0; i < technique->annotation_count; ++i)
655 free_parameter(&technique->annotations[i], FALSE, FALSE);
656 HeapFree(GetProcessHeap(), 0, technique->annotations);
657 technique->annotations = NULL;
660 if (technique->passes)
662 for (i = 0; i < technique->pass_count; ++i)
663 free_pass(&technique->passes[i]);
664 HeapFree(GetProcessHeap(), 0, technique->passes);
665 technique->passes = NULL;
668 HeapFree(GetProcessHeap(), 0, technique->name);
669 technique->name = NULL;
672 static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
674 unsigned int i;
676 TRACE("base %p.\n", base);
678 if (base->parameters)
680 for (i = 0; i < base->parameter_count; ++i)
681 free_parameter(&base->parameters[i], FALSE, FALSE);
682 HeapFree(GetProcessHeap(), 0, base->parameters);
683 base->parameters = NULL;
686 if (base->techniques)
688 for (i = 0; i < base->technique_count; ++i)
689 free_technique(&base->techniques[i]);
690 HeapFree(GetProcessHeap(), 0, base->techniques);
691 base->techniques = NULL;
694 if (base->objects)
696 for (i = 0; i < base->object_count; ++i)
698 free_object(&base->objects[i]);
700 HeapFree(GetProcessHeap(), 0, base->objects);
701 base->objects = NULL;
705 static void free_effect(struct ID3DXEffectImpl *effect)
707 TRACE("Free effect %p\n", effect);
709 d3dx9_base_effect_cleanup(&effect->base_effect);
711 if (effect->pool)
713 effect->pool->lpVtbl->Release(effect->pool);
716 if (effect->manager)
718 IUnknown_Release(effect->manager);
721 IDirect3DDevice9_Release(effect->device);
724 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
726 TRACE("Free effect compiler %p\n", compiler);
728 d3dx9_base_effect_cleanup(&compiler->base_effect);
731 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
733 UINT i;
735 for (i = 0; i < 4; ++i)
737 if (i < param->columns)
738 set_number((FLOAT *)vector + i, D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
739 else
740 ((FLOAT *)vector)[i] = 0.0f;
744 static void set_vector(struct d3dx_parameter *param, const D3DXVECTOR4 *vector)
746 UINT i;
748 for (i = 0; i < param->columns; ++i)
750 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
754 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix, BOOL transpose)
756 UINT i, k;
758 for (i = 0; i < 4; ++i)
760 for (k = 0; k < 4; ++k)
762 FLOAT *tmp = transpose ? (FLOAT *)&matrix->u.m[k][i] : (FLOAT *)&matrix->u.m[i][k];
764 if ((i < param->rows) && (k < param->columns))
765 set_number(tmp, D3DXPT_FLOAT, (DWORD *)param->data + i * param->columns + k, param->type);
766 else
767 *tmp = 0.0f;
772 static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
774 UINT i, k;
776 if (param->type == D3DXPT_FLOAT)
778 if (param->columns == 4)
779 memcpy(param->data, matrix->u.m, param->rows * 4 * sizeof(float));
780 else
781 for (i = 0; i < param->rows; ++i)
782 memcpy((float *)param->data + i * param->columns, matrix->u.m + i, param->columns * sizeof(float));
783 return;
786 for (i = 0; i < param->rows; ++i)
788 for (k = 0; k < param->columns; ++k)
790 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
791 &matrix->u.m[i][k], D3DXPT_FLOAT);
796 static void set_matrix_transpose(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
798 UINT i, k;
800 for (i = 0; i < param->rows; ++i)
802 for (k = 0; k < param->columns; ++k)
804 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
805 &matrix->u.m[k][i], D3DXPT_FLOAT);
810 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, const char *name)
812 UINT element;
813 struct d3dx_parameter *temp_parameter;
814 const char *part;
816 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
818 if (!name || !*name) return NULL;
820 element = atoi(name);
821 part = strchr(name, ']') + 1;
823 /* check for empty [] && element range */
824 if ((part - name) > 1 && parameter->element_count > element)
826 temp_parameter = &parameter->members[element];
828 switch (*part++)
830 case '.':
831 return get_parameter_by_name(NULL, temp_parameter, part);
833 case '@':
834 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
836 case '\0':
837 TRACE("Returning parameter %p\n", temp_parameter);
838 return temp_parameter;
840 default:
841 FIXME("Unhandled case \"%c\"\n", *--part);
842 break;
846 TRACE("Parameter not found\n");
847 return NULL;
850 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *annotations,
851 const char *name)
853 UINT i, length;
854 struct d3dx_parameter *temp_parameter;
855 const char *part;
857 TRACE("count %u, annotations %p, name %s\n", count, annotations, debugstr_a(name));
859 if (!name || !*name) return NULL;
861 length = strcspn( name, "[.@" );
862 part = name + length;
864 for (i = 0; i < count; ++i)
866 temp_parameter = &annotations[i];
868 if (!strcmp(temp_parameter->name, name))
870 TRACE("Returning annotation %p\n", temp_parameter);
871 return temp_parameter;
873 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
875 switch (*part++)
877 case '.':
878 return get_parameter_by_name(NULL, temp_parameter, part);
880 case '[':
881 return get_parameter_element_by_name(temp_parameter, part);
883 default:
884 FIXME("Unhandled case \"%c\"\n", *--part);
885 break;
890 TRACE("Annotation not found\n");
891 return NULL;
894 struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
895 struct d3dx_parameter *parameter, const char *name)
897 UINT i, count, length;
898 struct d3dx_parameter *temp_parameter;
899 struct d3dx_parameter *parameters;
900 const char *part;
902 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
904 if (!name || !*name) return NULL;
906 if (!parameter)
908 count = base->parameter_count;
909 parameters = base->parameters;
911 else
913 count = parameter->member_count;
914 parameters = parameter->members;
917 length = strcspn( name, "[.@" );
918 part = name + length;
920 for (i = 0; i < count; i++)
922 temp_parameter = &parameters[i];
924 if (!strcmp(temp_parameter->name, name))
926 TRACE("Returning parameter %p\n", temp_parameter);
927 return temp_parameter;
929 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
931 switch (*part++)
933 case '.':
934 return get_parameter_by_name(NULL, temp_parameter, part);
936 case '@':
937 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
939 case '[':
940 return get_parameter_element_by_name(temp_parameter, part);
942 default:
943 FIXME("Unhandled case \"%c\"\n", *--part);
944 break;
949 TRACE("Parameter not found\n");
950 return NULL;
953 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
955 return (0xfeff0000 | ((major) << 8) | (minor));
958 static HRESULT d3dx9_base_effect_get_desc(struct d3dx9_base_effect *base, D3DXEFFECT_DESC *desc)
960 if (!desc)
962 WARN("Invalid argument specified.\n");
963 return D3DERR_INVALIDCALL;
966 FIXME("partial stub!\n");
968 /* TODO: add creator and function count. */
969 desc->Creator = NULL;
970 desc->Functions = 0;
971 desc->Parameters = base->parameter_count;
972 desc->Techniques = base->technique_count;
974 return D3D_OK;
977 static HRESULT d3dx9_base_effect_get_parameter_desc(struct d3dx9_base_effect *base,
978 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
980 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
982 if (!desc || !param)
984 WARN("Invalid argument specified.\n");
985 return D3DERR_INVALIDCALL;
988 desc->Name = param->name;
989 desc->Semantic = param->semantic;
990 desc->Class = param->class;
991 desc->Type = param->type;
992 desc->Rows = param->rows;
993 desc->Columns = param->columns;
994 desc->Elements = param->element_count;
995 desc->Annotations = param->annotation_count;
996 desc->StructMembers = param->member_count;
997 desc->Flags = param->flags;
998 desc->Bytes = param->bytes;
1000 return D3D_OK;
1003 static HRESULT d3dx9_base_effect_get_technique_desc(struct d3dx9_base_effect *base,
1004 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
1006 struct d3dx_technique *tech = technique ? get_valid_technique(base, technique) : &base->techniques[0];
1008 if (!desc || !tech)
1010 WARN("Invalid argument specified.\n");
1011 return D3DERR_INVALIDCALL;
1014 desc->Name = tech->name;
1015 desc->Passes = tech->pass_count;
1016 desc->Annotations = tech->annotation_count;
1018 return D3D_OK;
1021 static HRESULT d3dx9_get_param_value_ptr(struct d3dx_pass *pass, struct d3dx_state *state,
1022 void **param_value, struct d3dx_parameter **out_param,
1023 BOOL update_all, BOOL *param_dirty)
1025 struct d3dx_parameter *param = &state->parameter;
1027 *param_value = NULL;
1028 *out_param = NULL;
1029 *param_dirty = FALSE;
1031 switch (state->type)
1033 case ST_PARAMETER:
1034 param = param->u.referenced_param;
1035 *param_dirty = is_param_dirty(param, pass->update_version);
1036 /* fallthrough */
1037 case ST_CONSTANT:
1038 *out_param = param;
1039 *param_value = param->data;
1040 return D3D_OK;
1041 case ST_ARRAY_SELECTOR:
1043 unsigned int array_idx;
1044 static const struct d3dx_parameter array_idx_param =
1045 {"", NULL, NULL, NULL, D3DXPC_SCALAR, D3DXPT_INT, 1, 1, 0, 0, 0, 0, sizeof(array_idx)};
1046 HRESULT hr;
1047 struct d3dx_parameter *ref_param, *selected_param;
1049 if (!param->param_eval)
1051 FIXME("Preshader structure is null.\n");
1052 return D3DERR_INVALIDCALL;
1054 /* We override with the update_version of the pass because we want
1055 * to force index recomputation and check for out of bounds. */
1056 if (is_param_eval_input_dirty(param->param_eval, pass->update_version))
1058 if (FAILED(hr = d3dx_evaluate_parameter(param->param_eval, &array_idx_param, &array_idx)))
1059 return hr;
1061 else
1063 array_idx = state->index;
1065 ref_param = param->u.referenced_param;
1066 TRACE("Array index %u, stored array index %u, element_count %u.\n", array_idx, state->index,
1067 ref_param->element_count);
1068 /* According to the tests, native d3dx handles the case of array index evaluated to -1
1069 * in a specific way, always selecting first array element and not returning error. */
1070 if (array_idx == ~0u)
1072 WARN("Array index is -1, setting to 0.\n");
1073 array_idx = 0;
1076 if (array_idx >= ref_param->element_count)
1078 WARN("Computed array index %u is larger than array size %u.\n",
1079 array_idx, ref_param->element_count);
1080 return E_FAIL;
1082 selected_param = &ref_param->members[array_idx];
1083 *param_dirty = state->index != array_idx || is_param_dirty(selected_param, pass->update_version);
1084 state->index = array_idx;
1086 *param_value = selected_param->data;
1087 *out_param = selected_param;
1088 return D3D_OK;
1090 case ST_FXLC:
1091 if (param->param_eval)
1093 *out_param = param;
1094 *param_value = param->data;
1095 /* We check with the update_version of the pass because the
1096 * same preshader might be used by both the vertex and the
1097 * pixel shader (that can happen e.g. for sampler states). */
1098 if (update_all || is_param_eval_input_dirty(param->param_eval, pass->update_version))
1100 *param_dirty = TRUE;
1101 return d3dx_evaluate_parameter(param->param_eval, param, *param_value);
1103 else
1104 return D3D_OK;
1106 else
1108 FIXME("No preshader for FXLC parameter.\n");
1109 return D3DERR_INVALIDCALL;
1112 return E_NOTIMPL;
1115 static HRESULT d3dx9_base_effect_get_pass_desc(struct d3dx9_base_effect *base,
1116 D3DXHANDLE pass_handle, D3DXPASS_DESC *desc)
1118 struct d3dx_pass *pass = get_valid_pass(base, pass_handle);
1119 unsigned int i;
1121 if (!desc || !pass)
1123 WARN("Invalid argument specified.\n");
1124 return D3DERR_INVALIDCALL;
1127 desc->Name = pass->name;
1128 desc->Annotations = pass->annotation_count;
1130 desc->pVertexShaderFunction = NULL;
1131 desc->pPixelShaderFunction = NULL;
1133 if (base->flags & D3DXFX_NOT_CLONEABLE)
1134 return D3D_OK;
1136 for (i = 0; i < pass->state_count; ++i)
1138 struct d3dx_state *state = &pass->states[i];
1140 if (state_table[state->operation].class == SC_VERTEXSHADER
1141 || state_table[state->operation].class == SC_PIXELSHADER)
1143 struct d3dx_parameter *param;
1144 void *param_value;
1145 BOOL param_dirty;
1146 HRESULT hr;
1148 if (FAILED(hr = d3dx9_get_param_value_ptr(pass, &pass->states[i], &param_value, &param,
1149 FALSE, &param_dirty)))
1150 return hr;
1152 if (!param->object_id)
1154 FIXME("Zero object ID in shader parameter.\n");
1155 return E_FAIL;
1158 if (state_table[state->operation].class == SC_VERTEXSHADER)
1159 desc->pVertexShaderFunction = base->objects[param->object_id].data;
1160 else
1161 desc->pPixelShaderFunction = base->objects[param->object_id].data;
1165 return D3D_OK;
1168 static HRESULT d3dx9_base_effect_get_function_desc(struct d3dx9_base_effect *base,
1169 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1171 FIXME("stub!\n");
1173 return E_NOTIMPL;
1176 static D3DXHANDLE d3dx9_base_effect_get_parameter(struct d3dx9_base_effect *base,
1177 D3DXHANDLE parameter, UINT index)
1179 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1181 if (!parameter)
1183 if (index < base->parameter_count)
1185 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1186 return get_parameter_handle(&base->parameters[index]);
1189 else
1191 if (param && !param->element_count && index < param->member_count)
1193 TRACE("Returning parameter %p.\n", &param->members[index]);
1194 return get_parameter_handle(&param->members[index]);
1198 WARN("Parameter not found.\n");
1200 return NULL;
1203 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_name(struct d3dx9_base_effect *base,
1204 D3DXHANDLE parameter, const char *name)
1206 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1207 D3DXHANDLE handle;
1209 if (!name)
1211 handle = get_parameter_handle(param);
1212 TRACE("Returning parameter %p.\n", handle);
1213 return handle;
1216 handle = get_parameter_handle(get_parameter_by_name(base, param, name));
1217 TRACE("Returning parameter %p.\n", handle);
1219 return handle;
1222 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_semantic(struct d3dx9_base_effect *base,
1223 D3DXHANDLE parameter, const char *semantic)
1225 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1226 struct d3dx_parameter *temp_param;
1227 UINT i;
1229 if (!parameter)
1231 for (i = 0; i < base->parameter_count; ++i)
1233 temp_param = &base->parameters[i];
1235 if (!temp_param->semantic)
1237 if (!semantic)
1239 TRACE("Returning parameter %p\n", temp_param);
1240 return get_parameter_handle(temp_param);
1242 continue;
1245 if (!strcasecmp(temp_param->semantic, semantic))
1247 TRACE("Returning parameter %p\n", temp_param);
1248 return get_parameter_handle(temp_param);
1252 else if (param)
1254 for (i = 0; i < param->member_count; ++i)
1256 temp_param = &param->members[i];
1258 if (!temp_param->semantic)
1260 if (!semantic)
1262 TRACE("Returning parameter %p\n", temp_param);
1263 return get_parameter_handle(temp_param);
1265 continue;
1268 if (!strcasecmp(temp_param->semantic, semantic))
1270 TRACE("Returning parameter %p\n", temp_param);
1271 return get_parameter_handle(temp_param);
1276 WARN("Parameter not found.\n");
1278 return NULL;
1281 static D3DXHANDLE d3dx9_base_effect_get_parameter_element(struct d3dx9_base_effect *base,
1282 D3DXHANDLE parameter, UINT index)
1284 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1286 if (!param)
1288 if (index < base->parameter_count)
1290 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1291 return get_parameter_handle(&base->parameters[index]);
1294 else
1296 if (index < param->element_count)
1298 TRACE("Returning parameter %p.\n", &param->members[index]);
1299 return get_parameter_handle(&param->members[index]);
1303 WARN("Parameter not found.\n");
1305 return NULL;
1308 static D3DXHANDLE d3dx9_base_effect_get_technique(struct d3dx9_base_effect *base, UINT index)
1310 if (index >= base->technique_count)
1312 WARN("Invalid argument specified.\n");
1313 return NULL;
1316 TRACE("Returning technique %p.\n", &base->techniques[index]);
1318 return get_technique_handle(&base->techniques[index]);
1321 static D3DXHANDLE d3dx9_base_effect_get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
1323 struct d3dx_technique *tech = get_technique_by_name(base, name);
1325 if (tech)
1327 D3DXHANDLE t = get_technique_handle(tech);
1328 TRACE("Returning technique %p\n", t);
1329 return t;
1332 WARN("Technique not found.\n");
1334 return NULL;
1337 static D3DXHANDLE d3dx9_base_effect_get_pass(struct d3dx9_base_effect *base,
1338 D3DXHANDLE technique, UINT index)
1340 struct d3dx_technique *tech = get_valid_technique(base, technique);
1342 if (tech && index < tech->pass_count)
1344 TRACE("Returning pass %p\n", &tech->passes[index]);
1345 return get_pass_handle(&tech->passes[index]);
1348 WARN("Pass not found.\n");
1350 return NULL;
1353 static D3DXHANDLE d3dx9_base_effect_get_pass_by_name(struct d3dx9_base_effect *base,
1354 D3DXHANDLE technique, const char *name)
1356 struct d3dx_technique *tech = get_valid_technique(base, technique);
1358 if (tech && name)
1360 unsigned int i;
1362 for (i = 0; i < tech->pass_count; ++i)
1364 struct d3dx_pass *pass = &tech->passes[i];
1366 if (!strcmp(pass->name, name))
1368 TRACE("Returning pass %p\n", pass);
1369 return get_pass_handle(pass);
1374 WARN("Pass not found.\n");
1376 return NULL;
1379 static D3DXHANDLE d3dx9_base_effect_get_function(struct d3dx9_base_effect *base, UINT index)
1381 FIXME("stub!\n");
1383 return NULL;
1386 static D3DXHANDLE d3dx9_base_effect_get_function_by_name(struct d3dx9_base_effect *base, const char *name)
1388 FIXME("stub!\n");
1390 return NULL;
1393 static UINT get_annotation_from_object(struct d3dx9_base_effect *base,
1394 D3DXHANDLE object, struct d3dx_parameter **annotations)
1396 struct d3dx_parameter *param = get_valid_parameter(base, object);
1397 struct d3dx_pass *pass = get_valid_pass(base, object);
1398 struct d3dx_technique *technique = get_valid_technique(base, object);
1400 if (pass)
1402 *annotations = pass->annotations;
1403 return pass->annotation_count;
1405 else if (technique)
1407 *annotations = technique->annotations;
1408 return technique->annotation_count;
1410 else if (param)
1412 *annotations = param->annotations;
1413 return param->annotation_count;
1415 else
1417 FIXME("Functions are not handled, yet!\n");
1418 return 0;
1422 static D3DXHANDLE d3dx9_base_effect_get_annotation(struct d3dx9_base_effect *base,
1423 D3DXHANDLE object, UINT index)
1425 struct d3dx_parameter *annotations = NULL;
1426 UINT annotation_count = 0;
1428 annotation_count = get_annotation_from_object(base, object, &annotations);
1430 if (index < annotation_count)
1432 TRACE("Returning parameter %p\n", &annotations[index]);
1433 return get_parameter_handle(&annotations[index]);
1436 WARN("Annotation not found.\n");
1438 return NULL;
1441 static D3DXHANDLE d3dx9_base_effect_get_annotation_by_name(struct d3dx9_base_effect *base,
1442 D3DXHANDLE object, const char *name)
1444 struct d3dx_parameter *annotation = NULL;
1445 struct d3dx_parameter *annotations = NULL;
1446 UINT annotation_count = 0;
1448 if (!name)
1450 WARN("Invalid argument specified\n");
1451 return NULL;
1454 annotation_count = get_annotation_from_object(base, object, &annotations);
1456 annotation = get_annotation_by_name(annotation_count, annotations, name);
1457 if (annotation)
1459 TRACE("Returning parameter %p\n", annotation);
1460 return get_parameter_handle(annotation);
1463 WARN("Annotation not found.\n");
1465 return NULL;
1468 static BOOL walk_parameter_tree(struct d3dx_parameter *param, walk_parameter_dep_func param_func,
1469 void *data)
1471 unsigned int i;
1472 unsigned int member_count;
1474 if (param_func(data, param))
1475 return TRUE;
1477 member_count = param->element_count ? param->element_count : param->member_count;
1478 for (i = 0; i < member_count; ++i)
1480 if (walk_parameter_tree(&param->members[i], param_func, data))
1481 return TRUE;
1483 return FALSE;
1486 static ULONG64 *get_version_counter_ptr(struct d3dx9_base_effect *base)
1488 return base->pool ? &base->pool->version_counter : &base->version_counter;
1491 static ULONG64 next_effect_update_version(struct d3dx9_base_effect *base)
1493 return next_update_version(get_version_counter_ptr(base));
1496 static void set_dirty(struct d3dx_parameter *param)
1498 struct d3dx_shared_data *shared_data;
1499 struct d3dx_parameter *top_param = param->top_level_param;
1500 ULONG64 new_update_version = next_update_version(top_param->version_counter);
1502 if ((shared_data = top_param->u.shared_data))
1503 shared_data->update_version = new_update_version;
1504 else
1505 top_param->update_version = new_update_version;
1508 static HRESULT set_string(char **param_data, const char *string)
1510 HeapFree(GetProcessHeap(), 0, *param_data);
1511 *param_data = HeapAlloc(GetProcessHeap(), 0, strlen(string) + 1);
1512 if (!*param_data)
1514 ERR("Out of memory.\n");
1515 return E_OUTOFMEMORY;
1517 strcpy(*param_data, string);
1518 return D3D_OK;
1521 static HRESULT d3dx9_base_effect_set_value(struct d3dx9_base_effect *base,
1522 D3DXHANDLE parameter, const void *data, UINT bytes)
1524 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1525 unsigned int i;
1527 if (!param)
1529 WARN("Invalid parameter %p specified\n", parameter);
1530 return D3DERR_INVALIDCALL;
1533 /* samplers don't touch data */
1534 if (param->class == D3DXPC_OBJECT && is_param_type_sampler(param->type))
1536 TRACE("Sampler: returning E_FAIL\n");
1537 return E_FAIL;
1540 if (data && param->bytes <= bytes)
1542 switch (param->type)
1544 case D3DXPT_TEXTURE:
1545 case D3DXPT_TEXTURE1D:
1546 case D3DXPT_TEXTURE2D:
1547 case D3DXPT_TEXTURE3D:
1548 case D3DXPT_TEXTURECUBE:
1549 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1551 IUnknown *unk = ((IUnknown **)data)[i];
1552 if (unk)
1553 IUnknown_AddRef(unk);
1555 unk = ((IUnknown **)param->data)[i];
1556 if (unk)
1557 IUnknown_Release(unk);
1559 /* fallthrough */
1560 case D3DXPT_VOID:
1561 case D3DXPT_BOOL:
1562 case D3DXPT_INT:
1563 case D3DXPT_FLOAT:
1564 TRACE("Copy %u bytes.\n", param->bytes);
1565 memcpy(param->data, data, param->bytes);
1566 set_dirty(param);
1567 break;
1569 case D3DXPT_STRING:
1571 HRESULT hr;
1573 set_dirty(param);
1574 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1576 if (FAILED(hr = set_string(&((char **)param->data)[i], ((const char **)data)[i])))
1577 return hr;
1579 break;
1582 default:
1583 FIXME("Unhandled type %s.\n", debug_d3dxparameter_type(param->type));
1584 break;
1587 return D3D_OK;
1590 WARN("Invalid argument specified\n");
1592 return D3DERR_INVALIDCALL;
1595 static HRESULT d3dx9_base_effect_get_value(struct d3dx9_base_effect *base,
1596 D3DXHANDLE parameter, void *data, UINT bytes)
1598 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1600 if (!param)
1602 WARN("Invalid parameter %p specified\n", parameter);
1603 return D3DERR_INVALIDCALL;
1606 /* samplers don't touch data */
1607 if (param->class == D3DXPC_OBJECT && is_param_type_sampler(param->type))
1609 TRACE("Sampler: returning E_FAIL\n");
1610 return E_FAIL;
1613 if (data && param->bytes <= bytes)
1615 TRACE("Type %s\n", debug_d3dxparameter_type(param->type));
1617 switch (param->type)
1619 case D3DXPT_VOID:
1620 case D3DXPT_BOOL:
1621 case D3DXPT_INT:
1622 case D3DXPT_FLOAT:
1623 case D3DXPT_STRING:
1624 break;
1626 case D3DXPT_VERTEXSHADER:
1627 case D3DXPT_PIXELSHADER:
1628 case D3DXPT_TEXTURE:
1629 case D3DXPT_TEXTURE1D:
1630 case D3DXPT_TEXTURE2D:
1631 case D3DXPT_TEXTURE3D:
1632 case D3DXPT_TEXTURECUBE:
1634 UINT i;
1636 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1638 IUnknown *unk = ((IUnknown **)param->data)[i];
1639 if (unk) IUnknown_AddRef(unk);
1641 break;
1644 default:
1645 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1646 break;
1649 TRACE("Copy %u bytes\n", param->bytes);
1650 memcpy(data, param->data, param->bytes);
1651 return D3D_OK;
1654 WARN("Parameter not found.\n");
1656 return D3DERR_INVALIDCALL;
1659 static HRESULT d3dx9_base_effect_set_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL b)
1661 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1663 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1665 set_number(param->data, param->type, &b, D3DXPT_BOOL);
1666 set_dirty(param);
1667 return D3D_OK;
1670 WARN("Parameter not found.\n");
1672 return D3DERR_INVALIDCALL;
1675 static HRESULT d3dx9_base_effect_get_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL *b)
1677 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1679 if (b && param && !param->element_count && param->rows == 1 && param->columns == 1)
1681 set_number(b, D3DXPT_BOOL, param->data, param->type);
1682 TRACE("Returning %s\n", *b ? "TRUE" : "FALSE");
1683 return D3D_OK;
1686 WARN("Parameter not found.\n");
1688 return D3DERR_INVALIDCALL;
1691 static HRESULT d3dx9_base_effect_set_bool_array(struct d3dx9_base_effect *base,
1692 D3DXHANDLE parameter, const BOOL *b, UINT count)
1694 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1696 if (param)
1698 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1700 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1702 switch (param->class)
1704 case D3DXPC_SCALAR:
1705 case D3DXPC_VECTOR:
1706 case D3DXPC_MATRIX_ROWS:
1707 for (i = 0; i < size; ++i)
1709 /* don't crop the input, use D3DXPT_INT instead of D3DXPT_BOOL */
1710 set_number((DWORD *)param->data + i, param->type, &b[i], D3DXPT_INT);
1712 set_dirty(param);
1713 return D3D_OK;
1715 case D3DXPC_OBJECT:
1716 case D3DXPC_STRUCT:
1717 break;
1719 default:
1720 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1721 break;
1725 WARN("Parameter not found.\n");
1727 return D3DERR_INVALIDCALL;
1730 static HRESULT d3dx9_base_effect_get_bool_array(struct d3dx9_base_effect *base,
1731 D3DXHANDLE parameter, BOOL *b, UINT count)
1733 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1735 if (b && param && (param->class == D3DXPC_SCALAR
1736 || param->class == D3DXPC_VECTOR
1737 || param->class == D3DXPC_MATRIX_ROWS
1738 || param->class == D3DXPC_MATRIX_COLUMNS))
1740 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1742 for (i = 0; i < size; ++i)
1744 set_number(&b[i], D3DXPT_BOOL, (DWORD *)param->data + i, param->type);
1746 return D3D_OK;
1749 WARN("Parameter not found.\n");
1751 return D3DERR_INVALIDCALL;
1754 static HRESULT d3dx9_base_effect_set_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT n)
1756 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1758 if (param && !param->element_count)
1760 if (param->rows == 1 && param->columns == 1)
1762 DWORD value;
1764 set_number(&value, param->type, &n, D3DXPT_INT);
1765 if (value != *(DWORD *)param->data)
1766 set_dirty(param);
1767 *(DWORD *)param->data = value;
1768 return D3D_OK;
1772 * Split the value, if parameter is a vector with dimension 3 or 4.
1774 if (param->type == D3DXPT_FLOAT &&
1775 ((param->class == D3DXPC_VECTOR && param->columns != 2) ||
1776 (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1778 TRACE("Vector fixup\n");
1780 *(FLOAT *)param->data = ((n & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1781 ((FLOAT *)param->data)[1] = ((n & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1782 ((FLOAT *)param->data)[2] = (n & 0xff) * INT_FLOAT_MULTI_INVERSE;
1783 if (param->rows * param->columns > 3)
1785 ((FLOAT *)param->data)[3] = ((n & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1787 set_dirty(param);
1788 return D3D_OK;
1792 WARN("Parameter not found.\n");
1794 return D3DERR_INVALIDCALL;
1797 static HRESULT d3dx9_base_effect_get_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT *n)
1799 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1801 if (n && param && !param->element_count)
1803 if (param->columns == 1 && param->rows == 1)
1805 set_number(n, D3DXPT_INT, param->data, param->type);
1806 TRACE("Returning %i\n", *n);
1807 return D3D_OK;
1810 if (param->type == D3DXPT_FLOAT &&
1811 ((param->class == D3DXPC_VECTOR && param->columns != 2)
1812 || (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1814 TRACE("Vector fixup\n");
1816 /* all components (3,4) are clamped (0,255) and put in the INT */
1817 *n = (INT)(min(max(0.0f, *((FLOAT *)param->data + 2)), 1.0f) * INT_FLOAT_MULTI);
1818 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 1)), 1.0f) * INT_FLOAT_MULTI)) << 8;
1819 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 0)), 1.0f) * INT_FLOAT_MULTI)) << 16;
1820 if (param->columns * param->rows > 3)
1822 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 3)), 1.0f) * INT_FLOAT_MULTI)) << 24;
1825 TRACE("Returning %i\n", *n);
1826 return D3D_OK;
1830 WARN("Parameter not found.\n");
1832 return D3DERR_INVALIDCALL;
1835 static HRESULT d3dx9_base_effect_set_int_array(struct d3dx9_base_effect *base,
1836 D3DXHANDLE parameter, const INT *n, UINT count)
1838 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1840 if (param)
1842 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1844 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1846 switch (param->class)
1848 case D3DXPC_SCALAR:
1849 case D3DXPC_VECTOR:
1850 case D3DXPC_MATRIX_ROWS:
1851 for (i = 0; i < size; ++i)
1853 set_number((DWORD *)param->data + i, param->type, &n[i], D3DXPT_INT);
1855 set_dirty(param);
1856 return D3D_OK;
1858 case D3DXPC_OBJECT:
1859 case D3DXPC_STRUCT:
1860 break;
1862 default:
1863 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1864 break;
1868 WARN("Parameter not found.\n");
1870 return D3DERR_INVALIDCALL;
1873 static HRESULT d3dx9_base_effect_get_int_array(struct d3dx9_base_effect *base,
1874 D3DXHANDLE parameter, INT *n, UINT count)
1876 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1878 if (n && param && (param->class == D3DXPC_SCALAR
1879 || param->class == D3DXPC_VECTOR
1880 || param->class == D3DXPC_MATRIX_ROWS
1881 || param->class == D3DXPC_MATRIX_COLUMNS))
1883 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1885 for (i = 0; i < size; ++i)
1887 set_number(&n[i], D3DXPT_INT, (DWORD *)param->data + i, param->type);
1889 return D3D_OK;
1892 WARN("Parameter not found.\n");
1894 return D3DERR_INVALIDCALL;
1897 static HRESULT d3dx9_base_effect_set_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float f)
1899 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1901 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1903 DWORD value;
1905 set_number(&value, param->type, &f, D3DXPT_FLOAT);
1906 if (value != *(DWORD *)param->data)
1907 set_dirty(param);
1908 *(DWORD *)param->data = value;
1909 return D3D_OK;
1912 WARN("Parameter not found.\n");
1914 return D3DERR_INVALIDCALL;
1917 static HRESULT d3dx9_base_effect_get_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float *f)
1919 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1921 if (f && param && !param->element_count && param->columns == 1 && param->rows == 1)
1923 set_number(f, D3DXPT_FLOAT, (DWORD *)param->data, param->type);
1924 TRACE("Returning %f\n", *f);
1925 return D3D_OK;
1928 WARN("Parameter not found.\n");
1930 return D3DERR_INVALIDCALL;
1933 static HRESULT d3dx9_base_effect_set_float_array(struct d3dx9_base_effect *base,
1934 D3DXHANDLE parameter, const float *f, UINT count)
1936 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1938 if (param)
1940 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1942 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1944 switch (param->class)
1946 case D3DXPC_SCALAR:
1947 case D3DXPC_VECTOR:
1948 case D3DXPC_MATRIX_ROWS:
1949 for (i = 0; i < size; ++i)
1951 set_number((DWORD *)param->data + i, param->type, &f[i], D3DXPT_FLOAT);
1953 set_dirty(param);
1954 return D3D_OK;
1956 case D3DXPC_OBJECT:
1957 case D3DXPC_STRUCT:
1958 break;
1960 default:
1961 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1962 break;
1966 WARN("Parameter not found.\n");
1968 return D3DERR_INVALIDCALL;
1971 static HRESULT d3dx9_base_effect_get_float_array(struct d3dx9_base_effect *base,
1972 D3DXHANDLE parameter, float *f, UINT count)
1974 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1976 if (f && param && (param->class == D3DXPC_SCALAR
1977 || param->class == D3DXPC_VECTOR
1978 || param->class == D3DXPC_MATRIX_ROWS
1979 || param->class == D3DXPC_MATRIX_COLUMNS))
1981 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1983 for (i = 0; i < size; ++i)
1985 set_number(&f[i], D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
1987 return D3D_OK;
1990 WARN("Parameter not found.\n");
1992 return D3DERR_INVALIDCALL;
1995 static HRESULT d3dx9_base_effect_set_vector(struct d3dx9_base_effect *base,
1996 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
1998 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2000 if (param && !param->element_count)
2002 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2004 switch (param->class)
2006 case D3DXPC_SCALAR:
2007 case D3DXPC_VECTOR:
2008 set_dirty(param);
2009 if (param->type == D3DXPT_INT && param->bytes == 4)
2011 DWORD tmp;
2013 TRACE("INT fixup\n");
2014 tmp = (DWORD)(max(min(vector->z, 1.0f), 0.0f) * INT_FLOAT_MULTI);
2015 tmp += ((DWORD)(max(min(vector->y, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 8;
2016 tmp += ((DWORD)(max(min(vector->x, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 16;
2017 tmp += ((DWORD)(max(min(vector->w, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 24;
2019 *(INT *)param->data = tmp;
2020 return D3D_OK;
2022 if (param->type == D3DXPT_FLOAT)
2024 memcpy(param->data, vector, param->columns * sizeof(float));
2025 return D3D_OK;
2028 set_vector(param, vector);
2029 return D3D_OK;
2031 case D3DXPC_MATRIX_ROWS:
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_vector(struct d3dx9_base_effect *base,
2048 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
2050 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2052 if (vector && param && !param->element_count)
2054 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2056 switch (param->class)
2058 case D3DXPC_SCALAR:
2059 case D3DXPC_VECTOR:
2060 if (param->type == D3DXPT_INT && param->bytes == 4)
2062 TRACE("INT fixup\n");
2063 vector->x = (((*(INT *)param->data) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
2064 vector->y = (((*(INT *)param->data) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
2065 vector->z = ((*(INT *)param->data) & 0xff) * INT_FLOAT_MULTI_INVERSE;
2066 vector->w = (((*(INT *)param->data) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
2067 return D3D_OK;
2069 get_vector(param, vector);
2070 return D3D_OK;
2072 case D3DXPC_MATRIX_ROWS:
2073 case D3DXPC_OBJECT:
2074 case D3DXPC_STRUCT:
2075 break;
2077 default:
2078 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2079 break;
2083 WARN("Parameter not found.\n");
2085 return D3DERR_INVALIDCALL;
2088 static HRESULT d3dx9_base_effect_set_vector_array(struct d3dx9_base_effect *base,
2089 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
2091 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2093 if (param && param->element_count && param->element_count >= count)
2095 UINT i;
2097 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2099 switch (param->class)
2101 case D3DXPC_VECTOR:
2102 set_dirty(param);
2103 if (param->type == D3DXPT_FLOAT)
2105 if (param->columns == 4)
2106 memcpy(param->data, vector, count * 4 * sizeof(float));
2107 else
2108 for (i = 0; i < count; ++i)
2109 memcpy((float *)param->data + param->columns * i, vector + i,
2110 param->columns * sizeof(float));
2111 return D3D_OK;
2114 for (i = 0; i < count; ++i)
2116 set_vector(&param->members[i], &vector[i]);
2118 return D3D_OK;
2120 case D3DXPC_SCALAR:
2121 case D3DXPC_MATRIX_ROWS:
2122 case D3DXPC_OBJECT:
2123 case D3DXPC_STRUCT:
2124 break;
2126 default:
2127 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2128 break;
2132 WARN("Parameter not found.\n");
2134 return D3DERR_INVALIDCALL;
2137 static HRESULT d3dx9_base_effect_get_vector_array(struct d3dx9_base_effect *base,
2138 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
2140 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2142 if (!count) return D3D_OK;
2144 if (vector && param && count <= param->element_count)
2146 UINT i;
2148 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2150 switch (param->class)
2152 case D3DXPC_VECTOR:
2153 for (i = 0; i < count; ++i)
2155 get_vector(&param->members[i], &vector[i]);
2157 return D3D_OK;
2159 case D3DXPC_SCALAR:
2160 case D3DXPC_MATRIX_ROWS:
2161 case D3DXPC_OBJECT:
2162 case D3DXPC_STRUCT:
2163 break;
2165 default:
2166 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2167 break;
2171 WARN("Parameter not found.\n");
2173 return D3DERR_INVALIDCALL;
2176 static HRESULT d3dx9_base_effect_set_matrix(struct d3dx9_base_effect *base,
2177 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2179 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2181 if (param && !param->element_count)
2183 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2185 switch (param->class)
2187 case D3DXPC_MATRIX_ROWS:
2188 set_matrix(param, matrix);
2189 set_dirty(param);
2190 return D3D_OK;
2192 case D3DXPC_SCALAR:
2193 case D3DXPC_VECTOR:
2194 case D3DXPC_OBJECT:
2195 case D3DXPC_STRUCT:
2196 break;
2198 default:
2199 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2200 break;
2204 WARN("Parameter not found.\n");
2206 return D3DERR_INVALIDCALL;
2209 static HRESULT d3dx9_base_effect_get_matrix(struct d3dx9_base_effect *base,
2210 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2212 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2214 if (matrix && param && !param->element_count)
2216 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2218 switch (param->class)
2220 case D3DXPC_MATRIX_ROWS:
2221 get_matrix(param, matrix, FALSE);
2222 return D3D_OK;
2224 case D3DXPC_SCALAR:
2225 case D3DXPC_VECTOR:
2226 case D3DXPC_OBJECT:
2227 case D3DXPC_STRUCT:
2228 break;
2230 default:
2231 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2232 break;
2236 WARN("Parameter not found.\n");
2238 return D3DERR_INVALIDCALL;
2241 static HRESULT d3dx9_base_effect_set_matrix_array(struct d3dx9_base_effect *base,
2242 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2244 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2246 if (param && param->element_count >= count)
2248 UINT i;
2250 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2252 switch (param->class)
2254 case D3DXPC_MATRIX_ROWS:
2255 set_dirty(param);
2256 for (i = 0; i < count; ++i)
2258 set_matrix(&param->members[i], &matrix[i]);
2260 return D3D_OK;
2262 case D3DXPC_SCALAR:
2263 case D3DXPC_VECTOR:
2264 case D3DXPC_OBJECT:
2265 case D3DXPC_STRUCT:
2266 break;
2268 default:
2269 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2270 break;
2274 WARN("Parameter not found.\n");
2276 return D3DERR_INVALIDCALL;
2279 static HRESULT d3dx9_base_effect_get_matrix_array(struct d3dx9_base_effect *base,
2280 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2282 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2284 if (!count) return D3D_OK;
2286 if (matrix && param && count <= param->element_count)
2288 UINT i;
2290 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2292 switch (param->class)
2294 case D3DXPC_MATRIX_ROWS:
2295 for (i = 0; i < count; ++i)
2297 get_matrix(&param->members[i], &matrix[i], FALSE);
2299 return D3D_OK;
2301 case D3DXPC_SCALAR:
2302 case D3DXPC_VECTOR:
2303 case D3DXPC_OBJECT:
2304 case D3DXPC_STRUCT:
2305 break;
2307 default:
2308 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2309 break;
2313 WARN("Parameter not found.\n");
2315 return D3DERR_INVALIDCALL;
2318 static HRESULT d3dx9_base_effect_set_matrix_pointer_array(struct d3dx9_base_effect *base,
2319 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2321 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2323 if (param && count <= param->element_count)
2325 UINT i;
2327 switch (param->class)
2329 case D3DXPC_MATRIX_ROWS:
2330 set_dirty(param);
2331 for (i = 0; i < count; ++i)
2333 set_matrix(&param->members[i], matrix[i]);
2335 return D3D_OK;
2337 case D3DXPC_SCALAR:
2338 case D3DXPC_VECTOR:
2339 case D3DXPC_OBJECT:
2340 break;
2342 default:
2343 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2344 break;
2348 WARN("Parameter not found.\n");
2350 return D3DERR_INVALIDCALL;
2353 static HRESULT d3dx9_base_effect_get_matrix_pointer_array(struct d3dx9_base_effect *base,
2354 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2356 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2358 if (!count) return D3D_OK;
2360 if (param && matrix && count <= param->element_count)
2362 UINT i;
2364 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2366 switch (param->class)
2368 case D3DXPC_MATRIX_ROWS:
2369 for (i = 0; i < count; ++i)
2371 get_matrix(&param->members[i], matrix[i], FALSE);
2373 return D3D_OK;
2375 case D3DXPC_SCALAR:
2376 case D3DXPC_VECTOR:
2377 case D3DXPC_OBJECT:
2378 break;
2380 default:
2381 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2382 break;
2386 WARN("Parameter not found.\n");
2388 return D3DERR_INVALIDCALL;
2391 static HRESULT d3dx9_base_effect_set_matrix_transpose(struct d3dx9_base_effect *base,
2392 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2394 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2396 if (param && !param->element_count)
2398 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2400 switch (param->class)
2402 case D3DXPC_MATRIX_ROWS:
2403 set_dirty(param);
2404 set_matrix_transpose(param, matrix);
2405 return D3D_OK;
2407 case D3DXPC_SCALAR:
2408 case D3DXPC_VECTOR:
2409 case D3DXPC_OBJECT:
2410 case D3DXPC_STRUCT:
2411 break;
2413 default:
2414 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2415 break;
2419 WARN("Parameter not found.\n");
2421 return D3DERR_INVALIDCALL;
2424 static HRESULT d3dx9_base_effect_get_matrix_transpose(struct d3dx9_base_effect *base,
2425 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2427 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2429 if (matrix && param && !param->element_count)
2431 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2433 switch (param->class)
2435 case D3DXPC_SCALAR:
2436 case D3DXPC_VECTOR:
2437 get_matrix(param, matrix, FALSE);
2438 return D3D_OK;
2440 case D3DXPC_MATRIX_ROWS:
2441 get_matrix(param, matrix, TRUE);
2442 return D3D_OK;
2444 case D3DXPC_OBJECT:
2445 case D3DXPC_STRUCT:
2446 break;
2448 default:
2449 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2450 break;
2454 WARN("Parameter not found.\n");
2456 return D3DERR_INVALIDCALL;
2459 static HRESULT d3dx9_base_effect_set_matrix_transpose_array(struct d3dx9_base_effect *base,
2460 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2462 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2464 if (param && param->element_count >= count)
2466 UINT i;
2468 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2470 switch (param->class)
2472 case D3DXPC_MATRIX_ROWS:
2473 set_dirty(param);
2474 for (i = 0; i < count; ++i)
2476 set_matrix_transpose(&param->members[i], &matrix[i]);
2478 return D3D_OK;
2480 case D3DXPC_SCALAR:
2481 case D3DXPC_VECTOR:
2482 case D3DXPC_OBJECT:
2483 case D3DXPC_STRUCT:
2484 break;
2486 default:
2487 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2488 break;
2492 WARN("Parameter not found.\n");
2494 return D3DERR_INVALIDCALL;
2497 static HRESULT d3dx9_base_effect_get_matrix_transpose_array(struct d3dx9_base_effect *base,
2498 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2500 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2502 if (!count) return D3D_OK;
2504 if (matrix && param && count <= param->element_count)
2506 UINT i;
2508 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2510 switch (param->class)
2512 case D3DXPC_MATRIX_ROWS:
2513 for (i = 0; i < count; ++i)
2515 get_matrix(&param->members[i], &matrix[i], TRUE);
2517 return D3D_OK;
2519 case D3DXPC_SCALAR:
2520 case D3DXPC_VECTOR:
2521 case D3DXPC_OBJECT:
2522 case D3DXPC_STRUCT:
2523 break;
2525 default:
2526 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2527 break;
2531 WARN("Parameter not found.\n");
2533 return D3DERR_INVALIDCALL;
2536 static HRESULT d3dx9_base_effect_set_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2537 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2539 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2541 if (param && count <= param->element_count)
2543 UINT i;
2545 switch (param->class)
2547 case D3DXPC_MATRIX_ROWS:
2548 set_dirty(param);
2549 for (i = 0; i < count; ++i)
2551 set_matrix_transpose(&param->members[i], matrix[i]);
2553 return D3D_OK;
2555 case D3DXPC_SCALAR:
2556 case D3DXPC_VECTOR:
2557 case D3DXPC_OBJECT:
2558 break;
2560 default:
2561 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2562 break;
2566 WARN("Parameter not found.\n");
2568 return D3DERR_INVALIDCALL;
2571 static HRESULT d3dx9_base_effect_get_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2572 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2574 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2576 if (!count) return D3D_OK;
2578 if (matrix && param && count <= param->element_count)
2580 UINT i;
2582 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2584 switch (param->class)
2586 case D3DXPC_MATRIX_ROWS:
2587 for (i = 0; i < count; ++i)
2589 get_matrix(&param->members[i], matrix[i], TRUE);
2591 return D3D_OK;
2593 case D3DXPC_SCALAR:
2594 case D3DXPC_VECTOR:
2595 case D3DXPC_OBJECT:
2596 break;
2598 default:
2599 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2600 break;
2604 WARN("Parameter not found.\n");
2606 return D3DERR_INVALIDCALL;
2609 static HRESULT d3dx9_base_effect_set_string(struct d3dx9_base_effect *base,
2610 D3DXHANDLE parameter, const char *string)
2612 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2614 if (param && param->type == D3DXPT_STRING)
2616 set_dirty(param);
2617 return set_string(param->data, string);
2620 WARN("Parameter not found.\n");
2622 return D3DERR_INVALIDCALL;
2625 static HRESULT d3dx9_base_effect_get_string(struct d3dx9_base_effect *base,
2626 D3DXHANDLE parameter, const char **string)
2628 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2630 if (string && param && !param->element_count && param->type == D3DXPT_STRING)
2632 *string = *(const char **)param->data;
2633 TRACE("Returning %s.\n", debugstr_a(*string));
2634 return D3D_OK;
2637 WARN("Parameter not found.\n");
2639 return D3DERR_INVALIDCALL;
2642 static HRESULT d3dx9_base_effect_set_texture(struct d3dx9_base_effect *base,
2643 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
2645 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2647 if (param && !param->element_count &&
2648 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2649 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2650 || param->type == D3DXPT_TEXTURECUBE))
2652 struct IDirect3DBaseTexture9 *oltexture = *(struct IDirect3DBaseTexture9 **)param->data;
2654 if (texture == oltexture)
2655 return D3D_OK;
2657 if (texture) IDirect3DBaseTexture9_AddRef(texture);
2658 if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
2660 *(struct IDirect3DBaseTexture9 **)param->data = texture;
2661 set_dirty(param);
2663 return D3D_OK;
2666 WARN("Parameter not found.\n");
2668 return D3DERR_INVALIDCALL;
2671 static HRESULT d3dx9_base_effect_get_texture(struct d3dx9_base_effect *base,
2672 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
2674 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2676 if (texture && param && !param->element_count &&
2677 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2678 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2679 || param->type == D3DXPT_TEXTURECUBE))
2681 *texture = *(struct IDirect3DBaseTexture9 **)param->data;
2682 if (*texture) IDirect3DBaseTexture9_AddRef(*texture);
2683 TRACE("Returning %p\n", *texture);
2684 return D3D_OK;
2687 WARN("Parameter not found.\n");
2689 return D3DERR_INVALIDCALL;
2692 static HRESULT d3dx9_base_effect_get_pixel_shader(struct d3dx9_base_effect *base,
2693 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
2695 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2697 if (shader && param && !param->element_count && param->type == D3DXPT_PIXELSHADER)
2699 if ((*shader = *(struct IDirect3DPixelShader9 **)param->data))
2700 IDirect3DPixelShader9_AddRef(*shader);
2701 TRACE("Returning %p.\n", *shader);
2702 return D3D_OK;
2705 WARN("Parameter not found.\n");
2707 return D3DERR_INVALIDCALL;
2710 static HRESULT d3dx9_base_effect_get_vertex_shader(struct d3dx9_base_effect *base,
2711 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
2713 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2715 if (shader && param && !param->element_count && param->type == D3DXPT_VERTEXSHADER)
2717 if ((*shader = *(struct IDirect3DVertexShader9 **)param->data))
2718 IDirect3DVertexShader9_AddRef(*shader);
2719 TRACE("Returning %p.\n", *shader);
2720 return D3D_OK;
2723 WARN("Parameter not found.\n");
2725 return D3DERR_INVALIDCALL;
2728 static HRESULT d3dx9_base_effect_set_array_range(struct d3dx9_base_effect *base,
2729 D3DXHANDLE parameter, UINT start, UINT end)
2731 FIXME("stub!\n");
2733 return E_NOTIMPL;
2736 static void d3dx9_set_light_parameter(enum LIGHT_TYPE op, D3DLIGHT9 *light, void *value)
2738 static const struct
2740 unsigned int offset;
2741 const char *name;
2743 light_tbl[] =
2745 {FIELD_OFFSET(D3DLIGHT9, Type), "LC_TYPE"},
2746 {FIELD_OFFSET(D3DLIGHT9, Diffuse), "LT_DIFFUSE"},
2747 {FIELD_OFFSET(D3DLIGHT9, Specular), "LT_SPECULAR"},
2748 {FIELD_OFFSET(D3DLIGHT9, Ambient), "LT_AMBIENT"},
2749 {FIELD_OFFSET(D3DLIGHT9, Position), "LT_POSITION"},
2750 {FIELD_OFFSET(D3DLIGHT9, Direction), "LT_DIRECTION"},
2751 {FIELD_OFFSET(D3DLIGHT9, Range), "LT_RANGE"},
2752 {FIELD_OFFSET(D3DLIGHT9, Falloff), "LT_FALLOFF"},
2753 {FIELD_OFFSET(D3DLIGHT9, Attenuation0), "LT_ATTENUATION0"},
2754 {FIELD_OFFSET(D3DLIGHT9, Attenuation1), "LT_ATTENUATION1"},
2755 {FIELD_OFFSET(D3DLIGHT9, Attenuation2), "LT_ATTENUATION2"},
2756 {FIELD_OFFSET(D3DLIGHT9, Theta), "LT_THETA"},
2757 {FIELD_OFFSET(D3DLIGHT9, Phi), "LT_PHI"}
2759 switch (op)
2761 case LT_TYPE:
2762 TRACE("LT_TYPE %u.\n", *(D3DLIGHTTYPE *)value);
2763 light->Type = *(D3DLIGHTTYPE *)value;
2764 break;
2765 case LT_DIFFUSE:
2766 case LT_SPECULAR:
2767 case LT_AMBIENT:
2769 D3DCOLORVALUE c = *(D3DCOLORVALUE *)value;
2771 TRACE("%s (%.8e %.8e %.8e %.8e).\n", light_tbl[op].name, c.r, c.g, c.b, c.a);
2772 *(D3DCOLORVALUE *)((BYTE *)light + light_tbl[op].offset) = c;
2773 break;
2775 case LT_POSITION:
2776 case LT_DIRECTION:
2778 D3DVECTOR v = *(D3DVECTOR *)value;
2780 TRACE("%s (%.8e %.8e %.8e).\n", light_tbl[op].name, v.x, v.y, v.z);
2781 *(D3DVECTOR *)((BYTE *)light + light_tbl[op].offset) = v;
2782 break;
2784 case LT_RANGE:
2785 case LT_FALLOFF:
2786 case LT_ATTENUATION0:
2787 case LT_ATTENUATION1:
2788 case LT_ATTENUATION2:
2789 case LT_THETA:
2790 case LT_PHI:
2792 float v = *(float *)value;
2793 TRACE("%s %.8e.\n", light_tbl[op].name, v);
2794 *(float *)((BYTE *)light + light_tbl[op].offset) = v;
2795 break;
2797 default:
2798 WARN("Unknown light parameter %u.\n", op);
2799 break;
2803 static void d3dx9_set_material_parameter(enum MATERIAL_TYPE op, D3DMATERIAL9 *material, void *value)
2805 static const struct
2807 unsigned int offset;
2808 const char *name;
2810 material_tbl[] =
2812 {FIELD_OFFSET(D3DMATERIAL9, Diffuse), "MT_DIFFUSE"},
2813 {FIELD_OFFSET(D3DMATERIAL9, Ambient), "MT_AMBIENT"},
2814 {FIELD_OFFSET(D3DMATERIAL9, Specular), "MT_SPECULAR"},
2815 {FIELD_OFFSET(D3DMATERIAL9, Emissive), "MT_EMISSIVE"},
2816 {FIELD_OFFSET(D3DMATERIAL9, Power), "MT_POWER"}
2819 switch (op)
2821 case MT_POWER:
2823 float v = *(float *)value;
2825 TRACE("%s %.8e.\n", material_tbl[op].name, v);
2826 material->Power = v;
2827 break;
2829 case MT_DIFFUSE:
2830 case MT_AMBIENT:
2831 case MT_SPECULAR:
2832 case MT_EMISSIVE:
2834 D3DCOLORVALUE c = *(D3DCOLORVALUE *)value;
2836 TRACE("%s, value (%.8e %.8e %.8e %.8e).\n", material_tbl[op].name, c.r, c.g, c.b, c.a);
2837 *(D3DCOLORVALUE *)((BYTE *)material + material_tbl[op].offset) = c;
2838 break;
2840 default:
2841 WARN("Unknown material parameter %u.\n", op);
2842 break;
2846 static HRESULT d3dx_set_shader_const_state(struct ID3DXEffectImpl *effect, enum SHADER_CONSTANT_TYPE op, UINT index,
2847 struct d3dx_parameter *param, void *value_ptr)
2849 static const struct
2851 D3DXPARAMETER_TYPE type;
2852 UINT elem_size;
2853 const char *name;
2855 const_tbl[] =
2857 {D3DXPT_FLOAT, sizeof(float) * 4, "SCT_VSFLOAT"},
2858 {D3DXPT_BOOL, sizeof(BOOL), "SCT_VSBOOL"},
2859 {D3DXPT_INT, sizeof(int) * 4, "SCT_VSINT"},
2860 {D3DXPT_FLOAT, sizeof(float) * 4, "SCT_PSFLOAT"},
2861 {D3DXPT_BOOL, sizeof(BOOL), "SCT_PSBOOL"},
2862 {D3DXPT_INT, sizeof(int) * 4, "SCT_PSINT"},
2864 unsigned int element_count;
2866 if (op < 0 || op > SCT_PSINT)
2868 FIXME("Unknown op %u.\n", op);
2869 return D3DERR_INVALIDCALL;
2871 element_count = param->bytes / const_tbl[op].elem_size;
2872 TRACE("%s, index %u, element_count %u.\n", const_tbl[op].name, index, element_count);
2873 if (param->type != const_tbl[op].type)
2875 FIXME("Unexpected param type %u.\n", param->type);
2876 return D3DERR_INVALIDCALL;
2878 if (param->bytes % const_tbl[op].elem_size != 0)
2880 FIXME("Unexpected param size %u, rows %u, cols %u.\n", param->bytes, param->rows, param->columns);
2881 return D3DERR_INVALIDCALL;
2884 switch (op)
2886 case SCT_VSFLOAT:
2887 return SET_D3D_STATE(effect, SetVertexShaderConstantF, index, (const float *)value_ptr, element_count);
2888 case SCT_VSBOOL:
2889 return SET_D3D_STATE(effect, SetVertexShaderConstantB, index, (const BOOL *)value_ptr, element_count);
2890 case SCT_VSINT:
2891 return SET_D3D_STATE(effect, SetVertexShaderConstantI, index, (const int *)value_ptr, element_count);
2892 case SCT_PSFLOAT:
2893 return SET_D3D_STATE(effect, SetPixelShaderConstantF, index, (const float *)value_ptr, element_count);
2894 case SCT_PSBOOL:
2895 return SET_D3D_STATE(effect, SetPixelShaderConstantB, index, (const BOOL *)value_ptr, element_count);
2896 case SCT_PSINT:
2897 return SET_D3D_STATE(effect, SetPixelShaderConstantI, index, (const int *)value_ptr, element_count);
2899 return D3D_OK;
2902 static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2903 struct d3dx_state *state, unsigned int parent_index, BOOL update_all);
2905 static HRESULT d3dx_set_shader_constants(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2906 struct d3dx_parameter *param, BOOL vs, BOOL update_all)
2908 HRESULT hr, ret;
2909 struct d3dx_parameter **params;
2910 D3DXCONSTANT_DESC *cdesc;
2911 unsigned int parameters_count;
2912 unsigned int i, j;
2914 if (!param->param_eval)
2916 FIXME("param_eval structure is null.\n");
2917 return D3DERR_INVALIDCALL;
2919 if (FAILED(hr = d3dx_param_eval_set_shader_constants(effect->manager, effect->device,
2920 param->param_eval, update_all)))
2921 return hr;
2922 params = param->param_eval->shader_inputs.inputs_param;
2923 cdesc = param->param_eval->shader_inputs.inputs;
2924 parameters_count = param->param_eval->shader_inputs.input_count;
2925 ret = D3D_OK;
2926 for (i = 0; i < parameters_count; ++i)
2928 if (params[i] && params[i]->class == D3DXPC_OBJECT && is_param_type_sampler(params[i]->type))
2930 struct d3dx_sampler *sampler;
2932 sampler = (struct d3dx_sampler *)params[i]->data;
2933 TRACE("sampler %s, register index %u, state count %u.\n", debugstr_a(params[i]->name),
2934 cdesc[i].RegisterIndex, sampler->state_count);
2935 for (j = 0; j < sampler->state_count; ++j)
2937 if (FAILED(hr = d3dx9_apply_state(effect, pass, &sampler->states[j],
2938 cdesc[i].RegisterIndex + (vs ? D3DVERTEXTEXTURESAMPLER0 : 0), update_all)))
2939 ret = hr;
2943 return ret;
2946 static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2947 struct d3dx_state *state, unsigned int parent_index, BOOL update_all)
2949 struct d3dx_parameter *param;
2950 void *param_value;
2951 BOOL param_dirty;
2952 HRESULT hr;
2954 TRACE("operation %u, index %u, type %u.\n", state->operation, state->index, state->type);
2956 if (FAILED(hr = d3dx9_get_param_value_ptr(pass, state, &param_value, &param,
2957 update_all, &param_dirty)))
2959 if (!update_all && hr == E_FAIL)
2961 /* Native d3dx9 returns D3D_OK from CommitChanges() involving
2962 * out of bounds array access and does not touch the affected
2963 * states. */
2964 WARN("Returning D3D_OK on out of bounds array access.\n");
2965 return D3D_OK;
2967 return hr;
2970 if (!(update_all || param_dirty
2971 || state_table[state->operation].class == SC_VERTEXSHADER
2972 || state_table[state->operation].class == SC_PIXELSHADER
2973 || state_table[state->operation].class == SC_SETSAMPLER))
2974 return D3D_OK;
2976 switch (state_table[state->operation].class)
2978 case SC_RENDERSTATE:
2979 TRACE("%s, operation %u, value %u.\n", state_table[state->operation].name,
2980 state_table[state->operation].op, *(DWORD *)param_value);
2981 return SET_D3D_STATE(effect, SetRenderState, state_table[state->operation].op, *(DWORD *)param_value);
2982 case SC_FVF:
2983 TRACE("%s, value %#x.\n", state_table[state->operation].name, *(DWORD *)param_value);
2984 return SET_D3D_STATE(effect, SetFVF, *(DWORD *)param_value);
2985 case SC_TEXTURE:
2987 UINT unit;
2989 unit = parent_index == ~0u ? state->index : parent_index;
2990 TRACE("%s, unit %u, value %p.\n", state_table[state->operation].name, unit,
2991 *(IDirect3DBaseTexture9 **)param_value);
2992 return SET_D3D_STATE(effect, SetTexture, unit, *(IDirect3DBaseTexture9 **)param_value);
2994 case SC_TEXTURESTAGE:
2995 TRACE("%s, stage %u, value %u.\n", state_table[state->operation].name, state->index, *(DWORD *)param_value);
2996 return SET_D3D_STATE(effect, SetTextureStageState, state->index,
2997 state_table[state->operation].op, *(DWORD *)param_value);
2998 case SC_SETSAMPLER:
3000 struct d3dx_sampler *sampler;
3001 HRESULT ret, hr;
3002 unsigned int i;
3004 sampler = (struct d3dx_sampler *)param_value;
3005 TRACE("%s, sampler %u, applying %u states.\n", state_table[state->operation].name, state->index,
3006 sampler->state_count);
3007 ret = D3D_OK;
3008 for (i = 0; i < sampler->state_count; i++)
3010 if (FAILED(hr = d3dx9_apply_state(effect, pass, &sampler->states[i], state->index, update_all)))
3011 ret = hr;
3013 return ret;
3015 case SC_SAMPLERSTATE:
3017 UINT sampler;
3019 sampler = parent_index == ~0u ? state->index : parent_index;
3020 TRACE("%s, sampler %u, value %u.\n", state_table[state->operation].name, sampler, *(DWORD *)param_value);
3021 return SET_D3D_STATE(effect, SetSamplerState, sampler, state_table[state->operation].op,
3022 *(DWORD *)param_value);
3024 case SC_VERTEXSHADER:
3025 TRACE("%s, shader %p.\n", state_table[state->operation].name, *(IDirect3DVertexShader9 **)param_value);
3026 if ((update_all || param_dirty)
3027 && FAILED(hr = SET_D3D_STATE(effect, SetVertexShader,
3028 *(IDirect3DVertexShader9 **)param_value)))
3029 ERR("Could not set vertex shader, hr %#x.\n", hr);
3030 else if (*(IDirect3DVertexShader9 **)param_value)
3031 hr = d3dx_set_shader_constants(effect, pass, param, TRUE, update_all || param_dirty);
3032 return hr;
3033 case SC_PIXELSHADER:
3034 TRACE("%s, shader %p.\n", state_table[state->operation].name, *(IDirect3DPixelShader9 **)param_value);
3035 if ((update_all || param_dirty)
3036 && FAILED(hr = SET_D3D_STATE(effect, SetPixelShader,
3037 *(IDirect3DPixelShader9 **)param_value)))
3038 ERR("Could not set pixel shader, hr %#x.\n", hr);
3039 else if (*(IDirect3DPixelShader9 **)param_value)
3040 hr = d3dx_set_shader_constants(effect, pass, param, FALSE, update_all || param_dirty);
3041 return hr;
3042 case SC_TRANSFORM:
3043 TRACE("%s, state %u.\n", state_table[state->operation].name, state->index);
3044 return SET_D3D_STATE(effect, SetTransform, state_table[state->operation].op + state->index,
3045 (D3DMATRIX *)param_value);
3046 case SC_LIGHTENABLE:
3047 TRACE("%s, index %u, value %u.\n", state_table[state->operation].name, state->index, *(BOOL *)param_value);
3048 return SET_D3D_STATE(effect, LightEnable, state->index, *(BOOL *)param_value);
3049 case SC_LIGHT:
3051 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
3052 state_table[state->operation].op);
3053 d3dx9_set_light_parameter(state_table[state->operation].op,
3054 &effect->current_light[state->index], param_value);
3055 effect->light_updated[state->index] = TRUE;
3056 return D3D_OK;
3058 case SC_MATERIAL:
3060 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
3061 state_table[state->operation].op);
3062 d3dx9_set_material_parameter(state_table[state->operation].op,
3063 &effect->current_material, param_value);
3064 effect->material_updated = TRUE;
3065 return D3D_OK;
3067 case SC_NPATCHMODE:
3068 TRACE("%s, nsegments %f.\n", state_table[state->operation].name, *(float *)param_value);
3069 return SET_D3D_STATE(effect, SetNPatchMode, *(float *)param_value);
3070 case SC_SHADERCONST:
3071 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
3072 state_table[state->operation].op);
3073 return d3dx_set_shader_const_state(effect, state_table[state->operation].op, state->index,
3074 param, param_value);
3075 default:
3076 FIXME("%s not handled.\n", state_table[state->operation].name);
3077 break;
3079 return D3D_OK;
3082 static HRESULT d3dx9_apply_pass_states(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass, BOOL update_all)
3084 unsigned int i;
3085 HRESULT ret;
3086 HRESULT hr;
3087 ULONG64 new_update_version = next_effect_update_version(&effect->base_effect);
3089 TRACE("effect %p, pass %p, state_count %u.\n", effect, pass, pass->state_count);
3091 ret = D3D_OK;
3092 for (i = 0; i < pass->state_count; ++i)
3094 if (FAILED(hr = d3dx9_apply_state(effect, pass, &pass->states[i], ~0u, update_all)))
3096 WARN("Error applying state, hr %#x.\n", hr);
3097 ret = hr;
3100 for (i = 0; i < ARRAY_SIZE(effect->current_light); ++i)
3102 if (effect->light_updated[i]
3103 && FAILED(hr = SET_D3D_STATE(effect, SetLight, i, &effect->current_light[i])))
3105 WARN("Error setting light, hr %#x.\n", hr);
3106 ret = hr;
3108 effect->light_updated[i] = FALSE;
3111 if (effect->material_updated
3112 && FAILED(hr = SET_D3D_STATE(effect, SetMaterial, &effect->current_material)))
3114 WARN("Error setting material, hr %#x.\n", hr);
3115 ret = hr;
3117 effect->material_updated = FALSE;
3119 pass->update_version = new_update_version;
3120 return ret;
3123 static void param_set_data_pointer(struct d3dx_parameter *param, unsigned char *data, BOOL child, BOOL free_data)
3125 unsigned char *member_data = data;
3126 unsigned int i, count;
3128 count = param->element_count ? param->element_count : param->member_count;
3129 for (i = 0; i < count; ++i)
3131 param_set_data_pointer(&param->members[i], member_data, TRUE, free_data);
3132 if (data)
3133 member_data += param->members[i].bytes;
3135 if (free_data)
3136 free_parameter_data(param, child);
3137 param->data = data;
3140 static BOOL is_same_parameter(void *param1_, struct d3dx_parameter *param2)
3142 struct d3dx_parameter *param1 = (struct d3dx_parameter *)param1_;
3143 BOOL matches;
3144 unsigned int i, member_count;
3146 matches = !strcmp(param1->name, param2->name) && param1->class == param2->class
3147 && param1->type == param2->type && param1->rows == param2->rows
3148 && param1->columns == param2->columns && param1->element_count == param2->element_count
3149 && param1->member_count == param2->member_count;
3151 member_count = param1->element_count ? param1->element_count : param1->member_count;
3153 if (!matches || !member_count)
3154 return matches;
3156 for (i = 0; i < member_count; ++i)
3158 if (!is_same_parameter(&param1->members[i], &param2->members[i]))
3159 return FALSE;
3161 return TRUE;
3164 static HRESULT d3dx_pool_sync_shared_parameter(struct d3dx_effect_pool *pool, struct d3dx_parameter *param)
3166 unsigned int i, free_entry_index;
3167 unsigned int new_size, new_count;
3169 if (!(param->flags & PARAMETER_FLAG_SHARED) || !pool || is_param_type_sampler(param->type))
3170 return D3D_OK;
3172 free_entry_index = pool->size;
3173 for (i = 0; i < pool->size; ++i)
3175 if (!pool->shared_data[i].count)
3176 free_entry_index = i;
3177 else if (is_same_parameter(param, pool->shared_data[i].parameters[0]))
3178 break;
3180 if (i == pool->size)
3182 i = free_entry_index;
3183 if (i == pool->size)
3185 struct d3dx_shared_data *new_alloc;
3187 if (!pool->size)
3189 new_size = INITIAL_POOL_SIZE;
3190 new_alloc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3191 sizeof(*pool->shared_data) * new_size);
3192 if (!new_alloc)
3194 ERR("Out of memory.\n");
3195 return E_OUTOFMEMORY;
3198 else
3200 new_size = pool->size * 2;
3201 new_alloc = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pool->shared_data,
3202 sizeof(*pool->shared_data) * new_size);
3203 if (!new_alloc)
3205 ERR("Out of memory.\n");
3206 return E_OUTOFMEMORY;
3208 if (new_alloc != pool->shared_data)
3210 unsigned int j, k;
3212 for (j = 0; j < pool->size; ++j)
3213 for (k = 0; k < new_alloc[j].count; ++k)
3214 new_alloc[j].parameters[k]->u.shared_data = &new_alloc[j];
3217 pool->shared_data = new_alloc;
3218 pool->size = new_size;
3220 pool->shared_data[i].data = param->data;
3222 else
3224 param_set_data_pointer(param, pool->shared_data[i].data, FALSE, TRUE);
3226 new_count = ++pool->shared_data[i].count;
3227 if (new_count >= pool->shared_data[i].size)
3229 if (!pool->shared_data[i].size)
3231 new_size = INITIAL_SHARED_DATA_SIZE;
3232 pool->shared_data[i].parameters = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3233 sizeof(*pool->shared_data[i].parameters) * INITIAL_SHARED_DATA_SIZE);
3235 else
3237 new_size = pool->shared_data[i].size * 2;
3238 pool->shared_data[i].parameters = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3239 pool->shared_data[i].parameters,
3240 sizeof(*pool->shared_data[i].parameters) * new_size);
3242 pool->shared_data[i].size = new_size;
3245 param->u.shared_data = &pool->shared_data[i];
3246 pool->shared_data[i].parameters[new_count - 1] = param;
3248 TRACE("name %s, parameter idx %u, new refcount %u.\n", param->name, i,
3249 new_count);
3251 return D3D_OK;
3254 static BOOL param_zero_data_func(void *dummy, struct d3dx_parameter *param)
3256 param->data = NULL;
3257 return FALSE;
3260 static void d3dx_pool_release_shared_parameter(struct d3dx_parameter *param)
3262 unsigned int new_count;
3264 if (!(param->flags & PARAMETER_FLAG_SHARED) || !param->u.shared_data)
3265 return;
3266 new_count = --param->u.shared_data->count;
3268 TRACE("param %p, param->u.shared_data %p, new_count %d.\n", param, param->u.shared_data, new_count);
3270 if (new_count)
3272 unsigned int i;
3274 for (i = 0; i < new_count; ++i)
3276 if (param->u.shared_data->parameters[i] == param)
3278 memmove(&param->u.shared_data->parameters[i],
3279 &param->u.shared_data->parameters[i + 1],
3280 sizeof(param->u.shared_data->parameters[i]) * (new_count - i));
3281 break;
3284 walk_parameter_tree(param, param_zero_data_func, NULL);
3286 else
3288 HeapFree(GetProcessHeap(), 0, param->u.shared_data->parameters);
3289 /* Zeroing table size is required as the entry in pool parameters table can be reused. */
3290 param->u.shared_data->size = 0;
3291 param->u.shared_data = NULL;
3295 static inline struct d3dx_effect_pool *impl_from_ID3DXEffectPool(ID3DXEffectPool *iface)
3297 return CONTAINING_RECORD(iface, struct d3dx_effect_pool, ID3DXEffectPool_iface);
3300 static inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
3302 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
3305 /*** IUnknown methods ***/
3306 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
3308 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
3310 if (IsEqualGUID(riid, &IID_IUnknown) ||
3311 IsEqualGUID(riid, &IID_ID3DXEffect))
3313 iface->lpVtbl->AddRef(iface);
3314 *object = iface;
3315 return S_OK;
3318 ERR("Interface %s not found\n", debugstr_guid(riid));
3320 return E_NOINTERFACE;
3323 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
3325 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3327 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
3329 return InterlockedIncrement(&This->ref);
3332 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
3334 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3335 ULONG ref = InterlockedDecrement(&This->ref);
3337 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
3339 if (!ref)
3341 free_effect(This);
3342 HeapFree(GetProcessHeap(), 0, This);
3345 return ref;
3348 /*** ID3DXBaseEffect methods ***/
3349 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
3351 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3353 TRACE("iface %p, desc %p.\n", iface, desc);
3355 return d3dx9_base_effect_get_desc(&effect->base_effect, desc);
3358 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface,
3359 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
3361 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3363 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
3365 return d3dx9_base_effect_get_parameter_desc(&effect->base_effect, parameter, desc);
3368 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface,
3369 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
3371 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3373 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
3375 return d3dx9_base_effect_get_technique_desc(&effect->base_effect, technique, desc);
3378 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
3380 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3382 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
3384 return d3dx9_base_effect_get_pass_desc(&effect->base_effect, pass, desc);
3387 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
3389 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3391 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
3393 return d3dx9_base_effect_get_function_desc(&effect->base_effect, shader, desc);
3396 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
3398 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3400 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3402 return d3dx9_base_effect_get_parameter(&effect->base_effect, parameter, index);
3405 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface,
3406 D3DXHANDLE parameter, const char *name)
3408 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3410 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
3412 return d3dx9_base_effect_get_parameter_by_name(&effect->base_effect, parameter, name);
3415 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface,
3416 D3DXHANDLE parameter, const char *semantic)
3418 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3420 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
3422 return d3dx9_base_effect_get_parameter_by_semantic(&effect->base_effect, parameter, semantic);
3425 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
3427 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3429 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3431 return d3dx9_base_effect_get_parameter_element(&effect->base_effect, parameter, index);
3434 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
3436 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3438 TRACE("iface %p, index %u.\n", iface, index);
3440 return d3dx9_base_effect_get_technique(&effect->base_effect, index);
3443 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, const char *name)
3445 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3447 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3449 return d3dx9_base_effect_get_technique_by_name(&effect->base_effect, name);
3452 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
3454 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3456 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
3458 return d3dx9_base_effect_get_pass(&effect->base_effect, technique, index);
3461 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface,
3462 D3DXHANDLE technique, const char *name)
3464 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3466 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
3468 return d3dx9_base_effect_get_pass_by_name(&effect->base_effect, technique, name);
3471 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
3473 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3475 TRACE("iface %p, index %u.\n", iface, index);
3477 return d3dx9_base_effect_get_function(&effect->base_effect, index);
3480 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, const char *name)
3482 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3484 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3486 return d3dx9_base_effect_get_function_by_name(&effect->base_effect, name);
3489 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
3491 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3493 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
3495 return d3dx9_base_effect_get_annotation(&effect->base_effect, object, index);
3498 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface,
3499 D3DXHANDLE object, const char *name)
3501 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3503 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
3505 return d3dx9_base_effect_get_annotation_by_name(&effect->base_effect, object, name);
3508 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface,
3509 D3DXHANDLE parameter, const void *data, UINT bytes)
3511 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3513 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3515 return d3dx9_base_effect_set_value(&effect->base_effect, parameter, data, bytes);
3518 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface,
3519 D3DXHANDLE parameter, void *data, UINT bytes)
3521 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3523 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3525 return d3dx9_base_effect_get_value(&effect->base_effect, parameter, data, bytes);
3528 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
3530 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3532 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
3534 return d3dx9_base_effect_set_bool(&effect->base_effect, parameter, b);
3537 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
3539 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3541 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
3543 return d3dx9_base_effect_get_bool(&effect->base_effect, parameter, b);
3546 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface,
3547 D3DXHANDLE parameter, const BOOL *b, UINT count)
3549 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3551 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3553 return d3dx9_base_effect_set_bool_array(&effect->base_effect, parameter, b, count);
3556 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface,
3557 D3DXHANDLE parameter, BOOL *b, UINT count)
3559 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3561 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3563 return d3dx9_base_effect_get_bool_array(&effect->base_effect, parameter, b, count);
3566 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
3568 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3570 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
3572 return d3dx9_base_effect_set_int(&effect->base_effect, parameter, n);
3575 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
3577 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3579 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
3581 return d3dx9_base_effect_get_int(&effect->base_effect, parameter, n);
3584 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface,
3585 D3DXHANDLE parameter, const INT *n, UINT count)
3587 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3589 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3591 return d3dx9_base_effect_set_int_array(&effect->base_effect, parameter, n, count);
3594 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface,
3595 D3DXHANDLE parameter, INT *n, UINT count)
3597 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3599 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3601 return d3dx9_base_effect_get_int_array(&effect->base_effect, parameter, n, count);
3604 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float f)
3606 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3608 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
3610 return d3dx9_base_effect_set_float(&effect->base_effect, parameter, f);
3613 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float *f)
3615 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3617 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
3619 return d3dx9_base_effect_get_float(&effect->base_effect, parameter, f);
3622 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface,
3623 D3DXHANDLE parameter, const float *f, UINT count)
3625 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3627 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3629 return d3dx9_base_effect_set_float_array(&effect->base_effect, parameter, f, count);
3632 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface,
3633 D3DXHANDLE parameter, float *f, UINT count)
3635 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3637 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3639 return d3dx9_base_effect_get_float_array(&effect->base_effect, parameter, f, count);
3642 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface,
3643 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
3645 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3647 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3649 return d3dx9_base_effect_set_vector(&effect->base_effect, parameter, vector);
3652 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface,
3653 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
3655 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3657 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3659 return d3dx9_base_effect_get_vector(&effect->base_effect, parameter, vector);
3662 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface,
3663 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
3665 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3667 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3669 return d3dx9_base_effect_set_vector_array(&effect->base_effect, parameter, vector, count);
3672 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface,
3673 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
3675 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3677 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3679 return d3dx9_base_effect_get_vector_array(&effect->base_effect, parameter, vector, count);
3682 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface,
3683 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3685 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3687 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3689 return d3dx9_base_effect_set_matrix(&effect->base_effect, parameter, matrix);
3692 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface,
3693 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3695 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3697 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3699 return d3dx9_base_effect_get_matrix(&effect->base_effect, parameter, matrix);
3702 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface,
3703 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3705 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3707 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3709 return d3dx9_base_effect_set_matrix_array(&effect->base_effect, parameter, matrix, count);
3712 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface,
3713 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3715 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3717 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3719 return d3dx9_base_effect_get_matrix_array(&effect->base_effect, parameter, matrix, count);
3722 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface,
3723 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3725 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3727 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3729 return d3dx9_base_effect_set_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
3732 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface,
3733 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3735 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3737 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3739 return d3dx9_base_effect_get_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
3742 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface,
3743 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3745 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3747 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3749 return d3dx9_base_effect_set_matrix_transpose(&effect->base_effect, parameter, matrix);
3752 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface,
3753 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3755 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3757 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3759 return d3dx9_base_effect_get_matrix_transpose(&effect->base_effect, parameter, matrix);
3762 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface,
3763 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3765 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3767 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3769 return d3dx9_base_effect_set_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
3772 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface,
3773 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3775 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3777 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3779 return d3dx9_base_effect_get_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
3782 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface,
3783 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3785 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3787 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3789 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
3792 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface,
3793 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3795 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3797 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3799 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
3802 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char *string)
3804 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3806 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
3808 return d3dx9_base_effect_set_string(&effect->base_effect, parameter, string);
3811 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char **string)
3813 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3815 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
3817 return d3dx9_base_effect_get_string(&effect->base_effect, parameter, string);
3820 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(struct ID3DXEffect *iface,
3821 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
3823 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3825 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3827 return d3dx9_base_effect_set_texture(&effect->base_effect, parameter, texture);
3830 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(struct ID3DXEffect *iface,
3831 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
3833 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3835 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3837 return d3dx9_base_effect_get_texture(&effect->base_effect, parameter, texture);
3840 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface,
3841 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
3843 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3845 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3847 return d3dx9_base_effect_get_pixel_shader(&effect->base_effect, parameter, shader);
3850 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(struct ID3DXEffect *iface,
3851 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
3853 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3855 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3857 return d3dx9_base_effect_get_vertex_shader(&effect->base_effect, parameter, shader);
3860 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3862 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3864 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
3866 return d3dx9_base_effect_set_array_range(&effect->base_effect, parameter, start, end);
3869 /*** ID3DXEffect methods ***/
3870 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, ID3DXEffectPool **pool)
3872 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3874 TRACE("iface %p, pool %p\n", This, pool);
3876 if (!pool)
3878 WARN("Invalid argument supplied.\n");
3879 return D3DERR_INVALIDCALL;
3882 if (This->pool)
3884 This->pool->lpVtbl->AddRef(This->pool);
3887 *pool = This->pool;
3889 TRACE("Returning pool %p\n", *pool);
3891 return S_OK;
3894 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3896 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3897 struct d3dx9_base_effect *base = &This->base_effect;
3898 struct d3dx_technique *tech = get_valid_technique(base, technique);
3900 TRACE("iface %p, technique %p\n", This, technique);
3902 if (tech)
3904 This->active_technique = tech;
3905 TRACE("Technique %p\n", tech);
3906 return D3D_OK;
3909 WARN("Technique not found.\n");
3911 return D3DERR_INVALIDCALL;
3914 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3916 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3918 TRACE("iface %p\n", This);
3920 return get_technique_handle(This->active_technique);
3923 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3925 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3927 FIXME("(%p)->(%p): stub\n", This, technique);
3929 return D3D_OK;
3932 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3934 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3936 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3938 return E_NOTIMPL;
3941 static BOOL walk_parameter_dep(struct d3dx_parameter *param, walk_parameter_dep_func param_func,
3942 void *data);
3944 static BOOL walk_param_eval_dep(struct d3dx_param_eval *param_eval, walk_parameter_dep_func param_func,
3945 void *data)
3947 struct d3dx_parameter **params;
3948 unsigned int i, param_count;
3950 if (!param_eval)
3951 return FALSE;
3953 params = param_eval->shader_inputs.inputs_param;
3954 param_count = param_eval->shader_inputs.input_count;
3955 for (i = 0; i < param_count; ++i)
3957 if (walk_parameter_dep(params[i], param_func, data))
3958 return TRUE;
3961 params = param_eval->pres.inputs.inputs_param;
3962 param_count = param_eval->pres.inputs.input_count;
3963 for (i = 0; i < param_count; ++i)
3965 if (walk_parameter_dep(params[i], param_func, data))
3966 return TRUE;
3968 return FALSE;
3971 static BOOL walk_state_dep(struct d3dx_state *state, walk_parameter_dep_func param_func,
3972 void *data)
3974 if (state->type == ST_CONSTANT && is_param_type_sampler(state->parameter.type))
3976 if (walk_parameter_dep(&state->parameter, param_func, data))
3977 return TRUE;
3979 else if (state->type == ST_ARRAY_SELECTOR || state->type == ST_PARAMETER)
3981 if (walk_parameter_dep(state->parameter.u.referenced_param, param_func, data))
3982 return TRUE;
3984 return walk_param_eval_dep(state->parameter.param_eval, param_func, data);
3987 static BOOL walk_parameter_dep(struct d3dx_parameter *param, walk_parameter_dep_func param_func,
3988 void *data)
3990 unsigned int i;
3991 unsigned int member_count;
3993 param = param->top_level_param;
3994 if (param_func(data, param))
3995 return TRUE;
3997 if (walk_param_eval_dep(param->param_eval, param_func, data))
3998 return TRUE;
4000 if (param->class == D3DXPC_OBJECT && is_param_type_sampler(param->type))
4002 struct d3dx_sampler *sampler;
4004 sampler = (struct d3dx_sampler *)param->data;
4005 for (i = 0; i < sampler->state_count; ++i)
4007 if (walk_state_dep(&sampler->states[i], param_func, data))
4008 return TRUE;
4010 return FALSE;
4013 member_count = param->element_count ? param->element_count : param->member_count;
4014 for (i = 0; i < member_count; ++i)
4016 if (walk_param_eval_dep(param->members[i].param_eval, param_func, data))
4017 return TRUE;
4020 return FALSE;
4023 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
4025 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
4026 unsigned int i, j;
4027 struct d3dx_parameter *param = get_valid_parameter(&effect->base_effect, parameter);
4028 struct d3dx_technique *tech = get_valid_technique(&effect->base_effect, technique);
4029 struct d3dx_pass *pass;
4031 TRACE("iface %p, parameter %p, technique %p.\n", iface, parameter, technique);
4032 TRACE("param %p, name %s, tech %p.\n", param, param ? debugstr_a(param->name) : "", tech);
4033 if (!tech || !param)
4034 return FALSE;
4036 for (i = 0; i < tech->pass_count; ++i)
4038 pass = &tech->passes[i];
4039 for (j = 0; j < pass->state_count; ++j)
4041 if (walk_state_dep(&pass->states[j], is_same_parameter, param))
4043 TRACE("Returning TRUE.\n");
4044 return TRUE;
4048 TRACE("Returning FALSE.\n");
4049 return FALSE;
4052 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
4054 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
4055 struct d3dx_technique *technique = effect->active_technique;
4057 TRACE("iface %p, passes %p, flags %#x.\n", iface, passes, flags);
4059 if (passes && technique)
4061 if (flags & ~(D3DXFX_DONOTSAVESTATE | D3DXFX_DONOTSAVESAMPLERSTATE | D3DXFX_DONOTSAVESHADERSTATE))
4062 WARN("Invalid flags (%#x) specified.\n", flags);
4064 if (flags & D3DXFX_DONOTSAVESTATE)
4066 TRACE("State capturing disabled.\n");
4068 else
4070 HRESULT hr;
4071 unsigned int i;
4073 if (!technique->saved_state)
4075 ID3DXEffectStateManager *manager;
4077 manager = effect->manager;
4078 effect->manager = NULL;
4079 if (FAILED(hr = IDirect3DDevice9_BeginStateBlock(effect->device)))
4080 ERR("BeginStateBlock failed, hr %#x.\n", hr);
4081 for (i = 0; i < technique->pass_count; i++)
4082 d3dx9_apply_pass_states(effect, &technique->passes[i], TRUE);
4083 if (FAILED(hr = IDirect3DDevice9_EndStateBlock(effect->device, &technique->saved_state)))
4084 ERR("EndStateBlock failed, hr %#x.\n", hr);
4085 effect->manager = manager;
4087 if (FAILED(hr = IDirect3DStateBlock9_Capture(technique->saved_state)))
4088 ERR("StateBlock Capture failed, hr %#x.\n", hr);
4091 *passes = technique->pass_count;
4092 effect->started = TRUE;
4093 effect->begin_flags = flags;
4095 return D3D_OK;
4098 WARN("Invalid argument supplied.\n");
4100 return D3DERR_INVALIDCALL;
4103 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
4105 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
4106 struct d3dx_technique *technique = effect->active_technique;
4108 TRACE("iface %p, pass %u\n", effect, pass);
4110 if (technique && pass < technique->pass_count && !effect->active_pass)
4112 HRESULT hr;
4114 memset(effect->current_light, 0, sizeof(effect->current_light));
4115 memset(&effect->current_material, 0, sizeof(effect->current_material));
4117 if (SUCCEEDED(hr = d3dx9_apply_pass_states(effect, &technique->passes[pass], TRUE)))
4118 effect->active_pass = &technique->passes[pass];
4119 return hr;
4122 WARN("Invalid argument supplied.\n");
4124 return D3DERR_INVALIDCALL;
4127 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect *iface)
4129 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
4131 TRACE("iface %p.\n", iface);
4133 if (!effect->active_pass)
4135 WARN("Called without an active pass.\n");
4136 return D3D_OK;
4138 return d3dx9_apply_pass_states(effect, effect->active_pass, FALSE);
4141 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
4143 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4145 TRACE("iface %p\n", This);
4147 if (This->active_pass)
4149 This->active_pass = NULL;
4150 return D3D_OK;
4153 WARN("Invalid call.\n");
4155 return D3DERR_INVALIDCALL;
4158 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect *iface)
4160 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
4161 struct d3dx_technique *technique = effect->active_technique;
4163 TRACE("iface %p.\n", iface);
4165 if (!effect->started)
4166 return D3D_OK;
4168 if (effect->begin_flags & D3DXFX_DONOTSAVESTATE)
4170 TRACE("State restoring disabled.\n");
4172 else
4174 HRESULT hr;
4176 if (technique && technique->saved_state)
4178 if (FAILED(hr = IDirect3DStateBlock9_Apply(technique->saved_state)))
4179 ERR("State block apply failed, hr %#x.\n", hr);
4181 else
4182 ERR("No saved state.\n");
4185 effect->started = FALSE;
4187 return D3D_OK;
4190 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, struct IDirect3DDevice9 **device)
4192 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4194 TRACE("iface %p, device %p\n", This, device);
4196 if (!device)
4198 WARN("Invalid argument supplied.\n");
4199 return D3DERR_INVALIDCALL;
4202 IDirect3DDevice9_AddRef(This->device);
4204 *device = This->device;
4206 TRACE("Returning device %p\n", *device);
4208 return S_OK;
4211 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
4213 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4215 FIXME("(%p)->(): stub\n", This);
4217 return E_NOTIMPL;
4220 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(ID3DXEffect* iface)
4222 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4224 FIXME("(%p)->(): stub\n", This);
4226 return E_NOTIMPL;
4229 static HRESULT WINAPI ID3DXEffectImpl_SetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager *manager)
4231 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4233 TRACE("iface %p, manager %p\n", This, manager);
4235 if (manager) IUnknown_AddRef(manager);
4236 if (This->manager) IUnknown_Release(This->manager);
4238 This->manager = manager;
4240 return D3D_OK;
4243 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager **manager)
4245 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4247 TRACE("iface %p, manager %p\n", This, manager);
4249 if (!manager)
4251 WARN("Invalid argument supplied.\n");
4252 return D3DERR_INVALIDCALL;
4255 if (This->manager) IUnknown_AddRef(This->manager);
4256 *manager = This->manager;
4258 return D3D_OK;
4261 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
4263 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4265 FIXME("(%p)->(): stub\n", This);
4267 return E_NOTIMPL;
4270 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
4272 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4274 FIXME("(%p)->(): stub\n", This);
4276 return NULL;
4279 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
4281 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4283 FIXME("(%p)->(%p): stub\n", This, parameter_block);
4285 return E_NOTIMPL;
4288 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
4290 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4292 FIXME("(%p)->(%p): stub\n", This, parameter_block);
4294 return E_NOTIMPL;
4297 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect *iface,
4298 struct IDirect3DDevice9 *device, struct ID3DXEffect **effect)
4300 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
4302 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
4304 return E_NOTIMPL;
4307 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect *iface,
4308 D3DXHANDLE parameter, const void *data, UINT byte_offset, UINT bytes)
4310 FIXME("iface %p, parameter %p, data %p, byte_offset %u, bytes %u stub!\n",
4311 iface, parameter, data, byte_offset, bytes);
4313 return E_NOTIMPL;
4316 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
4318 /*** IUnknown methods ***/
4319 ID3DXEffectImpl_QueryInterface,
4320 ID3DXEffectImpl_AddRef,
4321 ID3DXEffectImpl_Release,
4322 /*** ID3DXBaseEffect methods ***/
4323 ID3DXEffectImpl_GetDesc,
4324 ID3DXEffectImpl_GetParameterDesc,
4325 ID3DXEffectImpl_GetTechniqueDesc,
4326 ID3DXEffectImpl_GetPassDesc,
4327 ID3DXEffectImpl_GetFunctionDesc,
4328 ID3DXEffectImpl_GetParameter,
4329 ID3DXEffectImpl_GetParameterByName,
4330 ID3DXEffectImpl_GetParameterBySemantic,
4331 ID3DXEffectImpl_GetParameterElement,
4332 ID3DXEffectImpl_GetTechnique,
4333 ID3DXEffectImpl_GetTechniqueByName,
4334 ID3DXEffectImpl_GetPass,
4335 ID3DXEffectImpl_GetPassByName,
4336 ID3DXEffectImpl_GetFunction,
4337 ID3DXEffectImpl_GetFunctionByName,
4338 ID3DXEffectImpl_GetAnnotation,
4339 ID3DXEffectImpl_GetAnnotationByName,
4340 ID3DXEffectImpl_SetValue,
4341 ID3DXEffectImpl_GetValue,
4342 ID3DXEffectImpl_SetBool,
4343 ID3DXEffectImpl_GetBool,
4344 ID3DXEffectImpl_SetBoolArray,
4345 ID3DXEffectImpl_GetBoolArray,
4346 ID3DXEffectImpl_SetInt,
4347 ID3DXEffectImpl_GetInt,
4348 ID3DXEffectImpl_SetIntArray,
4349 ID3DXEffectImpl_GetIntArray,
4350 ID3DXEffectImpl_SetFloat,
4351 ID3DXEffectImpl_GetFloat,
4352 ID3DXEffectImpl_SetFloatArray,
4353 ID3DXEffectImpl_GetFloatArray,
4354 ID3DXEffectImpl_SetVector,
4355 ID3DXEffectImpl_GetVector,
4356 ID3DXEffectImpl_SetVectorArray,
4357 ID3DXEffectImpl_GetVectorArray,
4358 ID3DXEffectImpl_SetMatrix,
4359 ID3DXEffectImpl_GetMatrix,
4360 ID3DXEffectImpl_SetMatrixArray,
4361 ID3DXEffectImpl_GetMatrixArray,
4362 ID3DXEffectImpl_SetMatrixPointerArray,
4363 ID3DXEffectImpl_GetMatrixPointerArray,
4364 ID3DXEffectImpl_SetMatrixTranspose,
4365 ID3DXEffectImpl_GetMatrixTranspose,
4366 ID3DXEffectImpl_SetMatrixTransposeArray,
4367 ID3DXEffectImpl_GetMatrixTransposeArray,
4368 ID3DXEffectImpl_SetMatrixTransposePointerArray,
4369 ID3DXEffectImpl_GetMatrixTransposePointerArray,
4370 ID3DXEffectImpl_SetString,
4371 ID3DXEffectImpl_GetString,
4372 ID3DXEffectImpl_SetTexture,
4373 ID3DXEffectImpl_GetTexture,
4374 ID3DXEffectImpl_GetPixelShader,
4375 ID3DXEffectImpl_GetVertexShader,
4376 ID3DXEffectImpl_SetArrayRange,
4377 /*** ID3DXEffect methods ***/
4378 ID3DXEffectImpl_GetPool,
4379 ID3DXEffectImpl_SetTechnique,
4380 ID3DXEffectImpl_GetCurrentTechnique,
4381 ID3DXEffectImpl_ValidateTechnique,
4382 ID3DXEffectImpl_FindNextValidTechnique,
4383 ID3DXEffectImpl_IsParameterUsed,
4384 ID3DXEffectImpl_Begin,
4385 ID3DXEffectImpl_BeginPass,
4386 ID3DXEffectImpl_CommitChanges,
4387 ID3DXEffectImpl_EndPass,
4388 ID3DXEffectImpl_End,
4389 ID3DXEffectImpl_GetDevice,
4390 ID3DXEffectImpl_OnLostDevice,
4391 ID3DXEffectImpl_OnResetDevice,
4392 ID3DXEffectImpl_SetStateManager,
4393 ID3DXEffectImpl_GetStateManager,
4394 ID3DXEffectImpl_BeginParameterBlock,
4395 ID3DXEffectImpl_EndParameterBlock,
4396 ID3DXEffectImpl_ApplyParameterBlock,
4397 ID3DXEffectImpl_DeleteParameterBlock,
4398 ID3DXEffectImpl_CloneEffect,
4399 ID3DXEffectImpl_SetRawValue
4402 static inline struct ID3DXEffectCompilerImpl *impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler *iface)
4404 return CONTAINING_RECORD(iface, struct ID3DXEffectCompilerImpl, ID3DXEffectCompiler_iface);
4407 /*** IUnknown methods ***/
4408 static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler *iface, REFIID riid, void **object)
4410 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
4412 if (IsEqualGUID(riid, &IID_IUnknown) ||
4413 IsEqualGUID(riid, &IID_ID3DXEffectCompiler))
4415 iface->lpVtbl->AddRef(iface);
4416 *object = iface;
4417 return S_OK;
4420 ERR("Interface %s not found\n", debugstr_guid(riid));
4422 return E_NOINTERFACE;
4425 static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface)
4427 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4429 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
4431 return InterlockedIncrement(&This->ref);
4434 static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface)
4436 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4437 ULONG ref = InterlockedDecrement(&This->ref);
4439 TRACE("iface %p: Release from %u\n", iface, ref + 1);
4441 if (!ref)
4443 free_effect_compiler(This);
4444 HeapFree(GetProcessHeap(), 0, This);
4447 return ref;
4450 /*** ID3DXBaseEffect methods ***/
4451 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler *iface, D3DXEFFECT_DESC *desc)
4453 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4455 TRACE("iface %p, desc %p.\n", iface, desc);
4457 return d3dx9_base_effect_get_desc(&compiler->base_effect, desc);
4460 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler *iface,
4461 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
4463 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4465 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
4467 return d3dx9_base_effect_get_parameter_desc(&compiler->base_effect, parameter, desc);
4470 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler *iface,
4471 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
4473 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4475 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
4477 return d3dx9_base_effect_get_technique_desc(&compiler->base_effect, technique, desc);
4480 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler *iface,
4481 D3DXHANDLE pass, D3DXPASS_DESC *desc)
4483 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4485 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
4487 return d3dx9_base_effect_get_pass_desc(&compiler->base_effect, pass, desc);
4490 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler *iface,
4491 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
4493 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4495 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
4497 return d3dx9_base_effect_get_function_desc(&compiler->base_effect, shader, desc);
4500 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler *iface,
4501 D3DXHANDLE parameter, UINT index)
4503 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4505 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
4507 return d3dx9_base_effect_get_parameter(&compiler->base_effect, parameter, index);
4510 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler *iface,
4511 D3DXHANDLE parameter, const char *name)
4513 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4515 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
4517 return d3dx9_base_effect_get_parameter_by_name(&compiler->base_effect, parameter, name);
4520 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler *iface,
4521 D3DXHANDLE parameter, const char *semantic)
4523 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4525 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
4527 return d3dx9_base_effect_get_parameter_by_semantic(&compiler->base_effect, parameter, semantic);
4530 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler *iface,
4531 D3DXHANDLE parameter, UINT index)
4533 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4535 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
4537 return d3dx9_base_effect_get_parameter_element(&compiler->base_effect, parameter, index);
4540 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler *iface, UINT index)
4542 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4544 TRACE("iface %p, index %u.\n", iface, index);
4546 return d3dx9_base_effect_get_technique(&compiler->base_effect, index);
4549 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler *iface, const char *name)
4551 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4553 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4555 return d3dx9_base_effect_get_technique_by_name(&compiler->base_effect, name);
4558 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler *iface, D3DXHANDLE technique, UINT index)
4560 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4562 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
4564 return d3dx9_base_effect_get_pass(&compiler->base_effect, technique, index);
4567 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler *iface,
4568 D3DXHANDLE technique, const char *name)
4570 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4572 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
4574 return d3dx9_base_effect_get_pass_by_name(&compiler->base_effect, technique, name);
4577 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler *iface, UINT index)
4579 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4581 TRACE("iface %p, index %u.\n", iface, index);
4583 return d3dx9_base_effect_get_function(&compiler->base_effect, index);
4586 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler *iface, const char *name)
4588 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4590 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4592 return d3dx9_base_effect_get_function_by_name(&compiler->base_effect, name);
4595 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler *iface,
4596 D3DXHANDLE object, UINT index)
4598 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4600 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
4602 return d3dx9_base_effect_get_annotation(&compiler->base_effect, object, index);
4605 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler *iface,
4606 D3DXHANDLE object, const char *name)
4608 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4610 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
4612 return d3dx9_base_effect_get_annotation_by_name(&compiler->base_effect, object, name);
4615 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler *iface,
4616 D3DXHANDLE parameter, const void *data, UINT bytes)
4618 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4620 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
4622 return d3dx9_base_effect_set_value(&compiler->base_effect, parameter, data, bytes);
4625 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler *iface,
4626 D3DXHANDLE parameter, void *data, UINT bytes)
4628 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4630 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
4632 return d3dx9_base_effect_get_value(&compiler->base_effect, parameter, data, bytes);
4635 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL b)
4637 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4639 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
4641 return d3dx9_base_effect_set_bool(&compiler->base_effect, parameter, b);
4644 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b)
4646 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4648 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
4650 return d3dx9_base_effect_get_bool(&compiler->base_effect, parameter, b);
4653 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler *iface,
4654 D3DXHANDLE parameter, const BOOL *b, UINT count)
4656 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4658 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
4660 return d3dx9_base_effect_set_bool_array(&compiler->base_effect, parameter, b, count);
4663 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler *iface,
4664 D3DXHANDLE parameter, BOOL *b, UINT count)
4666 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4668 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
4670 return d3dx9_base_effect_get_bool_array(&compiler->base_effect, parameter, b, count);
4673 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT n)
4675 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4677 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
4679 return d3dx9_base_effect_set_int(&compiler->base_effect, parameter, n);
4682 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n)
4684 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4686 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
4688 return d3dx9_base_effect_get_int(&compiler->base_effect, parameter, n);
4691 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler *iface,
4692 D3DXHANDLE parameter, const INT *n, UINT count)
4694 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4696 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
4698 return d3dx9_base_effect_set_int_array(&compiler->base_effect, parameter, n, count);
4701 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler *iface,
4702 D3DXHANDLE parameter, INT *n, UINT count)
4704 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4706 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
4708 return d3dx9_base_effect_get_int_array(&compiler->base_effect, parameter, n, count);
4711 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float f)
4713 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4715 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
4717 return d3dx9_base_effect_set_float(&compiler->base_effect, parameter, f);
4720 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float *f)
4722 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4724 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
4726 return d3dx9_base_effect_get_float(&compiler->base_effect, parameter, f);
4729 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler *iface,
4730 D3DXHANDLE parameter, const float *f, UINT count)
4732 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4734 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
4736 return d3dx9_base_effect_set_float_array(&compiler->base_effect, parameter, f, count);
4739 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler *iface,
4740 D3DXHANDLE parameter, float *f, UINT count)
4742 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4744 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
4746 return d3dx9_base_effect_get_float_array(&compiler->base_effect, parameter, f, count);
4749 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler *iface,
4750 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
4752 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4754 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
4756 return d3dx9_base_effect_set_vector(&compiler->base_effect, parameter, vector);
4759 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler *iface,
4760 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
4762 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4764 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
4766 return d3dx9_base_effect_get_vector(&compiler->base_effect, parameter, vector);
4769 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler *iface,
4770 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
4772 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4774 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
4776 return d3dx9_base_effect_set_vector_array(&compiler->base_effect, parameter, vector, count);
4779 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler *iface,
4780 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
4782 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4784 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
4786 return d3dx9_base_effect_get_vector_array(&compiler->base_effect, parameter, vector, count);
4789 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler *iface,
4790 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
4792 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4794 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4796 return d3dx9_base_effect_set_matrix(&compiler->base_effect, parameter, matrix);
4799 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler *iface,
4800 D3DXHANDLE parameter, D3DXMATRIX *matrix)
4802 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4804 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4806 return d3dx9_base_effect_get_matrix(&compiler->base_effect, parameter, matrix);
4809 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler *iface,
4810 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
4812 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4814 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4816 return d3dx9_base_effect_set_matrix_array(&compiler->base_effect, parameter, matrix, count);
4819 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler *iface,
4820 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4822 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4824 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4826 return d3dx9_base_effect_get_matrix_array(&compiler->base_effect, parameter, matrix, count);
4829 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler *iface,
4830 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
4832 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4834 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4836 return d3dx9_base_effect_set_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
4839 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler *iface,
4840 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4842 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4844 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4846 return d3dx9_base_effect_get_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
4849 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler *iface,
4850 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
4852 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4854 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4856 return d3dx9_base_effect_set_matrix_transpose(&compiler->base_effect, parameter, matrix);
4859 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler *iface,
4860 D3DXHANDLE parameter, D3DXMATRIX *matrix)
4862 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4864 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4866 return d3dx9_base_effect_get_matrix_transpose(&compiler->base_effect, parameter, matrix);
4869 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler *iface,
4870 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
4872 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4874 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4876 return d3dx9_base_effect_set_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
4879 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler *iface,
4880 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4882 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4884 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4886 return d3dx9_base_effect_get_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
4889 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
4890 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
4892 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4894 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4896 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
4899 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
4900 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4902 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4904 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4906 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
4909 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler *iface,
4910 D3DXHANDLE parameter, const char *string)
4912 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4914 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
4916 return d3dx9_base_effect_set_string(&compiler->base_effect, parameter, string);
4919 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler *iface,
4920 D3DXHANDLE parameter, const char **string)
4922 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4924 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
4926 return d3dx9_base_effect_get_string(&compiler->base_effect, parameter, string);
4929 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetTexture(struct ID3DXEffectCompiler *iface,
4930 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
4932 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4934 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
4936 return d3dx9_base_effect_set_texture(&compiler->base_effect, parameter, texture);
4939 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTexture(struct ID3DXEffectCompiler *iface,
4940 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
4942 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4944 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
4946 return d3dx9_base_effect_get_texture(&compiler->base_effect, parameter, texture);
4949 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler *iface,
4950 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
4952 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4954 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4956 return d3dx9_base_effect_get_pixel_shader(&compiler->base_effect, parameter, shader);
4959 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVertexShader(struct ID3DXEffectCompiler *iface,
4960 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
4962 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4964 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4966 return d3dx9_base_effect_get_vertex_shader(&compiler->base_effect, parameter, shader);
4969 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler *iface,
4970 D3DXHANDLE parameter, UINT start, UINT end)
4972 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4974 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
4976 return d3dx9_base_effect_set_array_range(&compiler->base_effect, parameter, start, end);
4979 /*** ID3DXEffectCompiler methods ***/
4980 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL literal)
4982 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4984 FIXME("iface %p, parameter %p, literal %u\n", This, parameter, literal);
4986 return E_NOTIMPL;
4989 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *literal)
4991 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4993 FIXME("iface %p, parameter %p, literal %p\n", This, parameter, literal);
4995 return E_NOTIMPL;
4998 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler *iface, DWORD flags,
4999 ID3DXBuffer **effect, ID3DXBuffer **error_msgs)
5001 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
5003 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub\n", This, flags, effect, error_msgs);
5005 return E_NOTIMPL;
5008 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler *iface, D3DXHANDLE function,
5009 const char *target, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_msgs,
5010 ID3DXConstantTable **constant_table)
5012 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
5014 FIXME("iface %p, function %p, target %p, flags %#x, shader %p, error_msgs %p, constant_table %p stub\n",
5015 This, function, target, flags, shader, error_msgs, constant_table);
5017 return E_NOTIMPL;
5020 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
5022 /*** IUnknown methods ***/
5023 ID3DXEffectCompilerImpl_QueryInterface,
5024 ID3DXEffectCompilerImpl_AddRef,
5025 ID3DXEffectCompilerImpl_Release,
5026 /*** ID3DXBaseEffect methods ***/
5027 ID3DXEffectCompilerImpl_GetDesc,
5028 ID3DXEffectCompilerImpl_GetParameterDesc,
5029 ID3DXEffectCompilerImpl_GetTechniqueDesc,
5030 ID3DXEffectCompilerImpl_GetPassDesc,
5031 ID3DXEffectCompilerImpl_GetFunctionDesc,
5032 ID3DXEffectCompilerImpl_GetParameter,
5033 ID3DXEffectCompilerImpl_GetParameterByName,
5034 ID3DXEffectCompilerImpl_GetParameterBySemantic,
5035 ID3DXEffectCompilerImpl_GetParameterElement,
5036 ID3DXEffectCompilerImpl_GetTechnique,
5037 ID3DXEffectCompilerImpl_GetTechniqueByName,
5038 ID3DXEffectCompilerImpl_GetPass,
5039 ID3DXEffectCompilerImpl_GetPassByName,
5040 ID3DXEffectCompilerImpl_GetFunction,
5041 ID3DXEffectCompilerImpl_GetFunctionByName,
5042 ID3DXEffectCompilerImpl_GetAnnotation,
5043 ID3DXEffectCompilerImpl_GetAnnotationByName,
5044 ID3DXEffectCompilerImpl_SetValue,
5045 ID3DXEffectCompilerImpl_GetValue,
5046 ID3DXEffectCompilerImpl_SetBool,
5047 ID3DXEffectCompilerImpl_GetBool,
5048 ID3DXEffectCompilerImpl_SetBoolArray,
5049 ID3DXEffectCompilerImpl_GetBoolArray,
5050 ID3DXEffectCompilerImpl_SetInt,
5051 ID3DXEffectCompilerImpl_GetInt,
5052 ID3DXEffectCompilerImpl_SetIntArray,
5053 ID3DXEffectCompilerImpl_GetIntArray,
5054 ID3DXEffectCompilerImpl_SetFloat,
5055 ID3DXEffectCompilerImpl_GetFloat,
5056 ID3DXEffectCompilerImpl_SetFloatArray,
5057 ID3DXEffectCompilerImpl_GetFloatArray,
5058 ID3DXEffectCompilerImpl_SetVector,
5059 ID3DXEffectCompilerImpl_GetVector,
5060 ID3DXEffectCompilerImpl_SetVectorArray,
5061 ID3DXEffectCompilerImpl_GetVectorArray,
5062 ID3DXEffectCompilerImpl_SetMatrix,
5063 ID3DXEffectCompilerImpl_GetMatrix,
5064 ID3DXEffectCompilerImpl_SetMatrixArray,
5065 ID3DXEffectCompilerImpl_GetMatrixArray,
5066 ID3DXEffectCompilerImpl_SetMatrixPointerArray,
5067 ID3DXEffectCompilerImpl_GetMatrixPointerArray,
5068 ID3DXEffectCompilerImpl_SetMatrixTranspose,
5069 ID3DXEffectCompilerImpl_GetMatrixTranspose,
5070 ID3DXEffectCompilerImpl_SetMatrixTransposeArray,
5071 ID3DXEffectCompilerImpl_GetMatrixTransposeArray,
5072 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray,
5073 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray,
5074 ID3DXEffectCompilerImpl_SetString,
5075 ID3DXEffectCompilerImpl_GetString,
5076 ID3DXEffectCompilerImpl_SetTexture,
5077 ID3DXEffectCompilerImpl_GetTexture,
5078 ID3DXEffectCompilerImpl_GetPixelShader,
5079 ID3DXEffectCompilerImpl_GetVertexShader,
5080 ID3DXEffectCompilerImpl_SetArrayRange,
5081 /*** ID3DXEffectCompiler methods ***/
5082 ID3DXEffectCompilerImpl_SetLiteral,
5083 ID3DXEffectCompilerImpl_GetLiteral,
5084 ID3DXEffectCompilerImpl_CompileEffect,
5085 ID3DXEffectCompilerImpl_CompileShader,
5088 static HRESULT d3dx9_parse_sampler(struct d3dx9_base_effect *base, struct d3dx_sampler *sampler,
5089 const char *data, const char **ptr, struct d3dx_object *objects)
5091 HRESULT hr;
5092 UINT i;
5094 read_dword(ptr, &sampler->state_count);
5095 TRACE("Count: %u\n", sampler->state_count);
5097 sampler->states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler->states) * sampler->state_count);
5098 if (!sampler->states)
5100 ERR("Out of memory\n");
5101 return E_OUTOFMEMORY;
5104 for (i = 0; i < sampler->state_count; ++i)
5106 hr = d3dx9_parse_state(base, &sampler->states[i], data, ptr, objects);
5107 if (hr != D3D_OK)
5109 WARN("Failed to parse state %u\n", i);
5110 goto err_out;
5114 return D3D_OK;
5116 err_out:
5118 for (i = 0; i < sampler->state_count; ++i)
5120 free_state(&sampler->states[i]);
5122 HeapFree(GetProcessHeap(), 0, sampler->states);
5123 sampler->states = NULL;
5125 return hr;
5128 static HRESULT d3dx9_parse_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
5129 void *value, const char *data, const char **ptr, struct d3dx_object *objects)
5131 unsigned int i;
5132 HRESULT hr;
5133 UINT old_size = 0;
5135 if (param->element_count)
5137 param->data = value;
5139 for (i = 0; i < param->element_count; ++i)
5141 struct d3dx_parameter *member = &param->members[i];
5143 hr = d3dx9_parse_value(base, member, value ? (char *)value + old_size : NULL, data, ptr, objects);
5144 if (hr != D3D_OK)
5146 WARN("Failed to parse value %u\n", i);
5147 return hr;
5150 old_size += member->bytes;
5153 return D3D_OK;
5156 switch(param->class)
5158 case D3DXPC_SCALAR:
5159 case D3DXPC_VECTOR:
5160 case D3DXPC_MATRIX_ROWS:
5161 case D3DXPC_MATRIX_COLUMNS:
5162 param->data = value;
5163 break;
5165 case D3DXPC_STRUCT:
5166 param->data = value;
5168 for (i = 0; i < param->member_count; ++i)
5170 struct d3dx_parameter *member = &param->members[i];
5172 hr = d3dx9_parse_value(base, member, (char *)value + old_size, data, ptr, objects);
5173 if (hr != D3D_OK)
5175 WARN("Failed to parse value %u\n", i);
5176 return hr;
5179 old_size += member->bytes;
5181 break;
5183 case D3DXPC_OBJECT:
5184 switch (param->type)
5186 case D3DXPT_STRING:
5187 case D3DXPT_TEXTURE:
5188 case D3DXPT_TEXTURE1D:
5189 case D3DXPT_TEXTURE2D:
5190 case D3DXPT_TEXTURE3D:
5191 case D3DXPT_TEXTURECUBE:
5192 case D3DXPT_PIXELSHADER:
5193 case D3DXPT_VERTEXSHADER:
5194 read_dword(ptr, &param->object_id);
5195 TRACE("Id: %u\n", param->object_id);
5196 objects[param->object_id].param = param;
5197 param->data = value;
5198 break;
5200 case D3DXPT_SAMPLER:
5201 case D3DXPT_SAMPLER1D:
5202 case D3DXPT_SAMPLER2D:
5203 case D3DXPT_SAMPLER3D:
5204 case D3DXPT_SAMPLERCUBE:
5206 struct d3dx_sampler *sampler;
5208 sampler = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler));
5209 if (!sampler)
5210 return E_OUTOFMEMORY;
5212 hr = d3dx9_parse_sampler(base, sampler, data, ptr, objects);
5213 if (hr != D3D_OK)
5215 HeapFree(GetProcessHeap(), 0, sampler);
5216 WARN("Failed to parse sampler\n");
5217 return hr;
5220 param->data = sampler;
5221 break;
5224 default:
5225 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5226 break;
5228 break;
5230 default:
5231 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
5232 break;
5235 return D3D_OK;
5238 static HRESULT d3dx9_parse_init_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
5239 const char *data, const char *ptr, struct d3dx_object *objects)
5241 UINT size = param->bytes;
5242 HRESULT hr;
5243 void *value = NULL;
5245 TRACE("param size: %u\n", size);
5247 if (size)
5249 value = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
5250 if (!value)
5252 ERR("Failed to allocate data memory.\n");
5253 return E_OUTOFMEMORY;
5256 switch(param->class)
5258 case D3DXPC_OBJECT:
5259 break;
5261 case D3DXPC_SCALAR:
5262 case D3DXPC_VECTOR:
5263 case D3DXPC_MATRIX_ROWS:
5264 case D3DXPC_MATRIX_COLUMNS:
5265 case D3DXPC_STRUCT:
5266 TRACE("Data: %s.\n", debugstr_an(ptr, size));
5267 memcpy(value, ptr, size);
5268 break;
5270 default:
5271 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
5272 break;
5276 hr = d3dx9_parse_value(base, param, value, data, &ptr, objects);
5277 if (hr != D3D_OK)
5279 WARN("Failed to parse value\n");
5280 HeapFree(GetProcessHeap(), 0, value);
5281 return hr;
5284 return D3D_OK;
5287 static HRESULT d3dx9_parse_name(char **name, const char *ptr)
5289 DWORD size;
5291 read_dword(&ptr, &size);
5292 TRACE("Name size: %#x\n", size);
5294 if (!size)
5296 return D3D_OK;
5299 *name = HeapAlloc(GetProcessHeap(), 0, size);
5300 if (!*name)
5302 ERR("Failed to allocate name memory.\n");
5303 return E_OUTOFMEMORY;
5306 TRACE("Name: %s.\n", debugstr_an(ptr, size));
5307 memcpy(*name, ptr, size);
5309 return D3D_OK;
5312 static HRESULT d3dx9_copy_data(struct d3dx9_base_effect *base, unsigned int object_id, const char **ptr)
5314 struct d3dx_object *object = &base->objects[object_id];
5316 if (object->size || object->data)
5318 if (object_id)
5319 FIXME("Overwriting object id %u!\n", object_id);
5320 else
5321 TRACE("Overwriting object id 0.\n");
5323 HeapFree(GetProcessHeap(), 0, object->data);
5324 object->data = NULL;
5327 read_dword(ptr, &object->size);
5328 TRACE("Data size: %#x.\n", object->size);
5330 if (!object->size)
5331 return D3D_OK;
5333 object->data = HeapAlloc(GetProcessHeap(), 0, object->size);
5334 if (!object->data)
5336 ERR("Failed to allocate object memory.\n");
5337 return E_OUTOFMEMORY;
5340 TRACE("Data: %s.\n", debugstr_an(*ptr, object->size));
5341 memcpy(object->data, *ptr, object->size);
5343 *ptr += ((object->size + 3) & ~3);
5345 return D3D_OK;
5348 static void param_set_magic_number(struct d3dx_parameter *param)
5350 memcpy(param->magic_string, parameter_magic_string, sizeof(parameter_magic_string));
5353 static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
5354 const char *data, const char **ptr, struct d3dx_parameter *parent, UINT flags)
5356 DWORD offset;
5357 HRESULT hr;
5358 UINT i;
5360 param->flags = flags;
5362 if (!parent)
5364 read_dword(ptr, (DWORD *)&param->type);
5365 TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
5367 read_dword(ptr, (DWORD *)&param->class);
5368 TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
5370 read_dword(ptr, &offset);
5371 TRACE("Type name offset: %#x\n", offset);
5372 hr = d3dx9_parse_name(&param->name, data + offset);
5373 if (hr != D3D_OK)
5375 WARN("Failed to parse name\n");
5376 goto err_out;
5379 read_dword(ptr, &offset);
5380 TRACE("Type semantic offset: %#x\n", offset);
5381 hr = d3dx9_parse_name(&param->semantic, data + offset);
5382 if (hr != D3D_OK)
5384 WARN("Failed to parse semantic\n");
5385 goto err_out;
5388 read_dword(ptr, &param->element_count);
5389 TRACE("Elements: %u\n", param->element_count);
5391 switch (param->class)
5393 case D3DXPC_VECTOR:
5394 read_dword(ptr, &param->columns);
5395 TRACE("Columns: %u\n", param->columns);
5397 read_dword(ptr, &param->rows);
5398 TRACE("Rows: %u\n", param->rows);
5400 /* sizeof(DWORD) * rows * columns */
5401 param->bytes = 4 * param->rows * param->columns;
5402 break;
5404 case D3DXPC_SCALAR:
5405 case D3DXPC_MATRIX_ROWS:
5406 case D3DXPC_MATRIX_COLUMNS:
5407 read_dword(ptr, &param->rows);
5408 TRACE("Rows: %u\n", param->rows);
5410 read_dword(ptr, &param->columns);
5411 TRACE("Columns: %u\n", param->columns);
5413 /* sizeof(DWORD) * rows * columns */
5414 param->bytes = 4 * param->rows * param->columns;
5415 break;
5417 case D3DXPC_STRUCT:
5418 read_dword(ptr, &param->member_count);
5419 TRACE("Members: %u\n", param->member_count);
5420 break;
5422 case D3DXPC_OBJECT:
5423 switch (param->type)
5425 case D3DXPT_STRING:
5426 case D3DXPT_PIXELSHADER:
5427 case D3DXPT_VERTEXSHADER:
5428 case D3DXPT_TEXTURE:
5429 case D3DXPT_TEXTURE1D:
5430 case D3DXPT_TEXTURE2D:
5431 case D3DXPT_TEXTURE3D:
5432 case D3DXPT_TEXTURECUBE:
5433 param->bytes = sizeof(void *);
5434 break;
5436 case D3DXPT_SAMPLER:
5437 case D3DXPT_SAMPLER1D:
5438 case D3DXPT_SAMPLER2D:
5439 case D3DXPT_SAMPLER3D:
5440 case D3DXPT_SAMPLERCUBE:
5441 param->bytes = 0;
5442 break;
5444 default:
5445 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5446 break;
5448 break;
5450 default:
5451 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
5452 break;
5455 else
5457 /* elements */
5458 param->type = parent->type;
5459 param->class = parent->class;
5460 param->name = parent->name;
5461 param->semantic = parent->semantic;
5462 param->element_count = 0;
5463 param->annotation_count = 0;
5464 param->member_count = parent->member_count;
5465 param->bytes = parent->bytes;
5466 param->rows = parent->rows;
5467 param->columns = parent->columns;
5470 if (param->element_count)
5472 unsigned int param_bytes = 0;
5473 const char *save_ptr = *ptr;
5475 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->element_count);
5476 if (!param->members)
5478 ERR("Out of memory\n");
5479 hr = E_OUTOFMEMORY;
5480 goto err_out;
5483 for (i = 0; i < param->element_count; ++i)
5485 *ptr = save_ptr;
5487 param_set_magic_number(&param->members[i]);
5488 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, param, flags);
5489 if (hr != D3D_OK)
5491 WARN("Failed to parse member %u\n", i);
5492 goto err_out;
5495 param_bytes += param->members[i].bytes;
5498 param->bytes = param_bytes;
5500 else if (param->member_count)
5502 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->member_count);
5503 if (!param->members)
5505 ERR("Out of memory\n");
5506 hr = E_OUTOFMEMORY;
5507 goto err_out;
5510 for (i = 0; i < param->member_count; ++i)
5512 param_set_magic_number(&param->members[i]);
5513 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, NULL, flags);
5514 if (hr != D3D_OK)
5516 WARN("Failed to parse member %u\n", i);
5517 goto err_out;
5520 param->bytes += param->members[i].bytes;
5523 return D3D_OK;
5525 err_out:
5527 if (param->members)
5529 unsigned int count = param->element_count ? param->element_count : param->member_count;
5531 for (i = 0; i < count; ++i)
5532 free_parameter(&param->members[i], param->element_count != 0, TRUE);
5533 HeapFree(GetProcessHeap(), 0, param->members);
5534 param->members = NULL;
5537 if (!parent)
5539 HeapFree(GetProcessHeap(), 0, param->name);
5540 HeapFree(GetProcessHeap(), 0, param->semantic);
5542 param->name = NULL;
5543 param->semantic = NULL;
5545 return hr;
5548 static HRESULT d3dx9_parse_effect_annotation(struct d3dx9_base_effect *base, struct d3dx_parameter *anno,
5549 const char *data, const char **ptr, struct d3dx_object *objects)
5551 DWORD offset;
5552 const char *ptr2;
5553 HRESULT hr;
5555 anno->flags = D3DX_PARAMETER_ANNOTATION;
5557 read_dword(ptr, &offset);
5558 TRACE("Typedef offset: %#x\n", offset);
5559 ptr2 = data + offset;
5560 hr = d3dx9_parse_effect_typedef(base, anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
5561 if (hr != D3D_OK)
5563 WARN("Failed to parse type definition\n");
5564 return hr;
5567 read_dword(ptr, &offset);
5568 TRACE("Value offset: %#x\n", offset);
5569 hr = d3dx9_parse_init_value(base, anno, data, data + offset, objects);
5570 if (hr != D3D_OK)
5572 WARN("Failed to parse value\n");
5573 return hr;
5576 return D3D_OK;
5579 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
5580 const char *data, const char **ptr, struct d3dx_object *objects)
5582 DWORD offset;
5583 const char *ptr2;
5584 HRESULT hr;
5586 state->type = ST_CONSTANT;
5588 read_dword(ptr, &state->operation);
5589 TRACE("Operation: %#x (%s)\n", state->operation, state_table[state->operation].name);
5591 read_dword(ptr, &state->index);
5592 TRACE("Index: %#x\n", state->index);
5594 read_dword(ptr, &offset);
5595 TRACE("Typedef offset: %#x\n", offset);
5596 ptr2 = data + offset;
5597 hr = d3dx9_parse_effect_typedef(base, &state->parameter, data, &ptr2, NULL, 0);
5598 if (hr != D3D_OK)
5600 WARN("Failed to parse type definition\n");
5601 goto err_out;
5604 read_dword(ptr, &offset);
5605 TRACE("Value offset: %#x\n", offset);
5606 hr = d3dx9_parse_init_value(base, &state->parameter, data, data + offset, objects);
5607 if (hr != D3D_OK)
5609 WARN("Failed to parse value\n");
5610 goto err_out;
5613 return D3D_OK;
5615 err_out:
5617 free_parameter(&state->parameter, FALSE, FALSE);
5619 return hr;
5622 static HRESULT d3dx9_parse_effect_parameter(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
5623 const char *data, const char **ptr, struct d3dx_object *objects)
5625 DWORD offset;
5626 HRESULT hr;
5627 unsigned int i;
5628 const char *ptr2;
5630 read_dword(ptr, &offset);
5631 TRACE("Typedef offset: %#x\n", offset);
5632 ptr2 = data + offset;
5634 read_dword(ptr, &offset);
5635 TRACE("Value offset: %#x\n", offset);
5637 read_dword(ptr, &param->flags);
5638 TRACE("Flags: %#x\n", param->flags);
5640 read_dword(ptr, &param->annotation_count);
5641 TRACE("Annotation count: %u\n", param->annotation_count);
5643 hr = d3dx9_parse_effect_typedef(base, param, data, &ptr2, NULL, param->flags);
5644 if (hr != D3D_OK)
5646 WARN("Failed to parse type definition\n");
5647 return hr;
5650 hr = d3dx9_parse_init_value(base, param, data, data + offset, objects);
5651 if (hr != D3D_OK)
5653 WARN("Failed to parse value\n");
5654 return hr;
5657 if (param->annotation_count)
5659 param->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5660 sizeof(*param->annotations) * param->annotation_count);
5661 if (!param->annotations)
5663 ERR("Out of memory\n");
5664 hr = E_OUTOFMEMORY;
5665 goto err_out;
5668 for (i = 0; i < param->annotation_count; ++i)
5670 param_set_magic_number(&param->annotations[i]);
5671 hr = d3dx9_parse_effect_annotation(base, &param->annotations[i], data, ptr, objects);
5672 if (hr != D3D_OK)
5674 WARN("Failed to parse annotation\n");
5675 goto err_out;
5680 return D3D_OK;
5682 err_out:
5684 if (param->annotations)
5686 for (i = 0; i < param->annotation_count; ++i)
5687 free_parameter(&param->annotations[i], FALSE, FALSE);
5688 HeapFree(GetProcessHeap(), 0, param->annotations);
5689 param->annotations = NULL;
5692 return hr;
5695 static HRESULT d3dx9_parse_effect_pass(struct d3dx9_base_effect *base, struct d3dx_pass *pass,
5696 const char *data, const char **ptr, struct d3dx_object *objects)
5698 DWORD offset;
5699 HRESULT hr;
5700 unsigned int i;
5701 struct d3dx_state *states = NULL;
5702 char *name = NULL;
5704 read_dword(ptr, &offset);
5705 TRACE("Pass name offset: %#x\n", offset);
5706 hr = d3dx9_parse_name(&name, data + offset);
5707 if (hr != D3D_OK)
5709 WARN("Failed to parse name\n");
5710 goto err_out;
5713 read_dword(ptr, &pass->annotation_count);
5714 TRACE("Annotation count: %u\n", pass->annotation_count);
5716 read_dword(ptr, &pass->state_count);
5717 TRACE("State count: %u\n", pass->state_count);
5719 if (pass->annotation_count)
5721 pass->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5722 sizeof(*pass->annotations) * pass->annotation_count);
5723 if (!pass->annotations)
5725 ERR("Out of memory\n");
5726 hr = E_OUTOFMEMORY;
5727 goto err_out;
5730 for (i = 0; i < pass->annotation_count; ++i)
5732 param_set_magic_number(&pass->annotations[i]);
5733 hr = d3dx9_parse_effect_annotation(base, &pass->annotations[i], data, ptr, objects);
5734 if (hr != D3D_OK)
5736 WARN("Failed to parse annotation %u\n", i);
5737 goto err_out;
5742 if (pass->state_count)
5744 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * pass->state_count);
5745 if (!states)
5747 ERR("Out of memory\n");
5748 hr = E_OUTOFMEMORY;
5749 goto err_out;
5752 for (i = 0; i < pass->state_count; ++i)
5754 hr = d3dx9_parse_state(base, &states[i], data, ptr, objects);
5755 if (hr != D3D_OK)
5757 WARN("Failed to parse annotation %u\n", i);
5758 goto err_out;
5763 pass->name = name;
5764 pass->states = states;
5766 return D3D_OK;
5768 err_out:
5770 if (pass->annotations)
5772 for (i = 0; i < pass->annotation_count; ++i)
5773 free_parameter(&pass->annotations[i], FALSE, FALSE);
5774 HeapFree(GetProcessHeap(), 0, pass->annotations);
5775 pass->annotations = NULL;
5778 if (states)
5780 for (i = 0; i < pass->state_count; ++i)
5782 free_state(&states[i]);
5784 HeapFree(GetProcessHeap(), 0, states);
5787 HeapFree(GetProcessHeap(), 0, name);
5789 return hr;
5792 static HRESULT d3dx9_parse_effect_technique(struct d3dx9_base_effect *base, struct d3dx_technique *technique,
5793 const char *data, const char **ptr, struct d3dx_object *objects)
5795 DWORD offset;
5796 HRESULT hr;
5797 unsigned int i;
5798 char *name = NULL;
5800 read_dword(ptr, &offset);
5801 TRACE("Technique name offset: %#x\n", offset);
5802 hr = d3dx9_parse_name(&name, data + offset);
5803 if (hr != D3D_OK)
5805 WARN("Failed to parse name\n");
5806 goto err_out;
5809 read_dword(ptr, &technique->annotation_count);
5810 TRACE("Annotation count: %u\n", technique->annotation_count);
5812 read_dword(ptr, &technique->pass_count);
5813 TRACE("Pass count: %u\n", technique->pass_count);
5815 if (technique->annotation_count)
5817 technique->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5818 sizeof(*technique->annotations) * technique->annotation_count);
5819 if (!technique->annotations)
5821 ERR("Out of memory\n");
5822 hr = E_OUTOFMEMORY;
5823 goto err_out;
5826 for (i = 0; i < technique->annotation_count; ++i)
5828 param_set_magic_number(&technique->annotations[i]);
5829 hr = d3dx9_parse_effect_annotation(base, &technique->annotations[i], data, ptr, objects);
5830 if (hr != D3D_OK)
5832 WARN("Failed to parse annotation %u\n", i);
5833 goto err_out;
5838 if (technique->pass_count)
5840 technique->passes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5841 sizeof(*technique->passes) * technique->pass_count);
5842 if (!technique->passes)
5844 ERR("Out of memory\n");
5845 hr = E_OUTOFMEMORY;
5846 goto err_out;
5849 for (i = 0; i < technique->pass_count; ++i)
5851 hr = d3dx9_parse_effect_pass(base, &technique->passes[i], data, ptr, objects);
5852 if (hr != D3D_OK)
5854 WARN("Failed to parse pass %u\n", i);
5855 goto err_out;
5860 technique->name = name;
5862 return D3D_OK;
5864 err_out:
5866 if (technique->passes)
5868 for (i = 0; i < technique->pass_count; ++i)
5869 free_pass(&technique->passes[i]);
5870 HeapFree(GetProcessHeap(), 0, technique->passes);
5871 technique->passes = NULL;
5874 if (technique->annotations)
5876 for (i = 0; i < technique->annotation_count; ++i)
5877 free_parameter(&technique->annotations[i], FALSE, FALSE);
5878 HeapFree(GetProcessHeap(), 0, technique->annotations);
5879 technique->annotations = NULL;
5882 HeapFree(GetProcessHeap(), 0, name);
5884 return hr;
5887 static HRESULT d3dx9_create_object(struct d3dx9_base_effect *base, struct d3dx_object *object)
5889 struct d3dx_parameter *param = object->param;
5890 struct IDirect3DDevice9 *device = base->effect->device;
5891 HRESULT hr;
5893 if (*(char **)param->data)
5894 ERR("Parameter data already allocated.\n");
5896 switch (param->type)
5898 case D3DXPT_STRING:
5899 *(char **)param->data = HeapAlloc(GetProcessHeap(), 0, object->size);
5900 if (!*(char **)param->data)
5902 ERR("Out of memory.\n");
5903 return E_OUTOFMEMORY;
5905 memcpy(*(char **)param->data, object->data, object->size);
5906 break;
5907 case D3DXPT_VERTEXSHADER:
5908 if (FAILED(hr = IDirect3DDevice9_CreateVertexShader(device, object->data,
5909 (IDirect3DVertexShader9 **)param->data)))
5911 WARN("Failed to create vertex shader.\n");
5912 return hr;
5914 break;
5915 case D3DXPT_PIXELSHADER:
5916 if (FAILED(hr = IDirect3DDevice9_CreatePixelShader(device, object->data,
5917 (IDirect3DPixelShader9 **)param->data)))
5919 WARN("Failed to create pixel shader.\n");
5920 return hr;
5922 break;
5923 default:
5924 break;
5926 return D3D_OK;
5929 static HRESULT d3dx9_parse_array_selector(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
5931 DWORD string_size;
5932 struct d3dx_object *object = &base->objects[param->object_id];
5933 char *ptr = object->data;
5934 HRESULT ret;
5936 TRACE("Parsing array entry selection state for parameter %p.\n", param);
5938 string_size = *(DWORD *)ptr;
5939 param->u.referenced_param = get_parameter_by_name(base, NULL, ptr + 4);
5940 if (param->u.referenced_param)
5942 TRACE("Mapping to parameter %s.\n", debugstr_a(param->u.referenced_param->name));
5944 else
5946 FIXME("Referenced parameter %s not found.\n", ptr + 4);
5947 return D3DXERR_INVALIDDATA;
5949 TRACE("Unknown DWORD: 0x%.8x.\n", *(DWORD *)(ptr + string_size));
5951 if (string_size % sizeof(DWORD))
5952 FIXME("Unaligned string_size %u.\n", string_size);
5953 d3dx_create_param_eval(base, (DWORD *)(ptr + string_size) + 1, object->size - (string_size + sizeof(DWORD)),
5954 D3DXPT_INT, &param->param_eval, get_version_counter_ptr(base));
5955 ret = D3D_OK;
5956 param = param->u.referenced_param;
5957 if (param->type == D3DXPT_VERTEXSHADER || param->type == D3DXPT_PIXELSHADER)
5959 unsigned int i;
5961 for (i = 0; i < param->element_count; i++)
5963 if (param->members[i].type != param->type)
5965 FIXME("Unexpected member parameter type %u, expected %u.\n", param->members[i].type, param->type);
5966 return D3DXERR_INVALIDDATA;
5968 if (!param->members[i].param_eval)
5970 TRACE("Creating preshader for object %u.\n", param->members[i].object_id);
5971 object = &base->objects[param->members[i].object_id];
5972 d3dx_create_param_eval(base, object->data, object->size, param->type,
5973 &param->members[i].param_eval, get_version_counter_ptr(base));
5977 return ret;
5980 static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *data, const char **ptr)
5982 DWORD technique_index;
5983 DWORD index, state_index, usage, element_index;
5984 struct d3dx_state *state;
5985 struct d3dx_parameter *param;
5986 struct d3dx_object *object;
5987 HRESULT hr = E_FAIL;
5989 read_dword(ptr, &technique_index);
5990 TRACE("technique_index: %u\n", technique_index);
5992 read_dword(ptr, &index);
5993 TRACE("index: %u\n", index);
5995 read_dword(ptr, &element_index);
5996 TRACE("element_index: %u\n", element_index);
5998 read_dword(ptr, &state_index);
5999 TRACE("state_index: %u\n", state_index);
6001 read_dword(ptr, &usage);
6002 TRACE("usage: %u\n", usage);
6004 if (technique_index == 0xffffffff)
6006 struct d3dx_parameter *parameter;
6007 struct d3dx_sampler *sampler;
6009 if (index >= base->parameter_count)
6011 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index, base->parameter_count);
6012 return E_FAIL;
6015 parameter = &base->parameters[index];
6016 if (element_index != 0xffffffff)
6018 if (element_index >= parameter->element_count && parameter->element_count != 0)
6020 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index, parameter->element_count);
6021 return E_FAIL;
6024 if (parameter->element_count != 0) parameter = &parameter->members[element_index];
6027 sampler = parameter->data;
6028 if (state_index >= sampler->state_count)
6030 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, sampler->state_count);
6031 return E_FAIL;
6034 state = &sampler->states[state_index];
6036 else
6038 struct d3dx_technique *technique;
6039 struct d3dx_pass *pass;
6041 if (technique_index >= base->technique_count)
6043 FIXME("Index out of bounds: technique_index %u >= technique_count %u\n", technique_index, base->technique_count);
6044 return E_FAIL;
6047 technique = &base->techniques[technique_index];
6048 if (index >= technique->pass_count)
6050 FIXME("Index out of bounds: index %u >= pass_count %u\n", index, technique->pass_count);
6051 return E_FAIL;
6054 pass = &technique->passes[index];
6055 if (state_index >= pass->state_count)
6057 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, pass->state_count);
6058 return E_FAIL;
6061 state = &pass->states[state_index];
6064 TRACE("State operation %#x (%s).\n", state->operation, state_table[state->operation].name);
6065 param = &state->parameter;
6066 TRACE("Using object id %u.\n", param->object_id);
6067 object = &base->objects[param->object_id];
6069 TRACE("Usage %u: class %s, type %s.\n", usage, debug_d3dxparameter_class(param->class),
6070 debug_d3dxparameter_type(param->type));
6071 switch (usage)
6073 case 0:
6074 switch (param->type)
6076 case D3DXPT_VERTEXSHADER:
6077 case D3DXPT_PIXELSHADER:
6078 state->type = ST_CONSTANT;
6079 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
6080 return hr;
6082 if (object->data)
6084 if (FAILED(hr = d3dx9_create_object(base, object)))
6085 return hr;
6086 d3dx_create_param_eval(base, object->data, object->size, param->type,
6087 &param->param_eval, get_version_counter_ptr(base));
6089 break;
6091 case D3DXPT_BOOL:
6092 case D3DXPT_INT:
6093 case D3DXPT_FLOAT:
6094 case D3DXPT_STRING:
6095 state->type = ST_FXLC;
6096 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
6097 return hr;
6098 d3dx_create_param_eval(base, object->data, object->size, param->type,
6099 &param->param_eval, get_version_counter_ptr(base));
6100 break;
6102 default:
6103 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
6104 break;
6106 break;
6108 case 1:
6109 state->type = ST_PARAMETER;
6110 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
6111 return hr;
6113 TRACE("Looking for parameter %s.\n", debugstr_a(object->data));
6114 param->u.referenced_param = get_parameter_by_name(base, NULL, object->data);
6115 if (param->u.referenced_param)
6117 struct d3dx_parameter *refpar = param->u.referenced_param;
6119 TRACE("Mapping to parameter %p, having object id %u.\n", refpar, refpar->object_id);
6120 if (refpar->type == D3DXPT_VERTEXSHADER || refpar->type == D3DXPT_PIXELSHADER)
6122 struct d3dx_object *refobj = &base->objects[refpar->object_id];
6124 if (!refpar->param_eval)
6125 d3dx_create_param_eval(base, refobj->data, refobj->size,
6126 refpar->type, &refpar->param_eval, get_version_counter_ptr(base));
6129 else
6131 FIXME("Referenced parameter %s not found.\n", (char *)object->data);
6132 return D3DXERR_INVALIDDATA;
6134 break;
6136 case 2:
6137 state->type = ST_ARRAY_SELECTOR;
6138 if (FAILED(hr = d3dx9_copy_data(base, param->object_id, ptr)))
6139 return hr;
6140 hr = d3dx9_parse_array_selector(base, param);
6141 break;
6143 default:
6144 FIXME("Unknown usage %x\n", usage);
6145 break;
6148 return hr;
6151 static BOOL param_set_top_level_param(void *top_level_param, struct d3dx_parameter *param)
6153 param->top_level_param = top_level_param;
6154 return FALSE;
6157 static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *data, UINT data_size, DWORD start)
6159 const char *ptr = data + start;
6160 UINT stringcount, resourcecount;
6161 HRESULT hr;
6162 UINT i;
6164 read_dword(&ptr, &base->parameter_count);
6165 TRACE("Parameter count: %u\n", base->parameter_count);
6167 read_dword(&ptr, &base->technique_count);
6168 TRACE("Technique count: %u\n", base->technique_count);
6170 skip_dword_unknown(&ptr, 1);
6172 read_dword(&ptr, &base->object_count);
6173 TRACE("Object count: %u\n", base->object_count);
6175 base->objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*base->objects) * base->object_count);
6176 if (!base->objects)
6178 ERR("Out of memory\n");
6179 hr = E_OUTOFMEMORY;
6180 goto err_out;
6183 if (base->parameter_count)
6185 base->parameters = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
6186 sizeof(*base->parameters) * base->parameter_count);
6187 if (!base->parameters)
6189 ERR("Out of memory\n");
6190 hr = E_OUTOFMEMORY;
6191 goto err_out;
6194 for (i = 0; i < base->parameter_count; ++i)
6196 param_set_magic_number(&base->parameters[i]);
6197 hr = d3dx9_parse_effect_parameter(base, &base->parameters[i], data, &ptr, base->objects);
6198 if (hr != D3D_OK)
6200 WARN("Failed to parse parameter %u\n", i);
6201 goto err_out;
6206 if (base->technique_count)
6208 base->techniques = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
6209 sizeof(*base->techniques) * base->technique_count);
6210 if (!base->techniques)
6212 ERR("Out of memory\n");
6213 hr = E_OUTOFMEMORY;
6214 goto err_out;
6217 for (i = 0; i < base->technique_count; ++i)
6219 TRACE("Parsing technique %u.\n", i);
6220 hr = d3dx9_parse_effect_technique(base, &base->techniques[i], data, &ptr, base->objects);
6221 if (hr != D3D_OK)
6223 WARN("Failed to parse technique %u\n", i);
6224 goto err_out;
6229 read_dword(&ptr, &stringcount);
6230 TRACE("String count: %u\n", stringcount);
6232 read_dword(&ptr, &resourcecount);
6233 TRACE("Resource count: %u\n", resourcecount);
6235 for (i = 0; i < stringcount; ++i)
6237 DWORD id;
6239 read_dword(&ptr, &id);
6240 TRACE("Id: %u\n", id);
6242 if (FAILED(hr = d3dx9_copy_data(base, id, &ptr)))
6243 goto err_out;
6245 if (base->objects[id].data)
6247 if (FAILED(hr = d3dx9_create_object(base, &base->objects[id])))
6248 goto err_out;
6252 for (i = 0; i < resourcecount; ++i)
6254 TRACE("parse resource %u\n", i);
6256 hr = d3dx9_parse_resource(base, data, &ptr);
6257 if (hr != D3D_OK)
6259 WARN("Failed to parse resource %u\n", i);
6260 goto err_out;
6264 for (i = 0; i < base->parameter_count; ++i)
6266 if (FAILED(hr = d3dx_pool_sync_shared_parameter(base->pool, &base->parameters[i])))
6267 goto err_out;
6268 walk_parameter_tree(&base->parameters[i], param_set_top_level_param,
6269 &base->parameters[i]);
6270 base->parameters[i].version_counter = base->pool
6271 ? &base->pool->version_counter
6272 : &base->version_counter;
6273 set_dirty(&base->parameters[i]);
6275 return D3D_OK;
6277 err_out:
6279 if (base->techniques)
6281 for (i = 0; i < base->technique_count; ++i)
6282 free_technique(&base->techniques[i]);
6283 HeapFree(GetProcessHeap(), 0, base->techniques);
6284 base->techniques = NULL;
6287 if (base->parameters)
6289 for (i = 0; i < base->parameter_count; ++i)
6291 free_parameter(&base->parameters[i], FALSE, FALSE);
6293 HeapFree(GetProcessHeap(), 0, base->parameters);
6294 base->parameters = NULL;
6297 if (base->objects)
6299 for (i = 0; i < base->object_count; ++i)
6301 free_object(&base->objects[i]);
6303 HeapFree(GetProcessHeap(), 0, base->objects);
6304 base->objects = NULL;
6307 return hr;
6310 static HRESULT d3dx9_base_effect_init(struct d3dx9_base_effect *base,
6311 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
6312 UINT eflags, ID3DBlob **errors, struct ID3DXEffectImpl *effect, struct d3dx_effect_pool *pool)
6314 DWORD tag, offset;
6315 const char *ptr = data;
6316 HRESULT hr;
6317 ID3DBlob *bytecode = NULL, *temp_errors = NULL;
6319 TRACE("base %p, data %p, data_size %lu, effect %p, pool %p.\n", base, data, data_size, effect, pool);
6321 base->effect = effect;
6322 base->pool = pool;
6323 base->flags = eflags;
6325 read_dword(&ptr, &tag);
6326 TRACE("Tag: %x\n", tag);
6328 if (tag != d3dx9_effect_version(9, 1))
6330 TRACE("HLSL ASCII effect, trying to compile it.\n");
6331 hr = D3DCompile(data, data_size, NULL, defines, include,
6332 "main", "fx_2_0", 0, eflags, &bytecode, &temp_errors);
6333 if (FAILED(hr))
6335 WARN("Failed to compile ASCII effect.\n");
6336 if (bytecode)
6337 ID3D10Blob_Release(bytecode);
6338 if (temp_errors)
6340 const char *error_string = ID3D10Blob_GetBufferPointer(temp_errors);
6341 const char *string_ptr;
6343 while (*error_string)
6345 string_ptr = error_string;
6346 while (*string_ptr && *string_ptr != '\n' && *string_ptr != '\r'
6347 && string_ptr - error_string < 80)
6348 ++string_ptr;
6349 TRACE("%s\n", debugstr_an(error_string, string_ptr - error_string));
6350 error_string = string_ptr;
6351 while (*error_string == '\n' || *error_string == '\r')
6352 ++error_string;
6355 if (errors)
6356 *errors = temp_errors;
6357 else if (temp_errors)
6358 ID3D10Blob_Release(temp_errors);
6359 return hr;
6361 if (!bytecode)
6363 FIXME("No output from effect compilation.\n");
6364 return D3DERR_INVALIDCALL;
6366 if (errors)
6367 *errors = temp_errors;
6368 else if (temp_errors)
6369 ID3D10Blob_Release(temp_errors);
6371 ptr = ID3D10Blob_GetBufferPointer(bytecode);
6372 read_dword(&ptr, &tag);
6373 TRACE("Tag: %x\n", tag);
6376 read_dword(&ptr, &offset);
6377 TRACE("Offset: %x\n", offset);
6379 hr = d3dx9_parse_effect(base, ptr, data_size, offset);
6380 if (bytecode)
6381 ID3D10Blob_Release(bytecode);
6382 if (hr != D3D_OK)
6384 FIXME("Failed to parse effect.\n");
6385 return hr;
6388 return D3D_OK;
6391 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, struct IDirect3DDevice9 *device,
6392 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
6393 UINT eflags, ID3DBlob **error_messages, struct ID3DXEffectPool *pool)
6395 HRESULT hr;
6396 struct d3dx_effect_pool *pool_impl = NULL;
6398 TRACE("effect %p, device %p, data %p, data_size %lu, pool %p\n", effect, device, data, data_size, pool);
6400 effect->ID3DXEffect_iface.lpVtbl = &ID3DXEffect_Vtbl;
6401 effect->ref = 1;
6403 if (pool)
6405 pool->lpVtbl->AddRef(pool);
6406 pool_impl = impl_from_ID3DXEffectPool(pool);
6408 effect->pool = pool;
6410 IDirect3DDevice9_AddRef(device);
6411 effect->device = device;
6413 if (FAILED(hr = d3dx9_base_effect_init(&effect->base_effect, data, data_size, defines, include,
6414 eflags, error_messages, effect, pool_impl)))
6416 FIXME("Failed to parse effect, hr %#x.\n", hr);
6417 free_effect(effect);
6418 return hr;
6421 /* initialize defaults - check because of unsupported ascii effects */
6422 if (effect->base_effect.techniques)
6424 effect->active_technique = &effect->base_effect.techniques[0];
6425 effect->active_pass = NULL;
6428 return D3D_OK;
6431 HRESULT WINAPI D3DXCreateEffectEx(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
6432 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skip_constants, DWORD flags,
6433 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
6435 struct ID3DXEffectImpl *object;
6436 HRESULT hr;
6438 TRACE("device %p, srcdata %p, srcdatalen %u, defines %p, include %p,"
6439 " skip_constants %p, flags %#x, pool %p, effect %p, compilation_errors %p.\n",
6440 device, srcdata, srcdatalen, defines, include,
6441 skip_constants, flags, pool, effect, compilation_errors);
6443 if (compilation_errors)
6444 *compilation_errors = NULL;
6446 if (!device || !srcdata)
6447 return D3DERR_INVALIDCALL;
6449 if (!srcdatalen)
6450 return E_FAIL;
6452 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
6453 if (!effect)
6454 return D3D_OK;
6456 if (skip_constants)
6457 FIXME("skip_constants is not NULL, not supported yet.\n");
6459 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6460 if (!object)
6461 return E_OUTOFMEMORY;
6463 hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
6464 (ID3DInclude *)include, flags, (ID3DBlob **)compilation_errors, pool);
6465 if (FAILED(hr))
6467 WARN("Failed to create effect object.\n");
6468 HeapFree(GetProcessHeap(), 0, object);
6469 return hr;
6472 *effect = &object->ID3DXEffect_iface;
6474 TRACE("Created ID3DXEffect %p\n", object);
6476 return D3D_OK;
6479 HRESULT WINAPI D3DXCreateEffect(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
6480 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6481 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
6483 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device, srcdata, srcdatalen, defines,
6484 include, flags, pool, effect, compilation_errors);
6486 return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
6489 static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler,
6490 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
6491 UINT eflags, ID3DBlob **error_messages)
6493 HRESULT hr;
6495 TRACE("effect %p, data %p, data_size %lu\n", compiler, data, data_size);
6497 compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
6498 compiler->ref = 1;
6500 if (FAILED(hr = d3dx9_base_effect_init(&compiler->base_effect, data, data_size, defines,
6501 include, eflags, error_messages, NULL, NULL)))
6503 FIXME("Failed to parse effect, hr %#x.\n", hr);
6504 free_effect_compiler(compiler);
6505 return hr;
6508 return D3D_OK;
6511 HRESULT WINAPI D3DXCreateEffectCompiler(const char *srcdata, UINT srcdatalen, const D3DXMACRO *defines,
6512 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **compiler, ID3DXBuffer **parse_errors)
6514 struct ID3DXEffectCompilerImpl *object;
6515 HRESULT hr;
6517 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
6518 srcdata, srcdatalen, defines, include, flags, compiler, parse_errors);
6520 if (!srcdata || !compiler)
6522 WARN("Invalid arguments supplied\n");
6523 return D3DERR_INVALIDCALL;
6526 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6527 if (!object)
6528 return E_OUTOFMEMORY;
6530 hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
6531 (ID3DInclude *)include, flags, (ID3DBlob **)parse_errors);
6532 if (FAILED(hr))
6534 WARN("Failed to initialize effect compiler\n");
6535 HeapFree(GetProcessHeap(), 0, object);
6536 return hr;
6539 *compiler = &object->ID3DXEffectCompiler_iface;
6541 TRACE("Created ID3DXEffectCompiler %p\n", object);
6543 return D3D_OK;
6546 /*** IUnknown methods ***/
6547 static HRESULT WINAPI d3dx_effect_pool_QueryInterface(ID3DXEffectPool *iface, REFIID riid, void **object)
6549 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
6551 if (IsEqualGUID(riid, &IID_IUnknown) ||
6552 IsEqualGUID(riid, &IID_ID3DXEffectPool))
6554 iface->lpVtbl->AddRef(iface);
6555 *object = iface;
6556 return S_OK;
6559 WARN("Interface %s not found\n", debugstr_guid(riid));
6561 return E_NOINTERFACE;
6564 static ULONG WINAPI d3dx_effect_pool_AddRef(ID3DXEffectPool *iface)
6566 struct d3dx_effect_pool *pool = impl_from_ID3DXEffectPool(iface);
6567 ULONG refcount = InterlockedIncrement(&pool->refcount);
6569 TRACE("%p increasing refcount to %u.\n", pool, refcount);
6571 return refcount;
6574 static void free_effect_pool(struct d3dx_effect_pool *pool)
6576 unsigned int i;
6578 for (i = 0; i < pool->size; ++i)
6580 if (pool->shared_data[i].count)
6582 unsigned int j;
6584 WARN("Releasing pool with referenced parameters.\n");
6586 param_set_data_pointer(pool->shared_data[i].parameters[0], NULL, FALSE, TRUE);
6587 pool->shared_data[i].parameters[0]->u.shared_data = NULL;
6589 for (j = 1; j < pool->shared_data[i].count; ++j)
6591 walk_parameter_tree(pool->shared_data[i].parameters[j], param_zero_data_func, NULL);
6592 pool->shared_data[i].parameters[j]->u.shared_data = NULL;
6594 HeapFree(GetProcessHeap(), 0, pool->shared_data[i].parameters);
6597 HeapFree(GetProcessHeap(), 0, pool->shared_data);
6598 HeapFree(GetProcessHeap(), 0, pool);
6601 static ULONG WINAPI d3dx_effect_pool_Release(ID3DXEffectPool *iface)
6603 struct d3dx_effect_pool *pool = impl_from_ID3DXEffectPool(iface);
6604 ULONG refcount = InterlockedDecrement(&pool->refcount);
6606 TRACE("%p decreasing refcount to %u.\n", pool, refcount);
6608 if (!refcount)
6609 free_effect_pool(pool);
6611 return refcount;
6614 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl =
6616 /*** IUnknown methods ***/
6617 d3dx_effect_pool_QueryInterface,
6618 d3dx_effect_pool_AddRef,
6619 d3dx_effect_pool_Release
6622 HRESULT WINAPI D3DXCreateEffectPool(ID3DXEffectPool **pool)
6624 struct d3dx_effect_pool *object;
6626 TRACE("pool %p.\n", pool);
6628 if (!pool)
6629 return D3DERR_INVALIDCALL;
6631 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6632 if (!object)
6633 return E_OUTOFMEMORY;
6635 object->ID3DXEffectPool_iface.lpVtbl = &ID3DXEffectPool_Vtbl;
6636 object->refcount = 1;
6638 *pool = &object->ID3DXEffectPool_iface;
6640 return S_OK;
6643 HRESULT WINAPI D3DXCreateEffectFromFileExW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
6644 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
6645 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6647 void *buffer;
6648 HRESULT ret;
6649 DWORD size;
6651 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6652 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6653 device, debugstr_w(srcfile), defines, include, debugstr_a(skipconstants),
6654 flags, pool, effect, compilationerrors);
6656 if (!device || !srcfile)
6657 return D3DERR_INVALIDCALL;
6659 ret = map_view_of_file(srcfile, &buffer, &size);
6661 if (FAILED(ret))
6662 return D3DXERR_INVALIDDATA;
6664 ret = D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6665 UnmapViewOfFile(buffer);
6667 return ret;
6670 HRESULT WINAPI D3DXCreateEffectFromFileExA(struct IDirect3DDevice9 *device, const char *srcfile,
6671 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
6672 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6674 WCHAR *srcfileW;
6675 HRESULT ret;
6676 DWORD len;
6678 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6679 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6680 device, debugstr_a(srcfile), defines, include, debugstr_a(skipconstants),
6681 flags, pool, effect, compilationerrors);
6683 if (!srcfile)
6684 return D3DERR_INVALIDCALL;
6686 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6687 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6688 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6690 ret = D3DXCreateEffectFromFileExW(device, srcfileW, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6691 HeapFree(GetProcessHeap(), 0, srcfileW);
6693 return ret;
6696 HRESULT WINAPI D3DXCreateEffectFromFileW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
6697 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
6698 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6700 TRACE("(void): relay\n");
6701 return D3DXCreateEffectFromFileExW(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6704 HRESULT WINAPI D3DXCreateEffectFromFileA(struct IDirect3DDevice9 *device, const char *srcfile,
6705 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
6706 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6708 TRACE("(void): relay\n");
6709 return D3DXCreateEffectFromFileExA(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6712 HRESULT WINAPI D3DXCreateEffectFromResourceExW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6713 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
6714 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6716 HRSRC resinfo;
6717 void *buffer;
6718 DWORD size;
6720 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6721 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6722 device, srcmodule, debugstr_w(srcresource), defines, include, debugstr_a(skipconstants),
6723 flags, pool, effect, compilationerrors);
6725 if (!device)
6726 return D3DERR_INVALIDCALL;
6728 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
6729 return D3DXERR_INVALIDDATA;
6731 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6732 return D3DXERR_INVALIDDATA;
6734 return D3DXCreateEffectEx(device, buffer, size, defines, include,
6735 skipconstants, flags, pool, effect, compilationerrors);
6738 HRESULT WINAPI D3DXCreateEffectFromResourceExA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6739 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
6740 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6742 HRSRC resinfo;
6743 void *buffer;
6744 DWORD size;
6746 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6747 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6748 device, srcmodule, debugstr_a(srcresource), defines, include, debugstr_a(skipconstants),
6749 flags, pool, effect, compilationerrors);
6751 if (!device)
6752 return D3DERR_INVALIDCALL;
6754 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
6755 return D3DXERR_INVALIDDATA;
6757 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6758 return D3DXERR_INVALIDDATA;
6760 return D3DXCreateEffectEx(device, buffer, size, defines, include,
6761 skipconstants, flags, pool, effect, compilationerrors);
6764 HRESULT WINAPI D3DXCreateEffectFromResourceW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6765 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6766 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6768 TRACE("(void): relay\n");
6769 return D3DXCreateEffectFromResourceExW(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6772 HRESULT WINAPI D3DXCreateEffectFromResourceA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6773 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6774 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6776 TRACE("(void): relay\n");
6777 return D3DXCreateEffectFromResourceExA(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6780 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(const WCHAR *srcfile, const D3DXMACRO *defines,
6781 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6783 void *buffer;
6784 HRESULT ret;
6785 DWORD size;
6787 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6788 debugstr_w(srcfile), defines, include, flags, effectcompiler, parseerrors);
6790 if (!srcfile)
6791 return D3DERR_INVALIDCALL;
6793 ret = map_view_of_file(srcfile, &buffer, &size);
6795 if (FAILED(ret))
6796 return D3DXERR_INVALIDDATA;
6798 ret = D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6799 UnmapViewOfFile(buffer);
6801 return ret;
6804 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(const char *srcfile, const D3DXMACRO *defines,
6805 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6807 WCHAR *srcfileW;
6808 HRESULT ret;
6809 DWORD len;
6811 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6812 debugstr_a(srcfile), defines, include, flags, effectcompiler, parseerrors);
6814 if (!srcfile)
6815 return D3DERR_INVALIDCALL;
6817 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6818 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6819 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6821 ret = D3DXCreateEffectCompilerFromFileW(srcfileW, defines, include, flags, effectcompiler, parseerrors);
6822 HeapFree(GetProcessHeap(), 0, srcfileW);
6824 return ret;
6827 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule, const char *srcresource,
6828 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
6829 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6831 HRSRC resinfo;
6832 void *buffer;
6833 DWORD size;
6835 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6836 srcmodule, debugstr_a(srcresource), defines, include, flags, effectcompiler, parseerrors);
6838 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
6839 return D3DXERR_INVALIDDATA;
6841 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6842 return D3DXERR_INVALIDDATA;
6844 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6847 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule, const WCHAR *srcresource,
6848 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
6849 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6851 HRSRC resinfo;
6852 void *buffer;
6853 DWORD size;
6855 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6856 srcmodule, debugstr_w(srcresource), defines, include, flags, effectcompiler, parseerrors);
6858 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
6859 return D3DXERR_INVALIDDATA;
6861 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6862 return D3DXERR_INVALIDDATA;
6864 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6867 HRESULT WINAPI D3DXDisassembleEffect(ID3DXEffect *effect, BOOL enable_color_code, ID3DXBuffer **disassembly)
6869 FIXME("(%p, %u, %p): stub\n", effect, enable_color_code, disassembly);
6871 return D3DXERR_INVALIDDATA;