wined3d: Use the texture dimension helpers in surface_is_full_rect().
[wine.git] / dlls / d3dx9_36 / effect.c
blob76a012d3c2dbebae83ed8a6ee44ac4e9c5e0ee5a
1 /*
2 * Copyright 2010 Christian Costa
3 * Copyright 2011 Rico Schüller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3dx9_private.h"
24 #include "d3dcompiler.h"
26 /* Constants for special INT/FLOAT conversation */
27 #define INT_FLOAT_MULTI 255.0f
28 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
30 #define INITIAL_PARAM_TABLE_SIZE 16
32 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
34 enum STATE_CLASS
36 SC_LIGHTENABLE,
37 SC_FVF,
38 SC_LIGHT,
39 SC_MATERIAL,
40 SC_NPATCHMODE,
41 SC_PIXELSHADER,
42 SC_RENDERSTATE,
43 SC_SETSAMPLER,
44 SC_SAMPLERSTATE,
45 SC_TEXTURE,
46 SC_TEXTURESTAGE,
47 SC_TRANSFORM,
48 SC_VERTEXSHADER,
49 SC_SHADERCONST,
50 SC_UNKNOWN,
53 enum MATERIAL_TYPE
55 MT_DIFFUSE,
56 MT_AMBIENT,
57 MT_SPECULAR,
58 MT_EMISSIVE,
59 MT_POWER,
62 enum LIGHT_TYPE
64 LT_TYPE,
65 LT_DIFFUSE,
66 LT_SPECULAR,
67 LT_AMBIENT,
68 LT_POSITION,
69 LT_DIRECTION,
70 LT_RANGE,
71 LT_FALLOFF,
72 LT_ATTENUATION0,
73 LT_ATTENUATION1,
74 LT_ATTENUATION2,
75 LT_THETA,
76 LT_PHI,
79 enum SHADER_CONSTANT_TYPE
81 SCT_VSFLOAT,
82 SCT_VSBOOL,
83 SCT_VSINT,
84 SCT_PSFLOAT,
85 SCT_PSBOOL,
86 SCT_PSINT,
89 enum STATE_TYPE
91 ST_CONSTANT,
92 ST_PARAMETER,
93 ST_FXLC,
94 ST_ARRAY_SELECTOR,
97 struct d3dx_object
99 UINT size;
100 void *data;
101 struct d3dx_parameter *param;
104 struct d3dx_state
106 UINT operation;
107 UINT index;
108 enum STATE_TYPE type;
109 struct d3dx_parameter parameter;
112 struct d3dx_sampler
114 UINT state_count;
115 struct d3dx_state *states;
118 struct d3dx_pass
120 char *name;
121 UINT state_count;
122 UINT annotation_count;
124 struct d3dx_state *states;
125 struct d3dx_parameter *annotations;
128 struct d3dx_technique
130 char *name;
131 UINT pass_count;
132 UINT annotation_count;
134 struct d3dx_parameter *annotations;
135 struct d3dx_pass *passes;
137 struct IDirect3DStateBlock9 *saved_state;
140 struct param_table
142 struct d3dx_parameter **table;
143 unsigned int count, size;
146 struct d3dx9_base_effect
148 struct ID3DXEffectImpl *effect;
150 UINT parameter_count;
151 UINT technique_count;
152 UINT object_count;
154 struct d3dx_parameter *parameters;
155 struct d3dx_technique *techniques;
156 struct d3dx_object *objects;
158 struct param_table param_table;
161 struct ID3DXEffectImpl
163 ID3DXEffect ID3DXEffect_iface;
164 LONG ref;
166 struct d3dx9_base_effect base_effect;
168 struct ID3DXEffectStateManager *manager;
169 struct IDirect3DDevice9 *device;
170 struct ID3DXEffectPool *pool;
171 struct d3dx_technique *active_technique;
172 struct d3dx_pass *active_pass;
173 BOOL started;
174 DWORD flags;
177 struct ID3DXEffectCompilerImpl
179 ID3DXEffectCompiler ID3DXEffectCompiler_iface;
180 LONG ref;
182 struct d3dx9_base_effect base_effect;
185 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *parameters,
186 const char *name);
187 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
188 const char *data, const char **ptr, struct d3dx_object *objects);
189 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child);
191 static const struct
193 enum STATE_CLASS class;
194 UINT op;
195 const char *name;
197 state_table[] =
199 /* Render sates */
200 {SC_RENDERSTATE, D3DRS_ZENABLE, "D3DRS_ZENABLE"}, /* 0x0 */
201 {SC_RENDERSTATE, D3DRS_FILLMODE, "D3DRS_FILLMODE"},
202 {SC_RENDERSTATE, D3DRS_SHADEMODE, "D3DRS_SHADEMODE"},
203 {SC_RENDERSTATE, D3DRS_ZWRITEENABLE, "D3DRS_ZWRITEENABLE"},
204 {SC_RENDERSTATE, D3DRS_ALPHATESTENABLE, "D3DRS_ALPHATESTENABLE"},
205 {SC_RENDERSTATE, D3DRS_LASTPIXEL, "D3DRS_LASTPIXEL"},
206 {SC_RENDERSTATE, D3DRS_SRCBLEND, "D3DRS_SRCBLEND"},
207 {SC_RENDERSTATE, D3DRS_DESTBLEND, "D3DRS_DESTBLEND"},
208 {SC_RENDERSTATE, D3DRS_CULLMODE, "D3DRS_CULLMODE"},
209 {SC_RENDERSTATE, D3DRS_ZFUNC, "D3DRS_ZFUNC"},
210 {SC_RENDERSTATE, D3DRS_ALPHAREF, "D3DRS_ALPHAREF"},
211 {SC_RENDERSTATE, D3DRS_ALPHAFUNC, "D3DRS_ALPHAFUNC"},
212 {SC_RENDERSTATE, D3DRS_DITHERENABLE, "D3DRS_DITHERENABLE"},
213 {SC_RENDERSTATE, D3DRS_ALPHABLENDENABLE, "D3DRS_ALPHABLENDENABLE"},
214 {SC_RENDERSTATE, D3DRS_FOGENABLE, "D3DRS_FOGENABLE"},
215 {SC_RENDERSTATE, D3DRS_SPECULARENABLE, "D3DRS_SPECULARENABLE"},
216 {SC_RENDERSTATE, D3DRS_FOGCOLOR, "D3DRS_FOGCOLOR"}, /* 0x10 */
217 {SC_RENDERSTATE, D3DRS_FOGTABLEMODE, "D3DRS_FOGTABLEMODE"},
218 {SC_RENDERSTATE, D3DRS_FOGSTART, "D3DRS_FOGSTART"},
219 {SC_RENDERSTATE, D3DRS_FOGEND, "D3DRS_FOGEND"},
220 {SC_RENDERSTATE, D3DRS_FOGDENSITY, "D3DRS_FOGDENSITY"},
221 {SC_RENDERSTATE, D3DRS_RANGEFOGENABLE, "D3DRS_RANGEFOGENABLE"},
222 {SC_RENDERSTATE, D3DRS_STENCILENABLE, "D3DRS_STENCILENABLE"},
223 {SC_RENDERSTATE, D3DRS_STENCILFAIL, "D3DRS_STENCILFAIL"},
224 {SC_RENDERSTATE, D3DRS_STENCILZFAIL, "D3DRS_STENCILZFAIL"},
225 {SC_RENDERSTATE, D3DRS_STENCILPASS, "D3DRS_STENCILPASS"},
226 {SC_RENDERSTATE, D3DRS_STENCILFUNC, "D3DRS_STENCILFUNC"},
227 {SC_RENDERSTATE, D3DRS_STENCILREF, "D3DRS_STENCILREF"},
228 {SC_RENDERSTATE, D3DRS_STENCILMASK, "D3DRS_STENCILMASK"},
229 {SC_RENDERSTATE, D3DRS_STENCILWRITEMASK, "D3DRS_STENCILWRITEMASK"},
230 {SC_RENDERSTATE, D3DRS_TEXTUREFACTOR, "D3DRS_TEXTUREFACTOR"},
231 {SC_RENDERSTATE, D3DRS_WRAP0, "D3DRS_WRAP0"},
232 {SC_RENDERSTATE, D3DRS_WRAP1, "D3DRS_WRAP1"}, /* 0x20 */
233 {SC_RENDERSTATE, D3DRS_WRAP2, "D3DRS_WRAP2"},
234 {SC_RENDERSTATE, D3DRS_WRAP3, "D3DRS_WRAP3"},
235 {SC_RENDERSTATE, D3DRS_WRAP4, "D3DRS_WRAP4"},
236 {SC_RENDERSTATE, D3DRS_WRAP5, "D3DRS_WRAP5"},
237 {SC_RENDERSTATE, D3DRS_WRAP6, "D3DRS_WRAP6"},
238 {SC_RENDERSTATE, D3DRS_WRAP7, "D3DRS_WRAP7"},
239 {SC_RENDERSTATE, D3DRS_WRAP8, "D3DRS_WRAP8"},
240 {SC_RENDERSTATE, D3DRS_WRAP9, "D3DRS_WRAP9"},
241 {SC_RENDERSTATE, D3DRS_WRAP10, "D3DRS_WRAP10"},
242 {SC_RENDERSTATE, D3DRS_WRAP11, "D3DRS_WRAP11"},
243 {SC_RENDERSTATE, D3DRS_WRAP12, "D3DRS_WRAP12"},
244 {SC_RENDERSTATE, D3DRS_WRAP13, "D3DRS_WRAP13"},
245 {SC_RENDERSTATE, D3DRS_WRAP14, "D3DRS_WRAP14"},
246 {SC_RENDERSTATE, D3DRS_WRAP15, "D3DRS_WRAP15"},
247 {SC_RENDERSTATE, D3DRS_CLIPPING, "D3DRS_CLIPPING"},
248 {SC_RENDERSTATE, D3DRS_LIGHTING, "D3DRS_LIGHTING"}, /* 0x30 */
249 {SC_RENDERSTATE, D3DRS_AMBIENT, "D3DRS_AMBIENT"},
250 {SC_RENDERSTATE, D3DRS_FOGVERTEXMODE, "D3DRS_FOGVERTEXMODE"},
251 {SC_RENDERSTATE, D3DRS_COLORVERTEX, "D3DRS_COLORVERTEX"},
252 {SC_RENDERSTATE, D3DRS_LOCALVIEWER, "D3DRS_LOCALVIEWER"},
253 {SC_RENDERSTATE, D3DRS_NORMALIZENORMALS, "D3DRS_NORMALIZENORMALS"},
254 {SC_RENDERSTATE, D3DRS_DIFFUSEMATERIALSOURCE, "D3DRS_DIFFUSEMATERIALSOURCE"},
255 {SC_RENDERSTATE, D3DRS_SPECULARMATERIALSOURCE, "D3DRS_SPECULARMATERIALSOURCE"},
256 {SC_RENDERSTATE, D3DRS_AMBIENTMATERIALSOURCE, "D3DRS_AMBIENTMATERIALSOURCE"},
257 {SC_RENDERSTATE, D3DRS_EMISSIVEMATERIALSOURCE, "D3DRS_EMISSIVEMATERIALSOURCE"},
258 {SC_RENDERSTATE, D3DRS_VERTEXBLEND, "D3DRS_VERTEXBLEND"},
259 {SC_RENDERSTATE, D3DRS_CLIPPLANEENABLE, "D3DRS_CLIPPLANEENABLE"},
260 {SC_RENDERSTATE, D3DRS_POINTSIZE, "D3DRS_POINTSIZE"},
261 {SC_RENDERSTATE, D3DRS_POINTSIZE_MIN, "D3DRS_POINTSIZE_MIN"},
262 {SC_RENDERSTATE, D3DRS_POINTSIZE_MAX, "D3DRS_POINTSIZE_MAX"},
263 {SC_RENDERSTATE, D3DRS_POINTSPRITEENABLE, "D3DRS_POINTSPRITEENABLE"},
264 {SC_RENDERSTATE, D3DRS_POINTSCALEENABLE, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
265 {SC_RENDERSTATE, D3DRS_POINTSCALE_A, "D3DRS_POINTSCALE_A"},
266 {SC_RENDERSTATE, D3DRS_POINTSCALE_B, "D3DRS_POINTSCALE_B"},
267 {SC_RENDERSTATE, D3DRS_POINTSCALE_C, "D3DRS_POINTSCALE_C"},
268 {SC_RENDERSTATE, D3DRS_MULTISAMPLEANTIALIAS, "D3DRS_MULTISAMPLEANTIALIAS"},
269 {SC_RENDERSTATE, D3DRS_MULTISAMPLEMASK, "D3DRS_MULTISAMPLEMASK"},
270 {SC_RENDERSTATE, D3DRS_PATCHEDGESTYLE, "D3DRS_PATCHEDGESTYLE"},
271 {SC_RENDERSTATE, D3DRS_DEBUGMONITORTOKEN, "D3DRS_DEBUGMONITORTOKEN"},
272 {SC_RENDERSTATE, D3DRS_INDEXEDVERTEXBLENDENABLE, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
273 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE, "D3DRS_COLORWRITEENABLE"},
274 {SC_RENDERSTATE, D3DRS_TWEENFACTOR, "D3DRS_TWEENFACTOR"},
275 {SC_RENDERSTATE, D3DRS_BLENDOP, "D3DRS_BLENDOP"},
276 {SC_RENDERSTATE, D3DRS_POSITIONDEGREE, "D3DRS_POSITIONDEGREE"},
277 {SC_RENDERSTATE, D3DRS_NORMALDEGREE, "D3DRS_NORMALDEGREE"},
278 {SC_RENDERSTATE, D3DRS_SCISSORTESTENABLE, "D3DRS_SCISSORTESTENABLE"},
279 {SC_RENDERSTATE, D3DRS_SLOPESCALEDEPTHBIAS, "D3DRS_SLOPESCALEDEPTHBIAS"},
280 {SC_RENDERSTATE, D3DRS_ANTIALIASEDLINEENABLE, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
281 {SC_RENDERSTATE, D3DRS_MINTESSELLATIONLEVEL, "D3DRS_MINTESSELLATIONLEVEL"},
282 {SC_RENDERSTATE, D3DRS_MAXTESSELLATIONLEVEL, "D3DRS_MAXTESSELLATIONLEVEL"},
283 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_X, "D3DRS_ADAPTIVETESS_X"},
284 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Y, "D3DRS_ADAPTIVETESS_Y"},
285 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Z, "D3DRS_ADAPTIVETESS_Z"},
286 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_W, "D3DRS_ADAPTIVETESS_W"},
287 {SC_RENDERSTATE, D3DRS_ENABLEADAPTIVETESSELLATION, "D3DRS_ENABLEADAPTIVETESSELLATION"},
288 {SC_RENDERSTATE, D3DRS_TWOSIDEDSTENCILMODE, "D3DRS_TWOSIDEDSTENCILMODE"},
289 {SC_RENDERSTATE, D3DRS_CCW_STENCILFAIL, "D3DRS_CCW_STENCILFAIL"},
290 {SC_RENDERSTATE, D3DRS_CCW_STENCILZFAIL, "D3DRS_CCW_STENCILZFAIL"},
291 {SC_RENDERSTATE, D3DRS_CCW_STENCILPASS, "D3DRS_CCW_STENCILPASS"},
292 {SC_RENDERSTATE, D3DRS_CCW_STENCILFUNC, "D3DRS_CCW_STENCILFUNC"},
293 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE1, "D3DRS_COLORWRITEENABLE1"},
294 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE2, "D3DRS_COLORWRITEENABLE2"},
295 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE3, "D3DRS_COLORWRITEENABLE3"},
296 {SC_RENDERSTATE, D3DRS_BLENDFACTOR, "D3DRS_BLENDFACTOR"}, /* 0x60 */
297 {SC_RENDERSTATE, D3DRS_SRGBWRITEENABLE, "D3DRS_SRGBWRITEENABLE"},
298 {SC_RENDERSTATE, D3DRS_DEPTHBIAS, "D3DRS_DEPTHBIAS"},
299 {SC_RENDERSTATE, D3DRS_SEPARATEALPHABLENDENABLE, "D3DRS_SEPARATEALPHABLENDENABLE"},
300 {SC_RENDERSTATE, D3DRS_SRCBLENDALPHA, "D3DRS_SRCBLENDALPHA"},
301 {SC_RENDERSTATE, D3DRS_DESTBLENDALPHA, "D3DRS_DESTBLENDALPHA"},
302 {SC_RENDERSTATE, D3DRS_BLENDOPALPHA, "D3DRS_BLENDOPALPHA"},
303 /* Texture stages */
304 {SC_TEXTURESTAGE, D3DTSS_COLOROP, "D3DTSS_COLOROP"},
305 {SC_TEXTURESTAGE, D3DTSS_COLORARG0, "D3DTSS_COLORARG0"},
306 {SC_TEXTURESTAGE, D3DTSS_COLORARG1, "D3DTSS_COLORARG1"},
307 {SC_TEXTURESTAGE, D3DTSS_COLORARG2, "D3DTSS_COLORARG2"},
308 {SC_TEXTURESTAGE, D3DTSS_ALPHAOP, "D3DTSS_ALPHAOP"},
309 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG0, "D3DTSS_ALPHAARG0"},
310 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG1, "D3DTSS_ALPHAARG1"},
311 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG2, "D3DTSS_ALPHAARG2"},
312 {SC_TEXTURESTAGE, D3DTSS_RESULTARG, "D3DTSS_RESULTARG"},
313 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT00, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
314 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT01, "D3DTSS_BUMPENVMAT01"},
315 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT10, "D3DTSS_BUMPENVMAT10"},
316 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT11, "D3DTSS_BUMPENVMAT11"},
317 {SC_TEXTURESTAGE, D3DTSS_TEXCOORDINDEX, "D3DTSS_TEXCOORDINDEX"},
318 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLSCALE, "D3DTSS_BUMPENVLSCALE"},
319 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLOFFSET, "D3DTSS_BUMPENVLOFFSET"},
320 {SC_TEXTURESTAGE, D3DTSS_TEXTURETRANSFORMFLAGS, "D3DTSS_TEXTURETRANSFORMFLAGS"},
321 {SC_TEXTURESTAGE, D3DTSS_CONSTANT, "D3DTSS_CONSTANT"},
322 /* NPatchMode */
323 {SC_NPATCHMODE, 0, "NPatchMode"},
324 /* FVF */
325 {SC_FVF, 0, "FVF"},
326 /* Transform */
327 {SC_TRANSFORM, D3DTS_PROJECTION, "D3DTS_PROJECTION"},
328 {SC_TRANSFORM, D3DTS_VIEW, "D3DTS_VIEW"},
329 {SC_TRANSFORM, D3DTS_WORLD, "D3DTS_WORLD"},
330 {SC_TRANSFORM, D3DTS_TEXTURE0, "D3DTS_TEXTURE0"},
331 /* Material */
332 {SC_MATERIAL, MT_DIFFUSE, "MaterialDiffuse"},
333 {SC_MATERIAL, MT_AMBIENT, "MaterialAmbient"}, /* 0x80 */
334 {SC_MATERIAL, MT_SPECULAR, "MaterialSpecular"},
335 {SC_MATERIAL, MT_EMISSIVE, "MaterialEmissive"},
336 {SC_MATERIAL, MT_POWER, "MaterialPower"},
337 /* Light */
338 {SC_LIGHT, LT_TYPE, "LightType"},
339 {SC_LIGHT, LT_DIFFUSE, "LightDiffuse"},
340 {SC_LIGHT, LT_SPECULAR, "LightSpecular"},
341 {SC_LIGHT, LT_AMBIENT, "LightAmbient"},
342 {SC_LIGHT, LT_POSITION, "LightPosition"},
343 {SC_LIGHT, LT_DIRECTION, "LightDirection"},
344 {SC_LIGHT, LT_RANGE, "LightRange"},
345 {SC_LIGHT, LT_FALLOFF, "LightFallOff"},
346 {SC_LIGHT, LT_ATTENUATION0, "LightAttenuation0"},
347 {SC_LIGHT, LT_ATTENUATION1, "LightAttenuation1"},
348 {SC_LIGHT, LT_ATTENUATION2, "LightAttenuation2"},
349 {SC_LIGHT, LT_THETA, "LightTheta"},
350 {SC_LIGHT, LT_PHI, "LightPhi"}, /* 0x90 */
351 /* Ligthenable */
352 {SC_LIGHTENABLE, 0, "LightEnable"},
353 /* Vertexshader */
354 {SC_VERTEXSHADER, 0, "Vertexshader"},
355 /* Pixelshader */
356 {SC_PIXELSHADER, 0, "Pixelshader"},
357 /* Shader constants */
358 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstantF"},
359 {SC_SHADERCONST, SCT_VSBOOL, "VertexShaderConstantB"},
360 {SC_SHADERCONST, SCT_VSINT, "VertexShaderConstantI"},
361 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant"},
362 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant1"},
363 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant2"},
364 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant3"},
365 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant4"},
366 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstantF"},
367 {SC_SHADERCONST, SCT_PSBOOL, "PixelShaderConstantB"},
368 {SC_SHADERCONST, SCT_PSINT, "PixelShaderConstantI"},
369 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant"},
370 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant1"}, /* 0xa0 */
371 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant2"},
372 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant3"},
373 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant4"},
374 /* Texture */
375 {SC_TEXTURE, 0, "Texture"},
376 /* Sampler states */
377 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSU, "AddressU"},
378 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSV, "AddressV"},
379 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSW, "AddressW"},
380 {SC_SAMPLERSTATE, D3DSAMP_BORDERCOLOR, "BorderColor"},
381 {SC_SAMPLERSTATE, D3DSAMP_MAGFILTER, "MagFilter"},
382 {SC_SAMPLERSTATE, D3DSAMP_MINFILTER, "MinFilter"},
383 {SC_SAMPLERSTATE, D3DSAMP_MIPFILTER, "MipFilter"},
384 {SC_SAMPLERSTATE, D3DSAMP_MIPMAPLODBIAS, "MipMapLodBias"},
385 {SC_SAMPLERSTATE, D3DSAMP_MAXMIPLEVEL, "MaxMipLevel"},
386 {SC_SAMPLERSTATE, D3DSAMP_MAXANISOTROPY, "MaxAnisotropy"},
387 {SC_SAMPLERSTATE, D3DSAMP_SRGBTEXTURE, "SRGBTexture"},
388 {SC_SAMPLERSTATE, D3DSAMP_ELEMENTINDEX, "ElementIndex"}, /* 0xb0 */
389 {SC_SAMPLERSTATE, D3DSAMP_DMAPOFFSET, "DMAPOffset"},
390 /* Set sampler */
391 {SC_SETSAMPLER, 0, "Sampler"},
394 static inline void read_dword(const char **ptr, DWORD *d)
396 memcpy(d, *ptr, sizeof(*d));
397 *ptr += sizeof(*d);
400 static void skip_dword_unknown(const char **ptr, unsigned int count)
402 unsigned int i;
403 DWORD d;
405 FIXME("Skipping %u unknown DWORDs:\n", count);
406 for (i = 0; i < count; ++i)
408 read_dword(ptr, &d);
409 FIXME("\t0x%08x\n", d);
413 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
415 return parameter ? parameter->handle : NULL;
418 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
420 return (D3DXHANDLE) technique;
423 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
425 return (D3DXHANDLE) pass;
428 static struct d3dx_technique *get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
430 UINT i;
432 if (!name) return NULL;
434 for (i = 0; i < base->technique_count; ++i)
436 if (!strcmp(base->techniques[i].name, name))
437 return &base->techniques[i];
440 return NULL;
443 static struct d3dx_technique *get_valid_technique(struct d3dx9_base_effect *base, D3DXHANDLE technique)
445 unsigned int i;
447 for (i = 0; i < base->technique_count; ++i)
449 if (get_technique_handle(&base->techniques[i]) == technique)
450 return &base->techniques[i];
453 return get_technique_by_name(base, technique);
456 static struct d3dx_pass *get_valid_pass(struct d3dx9_base_effect *base, D3DXHANDLE pass)
458 unsigned int i, k;
460 for (i = 0; i < base->technique_count; ++i)
462 struct d3dx_technique *technique = &base->techniques[i];
464 for (k = 0; k < technique->pass_count; ++k)
466 if (get_pass_handle(&technique->passes[k]) == pass)
467 return &technique->passes[k];
471 return NULL;
474 static struct d3dx_parameter *get_valid_parameter(struct d3dx9_base_effect *base, D3DXHANDLE parameter)
476 struct d3dx_parameter **handle_param = (struct d3dx_parameter **)parameter;
478 if (handle_param >= base->param_table.table && handle_param < base->param_table.table + base->param_table.count)
479 return *handle_param;
481 return get_parameter_by_name(base, NULL, parameter);
484 static void free_state(struct d3dx_state *state)
486 free_parameter(&state->parameter, FALSE, FALSE);
489 static void free_object(struct d3dx_object *object)
491 HeapFree(GetProcessHeap(), 0, object->data);
494 static void free_sampler(struct d3dx_sampler *sampler)
496 UINT i;
498 for (i = 0; i < sampler->state_count; ++i)
500 free_state(&sampler->states[i]);
502 HeapFree(GetProcessHeap(), 0, sampler->states);
505 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child)
507 unsigned int i;
509 TRACE("Free parameter %p, name %s, type %s, child %s\n", param, param->name,
510 debug_d3dxparameter_type(param->type), child ? "yes" : "no");
512 if (param->param_eval)
514 d3dx_free_param_eval(param->param_eval);
515 param->param_eval = NULL;
518 if (param->annotations)
520 for (i = 0; i < param->annotation_count; ++i)
521 free_parameter(&param->annotations[i], FALSE, FALSE);
522 HeapFree(GetProcessHeap(), 0, param->annotations);
523 param->annotations = NULL;
526 if (param->members)
528 unsigned int count = param->element_count ? param->element_count : param->member_count;
530 for (i = 0; i < count; ++i)
531 free_parameter(&param->members[i], param->element_count != 0, TRUE);
532 HeapFree(GetProcessHeap(), 0, param->members);
533 param->members = NULL;
536 if (param->class == D3DXPC_OBJECT && !param->element_count)
538 switch (param->type)
540 case D3DXPT_STRING:
541 HeapFree(GetProcessHeap(), 0, *(char **)param->data);
542 break;
544 case D3DXPT_TEXTURE:
545 case D3DXPT_TEXTURE1D:
546 case D3DXPT_TEXTURE2D:
547 case D3DXPT_TEXTURE3D:
548 case D3DXPT_TEXTURECUBE:
549 case D3DXPT_PIXELSHADER:
550 case D3DXPT_VERTEXSHADER:
551 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
552 break;
554 case D3DXPT_SAMPLER:
555 case D3DXPT_SAMPLER1D:
556 case D3DXPT_SAMPLER2D:
557 case D3DXPT_SAMPLER3D:
558 case D3DXPT_SAMPLERCUBE:
559 free_sampler((struct d3dx_sampler *)param->data);
560 break;
562 default:
563 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
564 break;
568 if (!child)
570 HeapFree(GetProcessHeap(), 0, param->data);
573 /* only the parent has to release name and semantic */
574 if (!element)
576 HeapFree(GetProcessHeap(), 0, param->name);
577 HeapFree(GetProcessHeap(), 0, param->semantic);
581 static void free_pass(struct d3dx_pass *pass)
583 unsigned int i;
585 TRACE("Free pass %p\n", pass);
587 if (!pass)
588 return;
590 if (pass->annotations)
592 for (i = 0; i < pass->annotation_count; ++i)
593 free_parameter(&pass->annotations[i], FALSE, FALSE);
594 HeapFree(GetProcessHeap(), 0, pass->annotations);
595 pass->annotations = NULL;
598 if (pass->states)
600 for (i = 0; i < pass->state_count; ++i)
601 free_state(&pass->states[i]);
602 HeapFree(GetProcessHeap(), 0, pass->states);
603 pass->states = NULL;
606 HeapFree(GetProcessHeap(), 0, pass->name);
607 pass->name = NULL;
610 static void free_technique(struct d3dx_technique *technique)
612 unsigned int i;
614 TRACE("Free technique %p\n", technique);
616 if (!technique)
617 return;
619 if (technique->saved_state)
621 IDirect3DStateBlock9_Release(technique->saved_state);
622 technique->saved_state = NULL;
625 if (technique->annotations)
627 for (i = 0; i < technique->annotation_count; ++i)
628 free_parameter(&technique->annotations[i], FALSE, FALSE);
629 HeapFree(GetProcessHeap(), 0, technique->annotations);
630 technique->annotations = NULL;
633 if (technique->passes)
635 for (i = 0; i < technique->pass_count; ++i)
636 free_pass(&technique->passes[i]);
637 HeapFree(GetProcessHeap(), 0, technique->passes);
638 technique->passes = NULL;
641 HeapFree(GetProcessHeap(), 0, technique->name);
642 technique->name = NULL;
645 static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
647 unsigned int i;
649 TRACE("base %p.\n", base);
651 HeapFree(GetProcessHeap(), 0, base->param_table.table);
653 if (base->parameters)
655 for (i = 0; i < base->parameter_count; ++i)
656 free_parameter(&base->parameters[i], FALSE, FALSE);
657 HeapFree(GetProcessHeap(), 0, base->parameters);
658 base->parameters = NULL;
661 if (base->techniques)
663 for (i = 0; i < base->technique_count; ++i)
664 free_technique(&base->techniques[i]);
665 HeapFree(GetProcessHeap(), 0, base->techniques);
666 base->techniques = NULL;
669 if (base->objects)
671 for (i = 0; i < base->object_count; ++i)
673 free_object(&base->objects[i]);
675 HeapFree(GetProcessHeap(), 0, base->objects);
676 base->objects = NULL;
680 static void free_effect(struct ID3DXEffectImpl *effect)
682 TRACE("Free effect %p\n", effect);
684 d3dx9_base_effect_cleanup(&effect->base_effect);
686 if (effect->pool)
688 effect->pool->lpVtbl->Release(effect->pool);
691 if (effect->manager)
693 IUnknown_Release(effect->manager);
696 IDirect3DDevice9_Release(effect->device);
699 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
701 TRACE("Free effect compiler %p\n", compiler);
703 d3dx9_base_effect_cleanup(&compiler->base_effect);
706 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
708 UINT i;
710 for (i = 0; i < 4; ++i)
712 if (i < param->columns)
713 set_number((FLOAT *)vector + i, D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
714 else
715 ((FLOAT *)vector)[i] = 0.0f;
719 static void set_vector(struct d3dx_parameter *param, const D3DXVECTOR4 *vector)
721 UINT i;
723 for (i = 0; i < param->columns; ++i)
725 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
729 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix, BOOL transpose)
731 UINT i, k;
733 for (i = 0; i < 4; ++i)
735 for (k = 0; k < 4; ++k)
737 FLOAT *tmp = transpose ? (FLOAT *)&matrix->u.m[k][i] : (FLOAT *)&matrix->u.m[i][k];
739 if ((i < param->rows) && (k < param->columns))
740 set_number(tmp, D3DXPT_FLOAT, (DWORD *)param->data + i * param->columns + k, param->type);
741 else
742 *tmp = 0.0f;
747 static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
749 UINT i, k;
751 if (param->type == D3DXPT_FLOAT)
753 if (param->columns == 4)
754 memcpy(param->data, matrix->u.m, param->rows * 4 * sizeof(float));
755 else
756 for (i = 0; i < param->rows; ++i)
757 memcpy((float *)param->data + i * param->columns, matrix->u.m + i, param->columns * sizeof(float));
758 return;
761 for (i = 0; i < param->rows; ++i)
763 for (k = 0; k < param->columns; ++k)
765 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
766 &matrix->u.m[i][k], D3DXPT_FLOAT);
771 static void set_matrix_transpose(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
773 UINT i, k;
775 for (i = 0; i < param->rows; ++i)
777 for (k = 0; k < param->columns; ++k)
779 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
780 &matrix->u.m[k][i], D3DXPT_FLOAT);
785 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, const char *name)
787 UINT element;
788 struct d3dx_parameter *temp_parameter;
789 const char *part;
791 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
793 if (!name || !*name) return NULL;
795 element = atoi(name);
796 part = strchr(name, ']') + 1;
798 /* check for empty [] && element range */
799 if ((part - name) > 1 && parameter->element_count > element)
801 temp_parameter = &parameter->members[element];
803 switch (*part++)
805 case '.':
806 return get_parameter_by_name(NULL, temp_parameter, part);
808 case '@':
809 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
811 case '\0':
812 TRACE("Returning parameter %p\n", temp_parameter);
813 return temp_parameter;
815 default:
816 FIXME("Unhandled case \"%c\"\n", *--part);
817 break;
821 TRACE("Parameter not found\n");
822 return NULL;
825 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *annotations,
826 const char *name)
828 UINT i, length;
829 struct d3dx_parameter *temp_parameter;
830 const char *part;
832 TRACE("count %u, annotations %p, name %s\n", count, annotations, debugstr_a(name));
834 if (!name || !*name) return NULL;
836 length = strcspn( name, "[.@" );
837 part = name + length;
839 for (i = 0; i < count; ++i)
841 temp_parameter = &annotations[i];
843 if (!strcmp(temp_parameter->name, name))
845 TRACE("Returning annotation %p\n", temp_parameter);
846 return temp_parameter;
848 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
850 switch (*part++)
852 case '.':
853 return get_parameter_by_name(NULL, temp_parameter, part);
855 case '[':
856 return get_parameter_element_by_name(temp_parameter, part);
858 default:
859 FIXME("Unhandled case \"%c\"\n", *--part);
860 break;
865 TRACE("Annotation not found\n");
866 return NULL;
869 struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
870 struct d3dx_parameter *parameter, const char *name)
872 UINT i, count, length;
873 struct d3dx_parameter *temp_parameter;
874 struct d3dx_parameter *parameters;
875 const char *part;
877 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
879 if (!name || !*name) return NULL;
881 if (!parameter)
883 count = base->parameter_count;
884 parameters = base->parameters;
886 else
888 count = parameter->member_count;
889 parameters = parameter->members;
892 length = strcspn( name, "[.@" );
893 part = name + length;
895 for (i = 0; i < count; i++)
897 temp_parameter = &parameters[i];
899 if (!strcmp(temp_parameter->name, name))
901 TRACE("Returning parameter %p\n", temp_parameter);
902 return temp_parameter;
904 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
906 switch (*part++)
908 case '.':
909 return get_parameter_by_name(NULL, temp_parameter, part);
911 case '@':
912 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
914 case '[':
915 return get_parameter_element_by_name(temp_parameter, part);
917 default:
918 FIXME("Unhandled case \"%c\"\n", *--part);
919 break;
924 TRACE("Parameter not found\n");
925 return NULL;
928 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
930 return (0xfeff0000 | ((major) << 8) | (minor));
933 static HRESULT d3dx9_base_effect_get_desc(struct d3dx9_base_effect *base, D3DXEFFECT_DESC *desc)
935 if (!desc)
937 WARN("Invalid argument specified.\n");
938 return D3DERR_INVALIDCALL;
941 FIXME("partial stub!\n");
943 /* TODO: add creator and function count. */
944 desc->Creator = NULL;
945 desc->Functions = 0;
946 desc->Parameters = base->parameter_count;
947 desc->Techniques = base->technique_count;
949 return D3D_OK;
952 static HRESULT d3dx9_base_effect_get_parameter_desc(struct d3dx9_base_effect *base,
953 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
955 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
957 if (!desc || !param)
959 WARN("Invalid argument specified.\n");
960 return D3DERR_INVALIDCALL;
963 desc->Name = param->name;
964 desc->Semantic = param->semantic;
965 desc->Class = param->class;
966 desc->Type = param->type;
967 desc->Rows = param->rows;
968 desc->Columns = param->columns;
969 desc->Elements = param->element_count;
970 desc->Annotations = param->annotation_count;
971 desc->StructMembers = param->member_count;
972 desc->Flags = param->flags;
973 desc->Bytes = param->bytes;
975 return D3D_OK;
978 static HRESULT d3dx9_base_effect_get_technique_desc(struct d3dx9_base_effect *base,
979 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
981 struct d3dx_technique *tech = technique ? get_valid_technique(base, technique) : &base->techniques[0];
983 if (!desc || !tech)
985 WARN("Invalid argument specified.\n");
986 return D3DERR_INVALIDCALL;
989 desc->Name = tech->name;
990 desc->Passes = tech->pass_count;
991 desc->Annotations = tech->annotation_count;
993 return D3D_OK;
996 static HRESULT d3dx9_base_effect_get_pass_desc(struct d3dx9_base_effect *base,
997 D3DXHANDLE pass, D3DXPASS_DESC *desc)
999 struct d3dx_pass *p = get_valid_pass(base, pass);
1001 if (!desc || !p)
1003 WARN("Invalid argument specified.\n");
1004 return D3DERR_INVALIDCALL;
1007 desc->Name = p->name;
1008 desc->Annotations = p->annotation_count;
1010 FIXME("Pixel shader and vertex shader are not supported, yet.\n");
1011 desc->pVertexShaderFunction = NULL;
1012 desc->pPixelShaderFunction = NULL;
1014 return D3D_OK;
1017 static HRESULT d3dx9_base_effect_get_function_desc(struct d3dx9_base_effect *base,
1018 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1020 FIXME("stub!\n");
1022 return E_NOTIMPL;
1025 static D3DXHANDLE d3dx9_base_effect_get_parameter(struct d3dx9_base_effect *base,
1026 D3DXHANDLE parameter, UINT index)
1028 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1030 if (!parameter)
1032 if (index < base->parameter_count)
1034 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1035 return get_parameter_handle(&base->parameters[index]);
1038 else
1040 if (param && !param->element_count && index < param->member_count)
1042 TRACE("Returning parameter %p.\n", &param->members[index]);
1043 return get_parameter_handle(&param->members[index]);
1047 WARN("Parameter not found.\n");
1049 return NULL;
1052 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_name(struct d3dx9_base_effect *base,
1053 D3DXHANDLE parameter, const char *name)
1055 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1056 D3DXHANDLE handle;
1058 if (!name)
1060 handle = get_parameter_handle(param);
1061 TRACE("Returning parameter %p.\n", handle);
1062 return handle;
1065 handle = get_parameter_handle(get_parameter_by_name(base, param, name));
1066 TRACE("Returning parameter %p.\n", handle);
1068 return handle;
1071 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_semantic(struct d3dx9_base_effect *base,
1072 D3DXHANDLE parameter, const char *semantic)
1074 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1075 struct d3dx_parameter *temp_param;
1076 UINT i;
1078 if (!parameter)
1080 for (i = 0; i < base->parameter_count; ++i)
1082 temp_param = &base->parameters[i];
1084 if (!temp_param->semantic)
1086 if (!semantic)
1088 TRACE("Returning parameter %p\n", temp_param);
1089 return get_parameter_handle(temp_param);
1091 continue;
1094 if (!strcasecmp(temp_param->semantic, semantic))
1096 TRACE("Returning parameter %p\n", temp_param);
1097 return get_parameter_handle(temp_param);
1101 else if (param)
1103 for (i = 0; i < param->member_count; ++i)
1105 temp_param = &param->members[i];
1107 if (!temp_param->semantic)
1109 if (!semantic)
1111 TRACE("Returning parameter %p\n", temp_param);
1112 return get_parameter_handle(temp_param);
1114 continue;
1117 if (!strcasecmp(temp_param->semantic, semantic))
1119 TRACE("Returning parameter %p\n", temp_param);
1120 return get_parameter_handle(temp_param);
1125 WARN("Parameter not found.\n");
1127 return NULL;
1130 static D3DXHANDLE d3dx9_base_effect_get_parameter_element(struct d3dx9_base_effect *base,
1131 D3DXHANDLE parameter, UINT index)
1133 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1135 if (!param)
1137 if (index < base->parameter_count)
1139 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1140 return get_parameter_handle(&base->parameters[index]);
1143 else
1145 if (index < param->element_count)
1147 TRACE("Returning parameter %p.\n", &param->members[index]);
1148 return get_parameter_handle(&param->members[index]);
1152 WARN("Parameter not found.\n");
1154 return NULL;
1157 static D3DXHANDLE d3dx9_base_effect_get_technique(struct d3dx9_base_effect *base, UINT index)
1159 if (index >= base->technique_count)
1161 WARN("Invalid argument specified.\n");
1162 return NULL;
1165 TRACE("Returning technique %p.\n", &base->techniques[index]);
1167 return get_technique_handle(&base->techniques[index]);
1170 static D3DXHANDLE d3dx9_base_effect_get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
1172 struct d3dx_technique *tech = get_technique_by_name(base, name);
1174 if (tech)
1176 D3DXHANDLE t = get_technique_handle(tech);
1177 TRACE("Returning technique %p\n", t);
1178 return t;
1181 WARN("Technique not found.\n");
1183 return NULL;
1186 static D3DXHANDLE d3dx9_base_effect_get_pass(struct d3dx9_base_effect *base,
1187 D3DXHANDLE technique, UINT index)
1189 struct d3dx_technique *tech = get_valid_technique(base, technique);
1191 if (tech && index < tech->pass_count)
1193 TRACE("Returning pass %p\n", &tech->passes[index]);
1194 return get_pass_handle(&tech->passes[index]);
1197 WARN("Pass not found.\n");
1199 return NULL;
1202 static D3DXHANDLE d3dx9_base_effect_get_pass_by_name(struct d3dx9_base_effect *base,
1203 D3DXHANDLE technique, const char *name)
1205 struct d3dx_technique *tech = get_valid_technique(base, technique);
1207 if (tech && name)
1209 unsigned int i;
1211 for (i = 0; i < tech->pass_count; ++i)
1213 struct d3dx_pass *pass = &tech->passes[i];
1215 if (!strcmp(pass->name, name))
1217 TRACE("Returning pass %p\n", pass);
1218 return get_pass_handle(pass);
1223 WARN("Pass not found.\n");
1225 return NULL;
1228 static D3DXHANDLE d3dx9_base_effect_get_function(struct d3dx9_base_effect *base, UINT index)
1230 FIXME("stub!\n");
1232 return NULL;
1235 static D3DXHANDLE d3dx9_base_effect_get_function_by_name(struct d3dx9_base_effect *base, const char *name)
1237 FIXME("stub!\n");
1239 return NULL;
1242 static UINT get_annotation_from_object(struct d3dx9_base_effect *base,
1243 D3DXHANDLE object, struct d3dx_parameter **annotations)
1245 struct d3dx_parameter *param = get_valid_parameter(base, object);
1246 struct d3dx_pass *pass = get_valid_pass(base, object);
1247 struct d3dx_technique *technique = get_valid_technique(base, object);
1249 if (pass)
1251 *annotations = pass->annotations;
1252 return pass->annotation_count;
1254 else if (technique)
1256 *annotations = technique->annotations;
1257 return technique->annotation_count;
1259 else if (param)
1261 *annotations = param->annotations;
1262 return param->annotation_count;
1264 else
1266 FIXME("Functions are not handled, yet!\n");
1267 return 0;
1271 static D3DXHANDLE d3dx9_base_effect_get_annotation(struct d3dx9_base_effect *base,
1272 D3DXHANDLE object, UINT index)
1274 struct d3dx_parameter *annotations = NULL;
1275 UINT annotation_count = 0;
1277 annotation_count = get_annotation_from_object(base, object, &annotations);
1279 if (index < annotation_count)
1281 TRACE("Returning parameter %p\n", &annotations[index]);
1282 return get_parameter_handle(&annotations[index]);
1285 WARN("Annotation not found.\n");
1287 return NULL;
1290 static D3DXHANDLE d3dx9_base_effect_get_annotation_by_name(struct d3dx9_base_effect *base,
1291 D3DXHANDLE object, const char *name)
1293 struct d3dx_parameter *annotation = NULL;
1294 struct d3dx_parameter *annotations = NULL;
1295 UINT annotation_count = 0;
1297 if (!name)
1299 WARN("Invalid argument specified\n");
1300 return NULL;
1303 annotation_count = get_annotation_from_object(base, object, &annotations);
1305 annotation = get_annotation_by_name(annotation_count, annotations, name);
1306 if (annotation)
1308 TRACE("Returning parameter %p\n", annotation);
1309 return get_parameter_handle(annotation);
1312 WARN("Annotation not found.\n");
1314 return NULL;
1317 static HRESULT d3dx9_base_effect_set_value(struct d3dx9_base_effect *base,
1318 D3DXHANDLE parameter, const void *data, UINT bytes)
1320 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1322 if (!param)
1324 WARN("Invalid parameter %p specified\n", parameter);
1325 return D3DERR_INVALIDCALL;
1328 /* samplers don't touch data */
1329 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1330 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1331 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1333 TRACE("Sampler: returning E_FAIL\n");
1334 return E_FAIL;
1337 if (data && param->bytes <= bytes)
1339 switch (param->type)
1341 case D3DXPT_TEXTURE:
1342 case D3DXPT_TEXTURE1D:
1343 case D3DXPT_TEXTURE2D:
1344 case D3DXPT_TEXTURE3D:
1345 case D3DXPT_TEXTURECUBE:
1347 unsigned int i;
1349 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1351 IUnknown *unk = ((IUnknown **)data)[i];
1352 if (unk)
1353 IUnknown_AddRef(unk);
1355 unk = ((IUnknown **)param->data)[i];
1356 if (unk)
1357 IUnknown_Release(unk);
1360 /* fallthrough */
1361 case D3DXPT_VOID:
1362 case D3DXPT_BOOL:
1363 case D3DXPT_INT:
1364 case D3DXPT_FLOAT:
1365 TRACE("Copy %u bytes\n", param->bytes);
1366 memcpy(param->data, data, param->bytes);
1367 break;
1369 default:
1370 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1371 break;
1374 return D3D_OK;
1377 WARN("Invalid argument specified\n");
1379 return D3DERR_INVALIDCALL;
1382 static HRESULT d3dx9_base_effect_get_value(struct d3dx9_base_effect *base,
1383 D3DXHANDLE parameter, void *data, UINT bytes)
1385 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1387 if (!param)
1389 WARN("Invalid parameter %p specified\n", parameter);
1390 return D3DERR_INVALIDCALL;
1393 /* samplers don't touch data */
1394 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1395 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1396 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1398 TRACE("Sampler: returning E_FAIL\n");
1399 return E_FAIL;
1402 if (data && param->bytes <= bytes)
1404 TRACE("Type %s\n", debug_d3dxparameter_type(param->type));
1406 switch (param->type)
1408 case D3DXPT_VOID:
1409 case D3DXPT_BOOL:
1410 case D3DXPT_INT:
1411 case D3DXPT_FLOAT:
1412 case D3DXPT_STRING:
1413 break;
1415 case D3DXPT_VERTEXSHADER:
1416 case D3DXPT_PIXELSHADER:
1417 case D3DXPT_TEXTURE:
1418 case D3DXPT_TEXTURE1D:
1419 case D3DXPT_TEXTURE2D:
1420 case D3DXPT_TEXTURE3D:
1421 case D3DXPT_TEXTURECUBE:
1423 UINT i;
1425 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1427 IUnknown *unk = ((IUnknown **)param->data)[i];
1428 if (unk) IUnknown_AddRef(unk);
1430 break;
1433 default:
1434 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1435 break;
1438 TRACE("Copy %u bytes\n", param->bytes);
1439 memcpy(data, param->data, param->bytes);
1440 return D3D_OK;
1443 WARN("Parameter not found.\n");
1445 return D3DERR_INVALIDCALL;
1448 static HRESULT d3dx9_base_effect_set_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL b)
1450 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1452 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1454 set_number(param->data, param->type, &b, D3DXPT_BOOL);
1455 return D3D_OK;
1458 WARN("Parameter not found.\n");
1460 return D3DERR_INVALIDCALL;
1463 static HRESULT d3dx9_base_effect_get_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL *b)
1465 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1467 if (b && param && !param->element_count && param->rows == 1 && param->columns == 1)
1469 set_number(b, D3DXPT_BOOL, param->data, param->type);
1470 TRACE("Returning %s\n", *b ? "TRUE" : "FALSE");
1471 return D3D_OK;
1474 WARN("Parameter not found.\n");
1476 return D3DERR_INVALIDCALL;
1479 static HRESULT d3dx9_base_effect_set_bool_array(struct d3dx9_base_effect *base,
1480 D3DXHANDLE parameter, const BOOL *b, UINT count)
1482 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1484 if (param)
1486 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1488 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1490 switch (param->class)
1492 case D3DXPC_SCALAR:
1493 case D3DXPC_VECTOR:
1494 case D3DXPC_MATRIX_ROWS:
1495 for (i = 0; i < size; ++i)
1497 /* don't crop the input, use D3DXPT_INT instead of D3DXPT_BOOL */
1498 set_number((DWORD *)param->data + i, param->type, &b[i], D3DXPT_INT);
1500 return D3D_OK;
1502 case D3DXPC_OBJECT:
1503 case D3DXPC_STRUCT:
1504 break;
1506 default:
1507 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1508 break;
1512 WARN("Parameter not found.\n");
1514 return D3DERR_INVALIDCALL;
1517 static HRESULT d3dx9_base_effect_get_bool_array(struct d3dx9_base_effect *base,
1518 D3DXHANDLE parameter, BOOL *b, UINT count)
1520 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1522 if (b && param && (param->class == D3DXPC_SCALAR
1523 || param->class == D3DXPC_VECTOR
1524 || param->class == D3DXPC_MATRIX_ROWS
1525 || param->class == D3DXPC_MATRIX_COLUMNS))
1527 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1529 for (i = 0; i < size; ++i)
1531 set_number(&b[i], D3DXPT_BOOL, (DWORD *)param->data + i, param->type);
1533 return D3D_OK;
1536 WARN("Parameter not found.\n");
1538 return D3DERR_INVALIDCALL;
1541 static HRESULT d3dx9_base_effect_set_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT n)
1543 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1545 if (param && !param->element_count)
1547 if (param->rows == 1 && param->columns == 1)
1549 set_number(param->data, param->type, &n, D3DXPT_INT);
1550 return D3D_OK;
1554 * Split the value, if parameter is a vector with dimension 3 or 4.
1556 if (param->type == D3DXPT_FLOAT &&
1557 ((param->class == D3DXPC_VECTOR && param->columns != 2) ||
1558 (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1560 TRACE("Vector fixup\n");
1562 *(FLOAT *)param->data = ((n & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1563 ((FLOAT *)param->data)[1] = ((n & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1564 ((FLOAT *)param->data)[2] = (n & 0xff) * INT_FLOAT_MULTI_INVERSE;
1565 if (param->rows * param->columns > 3)
1567 ((FLOAT *)param->data)[3] = ((n & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1569 return D3D_OK;
1573 WARN("Parameter not found.\n");
1575 return D3DERR_INVALIDCALL;
1578 static HRESULT d3dx9_base_effect_get_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT *n)
1580 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1582 if (n && param && !param->element_count)
1584 if (param->columns == 1 && param->rows == 1)
1586 set_number(n, D3DXPT_INT, param->data, param->type);
1587 TRACE("Returning %i\n", *n);
1588 return D3D_OK;
1591 if (param->type == D3DXPT_FLOAT &&
1592 ((param->class == D3DXPC_VECTOR && param->columns != 2)
1593 || (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1595 TRACE("Vector fixup\n");
1597 /* all components (3,4) are clamped (0,255) and put in the INT */
1598 *n = (INT)(min(max(0.0f, *((FLOAT *)param->data + 2)), 1.0f) * INT_FLOAT_MULTI);
1599 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 1)), 1.0f) * INT_FLOAT_MULTI)) << 8;
1600 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 0)), 1.0f) * INT_FLOAT_MULTI)) << 16;
1601 if (param->columns * param->rows > 3)
1603 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 3)), 1.0f) * INT_FLOAT_MULTI)) << 24;
1606 TRACE("Returning %i\n", *n);
1607 return D3D_OK;
1611 WARN("Parameter not found.\n");
1613 return D3DERR_INVALIDCALL;
1616 static HRESULT d3dx9_base_effect_set_int_array(struct d3dx9_base_effect *base,
1617 D3DXHANDLE parameter, const INT *n, UINT count)
1619 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1621 if (param)
1623 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1625 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1627 switch (param->class)
1629 case D3DXPC_SCALAR:
1630 case D3DXPC_VECTOR:
1631 case D3DXPC_MATRIX_ROWS:
1632 for (i = 0; i < size; ++i)
1634 set_number((DWORD *)param->data + i, param->type, &n[i], D3DXPT_INT);
1636 return D3D_OK;
1638 case D3DXPC_OBJECT:
1639 case D3DXPC_STRUCT:
1640 break;
1642 default:
1643 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1644 break;
1648 WARN("Parameter not found.\n");
1650 return D3DERR_INVALIDCALL;
1653 static HRESULT d3dx9_base_effect_get_int_array(struct d3dx9_base_effect *base,
1654 D3DXHANDLE parameter, INT *n, UINT count)
1656 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1658 if (n && param && (param->class == D3DXPC_SCALAR
1659 || param->class == D3DXPC_VECTOR
1660 || param->class == D3DXPC_MATRIX_ROWS
1661 || param->class == D3DXPC_MATRIX_COLUMNS))
1663 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1665 for (i = 0; i < size; ++i)
1667 set_number(&n[i], D3DXPT_INT, (DWORD *)param->data + i, param->type);
1669 return D3D_OK;
1672 WARN("Parameter not found.\n");
1674 return D3DERR_INVALIDCALL;
1677 static HRESULT d3dx9_base_effect_set_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float f)
1679 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1681 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1683 set_number((DWORD *)param->data, param->type, &f, D3DXPT_FLOAT);
1684 return D3D_OK;
1687 WARN("Parameter not found.\n");
1689 return D3DERR_INVALIDCALL;
1692 static HRESULT d3dx9_base_effect_get_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float *f)
1694 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1696 if (f && param && !param->element_count && param->columns == 1 && param->rows == 1)
1698 set_number(f, D3DXPT_FLOAT, (DWORD *)param->data, param->type);
1699 TRACE("Returning %f\n", *f);
1700 return D3D_OK;
1703 WARN("Parameter not found.\n");
1705 return D3DERR_INVALIDCALL;
1708 static HRESULT d3dx9_base_effect_set_float_array(struct d3dx9_base_effect *base,
1709 D3DXHANDLE parameter, const float *f, UINT count)
1711 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1713 if (param)
1715 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1717 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1719 switch (param->class)
1721 case D3DXPC_SCALAR:
1722 case D3DXPC_VECTOR:
1723 case D3DXPC_MATRIX_ROWS:
1724 for (i = 0; i < size; ++i)
1726 set_number((DWORD *)param->data + i, param->type, &f[i], D3DXPT_FLOAT);
1728 return D3D_OK;
1730 case D3DXPC_OBJECT:
1731 case D3DXPC_STRUCT:
1732 break;
1734 default:
1735 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1736 break;
1740 WARN("Parameter not found.\n");
1742 return D3DERR_INVALIDCALL;
1745 static HRESULT d3dx9_base_effect_get_float_array(struct d3dx9_base_effect *base,
1746 D3DXHANDLE parameter, float *f, UINT count)
1748 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1750 if (f && param && (param->class == D3DXPC_SCALAR
1751 || param->class == D3DXPC_VECTOR
1752 || param->class == D3DXPC_MATRIX_ROWS
1753 || param->class == D3DXPC_MATRIX_COLUMNS))
1755 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1757 for (i = 0; i < size; ++i)
1759 set_number(&f[i], D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
1761 return D3D_OK;
1764 WARN("Parameter not found.\n");
1766 return D3DERR_INVALIDCALL;
1769 static HRESULT d3dx9_base_effect_set_vector(struct d3dx9_base_effect *base,
1770 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
1772 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1774 if (param && !param->element_count)
1776 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1778 switch (param->class)
1780 case D3DXPC_SCALAR:
1781 case D3DXPC_VECTOR:
1782 if (param->type == D3DXPT_INT && param->bytes == 4)
1784 DWORD tmp;
1786 TRACE("INT fixup\n");
1787 tmp = (DWORD)(max(min(vector->z, 1.0f), 0.0f) * INT_FLOAT_MULTI);
1788 tmp += ((DWORD)(max(min(vector->y, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 8;
1789 tmp += ((DWORD)(max(min(vector->x, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 16;
1790 tmp += ((DWORD)(max(min(vector->w, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 24;
1792 *(INT *)param->data = tmp;
1793 return D3D_OK;
1795 if (param->type == D3DXPT_FLOAT)
1797 memcpy(param->data, vector, param->columns * sizeof(float));
1798 return D3D_OK;
1801 set_vector(param, vector);
1802 return D3D_OK;
1804 case D3DXPC_MATRIX_ROWS:
1805 case D3DXPC_OBJECT:
1806 case D3DXPC_STRUCT:
1807 break;
1809 default:
1810 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1811 break;
1815 WARN("Parameter not found.\n");
1817 return D3DERR_INVALIDCALL;
1820 static HRESULT d3dx9_base_effect_get_vector(struct d3dx9_base_effect *base,
1821 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
1823 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1825 if (vector && param && !param->element_count)
1827 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1829 switch (param->class)
1831 case D3DXPC_SCALAR:
1832 case D3DXPC_VECTOR:
1833 if (param->type == D3DXPT_INT && param->bytes == 4)
1835 TRACE("INT fixup\n");
1836 vector->x = (((*(INT *)param->data) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1837 vector->y = (((*(INT *)param->data) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1838 vector->z = ((*(INT *)param->data) & 0xff) * INT_FLOAT_MULTI_INVERSE;
1839 vector->w = (((*(INT *)param->data) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1840 return D3D_OK;
1842 get_vector(param, vector);
1843 return D3D_OK;
1845 case D3DXPC_MATRIX_ROWS:
1846 case D3DXPC_OBJECT:
1847 case D3DXPC_STRUCT:
1848 break;
1850 default:
1851 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1852 break;
1856 WARN("Parameter not found.\n");
1858 return D3DERR_INVALIDCALL;
1861 static HRESULT d3dx9_base_effect_set_vector_array(struct d3dx9_base_effect *base,
1862 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
1864 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1866 if (param && param->element_count && param->element_count >= count)
1868 UINT i;
1870 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1872 switch (param->class)
1874 case D3DXPC_VECTOR:
1875 if (param->type == D3DXPT_FLOAT)
1877 if (param->columns == 4)
1878 memcpy(param->data, vector, count * 4 * sizeof(float));
1879 else
1880 for (i = 0; i < count; ++i)
1881 memcpy((float *)param->data + param->columns * i, vector + i,
1882 param->columns * sizeof(float));
1883 return D3D_OK;
1886 for (i = 0; i < count; ++i)
1888 set_vector(&param->members[i], &vector[i]);
1890 return D3D_OK;
1892 case D3DXPC_SCALAR:
1893 case D3DXPC_MATRIX_ROWS:
1894 case D3DXPC_OBJECT:
1895 case D3DXPC_STRUCT:
1896 break;
1898 default:
1899 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1900 break;
1904 WARN("Parameter not found.\n");
1906 return D3DERR_INVALIDCALL;
1909 static HRESULT d3dx9_base_effect_get_vector_array(struct d3dx9_base_effect *base,
1910 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
1912 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1914 if (!count) return D3D_OK;
1916 if (vector && param && count <= param->element_count)
1918 UINT i;
1920 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1922 switch (param->class)
1924 case D3DXPC_VECTOR:
1925 for (i = 0; i < count; ++i)
1927 get_vector(&param->members[i], &vector[i]);
1929 return D3D_OK;
1931 case D3DXPC_SCALAR:
1932 case D3DXPC_MATRIX_ROWS:
1933 case D3DXPC_OBJECT:
1934 case D3DXPC_STRUCT:
1935 break;
1937 default:
1938 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1939 break;
1943 WARN("Parameter not found.\n");
1945 return D3DERR_INVALIDCALL;
1948 static HRESULT d3dx9_base_effect_set_matrix(struct d3dx9_base_effect *base,
1949 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
1951 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1953 if (param && !param->element_count)
1955 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1957 switch (param->class)
1959 case D3DXPC_MATRIX_ROWS:
1960 set_matrix(param, matrix);
1961 return D3D_OK;
1963 case D3DXPC_SCALAR:
1964 case D3DXPC_VECTOR:
1965 case D3DXPC_OBJECT:
1966 case D3DXPC_STRUCT:
1967 break;
1969 default:
1970 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1971 break;
1975 WARN("Parameter not found.\n");
1977 return D3DERR_INVALIDCALL;
1980 static HRESULT d3dx9_base_effect_get_matrix(struct d3dx9_base_effect *base,
1981 D3DXHANDLE parameter, D3DXMATRIX *matrix)
1983 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1985 if (matrix && param && !param->element_count)
1987 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1989 switch (param->class)
1991 case D3DXPC_MATRIX_ROWS:
1992 get_matrix(param, matrix, FALSE);
1993 return D3D_OK;
1995 case D3DXPC_SCALAR:
1996 case D3DXPC_VECTOR:
1997 case D3DXPC_OBJECT:
1998 case D3DXPC_STRUCT:
1999 break;
2001 default:
2002 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2003 break;
2007 WARN("Parameter not found.\n");
2009 return D3DERR_INVALIDCALL;
2012 static HRESULT d3dx9_base_effect_set_matrix_array(struct d3dx9_base_effect *base,
2013 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2015 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2017 if (param && param->element_count >= count)
2019 UINT i;
2021 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2023 switch (param->class)
2025 case D3DXPC_MATRIX_ROWS:
2026 for (i = 0; i < count; ++i)
2028 set_matrix(&param->members[i], &matrix[i]);
2030 return D3D_OK;
2032 case D3DXPC_SCALAR:
2033 case D3DXPC_VECTOR:
2034 case D3DXPC_OBJECT:
2035 case D3DXPC_STRUCT:
2036 break;
2038 default:
2039 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2040 break;
2044 WARN("Parameter not found.\n");
2046 return D3DERR_INVALIDCALL;
2049 static HRESULT d3dx9_base_effect_get_matrix_array(struct d3dx9_base_effect *base,
2050 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2052 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2054 if (!count) return D3D_OK;
2056 if (matrix && param && count <= param->element_count)
2058 UINT i;
2060 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2062 switch (param->class)
2064 case D3DXPC_MATRIX_ROWS:
2065 for (i = 0; i < count; ++i)
2067 get_matrix(&param->members[i], &matrix[i], FALSE);
2069 return D3D_OK;
2071 case D3DXPC_SCALAR:
2072 case D3DXPC_VECTOR:
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_matrix_pointer_array(struct d3dx9_base_effect *base,
2089 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2091 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2093 if (param && count <= param->element_count)
2095 UINT i;
2097 switch (param->class)
2099 case D3DXPC_MATRIX_ROWS:
2100 for (i = 0; i < count; ++i)
2102 set_matrix(&param->members[i], matrix[i]);
2104 return D3D_OK;
2106 case D3DXPC_SCALAR:
2107 case D3DXPC_VECTOR:
2108 case D3DXPC_OBJECT:
2109 break;
2111 default:
2112 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2113 break;
2117 WARN("Parameter not found.\n");
2119 return D3DERR_INVALIDCALL;
2122 static HRESULT d3dx9_base_effect_get_matrix_pointer_array(struct d3dx9_base_effect *base,
2123 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2125 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2127 if (!count) return D3D_OK;
2129 if (param && matrix && count <= param->element_count)
2131 UINT i;
2133 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2135 switch (param->class)
2137 case D3DXPC_MATRIX_ROWS:
2138 for (i = 0; i < count; ++i)
2140 get_matrix(&param->members[i], matrix[i], FALSE);
2142 return D3D_OK;
2144 case D3DXPC_SCALAR:
2145 case D3DXPC_VECTOR:
2146 case D3DXPC_OBJECT:
2147 break;
2149 default:
2150 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2151 break;
2155 WARN("Parameter not found.\n");
2157 return D3DERR_INVALIDCALL;
2160 static HRESULT d3dx9_base_effect_set_matrix_transpose(struct d3dx9_base_effect *base,
2161 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2163 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2165 if (param && !param->element_count)
2167 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2169 switch (param->class)
2171 case D3DXPC_MATRIX_ROWS:
2172 set_matrix_transpose(param, matrix);
2173 return D3D_OK;
2175 case D3DXPC_SCALAR:
2176 case D3DXPC_VECTOR:
2177 case D3DXPC_OBJECT:
2178 case D3DXPC_STRUCT:
2179 break;
2181 default:
2182 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2183 break;
2187 WARN("Parameter not found.\n");
2189 return D3DERR_INVALIDCALL;
2192 static HRESULT d3dx9_base_effect_get_matrix_transpose(struct d3dx9_base_effect *base,
2193 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2195 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2197 if (matrix && param && !param->element_count)
2199 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2201 switch (param->class)
2203 case D3DXPC_SCALAR:
2204 case D3DXPC_VECTOR:
2205 get_matrix(param, matrix, FALSE);
2206 return D3D_OK;
2208 case D3DXPC_MATRIX_ROWS:
2209 get_matrix(param, matrix, TRUE);
2210 return D3D_OK;
2212 case D3DXPC_OBJECT:
2213 case D3DXPC_STRUCT:
2214 break;
2216 default:
2217 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2218 break;
2222 WARN("Parameter not found.\n");
2224 return D3DERR_INVALIDCALL;
2227 static HRESULT d3dx9_base_effect_set_matrix_transpose_array(struct d3dx9_base_effect *base,
2228 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2230 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2232 if (param && param->element_count >= count)
2234 UINT i;
2236 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2238 switch (param->class)
2240 case D3DXPC_MATRIX_ROWS:
2241 for (i = 0; i < count; ++i)
2243 set_matrix_transpose(&param->members[i], &matrix[i]);
2245 return D3D_OK;
2247 case D3DXPC_SCALAR:
2248 case D3DXPC_VECTOR:
2249 case D3DXPC_OBJECT:
2250 case D3DXPC_STRUCT:
2251 break;
2253 default:
2254 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2255 break;
2259 WARN("Parameter not found.\n");
2261 return D3DERR_INVALIDCALL;
2264 static HRESULT d3dx9_base_effect_get_matrix_transpose_array(struct d3dx9_base_effect *base,
2265 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2267 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2269 if (!count) return D3D_OK;
2271 if (matrix && param && count <= param->element_count)
2273 UINT i;
2275 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2277 switch (param->class)
2279 case D3DXPC_MATRIX_ROWS:
2280 for (i = 0; i < count; ++i)
2282 get_matrix(&param->members[i], &matrix[i], TRUE);
2284 return D3D_OK;
2286 case D3DXPC_SCALAR:
2287 case D3DXPC_VECTOR:
2288 case D3DXPC_OBJECT:
2289 case D3DXPC_STRUCT:
2290 break;
2292 default:
2293 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2294 break;
2298 WARN("Parameter not found.\n");
2300 return D3DERR_INVALIDCALL;
2303 static HRESULT d3dx9_base_effect_set_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2304 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2306 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2308 if (param && count <= param->element_count)
2310 UINT i;
2312 switch (param->class)
2314 case D3DXPC_MATRIX_ROWS:
2315 for (i = 0; i < count; ++i)
2317 set_matrix_transpose(&param->members[i], matrix[i]);
2319 return D3D_OK;
2321 case D3DXPC_SCALAR:
2322 case D3DXPC_VECTOR:
2323 case D3DXPC_OBJECT:
2324 break;
2326 default:
2327 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2328 break;
2332 WARN("Parameter not found.\n");
2334 return D3DERR_INVALIDCALL;
2337 static HRESULT d3dx9_base_effect_get_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2338 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2340 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2342 if (!count) return D3D_OK;
2344 if (matrix && param && count <= param->element_count)
2346 UINT i;
2348 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2350 switch (param->class)
2352 case D3DXPC_MATRIX_ROWS:
2353 for (i = 0; i < count; ++i)
2355 get_matrix(&param->members[i], matrix[i], TRUE);
2357 return D3D_OK;
2359 case D3DXPC_SCALAR:
2360 case D3DXPC_VECTOR:
2361 case D3DXPC_OBJECT:
2362 break;
2364 default:
2365 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2366 break;
2370 WARN("Parameter not found.\n");
2372 return D3DERR_INVALIDCALL;
2375 static HRESULT d3dx9_base_effect_set_string(struct d3dx9_base_effect *base,
2376 D3DXHANDLE parameter, const char *string)
2378 FIXME("stub!\n");
2380 return E_NOTIMPL;
2383 static HRESULT d3dx9_base_effect_get_string(struct d3dx9_base_effect *base,
2384 D3DXHANDLE parameter, const char **string)
2386 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2388 if (string && param && !param->element_count && param->type == D3DXPT_STRING)
2390 *string = *(const char **)param->data;
2391 TRACE("Returning %s.\n", debugstr_a(*string));
2392 return D3D_OK;
2395 WARN("Parameter not found.\n");
2397 return D3DERR_INVALIDCALL;
2400 static HRESULT d3dx9_base_effect_set_texture(struct d3dx9_base_effect *base,
2401 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
2403 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2405 if (param && !param->element_count &&
2406 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2407 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2408 || param->type == D3DXPT_TEXTURECUBE))
2410 struct IDirect3DBaseTexture9 *oltexture = *(struct IDirect3DBaseTexture9 **)param->data;
2412 if (texture == oltexture)
2413 return D3D_OK;
2415 if (texture) IDirect3DBaseTexture9_AddRef(texture);
2416 if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
2418 *(struct IDirect3DBaseTexture9 **)param->data = texture;
2420 return D3D_OK;
2423 WARN("Parameter not found.\n");
2425 return D3DERR_INVALIDCALL;
2428 static HRESULT d3dx9_base_effect_get_texture(struct d3dx9_base_effect *base,
2429 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
2431 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2433 if (texture && param && !param->element_count &&
2434 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2435 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2436 || param->type == D3DXPT_TEXTURECUBE))
2438 *texture = *(struct IDirect3DBaseTexture9 **)param->data;
2439 if (*texture) IDirect3DBaseTexture9_AddRef(*texture);
2440 TRACE("Returning %p\n", *texture);
2441 return D3D_OK;
2444 WARN("Parameter not found.\n");
2446 return D3DERR_INVALIDCALL;
2449 static HRESULT d3dx9_base_effect_get_pixel_shader(struct d3dx9_base_effect *base,
2450 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
2452 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2454 if (shader && param && !param->element_count && param->type == D3DXPT_PIXELSHADER)
2456 if ((*shader = *(struct IDirect3DPixelShader9 **)param->data))
2457 IDirect3DPixelShader9_AddRef(*shader);
2458 TRACE("Returning %p.\n", *shader);
2459 return D3D_OK;
2462 WARN("Parameter not found.\n");
2464 return D3DERR_INVALIDCALL;
2467 static HRESULT d3dx9_base_effect_get_vertex_shader(struct d3dx9_base_effect *base,
2468 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
2470 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2472 if (shader && param && !param->element_count && param->type == D3DXPT_VERTEXSHADER)
2474 if ((*shader = *(struct IDirect3DVertexShader9 **)param->data))
2475 IDirect3DVertexShader9_AddRef(*shader);
2476 TRACE("Returning %p.\n", *shader);
2477 return D3D_OK;
2480 WARN("Parameter not found.\n");
2482 return D3DERR_INVALIDCALL;
2485 static HRESULT d3dx9_base_effect_set_array_range(struct d3dx9_base_effect *base,
2486 D3DXHANDLE parameter, UINT start, UINT end)
2488 FIXME("stub!\n");
2490 return E_NOTIMPL;
2493 static HRESULT d3dx9_get_param_value_ptr(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2494 struct d3dx_state *state, void **param_value, struct d3dx_parameter **out_param)
2496 struct d3dx_parameter *param;
2497 param = state->parameter.referenced_param ? state->parameter.referenced_param : &state->parameter;
2499 switch (state->type)
2501 case ST_CONSTANT:
2502 case ST_PARAMETER:
2503 *param_value = param->data;
2504 *out_param = param;
2505 return D3D_OK;
2506 case ST_ARRAY_SELECTOR:
2507 FIXME("Array selector.\n");
2508 break;
2509 case ST_FXLC:
2510 FIXME("FXLC not supported yet.\n");
2511 break;
2513 *param_value = NULL;
2514 *out_param = NULL;
2515 return E_NOTIMPL;
2518 static void d3dx9_set_light_parameter(enum LIGHT_TYPE op, D3DLIGHT9 *light, void *value)
2520 static const struct
2522 unsigned int offset;
2523 const char *name;
2525 light_tbl[] =
2527 {FIELD_OFFSET(D3DLIGHT9, Type), "LC_TYPE"},
2528 {FIELD_OFFSET(D3DLIGHT9, Diffuse), "LT_DIFFUSE"},
2529 {FIELD_OFFSET(D3DLIGHT9, Specular), "LT_SPECULAR"},
2530 {FIELD_OFFSET(D3DLIGHT9, Ambient), "LT_AMBIENT"},
2531 {FIELD_OFFSET(D3DLIGHT9, Position), "LT_POSITION"},
2532 {FIELD_OFFSET(D3DLIGHT9, Direction), "LT_DIRECTION"},
2533 {FIELD_OFFSET(D3DLIGHT9, Range), "LT_RANGE"},
2534 {FIELD_OFFSET(D3DLIGHT9, Falloff), "LT_FALLOFF"},
2535 {FIELD_OFFSET(D3DLIGHT9, Attenuation0), "LT_ATTENUATION0"},
2536 {FIELD_OFFSET(D3DLIGHT9, Attenuation1), "LT_ATTENUATION1"},
2537 {FIELD_OFFSET(D3DLIGHT9, Attenuation2), "LT_ATTENUATION2"},
2538 {FIELD_OFFSET(D3DLIGHT9, Theta), "LT_THETA"},
2539 {FIELD_OFFSET(D3DLIGHT9, Phi), "LT_PHI"}
2541 switch (op)
2543 case LT_TYPE:
2544 TRACE("LT_TYPE %u.\n", *(D3DLIGHTTYPE *)value);
2545 light->Type = *(D3DLIGHTTYPE *)value;
2546 break;
2547 case LT_DIFFUSE:
2548 case LT_SPECULAR:
2549 case LT_AMBIENT:
2551 D3DCOLORVALUE c = *(D3DCOLORVALUE *)value;
2553 TRACE("%s (%f %f %f %f).\n", light_tbl[op].name, c.r, c.g, c.b, c.a);
2554 *(D3DCOLORVALUE *)((char *)light + light_tbl[op].offset) = c;
2555 break;
2557 case LT_POSITION:
2558 case LT_DIRECTION:
2560 D3DVECTOR v = *(D3DVECTOR *)value;
2562 TRACE("%s (%f %f %f).\n", light_tbl[op].name, v.x, v.y, v.z);
2563 *(D3DVECTOR *)((char *)light + light_tbl[op].offset) = v;
2564 break;
2566 case LT_RANGE:
2567 case LT_FALLOFF:
2568 case LT_ATTENUATION0:
2569 case LT_ATTENUATION1:
2570 case LT_ATTENUATION2:
2571 case LT_THETA:
2572 case LT_PHI:
2574 float v = *(float *)value;
2575 TRACE("%s %f.\n", light_tbl[op].name, v);
2576 *(float *)((char *)light + light_tbl[op].offset) = v;
2577 break;
2579 default:
2580 WARN("Unknown light parameter %u.\n", op);
2581 break;
2585 static void d3dx9_set_material_parameter(enum MATERIAL_TYPE op, D3DMATERIAL9 *material, void *value)
2587 static const struct
2589 unsigned int offset;
2590 const char *name;
2592 material_tbl[] =
2594 {FIELD_OFFSET(D3DMATERIAL9, Diffuse), "MT_DIFFUSE"},
2595 {FIELD_OFFSET(D3DMATERIAL9, Ambient), "MT_AMBIENT"},
2596 {FIELD_OFFSET(D3DMATERIAL9, Specular), "MT_SPECULAR"},
2597 {FIELD_OFFSET(D3DMATERIAL9, Emissive), "MT_EMISSIVE"},
2598 {FIELD_OFFSET(D3DMATERIAL9, Power), "MT_POWER"}
2601 switch (op)
2603 case MT_POWER:
2605 float v = *(float *)value;
2607 TRACE("%s %f.\n", material_tbl[op].name, v);
2608 material->Power = v;
2609 break;
2611 case MT_DIFFUSE:
2612 case MT_AMBIENT:
2613 case MT_SPECULAR:
2614 case MT_EMISSIVE:
2616 D3DCOLORVALUE c = *(D3DCOLORVALUE *)value;
2618 TRACE("%s, value (%f %f %f %f).\n", material_tbl[op].name, c.r, c.g, c.b, c.a);
2619 *(D3DCOLORVALUE *)((char *)material + material_tbl[op].offset) = c;
2620 break;
2622 default:
2623 WARN("Unknown material parameter %u.\n", op);
2624 break;
2628 static HRESULT d3dx_set_shader_const_state(IDirect3DDevice9 *device, enum SHADER_CONSTANT_TYPE op, UINT index,
2629 struct d3dx_parameter *param, void *value_ptr)
2631 static const struct
2633 D3DXPARAMETER_TYPE type;
2634 UINT elem_size;
2635 const char *name;
2637 const_tbl[] =
2639 {D3DXPT_FLOAT, sizeof(float) * 4, "SCT_VSFLOAT"},
2640 {D3DXPT_BOOL, sizeof(BOOL), "SCT_VSBOOL"},
2641 {D3DXPT_INT, sizeof(int) * 4, "SCT_VSINT"},
2642 {D3DXPT_FLOAT, sizeof(float) * 4, "SCT_PSFLOAT"},
2643 {D3DXPT_BOOL, sizeof(BOOL), "SCT_PSBOOL"},
2644 {D3DXPT_INT, sizeof(int) * 4, "SCT_PSINT"},
2646 UINT nelem;
2648 if (op < 0 || op > SCT_PSINT)
2650 FIXME("Unknown op %u.\n", op);
2651 return D3DERR_INVALIDCALL;
2653 nelem = param->bytes / const_tbl[op].elem_size;
2654 TRACE("%s, index %u, %u elements.\n", const_tbl[op].name, index, nelem);
2655 if (param->type != const_tbl[op].type)
2657 FIXME("Unexpected param type %u.\n", param->type);
2658 return D3DERR_INVALIDCALL;
2660 if (param->bytes % const_tbl[op].elem_size != 0)
2662 FIXME("Unexpected param size %u, rows %u, cols %u.\n", param->bytes, param->rows, param->columns);
2663 return D3DERR_INVALIDCALL;
2666 switch (op)
2668 case SCT_VSFLOAT:
2669 return IDirect3DDevice9_SetVertexShaderConstantF(device, index, (const float *)value_ptr, nelem);
2670 case SCT_VSBOOL:
2671 return IDirect3DDevice9_SetVertexShaderConstantB(device, index, (const BOOL *)value_ptr, nelem);
2672 case SCT_VSINT:
2673 return IDirect3DDevice9_SetVertexShaderConstantI(device, index, (const int *)value_ptr, nelem);
2674 case SCT_PSFLOAT:
2675 return IDirect3DDevice9_SetPixelShaderConstantF(device, index, (const float *)value_ptr, nelem);
2676 case SCT_PSBOOL:
2677 return IDirect3DDevice9_SetPixelShaderConstantB(device, index, (const BOOL *)value_ptr, nelem);
2678 case SCT_PSINT:
2679 return IDirect3DDevice9_SetPixelShaderConstantI(device, index, (const int *)value_ptr, nelem);
2681 return D3D_OK;
2684 static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
2685 struct d3dx_state *state, int parent_index)
2687 IDirect3DDevice9 *device = effect->device;
2688 struct d3dx_parameter *param;
2689 void *param_value;
2690 HRESULT hr;
2692 TRACE("operation %u, index %u, type %u.\n", state->operation, state->index, state->type);
2693 hr = d3dx9_get_param_value_ptr(effect, pass, state, &param_value, &param);
2694 if (FAILED(hr))
2695 return hr;
2697 switch (state_table[state->operation].class)
2699 case SC_RENDERSTATE:
2700 TRACE("%s, operation %u, value %u.\n", state_table[state->operation].name,
2701 state_table[state->operation].op, *(DWORD *)param_value);
2702 return IDirect3DDevice9_SetRenderState(device, state_table[state->operation].op, *(DWORD *)param_value);
2703 case SC_FVF:
2704 TRACE("%s, value %#x.\n", state_table[state->operation].name, *(DWORD *)param_value);
2705 return IDirect3DDevice9_SetFVF(device, *(DWORD *)param_value);
2706 case SC_TEXTURE:
2708 UINT unit;
2710 unit = parent_index == -1 ? state->index : parent_index;
2711 TRACE("%s, unit %u, value %p.\n", state_table[state->operation].name, unit,
2712 *(IDirect3DBaseTexture9 **)param_value);
2713 return IDirect3DDevice9_SetTexture(device, unit, *(IDirect3DBaseTexture9 **)param_value);
2715 case SC_TEXTURESTAGE:
2716 TRACE("%s, stage %u, value %u.\n", state_table[state->operation].name, state->index, *(DWORD *)param_value);
2717 return IDirect3DDevice9_SetTextureStageState(device, state->index,
2718 state_table[state->operation].op, *(DWORD *)param_value);
2719 case SC_SETSAMPLER:
2721 struct d3dx_sampler *sampler;
2722 HRESULT ret, hr;
2723 unsigned int i;
2725 sampler = (struct d3dx_sampler *)param_value;
2726 TRACE("%s, sampler %u, applying %u states.\n", state_table[state->operation].name, state->index,
2727 sampler->state_count);
2728 ret = D3D_OK;
2729 for (i = 0; i < sampler->state_count; i++)
2731 hr = d3dx9_apply_state(effect, pass, &sampler->states[i], state->index);
2732 if (FAILED(hr))
2733 ret = hr;
2735 return ret;
2737 case SC_SAMPLERSTATE:
2739 UINT sampler;
2741 sampler = parent_index == -1 ? state->index : parent_index;
2742 TRACE("%s, sampler %u, value %u.\n", state_table[state->operation].name, sampler, *(DWORD *)param_value);
2743 return IDirect3DDevice9_SetSamplerState(device, sampler, state_table[state->operation].op,
2744 *(DWORD *)param_value);
2746 case SC_VERTEXSHADER:
2747 TRACE("%s, shader %p.\n", state_table[state->operation].name, *(IDirect3DVertexShader9 **)param_value);
2748 hr = IDirect3DDevice9_SetVertexShader(device, *(IDirect3DVertexShader9 **)param_value);
2749 if (FAILED(hr))
2750 ERR("Could not set vertex shader, hr %#x.\n", hr);
2751 FIXME("Not executing preshader and not setting constants.\n");
2752 return hr;
2753 case SC_PIXELSHADER:
2754 TRACE("%s, shader %p.\n", state_table[state->operation].name, *(IDirect3DPixelShader9 **)param_value);
2755 hr = IDirect3DDevice9_SetPixelShader(device, *(IDirect3DPixelShader9 **)param_value);
2756 if (FAILED(hr))
2757 ERR("Could not set pixel shader, hr %#x.\n", hr);
2758 FIXME("Not executing preshader and not setting constants.\n");
2759 return hr;
2760 case SC_TRANSFORM:
2761 TRACE("%s, state %u.\n", state_table[state->operation].name, state->index);
2762 return IDirect3DDevice9_SetTransform(device, state_table[state->operation].op + state->index,
2763 (D3DMATRIX *)param_value);
2764 case SC_LIGHTENABLE:
2765 TRACE("%s, index %u, value %u.\n", state_table[state->operation].name, state->index, *(BOOL *)param_value);
2766 return IDirect3DDevice9_LightEnable(device, state->index, *(BOOL *)param_value);
2767 case SC_LIGHT:
2769 D3DLIGHT9 light;
2771 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
2772 state_table[state->operation].op);
2773 hr = IDirect3DDevice9_GetLight(device, state->index, &light);
2774 if (FAILED(hr))
2776 WARN("Could not get light, hr %#x.\n", hr);
2777 memset(&light, 0, sizeof(light));
2779 d3dx9_set_light_parameter(state_table[state->operation].op, &light, param_value);
2780 return IDirect3DDevice9_SetLight(device, state->index, &light);
2782 case SC_MATERIAL:
2784 D3DMATERIAL9 material;
2786 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
2787 state_table[state->operation].op);
2788 hr = IDirect3DDevice9_GetMaterial(device, &material);
2789 if (FAILED(hr))
2791 WARN("Could not get material, hr %#x.\n", hr);
2792 memset(&material, 0, sizeof(material));
2794 d3dx9_set_material_parameter(state_table[state->operation].op, &material, param_value);
2795 return IDirect3DDevice9_SetMaterial(device, &material);
2797 case SC_NPATCHMODE:
2798 TRACE("%s, nsegments %f.\n", state_table[state->operation].name, *(float *)param_value);
2799 return IDirect3DDevice9_SetNPatchMode(device, *(float *)param_value);
2800 case SC_SHADERCONST:
2801 TRACE("%s, index %u, op %u.\n", state_table[state->operation].name, state->index,
2802 state_table[state->operation].op);
2803 return d3dx_set_shader_const_state(device, state_table[state->operation].op, state->index,
2804 param, param_value);
2805 default:
2806 FIXME("%s not handled.\n", state_table[state->operation].name);
2807 break;
2809 return D3D_OK;
2812 static HRESULT d3dx9_apply_pass_states(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass)
2814 unsigned int i;
2815 HRESULT ret;
2817 TRACE("effect %p, pass %p, state_count %u.\n", effect, pass, pass->state_count);
2819 ret = D3D_OK;
2820 for (i = 0; i < pass->state_count; i++)
2822 HRESULT hr;
2824 hr = d3dx9_apply_state(effect, pass, &pass->states[i], -1);
2825 if (FAILED(hr))
2827 WARN("Error applying state, hr %#x.\n", hr);
2828 ret = hr;
2831 return ret;
2834 static inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
2836 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
2839 /*** IUnknown methods ***/
2840 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
2842 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
2844 if (IsEqualGUID(riid, &IID_IUnknown) ||
2845 IsEqualGUID(riid, &IID_ID3DXEffect))
2847 iface->lpVtbl->AddRef(iface);
2848 *object = iface;
2849 return S_OK;
2852 ERR("Interface %s not found\n", debugstr_guid(riid));
2854 return E_NOINTERFACE;
2857 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
2859 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2861 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
2863 return InterlockedIncrement(&This->ref);
2866 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
2868 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2869 ULONG ref = InterlockedDecrement(&This->ref);
2871 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
2873 if (!ref)
2875 free_effect(This);
2876 HeapFree(GetProcessHeap(), 0, This);
2879 return ref;
2882 /*** ID3DXBaseEffect methods ***/
2883 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
2885 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2887 TRACE("iface %p, desc %p.\n", iface, desc);
2889 return d3dx9_base_effect_get_desc(&effect->base_effect, desc);
2892 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface,
2893 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
2895 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2897 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
2899 return d3dx9_base_effect_get_parameter_desc(&effect->base_effect, parameter, desc);
2902 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface,
2903 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
2905 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2907 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
2909 return d3dx9_base_effect_get_technique_desc(&effect->base_effect, technique, desc);
2912 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
2914 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2916 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
2918 return d3dx9_base_effect_get_pass_desc(&effect->base_effect, pass, desc);
2921 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
2923 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2925 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
2927 return d3dx9_base_effect_get_function_desc(&effect->base_effect, shader, desc);
2930 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2932 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2934 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
2936 return d3dx9_base_effect_get_parameter(&effect->base_effect, parameter, index);
2939 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface,
2940 D3DXHANDLE parameter, const char *name)
2942 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2944 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
2946 return d3dx9_base_effect_get_parameter_by_name(&effect->base_effect, parameter, name);
2949 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface,
2950 D3DXHANDLE parameter, const char *semantic)
2952 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2954 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
2956 return d3dx9_base_effect_get_parameter_by_semantic(&effect->base_effect, parameter, semantic);
2959 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2961 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2963 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
2965 return d3dx9_base_effect_get_parameter_element(&effect->base_effect, parameter, index);
2968 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
2970 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2972 TRACE("iface %p, index %u.\n", iface, index);
2974 return d3dx9_base_effect_get_technique(&effect->base_effect, index);
2977 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, const char *name)
2979 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2981 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
2983 return d3dx9_base_effect_get_technique_by_name(&effect->base_effect, name);
2986 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
2988 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2990 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
2992 return d3dx9_base_effect_get_pass(&effect->base_effect, technique, index);
2995 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface,
2996 D3DXHANDLE technique, const char *name)
2998 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3000 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
3002 return d3dx9_base_effect_get_pass_by_name(&effect->base_effect, technique, name);
3005 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
3007 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3009 TRACE("iface %p, index %u.\n", iface, index);
3011 return d3dx9_base_effect_get_function(&effect->base_effect, index);
3014 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, const char *name)
3016 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3018 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3020 return d3dx9_base_effect_get_function_by_name(&effect->base_effect, name);
3023 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
3025 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3027 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
3029 return d3dx9_base_effect_get_annotation(&effect->base_effect, object, index);
3032 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface,
3033 D3DXHANDLE object, const char *name)
3035 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3037 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
3039 return d3dx9_base_effect_get_annotation_by_name(&effect->base_effect, object, name);
3042 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface,
3043 D3DXHANDLE parameter, const void *data, UINT bytes)
3045 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3047 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3049 return d3dx9_base_effect_set_value(&effect->base_effect, parameter, data, bytes);
3052 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface,
3053 D3DXHANDLE parameter, void *data, UINT bytes)
3055 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3057 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3059 return d3dx9_base_effect_get_value(&effect->base_effect, parameter, data, bytes);
3062 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
3064 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3066 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
3068 return d3dx9_base_effect_set_bool(&effect->base_effect, parameter, b);
3071 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
3073 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3075 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
3077 return d3dx9_base_effect_get_bool(&effect->base_effect, parameter, b);
3080 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface,
3081 D3DXHANDLE parameter, const BOOL *b, UINT count)
3083 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3085 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3087 return d3dx9_base_effect_set_bool_array(&effect->base_effect, parameter, b, count);
3090 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface,
3091 D3DXHANDLE parameter, BOOL *b, UINT count)
3093 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3095 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3097 return d3dx9_base_effect_get_bool_array(&effect->base_effect, parameter, b, count);
3100 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
3102 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3104 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
3106 return d3dx9_base_effect_set_int(&effect->base_effect, parameter, n);
3109 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
3111 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3113 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
3115 return d3dx9_base_effect_get_int(&effect->base_effect, parameter, n);
3118 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface,
3119 D3DXHANDLE parameter, const INT *n, UINT count)
3121 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3123 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3125 return d3dx9_base_effect_set_int_array(&effect->base_effect, parameter, n, count);
3128 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface,
3129 D3DXHANDLE parameter, INT *n, UINT count)
3131 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3133 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3135 return d3dx9_base_effect_get_int_array(&effect->base_effect, parameter, n, count);
3138 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float f)
3140 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3142 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
3144 return d3dx9_base_effect_set_float(&effect->base_effect, parameter, f);
3147 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float *f)
3149 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3151 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
3153 return d3dx9_base_effect_get_float(&effect->base_effect, parameter, f);
3156 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface,
3157 D3DXHANDLE parameter, const float *f, UINT count)
3159 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3161 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3163 return d3dx9_base_effect_set_float_array(&effect->base_effect, parameter, f, count);
3166 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface,
3167 D3DXHANDLE parameter, float *f, UINT count)
3169 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3171 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3173 return d3dx9_base_effect_get_float_array(&effect->base_effect, parameter, f, count);
3176 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface,
3177 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
3179 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3181 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3183 return d3dx9_base_effect_set_vector(&effect->base_effect, parameter, vector);
3186 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface,
3187 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
3189 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3191 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3193 return d3dx9_base_effect_get_vector(&effect->base_effect, parameter, vector);
3196 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface,
3197 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
3199 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3201 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3203 return d3dx9_base_effect_set_vector_array(&effect->base_effect, parameter, vector, count);
3206 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface,
3207 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
3209 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3211 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3213 return d3dx9_base_effect_get_vector_array(&effect->base_effect, parameter, vector, count);
3216 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface,
3217 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3219 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3221 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3223 return d3dx9_base_effect_set_matrix(&effect->base_effect, parameter, matrix);
3226 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface,
3227 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3229 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3231 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3233 return d3dx9_base_effect_get_matrix(&effect->base_effect, parameter, matrix);
3236 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface,
3237 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3239 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3241 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3243 return d3dx9_base_effect_set_matrix_array(&effect->base_effect, parameter, matrix, count);
3246 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface,
3247 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3249 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3251 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3253 return d3dx9_base_effect_get_matrix_array(&effect->base_effect, parameter, matrix, count);
3256 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface,
3257 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3259 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3261 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3263 return d3dx9_base_effect_set_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
3266 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface,
3267 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3269 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3271 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3273 return d3dx9_base_effect_get_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
3276 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface,
3277 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3279 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3281 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3283 return d3dx9_base_effect_set_matrix_transpose(&effect->base_effect, parameter, matrix);
3286 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface,
3287 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3289 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3291 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3293 return d3dx9_base_effect_get_matrix_transpose(&effect->base_effect, parameter, matrix);
3296 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface,
3297 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3299 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3301 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3303 return d3dx9_base_effect_set_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
3306 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface,
3307 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3309 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3311 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3313 return d3dx9_base_effect_get_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
3316 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface,
3317 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3319 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3321 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3323 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
3326 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface,
3327 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3329 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3331 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3333 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
3336 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char *string)
3338 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3340 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
3342 return d3dx9_base_effect_set_string(&effect->base_effect, parameter, string);
3345 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char **string)
3347 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3349 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
3351 return d3dx9_base_effect_get_string(&effect->base_effect, parameter, string);
3354 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(struct ID3DXEffect *iface,
3355 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
3357 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3359 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3361 return d3dx9_base_effect_set_texture(&effect->base_effect, parameter, texture);
3364 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(struct ID3DXEffect *iface,
3365 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
3367 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3369 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3371 return d3dx9_base_effect_get_texture(&effect->base_effect, parameter, texture);
3374 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface,
3375 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
3377 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3379 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3381 return d3dx9_base_effect_get_pixel_shader(&effect->base_effect, parameter, shader);
3384 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(struct ID3DXEffect *iface,
3385 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
3387 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3389 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3391 return d3dx9_base_effect_get_vertex_shader(&effect->base_effect, parameter, shader);
3394 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3396 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3398 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
3400 return d3dx9_base_effect_set_array_range(&effect->base_effect, parameter, start, end);
3403 /*** ID3DXEffect methods ***/
3404 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, ID3DXEffectPool **pool)
3406 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3408 TRACE("iface %p, pool %p\n", This, pool);
3410 if (!pool)
3412 WARN("Invalid argument supplied.\n");
3413 return D3DERR_INVALIDCALL;
3416 if (This->pool)
3418 This->pool->lpVtbl->AddRef(This->pool);
3421 *pool = This->pool;
3423 TRACE("Returning pool %p\n", *pool);
3425 return S_OK;
3428 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3430 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3431 struct d3dx9_base_effect *base = &This->base_effect;
3432 struct d3dx_technique *tech = get_valid_technique(base, technique);
3434 TRACE("iface %p, technique %p\n", This, technique);
3436 if (tech)
3438 This->active_technique = tech;
3439 TRACE("Technique %p\n", tech);
3440 return D3D_OK;
3443 WARN("Technique not found.\n");
3445 return D3DERR_INVALIDCALL;
3448 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3450 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3452 TRACE("iface %p\n", This);
3454 return get_technique_handle(This->active_technique);
3457 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3459 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3461 FIXME("(%p)->(%p): stub\n", This, technique);
3463 return D3D_OK;
3466 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3468 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3470 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3472 return E_NOTIMPL;
3475 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
3477 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3478 struct d3dx_parameter *param = get_valid_parameter(&effect->base_effect, parameter);
3480 FIXME("iface %p, parameter %p, technique %p stub.\n", iface, parameter, technique);
3481 TRACE("param %p (%s).\n", param, param ? debugstr_a(param->name) : "");
3483 return TRUE;
3486 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
3488 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3489 struct d3dx_technique *technique = effect->active_technique;
3491 TRACE("iface %p, passes %p, flags %#x.\n", iface, passes, flags);
3493 if (passes && technique)
3495 if (flags & ~(D3DXFX_DONOTSAVESTATE | D3DXFX_DONOTSAVESAMPLERSTATE | D3DXFX_DONOTSAVESHADERSTATE))
3496 WARN("Invalid flags (%#x) specified.\n", flags);
3498 if (effect->manager || flags & D3DXFX_DONOTSAVESTATE)
3500 TRACE("State capturing disabled.\n");
3502 else
3504 HRESULT hr;
3505 unsigned int i;
3507 if (!technique->saved_state)
3509 hr = IDirect3DDevice9_BeginStateBlock(effect->device);
3510 if (FAILED(hr))
3511 ERR("BeginStateBlock failed, hr %#x.\n", hr);
3512 for (i = 0; i < technique->pass_count; i++)
3513 d3dx9_apply_pass_states(effect, &technique->passes[i]);
3514 hr = IDirect3DDevice9_EndStateBlock(effect->device, &technique->saved_state);
3515 if (FAILED(hr))
3516 ERR("EndStateBlock failed, hr %#x.\n", hr);
3518 hr = IDirect3DStateBlock9_Capture(technique->saved_state);
3519 if (FAILED(hr))
3520 ERR("StateBlock Capture failed, hr %#x.\n", hr);
3523 *passes = technique->pass_count;
3524 effect->started = TRUE;
3525 effect->flags = flags;
3527 return D3D_OK;
3530 WARN("Invalid argument supplied.\n");
3532 return D3DERR_INVALIDCALL;
3535 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
3537 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3538 struct d3dx_technique *technique = effect->active_technique;
3540 TRACE("iface %p, pass %u\n", effect, pass);
3542 if (technique && pass < technique->pass_count && !effect->active_pass)
3544 effect->active_pass = &technique->passes[pass];
3545 return d3dx9_apply_pass_states(effect, effect->active_pass);
3548 WARN("Invalid argument supplied.\n");
3550 return D3DERR_INVALIDCALL;
3553 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect *iface)
3555 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3557 TRACE("iface %p.\n", iface);
3559 if (!effect->active_pass)
3561 WARN("Called without an active pass.\n");
3562 return D3D_OK;
3564 /* TODO: apply only changed states */
3565 return d3dx9_apply_pass_states(effect, effect->active_pass);
3568 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
3570 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3572 TRACE("iface %p\n", This);
3574 if (This->active_pass)
3576 This->active_pass = NULL;
3577 return D3D_OK;
3580 WARN("Invalid call.\n");
3582 return D3DERR_INVALIDCALL;
3585 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect *iface)
3587 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3588 struct d3dx_technique *technique = effect->active_technique;
3590 TRACE("iface %p.\n", iface);
3592 if (!effect->started)
3593 return D3D_OK;
3595 if (effect->manager || effect->flags & D3DXFX_DONOTSAVESTATE)
3597 TRACE("State restoring disabled.\n");
3599 else
3601 HRESULT hr;
3603 if (technique && technique->saved_state)
3605 hr = IDirect3DStateBlock9_Apply(technique->saved_state);
3606 if (FAILED(hr))
3607 ERR("State block apply failed, hr %#x.\n", hr);
3609 else
3610 ERR("No saved state.\n");
3613 effect->started = FALSE;
3615 return D3D_OK;
3618 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, struct IDirect3DDevice9 **device)
3620 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3622 TRACE("iface %p, device %p\n", This, device);
3624 if (!device)
3626 WARN("Invalid argument supplied.\n");
3627 return D3DERR_INVALIDCALL;
3630 IDirect3DDevice9_AddRef(This->device);
3632 *device = This->device;
3634 TRACE("Returning device %p\n", *device);
3636 return S_OK;
3639 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
3641 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3643 FIXME("(%p)->(): stub\n", This);
3645 return E_NOTIMPL;
3648 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(ID3DXEffect* iface)
3650 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3652 FIXME("(%p)->(): stub\n", This);
3654 return E_NOTIMPL;
3657 static HRESULT WINAPI ID3DXEffectImpl_SetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager *manager)
3659 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3661 TRACE("iface %p, manager %p\n", This, manager);
3663 if (manager) IUnknown_AddRef(manager);
3664 if (This->manager) IUnknown_Release(This->manager);
3666 This->manager = manager;
3668 return D3D_OK;
3671 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager **manager)
3673 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3675 TRACE("iface %p, manager %p\n", This, manager);
3677 if (!manager)
3679 WARN("Invalid argument supplied.\n");
3680 return D3DERR_INVALIDCALL;
3683 if (This->manager) IUnknown_AddRef(This->manager);
3684 *manager = This->manager;
3686 return D3D_OK;
3689 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
3691 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3693 FIXME("(%p)->(): stub\n", This);
3695 return E_NOTIMPL;
3698 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
3700 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3702 FIXME("(%p)->(): stub\n", This);
3704 return NULL;
3707 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3709 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3711 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3713 return E_NOTIMPL;
3716 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3718 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3720 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3722 return E_NOTIMPL;
3725 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect *iface,
3726 struct IDirect3DDevice9 *device, struct ID3DXEffect **effect)
3728 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3730 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
3732 return E_NOTIMPL;
3735 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect *iface,
3736 D3DXHANDLE parameter, const void *data, UINT byte_offset, UINT bytes)
3738 FIXME("iface %p, parameter %p, data %p, byte_offset %u, bytes %u stub!\n",
3739 iface, parameter, data, byte_offset, bytes);
3741 return E_NOTIMPL;
3744 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
3746 /*** IUnknown methods ***/
3747 ID3DXEffectImpl_QueryInterface,
3748 ID3DXEffectImpl_AddRef,
3749 ID3DXEffectImpl_Release,
3750 /*** ID3DXBaseEffect methods ***/
3751 ID3DXEffectImpl_GetDesc,
3752 ID3DXEffectImpl_GetParameterDesc,
3753 ID3DXEffectImpl_GetTechniqueDesc,
3754 ID3DXEffectImpl_GetPassDesc,
3755 ID3DXEffectImpl_GetFunctionDesc,
3756 ID3DXEffectImpl_GetParameter,
3757 ID3DXEffectImpl_GetParameterByName,
3758 ID3DXEffectImpl_GetParameterBySemantic,
3759 ID3DXEffectImpl_GetParameterElement,
3760 ID3DXEffectImpl_GetTechnique,
3761 ID3DXEffectImpl_GetTechniqueByName,
3762 ID3DXEffectImpl_GetPass,
3763 ID3DXEffectImpl_GetPassByName,
3764 ID3DXEffectImpl_GetFunction,
3765 ID3DXEffectImpl_GetFunctionByName,
3766 ID3DXEffectImpl_GetAnnotation,
3767 ID3DXEffectImpl_GetAnnotationByName,
3768 ID3DXEffectImpl_SetValue,
3769 ID3DXEffectImpl_GetValue,
3770 ID3DXEffectImpl_SetBool,
3771 ID3DXEffectImpl_GetBool,
3772 ID3DXEffectImpl_SetBoolArray,
3773 ID3DXEffectImpl_GetBoolArray,
3774 ID3DXEffectImpl_SetInt,
3775 ID3DXEffectImpl_GetInt,
3776 ID3DXEffectImpl_SetIntArray,
3777 ID3DXEffectImpl_GetIntArray,
3778 ID3DXEffectImpl_SetFloat,
3779 ID3DXEffectImpl_GetFloat,
3780 ID3DXEffectImpl_SetFloatArray,
3781 ID3DXEffectImpl_GetFloatArray,
3782 ID3DXEffectImpl_SetVector,
3783 ID3DXEffectImpl_GetVector,
3784 ID3DXEffectImpl_SetVectorArray,
3785 ID3DXEffectImpl_GetVectorArray,
3786 ID3DXEffectImpl_SetMatrix,
3787 ID3DXEffectImpl_GetMatrix,
3788 ID3DXEffectImpl_SetMatrixArray,
3789 ID3DXEffectImpl_GetMatrixArray,
3790 ID3DXEffectImpl_SetMatrixPointerArray,
3791 ID3DXEffectImpl_GetMatrixPointerArray,
3792 ID3DXEffectImpl_SetMatrixTranspose,
3793 ID3DXEffectImpl_GetMatrixTranspose,
3794 ID3DXEffectImpl_SetMatrixTransposeArray,
3795 ID3DXEffectImpl_GetMatrixTransposeArray,
3796 ID3DXEffectImpl_SetMatrixTransposePointerArray,
3797 ID3DXEffectImpl_GetMatrixTransposePointerArray,
3798 ID3DXEffectImpl_SetString,
3799 ID3DXEffectImpl_GetString,
3800 ID3DXEffectImpl_SetTexture,
3801 ID3DXEffectImpl_GetTexture,
3802 ID3DXEffectImpl_GetPixelShader,
3803 ID3DXEffectImpl_GetVertexShader,
3804 ID3DXEffectImpl_SetArrayRange,
3805 /*** ID3DXEffect methods ***/
3806 ID3DXEffectImpl_GetPool,
3807 ID3DXEffectImpl_SetTechnique,
3808 ID3DXEffectImpl_GetCurrentTechnique,
3809 ID3DXEffectImpl_ValidateTechnique,
3810 ID3DXEffectImpl_FindNextValidTechnique,
3811 ID3DXEffectImpl_IsParameterUsed,
3812 ID3DXEffectImpl_Begin,
3813 ID3DXEffectImpl_BeginPass,
3814 ID3DXEffectImpl_CommitChanges,
3815 ID3DXEffectImpl_EndPass,
3816 ID3DXEffectImpl_End,
3817 ID3DXEffectImpl_GetDevice,
3818 ID3DXEffectImpl_OnLostDevice,
3819 ID3DXEffectImpl_OnResetDevice,
3820 ID3DXEffectImpl_SetStateManager,
3821 ID3DXEffectImpl_GetStateManager,
3822 ID3DXEffectImpl_BeginParameterBlock,
3823 ID3DXEffectImpl_EndParameterBlock,
3824 ID3DXEffectImpl_ApplyParameterBlock,
3825 ID3DXEffectImpl_DeleteParameterBlock,
3826 ID3DXEffectImpl_CloneEffect,
3827 ID3DXEffectImpl_SetRawValue
3830 static inline struct ID3DXEffectCompilerImpl *impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler *iface)
3832 return CONTAINING_RECORD(iface, struct ID3DXEffectCompilerImpl, ID3DXEffectCompiler_iface);
3835 /*** IUnknown methods ***/
3836 static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler *iface, REFIID riid, void **object)
3838 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
3840 if (IsEqualGUID(riid, &IID_IUnknown) ||
3841 IsEqualGUID(riid, &IID_ID3DXEffectCompiler))
3843 iface->lpVtbl->AddRef(iface);
3844 *object = iface;
3845 return S_OK;
3848 ERR("Interface %s not found\n", debugstr_guid(riid));
3850 return E_NOINTERFACE;
3853 static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface)
3855 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3857 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
3859 return InterlockedIncrement(&This->ref);
3862 static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface)
3864 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3865 ULONG ref = InterlockedDecrement(&This->ref);
3867 TRACE("iface %p: Release from %u\n", iface, ref + 1);
3869 if (!ref)
3871 free_effect_compiler(This);
3872 HeapFree(GetProcessHeap(), 0, This);
3875 return ref;
3878 /*** ID3DXBaseEffect methods ***/
3879 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler *iface, D3DXEFFECT_DESC *desc)
3881 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3883 TRACE("iface %p, desc %p.\n", iface, desc);
3885 return d3dx9_base_effect_get_desc(&compiler->base_effect, desc);
3888 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler *iface,
3889 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
3891 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3893 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
3895 return d3dx9_base_effect_get_parameter_desc(&compiler->base_effect, parameter, desc);
3898 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler *iface,
3899 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
3901 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3903 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
3905 return d3dx9_base_effect_get_technique_desc(&compiler->base_effect, technique, desc);
3908 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler *iface,
3909 D3DXHANDLE pass, D3DXPASS_DESC *desc)
3911 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3913 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
3915 return d3dx9_base_effect_get_pass_desc(&compiler->base_effect, pass, desc);
3918 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler *iface,
3919 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
3921 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3923 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
3925 return d3dx9_base_effect_get_function_desc(&compiler->base_effect, shader, desc);
3928 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler *iface,
3929 D3DXHANDLE parameter, UINT index)
3931 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3933 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3935 return d3dx9_base_effect_get_parameter(&compiler->base_effect, parameter, index);
3938 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler *iface,
3939 D3DXHANDLE parameter, const char *name)
3941 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3943 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
3945 return d3dx9_base_effect_get_parameter_by_name(&compiler->base_effect, parameter, name);
3948 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler *iface,
3949 D3DXHANDLE parameter, const char *semantic)
3951 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3953 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
3955 return d3dx9_base_effect_get_parameter_by_semantic(&compiler->base_effect, parameter, semantic);
3958 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler *iface,
3959 D3DXHANDLE parameter, UINT index)
3961 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3963 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3965 return d3dx9_base_effect_get_parameter_element(&compiler->base_effect, parameter, index);
3968 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler *iface, UINT index)
3970 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3972 TRACE("iface %p, index %u.\n", iface, index);
3974 return d3dx9_base_effect_get_technique(&compiler->base_effect, index);
3977 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler *iface, const char *name)
3979 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3981 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3983 return d3dx9_base_effect_get_technique_by_name(&compiler->base_effect, name);
3986 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler *iface, D3DXHANDLE technique, UINT index)
3988 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3990 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
3992 return d3dx9_base_effect_get_pass(&compiler->base_effect, technique, index);
3995 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler *iface,
3996 D3DXHANDLE technique, const char *name)
3998 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4000 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
4002 return d3dx9_base_effect_get_pass_by_name(&compiler->base_effect, technique, name);
4005 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler *iface, UINT index)
4007 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4009 TRACE("iface %p, index %u.\n", iface, index);
4011 return d3dx9_base_effect_get_function(&compiler->base_effect, index);
4014 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler *iface, const char *name)
4016 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4018 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4020 return d3dx9_base_effect_get_function_by_name(&compiler->base_effect, name);
4023 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler *iface,
4024 D3DXHANDLE object, UINT index)
4026 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4028 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
4030 return d3dx9_base_effect_get_annotation(&compiler->base_effect, object, index);
4033 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler *iface,
4034 D3DXHANDLE object, const char *name)
4036 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4038 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
4040 return d3dx9_base_effect_get_annotation_by_name(&compiler->base_effect, object, name);
4043 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler *iface,
4044 D3DXHANDLE parameter, const void *data, UINT bytes)
4046 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4048 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
4050 return d3dx9_base_effect_set_value(&compiler->base_effect, parameter, data, bytes);
4053 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler *iface,
4054 D3DXHANDLE parameter, void *data, UINT bytes)
4056 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4058 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
4060 return d3dx9_base_effect_get_value(&compiler->base_effect, parameter, data, bytes);
4063 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL b)
4065 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4067 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
4069 return d3dx9_base_effect_set_bool(&compiler->base_effect, parameter, b);
4072 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b)
4074 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4076 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
4078 return d3dx9_base_effect_get_bool(&compiler->base_effect, parameter, b);
4081 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler *iface,
4082 D3DXHANDLE parameter, const BOOL *b, UINT count)
4084 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4086 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
4088 return d3dx9_base_effect_set_bool_array(&compiler->base_effect, parameter, b, count);
4091 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler *iface,
4092 D3DXHANDLE parameter, BOOL *b, UINT count)
4094 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4096 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
4098 return d3dx9_base_effect_get_bool_array(&compiler->base_effect, parameter, b, count);
4101 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT n)
4103 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4105 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
4107 return d3dx9_base_effect_set_int(&compiler->base_effect, parameter, n);
4110 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n)
4112 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4114 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
4116 return d3dx9_base_effect_get_int(&compiler->base_effect, parameter, n);
4119 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler *iface,
4120 D3DXHANDLE parameter, const INT *n, UINT count)
4122 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4124 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
4126 return d3dx9_base_effect_set_int_array(&compiler->base_effect, parameter, n, count);
4129 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler *iface,
4130 D3DXHANDLE parameter, INT *n, UINT count)
4132 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4134 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
4136 return d3dx9_base_effect_get_int_array(&compiler->base_effect, parameter, n, count);
4139 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float f)
4141 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4143 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
4145 return d3dx9_base_effect_set_float(&compiler->base_effect, parameter, f);
4148 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float *f)
4150 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4152 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
4154 return d3dx9_base_effect_get_float(&compiler->base_effect, parameter, f);
4157 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler *iface,
4158 D3DXHANDLE parameter, const float *f, UINT count)
4160 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4162 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
4164 return d3dx9_base_effect_set_float_array(&compiler->base_effect, parameter, f, count);
4167 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler *iface,
4168 D3DXHANDLE parameter, float *f, UINT count)
4170 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4172 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
4174 return d3dx9_base_effect_get_float_array(&compiler->base_effect, parameter, f, count);
4177 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler *iface,
4178 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
4180 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4182 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
4184 return d3dx9_base_effect_set_vector(&compiler->base_effect, parameter, vector);
4187 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler *iface,
4188 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
4190 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4192 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
4194 return d3dx9_base_effect_get_vector(&compiler->base_effect, parameter, vector);
4197 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler *iface,
4198 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
4200 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4202 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
4204 return d3dx9_base_effect_set_vector_array(&compiler->base_effect, parameter, vector, count);
4207 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler *iface,
4208 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
4210 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4212 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
4214 return d3dx9_base_effect_get_vector_array(&compiler->base_effect, parameter, vector, count);
4217 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler *iface,
4218 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
4220 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4222 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4224 return d3dx9_base_effect_set_matrix(&compiler->base_effect, parameter, matrix);
4227 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler *iface,
4228 D3DXHANDLE parameter, D3DXMATRIX *matrix)
4230 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4232 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4234 return d3dx9_base_effect_get_matrix(&compiler->base_effect, parameter, matrix);
4237 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler *iface,
4238 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
4240 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4242 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4244 return d3dx9_base_effect_set_matrix_array(&compiler->base_effect, parameter, matrix, count);
4247 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler *iface,
4248 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4250 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4252 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4254 return d3dx9_base_effect_get_matrix_array(&compiler->base_effect, parameter, matrix, count);
4257 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler *iface,
4258 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
4260 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4262 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4264 return d3dx9_base_effect_set_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
4267 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler *iface,
4268 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4270 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4272 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4274 return d3dx9_base_effect_get_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
4277 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler *iface,
4278 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
4280 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4282 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4284 return d3dx9_base_effect_set_matrix_transpose(&compiler->base_effect, parameter, matrix);
4287 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler *iface,
4288 D3DXHANDLE parameter, D3DXMATRIX *matrix)
4290 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4292 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
4294 return d3dx9_base_effect_get_matrix_transpose(&compiler->base_effect, parameter, matrix);
4297 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler *iface,
4298 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
4300 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4302 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4304 return d3dx9_base_effect_set_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
4307 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler *iface,
4308 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4310 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4312 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4314 return d3dx9_base_effect_get_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
4317 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
4318 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
4320 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4322 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4324 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
4327 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
4328 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4330 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4332 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
4334 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
4337 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler *iface,
4338 D3DXHANDLE parameter, const char *string)
4340 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4342 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
4344 return d3dx9_base_effect_set_string(&compiler->base_effect, parameter, string);
4347 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler *iface,
4348 D3DXHANDLE parameter, const char **string)
4350 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4352 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
4354 return d3dx9_base_effect_get_string(&compiler->base_effect, parameter, string);
4357 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetTexture(struct ID3DXEffectCompiler *iface,
4358 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
4360 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4362 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
4364 return d3dx9_base_effect_set_texture(&compiler->base_effect, parameter, texture);
4367 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTexture(struct ID3DXEffectCompiler *iface,
4368 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
4370 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4372 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
4374 return d3dx9_base_effect_get_texture(&compiler->base_effect, parameter, texture);
4377 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler *iface,
4378 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
4380 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4382 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4384 return d3dx9_base_effect_get_pixel_shader(&compiler->base_effect, parameter, shader);
4387 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVertexShader(struct ID3DXEffectCompiler *iface,
4388 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
4390 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4392 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4394 return d3dx9_base_effect_get_vertex_shader(&compiler->base_effect, parameter, shader);
4397 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler *iface,
4398 D3DXHANDLE parameter, UINT start, UINT end)
4400 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4402 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
4404 return d3dx9_base_effect_set_array_range(&compiler->base_effect, parameter, start, end);
4407 /*** ID3DXEffectCompiler methods ***/
4408 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL literal)
4410 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4412 FIXME("iface %p, parameter %p, literal %u\n", This, parameter, literal);
4414 return E_NOTIMPL;
4417 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *literal)
4419 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4421 FIXME("iface %p, parameter %p, literal %p\n", This, parameter, literal);
4423 return E_NOTIMPL;
4426 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler *iface, DWORD flags,
4427 ID3DXBuffer **effect, ID3DXBuffer **error_msgs)
4429 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4431 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub\n", This, flags, effect, error_msgs);
4433 return E_NOTIMPL;
4436 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler *iface, D3DXHANDLE function,
4437 const char *target, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_msgs,
4438 ID3DXConstantTable **constant_table)
4440 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4442 FIXME("iface %p, function %p, target %p, flags %#x, shader %p, error_msgs %p, constant_table %p stub\n",
4443 This, function, target, flags, shader, error_msgs, constant_table);
4445 return E_NOTIMPL;
4448 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
4450 /*** IUnknown methods ***/
4451 ID3DXEffectCompilerImpl_QueryInterface,
4452 ID3DXEffectCompilerImpl_AddRef,
4453 ID3DXEffectCompilerImpl_Release,
4454 /*** ID3DXBaseEffect methods ***/
4455 ID3DXEffectCompilerImpl_GetDesc,
4456 ID3DXEffectCompilerImpl_GetParameterDesc,
4457 ID3DXEffectCompilerImpl_GetTechniqueDesc,
4458 ID3DXEffectCompilerImpl_GetPassDesc,
4459 ID3DXEffectCompilerImpl_GetFunctionDesc,
4460 ID3DXEffectCompilerImpl_GetParameter,
4461 ID3DXEffectCompilerImpl_GetParameterByName,
4462 ID3DXEffectCompilerImpl_GetParameterBySemantic,
4463 ID3DXEffectCompilerImpl_GetParameterElement,
4464 ID3DXEffectCompilerImpl_GetTechnique,
4465 ID3DXEffectCompilerImpl_GetTechniqueByName,
4466 ID3DXEffectCompilerImpl_GetPass,
4467 ID3DXEffectCompilerImpl_GetPassByName,
4468 ID3DXEffectCompilerImpl_GetFunction,
4469 ID3DXEffectCompilerImpl_GetFunctionByName,
4470 ID3DXEffectCompilerImpl_GetAnnotation,
4471 ID3DXEffectCompilerImpl_GetAnnotationByName,
4472 ID3DXEffectCompilerImpl_SetValue,
4473 ID3DXEffectCompilerImpl_GetValue,
4474 ID3DXEffectCompilerImpl_SetBool,
4475 ID3DXEffectCompilerImpl_GetBool,
4476 ID3DXEffectCompilerImpl_SetBoolArray,
4477 ID3DXEffectCompilerImpl_GetBoolArray,
4478 ID3DXEffectCompilerImpl_SetInt,
4479 ID3DXEffectCompilerImpl_GetInt,
4480 ID3DXEffectCompilerImpl_SetIntArray,
4481 ID3DXEffectCompilerImpl_GetIntArray,
4482 ID3DXEffectCompilerImpl_SetFloat,
4483 ID3DXEffectCompilerImpl_GetFloat,
4484 ID3DXEffectCompilerImpl_SetFloatArray,
4485 ID3DXEffectCompilerImpl_GetFloatArray,
4486 ID3DXEffectCompilerImpl_SetVector,
4487 ID3DXEffectCompilerImpl_GetVector,
4488 ID3DXEffectCompilerImpl_SetVectorArray,
4489 ID3DXEffectCompilerImpl_GetVectorArray,
4490 ID3DXEffectCompilerImpl_SetMatrix,
4491 ID3DXEffectCompilerImpl_GetMatrix,
4492 ID3DXEffectCompilerImpl_SetMatrixArray,
4493 ID3DXEffectCompilerImpl_GetMatrixArray,
4494 ID3DXEffectCompilerImpl_SetMatrixPointerArray,
4495 ID3DXEffectCompilerImpl_GetMatrixPointerArray,
4496 ID3DXEffectCompilerImpl_SetMatrixTranspose,
4497 ID3DXEffectCompilerImpl_GetMatrixTranspose,
4498 ID3DXEffectCompilerImpl_SetMatrixTransposeArray,
4499 ID3DXEffectCompilerImpl_GetMatrixTransposeArray,
4500 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray,
4501 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray,
4502 ID3DXEffectCompilerImpl_SetString,
4503 ID3DXEffectCompilerImpl_GetString,
4504 ID3DXEffectCompilerImpl_SetTexture,
4505 ID3DXEffectCompilerImpl_GetTexture,
4506 ID3DXEffectCompilerImpl_GetPixelShader,
4507 ID3DXEffectCompilerImpl_GetVertexShader,
4508 ID3DXEffectCompilerImpl_SetArrayRange,
4509 /*** ID3DXEffectCompiler methods ***/
4510 ID3DXEffectCompilerImpl_SetLiteral,
4511 ID3DXEffectCompilerImpl_GetLiteral,
4512 ID3DXEffectCompilerImpl_CompileEffect,
4513 ID3DXEffectCompilerImpl_CompileShader,
4516 static HRESULT d3dx9_parse_sampler(struct d3dx9_base_effect *base, struct d3dx_sampler *sampler,
4517 const char *data, const char **ptr, struct d3dx_object *objects)
4519 HRESULT hr;
4520 UINT i;
4522 read_dword(ptr, &sampler->state_count);
4523 TRACE("Count: %u\n", sampler->state_count);
4525 sampler->states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler->states) * sampler->state_count);
4526 if (!sampler->states)
4528 ERR("Out of memory\n");
4529 return E_OUTOFMEMORY;
4532 for (i = 0; i < sampler->state_count; ++i)
4534 hr = d3dx9_parse_state(base, &sampler->states[i], data, ptr, objects);
4535 if (hr != D3D_OK)
4537 WARN("Failed to parse state %u\n", i);
4538 goto err_out;
4542 return D3D_OK;
4544 err_out:
4546 for (i = 0; i < sampler->state_count; ++i)
4548 free_state(&sampler->states[i]);
4550 HeapFree(GetProcessHeap(), 0, sampler->states);
4551 sampler->states = NULL;
4553 return hr;
4556 static HRESULT d3dx9_parse_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4557 void *value, const char *data, const char **ptr, struct d3dx_object *objects)
4559 unsigned int i;
4560 HRESULT hr;
4561 UINT old_size = 0;
4563 if (param->element_count)
4565 param->data = value;
4567 for (i = 0; i < param->element_count; ++i)
4569 struct d3dx_parameter *member = &param->members[i];
4571 hr = d3dx9_parse_value(base, member, value ? (char *)value + old_size : NULL, data, ptr, objects);
4572 if (hr != D3D_OK)
4574 WARN("Failed to parse value %u\n", i);
4575 return hr;
4578 old_size += member->bytes;
4581 return D3D_OK;
4584 switch(param->class)
4586 case D3DXPC_SCALAR:
4587 case D3DXPC_VECTOR:
4588 case D3DXPC_MATRIX_ROWS:
4589 case D3DXPC_MATRIX_COLUMNS:
4590 param->data = value;
4591 break;
4593 case D3DXPC_STRUCT:
4594 param->data = value;
4596 for (i = 0; i < param->member_count; ++i)
4598 struct d3dx_parameter *member = &param->members[i];
4600 hr = d3dx9_parse_value(base, member, (char *)value + old_size, data, ptr, objects);
4601 if (hr != D3D_OK)
4603 WARN("Failed to parse value %u\n", i);
4604 return hr;
4607 old_size += member->bytes;
4609 break;
4611 case D3DXPC_OBJECT:
4612 switch (param->type)
4614 case D3DXPT_STRING:
4615 case D3DXPT_TEXTURE:
4616 case D3DXPT_TEXTURE1D:
4617 case D3DXPT_TEXTURE2D:
4618 case D3DXPT_TEXTURE3D:
4619 case D3DXPT_TEXTURECUBE:
4620 case D3DXPT_PIXELSHADER:
4621 case D3DXPT_VERTEXSHADER:
4622 read_dword(ptr, &param->object_id);
4623 TRACE("Id: %u\n", param->object_id);
4624 objects[param->object_id].param = param;
4625 param->data = value;
4626 break;
4628 case D3DXPT_SAMPLER:
4629 case D3DXPT_SAMPLER1D:
4630 case D3DXPT_SAMPLER2D:
4631 case D3DXPT_SAMPLER3D:
4632 case D3DXPT_SAMPLERCUBE:
4634 struct d3dx_sampler *sampler;
4636 sampler = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler));
4637 if (!sampler)
4638 return E_OUTOFMEMORY;
4640 hr = d3dx9_parse_sampler(base, sampler, data, ptr, objects);
4641 if (hr != D3D_OK)
4643 HeapFree(GetProcessHeap(), 0, sampler);
4644 WARN("Failed to parse sampler\n");
4645 return hr;
4648 param->data = sampler;
4649 break;
4652 default:
4653 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4654 break;
4656 break;
4658 default:
4659 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4660 break;
4663 return D3D_OK;
4666 static HRESULT d3dx9_parse_init_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4667 const char *data, const char *ptr, struct d3dx_object *objects)
4669 UINT size = param->bytes;
4670 HRESULT hr;
4671 void *value = NULL;
4673 TRACE("param size: %u\n", size);
4675 if (size)
4677 value = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4678 if (!value)
4680 ERR("Failed to allocate data memory.\n");
4681 return E_OUTOFMEMORY;
4684 switch(param->class)
4686 case D3DXPC_OBJECT:
4687 break;
4689 case D3DXPC_SCALAR:
4690 case D3DXPC_VECTOR:
4691 case D3DXPC_MATRIX_ROWS:
4692 case D3DXPC_MATRIX_COLUMNS:
4693 case D3DXPC_STRUCT:
4694 TRACE("Data: %s.\n", debugstr_an(ptr, size));
4695 memcpy(value, ptr, size);
4696 break;
4698 default:
4699 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4700 break;
4704 hr = d3dx9_parse_value(base, param, value, data, &ptr, objects);
4705 if (hr != D3D_OK)
4707 WARN("Failed to parse value\n");
4708 HeapFree(GetProcessHeap(), 0, value);
4709 return hr;
4712 return D3D_OK;
4715 static HRESULT d3dx9_parse_name(char **name, const char *ptr)
4717 DWORD size;
4719 read_dword(&ptr, &size);
4720 TRACE("Name size: %#x\n", size);
4722 if (!size)
4724 return D3D_OK;
4727 *name = HeapAlloc(GetProcessHeap(), 0, size);
4728 if (!*name)
4730 ERR("Failed to allocate name memory.\n");
4731 return E_OUTOFMEMORY;
4734 TRACE("Name: %s.\n", debugstr_an(ptr, size));
4735 memcpy(*name, ptr, size);
4737 return D3D_OK;
4740 static HRESULT d3dx9_copy_data(struct d3dx_object *object, const char **ptr)
4742 if (object->size || object->data)
4743 FIXME("Object already initialized!\n");
4745 read_dword(ptr, &object->size);
4746 TRACE("Data size: %#x\n", object->size);
4748 if (!object->size)
4749 return D3D_OK;
4751 object->data = HeapAlloc(GetProcessHeap(), 0, object->size);
4752 if (!object->data)
4754 ERR("Failed to allocate object memory.\n");
4755 return E_OUTOFMEMORY;
4758 TRACE("Data: %s.\n", debugstr_an(*ptr, object->size));
4759 memcpy(object->data, *ptr, object->size);
4761 *ptr += ((object->size + 3) & ~3);
4763 return D3D_OK;
4766 static void add_param_to_table(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
4768 struct param_table *table = &base->param_table;
4770 if (table->count >= table->size)
4772 unsigned int new_size;
4773 struct d3dx_parameter **new_alloc;
4775 if (!table->size)
4777 new_size = INITIAL_PARAM_TABLE_SIZE;
4778 new_alloc = HeapAlloc(GetProcessHeap(), 0, sizeof(*table->table) * new_size);
4779 if (!new_alloc)
4781 ERR("Out of memory.\n");
4782 return;
4785 else
4787 new_size = table->size * 2;
4788 new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * new_size);
4789 if (!new_alloc)
4791 ERR("Out of memory.\n");
4792 return;
4795 table->table = new_alloc;
4796 table->size = new_size;
4799 table->table[table->count++] = param;
4802 static void sync_param_handles(struct d3dx9_base_effect *base)
4804 struct param_table *table = &base->param_table;
4805 struct d3dx_parameter **new_alloc;
4806 unsigned int i;
4808 if (table->count)
4810 new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * table->count);
4811 if (new_alloc)
4812 table->table = new_alloc;
4813 else
4814 ERR("Out of memory.\n");
4817 for (i = 0; i < table->count; ++i)
4818 table->table[i]->handle = (D3DXHANDLE)&table->table[i];
4821 static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4822 const char *data, const char **ptr, struct d3dx_parameter *parent, UINT flags)
4824 DWORD offset;
4825 HRESULT hr;
4826 UINT i;
4828 param->flags = flags;
4830 if (!parent)
4832 read_dword(ptr, (DWORD *)&param->type);
4833 TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
4835 read_dword(ptr, (DWORD *)&param->class);
4836 TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
4838 read_dword(ptr, &offset);
4839 TRACE("Type name offset: %#x\n", offset);
4840 hr = d3dx9_parse_name(&param->name, data + offset);
4841 if (hr != D3D_OK)
4843 WARN("Failed to parse name\n");
4844 goto err_out;
4847 read_dword(ptr, &offset);
4848 TRACE("Type semantic offset: %#x\n", offset);
4849 hr = d3dx9_parse_name(&param->semantic, data + offset);
4850 if (hr != D3D_OK)
4852 WARN("Failed to parse semantic\n");
4853 goto err_out;
4856 read_dword(ptr, &param->element_count);
4857 TRACE("Elements: %u\n", param->element_count);
4859 switch (param->class)
4861 case D3DXPC_VECTOR:
4862 read_dword(ptr, &param->columns);
4863 TRACE("Columns: %u\n", param->columns);
4865 read_dword(ptr, &param->rows);
4866 TRACE("Rows: %u\n", param->rows);
4868 /* sizeof(DWORD) * rows * columns */
4869 param->bytes = 4 * param->rows * param->columns;
4870 break;
4872 case D3DXPC_SCALAR:
4873 case D3DXPC_MATRIX_ROWS:
4874 case D3DXPC_MATRIX_COLUMNS:
4875 read_dword(ptr, &param->rows);
4876 TRACE("Rows: %u\n", param->rows);
4878 read_dword(ptr, &param->columns);
4879 TRACE("Columns: %u\n", param->columns);
4881 /* sizeof(DWORD) * rows * columns */
4882 param->bytes = 4 * param->rows * param->columns;
4883 break;
4885 case D3DXPC_STRUCT:
4886 read_dword(ptr, &param->member_count);
4887 TRACE("Members: %u\n", param->member_count);
4888 break;
4890 case D3DXPC_OBJECT:
4891 switch (param->type)
4893 case D3DXPT_STRING:
4894 case D3DXPT_PIXELSHADER:
4895 case D3DXPT_VERTEXSHADER:
4896 case D3DXPT_TEXTURE:
4897 case D3DXPT_TEXTURE1D:
4898 case D3DXPT_TEXTURE2D:
4899 case D3DXPT_TEXTURE3D:
4900 case D3DXPT_TEXTURECUBE:
4901 param->bytes = sizeof(void *);
4902 break;
4904 case D3DXPT_SAMPLER:
4905 case D3DXPT_SAMPLER1D:
4906 case D3DXPT_SAMPLER2D:
4907 case D3DXPT_SAMPLER3D:
4908 case D3DXPT_SAMPLERCUBE:
4909 param->bytes = 0;
4910 break;
4912 default:
4913 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4914 break;
4916 break;
4918 default:
4919 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4920 break;
4923 else
4925 /* elements */
4926 param->type = parent->type;
4927 param->class = parent->class;
4928 param->name = parent->name;
4929 param->semantic = parent->semantic;
4930 param->element_count = 0;
4931 param->annotation_count = 0;
4932 param->member_count = parent->member_count;
4933 param->bytes = parent->bytes;
4934 param->rows = parent->rows;
4935 param->columns = parent->columns;
4938 if (param->element_count)
4940 unsigned int param_bytes = 0;
4941 const char *save_ptr = *ptr;
4943 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->element_count);
4944 if (!param->members)
4946 ERR("Out of memory\n");
4947 hr = E_OUTOFMEMORY;
4948 goto err_out;
4951 for (i = 0; i < param->element_count; ++i)
4953 *ptr = save_ptr;
4955 add_param_to_table(base, &param->members[i]);
4956 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, param, flags);
4957 if (hr != D3D_OK)
4959 WARN("Failed to parse member %u\n", i);
4960 goto err_out;
4963 param_bytes += param->members[i].bytes;
4966 param->bytes = param_bytes;
4968 else if (param->member_count)
4970 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->member_count);
4971 if (!param->members)
4973 ERR("Out of memory\n");
4974 hr = E_OUTOFMEMORY;
4975 goto err_out;
4978 for (i = 0; i < param->member_count; ++i)
4980 add_param_to_table(base, &param->members[i]);
4981 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, NULL, flags);
4982 if (hr != D3D_OK)
4984 WARN("Failed to parse member %u\n", i);
4985 goto err_out;
4988 param->bytes += param->members[i].bytes;
4991 return D3D_OK;
4993 err_out:
4995 if (param->members)
4997 unsigned int count = param->element_count ? param->element_count : param->member_count;
4999 for (i = 0; i < count; ++i)
5000 free_parameter(&param->members[i], param->element_count != 0, TRUE);
5001 HeapFree(GetProcessHeap(), 0, param->members);
5002 param->members = NULL;
5005 if (!parent)
5007 HeapFree(GetProcessHeap(), 0, param->name);
5008 HeapFree(GetProcessHeap(), 0, param->semantic);
5010 param->name = NULL;
5011 param->semantic = NULL;
5013 return hr;
5016 static HRESULT d3dx9_parse_effect_annotation(struct d3dx9_base_effect *base, struct d3dx_parameter *anno,
5017 const char *data, const char **ptr, struct d3dx_object *objects)
5019 DWORD offset;
5020 const char *ptr2;
5021 HRESULT hr;
5023 anno->flags = D3DX_PARAMETER_ANNOTATION;
5025 read_dword(ptr, &offset);
5026 TRACE("Typedef offset: %#x\n", offset);
5027 ptr2 = data + offset;
5028 hr = d3dx9_parse_effect_typedef(base, anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
5029 if (hr != D3D_OK)
5031 WARN("Failed to parse type definition\n");
5032 return hr;
5035 read_dword(ptr, &offset);
5036 TRACE("Value offset: %#x\n", offset);
5037 hr = d3dx9_parse_init_value(base, anno, data, data + offset, objects);
5038 if (hr != D3D_OK)
5040 WARN("Failed to parse value\n");
5041 return hr;
5044 return D3D_OK;
5047 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
5048 const char *data, const char **ptr, struct d3dx_object *objects)
5050 DWORD offset;
5051 const char *ptr2;
5052 HRESULT hr;
5054 state->type = ST_CONSTANT;
5056 read_dword(ptr, &state->operation);
5057 TRACE("Operation: %#x (%s)\n", state->operation, state_table[state->operation].name);
5059 read_dword(ptr, &state->index);
5060 TRACE("Index: %#x\n", state->index);
5062 read_dword(ptr, &offset);
5063 TRACE("Typedef offset: %#x\n", offset);
5064 ptr2 = data + offset;
5065 hr = d3dx9_parse_effect_typedef(base, &state->parameter, data, &ptr2, NULL, 0);
5066 if (hr != D3D_OK)
5068 WARN("Failed to parse type definition\n");
5069 goto err_out;
5072 read_dword(ptr, &offset);
5073 TRACE("Value offset: %#x\n", offset);
5074 hr = d3dx9_parse_init_value(base, &state->parameter, data, data + offset, objects);
5075 if (hr != D3D_OK)
5077 WARN("Failed to parse value\n");
5078 goto err_out;
5081 return D3D_OK;
5083 err_out:
5085 free_parameter(&state->parameter, FALSE, FALSE);
5087 return hr;
5090 static HRESULT d3dx9_parse_effect_parameter(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
5091 const char *data, const char **ptr, struct d3dx_object *objects)
5093 DWORD offset;
5094 HRESULT hr;
5095 unsigned int i;
5096 const char *ptr2;
5098 read_dword(ptr, &offset);
5099 TRACE("Typedef offset: %#x\n", offset);
5100 ptr2 = data + offset;
5102 read_dword(ptr, &offset);
5103 TRACE("Value offset: %#x\n", offset);
5105 read_dword(ptr, &param->flags);
5106 TRACE("Flags: %#x\n", param->flags);
5108 read_dword(ptr, &param->annotation_count);
5109 TRACE("Annotation count: %u\n", param->annotation_count);
5111 hr = d3dx9_parse_effect_typedef(base, param, data, &ptr2, NULL, param->flags);
5112 if (hr != D3D_OK)
5114 WARN("Failed to parse type definition\n");
5115 return hr;
5118 hr = d3dx9_parse_init_value(base, param, data, data + offset, objects);
5119 if (hr != D3D_OK)
5121 WARN("Failed to parse value\n");
5122 return hr;
5125 if (param->annotation_count)
5127 param->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5128 sizeof(*param->annotations) * param->annotation_count);
5129 if (!param->annotations)
5131 ERR("Out of memory\n");
5132 hr = E_OUTOFMEMORY;
5133 goto err_out;
5136 for (i = 0; i < param->annotation_count; ++i)
5138 add_param_to_table(base, &param->annotations[i]);
5139 hr = d3dx9_parse_effect_annotation(base, &param->annotations[i], data, ptr, objects);
5140 if (hr != D3D_OK)
5142 WARN("Failed to parse annotation\n");
5143 goto err_out;
5148 return D3D_OK;
5150 err_out:
5152 if (param->annotations)
5154 for (i = 0; i < param->annotation_count; ++i)
5155 free_parameter(&param->annotations[i], FALSE, FALSE);
5156 HeapFree(GetProcessHeap(), 0, param->annotations);
5157 param->annotations = NULL;
5160 return hr;
5163 static HRESULT d3dx9_parse_effect_pass(struct d3dx9_base_effect *base, struct d3dx_pass *pass,
5164 const char *data, const char **ptr, struct d3dx_object *objects)
5166 DWORD offset;
5167 HRESULT hr;
5168 unsigned int i;
5169 struct d3dx_state *states = NULL;
5170 char *name = NULL;
5172 read_dword(ptr, &offset);
5173 TRACE("Pass name offset: %#x\n", offset);
5174 hr = d3dx9_parse_name(&name, data + offset);
5175 if (hr != D3D_OK)
5177 WARN("Failed to parse name\n");
5178 goto err_out;
5181 read_dword(ptr, &pass->annotation_count);
5182 TRACE("Annotation count: %u\n", pass->annotation_count);
5184 read_dword(ptr, &pass->state_count);
5185 TRACE("State count: %u\n", pass->state_count);
5187 if (pass->annotation_count)
5189 pass->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5190 sizeof(*pass->annotations) * pass->annotation_count);
5191 if (!pass->annotations)
5193 ERR("Out of memory\n");
5194 hr = E_OUTOFMEMORY;
5195 goto err_out;
5198 for (i = 0; i < pass->annotation_count; ++i)
5200 add_param_to_table(base, &pass->annotations[i]);
5201 hr = d3dx9_parse_effect_annotation(base, &pass->annotations[i], data, ptr, objects);
5202 if (hr != D3D_OK)
5204 WARN("Failed to parse annotation %u\n", i);
5205 goto err_out;
5210 if (pass->state_count)
5212 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * pass->state_count);
5213 if (!states)
5215 ERR("Out of memory\n");
5216 hr = E_OUTOFMEMORY;
5217 goto err_out;
5220 for (i = 0; i < pass->state_count; ++i)
5222 hr = d3dx9_parse_state(base, &states[i], data, ptr, objects);
5223 if (hr != D3D_OK)
5225 WARN("Failed to parse annotation %u\n", i);
5226 goto err_out;
5231 pass->name = name;
5232 pass->states = states;
5234 return D3D_OK;
5236 err_out:
5238 if (pass->annotations)
5240 for (i = 0; i < pass->annotation_count; ++i)
5241 free_parameter(&pass->annotations[i], FALSE, FALSE);
5242 HeapFree(GetProcessHeap(), 0, pass->annotations);
5243 pass->annotations = NULL;
5246 if (states)
5248 for (i = 0; i < pass->state_count; ++i)
5250 free_state(&states[i]);
5252 HeapFree(GetProcessHeap(), 0, states);
5255 HeapFree(GetProcessHeap(), 0, name);
5257 return hr;
5260 static HRESULT d3dx9_parse_effect_technique(struct d3dx9_base_effect *base, struct d3dx_technique *technique,
5261 const char *data, const char **ptr, struct d3dx_object *objects)
5263 DWORD offset;
5264 HRESULT hr;
5265 unsigned int i;
5266 char *name = NULL;
5268 read_dword(ptr, &offset);
5269 TRACE("Technique name offset: %#x\n", offset);
5270 hr = d3dx9_parse_name(&name, data + offset);
5271 if (hr != D3D_OK)
5273 WARN("Failed to parse name\n");
5274 goto err_out;
5277 read_dword(ptr, &technique->annotation_count);
5278 TRACE("Annotation count: %u\n", technique->annotation_count);
5280 read_dword(ptr, &technique->pass_count);
5281 TRACE("Pass count: %u\n", technique->pass_count);
5283 if (technique->annotation_count)
5285 technique->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5286 sizeof(*technique->annotations) * technique->annotation_count);
5287 if (!technique->annotations)
5289 ERR("Out of memory\n");
5290 hr = E_OUTOFMEMORY;
5291 goto err_out;
5294 for (i = 0; i < technique->annotation_count; ++i)
5296 add_param_to_table(base, &technique->annotations[i]);
5297 hr = d3dx9_parse_effect_annotation(base, &technique->annotations[i], data, ptr, objects);
5298 if (hr != D3D_OK)
5300 WARN("Failed to parse annotation %u\n", i);
5301 goto err_out;
5306 if (technique->pass_count)
5308 technique->passes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5309 sizeof(*technique->passes) * technique->pass_count);
5310 if (!technique->passes)
5312 ERR("Out of memory\n");
5313 hr = E_OUTOFMEMORY;
5314 goto err_out;
5317 for (i = 0; i < technique->pass_count; ++i)
5319 hr = d3dx9_parse_effect_pass(base, &technique->passes[i], data, ptr, objects);
5320 if (hr != D3D_OK)
5322 WARN("Failed to parse pass %u\n", i);
5323 goto err_out;
5328 technique->name = name;
5330 return D3D_OK;
5332 err_out:
5334 if (technique->passes)
5336 for (i = 0; i < technique->pass_count; ++i)
5337 free_pass(&technique->passes[i]);
5338 HeapFree(GetProcessHeap(), 0, technique->passes);
5339 technique->passes = NULL;
5342 if (technique->annotations)
5344 for (i = 0; i < technique->annotation_count; ++i)
5345 free_parameter(&technique->annotations[i], FALSE, FALSE);
5346 HeapFree(GetProcessHeap(), 0, technique->annotations);
5347 technique->annotations = NULL;
5350 HeapFree(GetProcessHeap(), 0, name);
5352 return hr;
5355 static HRESULT d3dx9_create_object(struct d3dx9_base_effect *base, struct d3dx_object *object)
5357 struct d3dx_parameter *param = object->param;
5358 struct IDirect3DDevice9 *device = base->effect->device;
5359 HRESULT hr;
5361 if (*(char **)param->data)
5362 ERR("Parameter data already allocated.\n");
5364 switch (param->type)
5366 case D3DXPT_STRING:
5367 *(char **)param->data = HeapAlloc(GetProcessHeap(), 0, object->size);
5368 if (!*(char **)param->data)
5370 ERR("Out of memory.\n");
5371 return E_OUTOFMEMORY;
5373 memcpy(*(char **)param->data, object->data, object->size);
5374 break;
5375 case D3DXPT_VERTEXSHADER:
5376 if (FAILED(hr = IDirect3DDevice9_CreateVertexShader(device, object->data,
5377 (IDirect3DVertexShader9 **)param->data)))
5379 WARN("Failed to create vertex shader.\n");
5380 return hr;
5382 break;
5383 case D3DXPT_PIXELSHADER:
5384 if (FAILED(hr = IDirect3DDevice9_CreatePixelShader(device, object->data,
5385 (IDirect3DPixelShader9 **)param->data)))
5387 WARN("Failed to create pixel shader.\n");
5388 return hr;
5390 break;
5391 default:
5392 break;
5394 return D3D_OK;
5397 static HRESULT d3dx9_parse_array_selector(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
5399 DWORD string_size;
5400 struct d3dx_object *object = &base->objects[param->object_id];
5401 char *ptr = object->data;
5402 HRESULT ret;
5404 TRACE("Parsing array entry selection state for parameter %p.\n", param);
5406 string_size = *(DWORD *)ptr;
5407 param->referenced_param = get_parameter_by_name(base, NULL, ptr + 4);
5408 if (param->referenced_param)
5410 TRACE("Mapping to parameter %s.\n", debugstr_a(param->referenced_param->name));
5412 else
5414 FIXME("Referenced parameter %s not found.\n", ptr + 4);
5415 return D3DXERR_INVALIDDATA;
5417 TRACE("Unknown DWORD: 0x%.8x.\n", *(DWORD *)(ptr + string_size));
5419 if (string_size % sizeof(DWORD))
5420 FIXME("Unaligned string_size %u.\n", string_size);
5421 d3dx_create_param_eval(base, (DWORD *)(ptr + string_size) + 1, object->size - (string_size + sizeof(DWORD)),
5422 D3DXPT_INT, &param->param_eval);
5423 ret = D3D_OK;
5424 param = param->referenced_param;
5425 if (param->type == D3DXPT_VERTEXSHADER || param->type == D3DXPT_PIXELSHADER)
5427 unsigned int i;
5429 for (i = 0; i < param->element_count; i++)
5431 if (param->members[i].type != param->type)
5433 FIXME("Unexpected member parameter type %u, expected %u.\n", param->members[i].type, param->type);
5434 return D3DXERR_INVALIDDATA;
5436 if (!param->members[i].param_eval)
5438 TRACE("Creating preshader for object %u.\n", param->members[i].object_id);
5439 object = &base->objects[param->members[i].object_id];
5440 d3dx_create_param_eval(base, object->data, object->size, param->type, &param->members[i].param_eval);
5444 return ret;
5447 static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *data, const char **ptr)
5449 DWORD technique_index;
5450 DWORD index, state_index, usage, element_index;
5451 struct d3dx_state *state;
5452 struct d3dx_parameter *param;
5453 struct d3dx_object *object;
5454 HRESULT hr = E_FAIL;
5456 read_dword(ptr, &technique_index);
5457 TRACE("technique_index: %u\n", technique_index);
5459 read_dword(ptr, &index);
5460 TRACE("index: %u\n", index);
5462 read_dword(ptr, &element_index);
5463 TRACE("element_index: %u\n", element_index);
5465 read_dword(ptr, &state_index);
5466 TRACE("state_index: %u\n", state_index);
5468 read_dword(ptr, &usage);
5469 TRACE("usage: %u\n", usage);
5471 if (technique_index == 0xffffffff)
5473 struct d3dx_parameter *parameter;
5474 struct d3dx_sampler *sampler;
5476 if (index >= base->parameter_count)
5478 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index, base->parameter_count);
5479 return E_FAIL;
5482 parameter = &base->parameters[index];
5483 if (element_index != 0xffffffff)
5485 if (element_index >= parameter->element_count && parameter->element_count != 0)
5487 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index, parameter->element_count);
5488 return E_FAIL;
5491 if (parameter->element_count != 0) parameter = &parameter->members[element_index];
5494 sampler = parameter->data;
5495 if (state_index >= sampler->state_count)
5497 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, sampler->state_count);
5498 return E_FAIL;
5501 state = &sampler->states[state_index];
5503 else
5505 struct d3dx_technique *technique;
5506 struct d3dx_pass *pass;
5508 if (technique_index >= base->technique_count)
5510 FIXME("Index out of bounds: technique_index %u >= technique_count %u\n", technique_index, base->technique_count);
5511 return E_FAIL;
5514 technique = &base->techniques[technique_index];
5515 if (index >= technique->pass_count)
5517 FIXME("Index out of bounds: index %u >= pass_count %u\n", index, technique->pass_count);
5518 return E_FAIL;
5521 pass = &technique->passes[index];
5522 if (state_index >= pass->state_count)
5524 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, pass->state_count);
5525 return E_FAIL;
5528 state = &pass->states[state_index];
5531 TRACE("State operation %#x (%s).\n", state->operation, state_table[state->operation].name);
5532 param = &state->parameter;
5533 TRACE("Using object id %u.\n", param->object_id);
5534 object = &base->objects[param->object_id];
5536 TRACE("Usage %u: class %s, type %s.\n", usage, debug_d3dxparameter_class(param->class),
5537 debug_d3dxparameter_type(param->type));
5538 switch (usage)
5540 case 0:
5541 switch (param->type)
5543 case D3DXPT_VERTEXSHADER:
5544 case D3DXPT_PIXELSHADER:
5545 state->type = ST_CONSTANT;
5546 if (FAILED(hr = d3dx9_copy_data(&base->objects[param->object_id], ptr)))
5547 return hr;
5549 if (object->data)
5551 if (FAILED(hr = d3dx9_create_object(base, object)))
5552 return hr;
5553 d3dx_create_param_eval(base, object->data, object->size, param->type, &param->param_eval);
5555 break;
5557 case D3DXPT_BOOL:
5558 case D3DXPT_INT:
5559 case D3DXPT_FLOAT:
5560 case D3DXPT_STRING:
5561 state->type = ST_FXLC;
5562 if (FAILED(hr = d3dx9_copy_data(&base->objects[param->object_id], ptr)))
5563 return hr;
5564 d3dx_create_param_eval(base, object->data, object->size, param->type, &param->param_eval);
5565 break;
5567 default:
5568 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5569 break;
5571 break;
5573 case 1:
5574 state->type = ST_PARAMETER;
5575 if (FAILED(hr = d3dx9_copy_data(&base->objects[param->object_id], ptr)))
5576 return hr;
5578 TRACE("Looking for parameter %s.\n", debugstr_a(object->data));
5579 param->referenced_param = get_parameter_by_name(base, NULL, object->data);
5580 if (param->referenced_param)
5582 struct d3dx_parameter *refpar = param->referenced_param;
5584 TRACE("Mapping to parameter %p, having object id %u.\n", refpar, refpar->object_id);
5585 if (refpar->type == D3DXPT_VERTEXSHADER || refpar->type == D3DXPT_PIXELSHADER)
5587 struct d3dx_object *refobj = &base->objects[refpar->object_id];
5589 if (!refpar->param_eval)
5590 d3dx_create_param_eval(base, refobj->data, refobj->size,
5591 refpar->type, &refpar->param_eval);
5594 else
5596 FIXME("Referenced parameter %s not found.\n", (char *)object->data);
5597 return D3DXERR_INVALIDDATA;
5599 break;
5601 case 2:
5602 state->type = ST_ARRAY_SELECTOR;
5603 if (FAILED(hr = d3dx9_copy_data(object, ptr)))
5604 return hr;
5605 hr = d3dx9_parse_array_selector(base, param);
5606 break;
5608 default:
5609 FIXME("Unknown usage %x\n", usage);
5610 break;
5613 return hr;
5616 static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *data, UINT data_size, DWORD start)
5618 const char *ptr = data + start;
5619 UINT stringcount, resourcecount;
5620 HRESULT hr;
5621 UINT i;
5623 read_dword(&ptr, &base->parameter_count);
5624 TRACE("Parameter count: %u\n", base->parameter_count);
5626 read_dword(&ptr, &base->technique_count);
5627 TRACE("Technique count: %u\n", base->technique_count);
5629 skip_dword_unknown(&ptr, 1);
5631 read_dword(&ptr, &base->object_count);
5632 TRACE("Object count: %u\n", base->object_count);
5634 base->objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*base->objects) * base->object_count);
5635 if (!base->objects)
5637 ERR("Out of memory\n");
5638 hr = E_OUTOFMEMORY;
5639 goto err_out;
5642 if (base->parameter_count)
5644 base->parameters = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5645 sizeof(*base->parameters) * base->parameter_count);
5646 if (!base->parameters)
5648 ERR("Out of memory\n");
5649 hr = E_OUTOFMEMORY;
5650 goto err_out;
5653 for (i = 0; i < base->parameter_count; ++i)
5655 add_param_to_table(base, &base->parameters[i]);
5656 hr = d3dx9_parse_effect_parameter(base, &base->parameters[i], data, &ptr, base->objects);
5657 if (hr != D3D_OK)
5659 WARN("Failed to parse parameter %u\n", i);
5660 goto err_out;
5665 if (base->technique_count)
5667 base->techniques = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5668 sizeof(*base->techniques) * base->technique_count);
5669 if (!base->techniques)
5671 ERR("Out of memory\n");
5672 hr = E_OUTOFMEMORY;
5673 goto err_out;
5676 for (i = 0; i < base->technique_count; ++i)
5678 TRACE("Parsing technique %u.\n", i);
5679 hr = d3dx9_parse_effect_technique(base, &base->techniques[i], data, &ptr, base->objects);
5680 if (hr != D3D_OK)
5682 WARN("Failed to parse technique %u\n", i);
5683 goto err_out;
5688 sync_param_handles(base);
5690 read_dword(&ptr, &stringcount);
5691 TRACE("String count: %u\n", stringcount);
5693 read_dword(&ptr, &resourcecount);
5694 TRACE("Resource count: %u\n", resourcecount);
5696 for (i = 0; i < stringcount; ++i)
5698 DWORD id;
5700 read_dword(&ptr, &id);
5701 TRACE("Id: %u\n", id);
5703 if (FAILED(hr = d3dx9_copy_data(&base->objects[id], &ptr)))
5704 goto err_out;
5706 if (base->objects[id].data)
5708 if (FAILED(hr = d3dx9_create_object(base, &base->objects[id])))
5709 goto err_out;
5713 for (i = 0; i < resourcecount; ++i)
5715 TRACE("parse resource %u\n", i);
5717 hr = d3dx9_parse_resource(base, data, &ptr);
5718 if (hr != D3D_OK)
5720 WARN("Failed to parse resource %u\n", i);
5721 goto err_out;
5725 return D3D_OK;
5727 err_out:
5729 if (base->techniques)
5731 for (i = 0; i < base->technique_count; ++i)
5732 free_technique(&base->techniques[i]);
5733 HeapFree(GetProcessHeap(), 0, base->techniques);
5734 base->techniques = NULL;
5737 if (base->parameters)
5739 for (i = 0; i < base->parameter_count; ++i)
5741 free_parameter(&base->parameters[i], FALSE, FALSE);
5743 HeapFree(GetProcessHeap(), 0, base->parameters);
5744 base->parameters = NULL;
5747 if (base->objects)
5749 for (i = 0; i < base->object_count; ++i)
5751 free_object(&base->objects[i]);
5753 HeapFree(GetProcessHeap(), 0, base->objects);
5754 base->objects = NULL;
5757 return hr;
5760 static HRESULT d3dx9_base_effect_init(struct d3dx9_base_effect *base,
5761 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
5762 UINT eflags, ID3DBlob **errors, struct ID3DXEffectImpl *effect)
5764 DWORD tag, offset;
5765 const char *ptr = data;
5766 HRESULT hr;
5767 ID3DBlob *bytecode = NULL, *temp_errors = NULL;
5769 TRACE("base %p, data %p, data_size %lu, effect %p\n", base, data, data_size, effect);
5771 base->effect = effect;
5773 read_dword(&ptr, &tag);
5774 TRACE("Tag: %x\n", tag);
5776 if (tag != d3dx9_effect_version(9, 1))
5778 TRACE("HLSL ASCII effect, trying to compile it.\n");
5779 hr = D3DCompile(data, data_size, NULL, defines, include,
5780 "main", "fx_2_0", 0, eflags, &bytecode, &temp_errors);
5781 if (FAILED(hr))
5783 WARN("Failed to compile ASCII effect.\n");
5784 if (bytecode)
5785 ID3D10Blob_Release(bytecode);
5786 if (temp_errors)
5787 TRACE("%s\n", (char *)ID3D10Blob_GetBufferPointer(temp_errors));
5788 if (errors)
5789 *errors = temp_errors;
5790 else if (temp_errors)
5791 ID3D10Blob_Release(temp_errors);
5792 return hr;
5794 if (!bytecode)
5796 FIXME("No output from effect compilation.\n");
5797 return D3DERR_INVALIDCALL;
5799 if (errors)
5800 *errors = temp_errors;
5801 else if (temp_errors)
5802 ID3D10Blob_Release(temp_errors);
5804 ptr = ID3D10Blob_GetBufferPointer(bytecode);
5805 read_dword(&ptr, &tag);
5806 TRACE("Tag: %x\n", tag);
5809 read_dword(&ptr, &offset);
5810 TRACE("Offset: %x\n", offset);
5812 hr = d3dx9_parse_effect(base, ptr, data_size, offset);
5813 if (bytecode)
5814 ID3D10Blob_Release(bytecode);
5815 if (hr != D3D_OK)
5817 FIXME("Failed to parse effect.\n");
5818 return hr;
5821 return D3D_OK;
5824 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, struct IDirect3DDevice9 *device,
5825 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
5826 UINT eflags, ID3DBlob **error_messages, struct ID3DXEffectPool *pool)
5828 HRESULT hr;
5830 TRACE("effect %p, device %p, data %p, data_size %lu, pool %p\n", effect, device, data, data_size, pool);
5832 effect->ID3DXEffect_iface.lpVtbl = &ID3DXEffect_Vtbl;
5833 effect->ref = 1;
5835 if (pool) pool->lpVtbl->AddRef(pool);
5836 effect->pool = pool;
5838 IDirect3DDevice9_AddRef(device);
5839 effect->device = device;
5841 if (FAILED(hr = d3dx9_base_effect_init(&effect->base_effect, data, data_size, defines, include,
5842 eflags, error_messages, effect)))
5844 FIXME("Failed to parse effect, hr %#x.\n", hr);
5845 free_effect(effect);
5846 return hr;
5849 /* initialize defaults - check because of unsupported ascii effects */
5850 if (effect->base_effect.techniques)
5852 effect->active_technique = &effect->base_effect.techniques[0];
5853 effect->active_pass = NULL;
5856 return D3D_OK;
5859 HRESULT WINAPI D3DXCreateEffectEx(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
5860 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skip_constants, DWORD flags,
5861 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
5863 struct ID3DXEffectImpl *object;
5864 HRESULT hr;
5866 TRACE("device %p, srcdata %p, srcdatalen %u, defines %p, include %p,"
5867 " skip_constants %p, flags %#x, pool %p, effect %p, compilation_errors %p.\n",
5868 device, srcdata, srcdatalen, defines, include,
5869 skip_constants, flags, pool, effect, compilation_errors);
5871 if (compilation_errors)
5872 *compilation_errors = NULL;
5874 if (!device || !srcdata)
5875 return D3DERR_INVALIDCALL;
5877 if (!srcdatalen)
5878 return E_FAIL;
5880 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
5881 if (!effect)
5882 return D3D_OK;
5884 if (skip_constants)
5885 FIXME("skip_constants is not NULL, not supported yet.\n");
5887 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5888 if (!object)
5889 return E_OUTOFMEMORY;
5891 hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
5892 (ID3DInclude *)include, flags, (ID3DBlob **)compilation_errors, pool);
5893 if (FAILED(hr))
5895 WARN("Failed to create effect object.\n");
5896 HeapFree(GetProcessHeap(), 0, object);
5897 return hr;
5900 *effect = &object->ID3DXEffect_iface;
5902 TRACE("Created ID3DXEffect %p\n", object);
5904 return D3D_OK;
5907 HRESULT WINAPI D3DXCreateEffect(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
5908 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
5909 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
5911 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device, srcdata, srcdatalen, defines,
5912 include, flags, pool, effect, compilation_errors);
5914 return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
5917 static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler,
5918 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
5919 UINT eflags, ID3DBlob **error_messages)
5921 HRESULT hr;
5923 TRACE("effect %p, data %p, data_size %lu\n", compiler, data, data_size);
5925 compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
5926 compiler->ref = 1;
5928 if (FAILED(hr = d3dx9_base_effect_init(&compiler->base_effect, data, data_size, defines,
5929 include, eflags, error_messages, NULL)))
5931 FIXME("Failed to parse effect, hr %#x.\n", hr);
5932 free_effect_compiler(compiler);
5933 return hr;
5936 return D3D_OK;
5939 HRESULT WINAPI D3DXCreateEffectCompiler(const char *srcdata, UINT srcdatalen, const D3DXMACRO *defines,
5940 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **compiler, ID3DXBuffer **parse_errors)
5942 struct ID3DXEffectCompilerImpl *object;
5943 HRESULT hr;
5945 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
5946 srcdata, srcdatalen, defines, include, flags, compiler, parse_errors);
5948 if (!srcdata || !compiler)
5950 WARN("Invalid arguments supplied\n");
5951 return D3DERR_INVALIDCALL;
5954 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5955 if (!object)
5956 return E_OUTOFMEMORY;
5958 hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
5959 (ID3DInclude *)include, flags, (ID3DBlob **)parse_errors);
5960 if (FAILED(hr))
5962 WARN("Failed to initialize effect compiler\n");
5963 HeapFree(GetProcessHeap(), 0, object);
5964 return hr;
5967 *compiler = &object->ID3DXEffectCompiler_iface;
5969 TRACE("Created ID3DXEffectCompiler %p\n", object);
5971 return D3D_OK;
5974 struct ID3DXEffectPoolImpl
5976 ID3DXEffectPool ID3DXEffectPool_iface;
5977 LONG ref;
5980 static inline struct ID3DXEffectPoolImpl *impl_from_ID3DXEffectPool(ID3DXEffectPool *iface)
5982 return CONTAINING_RECORD(iface, struct ID3DXEffectPoolImpl, ID3DXEffectPool_iface);
5985 /*** IUnknown methods ***/
5986 static HRESULT WINAPI ID3DXEffectPoolImpl_QueryInterface(ID3DXEffectPool *iface, REFIID riid, void **object)
5988 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
5990 if (IsEqualGUID(riid, &IID_IUnknown) ||
5991 IsEqualGUID(riid, &IID_ID3DXEffectPool))
5993 iface->lpVtbl->AddRef(iface);
5994 *object = iface;
5995 return S_OK;
5998 WARN("Interface %s not found\n", debugstr_guid(riid));
6000 return E_NOINTERFACE;
6003 static ULONG WINAPI ID3DXEffectPoolImpl_AddRef(ID3DXEffectPool *iface)
6005 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
6007 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
6009 return InterlockedIncrement(&This->ref);
6012 static ULONG WINAPI ID3DXEffectPoolImpl_Release(ID3DXEffectPool *iface)
6014 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
6015 ULONG ref = InterlockedDecrement(&This->ref);
6017 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
6019 if (!ref)
6020 HeapFree(GetProcessHeap(), 0, This);
6022 return ref;
6025 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl =
6027 /*** IUnknown methods ***/
6028 ID3DXEffectPoolImpl_QueryInterface,
6029 ID3DXEffectPoolImpl_AddRef,
6030 ID3DXEffectPoolImpl_Release
6033 HRESULT WINAPI D3DXCreateEffectPool(ID3DXEffectPool **pool)
6035 struct ID3DXEffectPoolImpl *object;
6037 TRACE("(%p)\n", pool);
6039 if (!pool)
6040 return D3DERR_INVALIDCALL;
6042 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6043 if (!object)
6044 return E_OUTOFMEMORY;
6046 object->ID3DXEffectPool_iface.lpVtbl = &ID3DXEffectPool_Vtbl;
6047 object->ref = 1;
6049 *pool = &object->ID3DXEffectPool_iface;
6051 return S_OK;
6054 HRESULT WINAPI D3DXCreateEffectFromFileExW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
6055 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
6056 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6058 void *buffer;
6059 HRESULT ret;
6060 DWORD size;
6062 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6063 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6064 device, debugstr_w(srcfile), defines, include, debugstr_a(skipconstants),
6065 flags, pool, effect, compilationerrors);
6067 if (!device || !srcfile)
6068 return D3DERR_INVALIDCALL;
6070 ret = map_view_of_file(srcfile, &buffer, &size);
6072 if (FAILED(ret))
6073 return D3DXERR_INVALIDDATA;
6075 ret = D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6076 UnmapViewOfFile(buffer);
6078 return ret;
6081 HRESULT WINAPI D3DXCreateEffectFromFileExA(struct IDirect3DDevice9 *device, const char *srcfile,
6082 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
6083 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6085 WCHAR *srcfileW;
6086 HRESULT ret;
6087 DWORD len;
6089 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6090 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6091 device, debugstr_a(srcfile), defines, include, debugstr_a(skipconstants),
6092 flags, pool, effect, compilationerrors);
6094 if (!srcfile)
6095 return D3DERR_INVALIDCALL;
6097 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6098 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6099 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6101 ret = D3DXCreateEffectFromFileExW(device, srcfileW, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6102 HeapFree(GetProcessHeap(), 0, srcfileW);
6104 return ret;
6107 HRESULT WINAPI D3DXCreateEffectFromFileW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
6108 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
6109 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6111 TRACE("(void): relay\n");
6112 return D3DXCreateEffectFromFileExW(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6115 HRESULT WINAPI D3DXCreateEffectFromFileA(struct IDirect3DDevice9 *device, const char *srcfile,
6116 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
6117 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6119 TRACE("(void): relay\n");
6120 return D3DXCreateEffectFromFileExA(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6123 HRESULT WINAPI D3DXCreateEffectFromResourceExW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6124 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
6125 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6127 HRSRC resinfo;
6128 void *buffer;
6129 DWORD size;
6131 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6132 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6133 device, srcmodule, debugstr_w(srcresource), defines, include, debugstr_a(skipconstants),
6134 flags, pool, effect, compilationerrors);
6136 if (!device)
6137 return D3DERR_INVALIDCALL;
6139 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
6140 return D3DXERR_INVALIDDATA;
6142 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6143 return D3DXERR_INVALIDDATA;
6145 return D3DXCreateEffectEx(device, buffer, size, defines, include,
6146 skipconstants, flags, pool, effect, compilationerrors);
6149 HRESULT WINAPI D3DXCreateEffectFromResourceExA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6150 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
6151 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6153 HRSRC resinfo;
6154 void *buffer;
6155 DWORD size;
6157 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6158 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6159 device, srcmodule, debugstr_a(srcresource), defines, include, debugstr_a(skipconstants),
6160 flags, pool, effect, compilationerrors);
6162 if (!device)
6163 return D3DERR_INVALIDCALL;
6165 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
6166 return D3DXERR_INVALIDDATA;
6168 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6169 return D3DXERR_INVALIDDATA;
6171 return D3DXCreateEffectEx(device, buffer, size, defines, include,
6172 skipconstants, flags, pool, effect, compilationerrors);
6175 HRESULT WINAPI D3DXCreateEffectFromResourceW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6176 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6177 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6179 TRACE("(void): relay\n");
6180 return D3DXCreateEffectFromResourceExW(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6183 HRESULT WINAPI D3DXCreateEffectFromResourceA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
6184 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
6185 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
6187 TRACE("(void): relay\n");
6188 return D3DXCreateEffectFromResourceExA(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6191 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(const WCHAR *srcfile, const D3DXMACRO *defines,
6192 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6194 void *buffer;
6195 HRESULT ret;
6196 DWORD size;
6198 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6199 debugstr_w(srcfile), defines, include, flags, effectcompiler, parseerrors);
6201 if (!srcfile)
6202 return D3DERR_INVALIDCALL;
6204 ret = map_view_of_file(srcfile, &buffer, &size);
6206 if (FAILED(ret))
6207 return D3DXERR_INVALIDDATA;
6209 ret = D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6210 UnmapViewOfFile(buffer);
6212 return ret;
6215 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(const char *srcfile, const D3DXMACRO *defines,
6216 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6218 WCHAR *srcfileW;
6219 HRESULT ret;
6220 DWORD len;
6222 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6223 debugstr_a(srcfile), defines, include, flags, effectcompiler, parseerrors);
6225 if (!srcfile)
6226 return D3DERR_INVALIDCALL;
6228 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6229 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6230 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6232 ret = D3DXCreateEffectCompilerFromFileW(srcfileW, defines, include, flags, effectcompiler, parseerrors);
6233 HeapFree(GetProcessHeap(), 0, srcfileW);
6235 return ret;
6238 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule, const char *srcresource,
6239 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
6240 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6242 HRSRC resinfo;
6243 void *buffer;
6244 DWORD size;
6246 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6247 srcmodule, debugstr_a(srcresource), defines, include, flags, effectcompiler, parseerrors);
6249 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
6250 return D3DXERR_INVALIDDATA;
6252 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6253 return D3DXERR_INVALIDDATA;
6255 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6258 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule, const WCHAR *srcresource,
6259 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
6260 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
6262 HRSRC resinfo;
6263 void *buffer;
6264 DWORD size;
6266 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6267 srcmodule, debugstr_w(srcresource), defines, include, flags, effectcompiler, parseerrors);
6269 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
6270 return D3DXERR_INVALIDDATA;
6272 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
6273 return D3DXERR_INVALIDDATA;
6275 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6278 HRESULT WINAPI D3DXDisassembleEffect(ID3DXEffect *effect, BOOL enable_color_code, ID3DXBuffer **disassembly)
6280 FIXME("(%p, %u, %p): stub\n", effect, enable_color_code, disassembly);
6282 return D3DXERR_INVALIDDATA;