d3dx9: Implement ID3DXBaseEffect::SetVectorArray().
[wine.git] / dlls / d3dx9_36 / effect.c
blobd9fc0b9d3cdbbfe856d9bb99a372a0dd543c96f4
1 /*
2 * Copyright 2010 Christian Costa
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
21 #define NONAMELESSUNION
22 #include "wine/debug.h"
23 #include "wine/unicode.h"
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "d3dx9_36_private.h"
29 /* Constants for special INT/FLOAT conversation */
30 #define INT_FLOAT_MULTI 255.0f
31 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
33 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
35 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl;
36 static const struct ID3DXBaseEffectVtbl ID3DXBaseEffect_Vtbl;
37 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl;
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,
101 struct d3dx_parameter
103 char *name;
104 char *semantic;
105 void *data;
106 D3DXPARAMETER_CLASS class;
107 D3DXPARAMETER_TYPE type;
108 UINT rows;
109 UINT columns;
110 UINT element_count;
111 UINT annotation_count;
112 UINT member_count;
113 DWORD flags;
114 UINT bytes;
116 D3DXHANDLE *annotation_handles;
117 D3DXHANDLE *member_handles;
120 struct d3dx_state
122 UINT operation;
123 UINT index;
124 enum STATE_TYPE type;
125 D3DXHANDLE parameter;
128 struct d3dx_sampler
130 UINT state_count;
131 struct d3dx_state *states;
134 struct d3dx_pass
136 char *name;
137 UINT state_count;
138 UINT annotation_count;
140 struct d3dx_state *states;
141 D3DXHANDLE *annotation_handles;
144 struct d3dx_technique
146 char *name;
147 UINT pass_count;
148 UINT annotation_count;
150 D3DXHANDLE *annotation_handles;
151 D3DXHANDLE *pass_handles;
154 struct ID3DXBaseEffectImpl
156 ID3DXBaseEffect ID3DXBaseEffect_iface;
157 LONG ref;
159 struct ID3DXEffectImpl *effect;
161 UINT parameter_count;
162 UINT technique_count;
164 D3DXHANDLE *parameter_handles;
165 D3DXHANDLE *technique_handles;
168 struct ID3DXEffectImpl
170 ID3DXEffect ID3DXEffect_iface;
171 LONG ref;
173 LPD3DXEFFECTSTATEMANAGER manager;
174 LPDIRECT3DDEVICE9 device;
175 LPD3DXEFFECTPOOL pool;
176 D3DXHANDLE active_technique;
177 D3DXHANDLE active_pass;
179 ID3DXBaseEffect *base_effect;
182 struct ID3DXEffectCompilerImpl
184 ID3DXEffectCompiler ID3DXEffectCompiler_iface;
185 LONG ref;
187 ID3DXBaseEffect *base_effect;
190 static struct d3dx_parameter *get_parameter_by_name(struct ID3DXBaseEffectImpl *base,
191 struct d3dx_parameter *parameter, LPCSTR name);
192 static struct d3dx_parameter *get_parameter_annotation_by_name(struct d3dx_parameter *parameter, LPCSTR name);
193 static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects);
194 static void free_parameter_state(D3DXHANDLE handle, BOOL element, BOOL child, enum STATE_TYPE st);
196 static const struct
198 enum STATE_CLASS class;
199 UINT op;
200 LPCSTR name;
202 state_table[] =
204 /* Render sates */
205 {SC_RENDERSTATE, D3DRS_ZENABLE, "D3DRS_ZENABLE"}, /* 0x0 */
206 {SC_RENDERSTATE, D3DRS_FILLMODE, "D3DRS_FILLMODE"},
207 {SC_RENDERSTATE, D3DRS_SHADEMODE, "D3DRS_SHADEMODE"},
208 {SC_RENDERSTATE, D3DRS_ZWRITEENABLE, "D3DRS_ZWRITEENABLE"},
209 {SC_RENDERSTATE, D3DRS_ALPHATESTENABLE, "D3DRS_ALPHATESTENABLE"},
210 {SC_RENDERSTATE, D3DRS_LASTPIXEL, "D3DRS_LASTPIXEL"},
211 {SC_RENDERSTATE, D3DRS_SRCBLEND, "D3DRS_SRCBLEND"},
212 {SC_RENDERSTATE, D3DRS_DESTBLEND, "D3DRS_DESTBLEND"},
213 {SC_RENDERSTATE, D3DRS_CULLMODE, "D3DRS_CULLMODE"},
214 {SC_RENDERSTATE, D3DRS_ZFUNC, "D3DRS_ZFUNC"},
215 {SC_RENDERSTATE, D3DRS_ALPHAREF, "D3DRS_ALPHAREF"},
216 {SC_RENDERSTATE, D3DRS_ALPHAFUNC, "D3DRS_ALPHAFUNC"},
217 {SC_RENDERSTATE, D3DRS_DITHERENABLE, "D3DRS_DITHERENABLE"},
218 {SC_RENDERSTATE, D3DRS_ALPHABLENDENABLE, "D3DRS_ALPHABLENDENABLE"},
219 {SC_RENDERSTATE, D3DRS_FOGENABLE, "D3DRS_FOGENABLE"},
220 {SC_RENDERSTATE, D3DRS_SPECULARENABLE, "D3DRS_SPECULARENABLE"},
221 {SC_RENDERSTATE, D3DRS_FOGCOLOR, "D3DRS_FOGCOLOR"}, /* 0x10 */
222 {SC_RENDERSTATE, D3DRS_FOGTABLEMODE, "D3DRS_FOGTABLEMODE"},
223 {SC_RENDERSTATE, D3DRS_FOGSTART, "D3DRS_FOGSTART"},
224 {SC_RENDERSTATE, D3DRS_FOGEND, "D3DRS_FOGEND"},
225 {SC_RENDERSTATE, D3DRS_FOGDENSITY, "D3DRS_FOGDENSITY"},
226 {SC_RENDERSTATE, D3DRS_RANGEFOGENABLE, "D3DRS_RANGEFOGENABLE"},
227 {SC_RENDERSTATE, D3DRS_STENCILENABLE, "D3DRS_STENCILENABLE"},
228 {SC_RENDERSTATE, D3DRS_STENCILFAIL, "D3DRS_STENCILFAIL"},
229 {SC_RENDERSTATE, D3DRS_STENCILZFAIL, "D3DRS_STENCILZFAIL"},
230 {SC_RENDERSTATE, D3DRS_STENCILPASS, "D3DRS_STENCILPASS"},
231 {SC_RENDERSTATE, D3DRS_STENCILFUNC, "D3DRS_STENCILFUNC"},
232 {SC_RENDERSTATE, D3DRS_STENCILREF, "D3DRS_STENCILREF"},
233 {SC_RENDERSTATE, D3DRS_STENCILMASK, "D3DRS_STENCILMASK"},
234 {SC_RENDERSTATE, D3DRS_STENCILWRITEMASK, "D3DRS_STENCILWRITEMASK"},
235 {SC_RENDERSTATE, D3DRS_TEXTUREFACTOR, "D3DRS_TEXTUREFACTOR"},
236 {SC_RENDERSTATE, D3DRS_WRAP0, "D3DRS_WRAP0"},
237 {SC_RENDERSTATE, D3DRS_WRAP1, "D3DRS_WRAP1"}, /* 0x20 */
238 {SC_RENDERSTATE, D3DRS_WRAP2, "D3DRS_WRAP2"},
239 {SC_RENDERSTATE, D3DRS_WRAP3, "D3DRS_WRAP3"},
240 {SC_RENDERSTATE, D3DRS_WRAP4, "D3DRS_WRAP4"},
241 {SC_RENDERSTATE, D3DRS_WRAP5, "D3DRS_WRAP5"},
242 {SC_RENDERSTATE, D3DRS_WRAP6, "D3DRS_WRAP6"},
243 {SC_RENDERSTATE, D3DRS_WRAP7, "D3DRS_WRAP7"},
244 {SC_RENDERSTATE, D3DRS_WRAP8, "D3DRS_WRAP8"},
245 {SC_RENDERSTATE, D3DRS_WRAP9, "D3DRS_WRAP9"},
246 {SC_RENDERSTATE, D3DRS_WRAP10, "D3DRS_WRAP10"},
247 {SC_RENDERSTATE, D3DRS_WRAP11, "D3DRS_WRAP11"},
248 {SC_RENDERSTATE, D3DRS_WRAP12, "D3DRS_WRAP12"},
249 {SC_RENDERSTATE, D3DRS_WRAP13, "D3DRS_WRAP13"},
250 {SC_RENDERSTATE, D3DRS_WRAP14, "D3DRS_WRAP14"},
251 {SC_RENDERSTATE, D3DRS_WRAP15, "D3DRS_WRAP15"},
252 {SC_RENDERSTATE, D3DRS_CLIPPING, "D3DRS_CLIPPING"},
253 {SC_RENDERSTATE, D3DRS_LIGHTING, "D3DRS_LIGHTING"}, /* 0x30 */
254 {SC_RENDERSTATE, D3DRS_AMBIENT, "D3DRS_AMBIENT"},
255 {SC_RENDERSTATE, D3DRS_FOGVERTEXMODE, "D3DRS_FOGVERTEXMODE"},
256 {SC_RENDERSTATE, D3DRS_COLORVERTEX, "D3DRS_COLORVERTEX"},
257 {SC_RENDERSTATE, D3DRS_LOCALVIEWER, "D3DRS_LOCALVIEWER"},
258 {SC_RENDERSTATE, D3DRS_NORMALIZENORMALS, "D3DRS_NORMALIZENORMALS"},
259 {SC_RENDERSTATE, D3DRS_DIFFUSEMATERIALSOURCE, "D3DRS_DIFFUSEMATERIALSOURCE"},
260 {SC_RENDERSTATE, D3DRS_SPECULARMATERIALSOURCE, "D3DRS_SPECULARMATERIALSOURCE"},
261 {SC_RENDERSTATE, D3DRS_AMBIENTMATERIALSOURCE, "D3DRS_AMBIENTMATERIALSOURCE"},
262 {SC_RENDERSTATE, D3DRS_EMISSIVEMATERIALSOURCE, "D3DRS_EMISSIVEMATERIALSOURCE"},
263 {SC_RENDERSTATE, D3DRS_VERTEXBLEND, "D3DRS_VERTEXBLEND"},
264 {SC_RENDERSTATE, D3DRS_CLIPPLANEENABLE, "D3DRS_CLIPPLANEENABLE"},
265 {SC_RENDERSTATE, D3DRS_POINTSIZE, "D3DRS_POINTSIZE"},
266 {SC_RENDERSTATE, D3DRS_POINTSIZE_MIN, "D3DRS_POINTSIZE_MIN"},
267 {SC_RENDERSTATE, D3DRS_POINTSIZE_MAX, "D3DRS_POINTSIZE_MAX"},
268 {SC_RENDERSTATE, D3DRS_POINTSPRITEENABLE, "D3DRS_POINTSPRITEENABLE"},
269 {SC_RENDERSTATE, D3DRS_POINTSCALEENABLE, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
270 {SC_RENDERSTATE, D3DRS_POINTSCALE_A, "D3DRS_POINTSCALE_A"},
271 {SC_RENDERSTATE, D3DRS_POINTSCALE_B, "D3DRS_POINTSCALE_B"},
272 {SC_RENDERSTATE, D3DRS_POINTSCALE_C, "D3DRS_POINTSCALE_C"},
273 {SC_RENDERSTATE, D3DRS_MULTISAMPLEANTIALIAS, "D3DRS_MULTISAMPLEANTIALIAS"},
274 {SC_RENDERSTATE, D3DRS_MULTISAMPLEMASK, "D3DRS_MULTISAMPLEMASK"},
275 {SC_RENDERSTATE, D3DRS_PATCHEDGESTYLE, "D3DRS_PATCHEDGESTYLE"},
276 {SC_RENDERSTATE, D3DRS_DEBUGMONITORTOKEN, "D3DRS_DEBUGMONITORTOKEN"},
277 {SC_RENDERSTATE, D3DRS_INDEXEDVERTEXBLENDENABLE, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
278 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE, "D3DRS_COLORWRITEENABLE"},
279 {SC_RENDERSTATE, D3DRS_TWEENFACTOR, "D3DRS_TWEENFACTOR"},
280 {SC_RENDERSTATE, D3DRS_BLENDOP, "D3DRS_BLENDOP"},
281 {SC_RENDERSTATE, D3DRS_POSITIONDEGREE, "D3DRS_POSITIONDEGREE"},
282 {SC_RENDERSTATE, D3DRS_NORMALDEGREE, "D3DRS_NORMALDEGREE"},
283 {SC_RENDERSTATE, D3DRS_SCISSORTESTENABLE, "D3DRS_SCISSORTESTENABLE"},
284 {SC_RENDERSTATE, D3DRS_SLOPESCALEDEPTHBIAS, "D3DRS_SLOPESCALEDEPTHBIAS"},
285 {SC_RENDERSTATE, D3DRS_ANTIALIASEDLINEENABLE, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
286 {SC_RENDERSTATE, D3DRS_MINTESSELLATIONLEVEL, "D3DRS_MINTESSELLATIONLEVEL"},
287 {SC_RENDERSTATE, D3DRS_MAXTESSELLATIONLEVEL, "D3DRS_MAXTESSELLATIONLEVEL"},
288 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_X, "D3DRS_ADAPTIVETESS_X"},
289 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Y, "D3DRS_ADAPTIVETESS_Y"},
290 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Z, "D3DRS_ADAPTIVETESS_Z"},
291 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_W, "D3DRS_ADAPTIVETESS_W"},
292 {SC_RENDERSTATE, D3DRS_ENABLEADAPTIVETESSELLATION, "D3DRS_ENABLEADAPTIVETESSELLATION"},
293 {SC_RENDERSTATE, D3DRS_TWOSIDEDSTENCILMODE, "D3DRS_TWOSIDEDSTENCILMODE"},
294 {SC_RENDERSTATE, D3DRS_CCW_STENCILFAIL, "D3DRS_CCW_STENCILFAIL"},
295 {SC_RENDERSTATE, D3DRS_CCW_STENCILZFAIL, "D3DRS_CCW_STENCILZFAIL"},
296 {SC_RENDERSTATE, D3DRS_CCW_STENCILPASS, "D3DRS_CCW_STENCILPASS"},
297 {SC_RENDERSTATE, D3DRS_CCW_STENCILFUNC, "D3DRS_CCW_STENCILFUNC"},
298 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE1, "D3DRS_COLORWRITEENABLE1"},
299 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE2, "D3DRS_COLORWRITEENABLE2"},
300 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE3, "D3DRS_COLORWRITEENABLE3"},
301 {SC_RENDERSTATE, D3DRS_BLENDFACTOR, "D3DRS_BLENDFACTOR"}, /* 0x60 */
302 {SC_RENDERSTATE, D3DRS_SRGBWRITEENABLE, "D3DRS_SRGBWRITEENABLE"},
303 {SC_RENDERSTATE, D3DRS_DEPTHBIAS, "D3DRS_DEPTHBIAS"},
304 {SC_RENDERSTATE, D3DRS_SEPARATEALPHABLENDENABLE, "D3DRS_SEPARATEALPHABLENDENABLE"},
305 {SC_RENDERSTATE, D3DRS_SRCBLENDALPHA, "D3DRS_SRCBLENDALPHA"},
306 {SC_RENDERSTATE, D3DRS_DESTBLENDALPHA, "D3DRS_DESTBLENDALPHA"},
307 {SC_RENDERSTATE, D3DRS_BLENDOPALPHA, "D3DRS_BLENDOPALPHA"},
308 /* Texture stages */
309 {SC_TEXTURESTAGE, D3DTSS_COLOROP, "D3DTSS_COLOROP"},
310 {SC_TEXTURESTAGE, D3DTSS_COLORARG0, "D3DTSS_COLORARG0"},
311 {SC_TEXTURESTAGE, D3DTSS_COLORARG1, "D3DTSS_COLORARG1"},
312 {SC_TEXTURESTAGE, D3DTSS_COLORARG2, "D3DTSS_COLORARG2"},
313 {SC_TEXTURESTAGE, D3DTSS_ALPHAOP, "D3DTSS_ALPHAOP"},
314 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG0, "D3DTSS_ALPHAARG0"},
315 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG1, "D3DTSS_ALPHAARG1"},
316 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG2, "D3DTSS_ALPHAARG2"},
317 {SC_TEXTURESTAGE, D3DTSS_RESULTARG, "D3DTSS_RESULTARG"},
318 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT00, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
319 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT01, "D3DTSS_BUMPENVMAT01"},
320 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT10, "D3DTSS_BUMPENVMAT10"},
321 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT11, "D3DTSS_BUMPENVMAT11"},
322 {SC_TEXTURESTAGE, D3DTSS_TEXCOORDINDEX, "D3DTSS_TEXCOORDINDEX"},
323 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLSCALE, "D3DTSS_BUMPENVLSCALE"},
324 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLOFFSET, "D3DTSS_BUMPENVLOFFSET"},
325 {SC_TEXTURESTAGE, D3DTSS_TEXTURETRANSFORMFLAGS, "D3DTSS_TEXTURETRANSFORMFLAGS"},
326 /* */
327 {SC_UNKNOWN, 0, "UNKNOWN"},
328 /* NPatchMode */
329 {SC_NPATCHMODE, 0, "NPatchMode"},
330 /* */
331 {SC_UNKNOWN, 0, "UNKNOWN"},
332 /* Transform */
333 {SC_TRANSFORM, D3DTS_PROJECTION, "D3DTS_PROJECTION"},
334 {SC_TRANSFORM, D3DTS_VIEW, "D3DTS_VIEW"},
335 {SC_TRANSFORM, D3DTS_WORLD, "D3DTS_WORLD"},
336 {SC_TRANSFORM, D3DTS_TEXTURE0, "D3DTS_TEXTURE0"},
337 /* Material */
338 {SC_MATERIAL, MT_DIFFUSE, "MaterialDiffuse"},
339 {SC_MATERIAL, MT_AMBIENT, "MaterialAmbient"}, /* 0x80 */
340 {SC_MATERIAL, MT_SPECULAR, "MaterialSpecular"},
341 {SC_MATERIAL, MT_EMISSIVE, "MaterialEmissive"},
342 {SC_MATERIAL, MT_POWER, "MaterialPower"},
343 /* Light */
344 {SC_LIGHT, LT_TYPE, "LightType"},
345 {SC_LIGHT, LT_DIFFUSE, "LightDiffuse"},
346 {SC_LIGHT, LT_SPECULAR, "LightSpecular"},
347 {SC_LIGHT, LT_AMBIENT, "LightAmbient"},
348 {SC_LIGHT, LT_POSITION, "LightPosition"},
349 {SC_LIGHT, LT_DIRECTION, "LightDirection"},
350 {SC_LIGHT, LT_RANGE, "LightRange"},
351 {SC_LIGHT, LT_FALLOFF, "LightFallOff"},
352 {SC_LIGHT, LT_ATTENUATION0, "LightAttenuation0"},
353 {SC_LIGHT, LT_ATTENUATION1, "LightAttenuation1"},
354 {SC_LIGHT, LT_ATTENUATION2, "LightAttenuation2"},
355 {SC_LIGHT, LT_THETA, "LightTheta"},
356 {SC_LIGHT, LT_PHI, "LightPhi"}, /* 0x90 */
357 /* Ligthenable */
358 {SC_LIGHTENABLE, 0, "LightEnable"},
359 /* Vertexshader */
360 {SC_VERTEXSHADER, 0, "Vertexshader"},
361 /* Pixelshader */
362 {SC_PIXELSHADER, 0, "Pixelshader"},
363 /* Shader constants */
364 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstantF"},
365 {SC_SHADERCONST, SCT_VSBOOL, "VertexShaderConstantB"},
366 {SC_SHADERCONST, SCT_VSINT, "VertexShaderConstantI"},
367 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant"},
368 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant1"},
369 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant2"},
370 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant3"},
371 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant4"},
372 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstantF"},
373 {SC_SHADERCONST, SCT_PSBOOL, "PixelShaderConstantB"},
374 {SC_SHADERCONST, SCT_PSINT, "PixelShaderConstantI"},
375 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant"},
376 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant1"}, /* 0xa0 */
377 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant2"},
378 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant3"},
379 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant4"},
380 /* Texture */
381 {SC_TEXTURE, 0, "Texture"},
382 /* Sampler states */
383 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSU, "AddressU"},
384 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSV, "AddressV"},
385 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSW, "AddressW"},
386 {SC_SAMPLERSTATE, D3DSAMP_BORDERCOLOR, "BorderColor"},
387 {SC_SAMPLERSTATE, D3DSAMP_MAGFILTER, "MagFilter"},
388 {SC_SAMPLERSTATE, D3DSAMP_MINFILTER, "MinFilter"},
389 {SC_SAMPLERSTATE, D3DSAMP_MIPFILTER, "MipFilter"},
390 {SC_SAMPLERSTATE, D3DSAMP_MIPMAPLODBIAS, "MipMapLodBias"},
391 {SC_SAMPLERSTATE, D3DSAMP_MAXMIPLEVEL, "MaxMipLevel"},
392 {SC_SAMPLERSTATE, D3DSAMP_MAXANISOTROPY, "MaxAnisotropy"},
393 {SC_SAMPLERSTATE, D3DSAMP_SRGBTEXTURE, "SRGBTexture"},
394 {SC_SAMPLERSTATE, D3DSAMP_ELEMENTINDEX, "ElementIndex"}, /* 0xb0 */
395 {SC_SAMPLERSTATE, D3DSAMP_DMAPOFFSET, "DMAPOffset"},
396 /* Set sampler */
397 {SC_SETSAMPLER, 0, "Sampler"},
400 static inline void read_dword(const char **ptr, DWORD *d)
402 memcpy(d, *ptr, sizeof(*d));
403 *ptr += sizeof(*d);
406 static void skip_dword_unknown(const char **ptr, unsigned int count)
408 unsigned int i;
409 DWORD d;
411 FIXME("Skipping %u unknown DWORDs:\n", count);
412 for (i = 0; i < count; ++i)
414 read_dword(ptr, &d);
415 FIXME("\t0x%08x\n", d);
419 static inline struct d3dx_parameter *get_parameter_struct(D3DXHANDLE handle)
421 return (struct d3dx_parameter *) handle;
424 static inline struct d3dx_pass *get_pass_struct(D3DXHANDLE handle)
426 return (struct d3dx_pass *) handle;
429 static inline struct d3dx_technique *get_technique_struct(D3DXHANDLE handle)
431 return (struct d3dx_technique *) handle;
434 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
436 return (D3DXHANDLE) parameter;
439 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
441 return (D3DXHANDLE) technique;
444 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
446 return (D3DXHANDLE) pass;
449 static struct d3dx_technique *is_valid_technique(struct ID3DXBaseEffectImpl *base, D3DXHANDLE technique)
451 unsigned int i;
453 for (i = 0; i < base->technique_count; ++i)
455 if (base->technique_handles[i] == technique)
457 return get_technique_struct(technique);
461 return NULL;
464 static struct d3dx_pass *is_valid_pass(struct ID3DXBaseEffectImpl *base, D3DXHANDLE pass)
466 unsigned int i, k;
468 for (i = 0; i < base->technique_count; ++i)
470 struct d3dx_technique *technique = get_technique_struct(base->technique_handles[i]);
472 for (k = 0; k < technique->pass_count; ++k)
474 if (technique->pass_handles[k] == pass)
476 return get_pass_struct(pass);
481 return NULL;
484 static struct d3dx_parameter *is_valid_sub_parameter(struct d3dx_parameter *param, D3DXHANDLE parameter)
486 unsigned int i, count;
487 struct d3dx_parameter *p;
489 for (i = 0; i < param->annotation_count; ++i)
491 if (param->annotation_handles[i] == parameter)
493 return get_parameter_struct(parameter);
496 p = is_valid_sub_parameter(get_parameter_struct(param->annotation_handles[i]), parameter);
497 if (p) return p;
500 if (param->element_count) count = param->element_count;
501 else count = param->member_count;
503 for (i = 0; i < count; ++i)
505 if (param->member_handles[i] == parameter)
507 return get_parameter_struct(parameter);
510 p = is_valid_sub_parameter(get_parameter_struct(param->member_handles[i]), parameter);
511 if (p) return p;
514 return NULL;
517 static struct d3dx_parameter *is_valid_parameter(struct ID3DXBaseEffectImpl *base, D3DXHANDLE parameter)
519 unsigned int i, k, m;
520 struct d3dx_parameter *p;
522 for (i = 0; i < base->parameter_count; ++i)
524 if (base->parameter_handles[i] == parameter)
526 return get_parameter_struct(parameter);
529 p = is_valid_sub_parameter(get_parameter_struct(base->parameter_handles[i]), parameter);
530 if (p) return p;
533 for (i = 0; i < base->technique_count; ++i)
535 struct d3dx_technique *technique = get_technique_struct(base->technique_handles[i]);
537 for (k = 0; k < technique->pass_count; ++k)
539 struct d3dx_pass *pass = get_pass_struct(technique->pass_handles[k]);
541 for (m = 0; m < pass->annotation_count; ++m)
543 if (pass->annotation_handles[i] == parameter)
545 return get_parameter_struct(parameter);
548 p = is_valid_sub_parameter(get_parameter_struct(pass->annotation_handles[m]), parameter);
549 if (p) return p;
553 for (k = 0; k < technique->annotation_count; ++k)
555 if (technique->annotation_handles[k] == parameter)
557 return get_parameter_struct(parameter);
560 p = is_valid_sub_parameter(get_parameter_struct(technique->annotation_handles[k]), parameter);
561 if (p) return p;
565 return NULL;
568 static inline struct d3dx_parameter *get_valid_parameter(struct ID3DXBaseEffectImpl *base, D3DXHANDLE parameter)
570 struct d3dx_parameter *param = is_valid_parameter(base, parameter);
572 if (!param) param = get_parameter_by_name(base, NULL, parameter);
574 return param;
577 static void free_state(struct d3dx_state *state)
579 free_parameter_state(state->parameter, FALSE, FALSE, state->type);
582 static void free_sampler(struct d3dx_sampler *sampler)
584 UINT i;
586 for (i = 0; i < sampler->state_count; ++i)
588 free_state(&sampler->states[i]);
590 HeapFree(GetProcessHeap(), 0, sampler->states);
593 static void free_parameter(D3DXHANDLE handle, BOOL element, BOOL child)
595 free_parameter_state(handle, element, child, ST_CONSTANT);
598 static void free_parameter_state(D3DXHANDLE handle, BOOL element, BOOL child, enum STATE_TYPE st)
600 unsigned int i;
601 struct d3dx_parameter *param = get_parameter_struct(handle);
603 TRACE("Free parameter %p, name %s, type %s, child %s, state_type %x\n", param, param->name,
604 debug_d3dxparameter_type(param->type), child ? "yes" : "no", st);
606 if (!param)
608 return;
611 if (param->annotation_handles)
613 for (i = 0; i < param->annotation_count; ++i)
615 free_parameter(param->annotation_handles[i], FALSE, FALSE);
617 HeapFree(GetProcessHeap(), 0, param->annotation_handles);
620 if (param->member_handles)
622 unsigned int count;
624 if (param->element_count) count = param->element_count;
625 else count = param->member_count;
627 for (i = 0; i < count; ++i)
629 free_parameter(param->member_handles[i], param->element_count != 0, TRUE);
631 HeapFree(GetProcessHeap(), 0, param->member_handles);
634 if (param->class == D3DXPC_OBJECT && !param->element_count)
636 switch (param->type)
638 case D3DXPT_STRING:
639 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
640 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
641 break;
643 case D3DXPT_TEXTURE:
644 case D3DXPT_TEXTURE1D:
645 case D3DXPT_TEXTURE2D:
646 case D3DXPT_TEXTURE3D:
647 case D3DXPT_TEXTURECUBE:
648 case D3DXPT_PIXELSHADER:
649 case D3DXPT_VERTEXSHADER:
650 if (st == ST_CONSTANT)
652 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
654 else
656 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
658 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
659 break;
661 case D3DXPT_SAMPLER:
662 case D3DXPT_SAMPLER1D:
663 case D3DXPT_SAMPLER2D:
664 case D3DXPT_SAMPLER3D:
665 case D3DXPT_SAMPLERCUBE:
666 if (st == ST_CONSTANT)
668 free_sampler((struct d3dx_sampler *)param->data);
670 else
672 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
674 /* samplers have always own data, so free that */
675 HeapFree(GetProcessHeap(), 0, param->data);
676 break;
678 default:
679 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
680 break;
683 else
685 if (!child)
687 if (st != ST_CONSTANT)
689 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
691 HeapFree(GetProcessHeap(), 0, param->data);
695 /* only the parent has to release name and semantic */
696 if (!element)
698 HeapFree(GetProcessHeap(), 0, param->name);
699 HeapFree(GetProcessHeap(), 0, param->semantic);
702 HeapFree(GetProcessHeap(), 0, param);
705 static void free_pass(D3DXHANDLE handle)
707 unsigned int i;
708 struct d3dx_pass *pass = get_pass_struct(handle);
710 TRACE("Free pass %p\n", pass);
712 if (!pass)
714 return;
717 if (pass->annotation_handles)
719 for (i = 0; i < pass->annotation_count; ++i)
721 free_parameter(pass->annotation_handles[i], FALSE, FALSE);
723 HeapFree(GetProcessHeap(), 0, pass->annotation_handles);
726 if (pass->states)
728 for (i = 0; i < pass->state_count; ++i)
730 free_state(&pass->states[i]);
732 HeapFree(GetProcessHeap(), 0, pass->states);
735 HeapFree(GetProcessHeap(), 0, pass->name);
736 HeapFree(GetProcessHeap(), 0, pass);
739 static void free_technique(D3DXHANDLE handle)
741 unsigned int i;
742 struct d3dx_technique *technique = get_technique_struct(handle);
744 TRACE("Free technique %p\n", technique);
746 if (!technique)
748 return;
751 if (technique->annotation_handles)
753 for (i = 0; i < technique->annotation_count; ++i)
755 free_parameter(technique->annotation_handles[i], FALSE, FALSE);
757 HeapFree(GetProcessHeap(), 0, technique->annotation_handles);
760 if (technique->pass_handles)
762 for (i = 0; i < technique->pass_count; ++i)
764 free_pass(technique->pass_handles[i]);
766 HeapFree(GetProcessHeap(), 0, technique->pass_handles);
769 HeapFree(GetProcessHeap(), 0, technique->name);
770 HeapFree(GetProcessHeap(), 0, technique);
773 static void free_base_effect(struct ID3DXBaseEffectImpl *base)
775 unsigned int i;
777 TRACE("Free base effect %p\n", base);
779 if (base->parameter_handles)
781 for (i = 0; i < base->parameter_count; ++i)
783 free_parameter(base->parameter_handles[i], FALSE, FALSE);
785 HeapFree(GetProcessHeap(), 0, base->parameter_handles);
788 if (base->technique_handles)
790 for (i = 0; i < base->technique_count; ++i)
792 free_technique(base->technique_handles[i]);
794 HeapFree(GetProcessHeap(), 0, base->technique_handles);
798 static void free_effect(struct ID3DXEffectImpl *effect)
800 TRACE("Free effect %p\n", effect);
802 if (effect->base_effect)
804 effect->base_effect->lpVtbl->Release(effect->base_effect);
807 if (effect->pool)
809 effect->pool->lpVtbl->Release(effect->pool);
812 if (effect->manager)
814 IUnknown_Release(effect->manager);
817 IDirect3DDevice9_Release(effect->device);
820 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
822 TRACE("Free effect compiler %p\n", compiler);
824 if (compiler->base_effect)
826 compiler->base_effect->lpVtbl->Release(compiler->base_effect);
830 static INT get_int(D3DXPARAMETER_TYPE type, LPCVOID data)
832 INT i;
834 switch (type)
836 case D3DXPT_FLOAT:
837 i = *(FLOAT *)data;
838 break;
840 case D3DXPT_INT:
841 i = *(INT *)data;
842 break;
844 case D3DXPT_BOOL:
845 i = *(BOOL *)data;
846 break;
848 default:
849 i = 0;
850 FIXME("Unhandled type %s. This should not happen!\n", debug_d3dxparameter_type(type));
851 break;
854 return i;
857 inline static FLOAT get_float(D3DXPARAMETER_TYPE type, LPCVOID data)
859 FLOAT f;
861 switch (type)
863 case D3DXPT_FLOAT:
864 f = *(FLOAT *)data;
865 break;
867 case D3DXPT_INT:
868 f = *(INT *)data;
869 break;
871 case D3DXPT_BOOL:
872 f = *(BOOL *)data;
873 break;
875 default:
876 f = 0.0f;
877 FIXME("Unhandled type %s. This should not happen!\n", debug_d3dxparameter_type(type));
878 break;
881 return f;
884 static inline BOOL get_bool(LPCVOID data)
886 return (*(DWORD *)data) ? TRUE : FALSE;
889 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
891 vector->x = get_float(param->type, (float *)param->data);
892 vector->y = param->columns > 1 ? get_float(param->type, (float *)param->data + 1) : 0.0f;
893 vector->z = param->columns > 2 ? get_float(param->type, (float *)param->data + 2) : 0.0f;
894 vector->w = param->columns > 3 ? get_float(param->type, (float *)param->data + 3) : 0.0f;
897 static void set_number(LPVOID outdata, D3DXPARAMETER_TYPE outtype, LPCVOID indata, D3DXPARAMETER_TYPE intype)
899 TRACE("Changing from type %i to type %i\n", intype, outtype);
901 switch (outtype)
903 case D3DXPT_FLOAT:
904 *(FLOAT *)outdata = get_float(intype, indata);
905 break;
907 case D3DXPT_BOOL:
908 *(BOOL *)outdata = get_bool(indata);
909 break;
911 case D3DXPT_INT:
912 *(INT *)outdata = get_int(intype, indata);
913 break;
915 default:
916 FIXME("Error converting to type %i\n", outtype);
917 *(INT *)outdata = 0;
918 break;
922 static void set_vector(struct d3dx_parameter *param, CONST D3DXVECTOR4 *vector)
924 UINT i;
926 for (i = 0; i < param->columns; ++i)
928 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
932 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix)
934 unsigned int i, k;
936 for (i = 0; i < 4; ++i)
938 for (k = 0; k < 4; ++k)
940 if ((i < param->rows) && (k < param->columns))
941 matrix->u.m[i][k] = get_float(param->type, (float *)param->data + i * param->columns + k);
942 else
943 matrix->u.m[i][k] = 0.0f;
948 static void set_matrix(struct d3dx_parameter *param, CONST D3DXMATRIX *matrix)
950 unsigned int i, k;
952 for (i = 0; i < 4; ++i)
954 for (k = 0; k < 4; ++k)
956 if ((i < param->rows) && (k < param->columns))
957 set_number((float *)param->data + i * param->columns + k, param->type, &matrix->u.m[i][k], D3DXPT_FLOAT);
962 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, LPCSTR name)
964 UINT element;
965 struct d3dx_parameter *temp_parameter;
966 LPCSTR part;
968 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
970 if (!name || !*name) return parameter;
972 element = atoi(name);
973 part = strchr(name, ']') + 1;
975 if (parameter->element_count > element)
977 temp_parameter = get_parameter_struct(parameter->member_handles[element]);
979 switch (*part++)
981 case '.':
982 return get_parameter_by_name(NULL, temp_parameter, part);
984 case '@':
985 return get_parameter_annotation_by_name(temp_parameter, part);
987 case '\0':
988 TRACE("Returning parameter %p\n", temp_parameter);
989 return temp_parameter;
991 default:
992 FIXME("Unhandled case \"%c\"\n", *--part);
993 break;
997 TRACE("Parameter not found\n");
998 return NULL;
1001 static struct d3dx_parameter *get_parameter_annotation_by_name(struct d3dx_parameter *parameter, LPCSTR name)
1003 UINT i, length;
1004 struct d3dx_parameter *temp_parameter;
1005 LPCSTR part;
1007 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
1009 if (!name || !*name) return parameter;
1011 length = strcspn( name, "[.@" );
1012 part = name + length;
1014 for (i = 0; i < parameter->annotation_count; ++i)
1016 temp_parameter = get_parameter_struct(parameter->annotation_handles[i]);
1018 if (!strcmp(temp_parameter->name, name))
1020 TRACE("Returning parameter %p\n", temp_parameter);
1021 return temp_parameter;
1023 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
1025 switch (*part++)
1027 case '.':
1028 return get_parameter_by_name(NULL, temp_parameter, part);
1030 case '[':
1031 return get_parameter_element_by_name(temp_parameter, part);
1033 default:
1034 FIXME("Unhandled case \"%c\"\n", *--part);
1035 break;
1040 TRACE("Parameter not found\n");
1041 return NULL;
1044 static struct d3dx_parameter *get_parameter_by_name(struct ID3DXBaseEffectImpl *base,
1045 struct d3dx_parameter *parameter, LPCSTR name)
1047 UINT i, count, length;
1048 struct d3dx_parameter *temp_parameter;
1049 D3DXHANDLE *handles;
1050 LPCSTR part;
1052 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
1054 if (!name || !*name) return parameter;
1056 if (!parameter)
1058 count = base->parameter_count;
1059 handles = base->parameter_handles;
1061 else
1063 count = parameter->member_count;
1064 handles = parameter->member_handles;
1067 length = strcspn( name, "[.@" );
1068 part = name + length;
1070 for (i = 0; i < count; i++)
1072 temp_parameter = get_parameter_struct(handles[i]);
1074 if (!strcmp(temp_parameter->name, name))
1076 TRACE("Returning parameter %p\n", temp_parameter);
1077 return temp_parameter;
1079 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
1081 switch (*part++)
1083 case '.':
1084 return get_parameter_by_name(NULL, temp_parameter, part);
1086 case '@':
1087 return get_parameter_annotation_by_name(temp_parameter, part);
1089 case '[':
1090 return get_parameter_element_by_name(temp_parameter, part);
1092 default:
1093 FIXME("Unhandled case \"%c\"\n", *--part);
1094 break;
1099 TRACE("Parameter not found\n");
1100 return NULL;
1103 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
1105 return (0xfeff0000 | ((major) << 8) | (minor));
1108 static inline struct ID3DXBaseEffectImpl *impl_from_ID3DXBaseEffect(ID3DXBaseEffect *iface)
1110 return CONTAINING_RECORD(iface, struct ID3DXBaseEffectImpl, ID3DXBaseEffect_iface);
1113 /*** IUnknown methods ***/
1114 static HRESULT WINAPI ID3DXBaseEffectImpl_QueryInterface(ID3DXBaseEffect *iface, REFIID riid, void **object)
1116 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1118 TRACE("iface %p, riid %s, object %p\n", This, debugstr_guid(riid), object);
1120 if (IsEqualGUID(riid, &IID_IUnknown) ||
1121 IsEqualGUID(riid, &IID_ID3DXBaseEffect))
1123 This->ID3DXBaseEffect_iface.lpVtbl->AddRef(iface);
1124 *object = This;
1125 return S_OK;
1128 ERR("Interface %s not found\n", debugstr_guid(riid));
1130 return E_NOINTERFACE;
1133 static ULONG WINAPI ID3DXBaseEffectImpl_AddRef(ID3DXBaseEffect *iface)
1135 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1137 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
1139 return InterlockedIncrement(&This->ref);
1142 static ULONG WINAPI ID3DXBaseEffectImpl_Release(ID3DXBaseEffect *iface)
1144 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1145 ULONG ref = InterlockedDecrement(&This->ref);
1147 TRACE("iface %p: Release from %u\n", iface, ref + 1);
1149 if (!ref)
1151 free_base_effect(This);
1152 HeapFree(GetProcessHeap(), 0, This);
1155 return ref;
1158 /*** ID3DXBaseEffect methods ***/
1159 static HRESULT WINAPI ID3DXBaseEffectImpl_GetDesc(ID3DXBaseEffect *iface, D3DXEFFECT_DESC *desc)
1161 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1163 FIXME("iface %p, desc %p partial stub\n", This, desc);
1165 if (!desc)
1167 WARN("Invalid argument specified.\n");
1168 return D3DERR_INVALIDCALL;
1171 /* Todo: add creator and function count */
1172 desc->Creator = NULL;
1173 desc->Functions = 0;
1174 desc->Parameters = This->parameter_count;
1175 desc->Techniques = This->technique_count;
1177 return D3D_OK;
1180 static HRESULT WINAPI ID3DXBaseEffectImpl_GetParameterDesc(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
1182 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1183 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1185 TRACE("iface %p, parameter %p, desc %p\n", This, parameter, desc);
1187 if (!desc || !param)
1189 WARN("Invalid argument specified.\n");
1190 return D3DERR_INVALIDCALL;
1193 desc->Name = param->name;
1194 desc->Semantic = param->semantic;
1195 desc->Class = param->class;
1196 desc->Type = param->type;
1197 desc->Rows = param->rows;
1198 desc->Columns = param->columns;
1199 desc->Elements = param->element_count;
1200 desc->Annotations = param->annotation_count;
1201 desc->StructMembers = param->member_count;
1202 desc->Flags = param->flags;
1203 desc->Bytes = param->bytes;
1205 return D3D_OK;
1208 static HRESULT WINAPI ID3DXBaseEffectImpl_GetTechniqueDesc(ID3DXBaseEffect *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
1210 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1211 struct d3dx_technique *tech = technique ? is_valid_technique(This, technique) : get_technique_struct(This->technique_handles[0]);
1213 TRACE("iface %p, technique %p, desc %p\n", This, technique, desc);
1215 if (!desc || !tech)
1217 WARN("Invalid argument specified.\n");
1218 return D3DERR_INVALIDCALL;
1221 desc->Name = tech->name;
1222 desc->Passes = tech->pass_count;
1223 desc->Annotations = tech->annotation_count;
1225 return D3D_OK;
1228 static HRESULT WINAPI ID3DXBaseEffectImpl_GetPassDesc(ID3DXBaseEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
1230 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1231 struct d3dx_pass *p = is_valid_pass(This, pass);
1233 TRACE("iface %p, pass %p, desc %p\n", This, pass, desc);
1235 if (!desc || !p)
1237 WARN("Invalid argument specified.\n");
1238 return D3DERR_INVALIDCALL;
1241 desc->Name = p->name;
1242 desc->Annotations = p->annotation_count;
1244 FIXME("Pixel shader and vertex shader are not supported, yet.\n");
1245 desc->pVertexShaderFunction = NULL;
1246 desc->pPixelShaderFunction = NULL;
1248 return D3D_OK;
1251 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFunctionDesc(ID3DXBaseEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1253 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1255 FIXME("iface %p, shader %p, desc %p stub\n", This, shader, desc);
1257 return E_NOTIMPL;
1260 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameter(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT index)
1262 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1263 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1265 TRACE("iface %p, parameter %p, index %u\n", This, parameter, index);
1267 if (!parameter)
1269 if (index < This->parameter_count)
1271 TRACE("Returning parameter %p\n", This->parameter_handles[index]);
1272 return This->parameter_handles[index];
1275 else
1277 if (param && !param->element_count && index < param->member_count)
1279 TRACE("Returning parameter %p\n", param->member_handles[index]);
1280 return param->member_handles[index];
1284 WARN("Invalid argument specified.\n");
1286 return NULL;
1289 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterByName(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR name)
1291 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1292 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1293 D3DXHANDLE handle;
1295 TRACE("iface %p, parameter %p, name %s\n", This, parameter, debugstr_a(name));
1297 if (!name)
1299 handle = get_parameter_handle(param);
1300 TRACE("Returning parameter %p\n", handle);
1301 return handle;
1304 handle = get_parameter_handle(get_parameter_by_name(This, param, name));
1305 TRACE("Returning parameter %p\n", handle);
1307 return handle;
1310 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterBySemantic(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR semantic)
1312 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1313 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1314 struct d3dx_parameter *temp_param;
1315 UINT i;
1317 TRACE("iface %p, parameter %p, semantic %s\n", This, parameter, debugstr_a(semantic));
1319 if (!parameter)
1321 for (i = 0; i < This->parameter_count; ++i)
1323 temp_param = get_parameter_struct(This->parameter_handles[i]);
1325 if (!temp_param->semantic)
1327 if (!semantic)
1329 TRACE("Returning parameter %p\n", This->parameter_handles[i]);
1330 return This->parameter_handles[i];
1332 continue;
1335 if (!strcasecmp(temp_param->semantic, semantic))
1337 TRACE("Returning parameter %p\n", This->parameter_handles[i]);
1338 return This->parameter_handles[i];
1342 else if (param)
1344 for (i = 0; i < param->member_count; ++i)
1346 temp_param = get_parameter_struct(param->member_handles[i]);
1348 if (!temp_param->semantic)
1350 if (!semantic)
1352 TRACE("Returning parameter %p\n", param->member_handles[i]);
1353 return param->member_handles[i];
1355 continue;
1358 if (!strcasecmp(temp_param->semantic, semantic))
1360 TRACE("Returning parameter %p\n", param->member_handles[i]);
1361 return param->member_handles[i];
1366 WARN("Invalid argument specified\n");
1368 return NULL;
1371 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterElement(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT index)
1373 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1374 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1376 TRACE("iface %p, parameter %p, index %u\n", This, parameter, index);
1378 if (!param)
1380 if (index < This->parameter_count)
1382 TRACE("Returning parameter %p\n", This->parameter_handles[index]);
1383 return This->parameter_handles[index];
1386 else
1388 if (index < param->element_count)
1390 TRACE("Returning parameter %p\n", param->member_handles[index]);
1391 return param->member_handles[index];
1395 WARN("Invalid argument specified\n");
1397 return NULL;
1400 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetTechnique(ID3DXBaseEffect *iface, UINT index)
1402 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1404 TRACE("iface %p, index %u\n", This, index);
1406 if (index >= This->technique_count)
1408 WARN("Invalid argument specified.\n");
1409 return NULL;
1412 TRACE("Returning technique %p\n", This->technique_handles[index]);
1414 return This->technique_handles[index];
1417 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetTechniqueByName(ID3DXBaseEffect *iface, LPCSTR name)
1419 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1420 unsigned int i;
1422 TRACE("iface %p, name %s stub\n", This, debugstr_a(name));
1424 if (!name)
1426 WARN("Invalid argument specified.\n");
1427 return NULL;
1430 for (i = 0; i < This->technique_count; ++i)
1432 struct d3dx_technique *tech = get_technique_struct(This->technique_handles[i]);
1434 if (!strcmp(tech->name, name))
1436 TRACE("Returning technique %p\n", This->technique_handles[i]);
1437 return This->technique_handles[i];
1441 WARN("Invalid argument specified.\n");
1443 return NULL;
1446 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetPass(ID3DXBaseEffect *iface, D3DXHANDLE technique, UINT index)
1448 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1449 struct d3dx_technique *tech = is_valid_technique(This, technique);
1451 TRACE("iface %p, technique %p, index %u\n", This, technique, index);
1453 if (!tech) tech = get_technique_struct(iface->lpVtbl->GetTechniqueByName(iface, technique));
1455 if (tech && index < tech->pass_count)
1457 TRACE("Returning pass %p\n", tech->pass_handles[index]);
1458 return tech->pass_handles[index];
1461 WARN("Invalid argument specified.\n");
1463 return NULL;
1466 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetPassByName(ID3DXBaseEffect *iface, D3DXHANDLE technique, LPCSTR name)
1468 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1469 struct d3dx_technique *tech = is_valid_technique(This, technique);
1471 TRACE("iface %p, technique %p, name %s\n", This, technique, debugstr_a(name));
1473 if (!tech) tech = get_technique_struct(iface->lpVtbl->GetTechniqueByName(iface, technique));
1475 if (tech && name)
1477 unsigned int i;
1479 for (i = 0; i < tech->pass_count; ++i)
1481 struct d3dx_pass *pass = get_pass_struct(tech->pass_handles[i]);
1483 if (!strcmp(pass->name, name))
1485 TRACE("Returning pass %p\n", tech->pass_handles[i]);
1486 return tech->pass_handles[i];
1491 WARN("Invalid argument specified.\n");
1493 return NULL;
1496 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetFunction(ID3DXBaseEffect *iface, UINT index)
1498 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1500 FIXME("iface %p, index %u stub\n", This, index);
1502 return NULL;
1505 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetFunctionByName(ID3DXBaseEffect *iface, LPCSTR name)
1507 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1509 FIXME("iface %p, name %s stub\n", This, debugstr_a(name));
1511 return NULL;
1514 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetAnnotation(ID3DXBaseEffect *iface, D3DXHANDLE object, UINT index)
1516 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1517 struct d3dx_parameter *param = get_valid_parameter(This, object);
1518 struct d3dx_pass *pass = is_valid_pass(This, object);
1519 struct d3dx_technique *technique = is_valid_technique(This, object);
1520 UINT annotation_count = 0;
1521 D3DXHANDLE *annotation_handles = NULL;
1523 FIXME("iface %p, object %p, index %u partial stub\n", This, object, index);
1525 if (pass)
1527 annotation_count = pass->annotation_count;
1528 annotation_handles = pass->annotation_handles;
1530 else if (technique)
1532 annotation_count = technique->annotation_count;
1533 annotation_handles = technique->annotation_handles;
1535 else if (param)
1537 annotation_count = param->annotation_count;
1538 annotation_handles = param->annotation_handles;
1540 /* Todo: add funcs */
1542 if (index < annotation_count)
1544 TRACE("Returning parameter %p\n", annotation_handles[index]);
1545 return annotation_handles[index];
1548 WARN("Invalid argument specified\n");
1550 return NULL;
1553 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetAnnotationByName(ID3DXBaseEffect *iface, D3DXHANDLE object, LPCSTR name)
1555 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1556 struct d3dx_parameter *param = get_valid_parameter(This, object);
1557 struct d3dx_pass *pass = is_valid_pass(This, object);
1558 struct d3dx_technique *technique = is_valid_technique(This, object);
1559 UINT annotation_count = 0, i;
1560 D3DXHANDLE *annotation_handles = NULL;
1562 FIXME("iface %p, object %p, name %s partial stub\n", This, object, debugstr_a(name));
1564 if (!name)
1566 WARN("Invalid argument specified\n");
1567 return NULL;
1570 if (pass)
1572 annotation_count = pass->annotation_count;
1573 annotation_handles = pass->annotation_handles;
1575 else if (technique)
1577 annotation_count = technique->annotation_count;
1578 annotation_handles = technique->annotation_handles;
1580 else if (param)
1582 annotation_count = param->annotation_count;
1583 annotation_handles = param->annotation_handles;
1585 /* Todo: add funcs */
1587 for (i = 0; i < annotation_count; i++)
1589 struct d3dx_parameter *anno = get_parameter_struct(annotation_handles[i]);
1591 if (!strcmp(anno->name, name))
1593 TRACE("Returning parameter %p\n", anno);
1594 return get_parameter_handle(anno);
1598 WARN("Invalid argument specified\n");
1600 return NULL;
1603 static HRESULT WINAPI ID3DXBaseEffectImpl_SetValue(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
1605 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1607 FIXME("iface %p, parameter %p, data %p, bytes %u stub\n", This, parameter, data, bytes);
1609 return E_NOTIMPL;
1612 static HRESULT WINAPI ID3DXBaseEffectImpl_GetValue(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
1614 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1615 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1617 TRACE("iface %p, parameter %p, data %p, bytes %u\n", This, parameter, data, bytes);
1619 if (!param)
1621 WARN("Invalid parameter %p specified\n", parameter);
1622 return D3DERR_INVALIDCALL;
1625 /* samplers don't touch data */
1626 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1627 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1628 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1630 TRACE("Sampler: returning E_FAIL\n");
1631 return E_FAIL;
1634 if (data && param->bytes <= bytes)
1636 TRACE("Type %s\n", debug_d3dxparameter_type(param->type));
1638 switch (param->type)
1640 case D3DXPT_VOID:
1641 case D3DXPT_BOOL:
1642 case D3DXPT_INT:
1643 case D3DXPT_FLOAT:
1644 case D3DXPT_STRING:
1645 break;
1647 case D3DXPT_VERTEXSHADER:
1648 case D3DXPT_PIXELSHADER:
1649 case D3DXPT_TEXTURE:
1650 case D3DXPT_TEXTURE1D:
1651 case D3DXPT_TEXTURE2D:
1652 case D3DXPT_TEXTURE3D:
1653 case D3DXPT_TEXTURECUBE:
1655 UINT i;
1657 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1659 IUnknown *unk = ((IUnknown **)param->data)[i];
1660 if (unk) IUnknown_AddRef(unk);
1662 break;
1665 default:
1666 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1667 break;
1670 TRACE("Copy %u bytes\n", param->bytes);
1671 memcpy(data, param->data, param->bytes);
1672 return D3D_OK;
1675 WARN("Invalid argument specified\n");
1677 return D3DERR_INVALIDCALL;
1680 static HRESULT WINAPI ID3DXBaseEffectImpl_SetBool(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL b)
1682 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1683 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1685 TRACE("iface %p, parameter %p, b %s\n", This, parameter, b ? "TRUE" : "FALSE");
1687 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1689 set_number(param->data, param->type, &b, D3DXPT_BOOL);
1690 return D3D_OK;
1693 WARN("Invalid argument specified\n");
1695 return D3DERR_INVALIDCALL;
1698 static HRESULT WINAPI ID3DXBaseEffectImpl_GetBool(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL *b)
1700 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1701 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1703 TRACE("iface %p, parameter %p, b %p\n", This, parameter, b);
1705 if (b && param && !param->element_count && param->rows == 1 && param->columns == 1)
1707 *b = get_bool(param->data);
1708 TRACE("Returning %s\n", *b ? "TRUE" : "FALSE");
1709 return D3D_OK;
1712 WARN("Invalid argument specified\n");
1714 return D3DERR_INVALIDCALL;
1717 static HRESULT WINAPI ID3DXBaseEffectImpl_SetBoolArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
1719 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1720 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1722 TRACE("iface %p, parameter %p, b %p, count %u\n", This, parameter, b, count);
1724 if (param)
1726 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1728 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1730 switch (param->class)
1732 case D3DXPC_SCALAR:
1733 case D3DXPC_VECTOR:
1734 case D3DXPC_MATRIX_ROWS:
1735 for (i = 0; i < size; ++i)
1737 set_number((DWORD *)param->data + i, param->type, &b[i], D3DXPT_BOOL);
1739 return D3D_OK;
1741 case D3DXPC_OBJECT:
1742 case D3DXPC_STRUCT:
1743 break;
1745 default:
1746 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1747 break;
1751 WARN("Invalid argument specified\n");
1753 return D3DERR_INVALIDCALL;
1756 static HRESULT WINAPI ID3DXBaseEffectImpl_GetBoolArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
1758 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1759 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1761 TRACE("iface %p, parameter %p, b %p, count %u\n", This, parameter, b, count);
1763 if (b && param && (param->class == D3DXPC_SCALAR
1764 || param->class == D3DXPC_VECTOR
1765 || param->class == D3DXPC_MATRIX_ROWS
1766 || param->class == D3DXPC_MATRIX_COLUMNS))
1768 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1770 for (i = 0; i < size; ++i)
1772 b[i] = get_bool((DWORD *)param->data + i);
1774 return D3D_OK;
1777 WARN("Invalid argument specified\n");
1779 return D3DERR_INVALIDCALL;
1782 static HRESULT WINAPI ID3DXBaseEffectImpl_SetInt(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT n)
1784 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1785 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1787 TRACE("iface %p, parameter %p, n %i\n", This, parameter, n);
1789 if (param && !param->element_count)
1791 if (param->rows == 1 && param->columns == 1)
1793 set_number(param->data, param->type, &n, D3DXPT_INT);
1794 return D3D_OK;
1798 * Split the value, if parameter is a vector with dimension 3 or 4.
1800 if (param->type == D3DXPT_FLOAT &&
1801 ((param->class == D3DXPC_VECTOR && param->columns != 2) ||
1802 (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1804 FLOAT tmp = ((n & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1805 set_number((DWORD *)param->data, param->type, &tmp, D3DXPT_FLOAT);
1807 tmp = ((n & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1808 set_number((DWORD *)param->data + 1, param->type, &tmp, D3DXPT_FLOAT);
1810 tmp = (n & 0xff) * INT_FLOAT_MULTI_INVERSE;
1811 set_number((DWORD *)param->data + 2, param->type, &tmp, D3DXPT_FLOAT);
1813 if (param->rows * param->columns > 3)
1815 tmp = ((n & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1816 set_number((DWORD *)param->data + 3, param->type, &tmp, D3DXPT_FLOAT);
1818 return D3D_OK;
1822 WARN("Invalid argument specified\n");
1824 return D3DERR_INVALIDCALL;
1827 static HRESULT WINAPI ID3DXBaseEffectImpl_GetInt(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT *n)
1829 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1830 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1832 TRACE("iface %p, parameter %p, n %p\n", This, parameter, n);
1834 if (n && param && !param->element_count)
1836 if (param->columns == 1 && param->rows == 1)
1838 *n = get_int(param->type, param->data);
1839 TRACE("Returning %i\n", *n);
1840 return D3D_OK;
1843 if (param->type == D3DXPT_FLOAT &&
1844 ((param->class == D3DXPC_VECTOR && param->columns != 2)
1845 || (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1847 /* all components (3,4) are clamped (0,255) and put in the INT */
1848 *n = (INT)(min(max(0.0f, *((FLOAT *)param->data + 2)), 1.0f) * INT_FLOAT_MULTI);
1849 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 1)), 1.0f) * INT_FLOAT_MULTI)) << 8;
1850 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 0)), 1.0f) * INT_FLOAT_MULTI)) << 16;
1851 if (param->columns * param->rows > 3)
1853 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 3)), 1.0f) * INT_FLOAT_MULTI)) << 24;
1856 TRACE("Returning %i\n", *n);
1857 return D3D_OK;
1861 WARN("Invalid argument specified\n");
1863 return D3DERR_INVALIDCALL;
1866 static HRESULT WINAPI ID3DXBaseEffectImpl_SetIntArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
1868 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1869 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1871 TRACE("iface %p, parameter %p, n %p, count %u\n", This, parameter, n, count);
1873 if (param)
1875 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1877 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1879 switch (param->class)
1881 case D3DXPC_SCALAR:
1882 case D3DXPC_VECTOR:
1883 case D3DXPC_MATRIX_ROWS:
1884 for (i = 0; i < size; ++i)
1886 set_number((DWORD *)param->data + i, param->type, &n[i], D3DXPT_INT);
1888 return D3D_OK;
1890 case D3DXPC_OBJECT:
1891 case D3DXPC_STRUCT:
1892 break;
1894 default:
1895 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1896 break;
1900 WARN("Invalid argument specified\n");
1902 return D3DERR_INVALIDCALL;
1905 static HRESULT WINAPI ID3DXBaseEffectImpl_GetIntArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT *n, UINT count)
1907 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1908 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1910 TRACE("iface %p, parameter %p, n %p, count %u\n", This, parameter, n, count);
1912 if (n && param && (param->class == D3DXPC_SCALAR
1913 || param->class == D3DXPC_VECTOR
1914 || param->class == D3DXPC_MATRIX_ROWS
1915 || param->class == D3DXPC_MATRIX_COLUMNS))
1917 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1919 for (i = 0; i < size; ++i)
1921 n[i] = get_int(param->type, (DWORD *)param->data + i);
1923 return D3D_OK;
1926 WARN("Invalid argument specified\n");
1928 return D3DERR_INVALIDCALL;
1931 static HRESULT WINAPI ID3DXBaseEffectImpl_SetFloat(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT f)
1933 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1934 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1936 TRACE("iface %p, parameter %p, f %f\n", This, parameter, f);
1938 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1940 set_number((DWORD *)param->data, param->type, &f, D3DXPT_FLOAT);
1941 return D3D_OK;
1944 WARN("Invalid argument specified\n");
1946 return D3DERR_INVALIDCALL;
1949 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFloat(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT *f)
1951 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1952 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1954 TRACE("iface %p, parameter %p, f %p\n", This, parameter, f);
1956 if (f && param && !param->element_count && param->columns == 1 && param->rows == 1)
1958 *f = get_float(param->type, (DWORD *)param->data);
1959 TRACE("Returning %f\n", *f);
1960 return D3D_OK;
1963 WARN("Invalid argument specified\n");
1965 return D3DERR_INVALIDCALL;
1968 static HRESULT WINAPI ID3DXBaseEffectImpl_SetFloatArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
1970 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1971 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1973 TRACE("iface %p, parameter %p, f %p, count %u\n", This, parameter, f, count);
1975 if (param)
1977 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1979 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1981 switch (param->class)
1983 case D3DXPC_SCALAR:
1984 case D3DXPC_VECTOR:
1985 case D3DXPC_MATRIX_ROWS:
1986 for (i = 0; i < size; ++i)
1988 set_number((DWORD *)param->data + i, param->type, &f[i], D3DXPT_FLOAT);
1990 return D3D_OK;
1992 case D3DXPC_OBJECT:
1993 case D3DXPC_STRUCT:
1994 break;
1996 default:
1997 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1998 break;
2002 WARN("Invalid argument specified\n");
2004 return D3DERR_INVALIDCALL;
2007 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFloatArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
2009 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2010 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2012 TRACE("iface %p, parameter %p, f %p, count %u\n", This, parameter, f, count);
2014 if (f && param && (param->class == D3DXPC_SCALAR
2015 || param->class == D3DXPC_VECTOR
2016 || param->class == D3DXPC_MATRIX_ROWS
2017 || param->class == D3DXPC_MATRIX_COLUMNS))
2019 UINT i, size = min(count, param->bytes / sizeof(DWORD));
2021 for (i = 0; i < size; ++i)
2023 f[i] = get_float(param->type, (DWORD *)param->data + i);
2025 return D3D_OK;
2028 WARN("Invalid argument specified\n");
2030 return D3DERR_INVALIDCALL;
2033 static HRESULT WINAPI ID3DXBaseEffectImpl_SetVector(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
2035 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2036 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2038 TRACE("iface %p, parameter %p, vector %p\n", This, parameter, vector);
2040 if (param && !param->element_count)
2042 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2044 switch (param->class)
2046 case D3DXPC_SCALAR:
2047 case D3DXPC_VECTOR:
2048 if (param->type == D3DXPT_INT && param->bytes == 4)
2050 DWORD tmp;
2052 TRACE("INT fixup\n");
2053 tmp = (DWORD)(max(min(vector->z, 1.0f), 0.0f) * INT_FLOAT_MULTI);
2054 tmp += ((DWORD)(max(min(vector->y, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 8;
2055 tmp += ((DWORD)(max(min(vector->x, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 16;
2056 tmp += ((DWORD)(max(min(vector->w, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 24;
2058 *(INT *)param->data = tmp;
2059 return D3D_OK;
2061 set_vector(param, vector);
2062 return D3D_OK;
2064 case D3DXPC_MATRIX_ROWS:
2065 case D3DXPC_OBJECT:
2066 case D3DXPC_STRUCT:
2067 break;
2069 default:
2070 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2071 break;
2075 WARN("Invalid argument specified\n");
2077 return D3DERR_INVALIDCALL;
2080 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVector(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
2082 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2083 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2085 TRACE("iface %p, parameter %p, vector %p\n", This, parameter, vector);
2087 if (vector && param && !param->element_count)
2089 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2091 switch (param->class)
2093 case D3DXPC_SCALAR:
2094 case D3DXPC_VECTOR:
2095 if (param->type == D3DXPT_INT && param->bytes == 4)
2097 TRACE("INT fixup\n");
2098 vector->x = (((*(INT *)param->data) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
2099 vector->y = (((*(INT *)param->data) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
2100 vector->z = ((*(INT *)param->data) & 0xff) * INT_FLOAT_MULTI_INVERSE;
2101 vector->w = (((*(INT *)param->data) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
2102 return D3D_OK;
2104 get_vector(param, vector);
2105 return D3D_OK;
2107 case D3DXPC_MATRIX_ROWS:
2108 case D3DXPC_OBJECT:
2109 case D3DXPC_STRUCT:
2110 break;
2112 default:
2113 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2114 break;
2118 WARN("Invalid argument specified\n");
2120 return D3DERR_INVALIDCALL;
2123 static HRESULT WINAPI ID3DXBaseEffectImpl_SetVectorArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
2125 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2126 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2128 TRACE("iface %p, parameter %p, vector %p, count %u stub\n", This, parameter, vector, count);
2130 if (param && param->element_count && param->element_count >= count)
2132 UINT i;
2134 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2136 switch (param->class)
2138 case D3DXPC_VECTOR:
2139 for (i = 0; i < count; ++i)
2141 set_vector(get_parameter_struct(param->member_handles[i]), &vector[i]);
2143 return D3D_OK;
2145 case D3DXPC_SCALAR:
2146 case D3DXPC_MATRIX_ROWS:
2147 case D3DXPC_OBJECT:
2148 case D3DXPC_STRUCT:
2149 break;
2151 default:
2152 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2153 break;
2157 WARN("Invalid argument specified\n");
2159 return D3DERR_INVALIDCALL;
2162 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVectorArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
2164 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2165 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2167 TRACE("iface %p, parameter %p, vector %p, count %u\n", This, parameter, vector, count);
2169 if (!count) return D3D_OK;
2171 if (vector && param && count <= param->element_count)
2173 UINT i;
2175 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2177 switch (param->class)
2179 case D3DXPC_VECTOR:
2180 for (i = 0; i < count; ++i)
2182 get_vector(get_parameter_struct(param->member_handles[i]), &vector[i]);
2184 return D3D_OK;
2186 case D3DXPC_SCALAR:
2187 case D3DXPC_MATRIX_ROWS:
2188 case D3DXPC_OBJECT:
2189 case D3DXPC_STRUCT:
2190 break;
2192 default:
2193 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2194 break;
2198 WARN("Invalid argument specified\n");
2200 return D3DERR_INVALIDCALL;
2203 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrix(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
2205 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2206 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2208 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2210 if (param && !param->element_count)
2212 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2214 switch (param->class)
2216 case D3DXPC_MATRIX_ROWS:
2217 set_matrix(param, matrix);
2218 return D3D_OK;
2220 case D3DXPC_SCALAR:
2221 case D3DXPC_VECTOR:
2222 case D3DXPC_OBJECT:
2223 case D3DXPC_STRUCT:
2224 break;
2226 default:
2227 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2228 break;
2232 WARN("Invalid argument specified\n");
2234 return D3DERR_INVALIDCALL;
2237 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrix(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
2239 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2240 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2242 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2244 if (matrix && param && !param->element_count)
2246 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2248 switch (param->class)
2250 case D3DXPC_MATRIX_ROWS:
2251 get_matrix(param, matrix);
2252 return D3D_OK;
2254 case D3DXPC_SCALAR:
2255 case D3DXPC_VECTOR:
2256 case D3DXPC_OBJECT:
2257 case D3DXPC_STRUCT:
2258 break;
2260 default:
2261 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2262 break;
2266 WARN("Invalid argument specified\n");
2268 return D3DERR_INVALIDCALL;
2271 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
2273 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2274 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2276 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2278 if (param && param->element_count >= count)
2280 UINT i;
2282 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2284 switch (param->class)
2286 case D3DXPC_MATRIX_ROWS:
2287 for (i = 0; i < count; ++i)
2289 set_matrix(get_parameter_struct(param->member_handles[i]), &matrix[i]);
2291 return D3D_OK;
2293 case D3DXPC_SCALAR:
2294 case D3DXPC_VECTOR:
2295 case D3DXPC_OBJECT:
2296 case D3DXPC_STRUCT:
2297 break;
2299 default:
2300 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2301 break;
2305 WARN("Invalid argument specified\n");
2307 return D3DERR_INVALIDCALL;
2310 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2312 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2313 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2315 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2317 if (!count) return D3D_OK;
2319 if (matrix && param && count <= param->element_count)
2321 UINT i;
2323 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2325 switch (param->class)
2327 case D3DXPC_MATRIX_ROWS:
2328 for (i = 0; i < count; ++i)
2330 get_matrix(get_parameter_struct(param->member_handles[i]), &matrix[i]);
2332 return D3D_OK;
2334 case D3DXPC_SCALAR:
2335 case D3DXPC_VECTOR:
2336 case D3DXPC_OBJECT:
2337 case D3DXPC_STRUCT:
2338 break;
2340 default:
2341 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2342 break;
2346 WARN("Invalid argument specified\n");
2348 return D3DERR_INVALIDCALL;
2351 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixPointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
2353 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2355 FIXME("iface %p, parameter %p, matrix %p, count %u stub\n", This, parameter, matrix, count);
2357 return E_NOTIMPL;
2360 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixPointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2362 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2364 FIXME("iface %p, parameter %p, matrix %p, count %u stub\n", This, parameter, matrix, count);
2366 return E_NOTIMPL;
2369 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTranspose(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
2371 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2372 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2373 D3DXMATRIX m;
2375 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2377 if (param && !param->element_count)
2379 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2381 switch (param->class)
2383 case D3DXPC_MATRIX_ROWS:
2384 set_matrix(param, D3DXMatrixTranspose(&m, matrix));
2385 return D3D_OK;
2387 case D3DXPC_SCALAR:
2388 case D3DXPC_VECTOR:
2389 case D3DXPC_OBJECT:
2390 case D3DXPC_STRUCT:
2391 break;
2393 default:
2394 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2395 break;
2399 WARN("Invalid argument specified\n");
2401 return D3DERR_INVALIDCALL;
2404 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTranspose(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
2406 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2407 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2408 D3DXMATRIX m;
2410 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2412 if (matrix && param && !param->element_count)
2414 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2416 switch (param->class)
2418 case D3DXPC_SCALAR:
2419 case D3DXPC_VECTOR:
2420 get_matrix(param, matrix);
2421 return D3D_OK;
2423 case D3DXPC_MATRIX_ROWS:
2424 get_matrix(param, &m);
2425 D3DXMatrixTranspose(matrix, &m);
2426 return D3D_OK;
2428 case D3DXPC_OBJECT:
2429 case D3DXPC_STRUCT:
2430 break;
2432 default:
2433 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2434 break;
2438 WARN("Invalid argument specified\n");
2440 return D3DERR_INVALIDCALL;
2443 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTransposeArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
2445 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2446 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2447 D3DXMATRIX m;
2449 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2451 if (param && param->element_count >= count)
2453 UINT i;
2455 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2457 switch (param->class)
2459 case D3DXPC_MATRIX_ROWS:
2460 for (i = 0; i < count; ++i)
2462 set_matrix(get_parameter_struct(param->member_handles[i]), D3DXMatrixTranspose(&m, &matrix[i]));
2464 return D3D_OK;
2466 case D3DXPC_SCALAR:
2467 case D3DXPC_VECTOR:
2468 case D3DXPC_OBJECT:
2469 case D3DXPC_STRUCT:
2470 break;
2472 default:
2473 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2474 break;
2478 WARN("Invalid argument specified\n");
2480 return D3DERR_INVALIDCALL;
2483 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTransposeArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2485 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2486 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2488 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2490 if (!count) return D3D_OK;
2492 if (matrix && param && count <= param->element_count)
2494 UINT i;
2496 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2498 switch (param->class)
2500 case D3DXPC_MATRIX_ROWS:
2501 for (i = 0; i < count; ++i)
2503 D3DXMATRIX m;
2505 get_matrix(get_parameter_struct(param->member_handles[i]), &m);
2506 D3DXMatrixTranspose(&matrix[i], &m);
2508 return D3D_OK;
2510 case D3DXPC_SCALAR:
2511 case D3DXPC_VECTOR:
2512 case D3DXPC_OBJECT:
2513 case D3DXPC_STRUCT:
2514 break;
2516 default:
2517 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2518 break;
2522 WARN("Invalid argument specified\n");
2524 return D3DERR_INVALIDCALL;
2527 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
2529 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2531 FIXME("iface %p, parameter %p, matrix %p, count %u stub\n", This, parameter, matrix, count);
2533 return E_NOTIMPL;
2536 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2538 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2540 FIXME("iface %p, parameter %p, matrix %p, count %u stub\n", This, parameter, matrix, count);
2542 return E_NOTIMPL;
2545 static HRESULT WINAPI ID3DXBaseEffectImpl_SetString(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR string)
2547 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2549 FIXME("iface %p, parameter %p, string %p stub\n", This, parameter, string);
2551 return E_NOTIMPL;
2554 static HRESULT WINAPI ID3DXBaseEffectImpl_GetString(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR *string)
2556 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2557 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2559 TRACE("iface %p, parameter %p, string %p\n", This, parameter, string);
2561 if (string && param && !param->element_count && param->type == D3DXPT_STRING)
2563 *string = *(LPCSTR *)param->data;
2564 TRACE("Returning %s\n", debugstr_a(*string));
2565 return D3D_OK;
2568 WARN("Invalid argument specified\n");
2570 return D3DERR_INVALIDCALL;
2573 static HRESULT WINAPI ID3DXBaseEffectImpl_SetTexture(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
2575 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2576 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2578 TRACE("iface %p, parameter %p, texture %p\n", This, parameter, texture);
2580 if (param && !param->element_count &&
2581 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2582 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2583 || param->type == D3DXPT_TEXTURECUBE))
2585 LPDIRECT3DBASETEXTURE9 oltexture = *(LPDIRECT3DBASETEXTURE9 *)param->data;
2587 if (texture) IDirect3DBaseTexture9_AddRef(texture);
2588 if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
2590 *(LPDIRECT3DBASETEXTURE9 *)param->data = texture;
2592 return D3D_OK;
2595 WARN("Invalid argument specified\n");
2597 return D3DERR_INVALIDCALL;
2600 static HRESULT WINAPI ID3DXBaseEffectImpl_GetTexture(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
2602 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2603 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2605 TRACE("iface %p, parameter %p, texture %p\n", This, parameter, texture);
2607 if (texture && param && !param->element_count &&
2608 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2609 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2610 || param->type == D3DXPT_TEXTURECUBE))
2612 *texture = *(LPDIRECT3DBASETEXTURE9 *)param->data;
2613 if (*texture) IDirect3DBaseTexture9_AddRef(*texture);
2614 TRACE("Returning %p\n", *texture);
2615 return D3D_OK;
2618 WARN("Invalid argument specified\n");
2620 return D3DERR_INVALIDCALL;
2623 static HRESULT WINAPI ID3DXBaseEffectImpl_GetPixelShader(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
2625 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2626 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2628 TRACE("iface %p, parameter %p, pshader %p\n", This, parameter, pshader);
2630 if (pshader && param && !param->element_count && param->type == D3DXPT_PIXELSHADER)
2632 *pshader = *(LPDIRECT3DPIXELSHADER9 *)param->data;
2633 if (*pshader) IDirect3DPixelShader9_AddRef(*pshader);
2634 TRACE("Returning %p\n", *pshader);
2635 return D3D_OK;
2638 WARN("Invalid argument specified\n");
2640 return D3DERR_INVALIDCALL;
2643 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVertexShader(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
2645 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2646 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2648 TRACE("iface %p, parameter %p, vshader %p\n", This, parameter, vshader);
2650 if (vshader && param && !param->element_count && param->type == D3DXPT_VERTEXSHADER)
2652 *vshader = *(LPDIRECT3DVERTEXSHADER9 *)param->data;
2653 if (*vshader) IDirect3DVertexShader9_AddRef(*vshader);
2654 TRACE("Returning %p\n", *vshader);
2655 return D3D_OK;
2658 WARN("Invalid argument specified\n");
2660 return D3DERR_INVALIDCALL;
2663 static HRESULT WINAPI ID3DXBaseEffectImpl_SetArrayRange(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
2665 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2667 FIXME("iface %p, parameter %p, start %u, end %u stub\n", This, parameter, start, end);
2669 return E_NOTIMPL;
2672 static const struct ID3DXBaseEffectVtbl ID3DXBaseEffect_Vtbl =
2674 /*** IUnknown methods ***/
2675 ID3DXBaseEffectImpl_QueryInterface,
2676 ID3DXBaseEffectImpl_AddRef,
2677 ID3DXBaseEffectImpl_Release,
2678 /*** ID3DXBaseEffect methods ***/
2679 ID3DXBaseEffectImpl_GetDesc,
2680 ID3DXBaseEffectImpl_GetParameterDesc,
2681 ID3DXBaseEffectImpl_GetTechniqueDesc,
2682 ID3DXBaseEffectImpl_GetPassDesc,
2683 ID3DXBaseEffectImpl_GetFunctionDesc,
2684 ID3DXBaseEffectImpl_GetParameter,
2685 ID3DXBaseEffectImpl_GetParameterByName,
2686 ID3DXBaseEffectImpl_GetParameterBySemantic,
2687 ID3DXBaseEffectImpl_GetParameterElement,
2688 ID3DXBaseEffectImpl_GetTechnique,
2689 ID3DXBaseEffectImpl_GetTechniqueByName,
2690 ID3DXBaseEffectImpl_GetPass,
2691 ID3DXBaseEffectImpl_GetPassByName,
2692 ID3DXBaseEffectImpl_GetFunction,
2693 ID3DXBaseEffectImpl_GetFunctionByName,
2694 ID3DXBaseEffectImpl_GetAnnotation,
2695 ID3DXBaseEffectImpl_GetAnnotationByName,
2696 ID3DXBaseEffectImpl_SetValue,
2697 ID3DXBaseEffectImpl_GetValue,
2698 ID3DXBaseEffectImpl_SetBool,
2699 ID3DXBaseEffectImpl_GetBool,
2700 ID3DXBaseEffectImpl_SetBoolArray,
2701 ID3DXBaseEffectImpl_GetBoolArray,
2702 ID3DXBaseEffectImpl_SetInt,
2703 ID3DXBaseEffectImpl_GetInt,
2704 ID3DXBaseEffectImpl_SetIntArray,
2705 ID3DXBaseEffectImpl_GetIntArray,
2706 ID3DXBaseEffectImpl_SetFloat,
2707 ID3DXBaseEffectImpl_GetFloat,
2708 ID3DXBaseEffectImpl_SetFloatArray,
2709 ID3DXBaseEffectImpl_GetFloatArray,
2710 ID3DXBaseEffectImpl_SetVector,
2711 ID3DXBaseEffectImpl_GetVector,
2712 ID3DXBaseEffectImpl_SetVectorArray,
2713 ID3DXBaseEffectImpl_GetVectorArray,
2714 ID3DXBaseEffectImpl_SetMatrix,
2715 ID3DXBaseEffectImpl_GetMatrix,
2716 ID3DXBaseEffectImpl_SetMatrixArray,
2717 ID3DXBaseEffectImpl_GetMatrixArray,
2718 ID3DXBaseEffectImpl_SetMatrixPointerArray,
2719 ID3DXBaseEffectImpl_GetMatrixPointerArray,
2720 ID3DXBaseEffectImpl_SetMatrixTranspose,
2721 ID3DXBaseEffectImpl_GetMatrixTranspose,
2722 ID3DXBaseEffectImpl_SetMatrixTransposeArray,
2723 ID3DXBaseEffectImpl_GetMatrixTransposeArray,
2724 ID3DXBaseEffectImpl_SetMatrixTransposePointerArray,
2725 ID3DXBaseEffectImpl_GetMatrixTransposePointerArray,
2726 ID3DXBaseEffectImpl_SetString,
2727 ID3DXBaseEffectImpl_GetString,
2728 ID3DXBaseEffectImpl_SetTexture,
2729 ID3DXBaseEffectImpl_GetTexture,
2730 ID3DXBaseEffectImpl_GetPixelShader,
2731 ID3DXBaseEffectImpl_GetVertexShader,
2732 ID3DXBaseEffectImpl_SetArrayRange,
2735 static inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
2737 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
2740 /*** IUnknown methods ***/
2741 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
2743 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2745 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), object);
2747 if (IsEqualGUID(riid, &IID_IUnknown) ||
2748 IsEqualGUID(riid, &IID_ID3DXEffect))
2750 This->ID3DXEffect_iface.lpVtbl->AddRef(iface);
2751 *object = This;
2752 return S_OK;
2755 ERR("Interface %s not found\n", debugstr_guid(riid));
2757 return E_NOINTERFACE;
2760 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
2762 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2764 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
2766 return InterlockedIncrement(&This->ref);
2769 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
2771 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2772 ULONG ref = InterlockedDecrement(&This->ref);
2774 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
2776 if (!ref)
2778 free_effect(This);
2779 HeapFree(GetProcessHeap(), 0, This);
2782 return ref;
2785 /*** ID3DXBaseEffect methods ***/
2786 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
2788 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2789 ID3DXBaseEffect *base = This->base_effect;
2791 TRACE("Forward iface %p, base %p\n", This, base);
2793 return ID3DXBaseEffectImpl_GetDesc(base, desc);
2796 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
2798 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2799 ID3DXBaseEffect *base = This->base_effect;
2801 TRACE("Forward iface %p, base %p\n", This, base);
2803 return ID3DXBaseEffectImpl_GetParameterDesc(base, parameter, desc);
2806 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
2808 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2809 ID3DXBaseEffect *base = This->base_effect;
2811 TRACE("Forward iface %p, base %p\n", This, base);
2813 return ID3DXBaseEffectImpl_GetTechniqueDesc(base, technique, desc);
2816 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
2818 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2819 ID3DXBaseEffect *base = This->base_effect;
2821 TRACE("Forward iface %p, base %p\n", This, base);
2823 return ID3DXBaseEffectImpl_GetPassDesc(base, pass, desc);
2826 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
2828 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2829 ID3DXBaseEffect *base = This->base_effect;
2831 TRACE("Forward iface %p, base %p\n", This, base);
2833 return ID3DXBaseEffectImpl_GetFunctionDesc(base, shader, desc);
2836 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2838 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2839 ID3DXBaseEffect *base = This->base_effect;
2841 TRACE("Forward iface %p, base %p\n", This, base);
2843 return ID3DXBaseEffectImpl_GetParameter(base, parameter, index);
2846 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR name)
2848 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2849 ID3DXBaseEffect *base = This->base_effect;
2851 TRACE("Forward iface %p, base %p\n", This, base);
2853 return ID3DXBaseEffectImpl_GetParameterByName(base, parameter, name);
2856 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR semantic)
2858 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2859 ID3DXBaseEffect *base = This->base_effect;
2861 TRACE("Forward iface %p, base %p\n", This, base);
2863 return ID3DXBaseEffectImpl_GetParameterBySemantic(base, parameter, semantic);
2866 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2868 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2869 ID3DXBaseEffect *base = This->base_effect;
2871 TRACE("Forward iface %p, base %p\n", This, base);
2873 return ID3DXBaseEffectImpl_GetParameterElement(base, parameter, index);
2876 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
2878 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2879 ID3DXBaseEffect *base = This->base_effect;
2881 TRACE("Forward iface %p, base %p\n", This, base);
2883 return ID3DXBaseEffectImpl_GetTechnique(base, index);
2886 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, LPCSTR name)
2888 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2889 ID3DXBaseEffect *base = This->base_effect;
2891 TRACE("Forward iface %p, base %p\n", This, base);
2893 return ID3DXBaseEffectImpl_GetTechniqueByName(base, name);
2896 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
2898 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2899 ID3DXBaseEffect *base = This->base_effect;
2901 TRACE("Forward iface %p, base %p\n", This, base);
2903 return ID3DXBaseEffectImpl_GetPass(base, technique, index);
2906 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface, D3DXHANDLE technique, LPCSTR name)
2908 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2909 ID3DXBaseEffect *base = This->base_effect;
2911 TRACE("Forward iface %p, base %p\n", This, base);
2913 return ID3DXBaseEffectImpl_GetPassByName(base, technique, name);
2916 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
2918 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2919 ID3DXBaseEffect *base = This->base_effect;
2921 TRACE("Forward iface %p, base %p\n", This, base);
2923 return ID3DXBaseEffectImpl_GetFunction(base, index);
2926 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, LPCSTR name)
2928 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2929 ID3DXBaseEffect *base = This->base_effect;
2931 TRACE("Forward iface %p, base %p\n", This, base);
2933 return ID3DXBaseEffectImpl_GetFunctionByName(base, name);
2936 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
2938 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2939 ID3DXBaseEffect *base = This->base_effect;
2941 TRACE("Forward iface %p, base %p\n", This, base);
2943 return ID3DXBaseEffectImpl_GetAnnotation(base, object, index);
2946 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface, D3DXHANDLE object, LPCSTR name)
2948 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2949 ID3DXBaseEffect *base = This->base_effect;
2951 TRACE("Forward iface %p, base %p\n", This, base);
2953 return ID3DXBaseEffectImpl_GetAnnotationByName(base, object, name);
2956 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
2958 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2959 ID3DXBaseEffect *base = This->base_effect;
2961 TRACE("Forward iface %p, base %p\n", This, base);
2963 return ID3DXBaseEffectImpl_SetValue(base, parameter, data, bytes);
2966 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
2968 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2969 ID3DXBaseEffect *base = This->base_effect;
2971 TRACE("Forward iface %p, base %p\n", This, base);
2973 return ID3DXBaseEffectImpl_GetValue(base, parameter, data, bytes);
2976 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
2978 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2979 ID3DXBaseEffect *base = This->base_effect;
2981 TRACE("Forward iface %p, base %p\n", This, base);
2983 return ID3DXBaseEffectImpl_SetBool(base, parameter, b);
2986 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
2988 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2989 ID3DXBaseEffect *base = This->base_effect;
2991 TRACE("Forward iface %p, base %p\n", This, base);
2993 return ID3DXBaseEffectImpl_GetBool(base, parameter, b);
2996 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
2998 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2999 ID3DXBaseEffect *base = This->base_effect;
3001 TRACE("Forward iface %p, base %p\n", This, base);
3003 return ID3DXBaseEffectImpl_SetBoolArray(base, parameter, b, count);
3006 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
3008 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3009 ID3DXBaseEffect *base = This->base_effect;
3011 TRACE("Forward iface %p, base %p\n", This, base);
3013 return ID3DXBaseEffectImpl_GetBoolArray(base, parameter, b, count);
3016 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
3018 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3019 ID3DXBaseEffect *base = This->base_effect;
3021 TRACE("Forward iface %p, base %p\n", This, base);
3023 return ID3DXBaseEffectImpl_SetInt(base, parameter, n);
3026 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
3028 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3029 ID3DXBaseEffect *base = This->base_effect;
3031 TRACE("Forward iface %p, base %p\n", This, base);
3033 return ID3DXBaseEffectImpl_GetInt(base, parameter, n);
3036 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
3038 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3039 ID3DXBaseEffect *base = This->base_effect;
3041 TRACE("Forward iface %p, base %p\n", This, base);
3043 return ID3DXBaseEffectImpl_SetIntArray(base, parameter, n, count);
3046 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n, UINT count)
3048 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3049 ID3DXBaseEffect *base = This->base_effect;
3051 TRACE("Forward iface %p, base %p\n", This, base);
3053 return ID3DXBaseEffectImpl_GetIntArray(base, parameter, n, count);
3056 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT f)
3058 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3059 ID3DXBaseEffect *base = This->base_effect;
3061 TRACE("Forward iface %p, base %p\n", This, base);
3063 return ID3DXBaseEffectImpl_SetFloat(base, parameter, f);
3066 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT *f)
3068 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3069 ID3DXBaseEffect *base = This->base_effect;
3071 TRACE("Forward iface %p, base %p\n", This, base);
3073 return ID3DXBaseEffectImpl_GetFloat(base, parameter, f);
3076 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
3078 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3079 ID3DXBaseEffect *base = This->base_effect;
3081 TRACE("Forward iface %p, base %p\n", This, base);
3083 return ID3DXBaseEffectImpl_SetFloatArray(base, parameter, f, count);
3086 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
3088 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3089 ID3DXBaseEffect *base = This->base_effect;
3091 TRACE("Forward iface %p, base %p\n", This, base);
3093 return ID3DXBaseEffectImpl_GetFloatArray(base, parameter, f, count);
3096 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
3098 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3099 ID3DXBaseEffect *base = This->base_effect;
3101 TRACE("Forward iface %p, base %p\n", This, base);
3103 return ID3DXBaseEffectImpl_SetVector(base, parameter, vector);
3106 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
3108 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3109 ID3DXBaseEffect *base = This->base_effect;
3111 TRACE("Forward iface %p, base %p\n", This, base);
3113 return ID3DXBaseEffectImpl_GetVector(base, parameter, vector);
3116 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
3118 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3119 ID3DXBaseEffect *base = This->base_effect;
3121 TRACE("Forward iface %p, base %p\n", This, base);
3123 return ID3DXBaseEffectImpl_SetVectorArray(base, parameter, vector, count);
3126 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
3128 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3129 ID3DXBaseEffect *base = This->base_effect;
3131 TRACE("Forward iface %p, base %p\n", This, base);
3133 return ID3DXBaseEffectImpl_GetVectorArray(base, parameter, vector, count);
3136 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
3138 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3139 ID3DXBaseEffect *base = This->base_effect;
3141 TRACE("Forward iface %p, base %p\n", This, base);
3143 return ID3DXBaseEffectImpl_SetMatrix(base, parameter, matrix);
3146 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
3148 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3149 ID3DXBaseEffect *base = This->base_effect;
3151 TRACE("Forward iface %p, base %p\n", This, base);
3153 return ID3DXBaseEffectImpl_GetMatrix(base, parameter, matrix);
3156 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
3158 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3159 ID3DXBaseEffect *base = This->base_effect;
3161 TRACE("Forward iface %p, base %p\n", This, base);
3163 return ID3DXBaseEffectImpl_SetMatrixArray(base, parameter, matrix, count);
3166 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3168 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3169 ID3DXBaseEffect *base = This->base_effect;
3171 TRACE("Forward iface %p, base %p\n", This, base);
3173 return ID3DXBaseEffectImpl_GetMatrixArray(base, parameter, matrix, count);
3176 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
3178 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3179 ID3DXBaseEffect *base = This->base_effect;
3181 TRACE("Forward iface %p, base %p\n", This, base);
3183 return ID3DXBaseEffectImpl_SetMatrixPointerArray(base, parameter, matrix, count);
3186 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3188 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3189 ID3DXBaseEffect *base = This->base_effect;
3191 TRACE("Forward iface %p, base %p\n", This, base);
3193 return ID3DXBaseEffectImpl_GetMatrixPointerArray(base, parameter, matrix, count);
3196 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
3198 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3199 ID3DXBaseEffect *base = This->base_effect;
3201 TRACE("Forward iface %p, base %p\n", This, base);
3203 return ID3DXBaseEffectImpl_SetMatrixTranspose(base, parameter, matrix);
3206 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
3208 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3209 ID3DXBaseEffect *base = This->base_effect;
3211 TRACE("Forward iface %p, base %p\n", This, base);
3213 return ID3DXBaseEffectImpl_GetMatrixTranspose(base, parameter, matrix);
3216 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
3218 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3219 ID3DXBaseEffect *base = This->base_effect;
3221 TRACE("Forward iface %p, base %p\n", This, base);
3223 return ID3DXBaseEffectImpl_SetMatrixTransposeArray(base, parameter, matrix, count);
3226 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3228 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3229 ID3DXBaseEffect *base = This->base_effect;
3231 TRACE("Forward iface %p, base %p\n", This, base);
3233 return ID3DXBaseEffectImpl_GetMatrixTransposeArray(base, parameter, matrix, count);
3236 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
3238 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3239 ID3DXBaseEffect *base = This->base_effect;
3241 TRACE("Forward iface %p, base %p\n", This, base);
3243 return ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(base, parameter, matrix, count);
3246 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3248 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3249 ID3DXBaseEffect *base = This->base_effect;
3251 TRACE("Forward iface %p, base %p\n", This, base);
3253 return ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(base, parameter, matrix, count);
3256 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR string)
3258 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3259 ID3DXBaseEffect *base = This->base_effect;
3261 TRACE("Forward iface %p, base %p\n", This, base);
3263 return ID3DXBaseEffectImpl_SetString(base, parameter, string);
3266 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR *string)
3268 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3269 ID3DXBaseEffect *base = This->base_effect;
3271 TRACE("Forward iface %p, base %p\n", This, base);
3273 return ID3DXBaseEffectImpl_GetString(base, parameter, string);
3276 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
3278 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3279 ID3DXBaseEffect *base = This->base_effect;
3281 TRACE("Forward iface %p, base %p\n", This, base);
3283 return ID3DXBaseEffectImpl_SetTexture(base, parameter, texture);
3286 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
3288 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3289 ID3DXBaseEffect *base = This->base_effect;
3291 TRACE("Forward iface %p, base %p\n", This, base);
3293 return ID3DXBaseEffectImpl_GetTexture(base, parameter, texture);
3296 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
3298 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3299 ID3DXBaseEffect *base = This->base_effect;
3301 TRACE("Forward iface %p, base %p\n", This, base);
3303 return ID3DXBaseEffectImpl_GetPixelShader(base, parameter, pshader);
3306 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
3308 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3309 ID3DXBaseEffect *base = This->base_effect;
3311 TRACE("Forward iface %p, base %p\n", This, base);
3313 return ID3DXBaseEffectImpl_GetVertexShader(base, parameter, vshader);
3316 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3318 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3319 ID3DXBaseEffect *base = This->base_effect;
3321 TRACE("Forward iface %p, base %p\n", This, base);
3323 return ID3DXBaseEffectImpl_SetArrayRange(base, parameter, start, end);
3326 /*** ID3DXEffect methods ***/
3327 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, LPD3DXEFFECTPOOL *pool)
3329 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3331 TRACE("iface %p, pool %p\n", This, pool);
3333 if (!pool)
3335 WARN("Invalid argument supplied.\n");
3336 return D3DERR_INVALIDCALL;
3339 if (This->pool)
3341 This->pool->lpVtbl->AddRef(This->pool);
3344 *pool = This->pool;
3346 TRACE("Returning pool %p\n", *pool);
3348 return S_OK;
3351 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3353 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3354 struct ID3DXBaseEffectImpl *base = impl_from_ID3DXBaseEffect(This->base_effect);
3355 struct d3dx_technique *tech = is_valid_technique(base, technique);
3357 TRACE("iface %p, technique %p\n", This, technique);
3359 if (!tech) tech = get_technique_struct(iface->lpVtbl->GetTechniqueByName(iface, technique));
3361 if (tech)
3363 UINT i;
3365 for (i = 0; i < base->technique_count; ++i)
3367 struct d3dx_technique *t = get_technique_struct(base->technique_handles[i]);
3369 if (tech == t)
3371 This->active_technique = get_technique_handle(t);
3372 TRACE("Technique %u (%p)\n", i, tech);
3373 return D3D_OK;
3378 WARN("Invalid argument supplied.\n");
3380 return D3DERR_INVALIDCALL;
3383 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3385 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3387 TRACE("iface %p\n", This);
3389 return This->active_technique;
3392 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3394 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3396 FIXME("(%p)->(%p): stub\n", This, technique);
3398 return D3D_OK;
3401 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3403 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3405 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3407 return E_NOTIMPL;
3410 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
3412 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3414 FIXME("(%p)->(%p, %p): stub\n", This, parameter, technique);
3416 return FALSE;
3419 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
3421 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3422 struct d3dx_technique *technique = get_technique_struct(This->active_technique);
3424 FIXME("iface %p, passes %p, flags %#x partial stub\n", This, passes, flags);
3426 if (passes && technique)
3428 if (This->manager || flags & D3DXFX_DONOTSAVESTATE)
3430 TRACE("State capturing disabled.\n");
3432 else
3434 FIXME("State capturing not supported, yet!\n");
3437 *passes = technique->pass_count;
3439 return D3D_OK;
3442 WARN("Invalid argument supplied.\n");
3444 return D3DERR_INVALIDCALL;
3447 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
3449 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3450 struct d3dx_technique *technique = get_technique_struct(This->active_technique);
3452 TRACE("iface %p, pass %u\n", This, pass);
3454 if (technique && pass < technique->pass_count && !This->active_pass)
3456 This->active_pass = technique->pass_handles[pass];
3458 FIXME("No states applied, yet!\n");
3460 return D3D_OK;
3463 WARN("Invalid argument supplied.\n");
3465 return D3DERR_INVALIDCALL;
3468 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect* iface)
3470 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3472 FIXME("(%p)->(): stub\n", This);
3474 return E_NOTIMPL;
3477 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
3479 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3481 TRACE("iface %p\n", This);
3483 if (This->active_pass)
3485 This->active_pass = NULL;
3486 return D3D_OK;
3489 WARN("Invalid call.\n");
3491 return D3DERR_INVALIDCALL;
3494 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect* iface)
3496 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3498 FIXME("(%p)->(): stub\n", This);
3500 return E_NOTIMPL;
3503 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, LPDIRECT3DDEVICE9 *device)
3505 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3507 TRACE("iface %p, device %p\n", This, device);
3509 if (!device)
3511 WARN("Invalid argument supplied.\n");
3512 return D3DERR_INVALIDCALL;
3515 IDirect3DDevice9_AddRef(This->device);
3517 *device = This->device;
3519 TRACE("Returning device %p\n", *device);
3521 return S_OK;
3524 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
3526 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3528 FIXME("(%p)->(): stub\n", This);
3530 return E_NOTIMPL;
3533 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(ID3DXEffect* iface)
3535 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3537 FIXME("(%p)->(): stub\n", This);
3539 return E_NOTIMPL;
3542 static HRESULT WINAPI ID3DXEffectImpl_SetStateManager(ID3DXEffect *iface, LPD3DXEFFECTSTATEMANAGER manager)
3544 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3546 TRACE("iface %p, manager %p\n", This, manager);
3548 if (manager) IUnknown_AddRef(manager);
3549 if (This->manager) IUnknown_Release(This->manager);
3551 This->manager = manager;
3553 return D3D_OK;
3556 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, LPD3DXEFFECTSTATEMANAGER *manager)
3558 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3560 TRACE("iface %p, manager %p\n", This, manager);
3562 if (!manager)
3564 WARN("Invalid argument supplied.\n");
3565 return D3DERR_INVALIDCALL;
3568 if (This->manager) IUnknown_AddRef(This->manager);
3569 *manager = This->manager;
3571 return D3D_OK;
3574 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
3576 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3578 FIXME("(%p)->(): stub\n", This);
3580 return E_NOTIMPL;
3583 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
3585 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3587 FIXME("(%p)->(): stub\n", This);
3589 return NULL;
3592 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3594 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3596 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3598 return E_NOTIMPL;
3601 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3603 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3605 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3607 return E_NOTIMPL;
3610 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect* iface, LPDIRECT3DDEVICE9 device, LPD3DXEFFECT* effect)
3612 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3614 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
3616 return E_NOTIMPL;
3619 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect* iface, D3DXHANDLE parameter, LPCVOID data, UINT byte_offset, UINT bytes)
3621 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3623 FIXME("(%p)->(%p, %p, %u, %u): stub\n", This, parameter, data, byte_offset, bytes);
3625 return E_NOTIMPL;
3628 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
3630 /*** IUnknown methods ***/
3631 ID3DXEffectImpl_QueryInterface,
3632 ID3DXEffectImpl_AddRef,
3633 ID3DXEffectImpl_Release,
3634 /*** ID3DXBaseEffect methods ***/
3635 ID3DXEffectImpl_GetDesc,
3636 ID3DXEffectImpl_GetParameterDesc,
3637 ID3DXEffectImpl_GetTechniqueDesc,
3638 ID3DXEffectImpl_GetPassDesc,
3639 ID3DXEffectImpl_GetFunctionDesc,
3640 ID3DXEffectImpl_GetParameter,
3641 ID3DXEffectImpl_GetParameterByName,
3642 ID3DXEffectImpl_GetParameterBySemantic,
3643 ID3DXEffectImpl_GetParameterElement,
3644 ID3DXEffectImpl_GetTechnique,
3645 ID3DXEffectImpl_GetTechniqueByName,
3646 ID3DXEffectImpl_GetPass,
3647 ID3DXEffectImpl_GetPassByName,
3648 ID3DXEffectImpl_GetFunction,
3649 ID3DXEffectImpl_GetFunctionByName,
3650 ID3DXEffectImpl_GetAnnotation,
3651 ID3DXEffectImpl_GetAnnotationByName,
3652 ID3DXEffectImpl_SetValue,
3653 ID3DXEffectImpl_GetValue,
3654 ID3DXEffectImpl_SetBool,
3655 ID3DXEffectImpl_GetBool,
3656 ID3DXEffectImpl_SetBoolArray,
3657 ID3DXEffectImpl_GetBoolArray,
3658 ID3DXEffectImpl_SetInt,
3659 ID3DXEffectImpl_GetInt,
3660 ID3DXEffectImpl_SetIntArray,
3661 ID3DXEffectImpl_GetIntArray,
3662 ID3DXEffectImpl_SetFloat,
3663 ID3DXEffectImpl_GetFloat,
3664 ID3DXEffectImpl_SetFloatArray,
3665 ID3DXEffectImpl_GetFloatArray,
3666 ID3DXEffectImpl_SetVector,
3667 ID3DXEffectImpl_GetVector,
3668 ID3DXEffectImpl_SetVectorArray,
3669 ID3DXEffectImpl_GetVectorArray,
3670 ID3DXEffectImpl_SetMatrix,
3671 ID3DXEffectImpl_GetMatrix,
3672 ID3DXEffectImpl_SetMatrixArray,
3673 ID3DXEffectImpl_GetMatrixArray,
3674 ID3DXEffectImpl_SetMatrixPointerArray,
3675 ID3DXEffectImpl_GetMatrixPointerArray,
3676 ID3DXEffectImpl_SetMatrixTranspose,
3677 ID3DXEffectImpl_GetMatrixTranspose,
3678 ID3DXEffectImpl_SetMatrixTransposeArray,
3679 ID3DXEffectImpl_GetMatrixTransposeArray,
3680 ID3DXEffectImpl_SetMatrixTransposePointerArray,
3681 ID3DXEffectImpl_GetMatrixTransposePointerArray,
3682 ID3DXEffectImpl_SetString,
3683 ID3DXEffectImpl_GetString,
3684 ID3DXEffectImpl_SetTexture,
3685 ID3DXEffectImpl_GetTexture,
3686 ID3DXEffectImpl_GetPixelShader,
3687 ID3DXEffectImpl_GetVertexShader,
3688 ID3DXEffectImpl_SetArrayRange,
3689 /*** ID3DXEffect methods ***/
3690 ID3DXEffectImpl_GetPool,
3691 ID3DXEffectImpl_SetTechnique,
3692 ID3DXEffectImpl_GetCurrentTechnique,
3693 ID3DXEffectImpl_ValidateTechnique,
3694 ID3DXEffectImpl_FindNextValidTechnique,
3695 ID3DXEffectImpl_IsParameterUsed,
3696 ID3DXEffectImpl_Begin,
3697 ID3DXEffectImpl_BeginPass,
3698 ID3DXEffectImpl_CommitChanges,
3699 ID3DXEffectImpl_EndPass,
3700 ID3DXEffectImpl_End,
3701 ID3DXEffectImpl_GetDevice,
3702 ID3DXEffectImpl_OnLostDevice,
3703 ID3DXEffectImpl_OnResetDevice,
3704 ID3DXEffectImpl_SetStateManager,
3705 ID3DXEffectImpl_GetStateManager,
3706 ID3DXEffectImpl_BeginParameterBlock,
3707 ID3DXEffectImpl_EndParameterBlock,
3708 ID3DXEffectImpl_ApplyParameterBlock,
3709 ID3DXEffectImpl_DeleteParameterBlock,
3710 ID3DXEffectImpl_CloneEffect,
3711 ID3DXEffectImpl_SetRawValue
3714 static inline struct ID3DXEffectCompilerImpl *impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler *iface)
3716 return CONTAINING_RECORD(iface, struct ID3DXEffectCompilerImpl, ID3DXEffectCompiler_iface);
3719 /*** IUnknown methods ***/
3720 static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler *iface, REFIID riid, void **object)
3722 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3724 TRACE("iface %p, riid %s, object %p\n", This, debugstr_guid(riid), object);
3726 if (IsEqualGUID(riid, &IID_IUnknown) ||
3727 IsEqualGUID(riid, &IID_ID3DXEffectCompiler))
3729 This->ID3DXEffectCompiler_iface.lpVtbl->AddRef(iface);
3730 *object = This;
3731 return S_OK;
3734 ERR("Interface %s not found\n", debugstr_guid(riid));
3736 return E_NOINTERFACE;
3739 static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface)
3741 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3743 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
3745 return InterlockedIncrement(&This->ref);
3748 static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface)
3750 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3751 ULONG ref = InterlockedDecrement(&This->ref);
3753 TRACE("iface %p: Release from %u\n", iface, ref + 1);
3755 if (!ref)
3757 free_effect_compiler(This);
3758 HeapFree(GetProcessHeap(), 0, This);
3761 return ref;
3764 /*** ID3DXBaseEffect methods ***/
3765 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler *iface, D3DXEFFECT_DESC *desc)
3767 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3768 ID3DXBaseEffect *base = This->base_effect;
3770 TRACE("Forward iface %p, base %p\n", This, base);
3772 return ID3DXBaseEffectImpl_GetDesc(base, desc);
3775 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
3777 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3778 ID3DXBaseEffect *base = This->base_effect;
3780 TRACE("Forward iface %p, base %p\n", This, base);
3782 return ID3DXBaseEffectImpl_GetParameterDesc(base, parameter, desc);
3785 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
3787 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3788 ID3DXBaseEffect *base = This->base_effect;
3790 TRACE("Forward iface %p, base %p\n", This, base);
3792 return ID3DXBaseEffectImpl_GetTechniqueDesc(base, technique, desc);
3795 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
3797 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3798 ID3DXBaseEffect *base = This->base_effect;
3800 TRACE("Forward iface %p, base %p\n", This, base);
3802 return ID3DXBaseEffectImpl_GetPassDesc(base, pass, desc);
3805 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
3807 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3808 ID3DXBaseEffect *base = This->base_effect;
3810 TRACE("Forward iface %p, base %p\n", This, base);
3812 return ID3DXBaseEffectImpl_GetFunctionDesc(base, shader, desc);
3815 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT index)
3817 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3818 ID3DXBaseEffect *base = This->base_effect;
3820 TRACE("Forward iface %p, base %p\n", This, base);
3822 return ID3DXBaseEffectImpl_GetParameter(base, parameter, index);
3825 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR name)
3827 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3828 ID3DXBaseEffect *base = This->base_effect;
3830 TRACE("Forward iface %p, base %p\n", This, base);
3832 return ID3DXBaseEffectImpl_GetParameterByName(base, parameter, name);
3835 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR semantic)
3837 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3838 ID3DXBaseEffect *base = This->base_effect;
3840 TRACE("Forward iface %p, base %p\n", This, base);
3842 return ID3DXBaseEffectImpl_GetParameterBySemantic(base, parameter, semantic);
3845 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT index)
3847 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3848 ID3DXBaseEffect *base = This->base_effect;
3850 TRACE("Forward iface %p, base %p\n", This, base);
3852 return ID3DXBaseEffectImpl_GetParameterElement(base, parameter, index);
3855 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler *iface, UINT index)
3857 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3858 ID3DXBaseEffect *base = This->base_effect;
3860 TRACE("Forward iface %p, base %p\n", This, base);
3862 return ID3DXBaseEffectImpl_GetTechnique(base, index);
3865 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler *iface, LPCSTR name)
3867 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3868 ID3DXBaseEffect *base = This->base_effect;
3870 TRACE("Forward iface %p, base %p\n", This, base);
3872 return ID3DXBaseEffectImpl_GetTechniqueByName(base, name);
3875 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler *iface, D3DXHANDLE technique, UINT index)
3877 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3878 ID3DXBaseEffect *base = This->base_effect;
3880 TRACE("Forward iface %p, base %p\n", This, base);
3882 return ID3DXBaseEffectImpl_GetPass(base, technique, index);
3885 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler *iface, D3DXHANDLE technique, LPCSTR name)
3887 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3888 ID3DXBaseEffect *base = This->base_effect;
3890 TRACE("Forward iface %p, base %p\n", This, base);
3892 return ID3DXBaseEffectImpl_GetPassByName(base, technique, name);
3895 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler *iface, UINT index)
3897 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3898 ID3DXBaseEffect *base = This->base_effect;
3900 TRACE("Forward iface %p, base %p\n", This, base);
3902 return ID3DXBaseEffectImpl_GetFunction(base, index);
3905 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler *iface, LPCSTR name)
3907 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3908 ID3DXBaseEffect *base = This->base_effect;
3910 TRACE("Forward iface %p, base %p\n", This, base);
3912 return ID3DXBaseEffectImpl_GetFunctionByName(base, name);
3915 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler *iface, D3DXHANDLE object, UINT index)
3917 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3918 ID3DXBaseEffect *base = This->base_effect;
3920 TRACE("Forward iface %p, base %p\n", This, base);
3922 return ID3DXBaseEffectImpl_GetAnnotation(base, object, index);
3925 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler *iface, D3DXHANDLE object, LPCSTR name)
3927 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3928 ID3DXBaseEffect *base = This->base_effect;
3930 TRACE("Forward iface %p, base %p\n", This, base);
3932 return ID3DXBaseEffectImpl_GetAnnotationByName(base, object, name);
3935 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
3937 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3938 ID3DXBaseEffect *base = This->base_effect;
3940 TRACE("Forward iface %p, base %p\n", This, base);
3942 return ID3DXBaseEffectImpl_SetValue(base, parameter, data, bytes);
3945 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
3947 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3948 ID3DXBaseEffect *base = This->base_effect;
3950 TRACE("Forward iface %p, base %p\n", This, base);
3952 return ID3DXBaseEffectImpl_GetValue(base, parameter, data, bytes);
3955 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL b)
3957 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3958 ID3DXBaseEffect *base = This->base_effect;
3960 TRACE("Forward iface %p, base %p\n", This, base);
3962 return ID3DXBaseEffectImpl_SetBool(base, parameter, b);
3965 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b)
3967 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3968 ID3DXBaseEffect *base = This->base_effect;
3970 TRACE("Forward iface %p, base %p\n", This, base);
3972 return ID3DXBaseEffectImpl_GetBool(base, parameter, b);
3975 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
3977 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3978 ID3DXBaseEffect *base = This->base_effect;
3980 TRACE("Forward iface %p, base %p\n", This, base);
3982 return ID3DXBaseEffectImpl_SetBoolArray(base, parameter, b, count);
3985 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
3987 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3988 ID3DXBaseEffect *base = This->base_effect;
3990 TRACE("Forward iface %p, base %p\n", This, base);
3992 return ID3DXBaseEffectImpl_GetBoolArray(base, parameter, b, count);
3995 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT n)
3997 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3998 ID3DXBaseEffect *base = This->base_effect;
4000 TRACE("Forward iface %p, base %p\n", This, base);
4002 return ID3DXBaseEffectImpl_SetInt(base, parameter, n);
4005 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n)
4007 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4008 ID3DXBaseEffect *base = This->base_effect;
4010 TRACE("Forward iface %p, base %p\n", This, base);
4012 return ID3DXBaseEffectImpl_GetInt(base, parameter, n);
4015 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
4017 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4018 ID3DXBaseEffect *base = This->base_effect;
4020 TRACE("Forward iface %p, base %p\n", This, base);
4022 return ID3DXBaseEffectImpl_SetIntArray(base, parameter, n, count);
4025 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n, UINT count)
4027 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4028 ID3DXBaseEffect *base = This->base_effect;
4030 TRACE("Forward iface %p, base %p\n", This, base);
4032 return ID3DXBaseEffectImpl_GetIntArray(base, parameter, n, count);
4035 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT f)
4037 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4038 ID3DXBaseEffect *base = This->base_effect;
4040 TRACE("Forward iface %p, base %p\n", This, base);
4042 return ID3DXBaseEffectImpl_SetFloat(base, parameter, f);
4045 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT *f)
4047 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4048 ID3DXBaseEffect *base = This->base_effect;
4050 TRACE("Forward iface %p, base %p\n", This, base);
4052 return ID3DXBaseEffectImpl_GetFloat(base, parameter, f);
4055 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
4057 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4058 ID3DXBaseEffect *base = This->base_effect;
4060 TRACE("Forward iface %p, base %p\n", This, base);
4062 return ID3DXBaseEffectImpl_SetFloatArray(base, parameter, f, count);
4065 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
4067 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4068 ID3DXBaseEffect *base = This->base_effect;
4070 TRACE("Forward iface %p, base %p\n", This, base);
4072 return ID3DXBaseEffectImpl_GetFloatArray(base, parameter, f, count);
4075 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
4077 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4078 ID3DXBaseEffect *base = This->base_effect;
4080 TRACE("Forward iface %p, base %p\n", This, base);
4082 return ID3DXBaseEffectImpl_SetVector(base, parameter, vector);
4085 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
4087 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4088 ID3DXBaseEffect *base = This->base_effect;
4090 TRACE("Forward iface %p, base %p\n", This, base);
4092 return ID3DXBaseEffectImpl_GetVector(base, parameter, vector);
4095 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
4097 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4098 ID3DXBaseEffect *base = This->base_effect;
4100 TRACE("Forward iface %p, base %p\n", This, base);
4102 return ID3DXBaseEffectImpl_SetVectorArray(base, parameter, vector, count);
4105 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
4107 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4108 ID3DXBaseEffect *base = This->base_effect;
4110 TRACE("Forward iface %p, base %p\n", This, base);
4112 return ID3DXBaseEffectImpl_GetVectorArray(base, parameter, vector, count);
4115 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
4117 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4118 ID3DXBaseEffect *base = This->base_effect;
4120 TRACE("Forward iface %p, base %p\n", This, base);
4122 return ID3DXBaseEffectImpl_SetMatrix(base, parameter, matrix);
4125 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
4127 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4128 ID3DXBaseEffect *base = This->base_effect;
4130 TRACE("Forward iface %p, base %p\n", This, base);
4132 return ID3DXBaseEffectImpl_GetMatrix(base, parameter, matrix);
4135 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
4137 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4138 ID3DXBaseEffect *base = This->base_effect;
4140 TRACE("Forward iface %p, base %p\n", This, base);
4142 return ID3DXBaseEffectImpl_SetMatrixArray(base, parameter, matrix, count);
4145 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4147 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4148 ID3DXBaseEffect *base = This->base_effect;
4150 TRACE("Forward iface %p, base %p\n", This, base);
4152 return ID3DXBaseEffectImpl_GetMatrixArray(base, parameter, matrix, count);
4155 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
4157 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4158 ID3DXBaseEffect *base = This->base_effect;
4160 TRACE("Forward iface %p, base %p\n", This, base);
4162 return ID3DXBaseEffectImpl_SetMatrixPointerArray(base, parameter, matrix, count);
4165 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4167 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4168 ID3DXBaseEffect *base = This->base_effect;
4170 TRACE("Forward iface %p, base %p\n", This, base);
4172 return ID3DXBaseEffectImpl_GetMatrixPointerArray(base, parameter, matrix, count);
4175 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
4177 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4178 ID3DXBaseEffect *base = This->base_effect;
4180 TRACE("Forward iface %p, base %p\n", This, base);
4182 return ID3DXBaseEffectImpl_SetMatrixTranspose(base, parameter, matrix);
4185 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
4187 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4188 ID3DXBaseEffect *base = This->base_effect;
4190 TRACE("Forward iface %p, base %p\n", This, base);
4192 return ID3DXBaseEffectImpl_GetMatrixTranspose(base, parameter, matrix);
4195 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
4197 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4198 ID3DXBaseEffect *base = This->base_effect;
4200 TRACE("Forward iface %p, base %p\n", This, base);
4202 return ID3DXBaseEffectImpl_SetMatrixTransposeArray(base, parameter, matrix, count);
4205 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4207 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4208 ID3DXBaseEffect *base = This->base_effect;
4210 TRACE("Forward iface %p, base %p\n", This, base);
4212 return ID3DXBaseEffectImpl_GetMatrixTransposeArray(base, parameter, matrix, count);
4215 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
4217 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4218 ID3DXBaseEffect *base = This->base_effect;
4220 TRACE("Forward iface %p, base %p\n", This, base);
4222 return ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(base, parameter, matrix, count);
4225 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4227 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4228 ID3DXBaseEffect *base = This->base_effect;
4230 TRACE("Forward iface %p, base %p\n", This, base);
4232 return ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(base, parameter, matrix, count);
4235 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR string)
4237 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4238 ID3DXBaseEffect *base = This->base_effect;
4240 TRACE("Forward iface %p, base %p\n", This, base);
4242 return ID3DXBaseEffectImpl_SetString(base, parameter, string);
4245 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR *string)
4247 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4248 ID3DXBaseEffect *base = This->base_effect;
4250 TRACE("Forward iface %p, base %p\n", This, base);
4252 return ID3DXBaseEffectImpl_GetString(base, parameter, string);
4255 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetTexture(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
4257 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4258 ID3DXBaseEffect *base = This->base_effect;
4260 TRACE("Forward iface %p, base %p\n", This, base);
4262 return ID3DXBaseEffectImpl_SetTexture(base, parameter, texture);
4265 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTexture(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
4267 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4268 ID3DXBaseEffect *base = This->base_effect;
4270 TRACE("Forward iface %p, base %p\n", This, base);
4272 return ID3DXBaseEffectImpl_GetTexture(base, parameter, texture);
4275 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
4277 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4278 ID3DXBaseEffect *base = This->base_effect;
4280 TRACE("Forward iface %p, base %p\n", This, base);
4282 return ID3DXBaseEffectImpl_GetPixelShader(base, parameter, pshader);
4285 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVertexShader(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
4287 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4288 ID3DXBaseEffect *base = This->base_effect;
4290 TRACE("Forward iface %p, base %p\n", This, base);
4292 return ID3DXBaseEffectImpl_GetVertexShader(base, parameter, vshader);
4295 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT start, UINT end)
4297 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4298 ID3DXBaseEffect *base = This->base_effect;
4300 TRACE("Forward iface %p, base %p\n", This, base);
4302 return ID3DXBaseEffectImpl_SetArrayRange(base, parameter, start, end);
4305 /*** ID3DXEffectCompiler methods ***/
4306 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL literal)
4308 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4310 FIXME("iface %p, parameter %p, literal %u\n", This, parameter, literal);
4312 return E_NOTIMPL;
4315 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *literal)
4317 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4319 FIXME("iface %p, parameter %p, literal %p\n", This, parameter, literal);
4321 return E_NOTIMPL;
4324 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler *iface, DWORD flags,
4325 LPD3DXBUFFER *effect, LPD3DXBUFFER *error_msgs)
4327 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4329 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub\n", This, flags, effect, error_msgs);
4331 return E_NOTIMPL;
4334 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler *iface, D3DXHANDLE function,
4335 LPCSTR target, DWORD flags, LPD3DXBUFFER *shader, LPD3DXBUFFER *error_msgs, LPD3DXCONSTANTTABLE *constant_table)
4337 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4339 FIXME("iface %p, function %p, target %p, flags %#x, shader %p, error_msgs %p, constant_table %p stub\n",
4340 This, function, target, flags, shader, error_msgs, constant_table);
4342 return E_NOTIMPL;
4345 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
4347 /*** IUnknown methods ***/
4348 ID3DXEffectCompilerImpl_QueryInterface,
4349 ID3DXEffectCompilerImpl_AddRef,
4350 ID3DXEffectCompilerImpl_Release,
4351 /*** ID3DXBaseEffect methods ***/
4352 ID3DXEffectCompilerImpl_GetDesc,
4353 ID3DXEffectCompilerImpl_GetParameterDesc,
4354 ID3DXEffectCompilerImpl_GetTechniqueDesc,
4355 ID3DXEffectCompilerImpl_GetPassDesc,
4356 ID3DXEffectCompilerImpl_GetFunctionDesc,
4357 ID3DXEffectCompilerImpl_GetParameter,
4358 ID3DXEffectCompilerImpl_GetParameterByName,
4359 ID3DXEffectCompilerImpl_GetParameterBySemantic,
4360 ID3DXEffectCompilerImpl_GetParameterElement,
4361 ID3DXEffectCompilerImpl_GetTechnique,
4362 ID3DXEffectCompilerImpl_GetTechniqueByName,
4363 ID3DXEffectCompilerImpl_GetPass,
4364 ID3DXEffectCompilerImpl_GetPassByName,
4365 ID3DXEffectCompilerImpl_GetFunction,
4366 ID3DXEffectCompilerImpl_GetFunctionByName,
4367 ID3DXEffectCompilerImpl_GetAnnotation,
4368 ID3DXEffectCompilerImpl_GetAnnotationByName,
4369 ID3DXEffectCompilerImpl_SetValue,
4370 ID3DXEffectCompilerImpl_GetValue,
4371 ID3DXEffectCompilerImpl_SetBool,
4372 ID3DXEffectCompilerImpl_GetBool,
4373 ID3DXEffectCompilerImpl_SetBoolArray,
4374 ID3DXEffectCompilerImpl_GetBoolArray,
4375 ID3DXEffectCompilerImpl_SetInt,
4376 ID3DXEffectCompilerImpl_GetInt,
4377 ID3DXEffectCompilerImpl_SetIntArray,
4378 ID3DXEffectCompilerImpl_GetIntArray,
4379 ID3DXEffectCompilerImpl_SetFloat,
4380 ID3DXEffectCompilerImpl_GetFloat,
4381 ID3DXEffectCompilerImpl_SetFloatArray,
4382 ID3DXEffectCompilerImpl_GetFloatArray,
4383 ID3DXEffectCompilerImpl_SetVector,
4384 ID3DXEffectCompilerImpl_GetVector,
4385 ID3DXEffectCompilerImpl_SetVectorArray,
4386 ID3DXEffectCompilerImpl_GetVectorArray,
4387 ID3DXEffectCompilerImpl_SetMatrix,
4388 ID3DXEffectCompilerImpl_GetMatrix,
4389 ID3DXEffectCompilerImpl_SetMatrixArray,
4390 ID3DXEffectCompilerImpl_GetMatrixArray,
4391 ID3DXEffectCompilerImpl_SetMatrixPointerArray,
4392 ID3DXEffectCompilerImpl_GetMatrixPointerArray,
4393 ID3DXEffectCompilerImpl_SetMatrixTranspose,
4394 ID3DXEffectCompilerImpl_GetMatrixTranspose,
4395 ID3DXEffectCompilerImpl_SetMatrixTransposeArray,
4396 ID3DXEffectCompilerImpl_GetMatrixTransposeArray,
4397 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray,
4398 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray,
4399 ID3DXEffectCompilerImpl_SetString,
4400 ID3DXEffectCompilerImpl_GetString,
4401 ID3DXEffectCompilerImpl_SetTexture,
4402 ID3DXEffectCompilerImpl_GetTexture,
4403 ID3DXEffectCompilerImpl_GetPixelShader,
4404 ID3DXEffectCompilerImpl_GetVertexShader,
4405 ID3DXEffectCompilerImpl_SetArrayRange,
4406 /*** ID3DXEffectCompiler methods ***/
4407 ID3DXEffectCompilerImpl_SetLiteral,
4408 ID3DXEffectCompilerImpl_GetLiteral,
4409 ID3DXEffectCompilerImpl_CompileEffect,
4410 ID3DXEffectCompilerImpl_CompileShader,
4413 static HRESULT d3dx9_parse_sampler(struct d3dx_sampler *sampler, const char *data, const char **ptr, D3DXHANDLE *objects)
4415 HRESULT hr;
4416 UINT i;
4417 struct d3dx_state *states;
4419 read_dword(ptr, &sampler->state_count);
4420 TRACE("Count: %u\n", sampler->state_count);
4422 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * sampler->state_count);
4423 if (!states)
4425 ERR("Out of memory\n");
4426 return E_OUTOFMEMORY;
4429 for (i = 0; i < sampler->state_count; ++i)
4431 hr = d3dx9_parse_state(&states[i], data, ptr, objects);
4432 if (hr != D3D_OK)
4434 WARN("Failed to parse state\n");
4435 goto err_out;
4439 sampler->states = states;
4441 return D3D_OK;
4443 err_out:
4445 for (i = 0; i < sampler->state_count; ++i)
4447 free_state(&states[i]);
4450 HeapFree(GetProcessHeap(), 0, states);
4452 return hr;
4455 static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, const char *data, const char **ptr, D3DXHANDLE *objects)
4457 unsigned int i;
4458 HRESULT hr;
4459 UINT old_size = 0;
4460 DWORD id;
4462 if (param->element_count)
4464 param->data = value;
4466 for (i = 0; i < param->element_count; ++i)
4468 struct d3dx_parameter *member = get_parameter_struct(param->member_handles[i]);
4470 hr = d3dx9_parse_value(member, value ? (char *)value + old_size : NULL, data, ptr, objects);
4471 if (hr != D3D_OK)
4473 WARN("Failed to parse value\n");
4474 return hr;
4477 old_size += member->bytes;
4480 return D3D_OK;
4483 switch(param->class)
4485 case D3DXPC_SCALAR:
4486 case D3DXPC_VECTOR:
4487 case D3DXPC_MATRIX_ROWS:
4488 case D3DXPC_MATRIX_COLUMNS:
4489 param->data = value;
4490 break;
4492 case D3DXPC_STRUCT:
4493 param->data = value;
4495 for (i = 0; i < param->member_count; ++i)
4497 struct d3dx_parameter *member = get_parameter_struct(param->member_handles[i]);
4499 hr = d3dx9_parse_value(member, (char *)value + old_size, data, ptr, objects);
4500 if (hr != D3D_OK)
4502 WARN("Failed to parse value\n");
4503 return hr;
4506 old_size += member->bytes;
4508 break;
4510 case D3DXPC_OBJECT:
4511 switch (param->type)
4513 case D3DXPT_STRING:
4514 case D3DXPT_TEXTURE:
4515 case D3DXPT_TEXTURE1D:
4516 case D3DXPT_TEXTURE2D:
4517 case D3DXPT_TEXTURE3D:
4518 case D3DXPT_TEXTURECUBE:
4519 case D3DXPT_PIXELSHADER:
4520 case D3DXPT_VERTEXSHADER:
4521 read_dword(ptr, &id);
4522 TRACE("Id: %u\n", id);
4523 objects[id] = get_parameter_handle(param);
4524 param->data = value;
4525 break;
4527 case D3DXPT_SAMPLER:
4528 case D3DXPT_SAMPLER1D:
4529 case D3DXPT_SAMPLER2D:
4530 case D3DXPT_SAMPLER3D:
4531 case D3DXPT_SAMPLERCUBE:
4533 struct d3dx_sampler *sampler;
4535 sampler = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler));
4536 if (!sampler)
4538 ERR("Out of memory\n");
4539 return E_OUTOFMEMORY;
4542 hr = d3dx9_parse_sampler(sampler, data, ptr, objects);
4543 if (hr != D3D_OK)
4545 HeapFree(GetProcessHeap(), 0, sampler);
4546 WARN("Failed to parse sampler\n");
4547 return hr;
4550 param->data = sampler;
4551 break;
4554 default:
4555 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4556 break;
4558 break;
4560 default:
4561 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4562 break;
4565 return D3D_OK;
4568 static HRESULT d3dx9_parse_init_value(struct d3dx_parameter *param, const char *data, const char *ptr, D3DXHANDLE *objects)
4570 UINT size = param->bytes;
4571 HRESULT hr;
4572 void *value = NULL;
4574 TRACE("param size: %u\n", size);
4576 if (size)
4578 value = HeapAlloc(GetProcessHeap(), 0, size);
4579 if (!value)
4581 ERR("Failed to allocate data memory.\n");
4582 return E_OUTOFMEMORY;
4585 TRACE("Data: %s.\n", debugstr_an(ptr, size));
4586 memcpy(value, ptr, size);
4589 hr = d3dx9_parse_value(param, value, data, &ptr, objects);
4590 if (hr != D3D_OK)
4592 WARN("Failed to parse value\n");
4593 HeapFree(GetProcessHeap(), 0, value);
4594 return hr;
4597 return D3D_OK;
4600 static HRESULT d3dx9_parse_name(char **name, const char *ptr)
4602 DWORD size;
4604 read_dword(&ptr, &size);
4605 TRACE("Name size: %#x\n", size);
4607 if (!size)
4609 return D3D_OK;
4612 *name = HeapAlloc(GetProcessHeap(), 0, size);
4613 if (!*name)
4615 ERR("Failed to allocate name memory.\n");
4616 return E_OUTOFMEMORY;
4619 TRACE("Name: %s.\n", debugstr_an(ptr, size));
4620 memcpy(*name, ptr, size);
4622 return D3D_OK;
4625 static HRESULT d3dx9_copy_data(char **str, const char **ptr)
4627 DWORD size;
4629 read_dword(ptr, &size);
4630 TRACE("Data size: %#x\n", size);
4632 *str = HeapAlloc(GetProcessHeap(), 0, size);
4633 if (!*str)
4635 ERR("Failed to allocate name memory.\n");
4636 return E_OUTOFMEMORY;
4639 TRACE("Data: %s.\n", debugstr_an(*ptr, size));
4640 memcpy(*str, *ptr, size);
4642 *ptr += ((size + 3) & ~3);
4644 return D3D_OK;
4647 static HRESULT d3dx9_parse_data(struct d3dx_parameter *param, const char **ptr, LPDIRECT3DDEVICE9 device)
4649 DWORD size;
4650 HRESULT hr;
4652 TRACE("Parse data for parameter %s, type %s\n", debugstr_a(param->name), debug_d3dxparameter_type(param->type));
4654 read_dword(ptr, &size);
4655 TRACE("Data size: %#x\n", size);
4657 if (!size)
4659 TRACE("Size is 0\n");
4660 *(void **)param->data = NULL;
4661 return D3D_OK;
4664 switch (param->type)
4666 case D3DXPT_STRING:
4667 /* re-read with size (sizeof(DWORD) = 4) */
4668 hr = d3dx9_parse_name((LPSTR *)param->data, *ptr - 4);
4669 if (hr != D3D_OK)
4671 WARN("Failed to parse string data\n");
4672 return hr;
4674 break;
4676 case D3DXPT_VERTEXSHADER:
4677 hr = IDirect3DDevice9_CreateVertexShader(device, (DWORD *)*ptr, (LPDIRECT3DVERTEXSHADER9 *)param->data);
4678 if (hr != D3D_OK)
4680 WARN("Failed to create vertex shader\n");
4681 return hr;
4683 break;
4685 case D3DXPT_PIXELSHADER:
4686 hr = IDirect3DDevice9_CreatePixelShader(device, (DWORD *)*ptr, (LPDIRECT3DPIXELSHADER9 *)param->data);
4687 if (hr != D3D_OK)
4689 WARN("Failed to create pixel shader\n");
4690 return hr;
4692 break;
4694 default:
4695 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4696 break;
4700 *ptr += ((size + 3) & ~3);
4702 return D3D_OK;
4705 static HRESULT d3dx9_parse_effect_typedef(struct d3dx_parameter *param, const char *data, const char **ptr,
4706 struct d3dx_parameter *parent, UINT flags)
4708 DWORD offset;
4709 HRESULT hr;
4710 D3DXHANDLE *member_handles = NULL;
4711 UINT i;
4713 param->flags = flags;
4715 if (!parent)
4717 read_dword(ptr, &param->type);
4718 TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
4720 read_dword(ptr, &param->class);
4721 TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
4723 read_dword(ptr, &offset);
4724 TRACE("Type name offset: %#x\n", offset);
4725 hr = d3dx9_parse_name(&param->name, data + offset);
4726 if (hr != D3D_OK)
4728 WARN("Failed to parse name\n");
4729 goto err_out;
4732 read_dword(ptr, &offset);
4733 TRACE("Type semantic offset: %#x\n", offset);
4734 hr = d3dx9_parse_name(&param->semantic, data + offset);
4735 if (hr != D3D_OK)
4737 WARN("Failed to parse semantic\n");
4738 goto err_out;
4741 read_dword(ptr, &param->element_count);
4742 TRACE("Elements: %u\n", param->element_count);
4744 switch (param->class)
4746 case D3DXPC_VECTOR:
4747 read_dword(ptr, &param->columns);
4748 TRACE("Columns: %u\n", param->columns);
4750 read_dword(ptr, &param->rows);
4751 TRACE("Rows: %u\n", param->rows);
4753 /* sizeof(DWORD) * rows * columns */
4754 param->bytes = 4 * param->rows * param->columns;
4755 break;
4757 case D3DXPC_SCALAR:
4758 case D3DXPC_MATRIX_ROWS:
4759 case D3DXPC_MATRIX_COLUMNS:
4760 read_dword(ptr, &param->rows);
4761 TRACE("Rows: %u\n", param->rows);
4763 read_dword(ptr, &param->columns);
4764 TRACE("Columns: %u\n", param->columns);
4766 /* sizeof(DWORD) * rows * columns */
4767 param->bytes = 4 * param->rows * param->columns;
4768 break;
4770 case D3DXPC_STRUCT:
4771 read_dword(ptr, &param->member_count);
4772 TRACE("Members: %u\n", param->member_count);
4773 break;
4775 case D3DXPC_OBJECT:
4776 switch (param->type)
4778 case D3DXPT_STRING:
4779 param->bytes = sizeof(LPCSTR);
4780 break;
4782 case D3DXPT_PIXELSHADER:
4783 param->bytes = sizeof(LPDIRECT3DPIXELSHADER9);
4784 break;
4786 case D3DXPT_VERTEXSHADER:
4787 param->bytes = sizeof(LPDIRECT3DVERTEXSHADER9);
4788 break;
4790 case D3DXPT_TEXTURE:
4791 case D3DXPT_TEXTURE1D:
4792 case D3DXPT_TEXTURE2D:
4793 case D3DXPT_TEXTURE3D:
4794 case D3DXPT_TEXTURECUBE:
4795 param->bytes = sizeof(LPDIRECT3DBASETEXTURE9);
4796 break;
4798 case D3DXPT_SAMPLER:
4799 case D3DXPT_SAMPLER1D:
4800 case D3DXPT_SAMPLER2D:
4801 case D3DXPT_SAMPLER3D:
4802 case D3DXPT_SAMPLERCUBE:
4803 param->bytes = 0;
4804 break;
4806 default:
4807 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4808 break;
4810 break;
4812 default:
4813 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4814 break;
4817 else
4819 /* elements */
4820 param->type = parent->type;
4821 param->class = parent->class;
4822 param->name = parent->name;
4823 param->semantic = parent->semantic;
4824 param->element_count = 0;
4825 param->annotation_count = 0;
4826 param->member_count = parent->member_count;
4827 param->bytes = parent->bytes;
4828 param->rows = parent->rows;
4829 param->columns = parent->columns;
4832 if (param->element_count)
4834 unsigned int param_bytes = 0;
4835 const char *save_ptr = *ptr;
4837 member_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member_handles) * param->element_count);
4838 if (!member_handles)
4840 ERR("Out of memory\n");
4841 hr = E_OUTOFMEMORY;
4842 goto err_out;
4845 for (i = 0; i < param->element_count; ++i)
4847 struct d3dx_parameter *member;
4848 *ptr = save_ptr;
4850 member = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member));
4851 if (!member)
4853 ERR("Out of memory\n");
4854 hr = E_OUTOFMEMORY;
4855 goto err_out;
4858 member_handles[i] = get_parameter_handle(member);
4860 hr = d3dx9_parse_effect_typedef(member, data, ptr, param, flags);
4861 if (hr != D3D_OK)
4863 WARN("Failed to parse member\n");
4864 goto err_out;
4867 param_bytes += member->bytes;
4870 param->bytes = param_bytes;
4872 else if (param->member_count)
4874 member_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member_handles) * param->member_count);
4875 if (!member_handles)
4877 ERR("Out of memory\n");
4878 hr = E_OUTOFMEMORY;
4879 goto err_out;
4882 for (i = 0; i < param->member_count; ++i)
4884 struct d3dx_parameter *member;
4886 member = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member));
4887 if (!member)
4889 ERR("Out of memory\n");
4890 hr = E_OUTOFMEMORY;
4891 goto err_out;
4894 member_handles[i] = get_parameter_handle(member);
4896 hr = d3dx9_parse_effect_typedef(member, data, ptr, NULL, flags);
4897 if (hr != D3D_OK)
4899 WARN("Failed to parse member\n");
4900 goto err_out;
4903 param->bytes += member->bytes;
4907 param->member_handles = member_handles;
4909 return D3D_OK;
4911 err_out:
4913 if (member_handles)
4915 unsigned int count;
4917 if (param->element_count) count = param->element_count;
4918 else count = param->member_count;
4920 for (i = 0; i < count; ++i)
4922 free_parameter(member_handles[i], param->element_count != 0, TRUE);
4924 HeapFree(GetProcessHeap(), 0, member_handles);
4927 if (!parent)
4929 HeapFree(GetProcessHeap(), 0, param->name);
4930 HeapFree(GetProcessHeap(), 0, param->semantic);
4932 param->name = NULL;
4933 param->semantic = NULL;
4935 return hr;
4938 static HRESULT d3dx9_parse_effect_annotation(struct d3dx_parameter *anno, const char *data, const char **ptr, D3DXHANDLE *objects)
4940 DWORD offset;
4941 const char *ptr2;
4942 HRESULT hr;
4944 anno->flags = D3DX_PARAMETER_ANNOTATION;
4946 read_dword(ptr, &offset);
4947 TRACE("Typedef offset: %#x\n", offset);
4948 ptr2 = data + offset;
4949 hr = d3dx9_parse_effect_typedef(anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
4950 if (hr != D3D_OK)
4952 WARN("Failed to parse type definition\n");
4953 return hr;
4956 read_dword(ptr, &offset);
4957 TRACE("Value offset: %#x\n", offset);
4958 hr = d3dx9_parse_init_value(anno, data, data + offset, objects);
4959 if (hr != D3D_OK)
4961 WARN("Failed to parse value\n");
4962 return hr;
4965 return D3D_OK;
4968 static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects)
4970 DWORD offset;
4971 const char *ptr2;
4972 HRESULT hr;
4973 struct d3dx_parameter *parameter;
4975 parameter = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter));
4976 if (!parameter)
4978 ERR("Out of memory\n");
4979 return E_OUTOFMEMORY;
4982 state->type = ST_CONSTANT;
4984 read_dword(ptr, &state->operation);
4985 TRACE("Operation: %#x (%s)\n", state->operation, state_table[state->operation].name);
4987 read_dword(ptr, &state->index);
4988 TRACE("Index: %#x\n", state->index);
4990 read_dword(ptr, &offset);
4991 TRACE("Typedef offset: %#x\n", offset);
4992 ptr2 = data + offset;
4993 hr = d3dx9_parse_effect_typedef(parameter, data, &ptr2, NULL, 0);
4994 if (hr != D3D_OK)
4996 WARN("Failed to parse type definition\n");
4997 goto err_out;
5000 read_dword(ptr, &offset);
5001 TRACE("Value offset: %#x\n", offset);
5002 hr = d3dx9_parse_init_value(parameter, data, data + offset, objects);
5003 if (hr != D3D_OK)
5005 WARN("Failed to parse value\n");
5006 goto err_out;
5009 state->parameter = get_parameter_handle(parameter);
5011 return D3D_OK;
5013 err_out:
5015 free_parameter(get_parameter_handle(parameter), FALSE, FALSE);
5017 return hr;
5020 static HRESULT d3dx9_parse_effect_parameter(struct d3dx_parameter *param, const char *data, const char **ptr, D3DXHANDLE *objects)
5022 DWORD offset;
5023 HRESULT hr;
5024 unsigned int i;
5025 D3DXHANDLE *annotation_handles = NULL;
5026 const char *ptr2;
5028 read_dword(ptr, &offset);
5029 TRACE("Typedef offset: %#x\n", offset);
5030 ptr2 = data + offset;
5032 read_dword(ptr, &offset);
5033 TRACE("Value offset: %#x\n", offset);
5035 read_dword(ptr, &param->flags);
5036 TRACE("Flags: %#x\n", param->flags);
5038 read_dword(ptr, &param->annotation_count);
5039 TRACE("Annotation count: %u\n", param->annotation_count);
5041 hr = d3dx9_parse_effect_typedef(param, data, &ptr2, NULL, param->flags);
5042 if (hr != D3D_OK)
5044 WARN("Failed to parse type definition\n");
5045 return hr;
5048 hr = d3dx9_parse_init_value(param, data, data + offset, objects);
5049 if (hr != D3D_OK)
5051 WARN("Failed to parse value\n");
5052 return hr;
5055 if (param->annotation_count)
5057 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * param->annotation_count);
5058 if (!annotation_handles)
5060 ERR("Out of memory\n");
5061 hr = E_OUTOFMEMORY;
5062 goto err_out;
5065 for (i = 0; i < param->annotation_count; ++i)
5067 struct d3dx_parameter *annotation;
5069 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5070 if (!annotation)
5072 ERR("Out of memory\n");
5073 hr = E_OUTOFMEMORY;
5074 goto err_out;
5077 annotation_handles[i] = get_parameter_handle(annotation);
5079 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5080 if (hr != D3D_OK)
5082 WARN("Failed to parse annotation\n");
5083 goto err_out;
5088 param->annotation_handles = annotation_handles;
5090 return D3D_OK;
5092 err_out:
5094 if (annotation_handles)
5096 for (i = 0; i < param->annotation_count; ++i)
5098 free_parameter(annotation_handles[i], FALSE, FALSE);
5100 HeapFree(GetProcessHeap(), 0, annotation_handles);
5103 return hr;
5106 static HRESULT d3dx9_parse_effect_pass(struct d3dx_pass *pass, const char *data, const char **ptr, D3DXHANDLE *objects)
5108 DWORD offset;
5109 HRESULT hr;
5110 unsigned int i;
5111 D3DXHANDLE *annotation_handles = NULL;
5112 struct d3dx_state *states = NULL;
5113 char *name = NULL;
5115 read_dword(ptr, &offset);
5116 TRACE("Pass name offset: %#x\n", offset);
5117 hr = d3dx9_parse_name(&name, data + offset);
5118 if (hr != D3D_OK)
5120 WARN("Failed to parse name\n");
5121 goto err_out;
5124 read_dword(ptr, &pass->annotation_count);
5125 TRACE("Annotation count: %u\n", pass->annotation_count);
5127 read_dword(ptr, &pass->state_count);
5128 TRACE("State count: %u\n", pass->state_count);
5130 if (pass->annotation_count)
5132 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * pass->annotation_count);
5133 if (!annotation_handles)
5135 ERR("Out of memory\n");
5136 hr = E_OUTOFMEMORY;
5137 goto err_out;
5140 for (i = 0; i < pass->annotation_count; ++i)
5142 struct d3dx_parameter *annotation;
5144 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5145 if (!annotation)
5147 ERR("Out of memory\n");
5148 hr = E_OUTOFMEMORY;
5149 goto err_out;
5152 annotation_handles[i] = get_parameter_handle(annotation);
5154 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5155 if (hr != D3D_OK)
5157 WARN("Failed to parse annotations\n");
5158 goto err_out;
5163 if (pass->state_count)
5165 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * pass->state_count);
5166 if (!states)
5168 ERR("Out of memory\n");
5169 hr = E_OUTOFMEMORY;
5170 goto err_out;
5173 for (i = 0; i < pass->state_count; ++i)
5175 hr = d3dx9_parse_state(&states[i], data, ptr, objects);
5176 if (hr != D3D_OK)
5178 WARN("Failed to parse annotations\n");
5179 goto err_out;
5184 pass->name = name;
5185 pass->annotation_handles = annotation_handles;
5186 pass->states = states;
5188 return D3D_OK;
5190 err_out:
5192 if (annotation_handles)
5194 for (i = 0; i < pass->annotation_count; ++i)
5196 free_parameter(annotation_handles[i], FALSE, FALSE);
5198 HeapFree(GetProcessHeap(), 0, annotation_handles);
5201 if (states)
5203 for (i = 0; i < pass->state_count; ++i)
5205 free_state(&states[i]);
5207 HeapFree(GetProcessHeap(), 0, states);
5210 HeapFree(GetProcessHeap(), 0, name);
5212 return hr;
5215 static HRESULT d3dx9_parse_effect_technique(struct d3dx_technique *technique, const char *data, const char **ptr, D3DXHANDLE *objects)
5217 DWORD offset;
5218 HRESULT hr;
5219 unsigned int i;
5220 D3DXHANDLE *annotation_handles = NULL;
5221 D3DXHANDLE *pass_handles = NULL;
5222 char *name = NULL;
5224 read_dword(ptr, &offset);
5225 TRACE("Technique name offset: %#x\n", offset);
5226 hr = d3dx9_parse_name(&name, data + offset);
5227 if (hr != D3D_OK)
5229 WARN("Failed to parse name\n");
5230 goto err_out;
5233 read_dword(ptr, &technique->annotation_count);
5234 TRACE("Annotation count: %u\n", technique->annotation_count);
5236 read_dword(ptr, &technique->pass_count);
5237 TRACE("Pass count: %u\n", technique->pass_count);
5239 if (technique->annotation_count)
5241 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * technique->annotation_count);
5242 if (!annotation_handles)
5244 ERR("Out of memory\n");
5245 hr = E_OUTOFMEMORY;
5246 goto err_out;
5249 for (i = 0; i < technique->annotation_count; ++i)
5251 struct d3dx_parameter *annotation;
5253 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5254 if (!annotation)
5256 ERR("Out of memory\n");
5257 hr = E_OUTOFMEMORY;
5258 goto err_out;
5261 annotation_handles[i] = get_parameter_handle(annotation);
5263 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5264 if (hr != D3D_OK)
5266 WARN("Failed to parse annotations\n");
5267 goto err_out;
5272 if (technique->pass_count)
5274 pass_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pass_handles) * technique->pass_count);
5275 if (!pass_handles)
5277 ERR("Out of memory\n");
5278 hr = E_OUTOFMEMORY;
5279 goto err_out;
5282 for (i = 0; i < technique->pass_count; ++i)
5284 struct d3dx_pass *pass;
5286 pass = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pass));
5287 if (!pass)
5289 ERR("Out of memory\n");
5290 hr = E_OUTOFMEMORY;
5291 goto err_out;
5294 pass_handles[i] = get_pass_handle(pass);
5296 hr = d3dx9_parse_effect_pass(pass, data, ptr, objects);
5297 if (hr != D3D_OK)
5299 WARN("Failed to parse passes\n");
5300 goto err_out;
5305 technique->name = name;
5306 technique->pass_handles = pass_handles;
5307 technique->annotation_handles = annotation_handles;
5309 return D3D_OK;
5311 err_out:
5313 if (pass_handles)
5315 for (i = 0; i < technique->pass_count; ++i)
5317 free_pass(pass_handles[i]);
5319 HeapFree(GetProcessHeap(), 0, pass_handles);
5322 if (annotation_handles)
5324 for (i = 0; i < technique->annotation_count; ++i)
5326 free_parameter(annotation_handles[i], FALSE, FALSE);
5328 HeapFree(GetProcessHeap(), 0, annotation_handles);
5331 HeapFree(GetProcessHeap(), 0, name);
5333 return hr;
5336 static HRESULT d3dx9_parse_resource(struct ID3DXBaseEffectImpl *base, const char *data, const char **ptr)
5338 DWORD technique_index;
5339 DWORD index, state_index, usage, element_index;
5340 struct d3dx_state *state;
5341 struct d3dx_parameter *param;
5342 HRESULT hr = E_FAIL;
5344 read_dword(ptr, &technique_index);
5345 TRACE("techn: %u\n", technique_index);
5347 read_dword(ptr, &index);
5348 TRACE("index: %u\n", index);
5350 read_dword(ptr, &element_index);
5351 TRACE("element_index: %u\n", element_index);
5353 read_dword(ptr, &state_index);
5354 TRACE("state_index: %u\n", state_index);
5356 read_dword(ptr, &usage);
5357 TRACE("usage: %u\n", usage);
5359 if (technique_index == 0xffffffff)
5361 struct d3dx_parameter *parameter;
5362 struct d3dx_sampler *sampler;
5364 if (index >= base->parameter_count)
5366 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index, base->parameter_count);
5367 return E_FAIL;
5370 parameter = get_parameter_struct(base->parameter_handles[index]);
5371 if (element_index != 0xffffffff)
5373 if (element_index >= parameter->element_count && parameter->element_count != 0)
5375 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index, parameter->element_count);
5376 return E_FAIL;
5379 if (parameter->element_count != 0) parameter = get_parameter_struct(parameter->member_handles[element_index]);
5382 sampler = parameter->data;
5383 if (state_index >= sampler->state_count)
5385 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, sampler->state_count);
5386 return E_FAIL;
5389 state = &sampler->states[state_index];
5391 else
5393 struct d3dx_technique *technique;
5394 struct d3dx_pass *pass;
5396 if (technique_index >= base->technique_count)
5398 FIXME("Index out of bounds: technique_index %u >= technique_count %u\n", technique_index, base->technique_count);
5399 return E_FAIL;
5402 technique = get_technique_struct(base->technique_handles[technique_index]);
5403 if (index >= technique->pass_count)
5405 FIXME("Index out of bounds: index %u >= pass_count %u\n", index, technique->pass_count);
5406 return E_FAIL;
5409 pass = get_pass_struct(technique->pass_handles[index]);
5410 if (state_index >= pass->state_count)
5412 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, pass->state_count);
5413 return E_FAIL;
5416 state = &pass->states[state_index];
5419 param = get_parameter_struct(state->parameter);
5421 switch (usage)
5423 case 0:
5424 TRACE("usage 0: type %s\n", debug_d3dxparameter_type(param->type));
5425 switch (param->type)
5427 case D3DXPT_VERTEXSHADER:
5428 case D3DXPT_PIXELSHADER:
5429 state->type = ST_CONSTANT;
5430 hr = d3dx9_parse_data(param, ptr, base->effect->device);
5431 break;
5433 case D3DXPT_BOOL:
5434 case D3DXPT_INT:
5435 case D3DXPT_FLOAT:
5436 case D3DXPT_STRING:
5437 state->type = ST_FXLC;
5438 hr = d3dx9_copy_data(param->data, ptr);
5439 break;
5441 default:
5442 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5443 break;
5445 break;
5447 case 1:
5448 state->type = ST_PARAMETER;
5449 hr = d3dx9_copy_data(param->data, ptr);
5450 if (hr == D3D_OK)
5452 TRACE("Mapping to parameter %s\n", *(char **)param->data);
5454 break;
5456 default:
5457 FIXME("Unknown usage %x\n", usage);
5458 break;
5461 return hr;
5464 static HRESULT d3dx9_parse_effect(struct ID3DXBaseEffectImpl *base, const char *data, UINT data_size, DWORD start)
5466 const char *ptr = data + start;
5467 D3DXHANDLE *parameter_handles = NULL;
5468 D3DXHANDLE *technique_handles = NULL;
5469 D3DXHANDLE *objects = NULL;
5470 UINT stringcount, objectcount, resourcecount;
5471 HRESULT hr;
5472 UINT i;
5474 read_dword(&ptr, &base->parameter_count);
5475 TRACE("Parameter count: %u\n", base->parameter_count);
5477 read_dword(&ptr, &base->technique_count);
5478 TRACE("Technique count: %u\n", base->technique_count);
5480 skip_dword_unknown(&ptr, 1);
5482 read_dword(&ptr, &objectcount);
5483 TRACE("Object count: %u\n", objectcount);
5485 objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*objects) * objectcount);
5486 if (!objects)
5488 ERR("Out of memory\n");
5489 hr = E_OUTOFMEMORY;
5490 goto err_out;
5493 if (base->parameter_count)
5495 parameter_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter_handles) * base->parameter_count);
5496 if (!parameter_handles)
5498 ERR("Out of memory\n");
5499 hr = E_OUTOFMEMORY;
5500 goto err_out;
5503 for (i = 0; i < base->parameter_count; ++i)
5505 struct d3dx_parameter *parameter;
5507 parameter = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter));
5508 if (!parameter)
5510 ERR("Out of memory\n");
5511 hr = E_OUTOFMEMORY;
5512 goto err_out;
5515 parameter_handles[i] = get_parameter_handle(parameter);
5517 hr = d3dx9_parse_effect_parameter(parameter, data, &ptr, objects);
5518 if (hr != D3D_OK)
5520 WARN("Failed to parse parameter\n");
5521 goto err_out;
5526 if (base->technique_count)
5528 technique_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*technique_handles) * base->technique_count);
5529 if (!technique_handles)
5531 ERR("Out of memory\n");
5532 hr = E_OUTOFMEMORY;
5533 goto err_out;
5536 for (i = 0; i < base->technique_count; ++i)
5538 struct d3dx_technique *technique;
5540 technique = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*technique));
5541 if (!technique)
5543 ERR("Out of memory\n");
5544 hr = E_OUTOFMEMORY;
5545 goto err_out;
5548 technique_handles[i] = get_technique_handle(technique);
5550 hr = d3dx9_parse_effect_technique(technique, data, &ptr, objects);
5551 if (hr != D3D_OK)
5553 WARN("Failed to parse technique\n");
5554 goto err_out;
5559 /* needed for further parsing */
5560 base->technique_handles = technique_handles;
5561 base->parameter_handles = parameter_handles;
5563 read_dword(&ptr, &stringcount);
5564 TRACE("String count: %u\n", stringcount);
5566 read_dword(&ptr, &resourcecount);
5567 TRACE("Resource count: %u\n", resourcecount);
5569 for (i = 0; i < stringcount; ++i)
5571 DWORD id;
5572 struct d3dx_parameter *param;
5574 read_dword(&ptr, &id);
5575 TRACE("Id: %u\n", id);
5577 param = get_parameter_struct(objects[id]);
5579 hr = d3dx9_parse_data(param, &ptr, base->effect->device);
5580 if (hr != D3D_OK)
5582 WARN("Failed to parse data\n");
5583 goto err_out;
5587 for (i = 0; i < resourcecount; ++i)
5589 TRACE("parse resource %u\n", i);
5591 hr = d3dx9_parse_resource(base, data, &ptr);
5592 if (hr != D3D_OK)
5594 WARN("Failed to parse data\n");
5595 goto err_out;
5599 HeapFree(GetProcessHeap(), 0, objects);
5601 return D3D_OK;
5603 err_out:
5605 if (technique_handles)
5607 for (i = 0; i < base->technique_count; ++i)
5609 free_technique(technique_handles[i]);
5611 HeapFree(GetProcessHeap(), 0, technique_handles);
5614 if (parameter_handles)
5616 for (i = 0; i < base->parameter_count; ++i)
5618 free_parameter(parameter_handles[i], FALSE, FALSE);
5620 HeapFree(GetProcessHeap(), 0, parameter_handles);
5623 base->technique_handles = NULL;
5624 base->parameter_handles = NULL;
5626 HeapFree(GetProcessHeap(), 0, objects);
5628 return hr;
5631 static HRESULT d3dx9_base_effect_init(struct ID3DXBaseEffectImpl *base,
5632 const char *data, SIZE_T data_size, struct ID3DXEffectImpl *effect)
5634 DWORD tag, offset;
5635 const char *ptr = data;
5636 HRESULT hr;
5638 TRACE("base %p, data %p, data_size %lu, effect %p\n", base, data, data_size, effect);
5640 base->ID3DXBaseEffect_iface.lpVtbl = &ID3DXBaseEffect_Vtbl;
5641 base->ref = 1;
5642 base->effect = effect;
5644 read_dword(&ptr, &tag);
5645 TRACE("Tag: %x\n", tag);
5647 if (tag != d3dx9_effect_version(9, 1))
5649 /* todo: compile hlsl ascii code */
5650 FIXME("HLSL ascii effects not supported, yet\n");
5652 /* Show the start of the shader for debugging info. */
5653 TRACE("effect:\n%s\n", debugstr_an(data, data_size > 40 ? 40 : data_size));
5655 else
5657 read_dword(&ptr, &offset);
5658 TRACE("Offset: %x\n", offset);
5660 hr = d3dx9_parse_effect(base, ptr, data_size, offset);
5661 if (hr != D3D_OK)
5663 FIXME("Failed to parse effect.\n");
5664 return hr;
5668 return D3D_OK;
5671 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, LPDIRECT3DDEVICE9 device,
5672 const char *data, SIZE_T data_size, LPD3DXEFFECTPOOL pool)
5674 HRESULT hr;
5675 struct ID3DXBaseEffectImpl *object = NULL;
5677 TRACE("effect %p, device %p, data %p, data_size %lu, pool %p\n", effect, device, data, data_size, pool);
5679 effect->ID3DXEffect_iface.lpVtbl = &ID3DXEffect_Vtbl;
5680 effect->ref = 1;
5682 if (pool) pool->lpVtbl->AddRef(pool);
5683 effect->pool = pool;
5685 IDirect3DDevice9_AddRef(device);
5686 effect->device = device;
5688 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5689 if (!object)
5691 ERR("Out of memory\n");
5692 hr = E_OUTOFMEMORY;
5693 goto err_out;
5696 hr = d3dx9_base_effect_init(object, data, data_size, effect);
5697 if (hr != D3D_OK)
5699 FIXME("Failed to parse effect.\n");
5700 goto err_out;
5703 effect->base_effect = &object->ID3DXBaseEffect_iface;
5705 /* initialize defaults - check because of unsupported ascii effects */
5706 if (object->technique_handles)
5708 effect->active_technique = object->technique_handles[0];
5709 effect->active_pass = NULL;
5712 return D3D_OK;
5714 err_out:
5716 HeapFree(GetProcessHeap(), 0, object);
5717 free_effect(effect);
5719 return hr;
5722 HRESULT WINAPI D3DXCreateEffectEx(LPDIRECT3DDEVICE9 device,
5723 LPCVOID srcdata,
5724 UINT srcdatalen,
5725 CONST D3DXMACRO* defines,
5726 LPD3DXINCLUDE include,
5727 LPCSTR skip_constants,
5728 DWORD flags,
5729 LPD3DXEFFECTPOOL pool,
5730 LPD3DXEFFECT* effect,
5731 LPD3DXBUFFER* compilation_errors)
5733 struct ID3DXEffectImpl *object;
5734 HRESULT hr;
5736 FIXME("(%p, %p, %u, %p, %p, %p, %#x, %p, %p, %p): semi-stub\n", device, srcdata, srcdatalen, defines, include,
5737 skip_constants, flags, pool, effect, compilation_errors);
5739 if (!device || !srcdata)
5740 return D3DERR_INVALIDCALL;
5742 if (!srcdatalen)
5743 return E_FAIL;
5745 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
5746 if (!effect)
5747 return D3D_OK;
5749 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5750 if (!object)
5752 ERR("Out of memory\n");
5753 return E_OUTOFMEMORY;
5756 hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, pool);
5757 if (FAILED(hr))
5759 WARN("Failed to initialize shader reflection\n");
5760 HeapFree(GetProcessHeap(), 0, object);
5761 return hr;
5764 *effect = &object->ID3DXEffect_iface;
5766 TRACE("Created ID3DXEffect %p\n", object);
5768 return D3D_OK;
5771 HRESULT WINAPI D3DXCreateEffect(LPDIRECT3DDEVICE9 device,
5772 LPCVOID srcdata,
5773 UINT srcdatalen,
5774 CONST D3DXMACRO* defines,
5775 LPD3DXINCLUDE include,
5776 DWORD flags,
5777 LPD3DXEFFECTPOOL pool,
5778 LPD3DXEFFECT* effect,
5779 LPD3DXBUFFER* compilation_errors)
5781 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device, srcdata, srcdatalen, defines,
5782 include, flags, pool, effect, compilation_errors);
5784 return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
5787 static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler, const char *data, SIZE_T data_size)
5789 HRESULT hr;
5790 struct ID3DXBaseEffectImpl *object = NULL;
5792 TRACE("effect %p, data %p, data_size %lu\n", compiler, data, data_size);
5794 compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
5795 compiler->ref = 1;
5797 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5798 if (!object)
5800 ERR("Out of memory\n");
5801 hr = E_OUTOFMEMORY;
5802 goto err_out;
5805 hr = d3dx9_base_effect_init(object, data, data_size, NULL);
5806 if (hr != D3D_OK)
5808 FIXME("Failed to parse effect.\n");
5809 goto err_out;
5812 compiler->base_effect = &object->ID3DXBaseEffect_iface;
5814 return D3D_OK;
5816 err_out:
5818 HeapFree(GetProcessHeap(), 0, object);
5819 free_effect_compiler(compiler);
5821 return hr;
5824 HRESULT WINAPI D3DXCreateEffectCompiler(LPCSTR srcdata,
5825 UINT srcdatalen,
5826 CONST D3DXMACRO *defines,
5827 LPD3DXINCLUDE include,
5828 DWORD flags,
5829 LPD3DXEFFECTCOMPILER *compiler,
5830 LPD3DXBUFFER *parse_errors)
5832 struct ID3DXEffectCompilerImpl *object;
5833 HRESULT hr;
5835 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
5836 srcdata, srcdatalen, defines, include, flags, compiler, parse_errors);
5838 if (!srcdata || !compiler)
5840 WARN("Invalid arguments supplied\n");
5841 return D3DERR_INVALIDCALL;
5844 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5845 if (!object)
5847 ERR("Out of memory\n");
5848 return E_OUTOFMEMORY;
5851 hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen);
5852 if (FAILED(hr))
5854 WARN("Failed to initialize effect compiler\n");
5855 HeapFree(GetProcessHeap(), 0, object);
5856 return hr;
5859 *compiler = &object->ID3DXEffectCompiler_iface;
5861 TRACE("Created ID3DXEffectCompiler %p\n", object);
5863 return D3D_OK;
5866 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl;
5868 struct ID3DXEffectPoolImpl
5870 ID3DXEffectPool ID3DXEffectPool_iface;
5871 LONG ref;
5874 static inline struct ID3DXEffectPoolImpl *impl_from_ID3DXEffectPool(ID3DXEffectPool *iface)
5876 return CONTAINING_RECORD(iface, struct ID3DXEffectPoolImpl, ID3DXEffectPool_iface);
5879 /*** IUnknown methods ***/
5880 static HRESULT WINAPI ID3DXEffectPoolImpl_QueryInterface(ID3DXEffectPool *iface, REFIID riid, void **object)
5882 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
5884 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), object);
5886 if (IsEqualGUID(riid, &IID_IUnknown) ||
5887 IsEqualGUID(riid, &IID_ID3DXEffectPool))
5889 This->ID3DXEffectPool_iface.lpVtbl->AddRef(iface);
5890 *object = This;
5891 return S_OK;
5894 WARN("Interface %s not found\n", debugstr_guid(riid));
5896 return E_NOINTERFACE;
5899 static ULONG WINAPI ID3DXEffectPoolImpl_AddRef(ID3DXEffectPool *iface)
5901 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
5903 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
5905 return InterlockedIncrement(&This->ref);
5908 static ULONG WINAPI ID3DXEffectPoolImpl_Release(ID3DXEffectPool *iface)
5910 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
5911 ULONG ref = InterlockedDecrement(&This->ref);
5913 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
5915 if (!ref)
5916 HeapFree(GetProcessHeap(), 0, This);
5918 return ref;
5921 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl =
5923 /*** IUnknown methods ***/
5924 ID3DXEffectPoolImpl_QueryInterface,
5925 ID3DXEffectPoolImpl_AddRef,
5926 ID3DXEffectPoolImpl_Release
5929 HRESULT WINAPI D3DXCreateEffectPool(LPD3DXEFFECTPOOL *pool)
5931 struct ID3DXEffectPoolImpl *object;
5933 TRACE("(%p)\n", pool);
5935 if (!pool)
5936 return D3DERR_INVALIDCALL;
5938 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5939 if (!object)
5941 ERR("Out of memory\n");
5942 return E_OUTOFMEMORY;
5945 object->ID3DXEffectPool_iface.lpVtbl = &ID3DXEffectPool_Vtbl;
5946 object->ref = 1;
5948 *pool = &object->ID3DXEffectPool_iface;
5950 return S_OK;
5953 HRESULT WINAPI D3DXCreateEffectFromFileExW(LPDIRECT3DDEVICE9 device, LPCWSTR srcfile,
5954 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
5955 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
5957 LPVOID buffer;
5958 HRESULT ret;
5959 DWORD size;
5961 TRACE("(%s): relay\n", debugstr_w(srcfile));
5963 if (!device || !srcfile)
5964 return D3DERR_INVALIDCALL;
5966 ret = map_view_of_file(srcfile, &buffer, &size);
5968 if (FAILED(ret))
5969 return D3DXERR_INVALIDDATA;
5971 ret = D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
5972 UnmapViewOfFile(buffer);
5974 return ret;
5977 HRESULT WINAPI D3DXCreateEffectFromFileExA(LPDIRECT3DDEVICE9 device, LPCSTR srcfile,
5978 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
5979 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
5981 LPWSTR srcfileW;
5982 HRESULT ret;
5983 DWORD len;
5985 TRACE("(void): relay\n");
5987 if (!srcfile)
5988 return D3DERR_INVALIDCALL;
5990 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
5991 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
5992 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
5994 ret = D3DXCreateEffectFromFileExW(device, srcfileW, defines, include, skipconstants, flags, pool, effect, compilationerrors);
5995 HeapFree(GetProcessHeap(), 0, srcfileW);
5997 return ret;
6000 HRESULT WINAPI D3DXCreateEffectFromFileW(LPDIRECT3DDEVICE9 device, LPCWSTR srcfile,
6001 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6002 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6004 TRACE("(void): relay\n");
6005 return D3DXCreateEffectFromFileExW(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6008 HRESULT WINAPI D3DXCreateEffectFromFileA(LPDIRECT3DDEVICE9 device, LPCSTR srcfile,
6009 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6010 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6012 TRACE("(void): relay\n");
6013 return D3DXCreateEffectFromFileExA(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6016 HRESULT WINAPI D3DXCreateEffectFromResourceExW(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCWSTR srcresource,
6017 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6018 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6020 HRSRC resinfo;
6022 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(srcresource));
6024 if (!device)
6025 return D3DERR_INVALIDCALL;
6027 resinfo = FindResourceW(srcmodule, srcresource, (LPCWSTR) RT_RCDATA);
6029 if (resinfo)
6031 LPVOID buffer;
6032 HRESULT ret;
6033 DWORD size;
6035 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6037 if (FAILED(ret))
6038 return D3DXERR_INVALIDDATA;
6040 return D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6043 return D3DXERR_INVALIDDATA;
6046 HRESULT WINAPI D3DXCreateEffectFromResourceExA(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCSTR srcresource,
6047 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6048 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6050 HRSRC resinfo;
6052 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(srcresource));
6054 if (!device)
6055 return D3DERR_INVALIDCALL;
6057 resinfo = FindResourceA(srcmodule, srcresource, (LPCSTR) RT_RCDATA);
6059 if (resinfo)
6061 LPVOID buffer;
6062 HRESULT ret;
6063 DWORD size;
6065 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6067 if (FAILED(ret))
6068 return D3DXERR_INVALIDDATA;
6070 return D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6073 return D3DXERR_INVALIDDATA;
6076 HRESULT WINAPI D3DXCreateEffectFromResourceW(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCWSTR srcresource,
6077 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6078 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6080 TRACE("(void): relay\n");
6081 return D3DXCreateEffectFromResourceExW(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6084 HRESULT WINAPI D3DXCreateEffectFromResourceA(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCSTR srcresource,
6085 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6086 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6088 TRACE("(void): relay\n");
6089 return D3DXCreateEffectFromResourceExA(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6092 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(LPCWSTR srcfile, const D3DXMACRO *defines, LPD3DXINCLUDE include,
6093 DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6095 LPVOID buffer;
6096 HRESULT ret;
6097 DWORD size;
6099 TRACE("(%s): relay\n", debugstr_w(srcfile));
6101 if (!srcfile)
6102 return D3DERR_INVALIDCALL;
6104 ret = map_view_of_file(srcfile, &buffer, &size);
6106 if (FAILED(ret))
6107 return D3DXERR_INVALIDDATA;
6109 ret = D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6110 UnmapViewOfFile(buffer);
6112 return ret;
6115 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(LPCSTR srcfile, const D3DXMACRO *defines, LPD3DXINCLUDE include,
6116 DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6118 LPWSTR srcfileW;
6119 HRESULT ret;
6120 DWORD len;
6122 TRACE("(void): relay\n");
6124 if (!srcfile)
6125 return D3DERR_INVALIDCALL;
6127 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6128 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6129 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6131 ret = D3DXCreateEffectCompilerFromFileW(srcfileW, defines, include, flags, effectcompiler, parseerrors);
6132 HeapFree(GetProcessHeap(), 0, srcfileW);
6134 return ret;
6137 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule, LPCSTR srcresource, const D3DXMACRO *defines,
6138 LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6140 HRSRC resinfo;
6142 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(srcresource));
6144 resinfo = FindResourceA(srcmodule, srcresource, (LPCSTR) RT_RCDATA);
6146 if (resinfo)
6148 LPVOID buffer;
6149 HRESULT ret;
6150 DWORD size;
6152 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6154 if (FAILED(ret))
6155 return D3DXERR_INVALIDDATA;
6157 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6160 return D3DXERR_INVALIDDATA;
6163 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule, LPCWSTR srcresource, const D3DXMACRO *defines,
6164 LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6166 HRSRC resinfo;
6168 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(srcresource));
6170 resinfo = FindResourceW(srcmodule, srcresource, (LPCWSTR) RT_RCDATA);
6172 if (resinfo)
6174 LPVOID buffer;
6175 HRESULT ret;
6176 DWORD size;
6178 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6180 if (FAILED(ret))
6181 return D3DXERR_INVALIDDATA;
6183 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6186 return D3DXERR_INVALIDDATA;