TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / d3dx9_36 / effect.c
blobf0bbd0bd5b26d3cd73851581c9114554d2679571
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"
22 #define NONAMELESSUNION
23 #include "wine/debug.h"
24 #include "wine/unicode.h"
26 #include "windef.h"
27 #include "wingdi.h"
28 #include "d3dx9_36_private.h"
29 #include "d3dcompiler.h"
31 /* Constants for special INT/FLOAT conversation */
32 #define INT_FLOAT_MULTI 255.0f
33 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
35 #define INITIAL_PARAM_TABLE_SIZE 16
37 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
39 enum STATE_CLASS
41 SC_LIGHTENABLE,
42 SC_FVF,
43 SC_LIGHT,
44 SC_MATERIAL,
45 SC_NPATCHMODE,
46 SC_PIXELSHADER,
47 SC_RENDERSTATE,
48 SC_SETSAMPLER,
49 SC_SAMPLERSTATE,
50 SC_TEXTURE,
51 SC_TEXTURESTAGE,
52 SC_TRANSFORM,
53 SC_VERTEXSHADER,
54 SC_SHADERCONST,
55 SC_UNKNOWN,
58 enum MATERIAL_TYPE
60 MT_DIFFUSE,
61 MT_AMBIENT,
62 MT_SPECULAR,
63 MT_EMISSIVE,
64 MT_POWER,
67 enum LIGHT_TYPE
69 LT_TYPE,
70 LT_DIFFUSE,
71 LT_SPECULAR,
72 LT_AMBIENT,
73 LT_POSITION,
74 LT_DIRECTION,
75 LT_RANGE,
76 LT_FALLOFF,
77 LT_ATTENUATION0,
78 LT_ATTENUATION1,
79 LT_ATTENUATION2,
80 LT_THETA,
81 LT_PHI,
84 enum SHADER_CONSTANT_TYPE
86 SCT_VSFLOAT,
87 SCT_VSBOOL,
88 SCT_VSINT,
89 SCT_PSFLOAT,
90 SCT_PSBOOL,
91 SCT_PSINT,
94 enum STATE_TYPE
96 ST_CONSTANT,
97 ST_PARAMETER,
98 ST_FXLC,
99 ST_ARRAY_SELECTOR,
102 struct d3dx_parameter
104 char *name;
105 char *semantic;
106 void *data;
107 D3DXPARAMETER_CLASS class;
108 D3DXPARAMETER_TYPE type;
109 UINT rows;
110 UINT columns;
111 UINT element_count;
112 UINT annotation_count;
113 UINT member_count;
114 DWORD flags;
115 UINT bytes;
116 DWORD object_id;
118 D3DXHANDLE handle;
120 struct d3dx_parameter *annotations;
121 struct d3dx_parameter *members;
123 struct d3dx_parameter *referenced_param;
126 struct d3dx_object
128 UINT size;
129 void *data;
130 struct d3dx_parameter *param;
133 struct d3dx_state
135 UINT operation;
136 UINT index;
137 enum STATE_TYPE type;
138 struct d3dx_parameter parameter;
141 struct d3dx_sampler
143 UINT state_count;
144 struct d3dx_state *states;
147 struct d3dx_pass
149 char *name;
150 UINT state_count;
151 UINT annotation_count;
153 struct d3dx_state *states;
154 struct d3dx_parameter *annotations;
157 struct d3dx_technique
159 char *name;
160 UINT pass_count;
161 UINT annotation_count;
163 struct d3dx_parameter *annotations;
164 struct d3dx_pass *passes;
167 struct param_table
169 struct d3dx_parameter **table;
170 unsigned int count, size;
173 struct d3dx9_base_effect
175 struct ID3DXEffectImpl *effect;
177 UINT parameter_count;
178 UINT technique_count;
179 UINT object_count;
181 struct d3dx_parameter *parameters;
182 struct d3dx_technique *techniques;
183 struct d3dx_object *objects;
185 struct param_table param_table;
188 struct ID3DXEffectImpl
190 ID3DXEffect ID3DXEffect_iface;
191 LONG ref;
193 struct d3dx9_base_effect base_effect;
195 struct ID3DXEffectStateManager *manager;
196 struct IDirect3DDevice9 *device;
197 struct ID3DXEffectPool *pool;
198 struct d3dx_technique *active_technique;
199 struct d3dx_pass *active_pass;
200 BOOL started;
201 DWORD flags;
204 struct ID3DXEffectCompilerImpl
206 ID3DXEffectCompiler ID3DXEffectCompiler_iface;
207 LONG ref;
209 struct d3dx9_base_effect base_effect;
212 static struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
213 struct d3dx_parameter *parameter, const char *name);
214 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *parameters,
215 const char *name);
216 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
217 const char *data, const char **ptr, struct d3dx_object *objects);
218 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child);
220 static const struct
222 enum STATE_CLASS class;
223 UINT op;
224 const char *name;
226 state_table[] =
228 /* Render sates */
229 {SC_RENDERSTATE, D3DRS_ZENABLE, "D3DRS_ZENABLE"}, /* 0x0 */
230 {SC_RENDERSTATE, D3DRS_FILLMODE, "D3DRS_FILLMODE"},
231 {SC_RENDERSTATE, D3DRS_SHADEMODE, "D3DRS_SHADEMODE"},
232 {SC_RENDERSTATE, D3DRS_ZWRITEENABLE, "D3DRS_ZWRITEENABLE"},
233 {SC_RENDERSTATE, D3DRS_ALPHATESTENABLE, "D3DRS_ALPHATESTENABLE"},
234 {SC_RENDERSTATE, D3DRS_LASTPIXEL, "D3DRS_LASTPIXEL"},
235 {SC_RENDERSTATE, D3DRS_SRCBLEND, "D3DRS_SRCBLEND"},
236 {SC_RENDERSTATE, D3DRS_DESTBLEND, "D3DRS_DESTBLEND"},
237 {SC_RENDERSTATE, D3DRS_CULLMODE, "D3DRS_CULLMODE"},
238 {SC_RENDERSTATE, D3DRS_ZFUNC, "D3DRS_ZFUNC"},
239 {SC_RENDERSTATE, D3DRS_ALPHAREF, "D3DRS_ALPHAREF"},
240 {SC_RENDERSTATE, D3DRS_ALPHAFUNC, "D3DRS_ALPHAFUNC"},
241 {SC_RENDERSTATE, D3DRS_DITHERENABLE, "D3DRS_DITHERENABLE"},
242 {SC_RENDERSTATE, D3DRS_ALPHABLENDENABLE, "D3DRS_ALPHABLENDENABLE"},
243 {SC_RENDERSTATE, D3DRS_FOGENABLE, "D3DRS_FOGENABLE"},
244 {SC_RENDERSTATE, D3DRS_SPECULARENABLE, "D3DRS_SPECULARENABLE"},
245 {SC_RENDERSTATE, D3DRS_FOGCOLOR, "D3DRS_FOGCOLOR"}, /* 0x10 */
246 {SC_RENDERSTATE, D3DRS_FOGTABLEMODE, "D3DRS_FOGTABLEMODE"},
247 {SC_RENDERSTATE, D3DRS_FOGSTART, "D3DRS_FOGSTART"},
248 {SC_RENDERSTATE, D3DRS_FOGEND, "D3DRS_FOGEND"},
249 {SC_RENDERSTATE, D3DRS_FOGDENSITY, "D3DRS_FOGDENSITY"},
250 {SC_RENDERSTATE, D3DRS_RANGEFOGENABLE, "D3DRS_RANGEFOGENABLE"},
251 {SC_RENDERSTATE, D3DRS_STENCILENABLE, "D3DRS_STENCILENABLE"},
252 {SC_RENDERSTATE, D3DRS_STENCILFAIL, "D3DRS_STENCILFAIL"},
253 {SC_RENDERSTATE, D3DRS_STENCILZFAIL, "D3DRS_STENCILZFAIL"},
254 {SC_RENDERSTATE, D3DRS_STENCILPASS, "D3DRS_STENCILPASS"},
255 {SC_RENDERSTATE, D3DRS_STENCILFUNC, "D3DRS_STENCILFUNC"},
256 {SC_RENDERSTATE, D3DRS_STENCILREF, "D3DRS_STENCILREF"},
257 {SC_RENDERSTATE, D3DRS_STENCILMASK, "D3DRS_STENCILMASK"},
258 {SC_RENDERSTATE, D3DRS_STENCILWRITEMASK, "D3DRS_STENCILWRITEMASK"},
259 {SC_RENDERSTATE, D3DRS_TEXTUREFACTOR, "D3DRS_TEXTUREFACTOR"},
260 {SC_RENDERSTATE, D3DRS_WRAP0, "D3DRS_WRAP0"},
261 {SC_RENDERSTATE, D3DRS_WRAP1, "D3DRS_WRAP1"}, /* 0x20 */
262 {SC_RENDERSTATE, D3DRS_WRAP2, "D3DRS_WRAP2"},
263 {SC_RENDERSTATE, D3DRS_WRAP3, "D3DRS_WRAP3"},
264 {SC_RENDERSTATE, D3DRS_WRAP4, "D3DRS_WRAP4"},
265 {SC_RENDERSTATE, D3DRS_WRAP5, "D3DRS_WRAP5"},
266 {SC_RENDERSTATE, D3DRS_WRAP6, "D3DRS_WRAP6"},
267 {SC_RENDERSTATE, D3DRS_WRAP7, "D3DRS_WRAP7"},
268 {SC_RENDERSTATE, D3DRS_WRAP8, "D3DRS_WRAP8"},
269 {SC_RENDERSTATE, D3DRS_WRAP9, "D3DRS_WRAP9"},
270 {SC_RENDERSTATE, D3DRS_WRAP10, "D3DRS_WRAP10"},
271 {SC_RENDERSTATE, D3DRS_WRAP11, "D3DRS_WRAP11"},
272 {SC_RENDERSTATE, D3DRS_WRAP12, "D3DRS_WRAP12"},
273 {SC_RENDERSTATE, D3DRS_WRAP13, "D3DRS_WRAP13"},
274 {SC_RENDERSTATE, D3DRS_WRAP14, "D3DRS_WRAP14"},
275 {SC_RENDERSTATE, D3DRS_WRAP15, "D3DRS_WRAP15"},
276 {SC_RENDERSTATE, D3DRS_CLIPPING, "D3DRS_CLIPPING"},
277 {SC_RENDERSTATE, D3DRS_LIGHTING, "D3DRS_LIGHTING"}, /* 0x30 */
278 {SC_RENDERSTATE, D3DRS_AMBIENT, "D3DRS_AMBIENT"},
279 {SC_RENDERSTATE, D3DRS_FOGVERTEXMODE, "D3DRS_FOGVERTEXMODE"},
280 {SC_RENDERSTATE, D3DRS_COLORVERTEX, "D3DRS_COLORVERTEX"},
281 {SC_RENDERSTATE, D3DRS_LOCALVIEWER, "D3DRS_LOCALVIEWER"},
282 {SC_RENDERSTATE, D3DRS_NORMALIZENORMALS, "D3DRS_NORMALIZENORMALS"},
283 {SC_RENDERSTATE, D3DRS_DIFFUSEMATERIALSOURCE, "D3DRS_DIFFUSEMATERIALSOURCE"},
284 {SC_RENDERSTATE, D3DRS_SPECULARMATERIALSOURCE, "D3DRS_SPECULARMATERIALSOURCE"},
285 {SC_RENDERSTATE, D3DRS_AMBIENTMATERIALSOURCE, "D3DRS_AMBIENTMATERIALSOURCE"},
286 {SC_RENDERSTATE, D3DRS_EMISSIVEMATERIALSOURCE, "D3DRS_EMISSIVEMATERIALSOURCE"},
287 {SC_RENDERSTATE, D3DRS_VERTEXBLEND, "D3DRS_VERTEXBLEND"},
288 {SC_RENDERSTATE, D3DRS_CLIPPLANEENABLE, "D3DRS_CLIPPLANEENABLE"},
289 {SC_RENDERSTATE, D3DRS_POINTSIZE, "D3DRS_POINTSIZE"},
290 {SC_RENDERSTATE, D3DRS_POINTSIZE_MIN, "D3DRS_POINTSIZE_MIN"},
291 {SC_RENDERSTATE, D3DRS_POINTSIZE_MAX, "D3DRS_POINTSIZE_MAX"},
292 {SC_RENDERSTATE, D3DRS_POINTSPRITEENABLE, "D3DRS_POINTSPRITEENABLE"},
293 {SC_RENDERSTATE, D3DRS_POINTSCALEENABLE, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
294 {SC_RENDERSTATE, D3DRS_POINTSCALE_A, "D3DRS_POINTSCALE_A"},
295 {SC_RENDERSTATE, D3DRS_POINTSCALE_B, "D3DRS_POINTSCALE_B"},
296 {SC_RENDERSTATE, D3DRS_POINTSCALE_C, "D3DRS_POINTSCALE_C"},
297 {SC_RENDERSTATE, D3DRS_MULTISAMPLEANTIALIAS, "D3DRS_MULTISAMPLEANTIALIAS"},
298 {SC_RENDERSTATE, D3DRS_MULTISAMPLEMASK, "D3DRS_MULTISAMPLEMASK"},
299 {SC_RENDERSTATE, D3DRS_PATCHEDGESTYLE, "D3DRS_PATCHEDGESTYLE"},
300 {SC_RENDERSTATE, D3DRS_DEBUGMONITORTOKEN, "D3DRS_DEBUGMONITORTOKEN"},
301 {SC_RENDERSTATE, D3DRS_INDEXEDVERTEXBLENDENABLE, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
302 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE, "D3DRS_COLORWRITEENABLE"},
303 {SC_RENDERSTATE, D3DRS_TWEENFACTOR, "D3DRS_TWEENFACTOR"},
304 {SC_RENDERSTATE, D3DRS_BLENDOP, "D3DRS_BLENDOP"},
305 {SC_RENDERSTATE, D3DRS_POSITIONDEGREE, "D3DRS_POSITIONDEGREE"},
306 {SC_RENDERSTATE, D3DRS_NORMALDEGREE, "D3DRS_NORMALDEGREE"},
307 {SC_RENDERSTATE, D3DRS_SCISSORTESTENABLE, "D3DRS_SCISSORTESTENABLE"},
308 {SC_RENDERSTATE, D3DRS_SLOPESCALEDEPTHBIAS, "D3DRS_SLOPESCALEDEPTHBIAS"},
309 {SC_RENDERSTATE, D3DRS_ANTIALIASEDLINEENABLE, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
310 {SC_RENDERSTATE, D3DRS_MINTESSELLATIONLEVEL, "D3DRS_MINTESSELLATIONLEVEL"},
311 {SC_RENDERSTATE, D3DRS_MAXTESSELLATIONLEVEL, "D3DRS_MAXTESSELLATIONLEVEL"},
312 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_X, "D3DRS_ADAPTIVETESS_X"},
313 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Y, "D3DRS_ADAPTIVETESS_Y"},
314 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Z, "D3DRS_ADAPTIVETESS_Z"},
315 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_W, "D3DRS_ADAPTIVETESS_W"},
316 {SC_RENDERSTATE, D3DRS_ENABLEADAPTIVETESSELLATION, "D3DRS_ENABLEADAPTIVETESSELLATION"},
317 {SC_RENDERSTATE, D3DRS_TWOSIDEDSTENCILMODE, "D3DRS_TWOSIDEDSTENCILMODE"},
318 {SC_RENDERSTATE, D3DRS_CCW_STENCILFAIL, "D3DRS_CCW_STENCILFAIL"},
319 {SC_RENDERSTATE, D3DRS_CCW_STENCILZFAIL, "D3DRS_CCW_STENCILZFAIL"},
320 {SC_RENDERSTATE, D3DRS_CCW_STENCILPASS, "D3DRS_CCW_STENCILPASS"},
321 {SC_RENDERSTATE, D3DRS_CCW_STENCILFUNC, "D3DRS_CCW_STENCILFUNC"},
322 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE1, "D3DRS_COLORWRITEENABLE1"},
323 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE2, "D3DRS_COLORWRITEENABLE2"},
324 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE3, "D3DRS_COLORWRITEENABLE3"},
325 {SC_RENDERSTATE, D3DRS_BLENDFACTOR, "D3DRS_BLENDFACTOR"}, /* 0x60 */
326 {SC_RENDERSTATE, D3DRS_SRGBWRITEENABLE, "D3DRS_SRGBWRITEENABLE"},
327 {SC_RENDERSTATE, D3DRS_DEPTHBIAS, "D3DRS_DEPTHBIAS"},
328 {SC_RENDERSTATE, D3DRS_SEPARATEALPHABLENDENABLE, "D3DRS_SEPARATEALPHABLENDENABLE"},
329 {SC_RENDERSTATE, D3DRS_SRCBLENDALPHA, "D3DRS_SRCBLENDALPHA"},
330 {SC_RENDERSTATE, D3DRS_DESTBLENDALPHA, "D3DRS_DESTBLENDALPHA"},
331 {SC_RENDERSTATE, D3DRS_BLENDOPALPHA, "D3DRS_BLENDOPALPHA"},
332 /* Texture stages */
333 {SC_TEXTURESTAGE, D3DTSS_COLOROP, "D3DTSS_COLOROP"},
334 {SC_TEXTURESTAGE, D3DTSS_COLORARG0, "D3DTSS_COLORARG0"},
335 {SC_TEXTURESTAGE, D3DTSS_COLORARG1, "D3DTSS_COLORARG1"},
336 {SC_TEXTURESTAGE, D3DTSS_COLORARG2, "D3DTSS_COLORARG2"},
337 {SC_TEXTURESTAGE, D3DTSS_ALPHAOP, "D3DTSS_ALPHAOP"},
338 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG0, "D3DTSS_ALPHAARG0"},
339 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG1, "D3DTSS_ALPHAARG1"},
340 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG2, "D3DTSS_ALPHAARG2"},
341 {SC_TEXTURESTAGE, D3DTSS_RESULTARG, "D3DTSS_RESULTARG"},
342 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT00, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
343 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT01, "D3DTSS_BUMPENVMAT01"},
344 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT10, "D3DTSS_BUMPENVMAT10"},
345 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT11, "D3DTSS_BUMPENVMAT11"},
346 {SC_TEXTURESTAGE, D3DTSS_TEXCOORDINDEX, "D3DTSS_TEXCOORDINDEX"},
347 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLSCALE, "D3DTSS_BUMPENVLSCALE"},
348 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLOFFSET, "D3DTSS_BUMPENVLOFFSET"},
349 {SC_TEXTURESTAGE, D3DTSS_TEXTURETRANSFORMFLAGS, "D3DTSS_TEXTURETRANSFORMFLAGS"},
350 {SC_TEXTURESTAGE, D3DTSS_CONSTANT, "D3DTSS_CONSTANT"},
351 /* NPatchMode */
352 {SC_NPATCHMODE, 0, "NPatchMode"},
353 /* FVF */
354 {SC_FVF, 0, "FVF"},
355 /* Transform */
356 {SC_TRANSFORM, D3DTS_PROJECTION, "D3DTS_PROJECTION"},
357 {SC_TRANSFORM, D3DTS_VIEW, "D3DTS_VIEW"},
358 {SC_TRANSFORM, D3DTS_WORLD, "D3DTS_WORLD"},
359 {SC_TRANSFORM, D3DTS_TEXTURE0, "D3DTS_TEXTURE0"},
360 /* Material */
361 {SC_MATERIAL, MT_DIFFUSE, "MaterialDiffuse"},
362 {SC_MATERIAL, MT_AMBIENT, "MaterialAmbient"}, /* 0x80 */
363 {SC_MATERIAL, MT_SPECULAR, "MaterialSpecular"},
364 {SC_MATERIAL, MT_EMISSIVE, "MaterialEmissive"},
365 {SC_MATERIAL, MT_POWER, "MaterialPower"},
366 /* Light */
367 {SC_LIGHT, LT_TYPE, "LightType"},
368 {SC_LIGHT, LT_DIFFUSE, "LightDiffuse"},
369 {SC_LIGHT, LT_SPECULAR, "LightSpecular"},
370 {SC_LIGHT, LT_AMBIENT, "LightAmbient"},
371 {SC_LIGHT, LT_POSITION, "LightPosition"},
372 {SC_LIGHT, LT_DIRECTION, "LightDirection"},
373 {SC_LIGHT, LT_RANGE, "LightRange"},
374 {SC_LIGHT, LT_FALLOFF, "LightFallOff"},
375 {SC_LIGHT, LT_ATTENUATION0, "LightAttenuation0"},
376 {SC_LIGHT, LT_ATTENUATION1, "LightAttenuation1"},
377 {SC_LIGHT, LT_ATTENUATION2, "LightAttenuation2"},
378 {SC_LIGHT, LT_THETA, "LightTheta"},
379 {SC_LIGHT, LT_PHI, "LightPhi"}, /* 0x90 */
380 /* Ligthenable */
381 {SC_LIGHTENABLE, 0, "LightEnable"},
382 /* Vertexshader */
383 {SC_VERTEXSHADER, 0, "Vertexshader"},
384 /* Pixelshader */
385 {SC_PIXELSHADER, 0, "Pixelshader"},
386 /* Shader constants */
387 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstantF"},
388 {SC_SHADERCONST, SCT_VSBOOL, "VertexShaderConstantB"},
389 {SC_SHADERCONST, SCT_VSINT, "VertexShaderConstantI"},
390 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant"},
391 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant1"},
392 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant2"},
393 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant3"},
394 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant4"},
395 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstantF"},
396 {SC_SHADERCONST, SCT_PSBOOL, "PixelShaderConstantB"},
397 {SC_SHADERCONST, SCT_PSINT, "PixelShaderConstantI"},
398 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant"},
399 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant1"}, /* 0xa0 */
400 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant2"},
401 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant3"},
402 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant4"},
403 /* Texture */
404 {SC_TEXTURE, 0, "Texture"},
405 /* Sampler states */
406 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSU, "AddressU"},
407 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSV, "AddressV"},
408 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSW, "AddressW"},
409 {SC_SAMPLERSTATE, D3DSAMP_BORDERCOLOR, "BorderColor"},
410 {SC_SAMPLERSTATE, D3DSAMP_MAGFILTER, "MagFilter"},
411 {SC_SAMPLERSTATE, D3DSAMP_MINFILTER, "MinFilter"},
412 {SC_SAMPLERSTATE, D3DSAMP_MIPFILTER, "MipFilter"},
413 {SC_SAMPLERSTATE, D3DSAMP_MIPMAPLODBIAS, "MipMapLodBias"},
414 {SC_SAMPLERSTATE, D3DSAMP_MAXMIPLEVEL, "MaxMipLevel"},
415 {SC_SAMPLERSTATE, D3DSAMP_MAXANISOTROPY, "MaxAnisotropy"},
416 {SC_SAMPLERSTATE, D3DSAMP_SRGBTEXTURE, "SRGBTexture"},
417 {SC_SAMPLERSTATE, D3DSAMP_ELEMENTINDEX, "ElementIndex"}, /* 0xb0 */
418 {SC_SAMPLERSTATE, D3DSAMP_DMAPOFFSET, "DMAPOffset"},
419 /* Set sampler */
420 {SC_SETSAMPLER, 0, "Sampler"},
423 static inline void read_dword(const char **ptr, DWORD *d)
425 memcpy(d, *ptr, sizeof(*d));
426 *ptr += sizeof(*d);
429 static void skip_dword_unknown(const char **ptr, unsigned int count)
431 unsigned int i;
432 DWORD d;
434 FIXME("Skipping %u unknown DWORDs:\n", count);
435 for (i = 0; i < count; ++i)
437 read_dword(ptr, &d);
438 FIXME("\t0x%08x\n", d);
442 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
444 return parameter ? parameter->handle : NULL;
447 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
449 return (D3DXHANDLE) technique;
452 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
454 return (D3DXHANDLE) pass;
457 static struct d3dx_technique *get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
459 UINT i;
461 if (!name) return NULL;
463 for (i = 0; i < base->technique_count; ++i)
465 if (!strcmp(base->techniques[i].name, name))
466 return &base->techniques[i];
469 return NULL;
472 static struct d3dx_technique *get_valid_technique(struct d3dx9_base_effect *base, D3DXHANDLE technique)
474 unsigned int i;
476 for (i = 0; i < base->technique_count; ++i)
478 if (get_technique_handle(&base->techniques[i]) == technique)
479 return &base->techniques[i];
482 return get_technique_by_name(base, technique);
485 static struct d3dx_pass *get_valid_pass(struct d3dx9_base_effect *base, D3DXHANDLE pass)
487 unsigned int i, k;
489 for (i = 0; i < base->technique_count; ++i)
491 struct d3dx_technique *technique = &base->techniques[i];
493 for (k = 0; k < technique->pass_count; ++k)
495 if (get_pass_handle(&technique->passes[k]) == pass)
496 return &technique->passes[k];
500 return NULL;
503 static struct d3dx_parameter *get_valid_parameter(struct d3dx9_base_effect *base, D3DXHANDLE parameter)
505 struct d3dx_parameter **handle_param = (struct d3dx_parameter **)parameter;
507 if (handle_param >= base->param_table.table && handle_param < base->param_table.table + base->param_table.count)
508 return *handle_param;
510 return get_parameter_by_name(base, NULL, parameter);
513 static void free_state(struct d3dx_state *state)
515 free_parameter(&state->parameter, FALSE, FALSE);
518 static void free_object(struct d3dx_object *object)
520 HeapFree(GetProcessHeap(), 0, object->data);
523 static void free_sampler(struct d3dx_sampler *sampler)
525 UINT i;
527 for (i = 0; i < sampler->state_count; ++i)
529 free_state(&sampler->states[i]);
531 HeapFree(GetProcessHeap(), 0, sampler->states);
534 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child)
536 unsigned int i;
538 TRACE("Free parameter %p, name %s, type %s, child %s\n", param, param->name,
539 debug_d3dxparameter_type(param->type), child ? "yes" : "no");
541 if (!param)
542 return;
544 if (param->annotations)
546 for (i = 0; i < param->annotation_count; ++i)
547 free_parameter(&param->annotations[i], FALSE, FALSE);
548 HeapFree(GetProcessHeap(), 0, param->annotations);
549 param->annotations = NULL;
552 if (param->members)
554 unsigned int count = param->element_count ? param->element_count : param->member_count;
556 for (i = 0; i < count; ++i)
557 free_parameter(&param->members[i], param->element_count != 0, TRUE);
558 HeapFree(GetProcessHeap(), 0, param->members);
559 param->members = NULL;
562 if (param->class == D3DXPC_OBJECT && !param->element_count)
564 switch (param->type)
566 case D3DXPT_STRING:
567 HeapFree(GetProcessHeap(), 0, *(char **)param->data);
568 break;
570 case D3DXPT_TEXTURE:
571 case D3DXPT_TEXTURE1D:
572 case D3DXPT_TEXTURE2D:
573 case D3DXPT_TEXTURE3D:
574 case D3DXPT_TEXTURECUBE:
575 case D3DXPT_PIXELSHADER:
576 case D3DXPT_VERTEXSHADER:
577 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
578 break;
580 case D3DXPT_SAMPLER:
581 case D3DXPT_SAMPLER1D:
582 case D3DXPT_SAMPLER2D:
583 case D3DXPT_SAMPLER3D:
584 case D3DXPT_SAMPLERCUBE:
585 free_sampler((struct d3dx_sampler *)param->data);
586 break;
588 default:
589 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
590 break;
594 if (!child)
596 HeapFree(GetProcessHeap(), 0, param->data);
599 /* only the parent has to release name and semantic */
600 if (!element)
602 HeapFree(GetProcessHeap(), 0, param->name);
603 HeapFree(GetProcessHeap(), 0, param->semantic);
607 static void free_pass(struct d3dx_pass *pass)
609 unsigned int i;
611 TRACE("Free pass %p\n", pass);
613 if (!pass)
614 return;
616 if (pass->annotations)
618 for (i = 0; i < pass->annotation_count; ++i)
619 free_parameter(&pass->annotations[i], FALSE, FALSE);
620 HeapFree(GetProcessHeap(), 0, pass->annotations);
621 pass->annotations = NULL;
624 if (pass->states)
626 for (i = 0; i < pass->state_count; ++i)
627 free_state(&pass->states[i]);
628 HeapFree(GetProcessHeap(), 0, pass->states);
629 pass->states = NULL;
632 HeapFree(GetProcessHeap(), 0, pass->name);
633 pass->name = NULL;
636 static void free_technique(struct d3dx_technique *technique)
638 unsigned int i;
640 TRACE("Free technique %p\n", technique);
642 if (!technique)
643 return;
645 if (technique->annotations)
647 for (i = 0; i < technique->annotation_count; ++i)
648 free_parameter(&technique->annotations[i], FALSE, FALSE);
649 HeapFree(GetProcessHeap(), 0, technique->annotations);
650 technique->annotations = NULL;
653 if (technique->passes)
655 for (i = 0; i < technique->pass_count; ++i)
656 free_pass(&technique->passes[i]);
657 HeapFree(GetProcessHeap(), 0, technique->passes);
658 technique->passes = NULL;
661 HeapFree(GetProcessHeap(), 0, technique->name);
662 technique->name = NULL;
665 static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
667 unsigned int i;
669 TRACE("base %p.\n", base);
671 HeapFree(GetProcessHeap(), 0, base->param_table.table);
673 if (base->parameters)
675 for (i = 0; i < base->parameter_count; ++i)
676 free_parameter(&base->parameters[i], FALSE, FALSE);
677 HeapFree(GetProcessHeap(), 0, base->parameters);
678 base->parameters = NULL;
681 if (base->techniques)
683 for (i = 0; i < base->technique_count; ++i)
684 free_technique(&base->techniques[i]);
685 HeapFree(GetProcessHeap(), 0, base->techniques);
686 base->techniques = NULL;
689 if (base->objects)
691 for (i = 0; i < base->object_count; ++i)
693 free_object(&base->objects[i]);
695 HeapFree(GetProcessHeap(), 0, base->objects);
696 base->objects = NULL;
700 static void free_effect(struct ID3DXEffectImpl *effect)
702 TRACE("Free effect %p\n", effect);
704 d3dx9_base_effect_cleanup(&effect->base_effect);
706 if (effect->pool)
708 effect->pool->lpVtbl->Release(effect->pool);
711 if (effect->manager)
713 IUnknown_Release(effect->manager);
716 IDirect3DDevice9_Release(effect->device);
719 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
721 TRACE("Free effect compiler %p\n", compiler);
723 d3dx9_base_effect_cleanup(&compiler->base_effect);
726 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
728 UINT i;
730 for (i = 0; i < 4; ++i)
732 if (i < param->columns)
733 set_number((FLOAT *)vector + i, D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
734 else
735 ((FLOAT *)vector)[i] = 0.0f;
739 static void set_vector(struct d3dx_parameter *param, const D3DXVECTOR4 *vector)
741 UINT i;
743 for (i = 0; i < param->columns; ++i)
745 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
749 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix, BOOL transpose)
751 UINT i, k;
753 for (i = 0; i < 4; ++i)
755 for (k = 0; k < 4; ++k)
757 FLOAT *tmp = transpose ? (FLOAT *)&matrix->u.m[k][i] : (FLOAT *)&matrix->u.m[i][k];
759 if ((i < param->rows) && (k < param->columns))
760 set_number(tmp, D3DXPT_FLOAT, (DWORD *)param->data + i * param->columns + k, param->type);
761 else
762 *tmp = 0.0f;
767 static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
769 UINT i, k;
771 if (param->type == D3DXPT_FLOAT)
773 if (param->columns == 4)
774 memcpy(param->data, matrix->u.m, param->rows * 4 * sizeof(float));
775 else
776 for (i = 0; i < param->rows; ++i)
777 memcpy((float *)param->data + i * param->columns, matrix->u.m + i, param->columns * sizeof(float));
778 return;
781 for (i = 0; i < param->rows; ++i)
783 for (k = 0; k < param->columns; ++k)
785 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
786 &matrix->u.m[i][k], D3DXPT_FLOAT);
791 static void set_matrix_transpose(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
793 UINT i, k;
795 for (i = 0; i < param->rows; ++i)
797 for (k = 0; k < param->columns; ++k)
799 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
800 &matrix->u.m[k][i], D3DXPT_FLOAT);
805 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, const char *name)
807 UINT element;
808 struct d3dx_parameter *temp_parameter;
809 const char *part;
811 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
813 if (!name || !*name) return NULL;
815 element = atoi(name);
816 part = strchr(name, ']') + 1;
818 /* check for empty [] && element range */
819 if ((part - name) > 1 && parameter->element_count > element)
821 temp_parameter = &parameter->members[element];
823 switch (*part++)
825 case '.':
826 return get_parameter_by_name(NULL, temp_parameter, part);
828 case '@':
829 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
831 case '\0':
832 TRACE("Returning parameter %p\n", temp_parameter);
833 return temp_parameter;
835 default:
836 FIXME("Unhandled case \"%c\"\n", *--part);
837 break;
841 TRACE("Parameter not found\n");
842 return NULL;
845 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *annotations,
846 const char *name)
848 UINT i, length;
849 struct d3dx_parameter *temp_parameter;
850 const char *part;
852 TRACE("count %u, annotations %p, name %s\n", count, annotations, debugstr_a(name));
854 if (!name || !*name) return NULL;
856 length = strcspn( name, "[.@" );
857 part = name + length;
859 for (i = 0; i < count; ++i)
861 temp_parameter = &annotations[i];
863 if (!strcmp(temp_parameter->name, name))
865 TRACE("Returning annotation %p\n", temp_parameter);
866 return temp_parameter;
868 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
870 switch (*part++)
872 case '.':
873 return get_parameter_by_name(NULL, temp_parameter, part);
875 case '[':
876 return get_parameter_element_by_name(temp_parameter, part);
878 default:
879 FIXME("Unhandled case \"%c\"\n", *--part);
880 break;
885 TRACE("Annotation not found\n");
886 return NULL;
889 static struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
890 struct d3dx_parameter *parameter, const char *name)
892 UINT i, count, length;
893 struct d3dx_parameter *temp_parameter;
894 struct d3dx_parameter *parameters;
895 const char *part;
897 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
899 if (!name || !*name) return NULL;
901 if (!parameter)
903 count = base->parameter_count;
904 parameters = base->parameters;
906 else
908 count = parameter->member_count;
909 parameters = parameter->members;
912 length = strcspn( name, "[.@" );
913 part = name + length;
915 for (i = 0; i < count; i++)
917 temp_parameter = &parameters[i];
919 if (!strcmp(temp_parameter->name, name))
921 TRACE("Returning parameter %p\n", temp_parameter);
922 return temp_parameter;
924 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
926 switch (*part++)
928 case '.':
929 return get_parameter_by_name(NULL, temp_parameter, part);
931 case '@':
932 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
934 case '[':
935 return get_parameter_element_by_name(temp_parameter, part);
937 default:
938 FIXME("Unhandled case \"%c\"\n", *--part);
939 break;
944 TRACE("Parameter not found\n");
945 return NULL;
948 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
950 return (0xfeff0000 | ((major) << 8) | (minor));
953 static HRESULT d3dx9_base_effect_get_desc(struct d3dx9_base_effect *base, D3DXEFFECT_DESC *desc)
955 if (!desc)
957 WARN("Invalid argument specified.\n");
958 return D3DERR_INVALIDCALL;
961 FIXME("partial stub!\n");
963 /* TODO: add creator and function count. */
964 desc->Creator = NULL;
965 desc->Functions = 0;
966 desc->Parameters = base->parameter_count;
967 desc->Techniques = base->technique_count;
969 return D3D_OK;
972 static HRESULT d3dx9_base_effect_get_parameter_desc(struct d3dx9_base_effect *base,
973 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
975 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
977 if (!desc || !param)
979 WARN("Invalid argument specified.\n");
980 return D3DERR_INVALIDCALL;
983 desc->Name = param->name;
984 desc->Semantic = param->semantic;
985 desc->Class = param->class;
986 desc->Type = param->type;
987 desc->Rows = param->rows;
988 desc->Columns = param->columns;
989 desc->Elements = param->element_count;
990 desc->Annotations = param->annotation_count;
991 desc->StructMembers = param->member_count;
992 desc->Flags = param->flags;
993 desc->Bytes = param->bytes;
995 return D3D_OK;
998 static HRESULT d3dx9_base_effect_get_technique_desc(struct d3dx9_base_effect *base,
999 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
1001 struct d3dx_technique *tech = technique ? get_valid_technique(base, technique) : &base->techniques[0];
1003 if (!desc || !tech)
1005 WARN("Invalid argument specified.\n");
1006 return D3DERR_INVALIDCALL;
1009 desc->Name = tech->name;
1010 desc->Passes = tech->pass_count;
1011 desc->Annotations = tech->annotation_count;
1013 return D3D_OK;
1016 static HRESULT d3dx9_base_effect_get_pass_desc(struct d3dx9_base_effect *base,
1017 D3DXHANDLE pass, D3DXPASS_DESC *desc)
1019 struct d3dx_pass *p = get_valid_pass(base, pass);
1021 if (!desc || !p)
1023 WARN("Invalid argument specified.\n");
1024 return D3DERR_INVALIDCALL;
1027 desc->Name = p->name;
1028 desc->Annotations = p->annotation_count;
1030 FIXME("Pixel shader and vertex shader are not supported, yet.\n");
1031 desc->pVertexShaderFunction = NULL;
1032 desc->pPixelShaderFunction = NULL;
1034 return D3D_OK;
1037 static HRESULT d3dx9_base_effect_get_function_desc(struct d3dx9_base_effect *base,
1038 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1040 FIXME("stub!\n");
1042 return E_NOTIMPL;
1045 static D3DXHANDLE d3dx9_base_effect_get_parameter(struct d3dx9_base_effect *base,
1046 D3DXHANDLE parameter, UINT index)
1048 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1050 if (!parameter)
1052 if (index < base->parameter_count)
1054 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1055 return get_parameter_handle(&base->parameters[index]);
1058 else
1060 if (param && !param->element_count && index < param->member_count)
1062 TRACE("Returning parameter %p.\n", &param->members[index]);
1063 return get_parameter_handle(&param->members[index]);
1067 WARN("Parameter not found.\n");
1069 return NULL;
1072 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_name(struct d3dx9_base_effect *base,
1073 D3DXHANDLE parameter, const char *name)
1075 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1076 D3DXHANDLE handle;
1078 if (!name)
1080 handle = get_parameter_handle(param);
1081 TRACE("Returning parameter %p.\n", handle);
1082 return handle;
1085 handle = get_parameter_handle(get_parameter_by_name(base, param, name));
1086 TRACE("Returning parameter %p.\n", handle);
1088 return handle;
1091 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_semantic(struct d3dx9_base_effect *base,
1092 D3DXHANDLE parameter, const char *semantic)
1094 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1095 struct d3dx_parameter *temp_param;
1096 UINT i;
1098 if (!parameter)
1100 for (i = 0; i < base->parameter_count; ++i)
1102 temp_param = &base->parameters[i];
1104 if (!temp_param->semantic)
1106 if (!semantic)
1108 TRACE("Returning parameter %p\n", temp_param);
1109 return get_parameter_handle(temp_param);
1111 continue;
1114 if (!strcasecmp(temp_param->semantic, semantic))
1116 TRACE("Returning parameter %p\n", temp_param);
1117 return get_parameter_handle(temp_param);
1121 else if (param)
1123 for (i = 0; i < param->member_count; ++i)
1125 temp_param = &param->members[i];
1127 if (!temp_param->semantic)
1129 if (!semantic)
1131 TRACE("Returning parameter %p\n", temp_param);
1132 return get_parameter_handle(temp_param);
1134 continue;
1137 if (!strcasecmp(temp_param->semantic, semantic))
1139 TRACE("Returning parameter %p\n", temp_param);
1140 return get_parameter_handle(temp_param);
1145 WARN("Parameter not found.\n");
1147 return NULL;
1150 static D3DXHANDLE d3dx9_base_effect_get_parameter_element(struct d3dx9_base_effect *base,
1151 D3DXHANDLE parameter, UINT index)
1153 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1155 if (!param)
1157 if (index < base->parameter_count)
1159 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1160 return get_parameter_handle(&base->parameters[index]);
1163 else
1165 if (index < param->element_count)
1167 TRACE("Returning parameter %p.\n", &param->members[index]);
1168 return get_parameter_handle(&param->members[index]);
1172 WARN("Parameter not found.\n");
1174 return NULL;
1177 static D3DXHANDLE d3dx9_base_effect_get_technique(struct d3dx9_base_effect *base, UINT index)
1179 if (index >= base->technique_count)
1181 WARN("Invalid argument specified.\n");
1182 return NULL;
1185 TRACE("Returning technique %p.\n", &base->techniques[index]);
1187 return get_technique_handle(&base->techniques[index]);
1190 static D3DXHANDLE d3dx9_base_effect_get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
1192 struct d3dx_technique *tech = get_technique_by_name(base, name);
1194 if (tech)
1196 D3DXHANDLE t = get_technique_handle(tech);
1197 TRACE("Returning technique %p\n", t);
1198 return t;
1201 WARN("Technique not found.\n");
1203 return NULL;
1206 static D3DXHANDLE d3dx9_base_effect_get_pass(struct d3dx9_base_effect *base,
1207 D3DXHANDLE technique, UINT index)
1209 struct d3dx_technique *tech = get_valid_technique(base, technique);
1211 if (tech && index < tech->pass_count)
1213 TRACE("Returning pass %p\n", &tech->passes[index]);
1214 return get_pass_handle(&tech->passes[index]);
1217 WARN("Pass not found.\n");
1219 return NULL;
1222 static D3DXHANDLE d3dx9_base_effect_get_pass_by_name(struct d3dx9_base_effect *base,
1223 D3DXHANDLE technique, const char *name)
1225 struct d3dx_technique *tech = get_valid_technique(base, technique);
1227 if (tech && name)
1229 unsigned int i;
1231 for (i = 0; i < tech->pass_count; ++i)
1233 struct d3dx_pass *pass = &tech->passes[i];
1235 if (!strcmp(pass->name, name))
1237 TRACE("Returning pass %p\n", pass);
1238 return get_pass_handle(pass);
1243 WARN("Pass not found.\n");
1245 return NULL;
1248 static D3DXHANDLE d3dx9_base_effect_get_function(struct d3dx9_base_effect *base, UINT index)
1250 FIXME("stub!\n");
1252 return NULL;
1255 static D3DXHANDLE d3dx9_base_effect_get_function_by_name(struct d3dx9_base_effect *base, const char *name)
1257 FIXME("stub!\n");
1259 return NULL;
1262 static UINT get_annotation_from_object(struct d3dx9_base_effect *base,
1263 D3DXHANDLE object, struct d3dx_parameter **annotations)
1265 struct d3dx_parameter *param = get_valid_parameter(base, object);
1266 struct d3dx_pass *pass = get_valid_pass(base, object);
1267 struct d3dx_technique *technique = get_valid_technique(base, object);
1269 if (pass)
1271 *annotations = pass->annotations;
1272 return pass->annotation_count;
1274 else if (technique)
1276 *annotations = technique->annotations;
1277 return technique->annotation_count;
1279 else if (param)
1281 *annotations = param->annotations;
1282 return param->annotation_count;
1284 else
1286 FIXME("Functions are not handled, yet!\n");
1287 return 0;
1291 static D3DXHANDLE d3dx9_base_effect_get_annotation(struct d3dx9_base_effect *base,
1292 D3DXHANDLE object, UINT index)
1294 struct d3dx_parameter *annotations = NULL;
1295 UINT annotation_count = 0;
1297 annotation_count = get_annotation_from_object(base, object, &annotations);
1299 if (index < annotation_count)
1301 TRACE("Returning parameter %p\n", &annotations[index]);
1302 return get_parameter_handle(&annotations[index]);
1305 WARN("Annotation not found.\n");
1307 return NULL;
1310 static D3DXHANDLE d3dx9_base_effect_get_annotation_by_name(struct d3dx9_base_effect *base,
1311 D3DXHANDLE object, const char *name)
1313 struct d3dx_parameter *annotation = NULL;
1314 struct d3dx_parameter *annotations = NULL;
1315 UINT annotation_count = 0;
1317 if (!name)
1319 WARN("Invalid argument specified\n");
1320 return NULL;
1323 annotation_count = get_annotation_from_object(base, object, &annotations);
1325 annotation = get_annotation_by_name(annotation_count, annotations, name);
1326 if (annotation)
1328 TRACE("Returning parameter %p\n", annotation);
1329 return get_parameter_handle(annotation);
1332 WARN("Annotation not found.\n");
1334 return NULL;
1337 static HRESULT d3dx9_base_effect_set_value(struct d3dx9_base_effect *base,
1338 D3DXHANDLE parameter, const void *data, UINT bytes)
1340 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1342 if (!param)
1344 WARN("Invalid parameter %p specified\n", parameter);
1345 return D3DERR_INVALIDCALL;
1348 /* samplers don't touch data */
1349 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1350 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1351 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1353 TRACE("Sampler: returning E_FAIL\n");
1354 return E_FAIL;
1357 if (data && param->bytes <= bytes)
1359 switch (param->type)
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 inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
2495 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
2498 /*** IUnknown methods ***/
2499 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
2501 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
2503 if (IsEqualGUID(riid, &IID_IUnknown) ||
2504 IsEqualGUID(riid, &IID_ID3DXEffect))
2506 iface->lpVtbl->AddRef(iface);
2507 *object = iface;
2508 return S_OK;
2511 ERR("Interface %s not found\n", debugstr_guid(riid));
2513 return E_NOINTERFACE;
2516 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
2518 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2520 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
2522 return InterlockedIncrement(&This->ref);
2525 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
2527 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2528 ULONG ref = InterlockedDecrement(&This->ref);
2530 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
2532 if (!ref)
2534 free_effect(This);
2535 HeapFree(GetProcessHeap(), 0, This);
2538 return ref;
2541 /*** ID3DXBaseEffect methods ***/
2542 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
2544 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2546 TRACE("iface %p, desc %p.\n", iface, desc);
2548 return d3dx9_base_effect_get_desc(&effect->base_effect, desc);
2551 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface,
2552 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
2554 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2556 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
2558 return d3dx9_base_effect_get_parameter_desc(&effect->base_effect, parameter, desc);
2561 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface,
2562 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
2564 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2566 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
2568 return d3dx9_base_effect_get_technique_desc(&effect->base_effect, technique, desc);
2571 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
2573 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2575 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
2577 return d3dx9_base_effect_get_pass_desc(&effect->base_effect, pass, desc);
2580 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
2582 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2584 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
2586 return d3dx9_base_effect_get_function_desc(&effect->base_effect, shader, desc);
2589 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2591 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2593 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
2595 return d3dx9_base_effect_get_parameter(&effect->base_effect, parameter, index);
2598 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface,
2599 D3DXHANDLE parameter, const char *name)
2601 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2603 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
2605 return d3dx9_base_effect_get_parameter_by_name(&effect->base_effect, parameter, name);
2608 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface,
2609 D3DXHANDLE parameter, const char *semantic)
2611 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2613 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
2615 return d3dx9_base_effect_get_parameter_by_semantic(&effect->base_effect, parameter, semantic);
2618 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2620 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2622 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
2624 return d3dx9_base_effect_get_parameter_element(&effect->base_effect, parameter, index);
2627 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
2629 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2631 TRACE("iface %p, index %u.\n", iface, index);
2633 return d3dx9_base_effect_get_technique(&effect->base_effect, index);
2636 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, const char *name)
2638 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2640 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
2642 return d3dx9_base_effect_get_technique_by_name(&effect->base_effect, name);
2645 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
2647 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2649 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
2651 return d3dx9_base_effect_get_pass(&effect->base_effect, technique, index);
2654 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface,
2655 D3DXHANDLE technique, const char *name)
2657 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2659 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
2661 return d3dx9_base_effect_get_pass_by_name(&effect->base_effect, technique, name);
2664 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
2666 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2668 TRACE("iface %p, index %u.\n", iface, index);
2670 return d3dx9_base_effect_get_function(&effect->base_effect, index);
2673 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, const char *name)
2675 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2677 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
2679 return d3dx9_base_effect_get_function_by_name(&effect->base_effect, name);
2682 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
2684 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2686 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
2688 return d3dx9_base_effect_get_annotation(&effect->base_effect, object, index);
2691 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface,
2692 D3DXHANDLE object, const char *name)
2694 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2696 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
2698 return d3dx9_base_effect_get_annotation_by_name(&effect->base_effect, object, name);
2701 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface,
2702 D3DXHANDLE parameter, const void *data, UINT bytes)
2704 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2706 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
2708 return d3dx9_base_effect_set_value(&effect->base_effect, parameter, data, bytes);
2711 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface,
2712 D3DXHANDLE parameter, void *data, UINT bytes)
2714 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2716 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
2718 return d3dx9_base_effect_get_value(&effect->base_effect, parameter, data, bytes);
2721 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
2723 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2725 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
2727 return d3dx9_base_effect_set_bool(&effect->base_effect, parameter, b);
2730 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
2732 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2734 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
2736 return d3dx9_base_effect_get_bool(&effect->base_effect, parameter, b);
2739 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface,
2740 D3DXHANDLE parameter, const BOOL *b, UINT count)
2742 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2744 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
2746 return d3dx9_base_effect_set_bool_array(&effect->base_effect, parameter, b, count);
2749 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface,
2750 D3DXHANDLE parameter, BOOL *b, UINT count)
2752 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2754 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
2756 return d3dx9_base_effect_get_bool_array(&effect->base_effect, parameter, b, count);
2759 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
2761 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2763 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
2765 return d3dx9_base_effect_set_int(&effect->base_effect, parameter, n);
2768 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
2770 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2772 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
2774 return d3dx9_base_effect_get_int(&effect->base_effect, parameter, n);
2777 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface,
2778 D3DXHANDLE parameter, const INT *n, UINT count)
2780 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2782 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
2784 return d3dx9_base_effect_set_int_array(&effect->base_effect, parameter, n, count);
2787 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface,
2788 D3DXHANDLE parameter, INT *n, UINT count)
2790 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2792 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
2794 return d3dx9_base_effect_get_int_array(&effect->base_effect, parameter, n, count);
2797 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float f)
2799 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2801 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
2803 return d3dx9_base_effect_set_float(&effect->base_effect, parameter, f);
2806 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float *f)
2808 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2810 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
2812 return d3dx9_base_effect_get_float(&effect->base_effect, parameter, f);
2815 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface,
2816 D3DXHANDLE parameter, const float *f, UINT count)
2818 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2820 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
2822 return d3dx9_base_effect_set_float_array(&effect->base_effect, parameter, f, count);
2825 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface,
2826 D3DXHANDLE parameter, float *f, UINT count)
2828 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2830 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
2832 return d3dx9_base_effect_get_float_array(&effect->base_effect, parameter, f, count);
2835 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface,
2836 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
2838 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2840 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
2842 return d3dx9_base_effect_set_vector(&effect->base_effect, parameter, vector);
2845 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface,
2846 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
2848 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2850 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
2852 return d3dx9_base_effect_get_vector(&effect->base_effect, parameter, vector);
2855 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface,
2856 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
2858 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2860 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
2862 return d3dx9_base_effect_set_vector_array(&effect->base_effect, parameter, vector, count);
2865 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface,
2866 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
2868 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2870 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
2872 return d3dx9_base_effect_get_vector_array(&effect->base_effect, parameter, vector, count);
2875 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface,
2876 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2878 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2880 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2882 return d3dx9_base_effect_set_matrix(&effect->base_effect, parameter, matrix);
2885 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface,
2886 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2888 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2890 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2892 return d3dx9_base_effect_get_matrix(&effect->base_effect, parameter, matrix);
2895 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface,
2896 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2898 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2900 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2902 return d3dx9_base_effect_set_matrix_array(&effect->base_effect, parameter, matrix, count);
2905 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface,
2906 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2908 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2910 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2912 return d3dx9_base_effect_get_matrix_array(&effect->base_effect, parameter, matrix, count);
2915 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface,
2916 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2918 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2920 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2922 return d3dx9_base_effect_set_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
2925 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface,
2926 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2928 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2930 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2932 return d3dx9_base_effect_get_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
2935 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface,
2936 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2938 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2940 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2942 return d3dx9_base_effect_set_matrix_transpose(&effect->base_effect, parameter, matrix);
2945 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface,
2946 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2948 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2950 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2952 return d3dx9_base_effect_get_matrix_transpose(&effect->base_effect, parameter, matrix);
2955 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface,
2956 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2958 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2960 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2962 return d3dx9_base_effect_set_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
2965 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface,
2966 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2968 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2970 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2972 return d3dx9_base_effect_get_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
2975 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface,
2976 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2978 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2980 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2982 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
2985 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface,
2986 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2988 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2990 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2992 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
2995 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char *string)
2997 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2999 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
3001 return d3dx9_base_effect_set_string(&effect->base_effect, parameter, string);
3004 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char **string)
3006 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3008 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
3010 return d3dx9_base_effect_get_string(&effect->base_effect, parameter, string);
3013 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(struct ID3DXEffect *iface,
3014 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
3016 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3018 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3020 return d3dx9_base_effect_set_texture(&effect->base_effect, parameter, texture);
3023 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(struct ID3DXEffect *iface,
3024 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
3026 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3028 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3030 return d3dx9_base_effect_get_texture(&effect->base_effect, parameter, texture);
3033 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface,
3034 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
3036 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3038 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3040 return d3dx9_base_effect_get_pixel_shader(&effect->base_effect, parameter, shader);
3043 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(struct ID3DXEffect *iface,
3044 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
3046 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3048 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3050 return d3dx9_base_effect_get_vertex_shader(&effect->base_effect, parameter, shader);
3053 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3055 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3057 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
3059 return d3dx9_base_effect_set_array_range(&effect->base_effect, parameter, start, end);
3062 /*** ID3DXEffect methods ***/
3063 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, ID3DXEffectPool **pool)
3065 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3067 TRACE("iface %p, pool %p\n", This, pool);
3069 if (!pool)
3071 WARN("Invalid argument supplied.\n");
3072 return D3DERR_INVALIDCALL;
3075 if (This->pool)
3077 This->pool->lpVtbl->AddRef(This->pool);
3080 *pool = This->pool;
3082 TRACE("Returning pool %p\n", *pool);
3084 return S_OK;
3087 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3089 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3090 struct d3dx9_base_effect *base = &This->base_effect;
3091 struct d3dx_technique *tech = get_valid_technique(base, technique);
3093 TRACE("iface %p, technique %p\n", This, technique);
3095 if (tech)
3097 This->active_technique = tech;
3098 TRACE("Technique %p\n", tech);
3099 return D3D_OK;
3102 WARN("Technique not found.\n");
3104 return D3DERR_INVALIDCALL;
3107 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3109 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3111 TRACE("iface %p\n", This);
3113 return get_technique_handle(This->active_technique);
3116 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3118 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3120 FIXME("(%p)->(%p): stub\n", This, technique);
3122 return D3D_OK;
3125 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3127 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3129 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3131 return E_NOTIMPL;
3134 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
3136 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3138 FIXME("(%p)->(%p, %p): stub\n", This, parameter, technique);
3140 return FALSE;
3143 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
3145 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3146 struct d3dx_technique *technique = This->active_technique;
3148 TRACE("iface %p, passes %p, flags %#x.\n", iface, passes, flags);
3150 if (passes && technique)
3152 if (flags & ~(D3DXFX_DONOTSAVESTATE | D3DXFX_DONOTSAVESAMPLERSTATE | D3DXFX_DONOTSAVESHADERSTATE))
3153 WARN("Invalid flags (%#x) specified.\n", flags);
3155 if (This->manager || flags & D3DXFX_DONOTSAVESTATE)
3157 TRACE("State capturing disabled.\n");
3159 else
3161 FIXME("State capturing not supported, yet!\n");
3164 *passes = technique->pass_count;
3165 This->started = TRUE;
3166 This->flags = flags;
3168 return D3D_OK;
3171 WARN("Invalid argument supplied.\n");
3173 return D3DERR_INVALIDCALL;
3176 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
3178 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3179 struct d3dx_technique *technique = This->active_technique;
3181 TRACE("iface %p, pass %u\n", This, pass);
3183 if (technique && pass < technique->pass_count && !This->active_pass)
3185 This->active_pass = &technique->passes[pass];
3187 FIXME("No states applied, yet!\n");
3189 return D3D_OK;
3192 WARN("Invalid argument supplied.\n");
3194 return D3DERR_INVALIDCALL;
3197 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect* iface)
3199 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3201 FIXME("(%p)->(): stub\n", This);
3203 if (!This->active_pass)
3205 WARN("Called without an active pass.\n");
3206 return D3D_OK;
3209 return E_NOTIMPL;
3212 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
3214 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3216 TRACE("iface %p\n", This);
3218 if (This->active_pass)
3220 This->active_pass = NULL;
3221 return D3D_OK;
3224 WARN("Invalid call.\n");
3226 return D3DERR_INVALIDCALL;
3229 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect *iface)
3231 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3233 TRACE("iface %p.\n", iface);
3235 if (!This->started)
3236 return D3D_OK;
3238 if (This->manager || This->flags & D3DXFX_DONOTSAVESTATE)
3240 TRACE("State restoring disabled.\n");
3242 else
3244 FIXME("State restoring not supported, yet!\n");
3247 This->started = FALSE;
3249 return D3D_OK;
3252 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, struct IDirect3DDevice9 **device)
3254 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3256 TRACE("iface %p, device %p\n", This, device);
3258 if (!device)
3260 WARN("Invalid argument supplied.\n");
3261 return D3DERR_INVALIDCALL;
3264 IDirect3DDevice9_AddRef(This->device);
3266 *device = This->device;
3268 TRACE("Returning device %p\n", *device);
3270 return S_OK;
3273 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
3275 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3277 FIXME("(%p)->(): stub\n", This);
3279 return E_NOTIMPL;
3282 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(ID3DXEffect* iface)
3284 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3286 FIXME("(%p)->(): stub\n", This);
3288 return E_NOTIMPL;
3291 static HRESULT WINAPI ID3DXEffectImpl_SetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager *manager)
3293 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3295 TRACE("iface %p, manager %p\n", This, manager);
3297 if (manager) IUnknown_AddRef(manager);
3298 if (This->manager) IUnknown_Release(This->manager);
3300 This->manager = manager;
3302 return D3D_OK;
3305 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager **manager)
3307 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3309 TRACE("iface %p, manager %p\n", This, manager);
3311 if (!manager)
3313 WARN("Invalid argument supplied.\n");
3314 return D3DERR_INVALIDCALL;
3317 if (This->manager) IUnknown_AddRef(This->manager);
3318 *manager = This->manager;
3320 return D3D_OK;
3323 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
3325 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3327 FIXME("(%p)->(): stub\n", This);
3329 return E_NOTIMPL;
3332 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
3334 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3336 FIXME("(%p)->(): stub\n", This);
3338 return NULL;
3341 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3343 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3345 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3347 return E_NOTIMPL;
3350 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3352 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3354 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3356 return E_NOTIMPL;
3359 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect *iface,
3360 struct IDirect3DDevice9 *device, struct ID3DXEffect **effect)
3362 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3364 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
3366 return E_NOTIMPL;
3369 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect *iface,
3370 D3DXHANDLE parameter, const void *data, UINT byte_offset, UINT bytes)
3372 FIXME("iface %p, parameter %p, data %p, byte_offset %u, bytes %u stub!\n",
3373 iface, parameter, data, byte_offset, bytes);
3375 return E_NOTIMPL;
3378 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
3380 /*** IUnknown methods ***/
3381 ID3DXEffectImpl_QueryInterface,
3382 ID3DXEffectImpl_AddRef,
3383 ID3DXEffectImpl_Release,
3384 /*** ID3DXBaseEffect methods ***/
3385 ID3DXEffectImpl_GetDesc,
3386 ID3DXEffectImpl_GetParameterDesc,
3387 ID3DXEffectImpl_GetTechniqueDesc,
3388 ID3DXEffectImpl_GetPassDesc,
3389 ID3DXEffectImpl_GetFunctionDesc,
3390 ID3DXEffectImpl_GetParameter,
3391 ID3DXEffectImpl_GetParameterByName,
3392 ID3DXEffectImpl_GetParameterBySemantic,
3393 ID3DXEffectImpl_GetParameterElement,
3394 ID3DXEffectImpl_GetTechnique,
3395 ID3DXEffectImpl_GetTechniqueByName,
3396 ID3DXEffectImpl_GetPass,
3397 ID3DXEffectImpl_GetPassByName,
3398 ID3DXEffectImpl_GetFunction,
3399 ID3DXEffectImpl_GetFunctionByName,
3400 ID3DXEffectImpl_GetAnnotation,
3401 ID3DXEffectImpl_GetAnnotationByName,
3402 ID3DXEffectImpl_SetValue,
3403 ID3DXEffectImpl_GetValue,
3404 ID3DXEffectImpl_SetBool,
3405 ID3DXEffectImpl_GetBool,
3406 ID3DXEffectImpl_SetBoolArray,
3407 ID3DXEffectImpl_GetBoolArray,
3408 ID3DXEffectImpl_SetInt,
3409 ID3DXEffectImpl_GetInt,
3410 ID3DXEffectImpl_SetIntArray,
3411 ID3DXEffectImpl_GetIntArray,
3412 ID3DXEffectImpl_SetFloat,
3413 ID3DXEffectImpl_GetFloat,
3414 ID3DXEffectImpl_SetFloatArray,
3415 ID3DXEffectImpl_GetFloatArray,
3416 ID3DXEffectImpl_SetVector,
3417 ID3DXEffectImpl_GetVector,
3418 ID3DXEffectImpl_SetVectorArray,
3419 ID3DXEffectImpl_GetVectorArray,
3420 ID3DXEffectImpl_SetMatrix,
3421 ID3DXEffectImpl_GetMatrix,
3422 ID3DXEffectImpl_SetMatrixArray,
3423 ID3DXEffectImpl_GetMatrixArray,
3424 ID3DXEffectImpl_SetMatrixPointerArray,
3425 ID3DXEffectImpl_GetMatrixPointerArray,
3426 ID3DXEffectImpl_SetMatrixTranspose,
3427 ID3DXEffectImpl_GetMatrixTranspose,
3428 ID3DXEffectImpl_SetMatrixTransposeArray,
3429 ID3DXEffectImpl_GetMatrixTransposeArray,
3430 ID3DXEffectImpl_SetMatrixTransposePointerArray,
3431 ID3DXEffectImpl_GetMatrixTransposePointerArray,
3432 ID3DXEffectImpl_SetString,
3433 ID3DXEffectImpl_GetString,
3434 ID3DXEffectImpl_SetTexture,
3435 ID3DXEffectImpl_GetTexture,
3436 ID3DXEffectImpl_GetPixelShader,
3437 ID3DXEffectImpl_GetVertexShader,
3438 ID3DXEffectImpl_SetArrayRange,
3439 /*** ID3DXEffect methods ***/
3440 ID3DXEffectImpl_GetPool,
3441 ID3DXEffectImpl_SetTechnique,
3442 ID3DXEffectImpl_GetCurrentTechnique,
3443 ID3DXEffectImpl_ValidateTechnique,
3444 ID3DXEffectImpl_FindNextValidTechnique,
3445 ID3DXEffectImpl_IsParameterUsed,
3446 ID3DXEffectImpl_Begin,
3447 ID3DXEffectImpl_BeginPass,
3448 ID3DXEffectImpl_CommitChanges,
3449 ID3DXEffectImpl_EndPass,
3450 ID3DXEffectImpl_End,
3451 ID3DXEffectImpl_GetDevice,
3452 ID3DXEffectImpl_OnLostDevice,
3453 ID3DXEffectImpl_OnResetDevice,
3454 ID3DXEffectImpl_SetStateManager,
3455 ID3DXEffectImpl_GetStateManager,
3456 ID3DXEffectImpl_BeginParameterBlock,
3457 ID3DXEffectImpl_EndParameterBlock,
3458 ID3DXEffectImpl_ApplyParameterBlock,
3459 ID3DXEffectImpl_DeleteParameterBlock,
3460 ID3DXEffectImpl_CloneEffect,
3461 ID3DXEffectImpl_SetRawValue
3464 static inline struct ID3DXEffectCompilerImpl *impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler *iface)
3466 return CONTAINING_RECORD(iface, struct ID3DXEffectCompilerImpl, ID3DXEffectCompiler_iface);
3469 /*** IUnknown methods ***/
3470 static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler *iface, REFIID riid, void **object)
3472 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
3474 if (IsEqualGUID(riid, &IID_IUnknown) ||
3475 IsEqualGUID(riid, &IID_ID3DXEffectCompiler))
3477 iface->lpVtbl->AddRef(iface);
3478 *object = iface;
3479 return S_OK;
3482 ERR("Interface %s not found\n", debugstr_guid(riid));
3484 return E_NOINTERFACE;
3487 static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface)
3489 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3491 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
3493 return InterlockedIncrement(&This->ref);
3496 static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface)
3498 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3499 ULONG ref = InterlockedDecrement(&This->ref);
3501 TRACE("iface %p: Release from %u\n", iface, ref + 1);
3503 if (!ref)
3505 free_effect_compiler(This);
3506 HeapFree(GetProcessHeap(), 0, This);
3509 return ref;
3512 /*** ID3DXBaseEffect methods ***/
3513 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler *iface, D3DXEFFECT_DESC *desc)
3515 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3517 TRACE("iface %p, desc %p.\n", iface, desc);
3519 return d3dx9_base_effect_get_desc(&compiler->base_effect, desc);
3522 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler *iface,
3523 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
3525 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3527 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
3529 return d3dx9_base_effect_get_parameter_desc(&compiler->base_effect, parameter, desc);
3532 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler *iface,
3533 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
3535 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3537 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
3539 return d3dx9_base_effect_get_technique_desc(&compiler->base_effect, technique, desc);
3542 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler *iface,
3543 D3DXHANDLE pass, D3DXPASS_DESC *desc)
3545 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3547 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
3549 return d3dx9_base_effect_get_pass_desc(&compiler->base_effect, pass, desc);
3552 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler *iface,
3553 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
3555 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3557 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
3559 return d3dx9_base_effect_get_function_desc(&compiler->base_effect, shader, desc);
3562 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler *iface,
3563 D3DXHANDLE parameter, UINT index)
3565 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3567 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3569 return d3dx9_base_effect_get_parameter(&compiler->base_effect, parameter, index);
3572 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler *iface,
3573 D3DXHANDLE parameter, const char *name)
3575 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3577 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
3579 return d3dx9_base_effect_get_parameter_by_name(&compiler->base_effect, parameter, name);
3582 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler *iface,
3583 D3DXHANDLE parameter, const char *semantic)
3585 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3587 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
3589 return d3dx9_base_effect_get_parameter_by_semantic(&compiler->base_effect, parameter, semantic);
3592 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler *iface,
3593 D3DXHANDLE parameter, UINT index)
3595 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3597 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
3599 return d3dx9_base_effect_get_parameter_element(&compiler->base_effect, parameter, index);
3602 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler *iface, UINT index)
3604 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3606 TRACE("iface %p, index %u.\n", iface, index);
3608 return d3dx9_base_effect_get_technique(&compiler->base_effect, index);
3611 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler *iface, const char *name)
3613 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3615 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3617 return d3dx9_base_effect_get_technique_by_name(&compiler->base_effect, name);
3620 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler *iface, D3DXHANDLE technique, UINT index)
3622 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3624 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
3626 return d3dx9_base_effect_get_pass(&compiler->base_effect, technique, index);
3629 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler *iface,
3630 D3DXHANDLE technique, const char *name)
3632 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3634 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
3636 return d3dx9_base_effect_get_pass_by_name(&compiler->base_effect, technique, name);
3639 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler *iface, UINT index)
3641 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3643 TRACE("iface %p, index %u.\n", iface, index);
3645 return d3dx9_base_effect_get_function(&compiler->base_effect, index);
3648 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler *iface, const char *name)
3650 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3652 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
3654 return d3dx9_base_effect_get_function_by_name(&compiler->base_effect, name);
3657 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler *iface,
3658 D3DXHANDLE object, UINT index)
3660 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3662 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
3664 return d3dx9_base_effect_get_annotation(&compiler->base_effect, object, index);
3667 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler *iface,
3668 D3DXHANDLE object, const char *name)
3670 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3672 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
3674 return d3dx9_base_effect_get_annotation_by_name(&compiler->base_effect, object, name);
3677 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler *iface,
3678 D3DXHANDLE parameter, const void *data, UINT bytes)
3680 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3682 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3684 return d3dx9_base_effect_set_value(&compiler->base_effect, parameter, data, bytes);
3687 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler *iface,
3688 D3DXHANDLE parameter, void *data, UINT bytes)
3690 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3692 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
3694 return d3dx9_base_effect_get_value(&compiler->base_effect, parameter, data, bytes);
3697 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL b)
3699 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3701 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
3703 return d3dx9_base_effect_set_bool(&compiler->base_effect, parameter, b);
3706 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b)
3708 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3710 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
3712 return d3dx9_base_effect_get_bool(&compiler->base_effect, parameter, b);
3715 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler *iface,
3716 D3DXHANDLE parameter, const BOOL *b, UINT count)
3718 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3720 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3722 return d3dx9_base_effect_set_bool_array(&compiler->base_effect, parameter, b, count);
3725 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler *iface,
3726 D3DXHANDLE parameter, BOOL *b, UINT count)
3728 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3730 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
3732 return d3dx9_base_effect_get_bool_array(&compiler->base_effect, parameter, b, count);
3735 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT n)
3737 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3739 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
3741 return d3dx9_base_effect_set_int(&compiler->base_effect, parameter, n);
3744 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n)
3746 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3748 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
3750 return d3dx9_base_effect_get_int(&compiler->base_effect, parameter, n);
3753 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler *iface,
3754 D3DXHANDLE parameter, const INT *n, UINT count)
3756 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3758 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3760 return d3dx9_base_effect_set_int_array(&compiler->base_effect, parameter, n, count);
3763 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler *iface,
3764 D3DXHANDLE parameter, INT *n, UINT count)
3766 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3768 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
3770 return d3dx9_base_effect_get_int_array(&compiler->base_effect, parameter, n, count);
3773 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float f)
3775 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3777 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
3779 return d3dx9_base_effect_set_float(&compiler->base_effect, parameter, f);
3782 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, float *f)
3784 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3786 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
3788 return d3dx9_base_effect_get_float(&compiler->base_effect, parameter, f);
3791 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler *iface,
3792 D3DXHANDLE parameter, const float *f, UINT count)
3794 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3796 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3798 return d3dx9_base_effect_set_float_array(&compiler->base_effect, parameter, f, count);
3801 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler *iface,
3802 D3DXHANDLE parameter, float *f, UINT count)
3804 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3806 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
3808 return d3dx9_base_effect_get_float_array(&compiler->base_effect, parameter, f, count);
3811 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler *iface,
3812 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
3814 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3816 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3818 return d3dx9_base_effect_set_vector(&compiler->base_effect, parameter, vector);
3821 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler *iface,
3822 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
3824 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3826 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
3828 return d3dx9_base_effect_get_vector(&compiler->base_effect, parameter, vector);
3831 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler *iface,
3832 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
3834 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3836 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3838 return d3dx9_base_effect_set_vector_array(&compiler->base_effect, parameter, vector, count);
3841 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler *iface,
3842 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
3844 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3846 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
3848 return d3dx9_base_effect_get_vector_array(&compiler->base_effect, parameter, vector, count);
3851 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler *iface,
3852 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3854 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3856 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3858 return d3dx9_base_effect_set_matrix(&compiler->base_effect, parameter, matrix);
3861 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler *iface,
3862 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3864 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3866 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3868 return d3dx9_base_effect_get_matrix(&compiler->base_effect, parameter, matrix);
3871 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler *iface,
3872 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3874 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3876 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3878 return d3dx9_base_effect_set_matrix_array(&compiler->base_effect, parameter, matrix, count);
3881 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler *iface,
3882 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3884 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3886 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3888 return d3dx9_base_effect_get_matrix_array(&compiler->base_effect, parameter, matrix, count);
3891 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler *iface,
3892 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3894 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3896 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3898 return d3dx9_base_effect_set_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
3901 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler *iface,
3902 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3904 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3906 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3908 return d3dx9_base_effect_get_matrix_pointer_array(&compiler->base_effect, parameter, matrix, count);
3911 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler *iface,
3912 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
3914 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3916 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3918 return d3dx9_base_effect_set_matrix_transpose(&compiler->base_effect, parameter, matrix);
3921 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler *iface,
3922 D3DXHANDLE parameter, D3DXMATRIX *matrix)
3924 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3926 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
3928 return d3dx9_base_effect_get_matrix_transpose(&compiler->base_effect, parameter, matrix);
3931 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler *iface,
3932 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
3934 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3936 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3938 return d3dx9_base_effect_set_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
3941 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler *iface,
3942 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3944 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3946 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3948 return d3dx9_base_effect_get_matrix_transpose_array(&compiler->base_effect, parameter, matrix, count);
3951 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
3952 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
3954 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3956 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3958 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
3961 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler *iface,
3962 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3964 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3966 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
3968 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&compiler->base_effect, parameter, matrix, count);
3971 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler *iface,
3972 D3DXHANDLE parameter, const char *string)
3974 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3976 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
3978 return d3dx9_base_effect_set_string(&compiler->base_effect, parameter, string);
3981 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler *iface,
3982 D3DXHANDLE parameter, const char **string)
3984 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3986 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
3988 return d3dx9_base_effect_get_string(&compiler->base_effect, parameter, string);
3991 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetTexture(struct ID3DXEffectCompiler *iface,
3992 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
3994 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
3996 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3998 return d3dx9_base_effect_set_texture(&compiler->base_effect, parameter, texture);
4001 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTexture(struct ID3DXEffectCompiler *iface,
4002 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
4004 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4006 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
4008 return d3dx9_base_effect_get_texture(&compiler->base_effect, parameter, texture);
4011 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler *iface,
4012 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
4014 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4016 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4018 return d3dx9_base_effect_get_pixel_shader(&compiler->base_effect, parameter, shader);
4021 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVertexShader(struct ID3DXEffectCompiler *iface,
4022 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
4024 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4026 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
4028 return d3dx9_base_effect_get_vertex_shader(&compiler->base_effect, parameter, shader);
4031 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler *iface,
4032 D3DXHANDLE parameter, UINT start, UINT end)
4034 struct ID3DXEffectCompilerImpl *compiler = impl_from_ID3DXEffectCompiler(iface);
4036 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
4038 return d3dx9_base_effect_set_array_range(&compiler->base_effect, parameter, start, end);
4041 /*** ID3DXEffectCompiler methods ***/
4042 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL literal)
4044 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4046 FIXME("iface %p, parameter %p, literal %u\n", This, parameter, literal);
4048 return E_NOTIMPL;
4051 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *literal)
4053 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4055 FIXME("iface %p, parameter %p, literal %p\n", This, parameter, literal);
4057 return E_NOTIMPL;
4060 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler *iface, DWORD flags,
4061 ID3DXBuffer **effect, ID3DXBuffer **error_msgs)
4063 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4065 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub\n", This, flags, effect, error_msgs);
4067 return E_NOTIMPL;
4070 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler *iface, D3DXHANDLE function,
4071 const char *target, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_msgs,
4072 ID3DXConstantTable **constant_table)
4074 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4076 FIXME("iface %p, function %p, target %p, flags %#x, shader %p, error_msgs %p, constant_table %p stub\n",
4077 This, function, target, flags, shader, error_msgs, constant_table);
4079 return E_NOTIMPL;
4082 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
4084 /*** IUnknown methods ***/
4085 ID3DXEffectCompilerImpl_QueryInterface,
4086 ID3DXEffectCompilerImpl_AddRef,
4087 ID3DXEffectCompilerImpl_Release,
4088 /*** ID3DXBaseEffect methods ***/
4089 ID3DXEffectCompilerImpl_GetDesc,
4090 ID3DXEffectCompilerImpl_GetParameterDesc,
4091 ID3DXEffectCompilerImpl_GetTechniqueDesc,
4092 ID3DXEffectCompilerImpl_GetPassDesc,
4093 ID3DXEffectCompilerImpl_GetFunctionDesc,
4094 ID3DXEffectCompilerImpl_GetParameter,
4095 ID3DXEffectCompilerImpl_GetParameterByName,
4096 ID3DXEffectCompilerImpl_GetParameterBySemantic,
4097 ID3DXEffectCompilerImpl_GetParameterElement,
4098 ID3DXEffectCompilerImpl_GetTechnique,
4099 ID3DXEffectCompilerImpl_GetTechniqueByName,
4100 ID3DXEffectCompilerImpl_GetPass,
4101 ID3DXEffectCompilerImpl_GetPassByName,
4102 ID3DXEffectCompilerImpl_GetFunction,
4103 ID3DXEffectCompilerImpl_GetFunctionByName,
4104 ID3DXEffectCompilerImpl_GetAnnotation,
4105 ID3DXEffectCompilerImpl_GetAnnotationByName,
4106 ID3DXEffectCompilerImpl_SetValue,
4107 ID3DXEffectCompilerImpl_GetValue,
4108 ID3DXEffectCompilerImpl_SetBool,
4109 ID3DXEffectCompilerImpl_GetBool,
4110 ID3DXEffectCompilerImpl_SetBoolArray,
4111 ID3DXEffectCompilerImpl_GetBoolArray,
4112 ID3DXEffectCompilerImpl_SetInt,
4113 ID3DXEffectCompilerImpl_GetInt,
4114 ID3DXEffectCompilerImpl_SetIntArray,
4115 ID3DXEffectCompilerImpl_GetIntArray,
4116 ID3DXEffectCompilerImpl_SetFloat,
4117 ID3DXEffectCompilerImpl_GetFloat,
4118 ID3DXEffectCompilerImpl_SetFloatArray,
4119 ID3DXEffectCompilerImpl_GetFloatArray,
4120 ID3DXEffectCompilerImpl_SetVector,
4121 ID3DXEffectCompilerImpl_GetVector,
4122 ID3DXEffectCompilerImpl_SetVectorArray,
4123 ID3DXEffectCompilerImpl_GetVectorArray,
4124 ID3DXEffectCompilerImpl_SetMatrix,
4125 ID3DXEffectCompilerImpl_GetMatrix,
4126 ID3DXEffectCompilerImpl_SetMatrixArray,
4127 ID3DXEffectCompilerImpl_GetMatrixArray,
4128 ID3DXEffectCompilerImpl_SetMatrixPointerArray,
4129 ID3DXEffectCompilerImpl_GetMatrixPointerArray,
4130 ID3DXEffectCompilerImpl_SetMatrixTranspose,
4131 ID3DXEffectCompilerImpl_GetMatrixTranspose,
4132 ID3DXEffectCompilerImpl_SetMatrixTransposeArray,
4133 ID3DXEffectCompilerImpl_GetMatrixTransposeArray,
4134 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray,
4135 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray,
4136 ID3DXEffectCompilerImpl_SetString,
4137 ID3DXEffectCompilerImpl_GetString,
4138 ID3DXEffectCompilerImpl_SetTexture,
4139 ID3DXEffectCompilerImpl_GetTexture,
4140 ID3DXEffectCompilerImpl_GetPixelShader,
4141 ID3DXEffectCompilerImpl_GetVertexShader,
4142 ID3DXEffectCompilerImpl_SetArrayRange,
4143 /*** ID3DXEffectCompiler methods ***/
4144 ID3DXEffectCompilerImpl_SetLiteral,
4145 ID3DXEffectCompilerImpl_GetLiteral,
4146 ID3DXEffectCompilerImpl_CompileEffect,
4147 ID3DXEffectCompilerImpl_CompileShader,
4150 static HRESULT d3dx9_parse_sampler(struct d3dx9_base_effect *base, struct d3dx_sampler *sampler,
4151 const char *data, const char **ptr, struct d3dx_object *objects)
4153 HRESULT hr;
4154 UINT i;
4156 read_dword(ptr, &sampler->state_count);
4157 TRACE("Count: %u\n", sampler->state_count);
4159 sampler->states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler->states) * sampler->state_count);
4160 if (!sampler->states)
4162 ERR("Out of memory\n");
4163 return E_OUTOFMEMORY;
4166 for (i = 0; i < sampler->state_count; ++i)
4168 hr = d3dx9_parse_state(base, &sampler->states[i], data, ptr, objects);
4169 if (hr != D3D_OK)
4171 WARN("Failed to parse state %u\n", i);
4172 goto err_out;
4176 return D3D_OK;
4178 err_out:
4180 for (i = 0; i < sampler->state_count; ++i)
4182 free_state(&sampler->states[i]);
4184 HeapFree(GetProcessHeap(), 0, sampler->states);
4185 sampler->states = NULL;
4187 return hr;
4190 static HRESULT d3dx9_parse_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4191 void *value, const char *data, const char **ptr, struct d3dx_object *objects)
4193 unsigned int i;
4194 HRESULT hr;
4195 UINT old_size = 0;
4197 if (param->element_count)
4199 param->data = value;
4201 for (i = 0; i < param->element_count; ++i)
4203 struct d3dx_parameter *member = &param->members[i];
4205 hr = d3dx9_parse_value(base, member, value ? (char *)value + old_size : NULL, data, ptr, objects);
4206 if (hr != D3D_OK)
4208 WARN("Failed to parse value %u\n", i);
4209 return hr;
4212 old_size += member->bytes;
4215 return D3D_OK;
4218 switch(param->class)
4220 case D3DXPC_SCALAR:
4221 case D3DXPC_VECTOR:
4222 case D3DXPC_MATRIX_ROWS:
4223 case D3DXPC_MATRIX_COLUMNS:
4224 param->data = value;
4225 break;
4227 case D3DXPC_STRUCT:
4228 param->data = value;
4230 for (i = 0; i < param->member_count; ++i)
4232 struct d3dx_parameter *member = &param->members[i];
4234 hr = d3dx9_parse_value(base, member, (char *)value + old_size, data, ptr, objects);
4235 if (hr != D3D_OK)
4237 WARN("Failed to parse value %u\n", i);
4238 return hr;
4241 old_size += member->bytes;
4243 break;
4245 case D3DXPC_OBJECT:
4246 switch (param->type)
4248 case D3DXPT_STRING:
4249 case D3DXPT_TEXTURE:
4250 case D3DXPT_TEXTURE1D:
4251 case D3DXPT_TEXTURE2D:
4252 case D3DXPT_TEXTURE3D:
4253 case D3DXPT_TEXTURECUBE:
4254 case D3DXPT_PIXELSHADER:
4255 case D3DXPT_VERTEXSHADER:
4256 read_dword(ptr, &param->object_id);
4257 TRACE("Id: %u\n", param->object_id);
4258 objects[param->object_id].param = param;
4259 param->data = value;
4260 break;
4262 case D3DXPT_SAMPLER:
4263 case D3DXPT_SAMPLER1D:
4264 case D3DXPT_SAMPLER2D:
4265 case D3DXPT_SAMPLER3D:
4266 case D3DXPT_SAMPLERCUBE:
4268 struct d3dx_sampler *sampler;
4270 sampler = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler));
4271 if (!sampler)
4272 return E_OUTOFMEMORY;
4274 hr = d3dx9_parse_sampler(base, sampler, data, ptr, objects);
4275 if (hr != D3D_OK)
4277 HeapFree(GetProcessHeap(), 0, sampler);
4278 WARN("Failed to parse sampler\n");
4279 return hr;
4282 param->data = sampler;
4283 break;
4286 default:
4287 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4288 break;
4290 break;
4292 default:
4293 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4294 break;
4297 return D3D_OK;
4300 static HRESULT d3dx9_parse_init_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4301 const char *data, const char *ptr, struct d3dx_object *objects)
4303 UINT size = param->bytes;
4304 HRESULT hr;
4305 void *value = NULL;
4307 TRACE("param size: %u\n", size);
4309 if (size)
4311 value = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4312 if (!value)
4314 ERR("Failed to allocate data memory.\n");
4315 return E_OUTOFMEMORY;
4318 switch(param->class)
4320 case D3DXPC_OBJECT:
4321 break;
4323 case D3DXPC_SCALAR:
4324 case D3DXPC_VECTOR:
4325 case D3DXPC_MATRIX_ROWS:
4326 case D3DXPC_MATRIX_COLUMNS:
4327 case D3DXPC_STRUCT:
4328 TRACE("Data: %s.\n", debugstr_an(ptr, size));
4329 memcpy(value, ptr, size);
4330 break;
4332 default:
4333 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4334 break;
4338 hr = d3dx9_parse_value(base, param, value, data, &ptr, objects);
4339 if (hr != D3D_OK)
4341 WARN("Failed to parse value\n");
4342 HeapFree(GetProcessHeap(), 0, value);
4343 return hr;
4346 return D3D_OK;
4349 static HRESULT d3dx9_parse_name(char **name, const char *ptr)
4351 DWORD size;
4353 read_dword(&ptr, &size);
4354 TRACE("Name size: %#x\n", size);
4356 if (!size)
4358 return D3D_OK;
4361 *name = HeapAlloc(GetProcessHeap(), 0, size);
4362 if (!*name)
4364 ERR("Failed to allocate name memory.\n");
4365 return E_OUTOFMEMORY;
4368 TRACE("Name: %s.\n", debugstr_an(ptr, size));
4369 memcpy(*name, ptr, size);
4371 return D3D_OK;
4374 static HRESULT d3dx9_copy_data(struct d3dx_object *object, const char **ptr)
4376 if (object->size || object->data)
4377 FIXME("Object already initialized!\n");
4379 read_dword(ptr, &object->size);
4380 TRACE("Data size: %#x\n", object->size);
4382 if (!object->size)
4383 return D3D_OK;
4385 object->data = HeapAlloc(GetProcessHeap(), 0, object->size);
4386 if (!object->data)
4388 ERR("Failed to allocate object memory.\n");
4389 return E_OUTOFMEMORY;
4392 TRACE("Data: %s.\n", debugstr_an(*ptr, object->size));
4393 memcpy(object->data, *ptr, object->size);
4395 *ptr += ((object->size + 3) & ~3);
4397 return D3D_OK;
4400 static void add_param_to_table(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
4402 struct param_table *table = &base->param_table;
4404 if (table->count >= table->size)
4406 unsigned int new_size;
4407 struct d3dx_parameter **new_alloc;
4409 if (!table->size)
4411 new_size = INITIAL_PARAM_TABLE_SIZE;
4412 new_alloc = HeapAlloc(GetProcessHeap(), 0, sizeof(*table->table) * new_size);
4413 if (!new_alloc)
4415 ERR("Out of memory.\n");
4416 return;
4419 else
4421 new_size = table->size * 2;
4422 new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * new_size);
4423 if (!new_alloc)
4425 ERR("Out of memory.\n");
4426 return;
4429 table->table = new_alloc;
4430 table->size = new_size;
4433 table->table[table->count++] = param;
4436 static void sync_param_handles(struct d3dx9_base_effect *base)
4438 struct param_table *table = &base->param_table;
4439 struct d3dx_parameter **new_alloc;
4440 unsigned int i;
4442 if (table->count)
4444 new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * table->count);
4445 if (new_alloc)
4446 table->table = new_alloc;
4447 else
4448 ERR("Out of memory.\n");
4451 for (i = 0; i < table->count; ++i)
4452 table->table[i]->handle = (D3DXHANDLE)&table->table[i];
4455 static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4456 const char *data, const char **ptr, struct d3dx_parameter *parent, UINT flags)
4458 DWORD offset;
4459 HRESULT hr;
4460 UINT i;
4462 param->flags = flags;
4464 if (!parent)
4466 read_dword(ptr, (DWORD *)&param->type);
4467 TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
4469 read_dword(ptr, (DWORD *)&param->class);
4470 TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
4472 read_dword(ptr, &offset);
4473 TRACE("Type name offset: %#x\n", offset);
4474 hr = d3dx9_parse_name(&param->name, data + offset);
4475 if (hr != D3D_OK)
4477 WARN("Failed to parse name\n");
4478 goto err_out;
4481 read_dword(ptr, &offset);
4482 TRACE("Type semantic offset: %#x\n", offset);
4483 hr = d3dx9_parse_name(&param->semantic, data + offset);
4484 if (hr != D3D_OK)
4486 WARN("Failed to parse semantic\n");
4487 goto err_out;
4490 read_dword(ptr, &param->element_count);
4491 TRACE("Elements: %u\n", param->element_count);
4493 switch (param->class)
4495 case D3DXPC_VECTOR:
4496 read_dword(ptr, &param->columns);
4497 TRACE("Columns: %u\n", param->columns);
4499 read_dword(ptr, &param->rows);
4500 TRACE("Rows: %u\n", param->rows);
4502 /* sizeof(DWORD) * rows * columns */
4503 param->bytes = 4 * param->rows * param->columns;
4504 break;
4506 case D3DXPC_SCALAR:
4507 case D3DXPC_MATRIX_ROWS:
4508 case D3DXPC_MATRIX_COLUMNS:
4509 read_dword(ptr, &param->rows);
4510 TRACE("Rows: %u\n", param->rows);
4512 read_dword(ptr, &param->columns);
4513 TRACE("Columns: %u\n", param->columns);
4515 /* sizeof(DWORD) * rows * columns */
4516 param->bytes = 4 * param->rows * param->columns;
4517 break;
4519 case D3DXPC_STRUCT:
4520 read_dword(ptr, &param->member_count);
4521 TRACE("Members: %u\n", param->member_count);
4522 break;
4524 case D3DXPC_OBJECT:
4525 switch (param->type)
4527 case D3DXPT_STRING:
4528 case D3DXPT_PIXELSHADER:
4529 case D3DXPT_VERTEXSHADER:
4530 case D3DXPT_TEXTURE:
4531 case D3DXPT_TEXTURE1D:
4532 case D3DXPT_TEXTURE2D:
4533 case D3DXPT_TEXTURE3D:
4534 case D3DXPT_TEXTURECUBE:
4535 param->bytes = sizeof(void *);
4536 break;
4538 case D3DXPT_SAMPLER:
4539 case D3DXPT_SAMPLER1D:
4540 case D3DXPT_SAMPLER2D:
4541 case D3DXPT_SAMPLER3D:
4542 case D3DXPT_SAMPLERCUBE:
4543 param->bytes = 0;
4544 break;
4546 default:
4547 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4548 break;
4550 break;
4552 default:
4553 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4554 break;
4557 else
4559 /* elements */
4560 param->type = parent->type;
4561 param->class = parent->class;
4562 param->name = parent->name;
4563 param->semantic = parent->semantic;
4564 param->element_count = 0;
4565 param->annotation_count = 0;
4566 param->member_count = parent->member_count;
4567 param->bytes = parent->bytes;
4568 param->rows = parent->rows;
4569 param->columns = parent->columns;
4572 if (param->element_count)
4574 unsigned int param_bytes = 0;
4575 const char *save_ptr = *ptr;
4577 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->element_count);
4578 if (!param->members)
4580 ERR("Out of memory\n");
4581 hr = E_OUTOFMEMORY;
4582 goto err_out;
4585 for (i = 0; i < param->element_count; ++i)
4587 *ptr = save_ptr;
4589 add_param_to_table(base, &param->members[i]);
4590 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, param, flags);
4591 if (hr != D3D_OK)
4593 WARN("Failed to parse member %u\n", i);
4594 goto err_out;
4597 param_bytes += param->members[i].bytes;
4600 param->bytes = param_bytes;
4602 else if (param->member_count)
4604 param->members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*param->members) * param->member_count);
4605 if (!param->members)
4607 ERR("Out of memory\n");
4608 hr = E_OUTOFMEMORY;
4609 goto err_out;
4612 for (i = 0; i < param->member_count; ++i)
4614 add_param_to_table(base, &param->members[i]);
4615 hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, NULL, flags);
4616 if (hr != D3D_OK)
4618 WARN("Failed to parse member %u\n", i);
4619 goto err_out;
4622 param->bytes += param->members[i].bytes;
4625 return D3D_OK;
4627 err_out:
4629 if (param->members)
4631 unsigned int count = param->element_count ? param->element_count : param->member_count;
4633 for (i = 0; i < count; ++i)
4634 free_parameter(&param->members[i], param->element_count != 0, TRUE);
4635 HeapFree(GetProcessHeap(), 0, param->members);
4636 param->members = NULL;
4639 if (!parent)
4641 HeapFree(GetProcessHeap(), 0, param->name);
4642 HeapFree(GetProcessHeap(), 0, param->semantic);
4644 param->name = NULL;
4645 param->semantic = NULL;
4647 return hr;
4650 static HRESULT d3dx9_parse_effect_annotation(struct d3dx9_base_effect *base, struct d3dx_parameter *anno,
4651 const char *data, const char **ptr, struct d3dx_object *objects)
4653 DWORD offset;
4654 const char *ptr2;
4655 HRESULT hr;
4657 anno->flags = D3DX_PARAMETER_ANNOTATION;
4659 read_dword(ptr, &offset);
4660 TRACE("Typedef offset: %#x\n", offset);
4661 ptr2 = data + offset;
4662 hr = d3dx9_parse_effect_typedef(base, anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
4663 if (hr != D3D_OK)
4665 WARN("Failed to parse type definition\n");
4666 return hr;
4669 read_dword(ptr, &offset);
4670 TRACE("Value offset: %#x\n", offset);
4671 hr = d3dx9_parse_init_value(base, anno, data, data + offset, objects);
4672 if (hr != D3D_OK)
4674 WARN("Failed to parse value\n");
4675 return hr;
4678 return D3D_OK;
4681 static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
4682 const char *data, const char **ptr, struct d3dx_object *objects)
4684 DWORD offset;
4685 const char *ptr2;
4686 HRESULT hr;
4688 state->type = ST_CONSTANT;
4690 read_dword(ptr, &state->operation);
4691 TRACE("Operation: %#x (%s)\n", state->operation, state_table[state->operation].name);
4693 read_dword(ptr, &state->index);
4694 TRACE("Index: %#x\n", state->index);
4696 read_dword(ptr, &offset);
4697 TRACE("Typedef offset: %#x\n", offset);
4698 ptr2 = data + offset;
4699 hr = d3dx9_parse_effect_typedef(base, &state->parameter, data, &ptr2, NULL, 0);
4700 if (hr != D3D_OK)
4702 WARN("Failed to parse type definition\n");
4703 goto err_out;
4706 read_dword(ptr, &offset);
4707 TRACE("Value offset: %#x\n", offset);
4708 hr = d3dx9_parse_init_value(base, &state->parameter, data, data + offset, objects);
4709 if (hr != D3D_OK)
4711 WARN("Failed to parse value\n");
4712 goto err_out;
4715 return D3D_OK;
4717 err_out:
4719 free_parameter(&state->parameter, FALSE, FALSE);
4721 return hr;
4724 static HRESULT d3dx9_parse_effect_parameter(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
4725 const char *data, const char **ptr, struct d3dx_object *objects)
4727 DWORD offset;
4728 HRESULT hr;
4729 unsigned int i;
4730 const char *ptr2;
4732 read_dword(ptr, &offset);
4733 TRACE("Typedef offset: %#x\n", offset);
4734 ptr2 = data + offset;
4736 read_dword(ptr, &offset);
4737 TRACE("Value offset: %#x\n", offset);
4739 read_dword(ptr, &param->flags);
4740 TRACE("Flags: %#x\n", param->flags);
4742 read_dword(ptr, &param->annotation_count);
4743 TRACE("Annotation count: %u\n", param->annotation_count);
4745 hr = d3dx9_parse_effect_typedef(base, param, data, &ptr2, NULL, param->flags);
4746 if (hr != D3D_OK)
4748 WARN("Failed to parse type definition\n");
4749 return hr;
4752 hr = d3dx9_parse_init_value(base, param, data, data + offset, objects);
4753 if (hr != D3D_OK)
4755 WARN("Failed to parse value\n");
4756 return hr;
4759 if (param->annotation_count)
4761 param->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4762 sizeof(*param->annotations) * param->annotation_count);
4763 if (!param->annotations)
4765 ERR("Out of memory\n");
4766 hr = E_OUTOFMEMORY;
4767 goto err_out;
4770 for (i = 0; i < param->annotation_count; ++i)
4772 add_param_to_table(base, &param->annotations[i]);
4773 hr = d3dx9_parse_effect_annotation(base, &param->annotations[i], data, ptr, objects);
4774 if (hr != D3D_OK)
4776 WARN("Failed to parse annotation\n");
4777 goto err_out;
4782 return D3D_OK;
4784 err_out:
4786 if (param->annotations)
4788 for (i = 0; i < param->annotation_count; ++i)
4789 free_parameter(&param->annotations[i], FALSE, FALSE);
4790 HeapFree(GetProcessHeap(), 0, param->annotations);
4791 param->annotations = NULL;
4794 return hr;
4797 static HRESULT d3dx9_parse_effect_pass(struct d3dx9_base_effect *base, struct d3dx_pass *pass,
4798 const char *data, const char **ptr, struct d3dx_object *objects)
4800 DWORD offset;
4801 HRESULT hr;
4802 unsigned int i;
4803 struct d3dx_state *states = NULL;
4804 char *name = NULL;
4806 read_dword(ptr, &offset);
4807 TRACE("Pass name offset: %#x\n", offset);
4808 hr = d3dx9_parse_name(&name, data + offset);
4809 if (hr != D3D_OK)
4811 WARN("Failed to parse name\n");
4812 goto err_out;
4815 read_dword(ptr, &pass->annotation_count);
4816 TRACE("Annotation count: %u\n", pass->annotation_count);
4818 read_dword(ptr, &pass->state_count);
4819 TRACE("State count: %u\n", pass->state_count);
4821 if (pass->annotation_count)
4823 pass->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4824 sizeof(*pass->annotations) * pass->annotation_count);
4825 if (!pass->annotations)
4827 ERR("Out of memory\n");
4828 hr = E_OUTOFMEMORY;
4829 goto err_out;
4832 for (i = 0; i < pass->annotation_count; ++i)
4834 add_param_to_table(base, &pass->annotations[i]);
4835 hr = d3dx9_parse_effect_annotation(base, &pass->annotations[i], data, ptr, objects);
4836 if (hr != D3D_OK)
4838 WARN("Failed to parse annotation %u\n", i);
4839 goto err_out;
4844 if (pass->state_count)
4846 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * pass->state_count);
4847 if (!states)
4849 ERR("Out of memory\n");
4850 hr = E_OUTOFMEMORY;
4851 goto err_out;
4854 for (i = 0; i < pass->state_count; ++i)
4856 hr = d3dx9_parse_state(base, &states[i], data, ptr, objects);
4857 if (hr != D3D_OK)
4859 WARN("Failed to parse annotation %u\n", i);
4860 goto err_out;
4865 pass->name = name;
4866 pass->states = states;
4868 return D3D_OK;
4870 err_out:
4872 if (pass->annotations)
4874 for (i = 0; i < pass->annotation_count; ++i)
4875 free_parameter(&pass->annotations[i], FALSE, FALSE);
4876 HeapFree(GetProcessHeap(), 0, pass->annotations);
4877 pass->annotations = NULL;
4880 if (states)
4882 for (i = 0; i < pass->state_count; ++i)
4884 free_state(&states[i]);
4886 HeapFree(GetProcessHeap(), 0, states);
4889 HeapFree(GetProcessHeap(), 0, name);
4891 return hr;
4894 static HRESULT d3dx9_parse_effect_technique(struct d3dx9_base_effect *base, struct d3dx_technique *technique,
4895 const char *data, const char **ptr, struct d3dx_object *objects)
4897 DWORD offset;
4898 HRESULT hr;
4899 unsigned int i;
4900 char *name = NULL;
4902 read_dword(ptr, &offset);
4903 TRACE("Technique name offset: %#x\n", offset);
4904 hr = d3dx9_parse_name(&name, data + offset);
4905 if (hr != D3D_OK)
4907 WARN("Failed to parse name\n");
4908 goto err_out;
4911 read_dword(ptr, &technique->annotation_count);
4912 TRACE("Annotation count: %u\n", technique->annotation_count);
4914 read_dword(ptr, &technique->pass_count);
4915 TRACE("Pass count: %u\n", technique->pass_count);
4917 if (technique->annotation_count)
4919 technique->annotations = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4920 sizeof(*technique->annotations) * technique->annotation_count);
4921 if (!technique->annotations)
4923 ERR("Out of memory\n");
4924 hr = E_OUTOFMEMORY;
4925 goto err_out;
4928 for (i = 0; i < technique->annotation_count; ++i)
4930 add_param_to_table(base, &technique->annotations[i]);
4931 hr = d3dx9_parse_effect_annotation(base, &technique->annotations[i], data, ptr, objects);
4932 if (hr != D3D_OK)
4934 WARN("Failed to parse annotation %u\n", i);
4935 goto err_out;
4940 if (technique->pass_count)
4942 technique->passes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4943 sizeof(*technique->passes) * technique->pass_count);
4944 if (!technique->passes)
4946 ERR("Out of memory\n");
4947 hr = E_OUTOFMEMORY;
4948 goto err_out;
4951 for (i = 0; i < technique->pass_count; ++i)
4953 hr = d3dx9_parse_effect_pass(base, &technique->passes[i], data, ptr, objects);
4954 if (hr != D3D_OK)
4956 WARN("Failed to parse pass %u\n", i);
4957 goto err_out;
4962 technique->name = name;
4964 return D3D_OK;
4966 err_out:
4968 if (technique->passes)
4970 for (i = 0; i < technique->pass_count; ++i)
4971 free_pass(&technique->passes[i]);
4972 HeapFree(GetProcessHeap(), 0, technique->passes);
4973 technique->passes = NULL;
4976 if (technique->annotations)
4978 for (i = 0; i < technique->annotation_count; ++i)
4979 free_parameter(&technique->annotations[i], FALSE, FALSE);
4980 HeapFree(GetProcessHeap(), 0, technique->annotations);
4981 technique->annotations = NULL;
4984 HeapFree(GetProcessHeap(), 0, name);
4986 return hr;
4989 static HRESULT d3dx9_create_object(struct d3dx9_base_effect *base, struct d3dx_object *object)
4991 struct d3dx_parameter *param = object->param;
4992 struct IDirect3DDevice9 *device = base->effect->device;
4993 HRESULT hr;
4995 if (*(char **)param->data)
4996 ERR("Parameter data already allocated.\n");
4998 switch (param->type)
5000 case D3DXPT_STRING:
5001 *(char **)param->data = HeapAlloc(GetProcessHeap(), 0, object->size);
5002 if (!*(char **)param->data)
5004 ERR("Out of memory.\n");
5005 return E_OUTOFMEMORY;
5007 memcpy(*(char **)param->data, object->data, object->size);
5008 break;
5009 case D3DXPT_VERTEXSHADER:
5010 if (FAILED(hr = IDirect3DDevice9_CreateVertexShader(device, object->data,
5011 (IDirect3DVertexShader9 **)param->data)))
5013 WARN("Failed to create vertex shader.\n");
5014 return hr;
5016 break;
5017 case D3DXPT_PIXELSHADER:
5018 if (FAILED(hr = IDirect3DDevice9_CreatePixelShader(device, object->data,
5019 (IDirect3DPixelShader9 **)param->data)))
5021 WARN("Failed to create pixel shader.\n");
5022 return hr;
5024 break;
5025 default:
5026 break;
5028 return D3D_OK;
5031 static HRESULT d3dx9_parse_array_selector(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
5033 DWORD string_size;
5034 struct d3dx_object *object = &base->objects[param->object_id];
5035 char *ptr = object->data;
5037 TRACE("Parsing array entry selection state for parameter %p.\n", param);
5039 string_size = *(DWORD *)ptr;
5040 param->referenced_param = get_parameter_by_name(base, NULL, ptr + 4);
5041 if (param->referenced_param)
5043 TRACE("Mapping to parameter %s.\n", debugstr_a(param->referenced_param->name));
5045 else
5047 FIXME("Referenced parameter %s not found.\n", ptr + 4);
5048 return D3DXERR_INVALIDDATA;
5050 TRACE("Unknown DWORD: 0x%.8x.\n", *(DWORD *)(ptr + string_size));
5052 FIXME("Parse preshader.\n");
5054 return D3D_OK;
5057 static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *data, const char **ptr)
5059 DWORD technique_index;
5060 DWORD index, state_index, usage, element_index;
5061 struct d3dx_state *state;
5062 struct d3dx_parameter *param;
5063 struct d3dx_object *object;
5064 HRESULT hr = E_FAIL;
5066 read_dword(ptr, &technique_index);
5067 TRACE("technique_index: %u\n", technique_index);
5069 read_dword(ptr, &index);
5070 TRACE("index: %u\n", index);
5072 read_dword(ptr, &element_index);
5073 TRACE("element_index: %u\n", element_index);
5075 read_dword(ptr, &state_index);
5076 TRACE("state_index: %u\n", state_index);
5078 read_dword(ptr, &usage);
5079 TRACE("usage: %u\n", usage);
5081 if (technique_index == 0xffffffff)
5083 struct d3dx_parameter *parameter;
5084 struct d3dx_sampler *sampler;
5086 if (index >= base->parameter_count)
5088 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index, base->parameter_count);
5089 return E_FAIL;
5092 parameter = &base->parameters[index];
5093 if (element_index != 0xffffffff)
5095 if (element_index >= parameter->element_count && parameter->element_count != 0)
5097 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index, parameter->element_count);
5098 return E_FAIL;
5101 if (parameter->element_count != 0) parameter = &parameter->members[element_index];
5104 sampler = parameter->data;
5105 if (state_index >= sampler->state_count)
5107 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, sampler->state_count);
5108 return E_FAIL;
5111 state = &sampler->states[state_index];
5113 else
5115 struct d3dx_technique *technique;
5116 struct d3dx_pass *pass;
5118 if (technique_index >= base->technique_count)
5120 FIXME("Index out of bounds: technique_index %u >= technique_count %u\n", technique_index, base->technique_count);
5121 return E_FAIL;
5124 technique = &base->techniques[technique_index];
5125 if (index >= technique->pass_count)
5127 FIXME("Index out of bounds: index %u >= pass_count %u\n", index, technique->pass_count);
5128 return E_FAIL;
5131 pass = &technique->passes[index];
5132 if (state_index >= pass->state_count)
5134 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, pass->state_count);
5135 return E_FAIL;
5138 state = &pass->states[state_index];
5141 TRACE("State operation %#x (%s).\n", state->operation, state_table[state->operation].name);
5142 param = &state->parameter;
5143 TRACE("Using object id %u.\n", param->object_id);
5144 object = &base->objects[param->object_id];
5146 TRACE("Usage %u: class %s, type %s.\n", usage, debug_d3dxparameter_class(param->class),
5147 debug_d3dxparameter_type(param->type));
5148 switch (usage)
5150 case 0:
5151 switch (param->type)
5153 case D3DXPT_VERTEXSHADER:
5154 case D3DXPT_PIXELSHADER:
5155 state->type = ST_CONSTANT;
5156 if (FAILED(hr = d3dx9_copy_data(&base->objects[param->object_id], ptr)))
5157 return hr;
5159 if (object->data)
5160 hr = d3dx9_create_object(base, object);
5161 break;
5163 case D3DXPT_BOOL:
5164 case D3DXPT_INT:
5165 case D3DXPT_FLOAT:
5166 case D3DXPT_STRING:
5167 state->type = ST_FXLC;
5168 hr = d3dx9_copy_data(&base->objects[param->object_id], ptr);
5169 break;
5171 default:
5172 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5173 break;
5175 break;
5177 case 1:
5178 state->type = ST_PARAMETER;
5179 if (FAILED(hr = d3dx9_copy_data(&base->objects[param->object_id], ptr)))
5180 return hr;
5182 TRACE("Looking for parameter %s.\n", debugstr_a(object->data));
5183 param->referenced_param = get_parameter_by_name(base, NULL, object->data);
5184 if (param->referenced_param)
5186 TRACE("Mapping to parameter %p.\n", param->referenced_param);
5188 else
5190 FIXME("Referenced parameter %s not found.\n", (char *)object->data);
5191 return D3DXERR_INVALIDDATA;
5193 break;
5195 case 2:
5196 state->type = ST_ARRAY_SELECTOR;
5197 if (FAILED(hr = d3dx9_copy_data(object, ptr)))
5198 return hr;
5199 hr = d3dx9_parse_array_selector(base, param);
5200 break;
5202 default:
5203 FIXME("Unknown usage %x\n", usage);
5204 break;
5207 return hr;
5210 static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *data, UINT data_size, DWORD start)
5212 const char *ptr = data + start;
5213 UINT stringcount, resourcecount;
5214 HRESULT hr;
5215 UINT i;
5217 read_dword(&ptr, &base->parameter_count);
5218 TRACE("Parameter count: %u\n", base->parameter_count);
5220 read_dword(&ptr, &base->technique_count);
5221 TRACE("Technique count: %u\n", base->technique_count);
5223 skip_dword_unknown(&ptr, 1);
5225 read_dword(&ptr, &base->object_count);
5226 TRACE("Object count: %u\n", base->object_count);
5228 base->objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*base->objects) * base->object_count);
5229 if (!base->objects)
5231 ERR("Out of memory\n");
5232 hr = E_OUTOFMEMORY;
5233 goto err_out;
5236 if (base->parameter_count)
5238 base->parameters = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5239 sizeof(*base->parameters) * base->parameter_count);
5240 if (!base->parameters)
5242 ERR("Out of memory\n");
5243 hr = E_OUTOFMEMORY;
5244 goto err_out;
5247 for (i = 0; i < base->parameter_count; ++i)
5249 add_param_to_table(base, &base->parameters[i]);
5250 hr = d3dx9_parse_effect_parameter(base, &base->parameters[i], data, &ptr, base->objects);
5251 if (hr != D3D_OK)
5253 WARN("Failed to parse parameter %u\n", i);
5254 goto err_out;
5259 if (base->technique_count)
5261 base->techniques = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
5262 sizeof(*base->techniques) * base->technique_count);
5263 if (!base->techniques)
5265 ERR("Out of memory\n");
5266 hr = E_OUTOFMEMORY;
5267 goto err_out;
5270 for (i = 0; i < base->technique_count; ++i)
5272 TRACE("Parsing technique %u.\n", i);
5273 hr = d3dx9_parse_effect_technique(base, &base->techniques[i], data, &ptr, base->objects);
5274 if (hr != D3D_OK)
5276 WARN("Failed to parse technique %u\n", i);
5277 goto err_out;
5282 sync_param_handles(base);
5284 read_dword(&ptr, &stringcount);
5285 TRACE("String count: %u\n", stringcount);
5287 read_dword(&ptr, &resourcecount);
5288 TRACE("Resource count: %u\n", resourcecount);
5290 for (i = 0; i < stringcount; ++i)
5292 DWORD id;
5294 read_dword(&ptr, &id);
5295 TRACE("Id: %u\n", id);
5297 if (FAILED(hr = d3dx9_copy_data(&base->objects[id], &ptr)))
5298 goto err_out;
5300 if (base->objects[id].data)
5302 if (FAILED(hr = d3dx9_create_object(base, &base->objects[id])))
5303 goto err_out;
5307 for (i = 0; i < resourcecount; ++i)
5309 TRACE("parse resource %u\n", i);
5311 hr = d3dx9_parse_resource(base, data, &ptr);
5312 if (hr != D3D_OK)
5314 WARN("Failed to parse resource %u\n", i);
5315 goto err_out;
5319 return D3D_OK;
5321 err_out:
5323 if (base->techniques)
5325 for (i = 0; i < base->technique_count; ++i)
5326 free_technique(&base->techniques[i]);
5327 HeapFree(GetProcessHeap(), 0, base->techniques);
5328 base->techniques = NULL;
5331 if (base->parameters)
5333 for (i = 0; i < base->parameter_count; ++i)
5335 free_parameter(&base->parameters[i], FALSE, FALSE);
5337 HeapFree(GetProcessHeap(), 0, base->parameters);
5338 base->parameters = NULL;
5341 if (base->objects)
5343 for (i = 0; i < base->object_count; ++i)
5345 free_object(&base->objects[i]);
5347 HeapFree(GetProcessHeap(), 0, base->objects);
5348 base->objects = NULL;
5351 return hr;
5354 static HRESULT d3dx9_base_effect_init(struct d3dx9_base_effect *base,
5355 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
5356 UINT eflags, ID3DBlob **errors, struct ID3DXEffectImpl *effect)
5358 DWORD tag, offset;
5359 const char *ptr = data;
5360 HRESULT hr;
5361 ID3DBlob *bytecode = NULL, *temp_errors = NULL;
5363 TRACE("base %p, data %p, data_size %lu, effect %p\n", base, data, data_size, effect);
5365 base->effect = effect;
5367 read_dword(&ptr, &tag);
5368 TRACE("Tag: %x\n", tag);
5370 if (tag != d3dx9_effect_version(9, 1))
5372 TRACE("HLSL ASCII effect, trying to compile it.\n");
5373 hr = D3DCompile(data, data_size, NULL, defines, include,
5374 "main", "fx_2_0", 0, eflags, &bytecode, &temp_errors);
5375 if (FAILED(hr))
5377 WARN("Failed to compile ASCII effect.\n");
5378 if (bytecode)
5379 ID3D10Blob_Release(bytecode);
5380 if (temp_errors)
5381 TRACE("%s\n", (char *)ID3D10Blob_GetBufferPointer(temp_errors));
5382 if (errors)
5383 *errors = temp_errors;
5384 else if (temp_errors)
5385 ID3D10Blob_Release(temp_errors);
5386 return hr;
5388 if (!bytecode)
5390 FIXME("No output from effect compilation.\n");
5391 return D3DERR_INVALIDCALL;
5393 if (errors)
5394 *errors = temp_errors;
5395 else if (temp_errors)
5396 ID3D10Blob_Release(temp_errors);
5398 ptr = ID3D10Blob_GetBufferPointer(bytecode);
5399 read_dword(&ptr, &tag);
5400 TRACE("Tag: %x\n", tag);
5403 read_dword(&ptr, &offset);
5404 TRACE("Offset: %x\n", offset);
5406 hr = d3dx9_parse_effect(base, ptr, data_size, offset);
5407 if (bytecode)
5408 ID3D10Blob_Release(bytecode);
5409 if (hr != D3D_OK)
5411 FIXME("Failed to parse effect.\n");
5412 return hr;
5415 return D3D_OK;
5418 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, struct IDirect3DDevice9 *device,
5419 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
5420 UINT eflags, ID3DBlob **error_messages, struct ID3DXEffectPool *pool)
5422 HRESULT hr;
5424 TRACE("effect %p, device %p, data %p, data_size %lu, pool %p\n", effect, device, data, data_size, pool);
5426 effect->ID3DXEffect_iface.lpVtbl = &ID3DXEffect_Vtbl;
5427 effect->ref = 1;
5429 if (pool) pool->lpVtbl->AddRef(pool);
5430 effect->pool = pool;
5432 IDirect3DDevice9_AddRef(device);
5433 effect->device = device;
5435 if (FAILED(hr = d3dx9_base_effect_init(&effect->base_effect, data, data_size, defines, include,
5436 eflags, error_messages, effect)))
5438 FIXME("Failed to parse effect, hr %#x.\n", hr);
5439 free_effect(effect);
5440 return hr;
5443 /* initialize defaults - check because of unsupported ascii effects */
5444 if (effect->base_effect.techniques)
5446 effect->active_technique = &effect->base_effect.techniques[0];
5447 effect->active_pass = NULL;
5450 return D3D_OK;
5453 HRESULT WINAPI D3DXCreateEffectEx(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
5454 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skip_constants, DWORD flags,
5455 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
5457 struct ID3DXEffectImpl *object;
5458 HRESULT hr;
5460 TRACE("device %p, srcdata %p, srcdatalen %u, defines %p, include %p,"
5461 " skip_constants %p, flags %#x, pool %p, effect %p, compilation_errors %p.\n",
5462 device, srcdata, srcdatalen, defines, include,
5463 skip_constants, flags, pool, effect, compilation_errors);
5465 if (compilation_errors)
5466 *compilation_errors = NULL;
5468 if (!device || !srcdata)
5469 return D3DERR_INVALIDCALL;
5471 if (!srcdatalen)
5472 return E_FAIL;
5474 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
5475 if (!effect)
5476 return D3D_OK;
5478 if (skip_constants)
5479 FIXME("skip_constants is not NULL, not supported yet.\n");
5481 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5482 if (!object)
5483 return E_OUTOFMEMORY;
5485 hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
5486 (ID3DInclude *)include, flags, (ID3DBlob **)compilation_errors, pool);
5487 if (FAILED(hr))
5489 WARN("Failed to create effect object.\n");
5490 HeapFree(GetProcessHeap(), 0, object);
5491 return hr;
5494 *effect = &object->ID3DXEffect_iface;
5496 TRACE("Created ID3DXEffect %p\n", object);
5498 return D3D_OK;
5501 HRESULT WINAPI D3DXCreateEffect(struct IDirect3DDevice9 *device, const void *srcdata, UINT srcdatalen,
5502 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
5503 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilation_errors)
5505 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device, srcdata, srcdatalen, defines,
5506 include, flags, pool, effect, compilation_errors);
5508 return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
5511 static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler,
5512 const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
5513 UINT eflags, ID3DBlob **error_messages)
5515 HRESULT hr;
5517 TRACE("effect %p, data %p, data_size %lu\n", compiler, data, data_size);
5519 compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
5520 compiler->ref = 1;
5522 if (FAILED(hr = d3dx9_base_effect_init(&compiler->base_effect, data, data_size, defines,
5523 include, eflags, error_messages, NULL)))
5525 FIXME("Failed to parse effect, hr %#x.\n", hr);
5526 free_effect_compiler(compiler);
5527 return hr;
5530 return D3D_OK;
5533 HRESULT WINAPI D3DXCreateEffectCompiler(const char *srcdata, UINT srcdatalen, const D3DXMACRO *defines,
5534 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **compiler, ID3DXBuffer **parse_errors)
5536 struct ID3DXEffectCompilerImpl *object;
5537 HRESULT hr;
5539 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
5540 srcdata, srcdatalen, defines, include, flags, compiler, parse_errors);
5542 if (!srcdata || !compiler)
5544 WARN("Invalid arguments supplied\n");
5545 return D3DERR_INVALIDCALL;
5548 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5549 if (!object)
5550 return E_OUTOFMEMORY;
5552 hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
5553 (ID3DInclude *)include, flags, (ID3DBlob **)parse_errors);
5554 if (FAILED(hr))
5556 WARN("Failed to initialize effect compiler\n");
5557 HeapFree(GetProcessHeap(), 0, object);
5558 return hr;
5561 *compiler = &object->ID3DXEffectCompiler_iface;
5563 TRACE("Created ID3DXEffectCompiler %p\n", object);
5565 return D3D_OK;
5568 struct ID3DXEffectPoolImpl
5570 ID3DXEffectPool ID3DXEffectPool_iface;
5571 LONG ref;
5574 static inline struct ID3DXEffectPoolImpl *impl_from_ID3DXEffectPool(ID3DXEffectPool *iface)
5576 return CONTAINING_RECORD(iface, struct ID3DXEffectPoolImpl, ID3DXEffectPool_iface);
5579 /*** IUnknown methods ***/
5580 static HRESULT WINAPI ID3DXEffectPoolImpl_QueryInterface(ID3DXEffectPool *iface, REFIID riid, void **object)
5582 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
5584 if (IsEqualGUID(riid, &IID_IUnknown) ||
5585 IsEqualGUID(riid, &IID_ID3DXEffectPool))
5587 iface->lpVtbl->AddRef(iface);
5588 *object = iface;
5589 return S_OK;
5592 WARN("Interface %s not found\n", debugstr_guid(riid));
5594 return E_NOINTERFACE;
5597 static ULONG WINAPI ID3DXEffectPoolImpl_AddRef(ID3DXEffectPool *iface)
5599 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
5601 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
5603 return InterlockedIncrement(&This->ref);
5606 static ULONG WINAPI ID3DXEffectPoolImpl_Release(ID3DXEffectPool *iface)
5608 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
5609 ULONG ref = InterlockedDecrement(&This->ref);
5611 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
5613 if (!ref)
5614 HeapFree(GetProcessHeap(), 0, This);
5616 return ref;
5619 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl =
5621 /*** IUnknown methods ***/
5622 ID3DXEffectPoolImpl_QueryInterface,
5623 ID3DXEffectPoolImpl_AddRef,
5624 ID3DXEffectPoolImpl_Release
5627 HRESULT WINAPI D3DXCreateEffectPool(ID3DXEffectPool **pool)
5629 struct ID3DXEffectPoolImpl *object;
5631 TRACE("(%p)\n", pool);
5633 if (!pool)
5634 return D3DERR_INVALIDCALL;
5636 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5637 if (!object)
5638 return E_OUTOFMEMORY;
5640 object->ID3DXEffectPool_iface.lpVtbl = &ID3DXEffectPool_Vtbl;
5641 object->ref = 1;
5643 *pool = &object->ID3DXEffectPool_iface;
5645 return S_OK;
5648 HRESULT WINAPI D3DXCreateEffectFromFileExW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
5649 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
5650 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5652 void *buffer;
5653 HRESULT ret;
5654 DWORD size;
5656 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
5657 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
5658 device, debugstr_w(srcfile), defines, include, debugstr_a(skipconstants),
5659 flags, pool, effect, compilationerrors);
5661 if (!device || !srcfile)
5662 return D3DERR_INVALIDCALL;
5664 ret = map_view_of_file(srcfile, &buffer, &size);
5666 if (FAILED(ret))
5667 return D3DXERR_INVALIDDATA;
5669 ret = D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
5670 UnmapViewOfFile(buffer);
5672 return ret;
5675 HRESULT WINAPI D3DXCreateEffectFromFileExA(struct IDirect3DDevice9 *device, const char *srcfile,
5676 const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
5677 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5679 WCHAR *srcfileW;
5680 HRESULT ret;
5681 DWORD len;
5683 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
5684 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
5685 device, debugstr_a(srcfile), defines, include, debugstr_a(skipconstants),
5686 flags, pool, effect, compilationerrors);
5688 if (!srcfile)
5689 return D3DERR_INVALIDCALL;
5691 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
5692 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
5693 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
5695 ret = D3DXCreateEffectFromFileExW(device, srcfileW, defines, include, skipconstants, flags, pool, effect, compilationerrors);
5696 HeapFree(GetProcessHeap(), 0, srcfileW);
5698 return ret;
5701 HRESULT WINAPI D3DXCreateEffectFromFileW(struct IDirect3DDevice9 *device, const WCHAR *srcfile,
5702 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
5703 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5705 TRACE("(void): relay\n");
5706 return D3DXCreateEffectFromFileExW(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
5709 HRESULT WINAPI D3DXCreateEffectFromFileA(struct IDirect3DDevice9 *device, const char *srcfile,
5710 const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags, struct ID3DXEffectPool *pool,
5711 struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5713 TRACE("(void): relay\n");
5714 return D3DXCreateEffectFromFileExA(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
5717 HRESULT WINAPI D3DXCreateEffectFromResourceExW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
5718 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
5719 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5721 HRSRC resinfo;
5722 void *buffer;
5723 DWORD size;
5725 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
5726 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
5727 device, srcmodule, debugstr_w(srcresource), defines, include, debugstr_a(skipconstants),
5728 flags, pool, effect, compilationerrors);
5730 if (!device)
5731 return D3DERR_INVALIDCALL;
5733 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
5734 return D3DXERR_INVALIDDATA;
5736 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
5737 return D3DXERR_INVALIDDATA;
5739 return D3DXCreateEffectEx(device, buffer, size, defines, include,
5740 skipconstants, flags, pool, effect, compilationerrors);
5743 HRESULT WINAPI D3DXCreateEffectFromResourceExA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
5744 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants,
5745 DWORD flags, struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5747 HRSRC resinfo;
5748 void *buffer;
5749 DWORD size;
5751 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
5752 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
5753 device, srcmodule, debugstr_a(srcresource), defines, include, debugstr_a(skipconstants),
5754 flags, pool, effect, compilationerrors);
5756 if (!device)
5757 return D3DERR_INVALIDCALL;
5759 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
5760 return D3DXERR_INVALIDDATA;
5762 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
5763 return D3DXERR_INVALIDDATA;
5765 return D3DXCreateEffectEx(device, buffer, size, defines, include,
5766 skipconstants, flags, pool, effect, compilationerrors);
5769 HRESULT WINAPI D3DXCreateEffectFromResourceW(struct IDirect3DDevice9 *device, HMODULE srcmodule,
5770 const WCHAR *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
5771 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5773 TRACE("(void): relay\n");
5774 return D3DXCreateEffectFromResourceExW(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
5777 HRESULT WINAPI D3DXCreateEffectFromResourceA(struct IDirect3DDevice9 *device, HMODULE srcmodule,
5778 const char *srcresource, const D3DXMACRO *defines, struct ID3DXInclude *include, DWORD flags,
5779 struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
5781 TRACE("(void): relay\n");
5782 return D3DXCreateEffectFromResourceExA(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
5785 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(const WCHAR *srcfile, const D3DXMACRO *defines,
5786 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
5788 void *buffer;
5789 HRESULT ret;
5790 DWORD size;
5792 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
5793 debugstr_w(srcfile), defines, include, flags, effectcompiler, parseerrors);
5795 if (!srcfile)
5796 return D3DERR_INVALIDCALL;
5798 ret = map_view_of_file(srcfile, &buffer, &size);
5800 if (FAILED(ret))
5801 return D3DXERR_INVALIDDATA;
5803 ret = D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
5804 UnmapViewOfFile(buffer);
5806 return ret;
5809 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(const char *srcfile, const D3DXMACRO *defines,
5810 ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
5812 WCHAR *srcfileW;
5813 HRESULT ret;
5814 DWORD len;
5816 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
5817 debugstr_a(srcfile), defines, include, flags, effectcompiler, parseerrors);
5819 if (!srcfile)
5820 return D3DERR_INVALIDCALL;
5822 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
5823 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
5824 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
5826 ret = D3DXCreateEffectCompilerFromFileW(srcfileW, defines, include, flags, effectcompiler, parseerrors);
5827 HeapFree(GetProcessHeap(), 0, srcfileW);
5829 return ret;
5832 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule, const char *srcresource,
5833 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
5834 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
5836 HRSRC resinfo;
5837 void *buffer;
5838 DWORD size;
5840 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
5841 srcmodule, debugstr_a(srcresource), defines, include, flags, effectcompiler, parseerrors);
5843 if (!(resinfo = FindResourceA(srcmodule, srcresource, (const char *)RT_RCDATA)))
5844 return D3DXERR_INVALIDDATA;
5846 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
5847 return D3DXERR_INVALIDDATA;
5849 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
5852 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule, const WCHAR *srcresource,
5853 const D3DXMACRO *defines, ID3DXInclude *include, DWORD flags,
5854 ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
5856 HRSRC resinfo;
5857 void *buffer;
5858 DWORD size;
5860 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
5861 srcmodule, debugstr_w(srcresource), defines, include, flags, effectcompiler, parseerrors);
5863 if (!(resinfo = FindResourceW(srcmodule, srcresource, (const WCHAR *)RT_RCDATA)))
5864 return D3DXERR_INVALIDDATA;
5866 if (FAILED(load_resource_into_memory(srcmodule, resinfo, &buffer, &size)))
5867 return D3DXERR_INVALIDDATA;
5869 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
5872 HRESULT WINAPI D3DXDisassembleEffect(ID3DXEffect *effect, BOOL enable_color_code, ID3DXBuffer **disassembly)
5874 FIXME("(%p, %u, %p): stub\n", effect, enable_color_code, disassembly);
5876 return D3DXERR_INVALIDDATA;