d3dx9: Identify D3DTSS_CONSTANT and FVF states.
[wine.git] / dlls / d3dx9_36 / effect.c
blob72d44e70c865d4d9f4915ca83c21ef5754034cb1
1 /*
2 * Copyright 2010 Christian Costa
3 * Copyright 2011 Rico Schüller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
22 #define NONAMELESSUNION
23 #include "wine/debug.h"
24 #include "wine/unicode.h"
26 #include "windef.h"
27 #include "wingdi.h"
28 #include "d3dx9_36_private.h"
30 /* Constants for special INT/FLOAT conversation */
31 #define INT_FLOAT_MULTI 255.0f
32 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
34 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
36 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl;
37 static const struct ID3DXBaseEffectVtbl ID3DXBaseEffect_Vtbl;
38 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl;
40 enum STATE_CLASS
42 SC_LIGHTENABLE,
43 SC_FVF,
44 SC_LIGHT,
45 SC_MATERIAL,
46 SC_NPATCHMODE,
47 SC_PIXELSHADER,
48 SC_RENDERSTATE,
49 SC_SETSAMPLER,
50 SC_SAMPLERSTATE,
51 SC_TEXTURE,
52 SC_TEXTURESTAGE,
53 SC_TRANSFORM,
54 SC_VERTEXSHADER,
55 SC_SHADERCONST,
56 SC_UNKNOWN,
59 enum MATERIAL_TYPE
61 MT_DIFFUSE,
62 MT_AMBIENT,
63 MT_SPECULAR,
64 MT_EMISSIVE,
65 MT_POWER,
68 enum LIGHT_TYPE
70 LT_TYPE,
71 LT_DIFFUSE,
72 LT_SPECULAR,
73 LT_AMBIENT,
74 LT_POSITION,
75 LT_DIRECTION,
76 LT_RANGE,
77 LT_FALLOFF,
78 LT_ATTENUATION0,
79 LT_ATTENUATION1,
80 LT_ATTENUATION2,
81 LT_THETA,
82 LT_PHI,
85 enum SHADER_CONSTANT_TYPE
87 SCT_VSFLOAT,
88 SCT_VSBOOL,
89 SCT_VSINT,
90 SCT_PSFLOAT,
91 SCT_PSBOOL,
92 SCT_PSINT,
95 enum STATE_TYPE
97 ST_CONSTANT,
98 ST_PARAMETER,
99 ST_FXLC,
102 struct d3dx_parameter
104 char *name;
105 char *semantic;
106 void *data;
107 D3DXPARAMETER_CLASS class;
108 D3DXPARAMETER_TYPE type;
109 UINT rows;
110 UINT columns;
111 UINT element_count;
112 UINT annotation_count;
113 UINT member_count;
114 DWORD flags;
115 UINT bytes;
117 D3DXHANDLE *annotation_handles;
118 D3DXHANDLE *member_handles;
121 struct d3dx_state
123 UINT operation;
124 UINT index;
125 enum STATE_TYPE type;
126 D3DXHANDLE parameter;
129 struct d3dx_sampler
131 UINT state_count;
132 struct d3dx_state *states;
135 struct d3dx_pass
137 char *name;
138 UINT state_count;
139 UINT annotation_count;
141 struct d3dx_state *states;
142 D3DXHANDLE *annotation_handles;
145 struct d3dx_technique
147 char *name;
148 UINT pass_count;
149 UINT annotation_count;
151 D3DXHANDLE *annotation_handles;
152 D3DXHANDLE *pass_handles;
155 struct ID3DXBaseEffectImpl
157 ID3DXBaseEffect ID3DXBaseEffect_iface;
158 LONG ref;
160 struct ID3DXEffectImpl *effect;
162 UINT parameter_count;
163 UINT technique_count;
165 D3DXHANDLE *parameter_handles;
166 D3DXHANDLE *technique_handles;
169 struct ID3DXEffectImpl
171 ID3DXEffect ID3DXEffect_iface;
172 LONG ref;
174 LPD3DXEFFECTSTATEMANAGER manager;
175 LPDIRECT3DDEVICE9 device;
176 LPD3DXEFFECTPOOL pool;
177 D3DXHANDLE active_technique;
178 D3DXHANDLE active_pass;
180 ID3DXBaseEffect *base_effect;
183 struct ID3DXEffectCompilerImpl
185 ID3DXEffectCompiler ID3DXEffectCompiler_iface;
186 LONG ref;
188 ID3DXBaseEffect *base_effect;
191 static struct d3dx_parameter *get_parameter_by_name(struct ID3DXBaseEffectImpl *base,
192 struct d3dx_parameter *parameter, LPCSTR name);
193 static struct d3dx_parameter *get_annotation_by_name(UINT handlecount, D3DXHANDLE *handles, LPCSTR name);
194 static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects);
195 static void free_parameter_state(D3DXHANDLE handle, BOOL element, BOOL child, enum STATE_TYPE st);
197 static const struct
199 enum STATE_CLASS class;
200 UINT op;
201 LPCSTR name;
203 state_table[] =
205 /* Render sates */
206 {SC_RENDERSTATE, D3DRS_ZENABLE, "D3DRS_ZENABLE"}, /* 0x0 */
207 {SC_RENDERSTATE, D3DRS_FILLMODE, "D3DRS_FILLMODE"},
208 {SC_RENDERSTATE, D3DRS_SHADEMODE, "D3DRS_SHADEMODE"},
209 {SC_RENDERSTATE, D3DRS_ZWRITEENABLE, "D3DRS_ZWRITEENABLE"},
210 {SC_RENDERSTATE, D3DRS_ALPHATESTENABLE, "D3DRS_ALPHATESTENABLE"},
211 {SC_RENDERSTATE, D3DRS_LASTPIXEL, "D3DRS_LASTPIXEL"},
212 {SC_RENDERSTATE, D3DRS_SRCBLEND, "D3DRS_SRCBLEND"},
213 {SC_RENDERSTATE, D3DRS_DESTBLEND, "D3DRS_DESTBLEND"},
214 {SC_RENDERSTATE, D3DRS_CULLMODE, "D3DRS_CULLMODE"},
215 {SC_RENDERSTATE, D3DRS_ZFUNC, "D3DRS_ZFUNC"},
216 {SC_RENDERSTATE, D3DRS_ALPHAREF, "D3DRS_ALPHAREF"},
217 {SC_RENDERSTATE, D3DRS_ALPHAFUNC, "D3DRS_ALPHAFUNC"},
218 {SC_RENDERSTATE, D3DRS_DITHERENABLE, "D3DRS_DITHERENABLE"},
219 {SC_RENDERSTATE, D3DRS_ALPHABLENDENABLE, "D3DRS_ALPHABLENDENABLE"},
220 {SC_RENDERSTATE, D3DRS_FOGENABLE, "D3DRS_FOGENABLE"},
221 {SC_RENDERSTATE, D3DRS_SPECULARENABLE, "D3DRS_SPECULARENABLE"},
222 {SC_RENDERSTATE, D3DRS_FOGCOLOR, "D3DRS_FOGCOLOR"}, /* 0x10 */
223 {SC_RENDERSTATE, D3DRS_FOGTABLEMODE, "D3DRS_FOGTABLEMODE"},
224 {SC_RENDERSTATE, D3DRS_FOGSTART, "D3DRS_FOGSTART"},
225 {SC_RENDERSTATE, D3DRS_FOGEND, "D3DRS_FOGEND"},
226 {SC_RENDERSTATE, D3DRS_FOGDENSITY, "D3DRS_FOGDENSITY"},
227 {SC_RENDERSTATE, D3DRS_RANGEFOGENABLE, "D3DRS_RANGEFOGENABLE"},
228 {SC_RENDERSTATE, D3DRS_STENCILENABLE, "D3DRS_STENCILENABLE"},
229 {SC_RENDERSTATE, D3DRS_STENCILFAIL, "D3DRS_STENCILFAIL"},
230 {SC_RENDERSTATE, D3DRS_STENCILZFAIL, "D3DRS_STENCILZFAIL"},
231 {SC_RENDERSTATE, D3DRS_STENCILPASS, "D3DRS_STENCILPASS"},
232 {SC_RENDERSTATE, D3DRS_STENCILFUNC, "D3DRS_STENCILFUNC"},
233 {SC_RENDERSTATE, D3DRS_STENCILREF, "D3DRS_STENCILREF"},
234 {SC_RENDERSTATE, D3DRS_STENCILMASK, "D3DRS_STENCILMASK"},
235 {SC_RENDERSTATE, D3DRS_STENCILWRITEMASK, "D3DRS_STENCILWRITEMASK"},
236 {SC_RENDERSTATE, D3DRS_TEXTUREFACTOR, "D3DRS_TEXTUREFACTOR"},
237 {SC_RENDERSTATE, D3DRS_WRAP0, "D3DRS_WRAP0"},
238 {SC_RENDERSTATE, D3DRS_WRAP1, "D3DRS_WRAP1"}, /* 0x20 */
239 {SC_RENDERSTATE, D3DRS_WRAP2, "D3DRS_WRAP2"},
240 {SC_RENDERSTATE, D3DRS_WRAP3, "D3DRS_WRAP3"},
241 {SC_RENDERSTATE, D3DRS_WRAP4, "D3DRS_WRAP4"},
242 {SC_RENDERSTATE, D3DRS_WRAP5, "D3DRS_WRAP5"},
243 {SC_RENDERSTATE, D3DRS_WRAP6, "D3DRS_WRAP6"},
244 {SC_RENDERSTATE, D3DRS_WRAP7, "D3DRS_WRAP7"},
245 {SC_RENDERSTATE, D3DRS_WRAP8, "D3DRS_WRAP8"},
246 {SC_RENDERSTATE, D3DRS_WRAP9, "D3DRS_WRAP9"},
247 {SC_RENDERSTATE, D3DRS_WRAP10, "D3DRS_WRAP10"},
248 {SC_RENDERSTATE, D3DRS_WRAP11, "D3DRS_WRAP11"},
249 {SC_RENDERSTATE, D3DRS_WRAP12, "D3DRS_WRAP12"},
250 {SC_RENDERSTATE, D3DRS_WRAP13, "D3DRS_WRAP13"},
251 {SC_RENDERSTATE, D3DRS_WRAP14, "D3DRS_WRAP14"},
252 {SC_RENDERSTATE, D3DRS_WRAP15, "D3DRS_WRAP15"},
253 {SC_RENDERSTATE, D3DRS_CLIPPING, "D3DRS_CLIPPING"},
254 {SC_RENDERSTATE, D3DRS_LIGHTING, "D3DRS_LIGHTING"}, /* 0x30 */
255 {SC_RENDERSTATE, D3DRS_AMBIENT, "D3DRS_AMBIENT"},
256 {SC_RENDERSTATE, D3DRS_FOGVERTEXMODE, "D3DRS_FOGVERTEXMODE"},
257 {SC_RENDERSTATE, D3DRS_COLORVERTEX, "D3DRS_COLORVERTEX"},
258 {SC_RENDERSTATE, D3DRS_LOCALVIEWER, "D3DRS_LOCALVIEWER"},
259 {SC_RENDERSTATE, D3DRS_NORMALIZENORMALS, "D3DRS_NORMALIZENORMALS"},
260 {SC_RENDERSTATE, D3DRS_DIFFUSEMATERIALSOURCE, "D3DRS_DIFFUSEMATERIALSOURCE"},
261 {SC_RENDERSTATE, D3DRS_SPECULARMATERIALSOURCE, "D3DRS_SPECULARMATERIALSOURCE"},
262 {SC_RENDERSTATE, D3DRS_AMBIENTMATERIALSOURCE, "D3DRS_AMBIENTMATERIALSOURCE"},
263 {SC_RENDERSTATE, D3DRS_EMISSIVEMATERIALSOURCE, "D3DRS_EMISSIVEMATERIALSOURCE"},
264 {SC_RENDERSTATE, D3DRS_VERTEXBLEND, "D3DRS_VERTEXBLEND"},
265 {SC_RENDERSTATE, D3DRS_CLIPPLANEENABLE, "D3DRS_CLIPPLANEENABLE"},
266 {SC_RENDERSTATE, D3DRS_POINTSIZE, "D3DRS_POINTSIZE"},
267 {SC_RENDERSTATE, D3DRS_POINTSIZE_MIN, "D3DRS_POINTSIZE_MIN"},
268 {SC_RENDERSTATE, D3DRS_POINTSIZE_MAX, "D3DRS_POINTSIZE_MAX"},
269 {SC_RENDERSTATE, D3DRS_POINTSPRITEENABLE, "D3DRS_POINTSPRITEENABLE"},
270 {SC_RENDERSTATE, D3DRS_POINTSCALEENABLE, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
271 {SC_RENDERSTATE, D3DRS_POINTSCALE_A, "D3DRS_POINTSCALE_A"},
272 {SC_RENDERSTATE, D3DRS_POINTSCALE_B, "D3DRS_POINTSCALE_B"},
273 {SC_RENDERSTATE, D3DRS_POINTSCALE_C, "D3DRS_POINTSCALE_C"},
274 {SC_RENDERSTATE, D3DRS_MULTISAMPLEANTIALIAS, "D3DRS_MULTISAMPLEANTIALIAS"},
275 {SC_RENDERSTATE, D3DRS_MULTISAMPLEMASK, "D3DRS_MULTISAMPLEMASK"},
276 {SC_RENDERSTATE, D3DRS_PATCHEDGESTYLE, "D3DRS_PATCHEDGESTYLE"},
277 {SC_RENDERSTATE, D3DRS_DEBUGMONITORTOKEN, "D3DRS_DEBUGMONITORTOKEN"},
278 {SC_RENDERSTATE, D3DRS_INDEXEDVERTEXBLENDENABLE, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
279 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE, "D3DRS_COLORWRITEENABLE"},
280 {SC_RENDERSTATE, D3DRS_TWEENFACTOR, "D3DRS_TWEENFACTOR"},
281 {SC_RENDERSTATE, D3DRS_BLENDOP, "D3DRS_BLENDOP"},
282 {SC_RENDERSTATE, D3DRS_POSITIONDEGREE, "D3DRS_POSITIONDEGREE"},
283 {SC_RENDERSTATE, D3DRS_NORMALDEGREE, "D3DRS_NORMALDEGREE"},
284 {SC_RENDERSTATE, D3DRS_SCISSORTESTENABLE, "D3DRS_SCISSORTESTENABLE"},
285 {SC_RENDERSTATE, D3DRS_SLOPESCALEDEPTHBIAS, "D3DRS_SLOPESCALEDEPTHBIAS"},
286 {SC_RENDERSTATE, D3DRS_ANTIALIASEDLINEENABLE, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
287 {SC_RENDERSTATE, D3DRS_MINTESSELLATIONLEVEL, "D3DRS_MINTESSELLATIONLEVEL"},
288 {SC_RENDERSTATE, D3DRS_MAXTESSELLATIONLEVEL, "D3DRS_MAXTESSELLATIONLEVEL"},
289 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_X, "D3DRS_ADAPTIVETESS_X"},
290 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Y, "D3DRS_ADAPTIVETESS_Y"},
291 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Z, "D3DRS_ADAPTIVETESS_Z"},
292 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_W, "D3DRS_ADAPTIVETESS_W"},
293 {SC_RENDERSTATE, D3DRS_ENABLEADAPTIVETESSELLATION, "D3DRS_ENABLEADAPTIVETESSELLATION"},
294 {SC_RENDERSTATE, D3DRS_TWOSIDEDSTENCILMODE, "D3DRS_TWOSIDEDSTENCILMODE"},
295 {SC_RENDERSTATE, D3DRS_CCW_STENCILFAIL, "D3DRS_CCW_STENCILFAIL"},
296 {SC_RENDERSTATE, D3DRS_CCW_STENCILZFAIL, "D3DRS_CCW_STENCILZFAIL"},
297 {SC_RENDERSTATE, D3DRS_CCW_STENCILPASS, "D3DRS_CCW_STENCILPASS"},
298 {SC_RENDERSTATE, D3DRS_CCW_STENCILFUNC, "D3DRS_CCW_STENCILFUNC"},
299 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE1, "D3DRS_COLORWRITEENABLE1"},
300 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE2, "D3DRS_COLORWRITEENABLE2"},
301 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE3, "D3DRS_COLORWRITEENABLE3"},
302 {SC_RENDERSTATE, D3DRS_BLENDFACTOR, "D3DRS_BLENDFACTOR"}, /* 0x60 */
303 {SC_RENDERSTATE, D3DRS_SRGBWRITEENABLE, "D3DRS_SRGBWRITEENABLE"},
304 {SC_RENDERSTATE, D3DRS_DEPTHBIAS, "D3DRS_DEPTHBIAS"},
305 {SC_RENDERSTATE, D3DRS_SEPARATEALPHABLENDENABLE, "D3DRS_SEPARATEALPHABLENDENABLE"},
306 {SC_RENDERSTATE, D3DRS_SRCBLENDALPHA, "D3DRS_SRCBLENDALPHA"},
307 {SC_RENDERSTATE, D3DRS_DESTBLENDALPHA, "D3DRS_DESTBLENDALPHA"},
308 {SC_RENDERSTATE, D3DRS_BLENDOPALPHA, "D3DRS_BLENDOPALPHA"},
309 /* Texture stages */
310 {SC_TEXTURESTAGE, D3DTSS_COLOROP, "D3DTSS_COLOROP"},
311 {SC_TEXTURESTAGE, D3DTSS_COLORARG0, "D3DTSS_COLORARG0"},
312 {SC_TEXTURESTAGE, D3DTSS_COLORARG1, "D3DTSS_COLORARG1"},
313 {SC_TEXTURESTAGE, D3DTSS_COLORARG2, "D3DTSS_COLORARG2"},
314 {SC_TEXTURESTAGE, D3DTSS_ALPHAOP, "D3DTSS_ALPHAOP"},
315 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG0, "D3DTSS_ALPHAARG0"},
316 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG1, "D3DTSS_ALPHAARG1"},
317 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG2, "D3DTSS_ALPHAARG2"},
318 {SC_TEXTURESTAGE, D3DTSS_RESULTARG, "D3DTSS_RESULTARG"},
319 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT00, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
320 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT01, "D3DTSS_BUMPENVMAT01"},
321 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT10, "D3DTSS_BUMPENVMAT10"},
322 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT11, "D3DTSS_BUMPENVMAT11"},
323 {SC_TEXTURESTAGE, D3DTSS_TEXCOORDINDEX, "D3DTSS_TEXCOORDINDEX"},
324 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLSCALE, "D3DTSS_BUMPENVLSCALE"},
325 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLOFFSET, "D3DTSS_BUMPENVLOFFSET"},
326 {SC_TEXTURESTAGE, D3DTSS_TEXTURETRANSFORMFLAGS, "D3DTSS_TEXTURETRANSFORMFLAGS"},
327 {SC_TEXTURESTAGE, D3DTSS_CONSTANT, "D3DTSS_CONSTANT"},
328 /* NPatchMode */
329 {SC_NPATCHMODE, 0, "NPatchMode"},
330 /* FVF */
331 {SC_FVF, 0, "FVF"},
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 *get_technique_by_name(struct ID3DXBaseEffectImpl *base, LPCSTR name)
451 UINT i;
453 if (!name) return NULL;
455 for (i = 0; i < base->technique_count; ++i)
457 struct d3dx_technique *tech = get_technique_struct(base->technique_handles[i]);
459 if (!strcmp(tech->name, name))
461 TRACE("Returning technique %p\n", tech);
462 return tech;
466 return NULL;
469 static struct d3dx_technique *is_valid_technique(struct ID3DXBaseEffectImpl *base, D3DXHANDLE technique)
471 struct d3dx_technique *tech = NULL;
472 unsigned int i;
474 for (i = 0; i < base->technique_count; ++i)
476 if (base->technique_handles[i] == technique)
478 tech = get_technique_struct(technique);
479 break;
483 if (!tech) tech = get_technique_by_name(base, technique);
485 return tech;
488 static struct d3dx_pass *is_valid_pass(struct ID3DXBaseEffectImpl *base, D3DXHANDLE pass)
490 unsigned int i, k;
492 for (i = 0; i < base->technique_count; ++i)
494 struct d3dx_technique *technique = get_technique_struct(base->technique_handles[i]);
496 for (k = 0; k < technique->pass_count; ++k)
498 if (technique->pass_handles[k] == pass)
500 return get_pass_struct(pass);
505 return NULL;
508 static struct d3dx_parameter *is_valid_sub_parameter(struct d3dx_parameter *param, D3DXHANDLE parameter)
510 unsigned int i, count;
511 struct d3dx_parameter *p;
513 for (i = 0; i < param->annotation_count; ++i)
515 if (param->annotation_handles[i] == parameter)
517 return get_parameter_struct(parameter);
520 p = is_valid_sub_parameter(get_parameter_struct(param->annotation_handles[i]), parameter);
521 if (p) return p;
524 if (param->element_count) count = param->element_count;
525 else count = param->member_count;
527 for (i = 0; i < count; ++i)
529 if (param->member_handles[i] == parameter)
531 return get_parameter_struct(parameter);
534 p = is_valid_sub_parameter(get_parameter_struct(param->member_handles[i]), parameter);
535 if (p) return p;
538 return NULL;
541 static struct d3dx_parameter *is_valid_parameter(struct ID3DXBaseEffectImpl *base, D3DXHANDLE parameter)
543 unsigned int i, k, m;
544 struct d3dx_parameter *p;
546 for (i = 0; i < base->parameter_count; ++i)
548 if (base->parameter_handles[i] == parameter)
550 return get_parameter_struct(parameter);
553 p = is_valid_sub_parameter(get_parameter_struct(base->parameter_handles[i]), parameter);
554 if (p) return p;
557 for (i = 0; i < base->technique_count; ++i)
559 struct d3dx_technique *technique = get_technique_struct(base->technique_handles[i]);
561 for (k = 0; k < technique->pass_count; ++k)
563 struct d3dx_pass *pass = get_pass_struct(technique->pass_handles[k]);
565 for (m = 0; m < pass->annotation_count; ++m)
567 if (pass->annotation_handles[i] == parameter)
569 return get_parameter_struct(parameter);
572 p = is_valid_sub_parameter(get_parameter_struct(pass->annotation_handles[m]), parameter);
573 if (p) return p;
577 for (k = 0; k < technique->annotation_count; ++k)
579 if (technique->annotation_handles[k] == parameter)
581 return get_parameter_struct(parameter);
584 p = is_valid_sub_parameter(get_parameter_struct(technique->annotation_handles[k]), parameter);
585 if (p) return p;
589 return NULL;
592 static inline struct d3dx_parameter *get_valid_parameter(struct ID3DXBaseEffectImpl *base, D3DXHANDLE parameter)
594 struct d3dx_parameter *param = is_valid_parameter(base, parameter);
596 if (!param) param = get_parameter_by_name(base, NULL, parameter);
598 return param;
601 static void free_state(struct d3dx_state *state)
603 free_parameter_state(state->parameter, FALSE, FALSE, state->type);
606 static void free_sampler(struct d3dx_sampler *sampler)
608 UINT i;
610 for (i = 0; i < sampler->state_count; ++i)
612 free_state(&sampler->states[i]);
614 HeapFree(GetProcessHeap(), 0, sampler->states);
617 static void free_parameter(D3DXHANDLE handle, BOOL element, BOOL child)
619 free_parameter_state(handle, element, child, ST_CONSTANT);
622 static void free_parameter_state(D3DXHANDLE handle, BOOL element, BOOL child, enum STATE_TYPE st)
624 unsigned int i;
625 struct d3dx_parameter *param = get_parameter_struct(handle);
627 TRACE("Free parameter %p, name %s, type %s, child %s, state_type %x\n", param, param->name,
628 debug_d3dxparameter_type(param->type), child ? "yes" : "no", st);
630 if (!param)
632 return;
635 if (param->annotation_handles)
637 for (i = 0; i < param->annotation_count; ++i)
639 free_parameter(param->annotation_handles[i], FALSE, FALSE);
641 HeapFree(GetProcessHeap(), 0, param->annotation_handles);
644 if (param->member_handles)
646 unsigned int count;
648 if (param->element_count) count = param->element_count;
649 else count = param->member_count;
651 for (i = 0; i < count; ++i)
653 free_parameter(param->member_handles[i], param->element_count != 0, TRUE);
655 HeapFree(GetProcessHeap(), 0, param->member_handles);
658 if (param->class == D3DXPC_OBJECT && !param->element_count)
660 switch (param->type)
662 case D3DXPT_STRING:
663 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
664 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
665 break;
667 case D3DXPT_TEXTURE:
668 case D3DXPT_TEXTURE1D:
669 case D3DXPT_TEXTURE2D:
670 case D3DXPT_TEXTURE3D:
671 case D3DXPT_TEXTURECUBE:
672 case D3DXPT_PIXELSHADER:
673 case D3DXPT_VERTEXSHADER:
674 if (st == ST_CONSTANT)
676 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
678 else
680 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
682 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
683 break;
685 case D3DXPT_SAMPLER:
686 case D3DXPT_SAMPLER1D:
687 case D3DXPT_SAMPLER2D:
688 case D3DXPT_SAMPLER3D:
689 case D3DXPT_SAMPLERCUBE:
690 if (st == ST_CONSTANT)
692 free_sampler((struct d3dx_sampler *)param->data);
694 else
696 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
698 /* samplers have always own data, so free that */
699 HeapFree(GetProcessHeap(), 0, param->data);
700 break;
702 default:
703 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
704 break;
707 else
709 if (!child)
711 if (st != ST_CONSTANT)
713 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
715 HeapFree(GetProcessHeap(), 0, param->data);
719 /* only the parent has to release name and semantic */
720 if (!element)
722 HeapFree(GetProcessHeap(), 0, param->name);
723 HeapFree(GetProcessHeap(), 0, param->semantic);
726 HeapFree(GetProcessHeap(), 0, param);
729 static void free_pass(D3DXHANDLE handle)
731 unsigned int i;
732 struct d3dx_pass *pass = get_pass_struct(handle);
734 TRACE("Free pass %p\n", pass);
736 if (!pass)
738 return;
741 if (pass->annotation_handles)
743 for (i = 0; i < pass->annotation_count; ++i)
745 free_parameter(pass->annotation_handles[i], FALSE, FALSE);
747 HeapFree(GetProcessHeap(), 0, pass->annotation_handles);
750 if (pass->states)
752 for (i = 0; i < pass->state_count; ++i)
754 free_state(&pass->states[i]);
756 HeapFree(GetProcessHeap(), 0, pass->states);
759 HeapFree(GetProcessHeap(), 0, pass->name);
760 HeapFree(GetProcessHeap(), 0, pass);
763 static void free_technique(D3DXHANDLE handle)
765 unsigned int i;
766 struct d3dx_technique *technique = get_technique_struct(handle);
768 TRACE("Free technique %p\n", technique);
770 if (!technique)
772 return;
775 if (technique->annotation_handles)
777 for (i = 0; i < technique->annotation_count; ++i)
779 free_parameter(technique->annotation_handles[i], FALSE, FALSE);
781 HeapFree(GetProcessHeap(), 0, technique->annotation_handles);
784 if (technique->pass_handles)
786 for (i = 0; i < technique->pass_count; ++i)
788 free_pass(technique->pass_handles[i]);
790 HeapFree(GetProcessHeap(), 0, technique->pass_handles);
793 HeapFree(GetProcessHeap(), 0, technique->name);
794 HeapFree(GetProcessHeap(), 0, technique);
797 static void free_base_effect(struct ID3DXBaseEffectImpl *base)
799 unsigned int i;
801 TRACE("Free base effect %p\n", base);
803 if (base->parameter_handles)
805 for (i = 0; i < base->parameter_count; ++i)
807 free_parameter(base->parameter_handles[i], FALSE, FALSE);
809 HeapFree(GetProcessHeap(), 0, base->parameter_handles);
812 if (base->technique_handles)
814 for (i = 0; i < base->technique_count; ++i)
816 free_technique(base->technique_handles[i]);
818 HeapFree(GetProcessHeap(), 0, base->technique_handles);
822 static void free_effect(struct ID3DXEffectImpl *effect)
824 TRACE("Free effect %p\n", effect);
826 if (effect->base_effect)
828 effect->base_effect->lpVtbl->Release(effect->base_effect);
831 if (effect->pool)
833 effect->pool->lpVtbl->Release(effect->pool);
836 if (effect->manager)
838 IUnknown_Release(effect->manager);
841 IDirect3DDevice9_Release(effect->device);
844 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
846 TRACE("Free effect compiler %p\n", compiler);
848 if (compiler->base_effect)
850 compiler->base_effect->lpVtbl->Release(compiler->base_effect);
854 static INT get_int(D3DXPARAMETER_TYPE type, LPCVOID data)
856 INT i;
858 switch (type)
860 case D3DXPT_FLOAT:
861 i = *(FLOAT *)data;
862 break;
864 case D3DXPT_INT:
865 i = *(INT *)data;
866 break;
868 case D3DXPT_BOOL:
869 i = *(BOOL *)data;
870 break;
872 default:
873 i = 0;
874 FIXME("Unhandled type %s. This should not happen!\n", debug_d3dxparameter_type(type));
875 break;
878 return i;
881 inline static FLOAT get_float(D3DXPARAMETER_TYPE type, LPCVOID data)
883 FLOAT f;
885 switch (type)
887 case D3DXPT_FLOAT:
888 f = *(FLOAT *)data;
889 break;
891 case D3DXPT_INT:
892 f = *(INT *)data;
893 break;
895 case D3DXPT_BOOL:
896 f = *(BOOL *)data;
897 break;
899 default:
900 f = 0.0f;
901 FIXME("Unhandled type %s. This should not happen!\n", debug_d3dxparameter_type(type));
902 break;
905 return f;
908 static inline BOOL get_bool(LPCVOID data)
910 return (*(DWORD *)data) ? TRUE : FALSE;
913 static void set_number(LPVOID outdata, D3DXPARAMETER_TYPE outtype, LPCVOID indata, D3DXPARAMETER_TYPE intype)
915 TRACE("Changing from type %i to type %i\n", intype, outtype);
917 switch (outtype)
919 case D3DXPT_FLOAT:
920 *(FLOAT *)outdata = get_float(intype, indata);
921 break;
923 case D3DXPT_BOOL:
924 *(BOOL *)outdata = get_bool(indata);
925 break;
927 case D3DXPT_INT:
928 *(INT *)outdata = get_int(intype, indata);
929 break;
931 default:
932 FIXME("Error converting to type %i\n", outtype);
933 *(INT *)outdata = 0;
934 break;
938 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
940 UINT i;
942 for (i = 0; i < 4; ++i)
944 ((FLOAT *)vector)[i] = i < param->columns ? get_float(param->type, (DWORD *)param->data + i) : 0.0f;
948 static void set_vector(struct d3dx_parameter *param, CONST D3DXVECTOR4 *vector)
950 UINT i;
952 for (i = 0; i < param->columns; ++i)
954 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
958 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix)
960 UINT i, k;
962 for (i = 0; i < 4; ++i)
964 for (k = 0; k < 4; ++k)
966 if ((i < param->rows) && (k < param->columns))
967 matrix->u.m[i][k] = get_float(param->type, (FLOAT *)param->data + i * param->columns + k);
968 else
969 matrix->u.m[i][k] = 0.0f;
974 static void set_matrix(struct d3dx_parameter *param, CONST D3DXMATRIX *matrix)
976 UINT i, k;
978 for (i = 0; i < 4; ++i)
980 for (k = 0; k < 4; ++k)
982 if ((i < param->rows) && (k < param->columns))
983 set_number((FLOAT *)param->data + i * param->columns + k, param->type, &matrix->u.m[i][k], D3DXPT_FLOAT);
988 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, LPCSTR name)
990 UINT element;
991 struct d3dx_parameter *temp_parameter;
992 LPCSTR part;
994 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
996 if (!name || !*name) return NULL;
998 element = atoi(name);
999 part = strchr(name, ']') + 1;
1001 /* check for empty [] && element range */
1002 if ((part - name) > 1 && parameter->element_count > element)
1004 temp_parameter = get_parameter_struct(parameter->member_handles[element]);
1006 switch (*part++)
1008 case '.':
1009 return get_parameter_by_name(NULL, temp_parameter, part);
1011 case '@':
1012 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotation_handles, part);
1014 case '\0':
1015 TRACE("Returning parameter %p\n", temp_parameter);
1016 return temp_parameter;
1018 default:
1019 FIXME("Unhandled case \"%c\"\n", *--part);
1020 break;
1024 TRACE("Parameter not found\n");
1025 return NULL;
1028 static struct d3dx_parameter *get_annotation_by_name(UINT handlecount, D3DXHANDLE *handles, LPCSTR name)
1030 UINT i, length;
1031 struct d3dx_parameter *temp_parameter;
1032 LPCSTR part;
1034 TRACE("handlecount %u, handles %p, name %s\n", handlecount, handles, debugstr_a(name));
1036 if (!name || !*name) return NULL;
1038 length = strcspn( name, "[.@" );
1039 part = name + length;
1041 for (i = 0; i < handlecount; ++i)
1043 temp_parameter = get_parameter_struct(handles[i]);
1045 if (!strcmp(temp_parameter->name, name))
1047 TRACE("Returning parameter %p\n", temp_parameter);
1048 return temp_parameter;
1050 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
1052 switch (*part++)
1054 case '.':
1055 return get_parameter_by_name(NULL, temp_parameter, part);
1057 case '[':
1058 return get_parameter_element_by_name(temp_parameter, part);
1060 default:
1061 FIXME("Unhandled case \"%c\"\n", *--part);
1062 break;
1067 TRACE("Parameter not found\n");
1068 return NULL;
1071 static struct d3dx_parameter *get_parameter_by_name(struct ID3DXBaseEffectImpl *base,
1072 struct d3dx_parameter *parameter, LPCSTR name)
1074 UINT i, count, length;
1075 struct d3dx_parameter *temp_parameter;
1076 D3DXHANDLE *handles;
1077 LPCSTR part;
1079 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
1081 if (!name || !*name) return NULL;
1083 if (!parameter)
1085 count = base->parameter_count;
1086 handles = base->parameter_handles;
1088 else
1090 count = parameter->member_count;
1091 handles = parameter->member_handles;
1094 length = strcspn( name, "[.@" );
1095 part = name + length;
1097 for (i = 0; i < count; i++)
1099 temp_parameter = get_parameter_struct(handles[i]);
1101 if (!strcmp(temp_parameter->name, name))
1103 TRACE("Returning parameter %p\n", temp_parameter);
1104 return temp_parameter;
1106 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
1108 switch (*part++)
1110 case '.':
1111 return get_parameter_by_name(NULL, temp_parameter, part);
1113 case '@':
1114 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotation_handles, part);
1116 case '[':
1117 return get_parameter_element_by_name(temp_parameter, part);
1119 default:
1120 FIXME("Unhandled case \"%c\"\n", *--part);
1121 break;
1126 TRACE("Parameter not found\n");
1127 return NULL;
1130 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
1132 return (0xfeff0000 | ((major) << 8) | (minor));
1135 static inline struct ID3DXBaseEffectImpl *impl_from_ID3DXBaseEffect(ID3DXBaseEffect *iface)
1137 return CONTAINING_RECORD(iface, struct ID3DXBaseEffectImpl, ID3DXBaseEffect_iface);
1140 /*** IUnknown methods ***/
1141 static HRESULT WINAPI ID3DXBaseEffectImpl_QueryInterface(ID3DXBaseEffect *iface, REFIID riid, void **object)
1143 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1145 if (IsEqualGUID(riid, &IID_IUnknown) ||
1146 IsEqualGUID(riid, &IID_ID3DXBaseEffect))
1148 iface->lpVtbl->AddRef(iface);
1149 *object = iface;
1150 return S_OK;
1153 ERR("Interface %s not found\n", debugstr_guid(riid));
1155 return E_NOINTERFACE;
1158 static ULONG WINAPI ID3DXBaseEffectImpl_AddRef(ID3DXBaseEffect *iface)
1160 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1162 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
1164 return InterlockedIncrement(&This->ref);
1167 static ULONG WINAPI ID3DXBaseEffectImpl_Release(ID3DXBaseEffect *iface)
1169 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1170 ULONG ref = InterlockedDecrement(&This->ref);
1172 TRACE("iface %p: Release from %u\n", iface, ref + 1);
1174 if (!ref)
1176 free_base_effect(This);
1177 HeapFree(GetProcessHeap(), 0, This);
1180 return ref;
1183 /*** ID3DXBaseEffect methods ***/
1184 static HRESULT WINAPI ID3DXBaseEffectImpl_GetDesc(ID3DXBaseEffect *iface, D3DXEFFECT_DESC *desc)
1186 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1188 FIXME("iface %p, desc %p partial stub\n", This, desc);
1190 if (!desc)
1192 WARN("Invalid argument specified.\n");
1193 return D3DERR_INVALIDCALL;
1196 /* Todo: add creator and function count */
1197 desc->Creator = NULL;
1198 desc->Functions = 0;
1199 desc->Parameters = This->parameter_count;
1200 desc->Techniques = This->technique_count;
1202 return D3D_OK;
1205 static HRESULT WINAPI ID3DXBaseEffectImpl_GetParameterDesc(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
1207 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1208 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1210 TRACE("iface %p, parameter %p, desc %p\n", This, parameter, desc);
1212 if (!desc || !param)
1214 WARN("Invalid argument specified.\n");
1215 return D3DERR_INVALIDCALL;
1218 desc->Name = param->name;
1219 desc->Semantic = param->semantic;
1220 desc->Class = param->class;
1221 desc->Type = param->type;
1222 desc->Rows = param->rows;
1223 desc->Columns = param->columns;
1224 desc->Elements = param->element_count;
1225 desc->Annotations = param->annotation_count;
1226 desc->StructMembers = param->member_count;
1227 desc->Flags = param->flags;
1228 desc->Bytes = param->bytes;
1230 return D3D_OK;
1233 static HRESULT WINAPI ID3DXBaseEffectImpl_GetTechniqueDesc(ID3DXBaseEffect *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
1235 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1236 struct d3dx_technique *tech = technique ? is_valid_technique(This, technique) : get_technique_struct(This->technique_handles[0]);
1238 TRACE("iface %p, technique %p, desc %p\n", This, technique, desc);
1240 if (!desc || !tech)
1242 WARN("Invalid argument specified.\n");
1243 return D3DERR_INVALIDCALL;
1246 desc->Name = tech->name;
1247 desc->Passes = tech->pass_count;
1248 desc->Annotations = tech->annotation_count;
1250 return D3D_OK;
1253 static HRESULT WINAPI ID3DXBaseEffectImpl_GetPassDesc(ID3DXBaseEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
1255 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1256 struct d3dx_pass *p = is_valid_pass(This, pass);
1258 TRACE("iface %p, pass %p, desc %p\n", This, pass, desc);
1260 if (!desc || !p)
1262 WARN("Invalid argument specified.\n");
1263 return D3DERR_INVALIDCALL;
1266 desc->Name = p->name;
1267 desc->Annotations = p->annotation_count;
1269 FIXME("Pixel shader and vertex shader are not supported, yet.\n");
1270 desc->pVertexShaderFunction = NULL;
1271 desc->pPixelShaderFunction = NULL;
1273 return D3D_OK;
1276 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFunctionDesc(ID3DXBaseEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1278 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1280 FIXME("iface %p, shader %p, desc %p stub\n", This, shader, desc);
1282 return E_NOTIMPL;
1285 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameter(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT index)
1287 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1288 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1290 TRACE("iface %p, parameter %p, index %u\n", This, parameter, index);
1292 if (!parameter)
1294 if (index < This->parameter_count)
1296 TRACE("Returning parameter %p\n", This->parameter_handles[index]);
1297 return This->parameter_handles[index];
1300 else
1302 if (param && !param->element_count && index < param->member_count)
1304 TRACE("Returning parameter %p\n", param->member_handles[index]);
1305 return param->member_handles[index];
1309 WARN("Invalid argument specified.\n");
1311 return NULL;
1314 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterByName(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR name)
1316 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1317 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1318 D3DXHANDLE handle;
1320 TRACE("iface %p, parameter %p, name %s\n", This, parameter, debugstr_a(name));
1322 if (!name)
1324 handle = get_parameter_handle(param);
1325 TRACE("Returning parameter %p\n", handle);
1326 return handle;
1329 handle = get_parameter_handle(get_parameter_by_name(This, param, name));
1330 TRACE("Returning parameter %p\n", handle);
1332 return handle;
1335 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterBySemantic(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR semantic)
1337 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1338 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1339 struct d3dx_parameter *temp_param;
1340 UINT i;
1342 TRACE("iface %p, parameter %p, semantic %s\n", This, parameter, debugstr_a(semantic));
1344 if (!parameter)
1346 for (i = 0; i < This->parameter_count; ++i)
1348 temp_param = get_parameter_struct(This->parameter_handles[i]);
1350 if (!temp_param->semantic)
1352 if (!semantic)
1354 TRACE("Returning parameter %p\n", This->parameter_handles[i]);
1355 return This->parameter_handles[i];
1357 continue;
1360 if (!strcasecmp(temp_param->semantic, semantic))
1362 TRACE("Returning parameter %p\n", This->parameter_handles[i]);
1363 return This->parameter_handles[i];
1367 else if (param)
1369 for (i = 0; i < param->member_count; ++i)
1371 temp_param = get_parameter_struct(param->member_handles[i]);
1373 if (!temp_param->semantic)
1375 if (!semantic)
1377 TRACE("Returning parameter %p\n", param->member_handles[i]);
1378 return param->member_handles[i];
1380 continue;
1383 if (!strcasecmp(temp_param->semantic, semantic))
1385 TRACE("Returning parameter %p\n", param->member_handles[i]);
1386 return param->member_handles[i];
1391 WARN("Invalid argument specified\n");
1393 return NULL;
1396 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterElement(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT index)
1398 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1399 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1401 TRACE("iface %p, parameter %p, index %u\n", This, parameter, index);
1403 if (!param)
1405 if (index < This->parameter_count)
1407 TRACE("Returning parameter %p\n", This->parameter_handles[index]);
1408 return This->parameter_handles[index];
1411 else
1413 if (index < param->element_count)
1415 TRACE("Returning parameter %p\n", param->member_handles[index]);
1416 return param->member_handles[index];
1420 WARN("Invalid argument specified\n");
1422 return NULL;
1425 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetTechnique(ID3DXBaseEffect *iface, UINT index)
1427 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1429 TRACE("iface %p, index %u\n", This, index);
1431 if (index >= This->technique_count)
1433 WARN("Invalid argument specified.\n");
1434 return NULL;
1437 TRACE("Returning technique %p\n", This->technique_handles[index]);
1439 return This->technique_handles[index];
1442 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetTechniqueByName(ID3DXBaseEffect *iface, LPCSTR name)
1444 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1445 struct d3dx_technique *tech = get_technique_by_name(This, name);
1447 TRACE("iface %p, name %s stub\n", This, debugstr_a(name));
1449 if (tech)
1451 D3DXHANDLE t = get_technique_handle(tech);
1452 TRACE("Returning technique %p\n", t);
1453 return t;
1456 WARN("Invalid argument specified.\n");
1458 return NULL;
1461 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetPass(ID3DXBaseEffect *iface, D3DXHANDLE technique, UINT index)
1463 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1464 struct d3dx_technique *tech = is_valid_technique(This, technique);
1466 TRACE("iface %p, technique %p, index %u\n", This, technique, index);
1468 if (tech && index < tech->pass_count)
1470 TRACE("Returning pass %p\n", tech->pass_handles[index]);
1471 return tech->pass_handles[index];
1474 WARN("Invalid argument specified.\n");
1476 return NULL;
1479 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetPassByName(ID3DXBaseEffect *iface, D3DXHANDLE technique, LPCSTR name)
1481 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1482 struct d3dx_technique *tech = is_valid_technique(This, technique);
1484 TRACE("iface %p, technique %p, name %s\n", This, technique, debugstr_a(name));
1486 if (tech && name)
1488 unsigned int i;
1490 for (i = 0; i < tech->pass_count; ++i)
1492 struct d3dx_pass *pass = get_pass_struct(tech->pass_handles[i]);
1494 if (!strcmp(pass->name, name))
1496 TRACE("Returning pass %p\n", tech->pass_handles[i]);
1497 return tech->pass_handles[i];
1502 WARN("Invalid argument specified.\n");
1504 return NULL;
1507 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetFunction(ID3DXBaseEffect *iface, UINT index)
1509 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1511 FIXME("iface %p, index %u stub\n", This, index);
1513 return NULL;
1516 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetFunctionByName(ID3DXBaseEffect *iface, LPCSTR name)
1518 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1520 FIXME("iface %p, name %s stub\n", This, debugstr_a(name));
1522 return NULL;
1525 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetAnnotation(ID3DXBaseEffect *iface, D3DXHANDLE object, UINT index)
1527 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1528 struct d3dx_parameter *param = get_valid_parameter(This, object);
1529 struct d3dx_pass *pass = is_valid_pass(This, object);
1530 struct d3dx_technique *technique = is_valid_technique(This, object);
1531 UINT annotation_count = 0;
1532 D3DXHANDLE *annotation_handles = NULL;
1534 TRACE("iface %p, object %p, index %u\n", This, object, index);
1536 if (pass)
1538 annotation_count = pass->annotation_count;
1539 annotation_handles = pass->annotation_handles;
1541 else if (technique)
1543 annotation_count = technique->annotation_count;
1544 annotation_handles = technique->annotation_handles;
1546 else if (param)
1548 annotation_count = param->annotation_count;
1549 annotation_handles = param->annotation_handles;
1551 else
1553 FIXME("Functions are not handled, yet!\n");
1556 if (index < annotation_count)
1558 TRACE("Returning parameter %p\n", annotation_handles[index]);
1559 return annotation_handles[index];
1562 WARN("Invalid argument specified\n");
1564 return NULL;
1567 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetAnnotationByName(ID3DXBaseEffect *iface, D3DXHANDLE object, LPCSTR name)
1569 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1570 struct d3dx_parameter *param = get_valid_parameter(This, object);
1571 struct d3dx_pass *pass = is_valid_pass(This, object);
1572 struct d3dx_technique *technique = is_valid_technique(This, object);
1573 struct d3dx_parameter *anno = NULL;
1574 UINT annotation_count = 0;
1575 D3DXHANDLE *annotation_handles = NULL;
1577 TRACE("iface %p, object %p, name %s\n", This, object, debugstr_a(name));
1579 if (!name)
1581 WARN("Invalid argument specified\n");
1582 return NULL;
1585 if (pass)
1587 annotation_count = pass->annotation_count;
1588 annotation_handles = pass->annotation_handles;
1590 else if (technique)
1592 annotation_count = technique->annotation_count;
1593 annotation_handles = technique->annotation_handles;
1595 else if (param)
1597 annotation_count = param->annotation_count;
1598 annotation_handles = param->annotation_handles;
1600 else
1602 FIXME("Functions are not handled, yet!\n");
1605 anno = get_annotation_by_name(annotation_count, annotation_handles, name);
1606 if (anno)
1608 TRACE("Returning parameter %p\n", anno);
1609 return get_parameter_handle(anno);
1612 WARN("Invalid argument specified\n");
1614 return NULL;
1617 static HRESULT WINAPI ID3DXBaseEffectImpl_SetValue(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
1619 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1620 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1622 TRACE("iface %p, parameter %p, data %p, bytes %u\n", This, parameter, data, bytes);
1624 if (!param)
1626 WARN("Invalid parameter %p specified\n", parameter);
1627 return D3DERR_INVALIDCALL;
1630 /* samplers don't touch data */
1631 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1632 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1633 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1635 TRACE("Sampler: returning E_FAIL\n");
1636 return E_FAIL;
1639 if (data && param->bytes <= bytes)
1641 switch (param->type)
1643 case D3DXPT_VOID:
1644 case D3DXPT_BOOL:
1645 case D3DXPT_INT:
1646 case D3DXPT_FLOAT:
1647 TRACE("Copy %u bytes\n", param->bytes);
1648 memcpy(param->data, data, param->bytes);
1649 break;
1651 default:
1652 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1653 break;
1656 return D3D_OK;
1659 WARN("Invalid argument specified\n");
1661 return D3DERR_INVALIDCALL;
1664 static HRESULT WINAPI ID3DXBaseEffectImpl_GetValue(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
1666 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1667 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1669 TRACE("iface %p, parameter %p, data %p, bytes %u\n", This, parameter, data, bytes);
1671 if (!param)
1673 WARN("Invalid parameter %p specified\n", parameter);
1674 return D3DERR_INVALIDCALL;
1677 /* samplers don't touch data */
1678 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1679 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1680 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1682 TRACE("Sampler: returning E_FAIL\n");
1683 return E_FAIL;
1686 if (data && param->bytes <= bytes)
1688 TRACE("Type %s\n", debug_d3dxparameter_type(param->type));
1690 switch (param->type)
1692 case D3DXPT_VOID:
1693 case D3DXPT_BOOL:
1694 case D3DXPT_INT:
1695 case D3DXPT_FLOAT:
1696 case D3DXPT_STRING:
1697 break;
1699 case D3DXPT_VERTEXSHADER:
1700 case D3DXPT_PIXELSHADER:
1701 case D3DXPT_TEXTURE:
1702 case D3DXPT_TEXTURE1D:
1703 case D3DXPT_TEXTURE2D:
1704 case D3DXPT_TEXTURE3D:
1705 case D3DXPT_TEXTURECUBE:
1707 UINT i;
1709 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1711 IUnknown *unk = ((IUnknown **)param->data)[i];
1712 if (unk) IUnknown_AddRef(unk);
1714 break;
1717 default:
1718 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1719 break;
1722 TRACE("Copy %u bytes\n", param->bytes);
1723 memcpy(data, param->data, param->bytes);
1724 return D3D_OK;
1727 WARN("Invalid argument specified\n");
1729 return D3DERR_INVALIDCALL;
1732 static HRESULT WINAPI ID3DXBaseEffectImpl_SetBool(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL b)
1734 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1735 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1737 TRACE("iface %p, parameter %p, b %s\n", This, parameter, b ? "TRUE" : "FALSE");
1739 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1741 /* crop input */
1742 b = b ? TRUE : FALSE;
1743 set_number(param->data, param->type, &b, D3DXPT_BOOL);
1744 return D3D_OK;
1747 WARN("Invalid argument specified\n");
1749 return D3DERR_INVALIDCALL;
1752 static HRESULT WINAPI ID3DXBaseEffectImpl_GetBool(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL *b)
1754 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1755 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1757 TRACE("iface %p, parameter %p, b %p\n", This, parameter, b);
1759 if (b && param && !param->element_count && param->rows == 1 && param->columns == 1)
1761 *b = get_bool(param->data);
1762 TRACE("Returning %s\n", *b ? "TRUE" : "FALSE");
1763 return D3D_OK;
1766 WARN("Invalid argument specified\n");
1768 return D3DERR_INVALIDCALL;
1771 static HRESULT WINAPI ID3DXBaseEffectImpl_SetBoolArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
1773 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1774 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1776 TRACE("iface %p, parameter %p, b %p, count %u\n", This, parameter, b, count);
1778 if (param)
1780 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1782 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1784 switch (param->class)
1786 case D3DXPC_SCALAR:
1787 case D3DXPC_VECTOR:
1788 case D3DXPC_MATRIX_ROWS:
1789 for (i = 0; i < size; ++i)
1791 set_number((DWORD *)param->data + i, param->type, &b[i], D3DXPT_BOOL);
1793 return D3D_OK;
1795 case D3DXPC_OBJECT:
1796 case D3DXPC_STRUCT:
1797 break;
1799 default:
1800 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1801 break;
1805 WARN("Invalid argument specified\n");
1807 return D3DERR_INVALIDCALL;
1810 static HRESULT WINAPI ID3DXBaseEffectImpl_GetBoolArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
1812 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1813 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1815 TRACE("iface %p, parameter %p, b %p, count %u\n", This, parameter, b, count);
1817 if (b && param && (param->class == D3DXPC_SCALAR
1818 || param->class == D3DXPC_VECTOR
1819 || param->class == D3DXPC_MATRIX_ROWS
1820 || param->class == D3DXPC_MATRIX_COLUMNS))
1822 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1824 for (i = 0; i < size; ++i)
1826 b[i] = get_bool((DWORD *)param->data + i);
1828 return D3D_OK;
1831 WARN("Invalid argument specified\n");
1833 return D3DERR_INVALIDCALL;
1836 static HRESULT WINAPI ID3DXBaseEffectImpl_SetInt(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT n)
1838 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1839 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1841 TRACE("iface %p, parameter %p, n %i\n", This, parameter, n);
1843 if (param && !param->element_count)
1845 if (param->rows == 1 && param->columns == 1)
1847 set_number(param->data, param->type, &n, D3DXPT_INT);
1848 return D3D_OK;
1852 * Split the value, if parameter is a vector with dimension 3 or 4.
1854 if (param->type == D3DXPT_FLOAT &&
1855 ((param->class == D3DXPC_VECTOR && param->columns != 2) ||
1856 (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1858 TRACE("Vector fixup\n");
1860 *(FLOAT *)param->data = ((n & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1861 ((FLOAT *)param->data)[1] = ((n & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1862 ((FLOAT *)param->data)[2] = (n & 0xff) * INT_FLOAT_MULTI_INVERSE;
1863 if (param->rows * param->columns > 3)
1865 ((FLOAT *)param->data)[3] = ((n & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1867 return D3D_OK;
1871 WARN("Invalid argument specified\n");
1873 return D3DERR_INVALIDCALL;
1876 static HRESULT WINAPI ID3DXBaseEffectImpl_GetInt(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT *n)
1878 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1879 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1881 TRACE("iface %p, parameter %p, n %p\n", This, parameter, n);
1883 if (n && param && !param->element_count)
1885 if (param->columns == 1 && param->rows == 1)
1887 *n = get_int(param->type, param->data);
1888 TRACE("Returning %i\n", *n);
1889 return D3D_OK;
1892 if (param->type == D3DXPT_FLOAT &&
1893 ((param->class == D3DXPC_VECTOR && param->columns != 2)
1894 || (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1896 TRACE("Vector fixup\n");
1898 /* all components (3,4) are clamped (0,255) and put in the INT */
1899 *n = (INT)(min(max(0.0f, *((FLOAT *)param->data + 2)), 1.0f) * INT_FLOAT_MULTI);
1900 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 1)), 1.0f) * INT_FLOAT_MULTI)) << 8;
1901 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 0)), 1.0f) * INT_FLOAT_MULTI)) << 16;
1902 if (param->columns * param->rows > 3)
1904 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 3)), 1.0f) * INT_FLOAT_MULTI)) << 24;
1907 TRACE("Returning %i\n", *n);
1908 return D3D_OK;
1912 WARN("Invalid argument specified\n");
1914 return D3DERR_INVALIDCALL;
1917 static HRESULT WINAPI ID3DXBaseEffectImpl_SetIntArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
1919 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1920 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1922 TRACE("iface %p, parameter %p, n %p, count %u\n", This, parameter, n, count);
1924 if (param)
1926 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1928 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1930 switch (param->class)
1932 case D3DXPC_SCALAR:
1933 case D3DXPC_VECTOR:
1934 case D3DXPC_MATRIX_ROWS:
1935 for (i = 0; i < size; ++i)
1937 set_number((DWORD *)param->data + i, param->type, &n[i], D3DXPT_INT);
1939 return D3D_OK;
1941 case D3DXPC_OBJECT:
1942 case D3DXPC_STRUCT:
1943 break;
1945 default:
1946 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1947 break;
1951 WARN("Invalid argument specified\n");
1953 return D3DERR_INVALIDCALL;
1956 static HRESULT WINAPI ID3DXBaseEffectImpl_GetIntArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT *n, UINT count)
1958 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1959 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1961 TRACE("iface %p, parameter %p, n %p, count %u\n", This, parameter, n, count);
1963 if (n && param && (param->class == D3DXPC_SCALAR
1964 || param->class == D3DXPC_VECTOR
1965 || param->class == D3DXPC_MATRIX_ROWS
1966 || param->class == D3DXPC_MATRIX_COLUMNS))
1968 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1970 for (i = 0; i < size; ++i)
1972 n[i] = get_int(param->type, (DWORD *)param->data + i);
1974 return D3D_OK;
1977 WARN("Invalid argument specified\n");
1979 return D3DERR_INVALIDCALL;
1982 static HRESULT WINAPI ID3DXBaseEffectImpl_SetFloat(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT f)
1984 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1985 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1987 TRACE("iface %p, parameter %p, f %f\n", This, parameter, f);
1989 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1991 set_number((DWORD *)param->data, param->type, &f, D3DXPT_FLOAT);
1992 return D3D_OK;
1995 WARN("Invalid argument specified\n");
1997 return D3DERR_INVALIDCALL;
2000 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFloat(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT *f)
2002 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2003 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2005 TRACE("iface %p, parameter %p, f %p\n", This, parameter, f);
2007 if (f && param && !param->element_count && param->columns == 1 && param->rows == 1)
2009 *f = get_float(param->type, (DWORD *)param->data);
2010 TRACE("Returning %f\n", *f);
2011 return D3D_OK;
2014 WARN("Invalid argument specified\n");
2016 return D3DERR_INVALIDCALL;
2019 static HRESULT WINAPI ID3DXBaseEffectImpl_SetFloatArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
2021 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2022 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2024 TRACE("iface %p, parameter %p, f %p, count %u\n", This, parameter, f, count);
2026 if (param)
2028 UINT i, size = min(count, param->bytes / sizeof(DWORD));
2030 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2032 switch (param->class)
2034 case D3DXPC_SCALAR:
2035 case D3DXPC_VECTOR:
2036 case D3DXPC_MATRIX_ROWS:
2037 for (i = 0; i < size; ++i)
2039 set_number((DWORD *)param->data + i, param->type, &f[i], D3DXPT_FLOAT);
2041 return D3D_OK;
2043 case D3DXPC_OBJECT:
2044 case D3DXPC_STRUCT:
2045 break;
2047 default:
2048 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2049 break;
2053 WARN("Invalid argument specified\n");
2055 return D3DERR_INVALIDCALL;
2058 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFloatArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
2060 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2061 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2063 TRACE("iface %p, parameter %p, f %p, count %u\n", This, parameter, f, count);
2065 if (f && param && (param->class == D3DXPC_SCALAR
2066 || param->class == D3DXPC_VECTOR
2067 || param->class == D3DXPC_MATRIX_ROWS
2068 || param->class == D3DXPC_MATRIX_COLUMNS))
2070 UINT i, size = min(count, param->bytes / sizeof(DWORD));
2072 for (i = 0; i < size; ++i)
2074 f[i] = get_float(param->type, (DWORD *)param->data + i);
2076 return D3D_OK;
2079 WARN("Invalid argument specified\n");
2081 return D3DERR_INVALIDCALL;
2084 static HRESULT WINAPI ID3DXBaseEffectImpl_SetVector(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
2086 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2087 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2089 TRACE("iface %p, parameter %p, vector %p\n", This, parameter, vector);
2091 if (param && !param->element_count)
2093 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2095 switch (param->class)
2097 case D3DXPC_SCALAR:
2098 case D3DXPC_VECTOR:
2099 if (param->type == D3DXPT_INT && param->bytes == 4)
2101 DWORD tmp;
2103 TRACE("INT fixup\n");
2104 tmp = (DWORD)(max(min(vector->z, 1.0f), 0.0f) * INT_FLOAT_MULTI);
2105 tmp += ((DWORD)(max(min(vector->y, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 8;
2106 tmp += ((DWORD)(max(min(vector->x, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 16;
2107 tmp += ((DWORD)(max(min(vector->w, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 24;
2109 *(INT *)param->data = tmp;
2110 return D3D_OK;
2112 set_vector(param, vector);
2113 return D3D_OK;
2115 case D3DXPC_MATRIX_ROWS:
2116 case D3DXPC_OBJECT:
2117 case D3DXPC_STRUCT:
2118 break;
2120 default:
2121 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2122 break;
2126 WARN("Invalid argument specified\n");
2128 return D3DERR_INVALIDCALL;
2131 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVector(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
2133 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2134 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2136 TRACE("iface %p, parameter %p, vector %p\n", This, parameter, vector);
2138 if (vector && param && !param->element_count)
2140 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2142 switch (param->class)
2144 case D3DXPC_SCALAR:
2145 case D3DXPC_VECTOR:
2146 if (param->type == D3DXPT_INT && param->bytes == 4)
2148 TRACE("INT fixup\n");
2149 vector->x = (((*(INT *)param->data) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
2150 vector->y = (((*(INT *)param->data) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
2151 vector->z = ((*(INT *)param->data) & 0xff) * INT_FLOAT_MULTI_INVERSE;
2152 vector->w = (((*(INT *)param->data) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
2153 return D3D_OK;
2155 get_vector(param, vector);
2156 return D3D_OK;
2158 case D3DXPC_MATRIX_ROWS:
2159 case D3DXPC_OBJECT:
2160 case D3DXPC_STRUCT:
2161 break;
2163 default:
2164 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2165 break;
2169 WARN("Invalid argument specified\n");
2171 return D3DERR_INVALIDCALL;
2174 static HRESULT WINAPI ID3DXBaseEffectImpl_SetVectorArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
2176 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2177 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2179 TRACE("iface %p, parameter %p, vector %p, count %u stub\n", This, parameter, vector, count);
2181 if (param && param->element_count && param->element_count >= count)
2183 UINT i;
2185 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2187 switch (param->class)
2189 case D3DXPC_VECTOR:
2190 for (i = 0; i < count; ++i)
2192 set_vector(get_parameter_struct(param->member_handles[i]), &vector[i]);
2194 return D3D_OK;
2196 case D3DXPC_SCALAR:
2197 case D3DXPC_MATRIX_ROWS:
2198 case D3DXPC_OBJECT:
2199 case D3DXPC_STRUCT:
2200 break;
2202 default:
2203 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2204 break;
2208 WARN("Invalid argument specified\n");
2210 return D3DERR_INVALIDCALL;
2213 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVectorArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
2215 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2216 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2218 TRACE("iface %p, parameter %p, vector %p, count %u\n", This, parameter, vector, count);
2220 if (!count) return D3D_OK;
2222 if (vector && param && count <= param->element_count)
2224 UINT i;
2226 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2228 switch (param->class)
2230 case D3DXPC_VECTOR:
2231 for (i = 0; i < count; ++i)
2233 get_vector(get_parameter_struct(param->member_handles[i]), &vector[i]);
2235 return D3D_OK;
2237 case D3DXPC_SCALAR:
2238 case D3DXPC_MATRIX_ROWS:
2239 case D3DXPC_OBJECT:
2240 case D3DXPC_STRUCT:
2241 break;
2243 default:
2244 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2245 break;
2249 WARN("Invalid argument specified\n");
2251 return D3DERR_INVALIDCALL;
2254 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrix(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
2256 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2257 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2259 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2261 if (param && !param->element_count)
2263 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2265 switch (param->class)
2267 case D3DXPC_MATRIX_ROWS:
2268 set_matrix(param, matrix);
2269 return D3D_OK;
2271 case D3DXPC_SCALAR:
2272 case D3DXPC_VECTOR:
2273 case D3DXPC_OBJECT:
2274 case D3DXPC_STRUCT:
2275 break;
2277 default:
2278 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2279 break;
2283 WARN("Invalid argument specified\n");
2285 return D3DERR_INVALIDCALL;
2288 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrix(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
2290 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2291 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2293 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2295 if (matrix && param && !param->element_count)
2297 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2299 switch (param->class)
2301 case D3DXPC_MATRIX_ROWS:
2302 get_matrix(param, matrix);
2303 return D3D_OK;
2305 case D3DXPC_SCALAR:
2306 case D3DXPC_VECTOR:
2307 case D3DXPC_OBJECT:
2308 case D3DXPC_STRUCT:
2309 break;
2311 default:
2312 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2313 break;
2317 WARN("Invalid argument specified\n");
2319 return D3DERR_INVALIDCALL;
2322 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
2324 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2325 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2327 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2329 if (param && param->element_count >= count)
2331 UINT i;
2333 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2335 switch (param->class)
2337 case D3DXPC_MATRIX_ROWS:
2338 for (i = 0; i < count; ++i)
2340 set_matrix(get_parameter_struct(param->member_handles[i]), &matrix[i]);
2342 return D3D_OK;
2344 case D3DXPC_SCALAR:
2345 case D3DXPC_VECTOR:
2346 case D3DXPC_OBJECT:
2347 case D3DXPC_STRUCT:
2348 break;
2350 default:
2351 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2352 break;
2356 WARN("Invalid argument specified\n");
2358 return D3DERR_INVALIDCALL;
2361 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2363 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2364 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2366 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2368 if (!count) return D3D_OK;
2370 if (matrix && param && count <= param->element_count)
2372 UINT i;
2374 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2376 switch (param->class)
2378 case D3DXPC_MATRIX_ROWS:
2379 for (i = 0; i < count; ++i)
2381 get_matrix(get_parameter_struct(param->member_handles[i]), &matrix[i]);
2383 return D3D_OK;
2385 case D3DXPC_SCALAR:
2386 case D3DXPC_VECTOR:
2387 case D3DXPC_OBJECT:
2388 case D3DXPC_STRUCT:
2389 break;
2391 default:
2392 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2393 break;
2397 WARN("Invalid argument specified\n");
2399 return D3DERR_INVALIDCALL;
2402 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixPointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
2404 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2405 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2407 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2409 if (param && count <= param->element_count)
2411 UINT i;
2413 switch (param->class)
2415 case D3DXPC_MATRIX_ROWS:
2416 for (i = 0; i < count; ++i)
2418 set_matrix(get_parameter_struct(param->member_handles[i]), matrix[i]);
2420 return D3D_OK;
2422 case D3DXPC_SCALAR:
2423 case D3DXPC_VECTOR:
2424 case D3DXPC_OBJECT:
2425 break;
2427 default:
2428 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2429 break;
2433 WARN("Invalid argument specified\n");
2435 return D3DERR_INVALIDCALL;
2438 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixPointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2440 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2441 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2443 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2445 if (!count) return D3D_OK;
2447 if (param && matrix && count <= param->element_count)
2449 UINT i;
2451 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2453 switch (param->class)
2455 case D3DXPC_MATRIX_ROWS:
2456 for (i = 0; i < count; ++i)
2458 get_matrix(get_parameter_struct(param->member_handles[i]), matrix[i]);
2460 return D3D_OK;
2462 case D3DXPC_SCALAR:
2463 case D3DXPC_VECTOR:
2464 case D3DXPC_OBJECT:
2465 break;
2467 default:
2468 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2469 break;
2473 WARN("Invalid argument specified\n");
2475 return D3DERR_INVALIDCALL;
2478 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTranspose(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
2480 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2481 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2482 D3DXMATRIX m;
2484 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2486 if (param && !param->element_count)
2488 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2490 switch (param->class)
2492 case D3DXPC_MATRIX_ROWS:
2493 set_matrix(param, D3DXMatrixTranspose(&m, matrix));
2494 return D3D_OK;
2496 case D3DXPC_SCALAR:
2497 case D3DXPC_VECTOR:
2498 case D3DXPC_OBJECT:
2499 case D3DXPC_STRUCT:
2500 break;
2502 default:
2503 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2504 break;
2508 WARN("Invalid argument specified\n");
2510 return D3DERR_INVALIDCALL;
2513 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTranspose(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
2515 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2516 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2517 D3DXMATRIX m;
2519 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2521 if (matrix && param && !param->element_count)
2523 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2525 switch (param->class)
2527 case D3DXPC_SCALAR:
2528 case D3DXPC_VECTOR:
2529 get_matrix(param, matrix);
2530 return D3D_OK;
2532 case D3DXPC_MATRIX_ROWS:
2533 get_matrix(param, &m);
2534 D3DXMatrixTranspose(matrix, &m);
2535 return D3D_OK;
2537 case D3DXPC_OBJECT:
2538 case D3DXPC_STRUCT:
2539 break;
2541 default:
2542 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2543 break;
2547 WARN("Invalid argument specified\n");
2549 return D3DERR_INVALIDCALL;
2552 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTransposeArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
2554 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2555 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2556 D3DXMATRIX m;
2558 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2560 if (param && param->element_count >= count)
2562 UINT i;
2564 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2566 switch (param->class)
2568 case D3DXPC_MATRIX_ROWS:
2569 for (i = 0; i < count; ++i)
2571 set_matrix(get_parameter_struct(param->member_handles[i]), D3DXMatrixTranspose(&m, &matrix[i]));
2573 return D3D_OK;
2575 case D3DXPC_SCALAR:
2576 case D3DXPC_VECTOR:
2577 case D3DXPC_OBJECT:
2578 case D3DXPC_STRUCT:
2579 break;
2581 default:
2582 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2583 break;
2587 WARN("Invalid argument specified\n");
2589 return D3DERR_INVALIDCALL;
2592 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTransposeArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2594 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2595 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2597 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2599 if (!count) return D3D_OK;
2601 if (matrix && param && count <= param->element_count)
2603 UINT i;
2605 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2607 switch (param->class)
2609 case D3DXPC_MATRIX_ROWS:
2610 for (i = 0; i < count; ++i)
2612 D3DXMATRIX m;
2614 get_matrix(get_parameter_struct(param->member_handles[i]), &m);
2615 D3DXMatrixTranspose(&matrix[i], &m);
2617 return D3D_OK;
2619 case D3DXPC_SCALAR:
2620 case D3DXPC_VECTOR:
2621 case D3DXPC_OBJECT:
2622 case D3DXPC_STRUCT:
2623 break;
2625 default:
2626 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2627 break;
2631 WARN("Invalid argument specified\n");
2633 return D3DERR_INVALIDCALL;
2636 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
2638 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2639 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2640 D3DXMATRIX m;
2642 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2644 if (param && count <= param->element_count)
2646 UINT i;
2648 switch (param->class)
2650 case D3DXPC_MATRIX_ROWS:
2651 for (i = 0; i < count; ++i)
2653 set_matrix(get_parameter_struct(param->member_handles[i]), D3DXMatrixTranspose(&m, matrix[i]));
2655 return D3D_OK;
2657 case D3DXPC_SCALAR:
2658 case D3DXPC_VECTOR:
2659 case D3DXPC_OBJECT:
2660 break;
2662 default:
2663 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2664 break;
2668 WARN("Invalid argument specified\n");
2670 return D3DERR_INVALIDCALL;
2673 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2675 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2676 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2678 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2680 if (!count) return D3D_OK;
2682 if (matrix && param && count <= param->element_count)
2684 UINT i;
2685 D3DXMATRIX m;
2687 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2689 switch (param->class)
2691 case D3DXPC_MATRIX_ROWS:
2692 for (i = 0; i < count; ++i)
2694 get_matrix(get_parameter_struct(param->member_handles[i]), &m);
2695 D3DXMatrixTranspose(matrix[i], &m);
2697 return D3D_OK;
2699 case D3DXPC_SCALAR:
2700 case D3DXPC_VECTOR:
2701 case D3DXPC_OBJECT:
2702 break;
2704 default:
2705 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2706 break;
2710 WARN("Invalid argument specified\n");
2712 return D3DERR_INVALIDCALL;
2715 static HRESULT WINAPI ID3DXBaseEffectImpl_SetString(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR string)
2717 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2719 FIXME("iface %p, parameter %p, string %p stub\n", This, parameter, string);
2721 return E_NOTIMPL;
2724 static HRESULT WINAPI ID3DXBaseEffectImpl_GetString(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR *string)
2726 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2727 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2729 TRACE("iface %p, parameter %p, string %p\n", This, parameter, string);
2731 if (string && param && !param->element_count && param->type == D3DXPT_STRING)
2733 *string = *(LPCSTR *)param->data;
2734 TRACE("Returning %s\n", debugstr_a(*string));
2735 return D3D_OK;
2738 WARN("Invalid argument specified\n");
2740 return D3DERR_INVALIDCALL;
2743 static HRESULT WINAPI ID3DXBaseEffectImpl_SetTexture(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
2745 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2746 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2748 TRACE("iface %p, parameter %p, texture %p\n", This, parameter, texture);
2750 if (param && !param->element_count &&
2751 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2752 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2753 || param->type == D3DXPT_TEXTURECUBE))
2755 LPDIRECT3DBASETEXTURE9 oltexture = *(LPDIRECT3DBASETEXTURE9 *)param->data;
2757 if (texture) IDirect3DBaseTexture9_AddRef(texture);
2758 if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
2760 *(LPDIRECT3DBASETEXTURE9 *)param->data = texture;
2762 return D3D_OK;
2765 WARN("Invalid argument specified\n");
2767 return D3DERR_INVALIDCALL;
2770 static HRESULT WINAPI ID3DXBaseEffectImpl_GetTexture(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
2772 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2773 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2775 TRACE("iface %p, parameter %p, texture %p\n", This, parameter, texture);
2777 if (texture && param && !param->element_count &&
2778 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2779 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2780 || param->type == D3DXPT_TEXTURECUBE))
2782 *texture = *(LPDIRECT3DBASETEXTURE9 *)param->data;
2783 if (*texture) IDirect3DBaseTexture9_AddRef(*texture);
2784 TRACE("Returning %p\n", *texture);
2785 return D3D_OK;
2788 WARN("Invalid argument specified\n");
2790 return D3DERR_INVALIDCALL;
2793 static HRESULT WINAPI ID3DXBaseEffectImpl_GetPixelShader(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
2795 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2796 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2798 TRACE("iface %p, parameter %p, pshader %p\n", This, parameter, pshader);
2800 if (pshader && param && !param->element_count && param->type == D3DXPT_PIXELSHADER)
2802 *pshader = *(LPDIRECT3DPIXELSHADER9 *)param->data;
2803 if (*pshader) IDirect3DPixelShader9_AddRef(*pshader);
2804 TRACE("Returning %p\n", *pshader);
2805 return D3D_OK;
2808 WARN("Invalid argument specified\n");
2810 return D3DERR_INVALIDCALL;
2813 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVertexShader(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
2815 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2816 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2818 TRACE("iface %p, parameter %p, vshader %p\n", This, parameter, vshader);
2820 if (vshader && param && !param->element_count && param->type == D3DXPT_VERTEXSHADER)
2822 *vshader = *(LPDIRECT3DVERTEXSHADER9 *)param->data;
2823 if (*vshader) IDirect3DVertexShader9_AddRef(*vshader);
2824 TRACE("Returning %p\n", *vshader);
2825 return D3D_OK;
2828 WARN("Invalid argument specified\n");
2830 return D3DERR_INVALIDCALL;
2833 static HRESULT WINAPI ID3DXBaseEffectImpl_SetArrayRange(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
2835 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2837 FIXME("iface %p, parameter %p, start %u, end %u stub\n", This, parameter, start, end);
2839 return E_NOTIMPL;
2842 static const struct ID3DXBaseEffectVtbl ID3DXBaseEffect_Vtbl =
2844 /*** IUnknown methods ***/
2845 ID3DXBaseEffectImpl_QueryInterface,
2846 ID3DXBaseEffectImpl_AddRef,
2847 ID3DXBaseEffectImpl_Release,
2848 /*** ID3DXBaseEffect methods ***/
2849 ID3DXBaseEffectImpl_GetDesc,
2850 ID3DXBaseEffectImpl_GetParameterDesc,
2851 ID3DXBaseEffectImpl_GetTechniqueDesc,
2852 ID3DXBaseEffectImpl_GetPassDesc,
2853 ID3DXBaseEffectImpl_GetFunctionDesc,
2854 ID3DXBaseEffectImpl_GetParameter,
2855 ID3DXBaseEffectImpl_GetParameterByName,
2856 ID3DXBaseEffectImpl_GetParameterBySemantic,
2857 ID3DXBaseEffectImpl_GetParameterElement,
2858 ID3DXBaseEffectImpl_GetTechnique,
2859 ID3DXBaseEffectImpl_GetTechniqueByName,
2860 ID3DXBaseEffectImpl_GetPass,
2861 ID3DXBaseEffectImpl_GetPassByName,
2862 ID3DXBaseEffectImpl_GetFunction,
2863 ID3DXBaseEffectImpl_GetFunctionByName,
2864 ID3DXBaseEffectImpl_GetAnnotation,
2865 ID3DXBaseEffectImpl_GetAnnotationByName,
2866 ID3DXBaseEffectImpl_SetValue,
2867 ID3DXBaseEffectImpl_GetValue,
2868 ID3DXBaseEffectImpl_SetBool,
2869 ID3DXBaseEffectImpl_GetBool,
2870 ID3DXBaseEffectImpl_SetBoolArray,
2871 ID3DXBaseEffectImpl_GetBoolArray,
2872 ID3DXBaseEffectImpl_SetInt,
2873 ID3DXBaseEffectImpl_GetInt,
2874 ID3DXBaseEffectImpl_SetIntArray,
2875 ID3DXBaseEffectImpl_GetIntArray,
2876 ID3DXBaseEffectImpl_SetFloat,
2877 ID3DXBaseEffectImpl_GetFloat,
2878 ID3DXBaseEffectImpl_SetFloatArray,
2879 ID3DXBaseEffectImpl_GetFloatArray,
2880 ID3DXBaseEffectImpl_SetVector,
2881 ID3DXBaseEffectImpl_GetVector,
2882 ID3DXBaseEffectImpl_SetVectorArray,
2883 ID3DXBaseEffectImpl_GetVectorArray,
2884 ID3DXBaseEffectImpl_SetMatrix,
2885 ID3DXBaseEffectImpl_GetMatrix,
2886 ID3DXBaseEffectImpl_SetMatrixArray,
2887 ID3DXBaseEffectImpl_GetMatrixArray,
2888 ID3DXBaseEffectImpl_SetMatrixPointerArray,
2889 ID3DXBaseEffectImpl_GetMatrixPointerArray,
2890 ID3DXBaseEffectImpl_SetMatrixTranspose,
2891 ID3DXBaseEffectImpl_GetMatrixTranspose,
2892 ID3DXBaseEffectImpl_SetMatrixTransposeArray,
2893 ID3DXBaseEffectImpl_GetMatrixTransposeArray,
2894 ID3DXBaseEffectImpl_SetMatrixTransposePointerArray,
2895 ID3DXBaseEffectImpl_GetMatrixTransposePointerArray,
2896 ID3DXBaseEffectImpl_SetString,
2897 ID3DXBaseEffectImpl_GetString,
2898 ID3DXBaseEffectImpl_SetTexture,
2899 ID3DXBaseEffectImpl_GetTexture,
2900 ID3DXBaseEffectImpl_GetPixelShader,
2901 ID3DXBaseEffectImpl_GetVertexShader,
2902 ID3DXBaseEffectImpl_SetArrayRange,
2905 static inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
2907 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
2910 /*** IUnknown methods ***/
2911 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
2913 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
2915 if (IsEqualGUID(riid, &IID_IUnknown) ||
2916 IsEqualGUID(riid, &IID_ID3DXEffect))
2918 iface->lpVtbl->AddRef(iface);
2919 *object = iface;
2920 return S_OK;
2923 ERR("Interface %s not found\n", debugstr_guid(riid));
2925 return E_NOINTERFACE;
2928 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
2930 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2932 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
2934 return InterlockedIncrement(&This->ref);
2937 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
2939 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2940 ULONG ref = InterlockedDecrement(&This->ref);
2942 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
2944 if (!ref)
2946 free_effect(This);
2947 HeapFree(GetProcessHeap(), 0, This);
2950 return ref;
2953 /*** ID3DXBaseEffect methods ***/
2954 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
2956 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2957 ID3DXBaseEffect *base = This->base_effect;
2959 TRACE("Forward iface %p, base %p\n", This, base);
2961 return ID3DXBaseEffectImpl_GetDesc(base, desc);
2964 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
2966 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2967 ID3DXBaseEffect *base = This->base_effect;
2969 TRACE("Forward iface %p, base %p\n", This, base);
2971 return ID3DXBaseEffectImpl_GetParameterDesc(base, parameter, desc);
2974 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
2976 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2977 ID3DXBaseEffect *base = This->base_effect;
2979 TRACE("Forward iface %p, base %p\n", This, base);
2981 return ID3DXBaseEffectImpl_GetTechniqueDesc(base, technique, desc);
2984 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
2986 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2987 ID3DXBaseEffect *base = This->base_effect;
2989 TRACE("Forward iface %p, base %p\n", This, base);
2991 return ID3DXBaseEffectImpl_GetPassDesc(base, pass, desc);
2994 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
2996 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2997 ID3DXBaseEffect *base = This->base_effect;
2999 TRACE("Forward iface %p, base %p\n", This, base);
3001 return ID3DXBaseEffectImpl_GetFunctionDesc(base, shader, desc);
3004 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
3006 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3007 ID3DXBaseEffect *base = This->base_effect;
3009 TRACE("Forward iface %p, base %p\n", This, base);
3011 return ID3DXBaseEffectImpl_GetParameter(base, parameter, index);
3014 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR name)
3016 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3017 ID3DXBaseEffect *base = This->base_effect;
3019 TRACE("Forward iface %p, base %p\n", This, base);
3021 return ID3DXBaseEffectImpl_GetParameterByName(base, parameter, name);
3024 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR semantic)
3026 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3027 ID3DXBaseEffect *base = This->base_effect;
3029 TRACE("Forward iface %p, base %p\n", This, base);
3031 return ID3DXBaseEffectImpl_GetParameterBySemantic(base, parameter, semantic);
3034 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
3036 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3037 ID3DXBaseEffect *base = This->base_effect;
3039 TRACE("Forward iface %p, base %p\n", This, base);
3041 return ID3DXBaseEffectImpl_GetParameterElement(base, parameter, index);
3044 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
3046 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3047 ID3DXBaseEffect *base = This->base_effect;
3049 TRACE("Forward iface %p, base %p\n", This, base);
3051 return ID3DXBaseEffectImpl_GetTechnique(base, index);
3054 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, LPCSTR name)
3056 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3057 ID3DXBaseEffect *base = This->base_effect;
3059 TRACE("Forward iface %p, base %p\n", This, base);
3061 return ID3DXBaseEffectImpl_GetTechniqueByName(base, name);
3064 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
3066 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3067 ID3DXBaseEffect *base = This->base_effect;
3069 TRACE("Forward iface %p, base %p\n", This, base);
3071 return ID3DXBaseEffectImpl_GetPass(base, technique, index);
3074 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface, D3DXHANDLE technique, LPCSTR name)
3076 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3077 ID3DXBaseEffect *base = This->base_effect;
3079 TRACE("Forward iface %p, base %p\n", This, base);
3081 return ID3DXBaseEffectImpl_GetPassByName(base, technique, name);
3084 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
3086 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3087 ID3DXBaseEffect *base = This->base_effect;
3089 TRACE("Forward iface %p, base %p\n", This, base);
3091 return ID3DXBaseEffectImpl_GetFunction(base, index);
3094 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, LPCSTR name)
3096 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3097 ID3DXBaseEffect *base = This->base_effect;
3099 TRACE("Forward iface %p, base %p\n", This, base);
3101 return ID3DXBaseEffectImpl_GetFunctionByName(base, name);
3104 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
3106 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3107 ID3DXBaseEffect *base = This->base_effect;
3109 TRACE("Forward iface %p, base %p\n", This, base);
3111 return ID3DXBaseEffectImpl_GetAnnotation(base, object, index);
3114 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface, D3DXHANDLE object, LPCSTR name)
3116 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3117 ID3DXBaseEffect *base = This->base_effect;
3119 TRACE("Forward iface %p, base %p\n", This, base);
3121 return ID3DXBaseEffectImpl_GetAnnotationByName(base, object, name);
3124 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
3126 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3127 ID3DXBaseEffect *base = This->base_effect;
3129 TRACE("Forward iface %p, base %p\n", This, base);
3131 return ID3DXBaseEffectImpl_SetValue(base, parameter, data, bytes);
3134 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
3136 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3137 ID3DXBaseEffect *base = This->base_effect;
3139 TRACE("Forward iface %p, base %p\n", This, base);
3141 return ID3DXBaseEffectImpl_GetValue(base, parameter, data, bytes);
3144 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
3146 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3147 ID3DXBaseEffect *base = This->base_effect;
3149 TRACE("Forward iface %p, base %p\n", This, base);
3151 return ID3DXBaseEffectImpl_SetBool(base, parameter, b);
3154 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
3156 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3157 ID3DXBaseEffect *base = This->base_effect;
3159 TRACE("Forward iface %p, base %p\n", This, base);
3161 return ID3DXBaseEffectImpl_GetBool(base, parameter, b);
3164 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
3166 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3167 ID3DXBaseEffect *base = This->base_effect;
3169 TRACE("Forward iface %p, base %p\n", This, base);
3171 return ID3DXBaseEffectImpl_SetBoolArray(base, parameter, b, count);
3174 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
3176 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3177 ID3DXBaseEffect *base = This->base_effect;
3179 TRACE("Forward iface %p, base %p\n", This, base);
3181 return ID3DXBaseEffectImpl_GetBoolArray(base, parameter, b, count);
3184 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
3186 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3187 ID3DXBaseEffect *base = This->base_effect;
3189 TRACE("Forward iface %p, base %p\n", This, base);
3191 return ID3DXBaseEffectImpl_SetInt(base, parameter, n);
3194 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
3196 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3197 ID3DXBaseEffect *base = This->base_effect;
3199 TRACE("Forward iface %p, base %p\n", This, base);
3201 return ID3DXBaseEffectImpl_GetInt(base, parameter, n);
3204 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
3206 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3207 ID3DXBaseEffect *base = This->base_effect;
3209 TRACE("Forward iface %p, base %p\n", This, base);
3211 return ID3DXBaseEffectImpl_SetIntArray(base, parameter, n, count);
3214 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n, UINT count)
3216 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3217 ID3DXBaseEffect *base = This->base_effect;
3219 TRACE("Forward iface %p, base %p\n", This, base);
3221 return ID3DXBaseEffectImpl_GetIntArray(base, parameter, n, count);
3224 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT f)
3226 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3227 ID3DXBaseEffect *base = This->base_effect;
3229 TRACE("Forward iface %p, base %p\n", This, base);
3231 return ID3DXBaseEffectImpl_SetFloat(base, parameter, f);
3234 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT *f)
3236 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3237 ID3DXBaseEffect *base = This->base_effect;
3239 TRACE("Forward iface %p, base %p\n", This, base);
3241 return ID3DXBaseEffectImpl_GetFloat(base, parameter, f);
3244 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
3246 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3247 ID3DXBaseEffect *base = This->base_effect;
3249 TRACE("Forward iface %p, base %p\n", This, base);
3251 return ID3DXBaseEffectImpl_SetFloatArray(base, parameter, f, count);
3254 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
3256 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3257 ID3DXBaseEffect *base = This->base_effect;
3259 TRACE("Forward iface %p, base %p\n", This, base);
3261 return ID3DXBaseEffectImpl_GetFloatArray(base, parameter, f, count);
3264 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
3266 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3267 ID3DXBaseEffect *base = This->base_effect;
3269 TRACE("Forward iface %p, base %p\n", This, base);
3271 return ID3DXBaseEffectImpl_SetVector(base, parameter, vector);
3274 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
3276 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3277 ID3DXBaseEffect *base = This->base_effect;
3279 TRACE("Forward iface %p, base %p\n", This, base);
3281 return ID3DXBaseEffectImpl_GetVector(base, parameter, vector);
3284 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
3286 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3287 ID3DXBaseEffect *base = This->base_effect;
3289 TRACE("Forward iface %p, base %p\n", This, base);
3291 return ID3DXBaseEffectImpl_SetVectorArray(base, parameter, vector, count);
3294 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
3296 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3297 ID3DXBaseEffect *base = This->base_effect;
3299 TRACE("Forward iface %p, base %p\n", This, base);
3301 return ID3DXBaseEffectImpl_GetVectorArray(base, parameter, vector, count);
3304 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
3306 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3307 ID3DXBaseEffect *base = This->base_effect;
3309 TRACE("Forward iface %p, base %p\n", This, base);
3311 return ID3DXBaseEffectImpl_SetMatrix(base, parameter, matrix);
3314 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
3316 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3317 ID3DXBaseEffect *base = This->base_effect;
3319 TRACE("Forward iface %p, base %p\n", This, base);
3321 return ID3DXBaseEffectImpl_GetMatrix(base, parameter, matrix);
3324 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
3326 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3327 ID3DXBaseEffect *base = This->base_effect;
3329 TRACE("Forward iface %p, base %p\n", This, base);
3331 return ID3DXBaseEffectImpl_SetMatrixArray(base, parameter, matrix, count);
3334 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3336 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3337 ID3DXBaseEffect *base = This->base_effect;
3339 TRACE("Forward iface %p, base %p\n", This, base);
3341 return ID3DXBaseEffectImpl_GetMatrixArray(base, parameter, matrix, count);
3344 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
3346 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3347 ID3DXBaseEffect *base = This->base_effect;
3349 TRACE("Forward iface %p, base %p\n", This, base);
3351 return ID3DXBaseEffectImpl_SetMatrixPointerArray(base, parameter, matrix, count);
3354 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3356 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3357 ID3DXBaseEffect *base = This->base_effect;
3359 TRACE("Forward iface %p, base %p\n", This, base);
3361 return ID3DXBaseEffectImpl_GetMatrixPointerArray(base, parameter, matrix, count);
3364 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
3366 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3367 ID3DXBaseEffect *base = This->base_effect;
3369 TRACE("Forward iface %p, base %p\n", This, base);
3371 return ID3DXBaseEffectImpl_SetMatrixTranspose(base, parameter, matrix);
3374 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
3376 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3377 ID3DXBaseEffect *base = This->base_effect;
3379 TRACE("Forward iface %p, base %p\n", This, base);
3381 return ID3DXBaseEffectImpl_GetMatrixTranspose(base, parameter, matrix);
3384 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
3386 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3387 ID3DXBaseEffect *base = This->base_effect;
3389 TRACE("Forward iface %p, base %p\n", This, base);
3391 return ID3DXBaseEffectImpl_SetMatrixTransposeArray(base, parameter, matrix, count);
3394 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3396 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3397 ID3DXBaseEffect *base = This->base_effect;
3399 TRACE("Forward iface %p, base %p\n", This, base);
3401 return ID3DXBaseEffectImpl_GetMatrixTransposeArray(base, parameter, matrix, count);
3404 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
3406 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3407 ID3DXBaseEffect *base = This->base_effect;
3409 TRACE("Forward iface %p, base %p\n", This, base);
3411 return ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(base, parameter, matrix, count);
3414 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3416 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3417 ID3DXBaseEffect *base = This->base_effect;
3419 TRACE("Forward iface %p, base %p\n", This, base);
3421 return ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(base, parameter, matrix, count);
3424 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR string)
3426 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3427 ID3DXBaseEffect *base = This->base_effect;
3429 TRACE("Forward iface %p, base %p\n", This, base);
3431 return ID3DXBaseEffectImpl_SetString(base, parameter, string);
3434 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR *string)
3436 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3437 ID3DXBaseEffect *base = This->base_effect;
3439 TRACE("Forward iface %p, base %p\n", This, base);
3441 return ID3DXBaseEffectImpl_GetString(base, parameter, string);
3444 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
3446 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3447 ID3DXBaseEffect *base = This->base_effect;
3449 TRACE("Forward iface %p, base %p\n", This, base);
3451 return ID3DXBaseEffectImpl_SetTexture(base, parameter, texture);
3454 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
3456 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3457 ID3DXBaseEffect *base = This->base_effect;
3459 TRACE("Forward iface %p, base %p\n", This, base);
3461 return ID3DXBaseEffectImpl_GetTexture(base, parameter, texture);
3464 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
3466 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3467 ID3DXBaseEffect *base = This->base_effect;
3469 TRACE("Forward iface %p, base %p\n", This, base);
3471 return ID3DXBaseEffectImpl_GetPixelShader(base, parameter, pshader);
3474 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
3476 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3477 ID3DXBaseEffect *base = This->base_effect;
3479 TRACE("Forward iface %p, base %p\n", This, base);
3481 return ID3DXBaseEffectImpl_GetVertexShader(base, parameter, vshader);
3484 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3486 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3487 ID3DXBaseEffect *base = This->base_effect;
3489 TRACE("Forward iface %p, base %p\n", This, base);
3491 return ID3DXBaseEffectImpl_SetArrayRange(base, parameter, start, end);
3494 /*** ID3DXEffect methods ***/
3495 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, LPD3DXEFFECTPOOL *pool)
3497 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3499 TRACE("iface %p, pool %p\n", This, pool);
3501 if (!pool)
3503 WARN("Invalid argument supplied.\n");
3504 return D3DERR_INVALIDCALL;
3507 if (This->pool)
3509 This->pool->lpVtbl->AddRef(This->pool);
3512 *pool = This->pool;
3514 TRACE("Returning pool %p\n", *pool);
3516 return S_OK;
3519 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3521 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3522 struct ID3DXBaseEffectImpl *base = impl_from_ID3DXBaseEffect(This->base_effect);
3523 struct d3dx_technique *tech = is_valid_technique(base, technique);
3525 TRACE("iface %p, technique %p\n", This, technique);
3527 if (tech)
3529 This->active_technique = get_technique_handle(tech);
3530 TRACE("Technique %p\n", tech);
3531 return D3D_OK;
3534 WARN("Invalid argument supplied.\n");
3536 return D3DERR_INVALIDCALL;
3539 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3541 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3543 TRACE("iface %p\n", This);
3545 return This->active_technique;
3548 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3550 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3552 FIXME("(%p)->(%p): stub\n", This, technique);
3554 return D3D_OK;
3557 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3559 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3561 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3563 return E_NOTIMPL;
3566 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
3568 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3570 FIXME("(%p)->(%p, %p): stub\n", This, parameter, technique);
3572 return FALSE;
3575 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
3577 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3578 struct d3dx_technique *technique = get_technique_struct(This->active_technique);
3580 FIXME("iface %p, passes %p, flags %#x partial stub\n", This, passes, flags);
3582 if (passes && technique)
3584 if (This->manager || flags & D3DXFX_DONOTSAVESTATE)
3586 TRACE("State capturing disabled.\n");
3588 else
3590 FIXME("State capturing not supported, yet!\n");
3593 *passes = technique->pass_count;
3595 return D3D_OK;
3598 WARN("Invalid argument supplied.\n");
3600 return D3DERR_INVALIDCALL;
3603 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
3605 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3606 struct d3dx_technique *technique = get_technique_struct(This->active_technique);
3608 TRACE("iface %p, pass %u\n", This, pass);
3610 if (technique && pass < technique->pass_count && !This->active_pass)
3612 This->active_pass = technique->pass_handles[pass];
3614 FIXME("No states applied, yet!\n");
3616 return D3D_OK;
3619 WARN("Invalid argument supplied.\n");
3621 return D3DERR_INVALIDCALL;
3624 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect* iface)
3626 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3628 FIXME("(%p)->(): stub\n", This);
3630 return E_NOTIMPL;
3633 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
3635 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3637 TRACE("iface %p\n", This);
3639 if (This->active_pass)
3641 This->active_pass = NULL;
3642 return D3D_OK;
3645 WARN("Invalid call.\n");
3647 return D3DERR_INVALIDCALL;
3650 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect* iface)
3652 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3654 FIXME("(%p)->(): stub\n", This);
3656 return E_NOTIMPL;
3659 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, LPDIRECT3DDEVICE9 *device)
3661 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3663 TRACE("iface %p, device %p\n", This, device);
3665 if (!device)
3667 WARN("Invalid argument supplied.\n");
3668 return D3DERR_INVALIDCALL;
3671 IDirect3DDevice9_AddRef(This->device);
3673 *device = This->device;
3675 TRACE("Returning device %p\n", *device);
3677 return S_OK;
3680 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
3682 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3684 FIXME("(%p)->(): stub\n", This);
3686 return E_NOTIMPL;
3689 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(ID3DXEffect* iface)
3691 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3693 FIXME("(%p)->(): stub\n", This);
3695 return E_NOTIMPL;
3698 static HRESULT WINAPI ID3DXEffectImpl_SetStateManager(ID3DXEffect *iface, LPD3DXEFFECTSTATEMANAGER manager)
3700 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3702 TRACE("iface %p, manager %p\n", This, manager);
3704 if (manager) IUnknown_AddRef(manager);
3705 if (This->manager) IUnknown_Release(This->manager);
3707 This->manager = manager;
3709 return D3D_OK;
3712 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, LPD3DXEFFECTSTATEMANAGER *manager)
3714 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3716 TRACE("iface %p, manager %p\n", This, manager);
3718 if (!manager)
3720 WARN("Invalid argument supplied.\n");
3721 return D3DERR_INVALIDCALL;
3724 if (This->manager) IUnknown_AddRef(This->manager);
3725 *manager = This->manager;
3727 return D3D_OK;
3730 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
3732 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3734 FIXME("(%p)->(): stub\n", This);
3736 return E_NOTIMPL;
3739 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
3741 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3743 FIXME("(%p)->(): stub\n", This);
3745 return NULL;
3748 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3750 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3752 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3754 return E_NOTIMPL;
3757 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3759 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3761 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3763 return E_NOTIMPL;
3766 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect* iface, LPDIRECT3DDEVICE9 device, LPD3DXEFFECT* effect)
3768 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3770 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
3772 return E_NOTIMPL;
3775 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect* iface, D3DXHANDLE parameter, LPCVOID data, UINT byte_offset, UINT bytes)
3777 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3779 FIXME("(%p)->(%p, %p, %u, %u): stub\n", This, parameter, data, byte_offset, bytes);
3781 return E_NOTIMPL;
3784 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
3786 /*** IUnknown methods ***/
3787 ID3DXEffectImpl_QueryInterface,
3788 ID3DXEffectImpl_AddRef,
3789 ID3DXEffectImpl_Release,
3790 /*** ID3DXBaseEffect methods ***/
3791 ID3DXEffectImpl_GetDesc,
3792 ID3DXEffectImpl_GetParameterDesc,
3793 ID3DXEffectImpl_GetTechniqueDesc,
3794 ID3DXEffectImpl_GetPassDesc,
3795 ID3DXEffectImpl_GetFunctionDesc,
3796 ID3DXEffectImpl_GetParameter,
3797 ID3DXEffectImpl_GetParameterByName,
3798 ID3DXEffectImpl_GetParameterBySemantic,
3799 ID3DXEffectImpl_GetParameterElement,
3800 ID3DXEffectImpl_GetTechnique,
3801 ID3DXEffectImpl_GetTechniqueByName,
3802 ID3DXEffectImpl_GetPass,
3803 ID3DXEffectImpl_GetPassByName,
3804 ID3DXEffectImpl_GetFunction,
3805 ID3DXEffectImpl_GetFunctionByName,
3806 ID3DXEffectImpl_GetAnnotation,
3807 ID3DXEffectImpl_GetAnnotationByName,
3808 ID3DXEffectImpl_SetValue,
3809 ID3DXEffectImpl_GetValue,
3810 ID3DXEffectImpl_SetBool,
3811 ID3DXEffectImpl_GetBool,
3812 ID3DXEffectImpl_SetBoolArray,
3813 ID3DXEffectImpl_GetBoolArray,
3814 ID3DXEffectImpl_SetInt,
3815 ID3DXEffectImpl_GetInt,
3816 ID3DXEffectImpl_SetIntArray,
3817 ID3DXEffectImpl_GetIntArray,
3818 ID3DXEffectImpl_SetFloat,
3819 ID3DXEffectImpl_GetFloat,
3820 ID3DXEffectImpl_SetFloatArray,
3821 ID3DXEffectImpl_GetFloatArray,
3822 ID3DXEffectImpl_SetVector,
3823 ID3DXEffectImpl_GetVector,
3824 ID3DXEffectImpl_SetVectorArray,
3825 ID3DXEffectImpl_GetVectorArray,
3826 ID3DXEffectImpl_SetMatrix,
3827 ID3DXEffectImpl_GetMatrix,
3828 ID3DXEffectImpl_SetMatrixArray,
3829 ID3DXEffectImpl_GetMatrixArray,
3830 ID3DXEffectImpl_SetMatrixPointerArray,
3831 ID3DXEffectImpl_GetMatrixPointerArray,
3832 ID3DXEffectImpl_SetMatrixTranspose,
3833 ID3DXEffectImpl_GetMatrixTranspose,
3834 ID3DXEffectImpl_SetMatrixTransposeArray,
3835 ID3DXEffectImpl_GetMatrixTransposeArray,
3836 ID3DXEffectImpl_SetMatrixTransposePointerArray,
3837 ID3DXEffectImpl_GetMatrixTransposePointerArray,
3838 ID3DXEffectImpl_SetString,
3839 ID3DXEffectImpl_GetString,
3840 ID3DXEffectImpl_SetTexture,
3841 ID3DXEffectImpl_GetTexture,
3842 ID3DXEffectImpl_GetPixelShader,
3843 ID3DXEffectImpl_GetVertexShader,
3844 ID3DXEffectImpl_SetArrayRange,
3845 /*** ID3DXEffect methods ***/
3846 ID3DXEffectImpl_GetPool,
3847 ID3DXEffectImpl_SetTechnique,
3848 ID3DXEffectImpl_GetCurrentTechnique,
3849 ID3DXEffectImpl_ValidateTechnique,
3850 ID3DXEffectImpl_FindNextValidTechnique,
3851 ID3DXEffectImpl_IsParameterUsed,
3852 ID3DXEffectImpl_Begin,
3853 ID3DXEffectImpl_BeginPass,
3854 ID3DXEffectImpl_CommitChanges,
3855 ID3DXEffectImpl_EndPass,
3856 ID3DXEffectImpl_End,
3857 ID3DXEffectImpl_GetDevice,
3858 ID3DXEffectImpl_OnLostDevice,
3859 ID3DXEffectImpl_OnResetDevice,
3860 ID3DXEffectImpl_SetStateManager,
3861 ID3DXEffectImpl_GetStateManager,
3862 ID3DXEffectImpl_BeginParameterBlock,
3863 ID3DXEffectImpl_EndParameterBlock,
3864 ID3DXEffectImpl_ApplyParameterBlock,
3865 ID3DXEffectImpl_DeleteParameterBlock,
3866 ID3DXEffectImpl_CloneEffect,
3867 ID3DXEffectImpl_SetRawValue
3870 static inline struct ID3DXEffectCompilerImpl *impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler *iface)
3872 return CONTAINING_RECORD(iface, struct ID3DXEffectCompilerImpl, ID3DXEffectCompiler_iface);
3875 /*** IUnknown methods ***/
3876 static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler *iface, REFIID riid, void **object)
3878 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
3880 if (IsEqualGUID(riid, &IID_IUnknown) ||
3881 IsEqualGUID(riid, &IID_ID3DXEffectCompiler))
3883 iface->lpVtbl->AddRef(iface);
3884 *object = iface;
3885 return S_OK;
3888 ERR("Interface %s not found\n", debugstr_guid(riid));
3890 return E_NOINTERFACE;
3893 static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface)
3895 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3897 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
3899 return InterlockedIncrement(&This->ref);
3902 static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface)
3904 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3905 ULONG ref = InterlockedDecrement(&This->ref);
3907 TRACE("iface %p: Release from %u\n", iface, ref + 1);
3909 if (!ref)
3911 free_effect_compiler(This);
3912 HeapFree(GetProcessHeap(), 0, This);
3915 return ref;
3918 /*** ID3DXBaseEffect methods ***/
3919 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler *iface, D3DXEFFECT_DESC *desc)
3921 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3922 ID3DXBaseEffect *base = This->base_effect;
3924 TRACE("Forward iface %p, base %p\n", This, base);
3926 return ID3DXBaseEffectImpl_GetDesc(base, desc);
3929 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
3931 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3932 ID3DXBaseEffect *base = This->base_effect;
3934 TRACE("Forward iface %p, base %p\n", This, base);
3936 return ID3DXBaseEffectImpl_GetParameterDesc(base, parameter, desc);
3939 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
3941 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3942 ID3DXBaseEffect *base = This->base_effect;
3944 TRACE("Forward iface %p, base %p\n", This, base);
3946 return ID3DXBaseEffectImpl_GetTechniqueDesc(base, technique, desc);
3949 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
3951 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3952 ID3DXBaseEffect *base = This->base_effect;
3954 TRACE("Forward iface %p, base %p\n", This, base);
3956 return ID3DXBaseEffectImpl_GetPassDesc(base, pass, desc);
3959 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
3961 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3962 ID3DXBaseEffect *base = This->base_effect;
3964 TRACE("Forward iface %p, base %p\n", This, base);
3966 return ID3DXBaseEffectImpl_GetFunctionDesc(base, shader, desc);
3969 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT index)
3971 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3972 ID3DXBaseEffect *base = This->base_effect;
3974 TRACE("Forward iface %p, base %p\n", This, base);
3976 return ID3DXBaseEffectImpl_GetParameter(base, parameter, index);
3979 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR name)
3981 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3982 ID3DXBaseEffect *base = This->base_effect;
3984 TRACE("Forward iface %p, base %p\n", This, base);
3986 return ID3DXBaseEffectImpl_GetParameterByName(base, parameter, name);
3989 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR semantic)
3991 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3992 ID3DXBaseEffect *base = This->base_effect;
3994 TRACE("Forward iface %p, base %p\n", This, base);
3996 return ID3DXBaseEffectImpl_GetParameterBySemantic(base, parameter, semantic);
3999 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT index)
4001 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4002 ID3DXBaseEffect *base = This->base_effect;
4004 TRACE("Forward iface %p, base %p\n", This, base);
4006 return ID3DXBaseEffectImpl_GetParameterElement(base, parameter, index);
4009 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler *iface, UINT index)
4011 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4012 ID3DXBaseEffect *base = This->base_effect;
4014 TRACE("Forward iface %p, base %p\n", This, base);
4016 return ID3DXBaseEffectImpl_GetTechnique(base, index);
4019 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler *iface, LPCSTR name)
4021 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4022 ID3DXBaseEffect *base = This->base_effect;
4024 TRACE("Forward iface %p, base %p\n", This, base);
4026 return ID3DXBaseEffectImpl_GetTechniqueByName(base, name);
4029 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler *iface, D3DXHANDLE technique, UINT index)
4031 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4032 ID3DXBaseEffect *base = This->base_effect;
4034 TRACE("Forward iface %p, base %p\n", This, base);
4036 return ID3DXBaseEffectImpl_GetPass(base, technique, index);
4039 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler *iface, D3DXHANDLE technique, LPCSTR name)
4041 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4042 ID3DXBaseEffect *base = This->base_effect;
4044 TRACE("Forward iface %p, base %p\n", This, base);
4046 return ID3DXBaseEffectImpl_GetPassByName(base, technique, name);
4049 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler *iface, UINT index)
4051 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4052 ID3DXBaseEffect *base = This->base_effect;
4054 TRACE("Forward iface %p, base %p\n", This, base);
4056 return ID3DXBaseEffectImpl_GetFunction(base, index);
4059 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler *iface, LPCSTR name)
4061 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4062 ID3DXBaseEffect *base = This->base_effect;
4064 TRACE("Forward iface %p, base %p\n", This, base);
4066 return ID3DXBaseEffectImpl_GetFunctionByName(base, name);
4069 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler *iface, D3DXHANDLE object, UINT index)
4071 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4072 ID3DXBaseEffect *base = This->base_effect;
4074 TRACE("Forward iface %p, base %p\n", This, base);
4076 return ID3DXBaseEffectImpl_GetAnnotation(base, object, index);
4079 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler *iface, D3DXHANDLE object, LPCSTR name)
4081 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4082 ID3DXBaseEffect *base = This->base_effect;
4084 TRACE("Forward iface %p, base %p\n", This, base);
4086 return ID3DXBaseEffectImpl_GetAnnotationByName(base, object, name);
4089 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
4091 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4092 ID3DXBaseEffect *base = This->base_effect;
4094 TRACE("Forward iface %p, base %p\n", This, base);
4096 return ID3DXBaseEffectImpl_SetValue(base, parameter, data, bytes);
4099 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
4101 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4102 ID3DXBaseEffect *base = This->base_effect;
4104 TRACE("Forward iface %p, base %p\n", This, base);
4106 return ID3DXBaseEffectImpl_GetValue(base, parameter, data, bytes);
4109 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL b)
4111 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4112 ID3DXBaseEffect *base = This->base_effect;
4114 TRACE("Forward iface %p, base %p\n", This, base);
4116 return ID3DXBaseEffectImpl_SetBool(base, parameter, b);
4119 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b)
4121 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4122 ID3DXBaseEffect *base = This->base_effect;
4124 TRACE("Forward iface %p, base %p\n", This, base);
4126 return ID3DXBaseEffectImpl_GetBool(base, parameter, b);
4129 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
4131 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4132 ID3DXBaseEffect *base = This->base_effect;
4134 TRACE("Forward iface %p, base %p\n", This, base);
4136 return ID3DXBaseEffectImpl_SetBoolArray(base, parameter, b, count);
4139 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
4141 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4142 ID3DXBaseEffect *base = This->base_effect;
4144 TRACE("Forward iface %p, base %p\n", This, base);
4146 return ID3DXBaseEffectImpl_GetBoolArray(base, parameter, b, count);
4149 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT n)
4151 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4152 ID3DXBaseEffect *base = This->base_effect;
4154 TRACE("Forward iface %p, base %p\n", This, base);
4156 return ID3DXBaseEffectImpl_SetInt(base, parameter, n);
4159 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n)
4161 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4162 ID3DXBaseEffect *base = This->base_effect;
4164 TRACE("Forward iface %p, base %p\n", This, base);
4166 return ID3DXBaseEffectImpl_GetInt(base, parameter, n);
4169 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
4171 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4172 ID3DXBaseEffect *base = This->base_effect;
4174 TRACE("Forward iface %p, base %p\n", This, base);
4176 return ID3DXBaseEffectImpl_SetIntArray(base, parameter, n, count);
4179 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n, UINT count)
4181 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4182 ID3DXBaseEffect *base = This->base_effect;
4184 TRACE("Forward iface %p, base %p\n", This, base);
4186 return ID3DXBaseEffectImpl_GetIntArray(base, parameter, n, count);
4189 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT f)
4191 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4192 ID3DXBaseEffect *base = This->base_effect;
4194 TRACE("Forward iface %p, base %p\n", This, base);
4196 return ID3DXBaseEffectImpl_SetFloat(base, parameter, f);
4199 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT *f)
4201 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4202 ID3DXBaseEffect *base = This->base_effect;
4204 TRACE("Forward iface %p, base %p\n", This, base);
4206 return ID3DXBaseEffectImpl_GetFloat(base, parameter, f);
4209 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
4211 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4212 ID3DXBaseEffect *base = This->base_effect;
4214 TRACE("Forward iface %p, base %p\n", This, base);
4216 return ID3DXBaseEffectImpl_SetFloatArray(base, parameter, f, count);
4219 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
4221 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4222 ID3DXBaseEffect *base = This->base_effect;
4224 TRACE("Forward iface %p, base %p\n", This, base);
4226 return ID3DXBaseEffectImpl_GetFloatArray(base, parameter, f, count);
4229 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
4231 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4232 ID3DXBaseEffect *base = This->base_effect;
4234 TRACE("Forward iface %p, base %p\n", This, base);
4236 return ID3DXBaseEffectImpl_SetVector(base, parameter, vector);
4239 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
4241 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4242 ID3DXBaseEffect *base = This->base_effect;
4244 TRACE("Forward iface %p, base %p\n", This, base);
4246 return ID3DXBaseEffectImpl_GetVector(base, parameter, vector);
4249 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
4251 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4252 ID3DXBaseEffect *base = This->base_effect;
4254 TRACE("Forward iface %p, base %p\n", This, base);
4256 return ID3DXBaseEffectImpl_SetVectorArray(base, parameter, vector, count);
4259 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
4261 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4262 ID3DXBaseEffect *base = This->base_effect;
4264 TRACE("Forward iface %p, base %p\n", This, base);
4266 return ID3DXBaseEffectImpl_GetVectorArray(base, parameter, vector, count);
4269 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
4271 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4272 ID3DXBaseEffect *base = This->base_effect;
4274 TRACE("Forward iface %p, base %p\n", This, base);
4276 return ID3DXBaseEffectImpl_SetMatrix(base, parameter, matrix);
4279 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
4281 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4282 ID3DXBaseEffect *base = This->base_effect;
4284 TRACE("Forward iface %p, base %p\n", This, base);
4286 return ID3DXBaseEffectImpl_GetMatrix(base, parameter, matrix);
4289 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
4291 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4292 ID3DXBaseEffect *base = This->base_effect;
4294 TRACE("Forward iface %p, base %p\n", This, base);
4296 return ID3DXBaseEffectImpl_SetMatrixArray(base, parameter, matrix, count);
4299 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4301 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4302 ID3DXBaseEffect *base = This->base_effect;
4304 TRACE("Forward iface %p, base %p\n", This, base);
4306 return ID3DXBaseEffectImpl_GetMatrixArray(base, parameter, matrix, count);
4309 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
4311 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4312 ID3DXBaseEffect *base = This->base_effect;
4314 TRACE("Forward iface %p, base %p\n", This, base);
4316 return ID3DXBaseEffectImpl_SetMatrixPointerArray(base, parameter, matrix, count);
4319 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4321 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4322 ID3DXBaseEffect *base = This->base_effect;
4324 TRACE("Forward iface %p, base %p\n", This, base);
4326 return ID3DXBaseEffectImpl_GetMatrixPointerArray(base, parameter, matrix, count);
4329 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
4331 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4332 ID3DXBaseEffect *base = This->base_effect;
4334 TRACE("Forward iface %p, base %p\n", This, base);
4336 return ID3DXBaseEffectImpl_SetMatrixTranspose(base, parameter, matrix);
4339 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
4341 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4342 ID3DXBaseEffect *base = This->base_effect;
4344 TRACE("Forward iface %p, base %p\n", This, base);
4346 return ID3DXBaseEffectImpl_GetMatrixTranspose(base, parameter, matrix);
4349 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
4351 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4352 ID3DXBaseEffect *base = This->base_effect;
4354 TRACE("Forward iface %p, base %p\n", This, base);
4356 return ID3DXBaseEffectImpl_SetMatrixTransposeArray(base, parameter, matrix, count);
4359 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4361 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4362 ID3DXBaseEffect *base = This->base_effect;
4364 TRACE("Forward iface %p, base %p\n", This, base);
4366 return ID3DXBaseEffectImpl_GetMatrixTransposeArray(base, parameter, matrix, count);
4369 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
4371 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4372 ID3DXBaseEffect *base = This->base_effect;
4374 TRACE("Forward iface %p, base %p\n", This, base);
4376 return ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(base, parameter, matrix, count);
4379 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4381 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4382 ID3DXBaseEffect *base = This->base_effect;
4384 TRACE("Forward iface %p, base %p\n", This, base);
4386 return ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(base, parameter, matrix, count);
4389 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR string)
4391 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4392 ID3DXBaseEffect *base = This->base_effect;
4394 TRACE("Forward iface %p, base %p\n", This, base);
4396 return ID3DXBaseEffectImpl_SetString(base, parameter, string);
4399 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR *string)
4401 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4402 ID3DXBaseEffect *base = This->base_effect;
4404 TRACE("Forward iface %p, base %p\n", This, base);
4406 return ID3DXBaseEffectImpl_GetString(base, parameter, string);
4409 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetTexture(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
4411 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4412 ID3DXBaseEffect *base = This->base_effect;
4414 TRACE("Forward iface %p, base %p\n", This, base);
4416 return ID3DXBaseEffectImpl_SetTexture(base, parameter, texture);
4419 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTexture(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
4421 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4422 ID3DXBaseEffect *base = This->base_effect;
4424 TRACE("Forward iface %p, base %p\n", This, base);
4426 return ID3DXBaseEffectImpl_GetTexture(base, parameter, texture);
4429 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
4431 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4432 ID3DXBaseEffect *base = This->base_effect;
4434 TRACE("Forward iface %p, base %p\n", This, base);
4436 return ID3DXBaseEffectImpl_GetPixelShader(base, parameter, pshader);
4439 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVertexShader(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
4441 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4442 ID3DXBaseEffect *base = This->base_effect;
4444 TRACE("Forward iface %p, base %p\n", This, base);
4446 return ID3DXBaseEffectImpl_GetVertexShader(base, parameter, vshader);
4449 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT start, UINT end)
4451 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4452 ID3DXBaseEffect *base = This->base_effect;
4454 TRACE("Forward iface %p, base %p\n", This, base);
4456 return ID3DXBaseEffectImpl_SetArrayRange(base, parameter, start, end);
4459 /*** ID3DXEffectCompiler methods ***/
4460 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL literal)
4462 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4464 FIXME("iface %p, parameter %p, literal %u\n", This, parameter, literal);
4466 return E_NOTIMPL;
4469 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *literal)
4471 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4473 FIXME("iface %p, parameter %p, literal %p\n", This, parameter, literal);
4475 return E_NOTIMPL;
4478 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler *iface, DWORD flags,
4479 LPD3DXBUFFER *effect, LPD3DXBUFFER *error_msgs)
4481 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4483 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub\n", This, flags, effect, error_msgs);
4485 return E_NOTIMPL;
4488 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler *iface, D3DXHANDLE function,
4489 LPCSTR target, DWORD flags, LPD3DXBUFFER *shader, LPD3DXBUFFER *error_msgs, LPD3DXCONSTANTTABLE *constant_table)
4491 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4493 FIXME("iface %p, function %p, target %p, flags %#x, shader %p, error_msgs %p, constant_table %p stub\n",
4494 This, function, target, flags, shader, error_msgs, constant_table);
4496 return E_NOTIMPL;
4499 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
4501 /*** IUnknown methods ***/
4502 ID3DXEffectCompilerImpl_QueryInterface,
4503 ID3DXEffectCompilerImpl_AddRef,
4504 ID3DXEffectCompilerImpl_Release,
4505 /*** ID3DXBaseEffect methods ***/
4506 ID3DXEffectCompilerImpl_GetDesc,
4507 ID3DXEffectCompilerImpl_GetParameterDesc,
4508 ID3DXEffectCompilerImpl_GetTechniqueDesc,
4509 ID3DXEffectCompilerImpl_GetPassDesc,
4510 ID3DXEffectCompilerImpl_GetFunctionDesc,
4511 ID3DXEffectCompilerImpl_GetParameter,
4512 ID3DXEffectCompilerImpl_GetParameterByName,
4513 ID3DXEffectCompilerImpl_GetParameterBySemantic,
4514 ID3DXEffectCompilerImpl_GetParameterElement,
4515 ID3DXEffectCompilerImpl_GetTechnique,
4516 ID3DXEffectCompilerImpl_GetTechniqueByName,
4517 ID3DXEffectCompilerImpl_GetPass,
4518 ID3DXEffectCompilerImpl_GetPassByName,
4519 ID3DXEffectCompilerImpl_GetFunction,
4520 ID3DXEffectCompilerImpl_GetFunctionByName,
4521 ID3DXEffectCompilerImpl_GetAnnotation,
4522 ID3DXEffectCompilerImpl_GetAnnotationByName,
4523 ID3DXEffectCompilerImpl_SetValue,
4524 ID3DXEffectCompilerImpl_GetValue,
4525 ID3DXEffectCompilerImpl_SetBool,
4526 ID3DXEffectCompilerImpl_GetBool,
4527 ID3DXEffectCompilerImpl_SetBoolArray,
4528 ID3DXEffectCompilerImpl_GetBoolArray,
4529 ID3DXEffectCompilerImpl_SetInt,
4530 ID3DXEffectCompilerImpl_GetInt,
4531 ID3DXEffectCompilerImpl_SetIntArray,
4532 ID3DXEffectCompilerImpl_GetIntArray,
4533 ID3DXEffectCompilerImpl_SetFloat,
4534 ID3DXEffectCompilerImpl_GetFloat,
4535 ID3DXEffectCompilerImpl_SetFloatArray,
4536 ID3DXEffectCompilerImpl_GetFloatArray,
4537 ID3DXEffectCompilerImpl_SetVector,
4538 ID3DXEffectCompilerImpl_GetVector,
4539 ID3DXEffectCompilerImpl_SetVectorArray,
4540 ID3DXEffectCompilerImpl_GetVectorArray,
4541 ID3DXEffectCompilerImpl_SetMatrix,
4542 ID3DXEffectCompilerImpl_GetMatrix,
4543 ID3DXEffectCompilerImpl_SetMatrixArray,
4544 ID3DXEffectCompilerImpl_GetMatrixArray,
4545 ID3DXEffectCompilerImpl_SetMatrixPointerArray,
4546 ID3DXEffectCompilerImpl_GetMatrixPointerArray,
4547 ID3DXEffectCompilerImpl_SetMatrixTranspose,
4548 ID3DXEffectCompilerImpl_GetMatrixTranspose,
4549 ID3DXEffectCompilerImpl_SetMatrixTransposeArray,
4550 ID3DXEffectCompilerImpl_GetMatrixTransposeArray,
4551 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray,
4552 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray,
4553 ID3DXEffectCompilerImpl_SetString,
4554 ID3DXEffectCompilerImpl_GetString,
4555 ID3DXEffectCompilerImpl_SetTexture,
4556 ID3DXEffectCompilerImpl_GetTexture,
4557 ID3DXEffectCompilerImpl_GetPixelShader,
4558 ID3DXEffectCompilerImpl_GetVertexShader,
4559 ID3DXEffectCompilerImpl_SetArrayRange,
4560 /*** ID3DXEffectCompiler methods ***/
4561 ID3DXEffectCompilerImpl_SetLiteral,
4562 ID3DXEffectCompilerImpl_GetLiteral,
4563 ID3DXEffectCompilerImpl_CompileEffect,
4564 ID3DXEffectCompilerImpl_CompileShader,
4567 static HRESULT d3dx9_parse_sampler(struct d3dx_sampler *sampler, const char *data, const char **ptr, D3DXHANDLE *objects)
4569 HRESULT hr;
4570 UINT i;
4571 struct d3dx_state *states;
4573 read_dword(ptr, &sampler->state_count);
4574 TRACE("Count: %u\n", sampler->state_count);
4576 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * sampler->state_count);
4577 if (!states)
4579 ERR("Out of memory\n");
4580 return E_OUTOFMEMORY;
4583 for (i = 0; i < sampler->state_count; ++i)
4585 hr = d3dx9_parse_state(&states[i], data, ptr, objects);
4586 if (hr != D3D_OK)
4588 WARN("Failed to parse state\n");
4589 goto err_out;
4593 sampler->states = states;
4595 return D3D_OK;
4597 err_out:
4599 for (i = 0; i < sampler->state_count; ++i)
4601 free_state(&states[i]);
4604 HeapFree(GetProcessHeap(), 0, states);
4606 return hr;
4609 static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, const char *data, const char **ptr, D3DXHANDLE *objects)
4611 unsigned int i;
4612 HRESULT hr;
4613 UINT old_size = 0;
4614 DWORD id;
4616 if (param->element_count)
4618 param->data = value;
4620 for (i = 0; i < param->element_count; ++i)
4622 struct d3dx_parameter *member = get_parameter_struct(param->member_handles[i]);
4624 hr = d3dx9_parse_value(member, value ? (char *)value + old_size : NULL, data, ptr, objects);
4625 if (hr != D3D_OK)
4627 WARN("Failed to parse value\n");
4628 return hr;
4631 old_size += member->bytes;
4634 return D3D_OK;
4637 switch(param->class)
4639 case D3DXPC_SCALAR:
4640 case D3DXPC_VECTOR:
4641 case D3DXPC_MATRIX_ROWS:
4642 case D3DXPC_MATRIX_COLUMNS:
4643 param->data = value;
4644 break;
4646 case D3DXPC_STRUCT:
4647 param->data = value;
4649 for (i = 0; i < param->member_count; ++i)
4651 struct d3dx_parameter *member = get_parameter_struct(param->member_handles[i]);
4653 hr = d3dx9_parse_value(member, (char *)value + old_size, data, ptr, objects);
4654 if (hr != D3D_OK)
4656 WARN("Failed to parse value\n");
4657 return hr;
4660 old_size += member->bytes;
4662 break;
4664 case D3DXPC_OBJECT:
4665 switch (param->type)
4667 case D3DXPT_STRING:
4668 case D3DXPT_TEXTURE:
4669 case D3DXPT_TEXTURE1D:
4670 case D3DXPT_TEXTURE2D:
4671 case D3DXPT_TEXTURE3D:
4672 case D3DXPT_TEXTURECUBE:
4673 case D3DXPT_PIXELSHADER:
4674 case D3DXPT_VERTEXSHADER:
4675 read_dword(ptr, &id);
4676 TRACE("Id: %u\n", id);
4677 objects[id] = get_parameter_handle(param);
4678 param->data = value;
4679 break;
4681 case D3DXPT_SAMPLER:
4682 case D3DXPT_SAMPLER1D:
4683 case D3DXPT_SAMPLER2D:
4684 case D3DXPT_SAMPLER3D:
4685 case D3DXPT_SAMPLERCUBE:
4687 struct d3dx_sampler *sampler;
4689 sampler = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler));
4690 if (!sampler)
4692 ERR("Out of memory\n");
4693 return E_OUTOFMEMORY;
4696 hr = d3dx9_parse_sampler(sampler, data, ptr, objects);
4697 if (hr != D3D_OK)
4699 HeapFree(GetProcessHeap(), 0, sampler);
4700 WARN("Failed to parse sampler\n");
4701 return hr;
4704 param->data = sampler;
4705 break;
4708 default:
4709 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4710 break;
4712 break;
4714 default:
4715 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4716 break;
4719 return D3D_OK;
4722 static HRESULT d3dx9_parse_init_value(struct d3dx_parameter *param, const char *data, const char *ptr, D3DXHANDLE *objects)
4724 UINT size = param->bytes;
4725 HRESULT hr;
4726 void *value = NULL;
4728 TRACE("param size: %u\n", size);
4730 if (size)
4732 value = HeapAlloc(GetProcessHeap(), 0, size);
4733 if (!value)
4735 ERR("Failed to allocate data memory.\n");
4736 return E_OUTOFMEMORY;
4739 TRACE("Data: %s.\n", debugstr_an(ptr, size));
4740 memcpy(value, ptr, size);
4743 hr = d3dx9_parse_value(param, value, data, &ptr, objects);
4744 if (hr != D3D_OK)
4746 WARN("Failed to parse value\n");
4747 HeapFree(GetProcessHeap(), 0, value);
4748 return hr;
4751 return D3D_OK;
4754 static HRESULT d3dx9_parse_name(char **name, const char *ptr)
4756 DWORD size;
4758 read_dword(&ptr, &size);
4759 TRACE("Name size: %#x\n", size);
4761 if (!size)
4763 return D3D_OK;
4766 *name = HeapAlloc(GetProcessHeap(), 0, size);
4767 if (!*name)
4769 ERR("Failed to allocate name memory.\n");
4770 return E_OUTOFMEMORY;
4773 TRACE("Name: %s.\n", debugstr_an(ptr, size));
4774 memcpy(*name, ptr, size);
4776 return D3D_OK;
4779 static HRESULT d3dx9_copy_data(char **str, const char **ptr)
4781 DWORD size;
4783 read_dword(ptr, &size);
4784 TRACE("Data size: %#x\n", size);
4786 *str = HeapAlloc(GetProcessHeap(), 0, size);
4787 if (!*str)
4789 ERR("Failed to allocate name memory.\n");
4790 return E_OUTOFMEMORY;
4793 TRACE("Data: %s.\n", debugstr_an(*ptr, size));
4794 memcpy(*str, *ptr, size);
4796 *ptr += ((size + 3) & ~3);
4798 return D3D_OK;
4801 static HRESULT d3dx9_parse_data(struct d3dx_parameter *param, const char **ptr, LPDIRECT3DDEVICE9 device)
4803 DWORD size;
4804 HRESULT hr;
4806 TRACE("Parse data for parameter %s, type %s\n", debugstr_a(param->name), debug_d3dxparameter_type(param->type));
4808 read_dword(ptr, &size);
4809 TRACE("Data size: %#x\n", size);
4811 if (!size)
4813 TRACE("Size is 0\n");
4814 *(void **)param->data = NULL;
4815 return D3D_OK;
4818 switch (param->type)
4820 case D3DXPT_STRING:
4821 /* re-read with size (sizeof(DWORD) = 4) */
4822 hr = d3dx9_parse_name((LPSTR *)param->data, *ptr - 4);
4823 if (hr != D3D_OK)
4825 WARN("Failed to parse string data\n");
4826 return hr;
4828 break;
4830 case D3DXPT_VERTEXSHADER:
4831 hr = IDirect3DDevice9_CreateVertexShader(device, (DWORD *)*ptr, (LPDIRECT3DVERTEXSHADER9 *)param->data);
4832 if (hr != D3D_OK)
4834 WARN("Failed to create vertex shader\n");
4835 return hr;
4837 break;
4839 case D3DXPT_PIXELSHADER:
4840 hr = IDirect3DDevice9_CreatePixelShader(device, (DWORD *)*ptr, (LPDIRECT3DPIXELSHADER9 *)param->data);
4841 if (hr != D3D_OK)
4843 WARN("Failed to create pixel shader\n");
4844 return hr;
4846 break;
4848 default:
4849 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4850 break;
4854 *ptr += ((size + 3) & ~3);
4856 return D3D_OK;
4859 static HRESULT d3dx9_parse_effect_typedef(struct d3dx_parameter *param, const char *data, const char **ptr,
4860 struct d3dx_parameter *parent, UINT flags)
4862 DWORD offset;
4863 HRESULT hr;
4864 D3DXHANDLE *member_handles = NULL;
4865 UINT i;
4867 param->flags = flags;
4869 if (!parent)
4871 read_dword(ptr, &param->type);
4872 TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
4874 read_dword(ptr, &param->class);
4875 TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
4877 read_dword(ptr, &offset);
4878 TRACE("Type name offset: %#x\n", offset);
4879 hr = d3dx9_parse_name(&param->name, data + offset);
4880 if (hr != D3D_OK)
4882 WARN("Failed to parse name\n");
4883 goto err_out;
4886 read_dword(ptr, &offset);
4887 TRACE("Type semantic offset: %#x\n", offset);
4888 hr = d3dx9_parse_name(&param->semantic, data + offset);
4889 if (hr != D3D_OK)
4891 WARN("Failed to parse semantic\n");
4892 goto err_out;
4895 read_dword(ptr, &param->element_count);
4896 TRACE("Elements: %u\n", param->element_count);
4898 switch (param->class)
4900 case D3DXPC_VECTOR:
4901 read_dword(ptr, &param->columns);
4902 TRACE("Columns: %u\n", param->columns);
4904 read_dword(ptr, &param->rows);
4905 TRACE("Rows: %u\n", param->rows);
4907 /* sizeof(DWORD) * rows * columns */
4908 param->bytes = 4 * param->rows * param->columns;
4909 break;
4911 case D3DXPC_SCALAR:
4912 case D3DXPC_MATRIX_ROWS:
4913 case D3DXPC_MATRIX_COLUMNS:
4914 read_dword(ptr, &param->rows);
4915 TRACE("Rows: %u\n", param->rows);
4917 read_dword(ptr, &param->columns);
4918 TRACE("Columns: %u\n", param->columns);
4920 /* sizeof(DWORD) * rows * columns */
4921 param->bytes = 4 * param->rows * param->columns;
4922 break;
4924 case D3DXPC_STRUCT:
4925 read_dword(ptr, &param->member_count);
4926 TRACE("Members: %u\n", param->member_count);
4927 break;
4929 case D3DXPC_OBJECT:
4930 switch (param->type)
4932 case D3DXPT_STRING:
4933 param->bytes = sizeof(LPCSTR);
4934 break;
4936 case D3DXPT_PIXELSHADER:
4937 param->bytes = sizeof(LPDIRECT3DPIXELSHADER9);
4938 break;
4940 case D3DXPT_VERTEXSHADER:
4941 param->bytes = sizeof(LPDIRECT3DVERTEXSHADER9);
4942 break;
4944 case D3DXPT_TEXTURE:
4945 case D3DXPT_TEXTURE1D:
4946 case D3DXPT_TEXTURE2D:
4947 case D3DXPT_TEXTURE3D:
4948 case D3DXPT_TEXTURECUBE:
4949 param->bytes = sizeof(LPDIRECT3DBASETEXTURE9);
4950 break;
4952 case D3DXPT_SAMPLER:
4953 case D3DXPT_SAMPLER1D:
4954 case D3DXPT_SAMPLER2D:
4955 case D3DXPT_SAMPLER3D:
4956 case D3DXPT_SAMPLERCUBE:
4957 param->bytes = 0;
4958 break;
4960 default:
4961 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4962 break;
4964 break;
4966 default:
4967 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4968 break;
4971 else
4973 /* elements */
4974 param->type = parent->type;
4975 param->class = parent->class;
4976 param->name = parent->name;
4977 param->semantic = parent->semantic;
4978 param->element_count = 0;
4979 param->annotation_count = 0;
4980 param->member_count = parent->member_count;
4981 param->bytes = parent->bytes;
4982 param->rows = parent->rows;
4983 param->columns = parent->columns;
4986 if (param->element_count)
4988 unsigned int param_bytes = 0;
4989 const char *save_ptr = *ptr;
4991 member_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member_handles) * param->element_count);
4992 if (!member_handles)
4994 ERR("Out of memory\n");
4995 hr = E_OUTOFMEMORY;
4996 goto err_out;
4999 for (i = 0; i < param->element_count; ++i)
5001 struct d3dx_parameter *member;
5002 *ptr = save_ptr;
5004 member = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member));
5005 if (!member)
5007 ERR("Out of memory\n");
5008 hr = E_OUTOFMEMORY;
5009 goto err_out;
5012 member_handles[i] = get_parameter_handle(member);
5014 hr = d3dx9_parse_effect_typedef(member, data, ptr, param, flags);
5015 if (hr != D3D_OK)
5017 WARN("Failed to parse member\n");
5018 goto err_out;
5021 param_bytes += member->bytes;
5024 param->bytes = param_bytes;
5026 else if (param->member_count)
5028 member_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member_handles) * param->member_count);
5029 if (!member_handles)
5031 ERR("Out of memory\n");
5032 hr = E_OUTOFMEMORY;
5033 goto err_out;
5036 for (i = 0; i < param->member_count; ++i)
5038 struct d3dx_parameter *member;
5040 member = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member));
5041 if (!member)
5043 ERR("Out of memory\n");
5044 hr = E_OUTOFMEMORY;
5045 goto err_out;
5048 member_handles[i] = get_parameter_handle(member);
5050 hr = d3dx9_parse_effect_typedef(member, data, ptr, NULL, flags);
5051 if (hr != D3D_OK)
5053 WARN("Failed to parse member\n");
5054 goto err_out;
5057 param->bytes += member->bytes;
5061 param->member_handles = member_handles;
5063 return D3D_OK;
5065 err_out:
5067 if (member_handles)
5069 unsigned int count;
5071 if (param->element_count) count = param->element_count;
5072 else count = param->member_count;
5074 for (i = 0; i < count; ++i)
5076 free_parameter(member_handles[i], param->element_count != 0, TRUE);
5078 HeapFree(GetProcessHeap(), 0, member_handles);
5081 if (!parent)
5083 HeapFree(GetProcessHeap(), 0, param->name);
5084 HeapFree(GetProcessHeap(), 0, param->semantic);
5086 param->name = NULL;
5087 param->semantic = NULL;
5089 return hr;
5092 static HRESULT d3dx9_parse_effect_annotation(struct d3dx_parameter *anno, const char *data, const char **ptr, D3DXHANDLE *objects)
5094 DWORD offset;
5095 const char *ptr2;
5096 HRESULT hr;
5098 anno->flags = D3DX_PARAMETER_ANNOTATION;
5100 read_dword(ptr, &offset);
5101 TRACE("Typedef offset: %#x\n", offset);
5102 ptr2 = data + offset;
5103 hr = d3dx9_parse_effect_typedef(anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
5104 if (hr != D3D_OK)
5106 WARN("Failed to parse type definition\n");
5107 return hr;
5110 read_dword(ptr, &offset);
5111 TRACE("Value offset: %#x\n", offset);
5112 hr = d3dx9_parse_init_value(anno, data, data + offset, objects);
5113 if (hr != D3D_OK)
5115 WARN("Failed to parse value\n");
5116 return hr;
5119 return D3D_OK;
5122 static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects)
5124 DWORD offset;
5125 const char *ptr2;
5126 HRESULT hr;
5127 struct d3dx_parameter *parameter;
5129 parameter = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter));
5130 if (!parameter)
5132 ERR("Out of memory\n");
5133 return E_OUTOFMEMORY;
5136 state->type = ST_CONSTANT;
5138 read_dword(ptr, &state->operation);
5139 TRACE("Operation: %#x (%s)\n", state->operation, state_table[state->operation].name);
5141 read_dword(ptr, &state->index);
5142 TRACE("Index: %#x\n", state->index);
5144 read_dword(ptr, &offset);
5145 TRACE("Typedef offset: %#x\n", offset);
5146 ptr2 = data + offset;
5147 hr = d3dx9_parse_effect_typedef(parameter, data, &ptr2, NULL, 0);
5148 if (hr != D3D_OK)
5150 WARN("Failed to parse type definition\n");
5151 goto err_out;
5154 read_dword(ptr, &offset);
5155 TRACE("Value offset: %#x\n", offset);
5156 hr = d3dx9_parse_init_value(parameter, data, data + offset, objects);
5157 if (hr != D3D_OK)
5159 WARN("Failed to parse value\n");
5160 goto err_out;
5163 state->parameter = get_parameter_handle(parameter);
5165 return D3D_OK;
5167 err_out:
5169 free_parameter(get_parameter_handle(parameter), FALSE, FALSE);
5171 return hr;
5174 static HRESULT d3dx9_parse_effect_parameter(struct d3dx_parameter *param, const char *data, const char **ptr, D3DXHANDLE *objects)
5176 DWORD offset;
5177 HRESULT hr;
5178 unsigned int i;
5179 D3DXHANDLE *annotation_handles = NULL;
5180 const char *ptr2;
5182 read_dword(ptr, &offset);
5183 TRACE("Typedef offset: %#x\n", offset);
5184 ptr2 = data + offset;
5186 read_dword(ptr, &offset);
5187 TRACE("Value offset: %#x\n", offset);
5189 read_dword(ptr, &param->flags);
5190 TRACE("Flags: %#x\n", param->flags);
5192 read_dword(ptr, &param->annotation_count);
5193 TRACE("Annotation count: %u\n", param->annotation_count);
5195 hr = d3dx9_parse_effect_typedef(param, data, &ptr2, NULL, param->flags);
5196 if (hr != D3D_OK)
5198 WARN("Failed to parse type definition\n");
5199 return hr;
5202 hr = d3dx9_parse_init_value(param, data, data + offset, objects);
5203 if (hr != D3D_OK)
5205 WARN("Failed to parse value\n");
5206 return hr;
5209 if (param->annotation_count)
5211 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * param->annotation_count);
5212 if (!annotation_handles)
5214 ERR("Out of memory\n");
5215 hr = E_OUTOFMEMORY;
5216 goto err_out;
5219 for (i = 0; i < param->annotation_count; ++i)
5221 struct d3dx_parameter *annotation;
5223 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5224 if (!annotation)
5226 ERR("Out of memory\n");
5227 hr = E_OUTOFMEMORY;
5228 goto err_out;
5231 annotation_handles[i] = get_parameter_handle(annotation);
5233 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5234 if (hr != D3D_OK)
5236 WARN("Failed to parse annotation\n");
5237 goto err_out;
5242 param->annotation_handles = annotation_handles;
5244 return D3D_OK;
5246 err_out:
5248 if (annotation_handles)
5250 for (i = 0; i < param->annotation_count; ++i)
5252 free_parameter(annotation_handles[i], FALSE, FALSE);
5254 HeapFree(GetProcessHeap(), 0, annotation_handles);
5257 return hr;
5260 static HRESULT d3dx9_parse_effect_pass(struct d3dx_pass *pass, const char *data, const char **ptr, D3DXHANDLE *objects)
5262 DWORD offset;
5263 HRESULT hr;
5264 unsigned int i;
5265 D3DXHANDLE *annotation_handles = NULL;
5266 struct d3dx_state *states = NULL;
5267 char *name = NULL;
5269 read_dword(ptr, &offset);
5270 TRACE("Pass name offset: %#x\n", offset);
5271 hr = d3dx9_parse_name(&name, data + offset);
5272 if (hr != D3D_OK)
5274 WARN("Failed to parse name\n");
5275 goto err_out;
5278 read_dword(ptr, &pass->annotation_count);
5279 TRACE("Annotation count: %u\n", pass->annotation_count);
5281 read_dword(ptr, &pass->state_count);
5282 TRACE("State count: %u\n", pass->state_count);
5284 if (pass->annotation_count)
5286 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * pass->annotation_count);
5287 if (!annotation_handles)
5289 ERR("Out of memory\n");
5290 hr = E_OUTOFMEMORY;
5291 goto err_out;
5294 for (i = 0; i < pass->annotation_count; ++i)
5296 struct d3dx_parameter *annotation;
5298 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5299 if (!annotation)
5301 ERR("Out of memory\n");
5302 hr = E_OUTOFMEMORY;
5303 goto err_out;
5306 annotation_handles[i] = get_parameter_handle(annotation);
5308 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5309 if (hr != D3D_OK)
5311 WARN("Failed to parse annotations\n");
5312 goto err_out;
5317 if (pass->state_count)
5319 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * pass->state_count);
5320 if (!states)
5322 ERR("Out of memory\n");
5323 hr = E_OUTOFMEMORY;
5324 goto err_out;
5327 for (i = 0; i < pass->state_count; ++i)
5329 hr = d3dx9_parse_state(&states[i], data, ptr, objects);
5330 if (hr != D3D_OK)
5332 WARN("Failed to parse annotations\n");
5333 goto err_out;
5338 pass->name = name;
5339 pass->annotation_handles = annotation_handles;
5340 pass->states = states;
5342 return D3D_OK;
5344 err_out:
5346 if (annotation_handles)
5348 for (i = 0; i < pass->annotation_count; ++i)
5350 free_parameter(annotation_handles[i], FALSE, FALSE);
5352 HeapFree(GetProcessHeap(), 0, annotation_handles);
5355 if (states)
5357 for (i = 0; i < pass->state_count; ++i)
5359 free_state(&states[i]);
5361 HeapFree(GetProcessHeap(), 0, states);
5364 HeapFree(GetProcessHeap(), 0, name);
5366 return hr;
5369 static HRESULT d3dx9_parse_effect_technique(struct d3dx_technique *technique, const char *data, const char **ptr, D3DXHANDLE *objects)
5371 DWORD offset;
5372 HRESULT hr;
5373 unsigned int i;
5374 D3DXHANDLE *annotation_handles = NULL;
5375 D3DXHANDLE *pass_handles = NULL;
5376 char *name = NULL;
5378 read_dword(ptr, &offset);
5379 TRACE("Technique name offset: %#x\n", offset);
5380 hr = d3dx9_parse_name(&name, data + offset);
5381 if (hr != D3D_OK)
5383 WARN("Failed to parse name\n");
5384 goto err_out;
5387 read_dword(ptr, &technique->annotation_count);
5388 TRACE("Annotation count: %u\n", technique->annotation_count);
5390 read_dword(ptr, &technique->pass_count);
5391 TRACE("Pass count: %u\n", technique->pass_count);
5393 if (technique->annotation_count)
5395 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * technique->annotation_count);
5396 if (!annotation_handles)
5398 ERR("Out of memory\n");
5399 hr = E_OUTOFMEMORY;
5400 goto err_out;
5403 for (i = 0; i < technique->annotation_count; ++i)
5405 struct d3dx_parameter *annotation;
5407 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5408 if (!annotation)
5410 ERR("Out of memory\n");
5411 hr = E_OUTOFMEMORY;
5412 goto err_out;
5415 annotation_handles[i] = get_parameter_handle(annotation);
5417 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5418 if (hr != D3D_OK)
5420 WARN("Failed to parse annotations\n");
5421 goto err_out;
5426 if (technique->pass_count)
5428 pass_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pass_handles) * technique->pass_count);
5429 if (!pass_handles)
5431 ERR("Out of memory\n");
5432 hr = E_OUTOFMEMORY;
5433 goto err_out;
5436 for (i = 0; i < technique->pass_count; ++i)
5438 struct d3dx_pass *pass;
5440 pass = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pass));
5441 if (!pass)
5443 ERR("Out of memory\n");
5444 hr = E_OUTOFMEMORY;
5445 goto err_out;
5448 pass_handles[i] = get_pass_handle(pass);
5450 hr = d3dx9_parse_effect_pass(pass, data, ptr, objects);
5451 if (hr != D3D_OK)
5453 WARN("Failed to parse passes\n");
5454 goto err_out;
5459 technique->name = name;
5460 technique->pass_handles = pass_handles;
5461 technique->annotation_handles = annotation_handles;
5463 return D3D_OK;
5465 err_out:
5467 if (pass_handles)
5469 for (i = 0; i < technique->pass_count; ++i)
5471 free_pass(pass_handles[i]);
5473 HeapFree(GetProcessHeap(), 0, pass_handles);
5476 if (annotation_handles)
5478 for (i = 0; i < technique->annotation_count; ++i)
5480 free_parameter(annotation_handles[i], FALSE, FALSE);
5482 HeapFree(GetProcessHeap(), 0, annotation_handles);
5485 HeapFree(GetProcessHeap(), 0, name);
5487 return hr;
5490 static HRESULT d3dx9_parse_resource(struct ID3DXBaseEffectImpl *base, const char *data, const char **ptr)
5492 DWORD technique_index;
5493 DWORD index, state_index, usage, element_index;
5494 struct d3dx_state *state;
5495 struct d3dx_parameter *param;
5496 HRESULT hr = E_FAIL;
5498 read_dword(ptr, &technique_index);
5499 TRACE("techn: %u\n", technique_index);
5501 read_dword(ptr, &index);
5502 TRACE("index: %u\n", index);
5504 read_dword(ptr, &element_index);
5505 TRACE("element_index: %u\n", element_index);
5507 read_dword(ptr, &state_index);
5508 TRACE("state_index: %u\n", state_index);
5510 read_dword(ptr, &usage);
5511 TRACE("usage: %u\n", usage);
5513 if (technique_index == 0xffffffff)
5515 struct d3dx_parameter *parameter;
5516 struct d3dx_sampler *sampler;
5518 if (index >= base->parameter_count)
5520 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index, base->parameter_count);
5521 return E_FAIL;
5524 parameter = get_parameter_struct(base->parameter_handles[index]);
5525 if (element_index != 0xffffffff)
5527 if (element_index >= parameter->element_count && parameter->element_count != 0)
5529 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index, parameter->element_count);
5530 return E_FAIL;
5533 if (parameter->element_count != 0) parameter = get_parameter_struct(parameter->member_handles[element_index]);
5536 sampler = parameter->data;
5537 if (state_index >= sampler->state_count)
5539 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, sampler->state_count);
5540 return E_FAIL;
5543 state = &sampler->states[state_index];
5545 else
5547 struct d3dx_technique *technique;
5548 struct d3dx_pass *pass;
5550 if (technique_index >= base->technique_count)
5552 FIXME("Index out of bounds: technique_index %u >= technique_count %u\n", technique_index, base->technique_count);
5553 return E_FAIL;
5556 technique = get_technique_struct(base->technique_handles[technique_index]);
5557 if (index >= technique->pass_count)
5559 FIXME("Index out of bounds: index %u >= pass_count %u\n", index, technique->pass_count);
5560 return E_FAIL;
5563 pass = get_pass_struct(technique->pass_handles[index]);
5564 if (state_index >= pass->state_count)
5566 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, pass->state_count);
5567 return E_FAIL;
5570 state = &pass->states[state_index];
5573 param = get_parameter_struct(state->parameter);
5575 switch (usage)
5577 case 0:
5578 TRACE("usage 0: type %s\n", debug_d3dxparameter_type(param->type));
5579 switch (param->type)
5581 case D3DXPT_VERTEXSHADER:
5582 case D3DXPT_PIXELSHADER:
5583 state->type = ST_CONSTANT;
5584 hr = d3dx9_parse_data(param, ptr, base->effect->device);
5585 break;
5587 case D3DXPT_BOOL:
5588 case D3DXPT_INT:
5589 case D3DXPT_FLOAT:
5590 case D3DXPT_STRING:
5591 state->type = ST_FXLC;
5592 hr = d3dx9_copy_data(param->data, ptr);
5593 break;
5595 default:
5596 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5597 break;
5599 break;
5601 case 1:
5602 state->type = ST_PARAMETER;
5603 hr = d3dx9_copy_data(param->data, ptr);
5604 if (hr == D3D_OK)
5606 TRACE("Mapping to parameter %s\n", *(char **)param->data);
5608 break;
5610 default:
5611 FIXME("Unknown usage %x\n", usage);
5612 break;
5615 return hr;
5618 static HRESULT d3dx9_parse_effect(struct ID3DXBaseEffectImpl *base, const char *data, UINT data_size, DWORD start)
5620 const char *ptr = data + start;
5621 D3DXHANDLE *parameter_handles = NULL;
5622 D3DXHANDLE *technique_handles = NULL;
5623 D3DXHANDLE *objects = NULL;
5624 UINT stringcount, objectcount, resourcecount;
5625 HRESULT hr;
5626 UINT i;
5628 read_dword(&ptr, &base->parameter_count);
5629 TRACE("Parameter count: %u\n", base->parameter_count);
5631 read_dword(&ptr, &base->technique_count);
5632 TRACE("Technique count: %u\n", base->technique_count);
5634 skip_dword_unknown(&ptr, 1);
5636 read_dword(&ptr, &objectcount);
5637 TRACE("Object count: %u\n", objectcount);
5639 objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*objects) * objectcount);
5640 if (!objects)
5642 ERR("Out of memory\n");
5643 hr = E_OUTOFMEMORY;
5644 goto err_out;
5647 if (base->parameter_count)
5649 parameter_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter_handles) * base->parameter_count);
5650 if (!parameter_handles)
5652 ERR("Out of memory\n");
5653 hr = E_OUTOFMEMORY;
5654 goto err_out;
5657 for (i = 0; i < base->parameter_count; ++i)
5659 struct d3dx_parameter *parameter;
5661 parameter = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter));
5662 if (!parameter)
5664 ERR("Out of memory\n");
5665 hr = E_OUTOFMEMORY;
5666 goto err_out;
5669 parameter_handles[i] = get_parameter_handle(parameter);
5671 hr = d3dx9_parse_effect_parameter(parameter, data, &ptr, objects);
5672 if (hr != D3D_OK)
5674 WARN("Failed to parse parameter\n");
5675 goto err_out;
5680 if (base->technique_count)
5682 technique_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*technique_handles) * base->technique_count);
5683 if (!technique_handles)
5685 ERR("Out of memory\n");
5686 hr = E_OUTOFMEMORY;
5687 goto err_out;
5690 for (i = 0; i < base->technique_count; ++i)
5692 struct d3dx_technique *technique;
5694 technique = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*technique));
5695 if (!technique)
5697 ERR("Out of memory\n");
5698 hr = E_OUTOFMEMORY;
5699 goto err_out;
5702 technique_handles[i] = get_technique_handle(technique);
5704 hr = d3dx9_parse_effect_technique(technique, data, &ptr, objects);
5705 if (hr != D3D_OK)
5707 WARN("Failed to parse technique\n");
5708 goto err_out;
5713 /* needed for further parsing */
5714 base->technique_handles = technique_handles;
5715 base->parameter_handles = parameter_handles;
5717 read_dword(&ptr, &stringcount);
5718 TRACE("String count: %u\n", stringcount);
5720 read_dword(&ptr, &resourcecount);
5721 TRACE("Resource count: %u\n", resourcecount);
5723 for (i = 0; i < stringcount; ++i)
5725 DWORD id;
5726 struct d3dx_parameter *param;
5728 read_dword(&ptr, &id);
5729 TRACE("Id: %u\n", id);
5731 param = get_parameter_struct(objects[id]);
5733 hr = d3dx9_parse_data(param, &ptr, base->effect->device);
5734 if (hr != D3D_OK)
5736 WARN("Failed to parse data\n");
5737 goto err_out;
5741 for (i = 0; i < resourcecount; ++i)
5743 TRACE("parse resource %u\n", i);
5745 hr = d3dx9_parse_resource(base, data, &ptr);
5746 if (hr != D3D_OK)
5748 WARN("Failed to parse data\n");
5749 goto err_out;
5753 HeapFree(GetProcessHeap(), 0, objects);
5755 return D3D_OK;
5757 err_out:
5759 if (technique_handles)
5761 for (i = 0; i < base->technique_count; ++i)
5763 free_technique(technique_handles[i]);
5765 HeapFree(GetProcessHeap(), 0, technique_handles);
5768 if (parameter_handles)
5770 for (i = 0; i < base->parameter_count; ++i)
5772 free_parameter(parameter_handles[i], FALSE, FALSE);
5774 HeapFree(GetProcessHeap(), 0, parameter_handles);
5777 base->technique_handles = NULL;
5778 base->parameter_handles = NULL;
5780 HeapFree(GetProcessHeap(), 0, objects);
5782 return hr;
5785 static HRESULT d3dx9_base_effect_init(struct ID3DXBaseEffectImpl *base,
5786 const char *data, SIZE_T data_size, struct ID3DXEffectImpl *effect)
5788 DWORD tag, offset;
5789 const char *ptr = data;
5790 HRESULT hr;
5792 TRACE("base %p, data %p, data_size %lu, effect %p\n", base, data, data_size, effect);
5794 base->ID3DXBaseEffect_iface.lpVtbl = &ID3DXBaseEffect_Vtbl;
5795 base->ref = 1;
5796 base->effect = effect;
5798 read_dword(&ptr, &tag);
5799 TRACE("Tag: %x\n", tag);
5801 if (tag != d3dx9_effect_version(9, 1))
5803 /* todo: compile hlsl ascii code */
5804 FIXME("HLSL ascii effects not supported, yet\n");
5806 /* Show the start of the shader for debugging info. */
5807 TRACE("effect:\n%s\n", debugstr_an(data, data_size > 40 ? 40 : data_size));
5809 else
5811 read_dword(&ptr, &offset);
5812 TRACE("Offset: %x\n", offset);
5814 hr = d3dx9_parse_effect(base, ptr, data_size, offset);
5815 if (hr != D3D_OK)
5817 FIXME("Failed to parse effect.\n");
5818 return hr;
5822 return D3D_OK;
5825 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, LPDIRECT3DDEVICE9 device,
5826 const char *data, SIZE_T data_size, LPD3DXEFFECTPOOL pool)
5828 HRESULT hr;
5829 struct ID3DXBaseEffectImpl *object = NULL;
5831 TRACE("effect %p, device %p, data %p, data_size %lu, pool %p\n", effect, device, data, data_size, pool);
5833 effect->ID3DXEffect_iface.lpVtbl = &ID3DXEffect_Vtbl;
5834 effect->ref = 1;
5836 if (pool) pool->lpVtbl->AddRef(pool);
5837 effect->pool = pool;
5839 IDirect3DDevice9_AddRef(device);
5840 effect->device = device;
5842 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5843 if (!object)
5845 ERR("Out of memory\n");
5846 hr = E_OUTOFMEMORY;
5847 goto err_out;
5850 hr = d3dx9_base_effect_init(object, data, data_size, effect);
5851 if (hr != D3D_OK)
5853 FIXME("Failed to parse effect.\n");
5854 goto err_out;
5857 effect->base_effect = &object->ID3DXBaseEffect_iface;
5859 /* initialize defaults - check because of unsupported ascii effects */
5860 if (object->technique_handles)
5862 effect->active_technique = object->technique_handles[0];
5863 effect->active_pass = NULL;
5866 return D3D_OK;
5868 err_out:
5870 HeapFree(GetProcessHeap(), 0, object);
5871 free_effect(effect);
5873 return hr;
5876 HRESULT WINAPI D3DXCreateEffectEx(LPDIRECT3DDEVICE9 device,
5877 LPCVOID srcdata,
5878 UINT srcdatalen,
5879 CONST D3DXMACRO* defines,
5880 LPD3DXINCLUDE include,
5881 LPCSTR skip_constants,
5882 DWORD flags,
5883 LPD3DXEFFECTPOOL pool,
5884 LPD3DXEFFECT* effect,
5885 LPD3DXBUFFER* compilation_errors)
5887 struct ID3DXEffectImpl *object;
5888 HRESULT hr;
5890 FIXME("(%p, %p, %u, %p, %p, %p, %#x, %p, %p, %p): semi-stub\n", device, srcdata, srcdatalen, defines, include,
5891 skip_constants, flags, pool, effect, compilation_errors);
5893 if (!device || !srcdata)
5894 return D3DERR_INVALIDCALL;
5896 if (!srcdatalen)
5897 return E_FAIL;
5899 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
5900 if (!effect)
5901 return D3D_OK;
5903 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5904 if (!object)
5906 ERR("Out of memory\n");
5907 return E_OUTOFMEMORY;
5910 hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, pool);
5911 if (FAILED(hr))
5913 WARN("Failed to initialize shader reflection\n");
5914 HeapFree(GetProcessHeap(), 0, object);
5915 return hr;
5918 *effect = &object->ID3DXEffect_iface;
5920 TRACE("Created ID3DXEffect %p\n", object);
5922 return D3D_OK;
5925 HRESULT WINAPI D3DXCreateEffect(LPDIRECT3DDEVICE9 device,
5926 LPCVOID srcdata,
5927 UINT srcdatalen,
5928 CONST D3DXMACRO* defines,
5929 LPD3DXINCLUDE include,
5930 DWORD flags,
5931 LPD3DXEFFECTPOOL pool,
5932 LPD3DXEFFECT* effect,
5933 LPD3DXBUFFER* compilation_errors)
5935 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device, srcdata, srcdatalen, defines,
5936 include, flags, pool, effect, compilation_errors);
5938 return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
5941 static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler, const char *data, SIZE_T data_size)
5943 HRESULT hr;
5944 struct ID3DXBaseEffectImpl *object = NULL;
5946 TRACE("effect %p, data %p, data_size %lu\n", compiler, data, data_size);
5948 compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
5949 compiler->ref = 1;
5951 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5952 if (!object)
5954 ERR("Out of memory\n");
5955 hr = E_OUTOFMEMORY;
5956 goto err_out;
5959 hr = d3dx9_base_effect_init(object, data, data_size, NULL);
5960 if (hr != D3D_OK)
5962 FIXME("Failed to parse effect.\n");
5963 goto err_out;
5966 compiler->base_effect = &object->ID3DXBaseEffect_iface;
5968 return D3D_OK;
5970 err_out:
5972 HeapFree(GetProcessHeap(), 0, object);
5973 free_effect_compiler(compiler);
5975 return hr;
5978 HRESULT WINAPI D3DXCreateEffectCompiler(LPCSTR srcdata,
5979 UINT srcdatalen,
5980 CONST D3DXMACRO *defines,
5981 LPD3DXINCLUDE include,
5982 DWORD flags,
5983 LPD3DXEFFECTCOMPILER *compiler,
5984 LPD3DXBUFFER *parse_errors)
5986 struct ID3DXEffectCompilerImpl *object;
5987 HRESULT hr;
5989 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
5990 srcdata, srcdatalen, defines, include, flags, compiler, parse_errors);
5992 if (!srcdata || !compiler)
5994 WARN("Invalid arguments supplied\n");
5995 return D3DERR_INVALIDCALL;
5998 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5999 if (!object)
6001 ERR("Out of memory\n");
6002 return E_OUTOFMEMORY;
6005 hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen);
6006 if (FAILED(hr))
6008 WARN("Failed to initialize effect compiler\n");
6009 HeapFree(GetProcessHeap(), 0, object);
6010 return hr;
6013 *compiler = &object->ID3DXEffectCompiler_iface;
6015 TRACE("Created ID3DXEffectCompiler %p\n", object);
6017 return D3D_OK;
6020 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl;
6022 struct ID3DXEffectPoolImpl
6024 ID3DXEffectPool ID3DXEffectPool_iface;
6025 LONG ref;
6028 static inline struct ID3DXEffectPoolImpl *impl_from_ID3DXEffectPool(ID3DXEffectPool *iface)
6030 return CONTAINING_RECORD(iface, struct ID3DXEffectPoolImpl, ID3DXEffectPool_iface);
6033 /*** IUnknown methods ***/
6034 static HRESULT WINAPI ID3DXEffectPoolImpl_QueryInterface(ID3DXEffectPool *iface, REFIID riid, void **object)
6036 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
6038 if (IsEqualGUID(riid, &IID_IUnknown) ||
6039 IsEqualGUID(riid, &IID_ID3DXEffectPool))
6041 iface->lpVtbl->AddRef(iface);
6042 *object = iface;
6043 return S_OK;
6046 WARN("Interface %s not found\n", debugstr_guid(riid));
6048 return E_NOINTERFACE;
6051 static ULONG WINAPI ID3DXEffectPoolImpl_AddRef(ID3DXEffectPool *iface)
6053 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
6055 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
6057 return InterlockedIncrement(&This->ref);
6060 static ULONG WINAPI ID3DXEffectPoolImpl_Release(ID3DXEffectPool *iface)
6062 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
6063 ULONG ref = InterlockedDecrement(&This->ref);
6065 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
6067 if (!ref)
6068 HeapFree(GetProcessHeap(), 0, This);
6070 return ref;
6073 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl =
6075 /*** IUnknown methods ***/
6076 ID3DXEffectPoolImpl_QueryInterface,
6077 ID3DXEffectPoolImpl_AddRef,
6078 ID3DXEffectPoolImpl_Release
6081 HRESULT WINAPI D3DXCreateEffectPool(LPD3DXEFFECTPOOL *pool)
6083 struct ID3DXEffectPoolImpl *object;
6085 TRACE("(%p)\n", pool);
6087 if (!pool)
6088 return D3DERR_INVALIDCALL;
6090 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6091 if (!object)
6093 ERR("Out of memory\n");
6094 return E_OUTOFMEMORY;
6097 object->ID3DXEffectPool_iface.lpVtbl = &ID3DXEffectPool_Vtbl;
6098 object->ref = 1;
6100 *pool = &object->ID3DXEffectPool_iface;
6102 return S_OK;
6105 HRESULT WINAPI D3DXCreateEffectFromFileExW(LPDIRECT3DDEVICE9 device, LPCWSTR srcfile,
6106 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6107 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6109 LPVOID buffer;
6110 HRESULT ret;
6111 DWORD size;
6113 TRACE("(%s): relay\n", debugstr_w(srcfile));
6115 if (!device || !srcfile)
6116 return D3DERR_INVALIDCALL;
6118 ret = map_view_of_file(srcfile, &buffer, &size);
6120 if (FAILED(ret))
6121 return D3DXERR_INVALIDDATA;
6123 ret = D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6124 UnmapViewOfFile(buffer);
6126 return ret;
6129 HRESULT WINAPI D3DXCreateEffectFromFileExA(LPDIRECT3DDEVICE9 device, LPCSTR srcfile,
6130 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6131 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6133 LPWSTR srcfileW;
6134 HRESULT ret;
6135 DWORD len;
6137 TRACE("(void): relay\n");
6139 if (!srcfile)
6140 return D3DERR_INVALIDCALL;
6142 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6143 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6144 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6146 ret = D3DXCreateEffectFromFileExW(device, srcfileW, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6147 HeapFree(GetProcessHeap(), 0, srcfileW);
6149 return ret;
6152 HRESULT WINAPI D3DXCreateEffectFromFileW(LPDIRECT3DDEVICE9 device, LPCWSTR srcfile,
6153 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6154 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6156 TRACE("(void): relay\n");
6157 return D3DXCreateEffectFromFileExW(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6160 HRESULT WINAPI D3DXCreateEffectFromFileA(LPDIRECT3DDEVICE9 device, LPCSTR srcfile,
6161 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6162 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6164 TRACE("(void): relay\n");
6165 return D3DXCreateEffectFromFileExA(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6168 HRESULT WINAPI D3DXCreateEffectFromResourceExW(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCWSTR srcresource,
6169 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6170 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6172 HRSRC resinfo;
6174 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(srcresource));
6176 if (!device)
6177 return D3DERR_INVALIDCALL;
6179 resinfo = FindResourceW(srcmodule, srcresource, (LPCWSTR) RT_RCDATA);
6181 if (resinfo)
6183 LPVOID buffer;
6184 HRESULT ret;
6185 DWORD size;
6187 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6189 if (FAILED(ret))
6190 return D3DXERR_INVALIDDATA;
6192 return D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6195 return D3DXERR_INVALIDDATA;
6198 HRESULT WINAPI D3DXCreateEffectFromResourceExA(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCSTR srcresource,
6199 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6200 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6202 HRSRC resinfo;
6204 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(srcresource));
6206 if (!device)
6207 return D3DERR_INVALIDCALL;
6209 resinfo = FindResourceA(srcmodule, srcresource, (LPCSTR) RT_RCDATA);
6211 if (resinfo)
6213 LPVOID buffer;
6214 HRESULT ret;
6215 DWORD size;
6217 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6219 if (FAILED(ret))
6220 return D3DXERR_INVALIDDATA;
6222 return D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6225 return D3DXERR_INVALIDDATA;
6228 HRESULT WINAPI D3DXCreateEffectFromResourceW(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCWSTR srcresource,
6229 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6230 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6232 TRACE("(void): relay\n");
6233 return D3DXCreateEffectFromResourceExW(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6236 HRESULT WINAPI D3DXCreateEffectFromResourceA(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCSTR srcresource,
6237 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6238 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6240 TRACE("(void): relay\n");
6241 return D3DXCreateEffectFromResourceExA(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6244 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(LPCWSTR srcfile, const D3DXMACRO *defines, LPD3DXINCLUDE include,
6245 DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6247 LPVOID buffer;
6248 HRESULT ret;
6249 DWORD size;
6251 TRACE("(%s): relay\n", debugstr_w(srcfile));
6253 if (!srcfile)
6254 return D3DERR_INVALIDCALL;
6256 ret = map_view_of_file(srcfile, &buffer, &size);
6258 if (FAILED(ret))
6259 return D3DXERR_INVALIDDATA;
6261 ret = D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6262 UnmapViewOfFile(buffer);
6264 return ret;
6267 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(LPCSTR srcfile, const D3DXMACRO *defines, LPD3DXINCLUDE include,
6268 DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6270 LPWSTR srcfileW;
6271 HRESULT ret;
6272 DWORD len;
6274 TRACE("(void): relay\n");
6276 if (!srcfile)
6277 return D3DERR_INVALIDCALL;
6279 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6280 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6281 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6283 ret = D3DXCreateEffectCompilerFromFileW(srcfileW, defines, include, flags, effectcompiler, parseerrors);
6284 HeapFree(GetProcessHeap(), 0, srcfileW);
6286 return ret;
6289 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule, LPCSTR srcresource, const D3DXMACRO *defines,
6290 LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6292 HRSRC resinfo;
6294 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(srcresource));
6296 resinfo = FindResourceA(srcmodule, srcresource, (LPCSTR) RT_RCDATA);
6298 if (resinfo)
6300 LPVOID buffer;
6301 HRESULT ret;
6302 DWORD size;
6304 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6306 if (FAILED(ret))
6307 return D3DXERR_INVALIDDATA;
6309 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6312 return D3DXERR_INVALIDDATA;
6315 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule, LPCWSTR srcresource, const D3DXMACRO *defines,
6316 LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6318 HRSRC resinfo;
6320 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(srcresource));
6322 resinfo = FindResourceW(srcmodule, srcresource, (LPCWSTR) RT_RCDATA);
6324 if (resinfo)
6326 LPVOID buffer;
6327 HRESULT ret;
6328 DWORD size;
6330 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6332 if (FAILED(ret))
6333 return D3DXERR_INVALIDDATA;
6335 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6338 return D3DXERR_INVALIDDATA;