dsound: clean up capture interface and prepare for mmdevapi (v2)
[wine/multimedia.git] / dlls / d3dx9_36 / effect.c
blob877df298c0c0b0a192b4cf677599e7ba54966fba
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_parameter_annotation_by_name(struct d3dx_parameter *parameter, 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 /* */
328 {SC_UNKNOWN, 0, "UNKNOWN"},
329 /* NPatchMode */
330 {SC_NPATCHMODE, 0, "NPatchMode"},
331 /* */
332 {SC_UNKNOWN, 0, "UNKNOWN"},
333 /* Transform */
334 {SC_TRANSFORM, D3DTS_PROJECTION, "D3DTS_PROJECTION"},
335 {SC_TRANSFORM, D3DTS_VIEW, "D3DTS_VIEW"},
336 {SC_TRANSFORM, D3DTS_WORLD, "D3DTS_WORLD"},
337 {SC_TRANSFORM, D3DTS_TEXTURE0, "D3DTS_TEXTURE0"},
338 /* Material */
339 {SC_MATERIAL, MT_DIFFUSE, "MaterialDiffuse"},
340 {SC_MATERIAL, MT_AMBIENT, "MaterialAmbient"}, /* 0x80 */
341 {SC_MATERIAL, MT_SPECULAR, "MaterialSpecular"},
342 {SC_MATERIAL, MT_EMISSIVE, "MaterialEmissive"},
343 {SC_MATERIAL, MT_POWER, "MaterialPower"},
344 /* Light */
345 {SC_LIGHT, LT_TYPE, "LightType"},
346 {SC_LIGHT, LT_DIFFUSE, "LightDiffuse"},
347 {SC_LIGHT, LT_SPECULAR, "LightSpecular"},
348 {SC_LIGHT, LT_AMBIENT, "LightAmbient"},
349 {SC_LIGHT, LT_POSITION, "LightPosition"},
350 {SC_LIGHT, LT_DIRECTION, "LightDirection"},
351 {SC_LIGHT, LT_RANGE, "LightRange"},
352 {SC_LIGHT, LT_FALLOFF, "LightFallOff"},
353 {SC_LIGHT, LT_ATTENUATION0, "LightAttenuation0"},
354 {SC_LIGHT, LT_ATTENUATION1, "LightAttenuation1"},
355 {SC_LIGHT, LT_ATTENUATION2, "LightAttenuation2"},
356 {SC_LIGHT, LT_THETA, "LightTheta"},
357 {SC_LIGHT, LT_PHI, "LightPhi"}, /* 0x90 */
358 /* Ligthenable */
359 {SC_LIGHTENABLE, 0, "LightEnable"},
360 /* Vertexshader */
361 {SC_VERTEXSHADER, 0, "Vertexshader"},
362 /* Pixelshader */
363 {SC_PIXELSHADER, 0, "Pixelshader"},
364 /* Shader constants */
365 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstantF"},
366 {SC_SHADERCONST, SCT_VSBOOL, "VertexShaderConstantB"},
367 {SC_SHADERCONST, SCT_VSINT, "VertexShaderConstantI"},
368 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant"},
369 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant1"},
370 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant2"},
371 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant3"},
372 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant4"},
373 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstantF"},
374 {SC_SHADERCONST, SCT_PSBOOL, "PixelShaderConstantB"},
375 {SC_SHADERCONST, SCT_PSINT, "PixelShaderConstantI"},
376 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant"},
377 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant1"}, /* 0xa0 */
378 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant2"},
379 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant3"},
380 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant4"},
381 /* Texture */
382 {SC_TEXTURE, 0, "Texture"},
383 /* Sampler states */
384 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSU, "AddressU"},
385 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSV, "AddressV"},
386 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSW, "AddressW"},
387 {SC_SAMPLERSTATE, D3DSAMP_BORDERCOLOR, "BorderColor"},
388 {SC_SAMPLERSTATE, D3DSAMP_MAGFILTER, "MagFilter"},
389 {SC_SAMPLERSTATE, D3DSAMP_MINFILTER, "MinFilter"},
390 {SC_SAMPLERSTATE, D3DSAMP_MIPFILTER, "MipFilter"},
391 {SC_SAMPLERSTATE, D3DSAMP_MIPMAPLODBIAS, "MipMapLodBias"},
392 {SC_SAMPLERSTATE, D3DSAMP_MAXMIPLEVEL, "MaxMipLevel"},
393 {SC_SAMPLERSTATE, D3DSAMP_MAXANISOTROPY, "MaxAnisotropy"},
394 {SC_SAMPLERSTATE, D3DSAMP_SRGBTEXTURE, "SRGBTexture"},
395 {SC_SAMPLERSTATE, D3DSAMP_ELEMENTINDEX, "ElementIndex"}, /* 0xb0 */
396 {SC_SAMPLERSTATE, D3DSAMP_DMAPOFFSET, "DMAPOffset"},
397 /* Set sampler */
398 {SC_SETSAMPLER, 0, "Sampler"},
401 static inline void read_dword(const char **ptr, DWORD *d)
403 memcpy(d, *ptr, sizeof(*d));
404 *ptr += sizeof(*d);
407 static void skip_dword_unknown(const char **ptr, unsigned int count)
409 unsigned int i;
410 DWORD d;
412 FIXME("Skipping %u unknown DWORDs:\n", count);
413 for (i = 0; i < count; ++i)
415 read_dword(ptr, &d);
416 FIXME("\t0x%08x\n", d);
420 static inline struct d3dx_parameter *get_parameter_struct(D3DXHANDLE handle)
422 return (struct d3dx_parameter *) handle;
425 static inline struct d3dx_pass *get_pass_struct(D3DXHANDLE handle)
427 return (struct d3dx_pass *) handle;
430 static inline struct d3dx_technique *get_technique_struct(D3DXHANDLE handle)
432 return (struct d3dx_technique *) handle;
435 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
437 return (D3DXHANDLE) parameter;
440 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
442 return (D3DXHANDLE) technique;
445 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
447 return (D3DXHANDLE) pass;
450 static struct d3dx_technique *is_valid_technique(struct ID3DXBaseEffectImpl *base, D3DXHANDLE technique)
452 unsigned int i;
454 for (i = 0; i < base->technique_count; ++i)
456 if (base->technique_handles[i] == technique)
458 return get_technique_struct(technique);
462 return NULL;
465 static struct d3dx_pass *is_valid_pass(struct ID3DXBaseEffectImpl *base, D3DXHANDLE pass)
467 unsigned int i, k;
469 for (i = 0; i < base->technique_count; ++i)
471 struct d3dx_technique *technique = get_technique_struct(base->technique_handles[i]);
473 for (k = 0; k < technique->pass_count; ++k)
475 if (technique->pass_handles[k] == pass)
477 return get_pass_struct(pass);
482 return NULL;
485 static struct d3dx_parameter *is_valid_sub_parameter(struct d3dx_parameter *param, D3DXHANDLE parameter)
487 unsigned int i, count;
488 struct d3dx_parameter *p;
490 for (i = 0; i < param->annotation_count; ++i)
492 if (param->annotation_handles[i] == parameter)
494 return get_parameter_struct(parameter);
497 p = is_valid_sub_parameter(get_parameter_struct(param->annotation_handles[i]), parameter);
498 if (p) return p;
501 if (param->element_count) count = param->element_count;
502 else count = param->member_count;
504 for (i = 0; i < count; ++i)
506 if (param->member_handles[i] == parameter)
508 return get_parameter_struct(parameter);
511 p = is_valid_sub_parameter(get_parameter_struct(param->member_handles[i]), parameter);
512 if (p) return p;
515 return NULL;
518 static struct d3dx_parameter *is_valid_parameter(struct ID3DXBaseEffectImpl *base, D3DXHANDLE parameter)
520 unsigned int i, k, m;
521 struct d3dx_parameter *p;
523 for (i = 0; i < base->parameter_count; ++i)
525 if (base->parameter_handles[i] == parameter)
527 return get_parameter_struct(parameter);
530 p = is_valid_sub_parameter(get_parameter_struct(base->parameter_handles[i]), parameter);
531 if (p) return p;
534 for (i = 0; i < base->technique_count; ++i)
536 struct d3dx_technique *technique = get_technique_struct(base->technique_handles[i]);
538 for (k = 0; k < technique->pass_count; ++k)
540 struct d3dx_pass *pass = get_pass_struct(technique->pass_handles[k]);
542 for (m = 0; m < pass->annotation_count; ++m)
544 if (pass->annotation_handles[i] == parameter)
546 return get_parameter_struct(parameter);
549 p = is_valid_sub_parameter(get_parameter_struct(pass->annotation_handles[m]), parameter);
550 if (p) return p;
554 for (k = 0; k < technique->annotation_count; ++k)
556 if (technique->annotation_handles[k] == parameter)
558 return get_parameter_struct(parameter);
561 p = is_valid_sub_parameter(get_parameter_struct(technique->annotation_handles[k]), parameter);
562 if (p) return p;
566 return NULL;
569 static inline struct d3dx_parameter *get_valid_parameter(struct ID3DXBaseEffectImpl *base, D3DXHANDLE parameter)
571 struct d3dx_parameter *param = is_valid_parameter(base, parameter);
573 if (!param) param = get_parameter_by_name(base, NULL, parameter);
575 return param;
578 static void free_state(struct d3dx_state *state)
580 free_parameter_state(state->parameter, FALSE, FALSE, state->type);
583 static void free_sampler(struct d3dx_sampler *sampler)
585 UINT i;
587 for (i = 0; i < sampler->state_count; ++i)
589 free_state(&sampler->states[i]);
591 HeapFree(GetProcessHeap(), 0, sampler->states);
594 static void free_parameter(D3DXHANDLE handle, BOOL element, BOOL child)
596 free_parameter_state(handle, element, child, ST_CONSTANT);
599 static void free_parameter_state(D3DXHANDLE handle, BOOL element, BOOL child, enum STATE_TYPE st)
601 unsigned int i;
602 struct d3dx_parameter *param = get_parameter_struct(handle);
604 TRACE("Free parameter %p, name %s, type %s, child %s, state_type %x\n", param, param->name,
605 debug_d3dxparameter_type(param->type), child ? "yes" : "no", st);
607 if (!param)
609 return;
612 if (param->annotation_handles)
614 for (i = 0; i < param->annotation_count; ++i)
616 free_parameter(param->annotation_handles[i], FALSE, FALSE);
618 HeapFree(GetProcessHeap(), 0, param->annotation_handles);
621 if (param->member_handles)
623 unsigned int count;
625 if (param->element_count) count = param->element_count;
626 else count = param->member_count;
628 for (i = 0; i < count; ++i)
630 free_parameter(param->member_handles[i], param->element_count != 0, TRUE);
632 HeapFree(GetProcessHeap(), 0, param->member_handles);
635 if (param->class == D3DXPC_OBJECT && !param->element_count)
637 switch (param->type)
639 case D3DXPT_STRING:
640 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
641 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
642 break;
644 case D3DXPT_TEXTURE:
645 case D3DXPT_TEXTURE1D:
646 case D3DXPT_TEXTURE2D:
647 case D3DXPT_TEXTURE3D:
648 case D3DXPT_TEXTURECUBE:
649 case D3DXPT_PIXELSHADER:
650 case D3DXPT_VERTEXSHADER:
651 if (st == ST_CONSTANT)
653 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
655 else
657 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
659 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
660 break;
662 case D3DXPT_SAMPLER:
663 case D3DXPT_SAMPLER1D:
664 case D3DXPT_SAMPLER2D:
665 case D3DXPT_SAMPLER3D:
666 case D3DXPT_SAMPLERCUBE:
667 if (st == ST_CONSTANT)
669 free_sampler((struct d3dx_sampler *)param->data);
671 else
673 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
675 /* samplers have always own data, so free that */
676 HeapFree(GetProcessHeap(), 0, param->data);
677 break;
679 default:
680 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
681 break;
684 else
686 if (!child)
688 if (st != ST_CONSTANT)
690 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
692 HeapFree(GetProcessHeap(), 0, param->data);
696 /* only the parent has to release name and semantic */
697 if (!element)
699 HeapFree(GetProcessHeap(), 0, param->name);
700 HeapFree(GetProcessHeap(), 0, param->semantic);
703 HeapFree(GetProcessHeap(), 0, param);
706 static void free_pass(D3DXHANDLE handle)
708 unsigned int i;
709 struct d3dx_pass *pass = get_pass_struct(handle);
711 TRACE("Free pass %p\n", pass);
713 if (!pass)
715 return;
718 if (pass->annotation_handles)
720 for (i = 0; i < pass->annotation_count; ++i)
722 free_parameter(pass->annotation_handles[i], FALSE, FALSE);
724 HeapFree(GetProcessHeap(), 0, pass->annotation_handles);
727 if (pass->states)
729 for (i = 0; i < pass->state_count; ++i)
731 free_state(&pass->states[i]);
733 HeapFree(GetProcessHeap(), 0, pass->states);
736 HeapFree(GetProcessHeap(), 0, pass->name);
737 HeapFree(GetProcessHeap(), 0, pass);
740 static void free_technique(D3DXHANDLE handle)
742 unsigned int i;
743 struct d3dx_technique *technique = get_technique_struct(handle);
745 TRACE("Free technique %p\n", technique);
747 if (!technique)
749 return;
752 if (technique->annotation_handles)
754 for (i = 0; i < technique->annotation_count; ++i)
756 free_parameter(technique->annotation_handles[i], FALSE, FALSE);
758 HeapFree(GetProcessHeap(), 0, technique->annotation_handles);
761 if (technique->pass_handles)
763 for (i = 0; i < technique->pass_count; ++i)
765 free_pass(technique->pass_handles[i]);
767 HeapFree(GetProcessHeap(), 0, technique->pass_handles);
770 HeapFree(GetProcessHeap(), 0, technique->name);
771 HeapFree(GetProcessHeap(), 0, technique);
774 static void free_base_effect(struct ID3DXBaseEffectImpl *base)
776 unsigned int i;
778 TRACE("Free base effect %p\n", base);
780 if (base->parameter_handles)
782 for (i = 0; i < base->parameter_count; ++i)
784 free_parameter(base->parameter_handles[i], FALSE, FALSE);
786 HeapFree(GetProcessHeap(), 0, base->parameter_handles);
789 if (base->technique_handles)
791 for (i = 0; i < base->technique_count; ++i)
793 free_technique(base->technique_handles[i]);
795 HeapFree(GetProcessHeap(), 0, base->technique_handles);
799 static void free_effect(struct ID3DXEffectImpl *effect)
801 TRACE("Free effect %p\n", effect);
803 if (effect->base_effect)
805 effect->base_effect->lpVtbl->Release(effect->base_effect);
808 if (effect->pool)
810 effect->pool->lpVtbl->Release(effect->pool);
813 if (effect->manager)
815 IUnknown_Release(effect->manager);
818 IDirect3DDevice9_Release(effect->device);
821 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
823 TRACE("Free effect compiler %p\n", compiler);
825 if (compiler->base_effect)
827 compiler->base_effect->lpVtbl->Release(compiler->base_effect);
831 static INT get_int(D3DXPARAMETER_TYPE type, LPCVOID data)
833 INT i;
835 switch (type)
837 case D3DXPT_FLOAT:
838 i = *(FLOAT *)data;
839 break;
841 case D3DXPT_INT:
842 i = *(INT *)data;
843 break;
845 case D3DXPT_BOOL:
846 i = *(BOOL *)data;
847 break;
849 default:
850 i = 0;
851 FIXME("Unhandled type %s. This should not happen!\n", debug_d3dxparameter_type(type));
852 break;
855 return i;
858 inline static FLOAT get_float(D3DXPARAMETER_TYPE type, LPCVOID data)
860 FLOAT f;
862 switch (type)
864 case D3DXPT_FLOAT:
865 f = *(FLOAT *)data;
866 break;
868 case D3DXPT_INT:
869 f = *(INT *)data;
870 break;
872 case D3DXPT_BOOL:
873 f = *(BOOL *)data;
874 break;
876 default:
877 f = 0.0f;
878 FIXME("Unhandled type %s. This should not happen!\n", debug_d3dxparameter_type(type));
879 break;
882 return f;
885 static inline BOOL get_bool(LPCVOID data)
887 return (*(DWORD *)data) ? TRUE : FALSE;
890 static void set_number(LPVOID outdata, D3DXPARAMETER_TYPE outtype, LPCVOID indata, D3DXPARAMETER_TYPE intype)
892 TRACE("Changing from type %i to type %i\n", intype, outtype);
894 switch (outtype)
896 case D3DXPT_FLOAT:
897 *(FLOAT *)outdata = get_float(intype, indata);
898 break;
900 case D3DXPT_BOOL:
901 *(BOOL *)outdata = get_bool(indata);
902 break;
904 case D3DXPT_INT:
905 *(INT *)outdata = get_int(intype, indata);
906 break;
908 default:
909 FIXME("Error converting to type %i\n", outtype);
910 *(INT *)outdata = 0;
911 break;
915 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
917 UINT i;
919 for (i = 0; i < 4; ++i)
921 ((FLOAT *)vector)[i] = i < param->columns ? get_float(param->type, (DWORD *)param->data + i) : 0.0f;
925 static void set_vector(struct d3dx_parameter *param, CONST D3DXVECTOR4 *vector)
927 UINT i;
929 for (i = 0; i < param->columns; ++i)
931 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
935 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix)
937 UINT i, k;
939 for (i = 0; i < 4; ++i)
941 for (k = 0; k < 4; ++k)
943 if ((i < param->rows) && (k < param->columns))
944 matrix->u.m[i][k] = get_float(param->type, (FLOAT *)param->data + i * param->columns + k);
945 else
946 matrix->u.m[i][k] = 0.0f;
951 static void set_matrix(struct d3dx_parameter *param, CONST D3DXMATRIX *matrix)
953 UINT i, k;
955 for (i = 0; i < 4; ++i)
957 for (k = 0; k < 4; ++k)
959 if ((i < param->rows) && (k < param->columns))
960 set_number((FLOAT *)param->data + i * param->columns + k, param->type, &matrix->u.m[i][k], D3DXPT_FLOAT);
965 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, LPCSTR name)
967 UINT element;
968 struct d3dx_parameter *temp_parameter;
969 LPCSTR part;
971 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
973 if (!name || !*name) return parameter;
975 element = atoi(name);
976 part = strchr(name, ']') + 1;
978 if (parameter->element_count > element)
980 temp_parameter = get_parameter_struct(parameter->member_handles[element]);
982 switch (*part++)
984 case '.':
985 return get_parameter_by_name(NULL, temp_parameter, part);
987 case '@':
988 return get_parameter_annotation_by_name(temp_parameter, part);
990 case '\0':
991 TRACE("Returning parameter %p\n", temp_parameter);
992 return temp_parameter;
994 default:
995 FIXME("Unhandled case \"%c\"\n", *--part);
996 break;
1000 TRACE("Parameter not found\n");
1001 return NULL;
1004 static struct d3dx_parameter *get_parameter_annotation_by_name(struct d3dx_parameter *parameter, LPCSTR name)
1006 UINT i, length;
1007 struct d3dx_parameter *temp_parameter;
1008 LPCSTR part;
1010 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
1012 if (!name || !*name) return parameter;
1014 length = strcspn( name, "[.@" );
1015 part = name + length;
1017 for (i = 0; i < parameter->annotation_count; ++i)
1019 temp_parameter = get_parameter_struct(parameter->annotation_handles[i]);
1021 if (!strcmp(temp_parameter->name, name))
1023 TRACE("Returning parameter %p\n", temp_parameter);
1024 return temp_parameter;
1026 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
1028 switch (*part++)
1030 case '.':
1031 return get_parameter_by_name(NULL, temp_parameter, part);
1033 case '[':
1034 return get_parameter_element_by_name(temp_parameter, part);
1036 default:
1037 FIXME("Unhandled case \"%c\"\n", *--part);
1038 break;
1043 TRACE("Parameter not found\n");
1044 return NULL;
1047 static struct d3dx_parameter *get_parameter_by_name(struct ID3DXBaseEffectImpl *base,
1048 struct d3dx_parameter *parameter, LPCSTR name)
1050 UINT i, count, length;
1051 struct d3dx_parameter *temp_parameter;
1052 D3DXHANDLE *handles;
1053 LPCSTR part;
1055 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
1057 if (!name || !*name) return parameter;
1059 if (!parameter)
1061 count = base->parameter_count;
1062 handles = base->parameter_handles;
1064 else
1066 count = parameter->member_count;
1067 handles = parameter->member_handles;
1070 length = strcspn( name, "[.@" );
1071 part = name + length;
1073 for (i = 0; i < count; i++)
1075 temp_parameter = get_parameter_struct(handles[i]);
1077 if (!strcmp(temp_parameter->name, name))
1079 TRACE("Returning parameter %p\n", temp_parameter);
1080 return temp_parameter;
1082 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
1084 switch (*part++)
1086 case '.':
1087 return get_parameter_by_name(NULL, temp_parameter, part);
1089 case '@':
1090 return get_parameter_annotation_by_name(temp_parameter, part);
1092 case '[':
1093 return get_parameter_element_by_name(temp_parameter, part);
1095 default:
1096 FIXME("Unhandled case \"%c\"\n", *--part);
1097 break;
1102 TRACE("Parameter not found\n");
1103 return NULL;
1106 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
1108 return (0xfeff0000 | ((major) << 8) | (minor));
1111 static inline struct ID3DXBaseEffectImpl *impl_from_ID3DXBaseEffect(ID3DXBaseEffect *iface)
1113 return CONTAINING_RECORD(iface, struct ID3DXBaseEffectImpl, ID3DXBaseEffect_iface);
1116 /*** IUnknown methods ***/
1117 static HRESULT WINAPI ID3DXBaseEffectImpl_QueryInterface(ID3DXBaseEffect *iface, REFIID riid, void **object)
1119 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1121 if (IsEqualGUID(riid, &IID_IUnknown) ||
1122 IsEqualGUID(riid, &IID_ID3DXBaseEffect))
1124 iface->lpVtbl->AddRef(iface);
1125 *object = iface;
1126 return S_OK;
1129 ERR("Interface %s not found\n", debugstr_guid(riid));
1131 return E_NOINTERFACE;
1134 static ULONG WINAPI ID3DXBaseEffectImpl_AddRef(ID3DXBaseEffect *iface)
1136 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1138 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
1140 return InterlockedIncrement(&This->ref);
1143 static ULONG WINAPI ID3DXBaseEffectImpl_Release(ID3DXBaseEffect *iface)
1145 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1146 ULONG ref = InterlockedDecrement(&This->ref);
1148 TRACE("iface %p: Release from %u\n", iface, ref + 1);
1150 if (!ref)
1152 free_base_effect(This);
1153 HeapFree(GetProcessHeap(), 0, This);
1156 return ref;
1159 /*** ID3DXBaseEffect methods ***/
1160 static HRESULT WINAPI ID3DXBaseEffectImpl_GetDesc(ID3DXBaseEffect *iface, D3DXEFFECT_DESC *desc)
1162 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1164 FIXME("iface %p, desc %p partial stub\n", This, desc);
1166 if (!desc)
1168 WARN("Invalid argument specified.\n");
1169 return D3DERR_INVALIDCALL;
1172 /* Todo: add creator and function count */
1173 desc->Creator = NULL;
1174 desc->Functions = 0;
1175 desc->Parameters = This->parameter_count;
1176 desc->Techniques = This->technique_count;
1178 return D3D_OK;
1181 static HRESULT WINAPI ID3DXBaseEffectImpl_GetParameterDesc(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
1183 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1184 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1186 TRACE("iface %p, parameter %p, desc %p\n", This, parameter, desc);
1188 if (!desc || !param)
1190 WARN("Invalid argument specified.\n");
1191 return D3DERR_INVALIDCALL;
1194 desc->Name = param->name;
1195 desc->Semantic = param->semantic;
1196 desc->Class = param->class;
1197 desc->Type = param->type;
1198 desc->Rows = param->rows;
1199 desc->Columns = param->columns;
1200 desc->Elements = param->element_count;
1201 desc->Annotations = param->annotation_count;
1202 desc->StructMembers = param->member_count;
1203 desc->Flags = param->flags;
1204 desc->Bytes = param->bytes;
1206 return D3D_OK;
1209 static HRESULT WINAPI ID3DXBaseEffectImpl_GetTechniqueDesc(ID3DXBaseEffect *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
1211 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1212 struct d3dx_technique *tech = technique ? is_valid_technique(This, technique) : get_technique_struct(This->technique_handles[0]);
1214 TRACE("iface %p, technique %p, desc %p\n", This, technique, desc);
1216 if (!desc || !tech)
1218 WARN("Invalid argument specified.\n");
1219 return D3DERR_INVALIDCALL;
1222 desc->Name = tech->name;
1223 desc->Passes = tech->pass_count;
1224 desc->Annotations = tech->annotation_count;
1226 return D3D_OK;
1229 static HRESULT WINAPI ID3DXBaseEffectImpl_GetPassDesc(ID3DXBaseEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
1231 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1232 struct d3dx_pass *p = is_valid_pass(This, pass);
1234 TRACE("iface %p, pass %p, desc %p\n", This, pass, desc);
1236 if (!desc || !p)
1238 WARN("Invalid argument specified.\n");
1239 return D3DERR_INVALIDCALL;
1242 desc->Name = p->name;
1243 desc->Annotations = p->annotation_count;
1245 FIXME("Pixel shader and vertex shader are not supported, yet.\n");
1246 desc->pVertexShaderFunction = NULL;
1247 desc->pPixelShaderFunction = NULL;
1249 return D3D_OK;
1252 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFunctionDesc(ID3DXBaseEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1254 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1256 FIXME("iface %p, shader %p, desc %p stub\n", This, shader, desc);
1258 return E_NOTIMPL;
1261 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameter(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT index)
1263 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1264 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1266 TRACE("iface %p, parameter %p, index %u\n", This, parameter, index);
1268 if (!parameter)
1270 if (index < This->parameter_count)
1272 TRACE("Returning parameter %p\n", This->parameter_handles[index]);
1273 return This->parameter_handles[index];
1276 else
1278 if (param && !param->element_count && index < param->member_count)
1280 TRACE("Returning parameter %p\n", param->member_handles[index]);
1281 return param->member_handles[index];
1285 WARN("Invalid argument specified.\n");
1287 return NULL;
1290 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterByName(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR name)
1292 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1293 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1294 D3DXHANDLE handle;
1296 TRACE("iface %p, parameter %p, name %s\n", This, parameter, debugstr_a(name));
1298 if (!name)
1300 handle = get_parameter_handle(param);
1301 TRACE("Returning parameter %p\n", handle);
1302 return handle;
1305 handle = get_parameter_handle(get_parameter_by_name(This, param, name));
1306 TRACE("Returning parameter %p\n", handle);
1308 return handle;
1311 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterBySemantic(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR semantic)
1313 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1314 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1315 struct d3dx_parameter *temp_param;
1316 UINT i;
1318 TRACE("iface %p, parameter %p, semantic %s\n", This, parameter, debugstr_a(semantic));
1320 if (!parameter)
1322 for (i = 0; i < This->parameter_count; ++i)
1324 temp_param = get_parameter_struct(This->parameter_handles[i]);
1326 if (!temp_param->semantic)
1328 if (!semantic)
1330 TRACE("Returning parameter %p\n", This->parameter_handles[i]);
1331 return This->parameter_handles[i];
1333 continue;
1336 if (!strcasecmp(temp_param->semantic, semantic))
1338 TRACE("Returning parameter %p\n", This->parameter_handles[i]);
1339 return This->parameter_handles[i];
1343 else if (param)
1345 for (i = 0; i < param->member_count; ++i)
1347 temp_param = get_parameter_struct(param->member_handles[i]);
1349 if (!temp_param->semantic)
1351 if (!semantic)
1353 TRACE("Returning parameter %p\n", param->member_handles[i]);
1354 return param->member_handles[i];
1356 continue;
1359 if (!strcasecmp(temp_param->semantic, semantic))
1361 TRACE("Returning parameter %p\n", param->member_handles[i]);
1362 return param->member_handles[i];
1367 WARN("Invalid argument specified\n");
1369 return NULL;
1372 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetParameterElement(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT index)
1374 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1375 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1377 TRACE("iface %p, parameter %p, index %u\n", This, parameter, index);
1379 if (!param)
1381 if (index < This->parameter_count)
1383 TRACE("Returning parameter %p\n", This->parameter_handles[index]);
1384 return This->parameter_handles[index];
1387 else
1389 if (index < param->element_count)
1391 TRACE("Returning parameter %p\n", param->member_handles[index]);
1392 return param->member_handles[index];
1396 WARN("Invalid argument specified\n");
1398 return NULL;
1401 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetTechnique(ID3DXBaseEffect *iface, UINT index)
1403 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1405 TRACE("iface %p, index %u\n", This, index);
1407 if (index >= This->technique_count)
1409 WARN("Invalid argument specified.\n");
1410 return NULL;
1413 TRACE("Returning technique %p\n", This->technique_handles[index]);
1415 return This->technique_handles[index];
1418 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetTechniqueByName(ID3DXBaseEffect *iface, LPCSTR name)
1420 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1421 unsigned int i;
1423 TRACE("iface %p, name %s stub\n", This, debugstr_a(name));
1425 if (!name)
1427 WARN("Invalid argument specified.\n");
1428 return NULL;
1431 for (i = 0; i < This->technique_count; ++i)
1433 struct d3dx_technique *tech = get_technique_struct(This->technique_handles[i]);
1435 if (!strcmp(tech->name, name))
1437 TRACE("Returning technique %p\n", This->technique_handles[i]);
1438 return This->technique_handles[i];
1442 WARN("Invalid argument specified.\n");
1444 return NULL;
1447 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetPass(ID3DXBaseEffect *iface, D3DXHANDLE technique, UINT index)
1449 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1450 struct d3dx_technique *tech = is_valid_technique(This, technique);
1452 TRACE("iface %p, technique %p, index %u\n", This, technique, index);
1454 if (!tech) tech = get_technique_struct(iface->lpVtbl->GetTechniqueByName(iface, technique));
1456 if (tech && index < tech->pass_count)
1458 TRACE("Returning pass %p\n", tech->pass_handles[index]);
1459 return tech->pass_handles[index];
1462 WARN("Invalid argument specified.\n");
1464 return NULL;
1467 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetPassByName(ID3DXBaseEffect *iface, D3DXHANDLE technique, LPCSTR name)
1469 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1470 struct d3dx_technique *tech = is_valid_technique(This, technique);
1472 TRACE("iface %p, technique %p, name %s\n", This, technique, debugstr_a(name));
1474 if (!tech) tech = get_technique_struct(iface->lpVtbl->GetTechniqueByName(iface, technique));
1476 if (tech && name)
1478 unsigned int i;
1480 for (i = 0; i < tech->pass_count; ++i)
1482 struct d3dx_pass *pass = get_pass_struct(tech->pass_handles[i]);
1484 if (!strcmp(pass->name, name))
1486 TRACE("Returning pass %p\n", tech->pass_handles[i]);
1487 return tech->pass_handles[i];
1492 WARN("Invalid argument specified.\n");
1494 return NULL;
1497 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetFunction(ID3DXBaseEffect *iface, UINT index)
1499 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1501 FIXME("iface %p, index %u stub\n", This, index);
1503 return NULL;
1506 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetFunctionByName(ID3DXBaseEffect *iface, LPCSTR name)
1508 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1510 FIXME("iface %p, name %s stub\n", This, debugstr_a(name));
1512 return NULL;
1515 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetAnnotation(ID3DXBaseEffect *iface, D3DXHANDLE object, UINT index)
1517 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1518 struct d3dx_parameter *param = get_valid_parameter(This, object);
1519 struct d3dx_pass *pass = is_valid_pass(This, object);
1520 struct d3dx_technique *technique = is_valid_technique(This, object);
1521 UINT annotation_count = 0;
1522 D3DXHANDLE *annotation_handles = NULL;
1524 FIXME("iface %p, object %p, index %u partial stub\n", This, object, index);
1526 if (pass)
1528 annotation_count = pass->annotation_count;
1529 annotation_handles = pass->annotation_handles;
1531 else if (technique)
1533 annotation_count = technique->annotation_count;
1534 annotation_handles = technique->annotation_handles;
1536 else if (param)
1538 annotation_count = param->annotation_count;
1539 annotation_handles = param->annotation_handles;
1541 /* Todo: add funcs */
1543 if (index < annotation_count)
1545 TRACE("Returning parameter %p\n", annotation_handles[index]);
1546 return annotation_handles[index];
1549 WARN("Invalid argument specified\n");
1551 return NULL;
1554 static D3DXHANDLE WINAPI ID3DXBaseEffectImpl_GetAnnotationByName(ID3DXBaseEffect *iface, D3DXHANDLE object, LPCSTR name)
1556 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1557 struct d3dx_parameter *param = get_valid_parameter(This, object);
1558 struct d3dx_pass *pass = is_valid_pass(This, object);
1559 struct d3dx_technique *technique = is_valid_technique(This, object);
1560 UINT annotation_count = 0, i;
1561 D3DXHANDLE *annotation_handles = NULL;
1563 FIXME("iface %p, object %p, name %s partial stub\n", This, object, debugstr_a(name));
1565 if (!name)
1567 WARN("Invalid argument specified\n");
1568 return NULL;
1571 if (pass)
1573 annotation_count = pass->annotation_count;
1574 annotation_handles = pass->annotation_handles;
1576 else if (technique)
1578 annotation_count = technique->annotation_count;
1579 annotation_handles = technique->annotation_handles;
1581 else if (param)
1583 annotation_count = param->annotation_count;
1584 annotation_handles = param->annotation_handles;
1586 /* Todo: add funcs */
1588 for (i = 0; i < annotation_count; i++)
1590 struct d3dx_parameter *anno = get_parameter_struct(annotation_handles[i]);
1592 if (!strcmp(anno->name, name))
1594 TRACE("Returning parameter %p\n", anno);
1595 return get_parameter_handle(anno);
1599 WARN("Invalid argument specified\n");
1601 return NULL;
1604 static HRESULT WINAPI ID3DXBaseEffectImpl_SetValue(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
1606 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1607 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1609 TRACE("iface %p, parameter %p, data %p, bytes %u\n", This, parameter, data, bytes);
1611 if (!param)
1613 WARN("Invalid parameter %p specified\n", parameter);
1614 return D3DERR_INVALIDCALL;
1617 /* samplers don't touch data */
1618 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1619 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1620 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1622 TRACE("Sampler: returning E_FAIL\n");
1623 return E_FAIL;
1626 if (data && param->bytes <= bytes)
1628 switch (param->type)
1630 case D3DXPT_VOID:
1631 case D3DXPT_BOOL:
1632 case D3DXPT_INT:
1633 case D3DXPT_FLOAT:
1634 TRACE("Copy %u bytes\n", param->bytes);
1635 memcpy(param->data, data, param->bytes);
1636 break;
1638 default:
1639 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1640 break;
1643 return D3D_OK;
1646 WARN("Invalid argument specified\n");
1648 return D3DERR_INVALIDCALL;
1651 static HRESULT WINAPI ID3DXBaseEffectImpl_GetValue(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
1653 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1654 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1656 TRACE("iface %p, parameter %p, data %p, bytes %u\n", This, parameter, data, bytes);
1658 if (!param)
1660 WARN("Invalid parameter %p specified\n", parameter);
1661 return D3DERR_INVALIDCALL;
1664 /* samplers don't touch data */
1665 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1666 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1667 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1669 TRACE("Sampler: returning E_FAIL\n");
1670 return E_FAIL;
1673 if (data && param->bytes <= bytes)
1675 TRACE("Type %s\n", debug_d3dxparameter_type(param->type));
1677 switch (param->type)
1679 case D3DXPT_VOID:
1680 case D3DXPT_BOOL:
1681 case D3DXPT_INT:
1682 case D3DXPT_FLOAT:
1683 case D3DXPT_STRING:
1684 break;
1686 case D3DXPT_VERTEXSHADER:
1687 case D3DXPT_PIXELSHADER:
1688 case D3DXPT_TEXTURE:
1689 case D3DXPT_TEXTURE1D:
1690 case D3DXPT_TEXTURE2D:
1691 case D3DXPT_TEXTURE3D:
1692 case D3DXPT_TEXTURECUBE:
1694 UINT i;
1696 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1698 IUnknown *unk = ((IUnknown **)param->data)[i];
1699 if (unk) IUnknown_AddRef(unk);
1701 break;
1704 default:
1705 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1706 break;
1709 TRACE("Copy %u bytes\n", param->bytes);
1710 memcpy(data, param->data, param->bytes);
1711 return D3D_OK;
1714 WARN("Invalid argument specified\n");
1716 return D3DERR_INVALIDCALL;
1719 static HRESULT WINAPI ID3DXBaseEffectImpl_SetBool(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL b)
1721 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1722 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1724 TRACE("iface %p, parameter %p, b %s\n", This, parameter, b ? "TRUE" : "FALSE");
1726 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1728 /* crop input */
1729 b = b ? TRUE : FALSE;
1730 set_number(param->data, param->type, &b, D3DXPT_BOOL);
1731 return D3D_OK;
1734 WARN("Invalid argument specified\n");
1736 return D3DERR_INVALIDCALL;
1739 static HRESULT WINAPI ID3DXBaseEffectImpl_GetBool(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL *b)
1741 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1742 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1744 TRACE("iface %p, parameter %p, b %p\n", This, parameter, b);
1746 if (b && param && !param->element_count && param->rows == 1 && param->columns == 1)
1748 *b = get_bool(param->data);
1749 TRACE("Returning %s\n", *b ? "TRUE" : "FALSE");
1750 return D3D_OK;
1753 WARN("Invalid argument specified\n");
1755 return D3DERR_INVALIDCALL;
1758 static HRESULT WINAPI ID3DXBaseEffectImpl_SetBoolArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
1760 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1761 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1763 TRACE("iface %p, parameter %p, b %p, count %u\n", This, parameter, b, count);
1765 if (param)
1767 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1769 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1771 switch (param->class)
1773 case D3DXPC_SCALAR:
1774 case D3DXPC_VECTOR:
1775 case D3DXPC_MATRIX_ROWS:
1776 for (i = 0; i < size; ++i)
1778 set_number((DWORD *)param->data + i, param->type, &b[i], D3DXPT_BOOL);
1780 return D3D_OK;
1782 case D3DXPC_OBJECT:
1783 case D3DXPC_STRUCT:
1784 break;
1786 default:
1787 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1788 break;
1792 WARN("Invalid argument specified\n");
1794 return D3DERR_INVALIDCALL;
1797 static HRESULT WINAPI ID3DXBaseEffectImpl_GetBoolArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
1799 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1800 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1802 TRACE("iface %p, parameter %p, b %p, count %u\n", This, parameter, b, count);
1804 if (b && param && (param->class == D3DXPC_SCALAR
1805 || param->class == D3DXPC_VECTOR
1806 || param->class == D3DXPC_MATRIX_ROWS
1807 || param->class == D3DXPC_MATRIX_COLUMNS))
1809 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1811 for (i = 0; i < size; ++i)
1813 b[i] = get_bool((DWORD *)param->data + i);
1815 return D3D_OK;
1818 WARN("Invalid argument specified\n");
1820 return D3DERR_INVALIDCALL;
1823 static HRESULT WINAPI ID3DXBaseEffectImpl_SetInt(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT n)
1825 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1826 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1828 TRACE("iface %p, parameter %p, n %i\n", This, parameter, n);
1830 if (param && !param->element_count)
1832 if (param->rows == 1 && param->columns == 1)
1834 set_number(param->data, param->type, &n, D3DXPT_INT);
1835 return D3D_OK;
1839 * Split the value, if parameter is a vector with dimension 3 or 4.
1841 if (param->type == D3DXPT_FLOAT &&
1842 ((param->class == D3DXPC_VECTOR && param->columns != 2) ||
1843 (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1845 TRACE("Vector fixup\n");
1847 *(FLOAT *)param->data = ((n & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1848 ((FLOAT *)param->data)[1] = ((n & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1849 ((FLOAT *)param->data)[2] = (n & 0xff) * INT_FLOAT_MULTI_INVERSE;
1850 if (param->rows * param->columns > 3)
1852 ((FLOAT *)param->data)[3] = ((n & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1854 return D3D_OK;
1858 WARN("Invalid argument specified\n");
1860 return D3DERR_INVALIDCALL;
1863 static HRESULT WINAPI ID3DXBaseEffectImpl_GetInt(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT *n)
1865 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1866 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1868 TRACE("iface %p, parameter %p, n %p\n", This, parameter, n);
1870 if (n && param && !param->element_count)
1872 if (param->columns == 1 && param->rows == 1)
1874 *n = get_int(param->type, param->data);
1875 TRACE("Returning %i\n", *n);
1876 return D3D_OK;
1879 if (param->type == D3DXPT_FLOAT &&
1880 ((param->class == D3DXPC_VECTOR && param->columns != 2)
1881 || (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1883 TRACE("Vector fixup\n");
1885 /* all components (3,4) are clamped (0,255) and put in the INT */
1886 *n = (INT)(min(max(0.0f, *((FLOAT *)param->data + 2)), 1.0f) * INT_FLOAT_MULTI);
1887 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 1)), 1.0f) * INT_FLOAT_MULTI)) << 8;
1888 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 0)), 1.0f) * INT_FLOAT_MULTI)) << 16;
1889 if (param->columns * param->rows > 3)
1891 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 3)), 1.0f) * INT_FLOAT_MULTI)) << 24;
1894 TRACE("Returning %i\n", *n);
1895 return D3D_OK;
1899 WARN("Invalid argument specified\n");
1901 return D3DERR_INVALIDCALL;
1904 static HRESULT WINAPI ID3DXBaseEffectImpl_SetIntArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
1906 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1907 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1909 TRACE("iface %p, parameter %p, n %p, count %u\n", This, parameter, n, count);
1911 if (param)
1913 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1915 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1917 switch (param->class)
1919 case D3DXPC_SCALAR:
1920 case D3DXPC_VECTOR:
1921 case D3DXPC_MATRIX_ROWS:
1922 for (i = 0; i < size; ++i)
1924 set_number((DWORD *)param->data + i, param->type, &n[i], D3DXPT_INT);
1926 return D3D_OK;
1928 case D3DXPC_OBJECT:
1929 case D3DXPC_STRUCT:
1930 break;
1932 default:
1933 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1934 break;
1938 WARN("Invalid argument specified\n");
1940 return D3DERR_INVALIDCALL;
1943 static HRESULT WINAPI ID3DXBaseEffectImpl_GetIntArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, INT *n, UINT count)
1945 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1946 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1948 TRACE("iface %p, parameter %p, n %p, count %u\n", This, parameter, n, count);
1950 if (n && param && (param->class == D3DXPC_SCALAR
1951 || param->class == D3DXPC_VECTOR
1952 || param->class == D3DXPC_MATRIX_ROWS
1953 || param->class == D3DXPC_MATRIX_COLUMNS))
1955 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1957 for (i = 0; i < size; ++i)
1959 n[i] = get_int(param->type, (DWORD *)param->data + i);
1961 return D3D_OK;
1964 WARN("Invalid argument specified\n");
1966 return D3DERR_INVALIDCALL;
1969 static HRESULT WINAPI ID3DXBaseEffectImpl_SetFloat(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT f)
1971 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1972 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1974 TRACE("iface %p, parameter %p, f %f\n", This, parameter, f);
1976 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1978 set_number((DWORD *)param->data, param->type, &f, D3DXPT_FLOAT);
1979 return D3D_OK;
1982 WARN("Invalid argument specified\n");
1984 return D3DERR_INVALIDCALL;
1987 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFloat(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT *f)
1989 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
1990 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
1992 TRACE("iface %p, parameter %p, f %p\n", This, parameter, f);
1994 if (f && param && !param->element_count && param->columns == 1 && param->rows == 1)
1996 *f = get_float(param->type, (DWORD *)param->data);
1997 TRACE("Returning %f\n", *f);
1998 return D3D_OK;
2001 WARN("Invalid argument specified\n");
2003 return D3DERR_INVALIDCALL;
2006 static HRESULT WINAPI ID3DXBaseEffectImpl_SetFloatArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
2008 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2009 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2011 TRACE("iface %p, parameter %p, f %p, count %u\n", This, parameter, f, count);
2013 if (param)
2015 UINT i, size = min(count, param->bytes / sizeof(DWORD));
2017 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2019 switch (param->class)
2021 case D3DXPC_SCALAR:
2022 case D3DXPC_VECTOR:
2023 case D3DXPC_MATRIX_ROWS:
2024 for (i = 0; i < size; ++i)
2026 set_number((DWORD *)param->data + i, param->type, &f[i], D3DXPT_FLOAT);
2028 return D3D_OK;
2030 case D3DXPC_OBJECT:
2031 case D3DXPC_STRUCT:
2032 break;
2034 default:
2035 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2036 break;
2040 WARN("Invalid argument specified\n");
2042 return D3DERR_INVALIDCALL;
2045 static HRESULT WINAPI ID3DXBaseEffectImpl_GetFloatArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
2047 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2048 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2050 TRACE("iface %p, parameter %p, f %p, count %u\n", This, parameter, f, count);
2052 if (f && param && (param->class == D3DXPC_SCALAR
2053 || param->class == D3DXPC_VECTOR
2054 || param->class == D3DXPC_MATRIX_ROWS
2055 || param->class == D3DXPC_MATRIX_COLUMNS))
2057 UINT i, size = min(count, param->bytes / sizeof(DWORD));
2059 for (i = 0; i < size; ++i)
2061 f[i] = get_float(param->type, (DWORD *)param->data + i);
2063 return D3D_OK;
2066 WARN("Invalid argument specified\n");
2068 return D3DERR_INVALIDCALL;
2071 static HRESULT WINAPI ID3DXBaseEffectImpl_SetVector(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
2073 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2074 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2076 TRACE("iface %p, parameter %p, vector %p\n", This, parameter, vector);
2078 if (param && !param->element_count)
2080 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2082 switch (param->class)
2084 case D3DXPC_SCALAR:
2085 case D3DXPC_VECTOR:
2086 if (param->type == D3DXPT_INT && param->bytes == 4)
2088 DWORD tmp;
2090 TRACE("INT fixup\n");
2091 tmp = (DWORD)(max(min(vector->z, 1.0f), 0.0f) * INT_FLOAT_MULTI);
2092 tmp += ((DWORD)(max(min(vector->y, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 8;
2093 tmp += ((DWORD)(max(min(vector->x, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 16;
2094 tmp += ((DWORD)(max(min(vector->w, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 24;
2096 *(INT *)param->data = tmp;
2097 return D3D_OK;
2099 set_vector(param, vector);
2100 return D3D_OK;
2102 case D3DXPC_MATRIX_ROWS:
2103 case D3DXPC_OBJECT:
2104 case D3DXPC_STRUCT:
2105 break;
2107 default:
2108 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2109 break;
2113 WARN("Invalid argument specified\n");
2115 return D3DERR_INVALIDCALL;
2118 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVector(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
2120 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2121 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2123 TRACE("iface %p, parameter %p, vector %p\n", This, parameter, vector);
2125 if (vector && param && !param->element_count)
2127 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2129 switch (param->class)
2131 case D3DXPC_SCALAR:
2132 case D3DXPC_VECTOR:
2133 if (param->type == D3DXPT_INT && param->bytes == 4)
2135 TRACE("INT fixup\n");
2136 vector->x = (((*(INT *)param->data) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
2137 vector->y = (((*(INT *)param->data) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
2138 vector->z = ((*(INT *)param->data) & 0xff) * INT_FLOAT_MULTI_INVERSE;
2139 vector->w = (((*(INT *)param->data) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
2140 return D3D_OK;
2142 get_vector(param, vector);
2143 return D3D_OK;
2145 case D3DXPC_MATRIX_ROWS:
2146 case D3DXPC_OBJECT:
2147 case D3DXPC_STRUCT:
2148 break;
2150 default:
2151 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2152 break;
2156 WARN("Invalid argument specified\n");
2158 return D3DERR_INVALIDCALL;
2161 static HRESULT WINAPI ID3DXBaseEffectImpl_SetVectorArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
2163 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2164 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2166 TRACE("iface %p, parameter %p, vector %p, count %u stub\n", This, parameter, vector, count);
2168 if (param && param->element_count && param->element_count >= count)
2170 UINT i;
2172 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2174 switch (param->class)
2176 case D3DXPC_VECTOR:
2177 for (i = 0; i < count; ++i)
2179 set_vector(get_parameter_struct(param->member_handles[i]), &vector[i]);
2181 return D3D_OK;
2183 case D3DXPC_SCALAR:
2184 case D3DXPC_MATRIX_ROWS:
2185 case D3DXPC_OBJECT:
2186 case D3DXPC_STRUCT:
2187 break;
2189 default:
2190 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2191 break;
2195 WARN("Invalid argument specified\n");
2197 return D3DERR_INVALIDCALL;
2200 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVectorArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
2202 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2203 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2205 TRACE("iface %p, parameter %p, vector %p, count %u\n", This, parameter, vector, count);
2207 if (!count) return D3D_OK;
2209 if (vector && param && count <= param->element_count)
2211 UINT i;
2213 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2215 switch (param->class)
2217 case D3DXPC_VECTOR:
2218 for (i = 0; i < count; ++i)
2220 get_vector(get_parameter_struct(param->member_handles[i]), &vector[i]);
2222 return D3D_OK;
2224 case D3DXPC_SCALAR:
2225 case D3DXPC_MATRIX_ROWS:
2226 case D3DXPC_OBJECT:
2227 case D3DXPC_STRUCT:
2228 break;
2230 default:
2231 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2232 break;
2236 WARN("Invalid argument specified\n");
2238 return D3DERR_INVALIDCALL;
2241 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrix(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
2243 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2244 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2246 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2248 if (param && !param->element_count)
2250 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2252 switch (param->class)
2254 case D3DXPC_MATRIX_ROWS:
2255 set_matrix(param, matrix);
2256 return D3D_OK;
2258 case D3DXPC_SCALAR:
2259 case D3DXPC_VECTOR:
2260 case D3DXPC_OBJECT:
2261 case D3DXPC_STRUCT:
2262 break;
2264 default:
2265 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2266 break;
2270 WARN("Invalid argument specified\n");
2272 return D3DERR_INVALIDCALL;
2275 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrix(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
2277 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2278 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2280 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2282 if (matrix && param && !param->element_count)
2284 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2286 switch (param->class)
2288 case D3DXPC_MATRIX_ROWS:
2289 get_matrix(param, matrix);
2290 return D3D_OK;
2292 case D3DXPC_SCALAR:
2293 case D3DXPC_VECTOR:
2294 case D3DXPC_OBJECT:
2295 case D3DXPC_STRUCT:
2296 break;
2298 default:
2299 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2300 break;
2304 WARN("Invalid argument specified\n");
2306 return D3DERR_INVALIDCALL;
2309 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
2311 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2312 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2314 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2316 if (param && param->element_count >= count)
2318 UINT i;
2320 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2322 switch (param->class)
2324 case D3DXPC_MATRIX_ROWS:
2325 for (i = 0; i < count; ++i)
2327 set_matrix(get_parameter_struct(param->member_handles[i]), &matrix[i]);
2329 return D3D_OK;
2331 case D3DXPC_SCALAR:
2332 case D3DXPC_VECTOR:
2333 case D3DXPC_OBJECT:
2334 case D3DXPC_STRUCT:
2335 break;
2337 default:
2338 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2339 break;
2343 WARN("Invalid argument specified\n");
2345 return D3DERR_INVALIDCALL;
2348 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2350 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2351 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2353 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2355 if (!count) return D3D_OK;
2357 if (matrix && param && count <= param->element_count)
2359 UINT i;
2361 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2363 switch (param->class)
2365 case D3DXPC_MATRIX_ROWS:
2366 for (i = 0; i < count; ++i)
2368 get_matrix(get_parameter_struct(param->member_handles[i]), &matrix[i]);
2370 return D3D_OK;
2372 case D3DXPC_SCALAR:
2373 case D3DXPC_VECTOR:
2374 case D3DXPC_OBJECT:
2375 case D3DXPC_STRUCT:
2376 break;
2378 default:
2379 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2380 break;
2384 WARN("Invalid argument specified\n");
2386 return D3DERR_INVALIDCALL;
2389 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixPointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
2391 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2392 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2394 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2396 if (param && count <= param->element_count)
2398 UINT i;
2400 switch (param->class)
2402 case D3DXPC_MATRIX_ROWS:
2403 for (i = 0; i < count; ++i)
2405 set_matrix(get_parameter_struct(param->member_handles[i]), matrix[i]);
2407 return D3D_OK;
2409 case D3DXPC_SCALAR:
2410 case D3DXPC_VECTOR:
2411 case D3DXPC_OBJECT:
2412 break;
2414 default:
2415 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2416 break;
2420 WARN("Invalid argument specified\n");
2422 return D3DERR_INVALIDCALL;
2425 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixPointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2427 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2429 FIXME("iface %p, parameter %p, matrix %p, count %u stub\n", This, parameter, matrix, count);
2431 return E_NOTIMPL;
2434 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTranspose(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
2436 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2437 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2438 D3DXMATRIX m;
2440 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2442 if (param && !param->element_count)
2444 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2446 switch (param->class)
2448 case D3DXPC_MATRIX_ROWS:
2449 set_matrix(param, D3DXMatrixTranspose(&m, matrix));
2450 return D3D_OK;
2452 case D3DXPC_SCALAR:
2453 case D3DXPC_VECTOR:
2454 case D3DXPC_OBJECT:
2455 case D3DXPC_STRUCT:
2456 break;
2458 default:
2459 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2460 break;
2464 WARN("Invalid argument specified\n");
2466 return D3DERR_INVALIDCALL;
2469 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTranspose(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
2471 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2472 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2473 D3DXMATRIX m;
2475 TRACE("iface %p, parameter %p, matrix %p\n", This, parameter, matrix);
2477 if (matrix && param && !param->element_count)
2479 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2481 switch (param->class)
2483 case D3DXPC_SCALAR:
2484 case D3DXPC_VECTOR:
2485 get_matrix(param, matrix);
2486 return D3D_OK;
2488 case D3DXPC_MATRIX_ROWS:
2489 get_matrix(param, &m);
2490 D3DXMatrixTranspose(matrix, &m);
2491 return D3D_OK;
2493 case D3DXPC_OBJECT:
2494 case D3DXPC_STRUCT:
2495 break;
2497 default:
2498 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2499 break;
2503 WARN("Invalid argument specified\n");
2505 return D3DERR_INVALIDCALL;
2508 static HRESULT WINAPI ID3DXBaseEffectImpl_SetMatrixTransposeArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
2510 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2511 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2512 D3DXMATRIX m;
2514 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2516 if (param && param->element_count >= count)
2518 UINT i;
2520 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2522 switch (param->class)
2524 case D3DXPC_MATRIX_ROWS:
2525 for (i = 0; i < count; ++i)
2527 set_matrix(get_parameter_struct(param->member_handles[i]), D3DXMatrixTranspose(&m, &matrix[i]));
2529 return D3D_OK;
2531 case D3DXPC_SCALAR:
2532 case D3DXPC_VECTOR:
2533 case D3DXPC_OBJECT:
2534 case D3DXPC_STRUCT:
2535 break;
2537 default:
2538 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2539 break;
2543 WARN("Invalid argument specified\n");
2545 return D3DERR_INVALIDCALL;
2548 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTransposeArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2550 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2551 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2553 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2555 if (!count) return D3D_OK;
2557 if (matrix && param && count <= param->element_count)
2559 UINT i;
2561 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2563 switch (param->class)
2565 case D3DXPC_MATRIX_ROWS:
2566 for (i = 0; i < count; ++i)
2568 D3DXMATRIX m;
2570 get_matrix(get_parameter_struct(param->member_handles[i]), &m);
2571 D3DXMatrixTranspose(&matrix[i], &m);
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_SetMatrixTransposePointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
2594 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2595 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2596 D3DXMATRIX m;
2598 TRACE("iface %p, parameter %p, matrix %p, count %u\n", This, parameter, matrix, count);
2600 if (param && count <= param->element_count)
2602 UINT i;
2604 switch (param->class)
2606 case D3DXPC_MATRIX_ROWS:
2607 for (i = 0; i < count; ++i)
2609 set_matrix(get_parameter_struct(param->member_handles[i]), D3DXMatrixTranspose(&m, matrix[i]));
2611 return D3D_OK;
2613 case D3DXPC_SCALAR:
2614 case D3DXPC_VECTOR:
2615 case D3DXPC_OBJECT:
2616 break;
2618 default:
2619 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2620 break;
2624 WARN("Invalid argument specified\n");
2626 return D3DERR_INVALIDCALL;
2629 static HRESULT WINAPI ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(ID3DXBaseEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2631 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2633 FIXME("iface %p, parameter %p, matrix %p, count %u stub\n", This, parameter, matrix, count);
2635 return E_NOTIMPL;
2638 static HRESULT WINAPI ID3DXBaseEffectImpl_SetString(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR string)
2640 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2642 FIXME("iface %p, parameter %p, string %p stub\n", This, parameter, string);
2644 return E_NOTIMPL;
2647 static HRESULT WINAPI ID3DXBaseEffectImpl_GetString(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPCSTR *string)
2649 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2650 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2652 TRACE("iface %p, parameter %p, string %p\n", This, parameter, string);
2654 if (string && param && !param->element_count && param->type == D3DXPT_STRING)
2656 *string = *(LPCSTR *)param->data;
2657 TRACE("Returning %s\n", debugstr_a(*string));
2658 return D3D_OK;
2661 WARN("Invalid argument specified\n");
2663 return D3DERR_INVALIDCALL;
2666 static HRESULT WINAPI ID3DXBaseEffectImpl_SetTexture(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
2668 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2669 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2671 TRACE("iface %p, parameter %p, texture %p\n", This, parameter, texture);
2673 if (param && !param->element_count &&
2674 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2675 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2676 || param->type == D3DXPT_TEXTURECUBE))
2678 LPDIRECT3DBASETEXTURE9 oltexture = *(LPDIRECT3DBASETEXTURE9 *)param->data;
2680 if (texture) IDirect3DBaseTexture9_AddRef(texture);
2681 if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
2683 *(LPDIRECT3DBASETEXTURE9 *)param->data = texture;
2685 return D3D_OK;
2688 WARN("Invalid argument specified\n");
2690 return D3DERR_INVALIDCALL;
2693 static HRESULT WINAPI ID3DXBaseEffectImpl_GetTexture(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
2695 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2696 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2698 TRACE("iface %p, parameter %p, texture %p\n", This, parameter, texture);
2700 if (texture && param && !param->element_count &&
2701 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2702 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2703 || param->type == D3DXPT_TEXTURECUBE))
2705 *texture = *(LPDIRECT3DBASETEXTURE9 *)param->data;
2706 if (*texture) IDirect3DBaseTexture9_AddRef(*texture);
2707 TRACE("Returning %p\n", *texture);
2708 return D3D_OK;
2711 WARN("Invalid argument specified\n");
2713 return D3DERR_INVALIDCALL;
2716 static HRESULT WINAPI ID3DXBaseEffectImpl_GetPixelShader(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
2718 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2719 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2721 TRACE("iface %p, parameter %p, pshader %p\n", This, parameter, pshader);
2723 if (pshader && param && !param->element_count && param->type == D3DXPT_PIXELSHADER)
2725 *pshader = *(LPDIRECT3DPIXELSHADER9 *)param->data;
2726 if (*pshader) IDirect3DPixelShader9_AddRef(*pshader);
2727 TRACE("Returning %p\n", *pshader);
2728 return D3D_OK;
2731 WARN("Invalid argument specified\n");
2733 return D3DERR_INVALIDCALL;
2736 static HRESULT WINAPI ID3DXBaseEffectImpl_GetVertexShader(ID3DXBaseEffect *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
2738 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2739 struct d3dx_parameter *param = get_valid_parameter(This, parameter);
2741 TRACE("iface %p, parameter %p, vshader %p\n", This, parameter, vshader);
2743 if (vshader && param && !param->element_count && param->type == D3DXPT_VERTEXSHADER)
2745 *vshader = *(LPDIRECT3DVERTEXSHADER9 *)param->data;
2746 if (*vshader) IDirect3DVertexShader9_AddRef(*vshader);
2747 TRACE("Returning %p\n", *vshader);
2748 return D3D_OK;
2751 WARN("Invalid argument specified\n");
2753 return D3DERR_INVALIDCALL;
2756 static HRESULT WINAPI ID3DXBaseEffectImpl_SetArrayRange(ID3DXBaseEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
2758 struct ID3DXBaseEffectImpl *This = impl_from_ID3DXBaseEffect(iface);
2760 FIXME("iface %p, parameter %p, start %u, end %u stub\n", This, parameter, start, end);
2762 return E_NOTIMPL;
2765 static const struct ID3DXBaseEffectVtbl ID3DXBaseEffect_Vtbl =
2767 /*** IUnknown methods ***/
2768 ID3DXBaseEffectImpl_QueryInterface,
2769 ID3DXBaseEffectImpl_AddRef,
2770 ID3DXBaseEffectImpl_Release,
2771 /*** ID3DXBaseEffect methods ***/
2772 ID3DXBaseEffectImpl_GetDesc,
2773 ID3DXBaseEffectImpl_GetParameterDesc,
2774 ID3DXBaseEffectImpl_GetTechniqueDesc,
2775 ID3DXBaseEffectImpl_GetPassDesc,
2776 ID3DXBaseEffectImpl_GetFunctionDesc,
2777 ID3DXBaseEffectImpl_GetParameter,
2778 ID3DXBaseEffectImpl_GetParameterByName,
2779 ID3DXBaseEffectImpl_GetParameterBySemantic,
2780 ID3DXBaseEffectImpl_GetParameterElement,
2781 ID3DXBaseEffectImpl_GetTechnique,
2782 ID3DXBaseEffectImpl_GetTechniqueByName,
2783 ID3DXBaseEffectImpl_GetPass,
2784 ID3DXBaseEffectImpl_GetPassByName,
2785 ID3DXBaseEffectImpl_GetFunction,
2786 ID3DXBaseEffectImpl_GetFunctionByName,
2787 ID3DXBaseEffectImpl_GetAnnotation,
2788 ID3DXBaseEffectImpl_GetAnnotationByName,
2789 ID3DXBaseEffectImpl_SetValue,
2790 ID3DXBaseEffectImpl_GetValue,
2791 ID3DXBaseEffectImpl_SetBool,
2792 ID3DXBaseEffectImpl_GetBool,
2793 ID3DXBaseEffectImpl_SetBoolArray,
2794 ID3DXBaseEffectImpl_GetBoolArray,
2795 ID3DXBaseEffectImpl_SetInt,
2796 ID3DXBaseEffectImpl_GetInt,
2797 ID3DXBaseEffectImpl_SetIntArray,
2798 ID3DXBaseEffectImpl_GetIntArray,
2799 ID3DXBaseEffectImpl_SetFloat,
2800 ID3DXBaseEffectImpl_GetFloat,
2801 ID3DXBaseEffectImpl_SetFloatArray,
2802 ID3DXBaseEffectImpl_GetFloatArray,
2803 ID3DXBaseEffectImpl_SetVector,
2804 ID3DXBaseEffectImpl_GetVector,
2805 ID3DXBaseEffectImpl_SetVectorArray,
2806 ID3DXBaseEffectImpl_GetVectorArray,
2807 ID3DXBaseEffectImpl_SetMatrix,
2808 ID3DXBaseEffectImpl_GetMatrix,
2809 ID3DXBaseEffectImpl_SetMatrixArray,
2810 ID3DXBaseEffectImpl_GetMatrixArray,
2811 ID3DXBaseEffectImpl_SetMatrixPointerArray,
2812 ID3DXBaseEffectImpl_GetMatrixPointerArray,
2813 ID3DXBaseEffectImpl_SetMatrixTranspose,
2814 ID3DXBaseEffectImpl_GetMatrixTranspose,
2815 ID3DXBaseEffectImpl_SetMatrixTransposeArray,
2816 ID3DXBaseEffectImpl_GetMatrixTransposeArray,
2817 ID3DXBaseEffectImpl_SetMatrixTransposePointerArray,
2818 ID3DXBaseEffectImpl_GetMatrixTransposePointerArray,
2819 ID3DXBaseEffectImpl_SetString,
2820 ID3DXBaseEffectImpl_GetString,
2821 ID3DXBaseEffectImpl_SetTexture,
2822 ID3DXBaseEffectImpl_GetTexture,
2823 ID3DXBaseEffectImpl_GetPixelShader,
2824 ID3DXBaseEffectImpl_GetVertexShader,
2825 ID3DXBaseEffectImpl_SetArrayRange,
2828 static inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
2830 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
2833 /*** IUnknown methods ***/
2834 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
2836 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
2838 if (IsEqualGUID(riid, &IID_IUnknown) ||
2839 IsEqualGUID(riid, &IID_ID3DXEffect))
2841 iface->lpVtbl->AddRef(iface);
2842 *object = iface;
2843 return S_OK;
2846 ERR("Interface %s not found\n", debugstr_guid(riid));
2848 return E_NOINTERFACE;
2851 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
2853 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2855 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
2857 return InterlockedIncrement(&This->ref);
2860 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
2862 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2863 ULONG ref = InterlockedDecrement(&This->ref);
2865 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
2867 if (!ref)
2869 free_effect(This);
2870 HeapFree(GetProcessHeap(), 0, This);
2873 return ref;
2876 /*** ID3DXBaseEffect methods ***/
2877 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
2879 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2880 ID3DXBaseEffect *base = This->base_effect;
2882 TRACE("Forward iface %p, base %p\n", This, base);
2884 return ID3DXBaseEffectImpl_GetDesc(base, desc);
2887 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
2889 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2890 ID3DXBaseEffect *base = This->base_effect;
2892 TRACE("Forward iface %p, base %p\n", This, base);
2894 return ID3DXBaseEffectImpl_GetParameterDesc(base, parameter, desc);
2897 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
2899 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2900 ID3DXBaseEffect *base = This->base_effect;
2902 TRACE("Forward iface %p, base %p\n", This, base);
2904 return ID3DXBaseEffectImpl_GetTechniqueDesc(base, technique, desc);
2907 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
2909 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2910 ID3DXBaseEffect *base = This->base_effect;
2912 TRACE("Forward iface %p, base %p\n", This, base);
2914 return ID3DXBaseEffectImpl_GetPassDesc(base, pass, desc);
2917 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
2919 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2920 ID3DXBaseEffect *base = This->base_effect;
2922 TRACE("Forward iface %p, base %p\n", This, base);
2924 return ID3DXBaseEffectImpl_GetFunctionDesc(base, shader, desc);
2927 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2929 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2930 ID3DXBaseEffect *base = This->base_effect;
2932 TRACE("Forward iface %p, base %p\n", This, base);
2934 return ID3DXBaseEffectImpl_GetParameter(base, parameter, index);
2937 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR name)
2939 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2940 ID3DXBaseEffect *base = This->base_effect;
2942 TRACE("Forward iface %p, base %p\n", This, base);
2944 return ID3DXBaseEffectImpl_GetParameterByName(base, parameter, name);
2947 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR semantic)
2949 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2950 ID3DXBaseEffect *base = This->base_effect;
2952 TRACE("Forward iface %p, base %p\n", This, base);
2954 return ID3DXBaseEffectImpl_GetParameterBySemantic(base, parameter, semantic);
2957 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2959 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2960 ID3DXBaseEffect *base = This->base_effect;
2962 TRACE("Forward iface %p, base %p\n", This, base);
2964 return ID3DXBaseEffectImpl_GetParameterElement(base, parameter, index);
2967 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
2969 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2970 ID3DXBaseEffect *base = This->base_effect;
2972 TRACE("Forward iface %p, base %p\n", This, base);
2974 return ID3DXBaseEffectImpl_GetTechnique(base, index);
2977 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, LPCSTR name)
2979 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2980 ID3DXBaseEffect *base = This->base_effect;
2982 TRACE("Forward iface %p, base %p\n", This, base);
2984 return ID3DXBaseEffectImpl_GetTechniqueByName(base, name);
2987 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
2989 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2990 ID3DXBaseEffect *base = This->base_effect;
2992 TRACE("Forward iface %p, base %p\n", This, base);
2994 return ID3DXBaseEffectImpl_GetPass(base, technique, index);
2997 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface, D3DXHANDLE technique, LPCSTR name)
2999 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3000 ID3DXBaseEffect *base = This->base_effect;
3002 TRACE("Forward iface %p, base %p\n", This, base);
3004 return ID3DXBaseEffectImpl_GetPassByName(base, technique, name);
3007 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
3009 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3010 ID3DXBaseEffect *base = This->base_effect;
3012 TRACE("Forward iface %p, base %p\n", This, base);
3014 return ID3DXBaseEffectImpl_GetFunction(base, index);
3017 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, LPCSTR name)
3019 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3020 ID3DXBaseEffect *base = This->base_effect;
3022 TRACE("Forward iface %p, base %p\n", This, base);
3024 return ID3DXBaseEffectImpl_GetFunctionByName(base, name);
3027 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
3029 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3030 ID3DXBaseEffect *base = This->base_effect;
3032 TRACE("Forward iface %p, base %p\n", This, base);
3034 return ID3DXBaseEffectImpl_GetAnnotation(base, object, index);
3037 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface, D3DXHANDLE object, LPCSTR name)
3039 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3040 ID3DXBaseEffect *base = This->base_effect;
3042 TRACE("Forward iface %p, base %p\n", This, base);
3044 return ID3DXBaseEffectImpl_GetAnnotationByName(base, object, name);
3047 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
3049 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3050 ID3DXBaseEffect *base = This->base_effect;
3052 TRACE("Forward iface %p, base %p\n", This, base);
3054 return ID3DXBaseEffectImpl_SetValue(base, parameter, data, bytes);
3057 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
3059 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3060 ID3DXBaseEffect *base = This->base_effect;
3062 TRACE("Forward iface %p, base %p\n", This, base);
3064 return ID3DXBaseEffectImpl_GetValue(base, parameter, data, bytes);
3067 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
3069 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3070 ID3DXBaseEffect *base = This->base_effect;
3072 TRACE("Forward iface %p, base %p\n", This, base);
3074 return ID3DXBaseEffectImpl_SetBool(base, parameter, b);
3077 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
3079 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3080 ID3DXBaseEffect *base = This->base_effect;
3082 TRACE("Forward iface %p, base %p\n", This, base);
3084 return ID3DXBaseEffectImpl_GetBool(base, parameter, b);
3087 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
3089 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3090 ID3DXBaseEffect *base = This->base_effect;
3092 TRACE("Forward iface %p, base %p\n", This, base);
3094 return ID3DXBaseEffectImpl_SetBoolArray(base, parameter, b, count);
3097 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
3099 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3100 ID3DXBaseEffect *base = This->base_effect;
3102 TRACE("Forward iface %p, base %p\n", This, base);
3104 return ID3DXBaseEffectImpl_GetBoolArray(base, parameter, b, count);
3107 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
3109 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3110 ID3DXBaseEffect *base = This->base_effect;
3112 TRACE("Forward iface %p, base %p\n", This, base);
3114 return ID3DXBaseEffectImpl_SetInt(base, parameter, n);
3117 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
3119 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3120 ID3DXBaseEffect *base = This->base_effect;
3122 TRACE("Forward iface %p, base %p\n", This, base);
3124 return ID3DXBaseEffectImpl_GetInt(base, parameter, n);
3127 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
3129 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3130 ID3DXBaseEffect *base = This->base_effect;
3132 TRACE("Forward iface %p, base %p\n", This, base);
3134 return ID3DXBaseEffectImpl_SetIntArray(base, parameter, n, count);
3137 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n, UINT count)
3139 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3140 ID3DXBaseEffect *base = This->base_effect;
3142 TRACE("Forward iface %p, base %p\n", This, base);
3144 return ID3DXBaseEffectImpl_GetIntArray(base, parameter, n, count);
3147 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT f)
3149 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3150 ID3DXBaseEffect *base = This->base_effect;
3152 TRACE("Forward iface %p, base %p\n", This, base);
3154 return ID3DXBaseEffectImpl_SetFloat(base, parameter, f);
3157 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT *f)
3159 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3160 ID3DXBaseEffect *base = This->base_effect;
3162 TRACE("Forward iface %p, base %p\n", This, base);
3164 return ID3DXBaseEffectImpl_GetFloat(base, parameter, f);
3167 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
3169 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3170 ID3DXBaseEffect *base = This->base_effect;
3172 TRACE("Forward iface %p, base %p\n", This, base);
3174 return ID3DXBaseEffectImpl_SetFloatArray(base, parameter, f, count);
3177 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
3179 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3180 ID3DXBaseEffect *base = This->base_effect;
3182 TRACE("Forward iface %p, base %p\n", This, base);
3184 return ID3DXBaseEffectImpl_GetFloatArray(base, parameter, f, count);
3187 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
3189 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3190 ID3DXBaseEffect *base = This->base_effect;
3192 TRACE("Forward iface %p, base %p\n", This, base);
3194 return ID3DXBaseEffectImpl_SetVector(base, parameter, vector);
3197 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
3199 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3200 ID3DXBaseEffect *base = This->base_effect;
3202 TRACE("Forward iface %p, base %p\n", This, base);
3204 return ID3DXBaseEffectImpl_GetVector(base, parameter, vector);
3207 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
3209 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3210 ID3DXBaseEffect *base = This->base_effect;
3212 TRACE("Forward iface %p, base %p\n", This, base);
3214 return ID3DXBaseEffectImpl_SetVectorArray(base, parameter, vector, count);
3217 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
3219 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3220 ID3DXBaseEffect *base = This->base_effect;
3222 TRACE("Forward iface %p, base %p\n", This, base);
3224 return ID3DXBaseEffectImpl_GetVectorArray(base, parameter, vector, count);
3227 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
3229 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3230 ID3DXBaseEffect *base = This->base_effect;
3232 TRACE("Forward iface %p, base %p\n", This, base);
3234 return ID3DXBaseEffectImpl_SetMatrix(base, parameter, matrix);
3237 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
3239 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3240 ID3DXBaseEffect *base = This->base_effect;
3242 TRACE("Forward iface %p, base %p\n", This, base);
3244 return ID3DXBaseEffectImpl_GetMatrix(base, parameter, matrix);
3247 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
3249 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3250 ID3DXBaseEffect *base = This->base_effect;
3252 TRACE("Forward iface %p, base %p\n", This, base);
3254 return ID3DXBaseEffectImpl_SetMatrixArray(base, parameter, matrix, count);
3257 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3259 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3260 ID3DXBaseEffect *base = This->base_effect;
3262 TRACE("Forward iface %p, base %p\n", This, base);
3264 return ID3DXBaseEffectImpl_GetMatrixArray(base, parameter, matrix, count);
3267 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
3269 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3270 ID3DXBaseEffect *base = This->base_effect;
3272 TRACE("Forward iface %p, base %p\n", This, base);
3274 return ID3DXBaseEffectImpl_SetMatrixPointerArray(base, parameter, matrix, count);
3277 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3279 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3280 ID3DXBaseEffect *base = This->base_effect;
3282 TRACE("Forward iface %p, base %p\n", This, base);
3284 return ID3DXBaseEffectImpl_GetMatrixPointerArray(base, parameter, matrix, count);
3287 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
3289 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3290 ID3DXBaseEffect *base = This->base_effect;
3292 TRACE("Forward iface %p, base %p\n", This, base);
3294 return ID3DXBaseEffectImpl_SetMatrixTranspose(base, parameter, matrix);
3297 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
3299 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3300 ID3DXBaseEffect *base = This->base_effect;
3302 TRACE("Forward iface %p, base %p\n", This, base);
3304 return ID3DXBaseEffectImpl_GetMatrixTranspose(base, parameter, matrix);
3307 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
3309 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3310 ID3DXBaseEffect *base = This->base_effect;
3312 TRACE("Forward iface %p, base %p\n", This, base);
3314 return ID3DXBaseEffectImpl_SetMatrixTransposeArray(base, parameter, matrix, count);
3317 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
3319 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3320 ID3DXBaseEffect *base = This->base_effect;
3322 TRACE("Forward iface %p, base %p\n", This, base);
3324 return ID3DXBaseEffectImpl_GetMatrixTransposeArray(base, parameter, matrix, count);
3327 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
3329 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3330 ID3DXBaseEffect *base = This->base_effect;
3332 TRACE("Forward iface %p, base %p\n", This, base);
3334 return ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(base, parameter, matrix, count);
3337 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
3339 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3340 ID3DXBaseEffect *base = This->base_effect;
3342 TRACE("Forward iface %p, base %p\n", This, base);
3344 return ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(base, parameter, matrix, count);
3347 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR string)
3349 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3350 ID3DXBaseEffect *base = This->base_effect;
3352 TRACE("Forward iface %p, base %p\n", This, base);
3354 return ID3DXBaseEffectImpl_SetString(base, parameter, string);
3357 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, LPCSTR *string)
3359 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3360 ID3DXBaseEffect *base = This->base_effect;
3362 TRACE("Forward iface %p, base %p\n", This, base);
3364 return ID3DXBaseEffectImpl_GetString(base, parameter, string);
3367 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
3369 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3370 ID3DXBaseEffect *base = This->base_effect;
3372 TRACE("Forward iface %p, base %p\n", This, base);
3374 return ID3DXBaseEffectImpl_SetTexture(base, parameter, texture);
3377 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
3379 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3380 ID3DXBaseEffect *base = This->base_effect;
3382 TRACE("Forward iface %p, base %p\n", This, base);
3384 return ID3DXBaseEffectImpl_GetTexture(base, parameter, texture);
3387 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
3389 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3390 ID3DXBaseEffect *base = This->base_effect;
3392 TRACE("Forward iface %p, base %p\n", This, base);
3394 return ID3DXBaseEffectImpl_GetPixelShader(base, parameter, pshader);
3397 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(ID3DXEffect *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
3399 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3400 ID3DXBaseEffect *base = This->base_effect;
3402 TRACE("Forward iface %p, base %p\n", This, base);
3404 return ID3DXBaseEffectImpl_GetVertexShader(base, parameter, vshader);
3407 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3409 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3410 ID3DXBaseEffect *base = This->base_effect;
3412 TRACE("Forward iface %p, base %p\n", This, base);
3414 return ID3DXBaseEffectImpl_SetArrayRange(base, parameter, start, end);
3417 /*** ID3DXEffect methods ***/
3418 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, LPD3DXEFFECTPOOL *pool)
3420 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3422 TRACE("iface %p, pool %p\n", This, pool);
3424 if (!pool)
3426 WARN("Invalid argument supplied.\n");
3427 return D3DERR_INVALIDCALL;
3430 if (This->pool)
3432 This->pool->lpVtbl->AddRef(This->pool);
3435 *pool = This->pool;
3437 TRACE("Returning pool %p\n", *pool);
3439 return S_OK;
3442 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3444 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3445 struct ID3DXBaseEffectImpl *base = impl_from_ID3DXBaseEffect(This->base_effect);
3446 struct d3dx_technique *tech = is_valid_technique(base, technique);
3448 TRACE("iface %p, technique %p\n", This, technique);
3450 if (!tech) tech = get_technique_struct(iface->lpVtbl->GetTechniqueByName(iface, technique));
3452 if (tech)
3454 UINT i;
3456 for (i = 0; i < base->technique_count; ++i)
3458 struct d3dx_technique *t = get_technique_struct(base->technique_handles[i]);
3460 if (tech == t)
3462 This->active_technique = get_technique_handle(t);
3463 TRACE("Technique %u (%p)\n", i, tech);
3464 return D3D_OK;
3469 WARN("Invalid argument supplied.\n");
3471 return D3DERR_INVALIDCALL;
3474 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3476 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3478 TRACE("iface %p\n", This);
3480 return This->active_technique;
3483 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3485 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3487 FIXME("(%p)->(%p): stub\n", This, technique);
3489 return D3D_OK;
3492 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3494 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3496 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3498 return E_NOTIMPL;
3501 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
3503 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3505 FIXME("(%p)->(%p, %p): stub\n", This, parameter, technique);
3507 return FALSE;
3510 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
3512 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3513 struct d3dx_technique *technique = get_technique_struct(This->active_technique);
3515 FIXME("iface %p, passes %p, flags %#x partial stub\n", This, passes, flags);
3517 if (passes && technique)
3519 if (This->manager || flags & D3DXFX_DONOTSAVESTATE)
3521 TRACE("State capturing disabled.\n");
3523 else
3525 FIXME("State capturing not supported, yet!\n");
3528 *passes = technique->pass_count;
3530 return D3D_OK;
3533 WARN("Invalid argument supplied.\n");
3535 return D3DERR_INVALIDCALL;
3538 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
3540 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3541 struct d3dx_technique *technique = get_technique_struct(This->active_technique);
3543 TRACE("iface %p, pass %u\n", This, pass);
3545 if (technique && pass < technique->pass_count && !This->active_pass)
3547 This->active_pass = technique->pass_handles[pass];
3549 FIXME("No states applied, yet!\n");
3551 return D3D_OK;
3554 WARN("Invalid argument supplied.\n");
3556 return D3DERR_INVALIDCALL;
3559 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect* iface)
3561 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3563 FIXME("(%p)->(): stub\n", This);
3565 return E_NOTIMPL;
3568 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
3570 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3572 TRACE("iface %p\n", This);
3574 if (This->active_pass)
3576 This->active_pass = NULL;
3577 return D3D_OK;
3580 WARN("Invalid call.\n");
3582 return D3DERR_INVALIDCALL;
3585 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect* iface)
3587 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3589 FIXME("(%p)->(): stub\n", This);
3591 return E_NOTIMPL;
3594 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, LPDIRECT3DDEVICE9 *device)
3596 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3598 TRACE("iface %p, device %p\n", This, device);
3600 if (!device)
3602 WARN("Invalid argument supplied.\n");
3603 return D3DERR_INVALIDCALL;
3606 IDirect3DDevice9_AddRef(This->device);
3608 *device = This->device;
3610 TRACE("Returning device %p\n", *device);
3612 return S_OK;
3615 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
3617 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3619 FIXME("(%p)->(): stub\n", This);
3621 return E_NOTIMPL;
3624 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(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_SetStateManager(ID3DXEffect *iface, LPD3DXEFFECTSTATEMANAGER manager)
3635 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3637 TRACE("iface %p, manager %p\n", This, manager);
3639 if (manager) IUnknown_AddRef(manager);
3640 if (This->manager) IUnknown_Release(This->manager);
3642 This->manager = manager;
3644 return D3D_OK;
3647 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, LPD3DXEFFECTSTATEMANAGER *manager)
3649 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3651 TRACE("iface %p, manager %p\n", This, manager);
3653 if (!manager)
3655 WARN("Invalid argument supplied.\n");
3656 return D3DERR_INVALIDCALL;
3659 if (This->manager) IUnknown_AddRef(This->manager);
3660 *manager = This->manager;
3662 return D3D_OK;
3665 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
3667 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3669 FIXME("(%p)->(): stub\n", This);
3671 return E_NOTIMPL;
3674 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
3676 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3678 FIXME("(%p)->(): stub\n", This);
3680 return NULL;
3683 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3685 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3687 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3689 return E_NOTIMPL;
3692 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3694 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3696 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3698 return E_NOTIMPL;
3701 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect* iface, LPDIRECT3DDEVICE9 device, LPD3DXEFFECT* effect)
3703 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3705 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
3707 return E_NOTIMPL;
3710 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect* iface, D3DXHANDLE parameter, LPCVOID data, UINT byte_offset, UINT bytes)
3712 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3714 FIXME("(%p)->(%p, %p, %u, %u): stub\n", This, parameter, data, byte_offset, bytes);
3716 return E_NOTIMPL;
3719 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
3721 /*** IUnknown methods ***/
3722 ID3DXEffectImpl_QueryInterface,
3723 ID3DXEffectImpl_AddRef,
3724 ID3DXEffectImpl_Release,
3725 /*** ID3DXBaseEffect methods ***/
3726 ID3DXEffectImpl_GetDesc,
3727 ID3DXEffectImpl_GetParameterDesc,
3728 ID3DXEffectImpl_GetTechniqueDesc,
3729 ID3DXEffectImpl_GetPassDesc,
3730 ID3DXEffectImpl_GetFunctionDesc,
3731 ID3DXEffectImpl_GetParameter,
3732 ID3DXEffectImpl_GetParameterByName,
3733 ID3DXEffectImpl_GetParameterBySemantic,
3734 ID3DXEffectImpl_GetParameterElement,
3735 ID3DXEffectImpl_GetTechnique,
3736 ID3DXEffectImpl_GetTechniqueByName,
3737 ID3DXEffectImpl_GetPass,
3738 ID3DXEffectImpl_GetPassByName,
3739 ID3DXEffectImpl_GetFunction,
3740 ID3DXEffectImpl_GetFunctionByName,
3741 ID3DXEffectImpl_GetAnnotation,
3742 ID3DXEffectImpl_GetAnnotationByName,
3743 ID3DXEffectImpl_SetValue,
3744 ID3DXEffectImpl_GetValue,
3745 ID3DXEffectImpl_SetBool,
3746 ID3DXEffectImpl_GetBool,
3747 ID3DXEffectImpl_SetBoolArray,
3748 ID3DXEffectImpl_GetBoolArray,
3749 ID3DXEffectImpl_SetInt,
3750 ID3DXEffectImpl_GetInt,
3751 ID3DXEffectImpl_SetIntArray,
3752 ID3DXEffectImpl_GetIntArray,
3753 ID3DXEffectImpl_SetFloat,
3754 ID3DXEffectImpl_GetFloat,
3755 ID3DXEffectImpl_SetFloatArray,
3756 ID3DXEffectImpl_GetFloatArray,
3757 ID3DXEffectImpl_SetVector,
3758 ID3DXEffectImpl_GetVector,
3759 ID3DXEffectImpl_SetVectorArray,
3760 ID3DXEffectImpl_GetVectorArray,
3761 ID3DXEffectImpl_SetMatrix,
3762 ID3DXEffectImpl_GetMatrix,
3763 ID3DXEffectImpl_SetMatrixArray,
3764 ID3DXEffectImpl_GetMatrixArray,
3765 ID3DXEffectImpl_SetMatrixPointerArray,
3766 ID3DXEffectImpl_GetMatrixPointerArray,
3767 ID3DXEffectImpl_SetMatrixTranspose,
3768 ID3DXEffectImpl_GetMatrixTranspose,
3769 ID3DXEffectImpl_SetMatrixTransposeArray,
3770 ID3DXEffectImpl_GetMatrixTransposeArray,
3771 ID3DXEffectImpl_SetMatrixTransposePointerArray,
3772 ID3DXEffectImpl_GetMatrixTransposePointerArray,
3773 ID3DXEffectImpl_SetString,
3774 ID3DXEffectImpl_GetString,
3775 ID3DXEffectImpl_SetTexture,
3776 ID3DXEffectImpl_GetTexture,
3777 ID3DXEffectImpl_GetPixelShader,
3778 ID3DXEffectImpl_GetVertexShader,
3779 ID3DXEffectImpl_SetArrayRange,
3780 /*** ID3DXEffect methods ***/
3781 ID3DXEffectImpl_GetPool,
3782 ID3DXEffectImpl_SetTechnique,
3783 ID3DXEffectImpl_GetCurrentTechnique,
3784 ID3DXEffectImpl_ValidateTechnique,
3785 ID3DXEffectImpl_FindNextValidTechnique,
3786 ID3DXEffectImpl_IsParameterUsed,
3787 ID3DXEffectImpl_Begin,
3788 ID3DXEffectImpl_BeginPass,
3789 ID3DXEffectImpl_CommitChanges,
3790 ID3DXEffectImpl_EndPass,
3791 ID3DXEffectImpl_End,
3792 ID3DXEffectImpl_GetDevice,
3793 ID3DXEffectImpl_OnLostDevice,
3794 ID3DXEffectImpl_OnResetDevice,
3795 ID3DXEffectImpl_SetStateManager,
3796 ID3DXEffectImpl_GetStateManager,
3797 ID3DXEffectImpl_BeginParameterBlock,
3798 ID3DXEffectImpl_EndParameterBlock,
3799 ID3DXEffectImpl_ApplyParameterBlock,
3800 ID3DXEffectImpl_DeleteParameterBlock,
3801 ID3DXEffectImpl_CloneEffect,
3802 ID3DXEffectImpl_SetRawValue
3805 static inline struct ID3DXEffectCompilerImpl *impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler *iface)
3807 return CONTAINING_RECORD(iface, struct ID3DXEffectCompilerImpl, ID3DXEffectCompiler_iface);
3810 /*** IUnknown methods ***/
3811 static HRESULT WINAPI ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler *iface, REFIID riid, void **object)
3813 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
3815 if (IsEqualGUID(riid, &IID_IUnknown) ||
3816 IsEqualGUID(riid, &IID_ID3DXEffectCompiler))
3818 iface->lpVtbl->AddRef(iface);
3819 *object = iface;
3820 return S_OK;
3823 ERR("Interface %s not found\n", debugstr_guid(riid));
3825 return E_NOINTERFACE;
3828 static ULONG WINAPI ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler *iface)
3830 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3832 TRACE("iface %p: AddRef from %u\n", iface, This->ref);
3834 return InterlockedIncrement(&This->ref);
3837 static ULONG WINAPI ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler *iface)
3839 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3840 ULONG ref = InterlockedDecrement(&This->ref);
3842 TRACE("iface %p: Release from %u\n", iface, ref + 1);
3844 if (!ref)
3846 free_effect_compiler(This);
3847 HeapFree(GetProcessHeap(), 0, This);
3850 return ref;
3853 /*** ID3DXBaseEffect methods ***/
3854 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler *iface, D3DXEFFECT_DESC *desc)
3856 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3857 ID3DXBaseEffect *base = This->base_effect;
3859 TRACE("Forward iface %p, base %p\n", This, base);
3861 return ID3DXBaseEffectImpl_GetDesc(base, desc);
3864 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
3866 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3867 ID3DXBaseEffect *base = This->base_effect;
3869 TRACE("Forward iface %p, base %p\n", This, base);
3871 return ID3DXBaseEffectImpl_GetParameterDesc(base, parameter, desc);
3874 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler *iface, D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
3876 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3877 ID3DXBaseEffect *base = This->base_effect;
3879 TRACE("Forward iface %p, base %p\n", This, base);
3881 return ID3DXBaseEffectImpl_GetTechniqueDesc(base, technique, desc);
3884 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
3886 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3887 ID3DXBaseEffect *base = This->base_effect;
3889 TRACE("Forward iface %p, base %p\n", This, base);
3891 return ID3DXBaseEffectImpl_GetPassDesc(base, pass, desc);
3894 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
3896 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3897 ID3DXBaseEffect *base = This->base_effect;
3899 TRACE("Forward iface %p, base %p\n", This, base);
3901 return ID3DXBaseEffectImpl_GetFunctionDesc(base, shader, desc);
3904 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT index)
3906 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3907 ID3DXBaseEffect *base = This->base_effect;
3909 TRACE("Forward iface %p, base %p\n", This, base);
3911 return ID3DXBaseEffectImpl_GetParameter(base, parameter, index);
3914 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR name)
3916 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3917 ID3DXBaseEffect *base = This->base_effect;
3919 TRACE("Forward iface %p, base %p\n", This, base);
3921 return ID3DXBaseEffectImpl_GetParameterByName(base, parameter, name);
3924 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR semantic)
3926 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3927 ID3DXBaseEffect *base = This->base_effect;
3929 TRACE("Forward iface %p, base %p\n", This, base);
3931 return ID3DXBaseEffectImpl_GetParameterBySemantic(base, parameter, semantic);
3934 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT index)
3936 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3937 ID3DXBaseEffect *base = This->base_effect;
3939 TRACE("Forward iface %p, base %p\n", This, base);
3941 return ID3DXBaseEffectImpl_GetParameterElement(base, parameter, index);
3944 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler *iface, UINT index)
3946 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3947 ID3DXBaseEffect *base = This->base_effect;
3949 TRACE("Forward iface %p, base %p\n", This, base);
3951 return ID3DXBaseEffectImpl_GetTechnique(base, index);
3954 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler *iface, LPCSTR name)
3956 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3957 ID3DXBaseEffect *base = This->base_effect;
3959 TRACE("Forward iface %p, base %p\n", This, base);
3961 return ID3DXBaseEffectImpl_GetTechniqueByName(base, name);
3964 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler *iface, D3DXHANDLE technique, UINT index)
3966 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3967 ID3DXBaseEffect *base = This->base_effect;
3969 TRACE("Forward iface %p, base %p\n", This, base);
3971 return ID3DXBaseEffectImpl_GetPass(base, technique, index);
3974 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler *iface, D3DXHANDLE technique, LPCSTR name)
3976 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3977 ID3DXBaseEffect *base = This->base_effect;
3979 TRACE("Forward iface %p, base %p\n", This, base);
3981 return ID3DXBaseEffectImpl_GetPassByName(base, technique, name);
3984 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler *iface, UINT index)
3986 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3987 ID3DXBaseEffect *base = This->base_effect;
3989 TRACE("Forward iface %p, base %p\n", This, base);
3991 return ID3DXBaseEffectImpl_GetFunction(base, index);
3994 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler *iface, LPCSTR name)
3996 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
3997 ID3DXBaseEffect *base = This->base_effect;
3999 TRACE("Forward iface %p, base %p\n", This, base);
4001 return ID3DXBaseEffectImpl_GetFunctionByName(base, name);
4004 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler *iface, D3DXHANDLE object, UINT index)
4006 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4007 ID3DXBaseEffect *base = This->base_effect;
4009 TRACE("Forward iface %p, base %p\n", This, base);
4011 return ID3DXBaseEffectImpl_GetAnnotation(base, object, index);
4014 static D3DXHANDLE WINAPI ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler *iface, D3DXHANDLE object, LPCSTR name)
4016 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4017 ID3DXBaseEffect *base = This->base_effect;
4019 TRACE("Forward iface %p, base %p\n", This, base);
4021 return ID3DXBaseEffectImpl_GetAnnotationByName(base, object, name);
4024 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCVOID data, UINT bytes)
4026 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4027 ID3DXBaseEffect *base = This->base_effect;
4029 TRACE("Forward iface %p, base %p\n", This, base);
4031 return ID3DXBaseEffectImpl_SetValue(base, parameter, data, bytes);
4034 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPVOID data, UINT bytes)
4036 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4037 ID3DXBaseEffect *base = This->base_effect;
4039 TRACE("Forward iface %p, base %p\n", This, base);
4041 return ID3DXBaseEffectImpl_GetValue(base, parameter, data, bytes);
4044 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL b)
4046 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4047 ID3DXBaseEffect *base = This->base_effect;
4049 TRACE("Forward iface %p, base %p\n", This, base);
4051 return ID3DXBaseEffectImpl_SetBool(base, parameter, b);
4054 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b)
4056 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4057 ID3DXBaseEffect *base = This->base_effect;
4059 TRACE("Forward iface %p, base %p\n", This, base);
4061 return ID3DXBaseEffectImpl_GetBool(base, parameter, b);
4064 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST BOOL *b, UINT count)
4066 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4067 ID3DXBaseEffect *base = This->base_effect;
4069 TRACE("Forward iface %p, base %p\n", This, base);
4071 return ID3DXBaseEffectImpl_SetBoolArray(base, parameter, b, count);
4074 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *b, UINT count)
4076 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4077 ID3DXBaseEffect *base = This->base_effect;
4079 TRACE("Forward iface %p, base %p\n", This, base);
4081 return ID3DXBaseEffectImpl_GetBoolArray(base, parameter, b, count);
4084 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT n)
4086 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4087 ID3DXBaseEffect *base = This->base_effect;
4089 TRACE("Forward iface %p, base %p\n", This, base);
4091 return ID3DXBaseEffectImpl_SetInt(base, parameter, n);
4094 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n)
4096 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4097 ID3DXBaseEffect *base = This->base_effect;
4099 TRACE("Forward iface %p, base %p\n", This, base);
4101 return ID3DXBaseEffectImpl_GetInt(base, parameter, n);
4104 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST INT *n, UINT count)
4106 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4107 ID3DXBaseEffect *base = This->base_effect;
4109 TRACE("Forward iface %p, base %p\n", This, base);
4111 return ID3DXBaseEffectImpl_SetIntArray(base, parameter, n, count);
4114 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, INT *n, UINT count)
4116 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4117 ID3DXBaseEffect *base = This->base_effect;
4119 TRACE("Forward iface %p, base %p\n", This, base);
4121 return ID3DXBaseEffectImpl_GetIntArray(base, parameter, n, count);
4124 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT f)
4126 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4127 ID3DXBaseEffect *base = This->base_effect;
4129 TRACE("Forward iface %p, base %p\n", This, base);
4131 return ID3DXBaseEffectImpl_SetFloat(base, parameter, f);
4134 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT *f)
4136 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4137 ID3DXBaseEffect *base = This->base_effect;
4139 TRACE("Forward iface %p, base %p\n", This, base);
4141 return ID3DXBaseEffectImpl_GetFloat(base, parameter, f);
4144 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST FLOAT *f, UINT count)
4146 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4147 ID3DXBaseEffect *base = This->base_effect;
4149 TRACE("Forward iface %p, base %p\n", This, base);
4151 return ID3DXBaseEffectImpl_SetFloatArray(base, parameter, f, count);
4154 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, FLOAT *f, UINT count)
4156 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4157 ID3DXBaseEffect *base = This->base_effect;
4159 TRACE("Forward iface %p, base %p\n", This, base);
4161 return ID3DXBaseEffectImpl_GetFloatArray(base, parameter, f, count);
4164 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector)
4166 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4167 ID3DXBaseEffect *base = This->base_effect;
4169 TRACE("Forward iface %p, base %p\n", This, base);
4171 return ID3DXBaseEffectImpl_SetVector(base, parameter, vector);
4174 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector)
4176 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4177 ID3DXBaseEffect *base = This->base_effect;
4179 TRACE("Forward iface %p, base %p\n", This, base);
4181 return ID3DXBaseEffectImpl_GetVector(base, parameter, vector);
4184 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXVECTOR4 *vector, UINT count)
4186 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4187 ID3DXBaseEffect *base = This->base_effect;
4189 TRACE("Forward iface %p, base %p\n", This, base);
4191 return ID3DXBaseEffectImpl_SetVectorArray(base, parameter, vector, count);
4194 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
4196 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4197 ID3DXBaseEffect *base = This->base_effect;
4199 TRACE("Forward iface %p, base %p\n", This, base);
4201 return ID3DXBaseEffectImpl_GetVectorArray(base, parameter, vector, count);
4204 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
4206 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4207 ID3DXBaseEffect *base = This->base_effect;
4209 TRACE("Forward iface %p, base %p\n", This, base);
4211 return ID3DXBaseEffectImpl_SetMatrix(base, parameter, matrix);
4214 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
4216 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4217 ID3DXBaseEffect *base = This->base_effect;
4219 TRACE("Forward iface %p, base %p\n", This, base);
4221 return ID3DXBaseEffectImpl_GetMatrix(base, parameter, matrix);
4224 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
4226 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4227 ID3DXBaseEffect *base = This->base_effect;
4229 TRACE("Forward iface %p, base %p\n", This, base);
4231 return ID3DXBaseEffectImpl_SetMatrixArray(base, parameter, matrix, count);
4234 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4236 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4237 ID3DXBaseEffect *base = This->base_effect;
4239 TRACE("Forward iface %p, base %p\n", This, base);
4241 return ID3DXBaseEffectImpl_GetMatrixArray(base, parameter, matrix, count);
4244 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
4246 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4247 ID3DXBaseEffect *base = This->base_effect;
4249 TRACE("Forward iface %p, base %p\n", This, base);
4251 return ID3DXBaseEffectImpl_SetMatrixPointerArray(base, parameter, matrix, count);
4254 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4256 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4257 ID3DXBaseEffect *base = This->base_effect;
4259 TRACE("Forward iface %p, base %p\n", This, base);
4261 return ID3DXBaseEffectImpl_GetMatrixPointerArray(base, parameter, matrix, count);
4264 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix)
4266 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4267 ID3DXBaseEffect *base = This->base_effect;
4269 TRACE("Forward iface %p, base %p\n", This, base);
4271 return ID3DXBaseEffectImpl_SetMatrixTranspose(base, parameter, matrix);
4274 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix)
4276 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4277 ID3DXBaseEffect *base = This->base_effect;
4279 TRACE("Forward iface %p, base %p\n", This, base);
4281 return ID3DXBaseEffectImpl_GetMatrixTranspose(base, parameter, matrix);
4284 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX *matrix, UINT count)
4286 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4287 ID3DXBaseEffect *base = This->base_effect;
4289 TRACE("Forward iface %p, base %p\n", This, base);
4291 return ID3DXBaseEffectImpl_SetMatrixTransposeArray(base, parameter, matrix, count);
4294 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
4296 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4297 ID3DXBaseEffect *base = This->base_effect;
4299 TRACE("Forward iface %p, base %p\n", This, base);
4301 return ID3DXBaseEffectImpl_GetMatrixTransposeArray(base, parameter, matrix, count);
4304 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, CONST D3DXMATRIX **matrix, UINT count)
4306 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4307 ID3DXBaseEffect *base = This->base_effect;
4309 TRACE("Forward iface %p, base %p\n", This, base);
4311 return ID3DXBaseEffectImpl_SetMatrixTransposePointerArray(base, parameter, matrix, count);
4314 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
4316 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4317 ID3DXBaseEffect *base = This->base_effect;
4319 TRACE("Forward iface %p, base %p\n", This, base);
4321 return ID3DXBaseEffectImpl_GetMatrixTransposePointerArray(base, parameter, matrix, count);
4324 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR string)
4326 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4327 ID3DXBaseEffect *base = This->base_effect;
4329 TRACE("Forward iface %p, base %p\n", This, base);
4331 return ID3DXBaseEffectImpl_SetString(base, parameter, string);
4334 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPCSTR *string)
4336 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4337 ID3DXBaseEffect *base = This->base_effect;
4339 TRACE("Forward iface %p, base %p\n", This, base);
4341 return ID3DXBaseEffectImpl_GetString(base, parameter, string);
4344 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetTexture(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 texture)
4346 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4347 ID3DXBaseEffect *base = This->base_effect;
4349 TRACE("Forward iface %p, base %p\n", This, base);
4351 return ID3DXBaseEffectImpl_SetTexture(base, parameter, texture);
4354 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetTexture(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DBASETEXTURE9 *texture)
4356 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4357 ID3DXBaseEffect *base = This->base_effect;
4359 TRACE("Forward iface %p, base %p\n", This, base);
4361 return ID3DXBaseEffectImpl_GetTexture(base, parameter, texture);
4364 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DPIXELSHADER9 *pshader)
4366 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4367 ID3DXBaseEffect *base = This->base_effect;
4369 TRACE("Forward iface %p, base %p\n", This, base);
4371 return ID3DXBaseEffectImpl_GetPixelShader(base, parameter, pshader);
4374 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetVertexShader(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, LPDIRECT3DVERTEXSHADER9 *vshader)
4376 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4377 ID3DXBaseEffect *base = This->base_effect;
4379 TRACE("Forward iface %p, base %p\n", This, base);
4381 return ID3DXBaseEffectImpl_GetVertexShader(base, parameter, vshader);
4384 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, UINT start, UINT end)
4386 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4387 ID3DXBaseEffect *base = This->base_effect;
4389 TRACE("Forward iface %p, base %p\n", This, base);
4391 return ID3DXBaseEffectImpl_SetArrayRange(base, parameter, start, end);
4394 /*** ID3DXEffectCompiler methods ***/
4395 static HRESULT WINAPI ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL literal)
4397 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4399 FIXME("iface %p, parameter %p, literal %u\n", This, parameter, literal);
4401 return E_NOTIMPL;
4404 static HRESULT WINAPI ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler *iface, D3DXHANDLE parameter, BOOL *literal)
4406 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4408 FIXME("iface %p, parameter %p, literal %p\n", This, parameter, literal);
4410 return E_NOTIMPL;
4413 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler *iface, DWORD flags,
4414 LPD3DXBUFFER *effect, LPD3DXBUFFER *error_msgs)
4416 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4418 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub\n", This, flags, effect, error_msgs);
4420 return E_NOTIMPL;
4423 static HRESULT WINAPI ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler *iface, D3DXHANDLE function,
4424 LPCSTR target, DWORD flags, LPD3DXBUFFER *shader, LPD3DXBUFFER *error_msgs, LPD3DXCONSTANTTABLE *constant_table)
4426 struct ID3DXEffectCompilerImpl *This = impl_from_ID3DXEffectCompiler(iface);
4428 FIXME("iface %p, function %p, target %p, flags %#x, shader %p, error_msgs %p, constant_table %p stub\n",
4429 This, function, target, flags, shader, error_msgs, constant_table);
4431 return E_NOTIMPL;
4434 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
4436 /*** IUnknown methods ***/
4437 ID3DXEffectCompilerImpl_QueryInterface,
4438 ID3DXEffectCompilerImpl_AddRef,
4439 ID3DXEffectCompilerImpl_Release,
4440 /*** ID3DXBaseEffect methods ***/
4441 ID3DXEffectCompilerImpl_GetDesc,
4442 ID3DXEffectCompilerImpl_GetParameterDesc,
4443 ID3DXEffectCompilerImpl_GetTechniqueDesc,
4444 ID3DXEffectCompilerImpl_GetPassDesc,
4445 ID3DXEffectCompilerImpl_GetFunctionDesc,
4446 ID3DXEffectCompilerImpl_GetParameter,
4447 ID3DXEffectCompilerImpl_GetParameterByName,
4448 ID3DXEffectCompilerImpl_GetParameterBySemantic,
4449 ID3DXEffectCompilerImpl_GetParameterElement,
4450 ID3DXEffectCompilerImpl_GetTechnique,
4451 ID3DXEffectCompilerImpl_GetTechniqueByName,
4452 ID3DXEffectCompilerImpl_GetPass,
4453 ID3DXEffectCompilerImpl_GetPassByName,
4454 ID3DXEffectCompilerImpl_GetFunction,
4455 ID3DXEffectCompilerImpl_GetFunctionByName,
4456 ID3DXEffectCompilerImpl_GetAnnotation,
4457 ID3DXEffectCompilerImpl_GetAnnotationByName,
4458 ID3DXEffectCompilerImpl_SetValue,
4459 ID3DXEffectCompilerImpl_GetValue,
4460 ID3DXEffectCompilerImpl_SetBool,
4461 ID3DXEffectCompilerImpl_GetBool,
4462 ID3DXEffectCompilerImpl_SetBoolArray,
4463 ID3DXEffectCompilerImpl_GetBoolArray,
4464 ID3DXEffectCompilerImpl_SetInt,
4465 ID3DXEffectCompilerImpl_GetInt,
4466 ID3DXEffectCompilerImpl_SetIntArray,
4467 ID3DXEffectCompilerImpl_GetIntArray,
4468 ID3DXEffectCompilerImpl_SetFloat,
4469 ID3DXEffectCompilerImpl_GetFloat,
4470 ID3DXEffectCompilerImpl_SetFloatArray,
4471 ID3DXEffectCompilerImpl_GetFloatArray,
4472 ID3DXEffectCompilerImpl_SetVector,
4473 ID3DXEffectCompilerImpl_GetVector,
4474 ID3DXEffectCompilerImpl_SetVectorArray,
4475 ID3DXEffectCompilerImpl_GetVectorArray,
4476 ID3DXEffectCompilerImpl_SetMatrix,
4477 ID3DXEffectCompilerImpl_GetMatrix,
4478 ID3DXEffectCompilerImpl_SetMatrixArray,
4479 ID3DXEffectCompilerImpl_GetMatrixArray,
4480 ID3DXEffectCompilerImpl_SetMatrixPointerArray,
4481 ID3DXEffectCompilerImpl_GetMatrixPointerArray,
4482 ID3DXEffectCompilerImpl_SetMatrixTranspose,
4483 ID3DXEffectCompilerImpl_GetMatrixTranspose,
4484 ID3DXEffectCompilerImpl_SetMatrixTransposeArray,
4485 ID3DXEffectCompilerImpl_GetMatrixTransposeArray,
4486 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray,
4487 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray,
4488 ID3DXEffectCompilerImpl_SetString,
4489 ID3DXEffectCompilerImpl_GetString,
4490 ID3DXEffectCompilerImpl_SetTexture,
4491 ID3DXEffectCompilerImpl_GetTexture,
4492 ID3DXEffectCompilerImpl_GetPixelShader,
4493 ID3DXEffectCompilerImpl_GetVertexShader,
4494 ID3DXEffectCompilerImpl_SetArrayRange,
4495 /*** ID3DXEffectCompiler methods ***/
4496 ID3DXEffectCompilerImpl_SetLiteral,
4497 ID3DXEffectCompilerImpl_GetLiteral,
4498 ID3DXEffectCompilerImpl_CompileEffect,
4499 ID3DXEffectCompilerImpl_CompileShader,
4502 static HRESULT d3dx9_parse_sampler(struct d3dx_sampler *sampler, const char *data, const char **ptr, D3DXHANDLE *objects)
4504 HRESULT hr;
4505 UINT i;
4506 struct d3dx_state *states;
4508 read_dword(ptr, &sampler->state_count);
4509 TRACE("Count: %u\n", sampler->state_count);
4511 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * sampler->state_count);
4512 if (!states)
4514 ERR("Out of memory\n");
4515 return E_OUTOFMEMORY;
4518 for (i = 0; i < sampler->state_count; ++i)
4520 hr = d3dx9_parse_state(&states[i], data, ptr, objects);
4521 if (hr != D3D_OK)
4523 WARN("Failed to parse state\n");
4524 goto err_out;
4528 sampler->states = states;
4530 return D3D_OK;
4532 err_out:
4534 for (i = 0; i < sampler->state_count; ++i)
4536 free_state(&states[i]);
4539 HeapFree(GetProcessHeap(), 0, states);
4541 return hr;
4544 static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, const char *data, const char **ptr, D3DXHANDLE *objects)
4546 unsigned int i;
4547 HRESULT hr;
4548 UINT old_size = 0;
4549 DWORD id;
4551 if (param->element_count)
4553 param->data = value;
4555 for (i = 0; i < param->element_count; ++i)
4557 struct d3dx_parameter *member = get_parameter_struct(param->member_handles[i]);
4559 hr = d3dx9_parse_value(member, value ? (char *)value + old_size : NULL, data, ptr, objects);
4560 if (hr != D3D_OK)
4562 WARN("Failed to parse value\n");
4563 return hr;
4566 old_size += member->bytes;
4569 return D3D_OK;
4572 switch(param->class)
4574 case D3DXPC_SCALAR:
4575 case D3DXPC_VECTOR:
4576 case D3DXPC_MATRIX_ROWS:
4577 case D3DXPC_MATRIX_COLUMNS:
4578 param->data = value;
4579 break;
4581 case D3DXPC_STRUCT:
4582 param->data = value;
4584 for (i = 0; i < param->member_count; ++i)
4586 struct d3dx_parameter *member = get_parameter_struct(param->member_handles[i]);
4588 hr = d3dx9_parse_value(member, (char *)value + old_size, data, ptr, objects);
4589 if (hr != D3D_OK)
4591 WARN("Failed to parse value\n");
4592 return hr;
4595 old_size += member->bytes;
4597 break;
4599 case D3DXPC_OBJECT:
4600 switch (param->type)
4602 case D3DXPT_STRING:
4603 case D3DXPT_TEXTURE:
4604 case D3DXPT_TEXTURE1D:
4605 case D3DXPT_TEXTURE2D:
4606 case D3DXPT_TEXTURE3D:
4607 case D3DXPT_TEXTURECUBE:
4608 case D3DXPT_PIXELSHADER:
4609 case D3DXPT_VERTEXSHADER:
4610 read_dword(ptr, &id);
4611 TRACE("Id: %u\n", id);
4612 objects[id] = get_parameter_handle(param);
4613 param->data = value;
4614 break;
4616 case D3DXPT_SAMPLER:
4617 case D3DXPT_SAMPLER1D:
4618 case D3DXPT_SAMPLER2D:
4619 case D3DXPT_SAMPLER3D:
4620 case D3DXPT_SAMPLERCUBE:
4622 struct d3dx_sampler *sampler;
4624 sampler = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler));
4625 if (!sampler)
4627 ERR("Out of memory\n");
4628 return E_OUTOFMEMORY;
4631 hr = d3dx9_parse_sampler(sampler, data, ptr, objects);
4632 if (hr != D3D_OK)
4634 HeapFree(GetProcessHeap(), 0, sampler);
4635 WARN("Failed to parse sampler\n");
4636 return hr;
4639 param->data = sampler;
4640 break;
4643 default:
4644 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4645 break;
4647 break;
4649 default:
4650 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4651 break;
4654 return D3D_OK;
4657 static HRESULT d3dx9_parse_init_value(struct d3dx_parameter *param, const char *data, const char *ptr, D3DXHANDLE *objects)
4659 UINT size = param->bytes;
4660 HRESULT hr;
4661 void *value = NULL;
4663 TRACE("param size: %u\n", size);
4665 if (size)
4667 value = HeapAlloc(GetProcessHeap(), 0, size);
4668 if (!value)
4670 ERR("Failed to allocate data memory.\n");
4671 return E_OUTOFMEMORY;
4674 TRACE("Data: %s.\n", debugstr_an(ptr, size));
4675 memcpy(value, ptr, size);
4678 hr = d3dx9_parse_value(param, value, data, &ptr, objects);
4679 if (hr != D3D_OK)
4681 WARN("Failed to parse value\n");
4682 HeapFree(GetProcessHeap(), 0, value);
4683 return hr;
4686 return D3D_OK;
4689 static HRESULT d3dx9_parse_name(char **name, const char *ptr)
4691 DWORD size;
4693 read_dword(&ptr, &size);
4694 TRACE("Name size: %#x\n", size);
4696 if (!size)
4698 return D3D_OK;
4701 *name = HeapAlloc(GetProcessHeap(), 0, size);
4702 if (!*name)
4704 ERR("Failed to allocate name memory.\n");
4705 return E_OUTOFMEMORY;
4708 TRACE("Name: %s.\n", debugstr_an(ptr, size));
4709 memcpy(*name, ptr, size);
4711 return D3D_OK;
4714 static HRESULT d3dx9_copy_data(char **str, const char **ptr)
4716 DWORD size;
4718 read_dword(ptr, &size);
4719 TRACE("Data size: %#x\n", size);
4721 *str = HeapAlloc(GetProcessHeap(), 0, size);
4722 if (!*str)
4724 ERR("Failed to allocate name memory.\n");
4725 return E_OUTOFMEMORY;
4728 TRACE("Data: %s.\n", debugstr_an(*ptr, size));
4729 memcpy(*str, *ptr, size);
4731 *ptr += ((size + 3) & ~3);
4733 return D3D_OK;
4736 static HRESULT d3dx9_parse_data(struct d3dx_parameter *param, const char **ptr, LPDIRECT3DDEVICE9 device)
4738 DWORD size;
4739 HRESULT hr;
4741 TRACE("Parse data for parameter %s, type %s\n", debugstr_a(param->name), debug_d3dxparameter_type(param->type));
4743 read_dword(ptr, &size);
4744 TRACE("Data size: %#x\n", size);
4746 if (!size)
4748 TRACE("Size is 0\n");
4749 *(void **)param->data = NULL;
4750 return D3D_OK;
4753 switch (param->type)
4755 case D3DXPT_STRING:
4756 /* re-read with size (sizeof(DWORD) = 4) */
4757 hr = d3dx9_parse_name((LPSTR *)param->data, *ptr - 4);
4758 if (hr != D3D_OK)
4760 WARN("Failed to parse string data\n");
4761 return hr;
4763 break;
4765 case D3DXPT_VERTEXSHADER:
4766 hr = IDirect3DDevice9_CreateVertexShader(device, (DWORD *)*ptr, (LPDIRECT3DVERTEXSHADER9 *)param->data);
4767 if (hr != D3D_OK)
4769 WARN("Failed to create vertex shader\n");
4770 return hr;
4772 break;
4774 case D3DXPT_PIXELSHADER:
4775 hr = IDirect3DDevice9_CreatePixelShader(device, (DWORD *)*ptr, (LPDIRECT3DPIXELSHADER9 *)param->data);
4776 if (hr != D3D_OK)
4778 WARN("Failed to create pixel shader\n");
4779 return hr;
4781 break;
4783 default:
4784 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4785 break;
4789 *ptr += ((size + 3) & ~3);
4791 return D3D_OK;
4794 static HRESULT d3dx9_parse_effect_typedef(struct d3dx_parameter *param, const char *data, const char **ptr,
4795 struct d3dx_parameter *parent, UINT flags)
4797 DWORD offset;
4798 HRESULT hr;
4799 D3DXHANDLE *member_handles = NULL;
4800 UINT i;
4802 param->flags = flags;
4804 if (!parent)
4806 read_dword(ptr, &param->type);
4807 TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
4809 read_dword(ptr, &param->class);
4810 TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
4812 read_dword(ptr, &offset);
4813 TRACE("Type name offset: %#x\n", offset);
4814 hr = d3dx9_parse_name(&param->name, data + offset);
4815 if (hr != D3D_OK)
4817 WARN("Failed to parse name\n");
4818 goto err_out;
4821 read_dword(ptr, &offset);
4822 TRACE("Type semantic offset: %#x\n", offset);
4823 hr = d3dx9_parse_name(&param->semantic, data + offset);
4824 if (hr != D3D_OK)
4826 WARN("Failed to parse semantic\n");
4827 goto err_out;
4830 read_dword(ptr, &param->element_count);
4831 TRACE("Elements: %u\n", param->element_count);
4833 switch (param->class)
4835 case D3DXPC_VECTOR:
4836 read_dword(ptr, &param->columns);
4837 TRACE("Columns: %u\n", param->columns);
4839 read_dword(ptr, &param->rows);
4840 TRACE("Rows: %u\n", param->rows);
4842 /* sizeof(DWORD) * rows * columns */
4843 param->bytes = 4 * param->rows * param->columns;
4844 break;
4846 case D3DXPC_SCALAR:
4847 case D3DXPC_MATRIX_ROWS:
4848 case D3DXPC_MATRIX_COLUMNS:
4849 read_dword(ptr, &param->rows);
4850 TRACE("Rows: %u\n", param->rows);
4852 read_dword(ptr, &param->columns);
4853 TRACE("Columns: %u\n", param->columns);
4855 /* sizeof(DWORD) * rows * columns */
4856 param->bytes = 4 * param->rows * param->columns;
4857 break;
4859 case D3DXPC_STRUCT:
4860 read_dword(ptr, &param->member_count);
4861 TRACE("Members: %u\n", param->member_count);
4862 break;
4864 case D3DXPC_OBJECT:
4865 switch (param->type)
4867 case D3DXPT_STRING:
4868 param->bytes = sizeof(LPCSTR);
4869 break;
4871 case D3DXPT_PIXELSHADER:
4872 param->bytes = sizeof(LPDIRECT3DPIXELSHADER9);
4873 break;
4875 case D3DXPT_VERTEXSHADER:
4876 param->bytes = sizeof(LPDIRECT3DVERTEXSHADER9);
4877 break;
4879 case D3DXPT_TEXTURE:
4880 case D3DXPT_TEXTURE1D:
4881 case D3DXPT_TEXTURE2D:
4882 case D3DXPT_TEXTURE3D:
4883 case D3DXPT_TEXTURECUBE:
4884 param->bytes = sizeof(LPDIRECT3DBASETEXTURE9);
4885 break;
4887 case D3DXPT_SAMPLER:
4888 case D3DXPT_SAMPLER1D:
4889 case D3DXPT_SAMPLER2D:
4890 case D3DXPT_SAMPLER3D:
4891 case D3DXPT_SAMPLERCUBE:
4892 param->bytes = 0;
4893 break;
4895 default:
4896 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
4897 break;
4899 break;
4901 default:
4902 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
4903 break;
4906 else
4908 /* elements */
4909 param->type = parent->type;
4910 param->class = parent->class;
4911 param->name = parent->name;
4912 param->semantic = parent->semantic;
4913 param->element_count = 0;
4914 param->annotation_count = 0;
4915 param->member_count = parent->member_count;
4916 param->bytes = parent->bytes;
4917 param->rows = parent->rows;
4918 param->columns = parent->columns;
4921 if (param->element_count)
4923 unsigned int param_bytes = 0;
4924 const char *save_ptr = *ptr;
4926 member_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member_handles) * param->element_count);
4927 if (!member_handles)
4929 ERR("Out of memory\n");
4930 hr = E_OUTOFMEMORY;
4931 goto err_out;
4934 for (i = 0; i < param->element_count; ++i)
4936 struct d3dx_parameter *member;
4937 *ptr = save_ptr;
4939 member = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member));
4940 if (!member)
4942 ERR("Out of memory\n");
4943 hr = E_OUTOFMEMORY;
4944 goto err_out;
4947 member_handles[i] = get_parameter_handle(member);
4949 hr = d3dx9_parse_effect_typedef(member, data, ptr, param, flags);
4950 if (hr != D3D_OK)
4952 WARN("Failed to parse member\n");
4953 goto err_out;
4956 param_bytes += member->bytes;
4959 param->bytes = param_bytes;
4961 else if (param->member_count)
4963 member_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member_handles) * param->member_count);
4964 if (!member_handles)
4966 ERR("Out of memory\n");
4967 hr = E_OUTOFMEMORY;
4968 goto err_out;
4971 for (i = 0; i < param->member_count; ++i)
4973 struct d3dx_parameter *member;
4975 member = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*member));
4976 if (!member)
4978 ERR("Out of memory\n");
4979 hr = E_OUTOFMEMORY;
4980 goto err_out;
4983 member_handles[i] = get_parameter_handle(member);
4985 hr = d3dx9_parse_effect_typedef(member, data, ptr, NULL, flags);
4986 if (hr != D3D_OK)
4988 WARN("Failed to parse member\n");
4989 goto err_out;
4992 param->bytes += member->bytes;
4996 param->member_handles = member_handles;
4998 return D3D_OK;
5000 err_out:
5002 if (member_handles)
5004 unsigned int count;
5006 if (param->element_count) count = param->element_count;
5007 else count = param->member_count;
5009 for (i = 0; i < count; ++i)
5011 free_parameter(member_handles[i], param->element_count != 0, TRUE);
5013 HeapFree(GetProcessHeap(), 0, member_handles);
5016 if (!parent)
5018 HeapFree(GetProcessHeap(), 0, param->name);
5019 HeapFree(GetProcessHeap(), 0, param->semantic);
5021 param->name = NULL;
5022 param->semantic = NULL;
5024 return hr;
5027 static HRESULT d3dx9_parse_effect_annotation(struct d3dx_parameter *anno, const char *data, const char **ptr, D3DXHANDLE *objects)
5029 DWORD offset;
5030 const char *ptr2;
5031 HRESULT hr;
5033 anno->flags = D3DX_PARAMETER_ANNOTATION;
5035 read_dword(ptr, &offset);
5036 TRACE("Typedef offset: %#x\n", offset);
5037 ptr2 = data + offset;
5038 hr = d3dx9_parse_effect_typedef(anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
5039 if (hr != D3D_OK)
5041 WARN("Failed to parse type definition\n");
5042 return hr;
5045 read_dword(ptr, &offset);
5046 TRACE("Value offset: %#x\n", offset);
5047 hr = d3dx9_parse_init_value(anno, data, data + offset, objects);
5048 if (hr != D3D_OK)
5050 WARN("Failed to parse value\n");
5051 return hr;
5054 return D3D_OK;
5057 static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects)
5059 DWORD offset;
5060 const char *ptr2;
5061 HRESULT hr;
5062 struct d3dx_parameter *parameter;
5064 parameter = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter));
5065 if (!parameter)
5067 ERR("Out of memory\n");
5068 return E_OUTOFMEMORY;
5071 state->type = ST_CONSTANT;
5073 read_dword(ptr, &state->operation);
5074 TRACE("Operation: %#x (%s)\n", state->operation, state_table[state->operation].name);
5076 read_dword(ptr, &state->index);
5077 TRACE("Index: %#x\n", state->index);
5079 read_dword(ptr, &offset);
5080 TRACE("Typedef offset: %#x\n", offset);
5081 ptr2 = data + offset;
5082 hr = d3dx9_parse_effect_typedef(parameter, data, &ptr2, NULL, 0);
5083 if (hr != D3D_OK)
5085 WARN("Failed to parse type definition\n");
5086 goto err_out;
5089 read_dword(ptr, &offset);
5090 TRACE("Value offset: %#x\n", offset);
5091 hr = d3dx9_parse_init_value(parameter, data, data + offset, objects);
5092 if (hr != D3D_OK)
5094 WARN("Failed to parse value\n");
5095 goto err_out;
5098 state->parameter = get_parameter_handle(parameter);
5100 return D3D_OK;
5102 err_out:
5104 free_parameter(get_parameter_handle(parameter), FALSE, FALSE);
5106 return hr;
5109 static HRESULT d3dx9_parse_effect_parameter(struct d3dx_parameter *param, const char *data, const char **ptr, D3DXHANDLE *objects)
5111 DWORD offset;
5112 HRESULT hr;
5113 unsigned int i;
5114 D3DXHANDLE *annotation_handles = NULL;
5115 const char *ptr2;
5117 read_dword(ptr, &offset);
5118 TRACE("Typedef offset: %#x\n", offset);
5119 ptr2 = data + offset;
5121 read_dword(ptr, &offset);
5122 TRACE("Value offset: %#x\n", offset);
5124 read_dword(ptr, &param->flags);
5125 TRACE("Flags: %#x\n", param->flags);
5127 read_dword(ptr, &param->annotation_count);
5128 TRACE("Annotation count: %u\n", param->annotation_count);
5130 hr = d3dx9_parse_effect_typedef(param, data, &ptr2, NULL, param->flags);
5131 if (hr != D3D_OK)
5133 WARN("Failed to parse type definition\n");
5134 return hr;
5137 hr = d3dx9_parse_init_value(param, data, data + offset, objects);
5138 if (hr != D3D_OK)
5140 WARN("Failed to parse value\n");
5141 return hr;
5144 if (param->annotation_count)
5146 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * param->annotation_count);
5147 if (!annotation_handles)
5149 ERR("Out of memory\n");
5150 hr = E_OUTOFMEMORY;
5151 goto err_out;
5154 for (i = 0; i < param->annotation_count; ++i)
5156 struct d3dx_parameter *annotation;
5158 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5159 if (!annotation)
5161 ERR("Out of memory\n");
5162 hr = E_OUTOFMEMORY;
5163 goto err_out;
5166 annotation_handles[i] = get_parameter_handle(annotation);
5168 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5169 if (hr != D3D_OK)
5171 WARN("Failed to parse annotation\n");
5172 goto err_out;
5177 param->annotation_handles = annotation_handles;
5179 return D3D_OK;
5181 err_out:
5183 if (annotation_handles)
5185 for (i = 0; i < param->annotation_count; ++i)
5187 free_parameter(annotation_handles[i], FALSE, FALSE);
5189 HeapFree(GetProcessHeap(), 0, annotation_handles);
5192 return hr;
5195 static HRESULT d3dx9_parse_effect_pass(struct d3dx_pass *pass, const char *data, const char **ptr, D3DXHANDLE *objects)
5197 DWORD offset;
5198 HRESULT hr;
5199 unsigned int i;
5200 D3DXHANDLE *annotation_handles = NULL;
5201 struct d3dx_state *states = NULL;
5202 char *name = NULL;
5204 read_dword(ptr, &offset);
5205 TRACE("Pass name offset: %#x\n", offset);
5206 hr = d3dx9_parse_name(&name, data + offset);
5207 if (hr != D3D_OK)
5209 WARN("Failed to parse name\n");
5210 goto err_out;
5213 read_dword(ptr, &pass->annotation_count);
5214 TRACE("Annotation count: %u\n", pass->annotation_count);
5216 read_dword(ptr, &pass->state_count);
5217 TRACE("State count: %u\n", pass->state_count);
5219 if (pass->annotation_count)
5221 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * pass->annotation_count);
5222 if (!annotation_handles)
5224 ERR("Out of memory\n");
5225 hr = E_OUTOFMEMORY;
5226 goto err_out;
5229 for (i = 0; i < pass->annotation_count; ++i)
5231 struct d3dx_parameter *annotation;
5233 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5234 if (!annotation)
5236 ERR("Out of memory\n");
5237 hr = E_OUTOFMEMORY;
5238 goto err_out;
5241 annotation_handles[i] = get_parameter_handle(annotation);
5243 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5244 if (hr != D3D_OK)
5246 WARN("Failed to parse annotations\n");
5247 goto err_out;
5252 if (pass->state_count)
5254 states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * pass->state_count);
5255 if (!states)
5257 ERR("Out of memory\n");
5258 hr = E_OUTOFMEMORY;
5259 goto err_out;
5262 for (i = 0; i < pass->state_count; ++i)
5264 hr = d3dx9_parse_state(&states[i], data, ptr, objects);
5265 if (hr != D3D_OK)
5267 WARN("Failed to parse annotations\n");
5268 goto err_out;
5273 pass->name = name;
5274 pass->annotation_handles = annotation_handles;
5275 pass->states = states;
5277 return D3D_OK;
5279 err_out:
5281 if (annotation_handles)
5283 for (i = 0; i < pass->annotation_count; ++i)
5285 free_parameter(annotation_handles[i], FALSE, FALSE);
5287 HeapFree(GetProcessHeap(), 0, annotation_handles);
5290 if (states)
5292 for (i = 0; i < pass->state_count; ++i)
5294 free_state(&states[i]);
5296 HeapFree(GetProcessHeap(), 0, states);
5299 HeapFree(GetProcessHeap(), 0, name);
5301 return hr;
5304 static HRESULT d3dx9_parse_effect_technique(struct d3dx_technique *technique, const char *data, const char **ptr, D3DXHANDLE *objects)
5306 DWORD offset;
5307 HRESULT hr;
5308 unsigned int i;
5309 D3DXHANDLE *annotation_handles = NULL;
5310 D3DXHANDLE *pass_handles = NULL;
5311 char *name = NULL;
5313 read_dword(ptr, &offset);
5314 TRACE("Technique name offset: %#x\n", offset);
5315 hr = d3dx9_parse_name(&name, data + offset);
5316 if (hr != D3D_OK)
5318 WARN("Failed to parse name\n");
5319 goto err_out;
5322 read_dword(ptr, &technique->annotation_count);
5323 TRACE("Annotation count: %u\n", technique->annotation_count);
5325 read_dword(ptr, &technique->pass_count);
5326 TRACE("Pass count: %u\n", technique->pass_count);
5328 if (technique->annotation_count)
5330 annotation_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation_handles) * technique->annotation_count);
5331 if (!annotation_handles)
5333 ERR("Out of memory\n");
5334 hr = E_OUTOFMEMORY;
5335 goto err_out;
5338 for (i = 0; i < technique->annotation_count; ++i)
5340 struct d3dx_parameter *annotation;
5342 annotation = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*annotation));
5343 if (!annotation)
5345 ERR("Out of memory\n");
5346 hr = E_OUTOFMEMORY;
5347 goto err_out;
5350 annotation_handles[i] = get_parameter_handle(annotation);
5352 hr = d3dx9_parse_effect_annotation(annotation, data, ptr, objects);
5353 if (hr != D3D_OK)
5355 WARN("Failed to parse annotations\n");
5356 goto err_out;
5361 if (technique->pass_count)
5363 pass_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pass_handles) * technique->pass_count);
5364 if (!pass_handles)
5366 ERR("Out of memory\n");
5367 hr = E_OUTOFMEMORY;
5368 goto err_out;
5371 for (i = 0; i < technique->pass_count; ++i)
5373 struct d3dx_pass *pass;
5375 pass = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pass));
5376 if (!pass)
5378 ERR("Out of memory\n");
5379 hr = E_OUTOFMEMORY;
5380 goto err_out;
5383 pass_handles[i] = get_pass_handle(pass);
5385 hr = d3dx9_parse_effect_pass(pass, data, ptr, objects);
5386 if (hr != D3D_OK)
5388 WARN("Failed to parse passes\n");
5389 goto err_out;
5394 technique->name = name;
5395 technique->pass_handles = pass_handles;
5396 technique->annotation_handles = annotation_handles;
5398 return D3D_OK;
5400 err_out:
5402 if (pass_handles)
5404 for (i = 0; i < technique->pass_count; ++i)
5406 free_pass(pass_handles[i]);
5408 HeapFree(GetProcessHeap(), 0, pass_handles);
5411 if (annotation_handles)
5413 for (i = 0; i < technique->annotation_count; ++i)
5415 free_parameter(annotation_handles[i], FALSE, FALSE);
5417 HeapFree(GetProcessHeap(), 0, annotation_handles);
5420 HeapFree(GetProcessHeap(), 0, name);
5422 return hr;
5425 static HRESULT d3dx9_parse_resource(struct ID3DXBaseEffectImpl *base, const char *data, const char **ptr)
5427 DWORD technique_index;
5428 DWORD index, state_index, usage, element_index;
5429 struct d3dx_state *state;
5430 struct d3dx_parameter *param;
5431 HRESULT hr = E_FAIL;
5433 read_dword(ptr, &technique_index);
5434 TRACE("techn: %u\n", technique_index);
5436 read_dword(ptr, &index);
5437 TRACE("index: %u\n", index);
5439 read_dword(ptr, &element_index);
5440 TRACE("element_index: %u\n", element_index);
5442 read_dword(ptr, &state_index);
5443 TRACE("state_index: %u\n", state_index);
5445 read_dword(ptr, &usage);
5446 TRACE("usage: %u\n", usage);
5448 if (technique_index == 0xffffffff)
5450 struct d3dx_parameter *parameter;
5451 struct d3dx_sampler *sampler;
5453 if (index >= base->parameter_count)
5455 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index, base->parameter_count);
5456 return E_FAIL;
5459 parameter = get_parameter_struct(base->parameter_handles[index]);
5460 if (element_index != 0xffffffff)
5462 if (element_index >= parameter->element_count && parameter->element_count != 0)
5464 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index, parameter->element_count);
5465 return E_FAIL;
5468 if (parameter->element_count != 0) parameter = get_parameter_struct(parameter->member_handles[element_index]);
5471 sampler = parameter->data;
5472 if (state_index >= sampler->state_count)
5474 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, sampler->state_count);
5475 return E_FAIL;
5478 state = &sampler->states[state_index];
5480 else
5482 struct d3dx_technique *technique;
5483 struct d3dx_pass *pass;
5485 if (technique_index >= base->technique_count)
5487 FIXME("Index out of bounds: technique_index %u >= technique_count %u\n", technique_index, base->technique_count);
5488 return E_FAIL;
5491 technique = get_technique_struct(base->technique_handles[technique_index]);
5492 if (index >= technique->pass_count)
5494 FIXME("Index out of bounds: index %u >= pass_count %u\n", index, technique->pass_count);
5495 return E_FAIL;
5498 pass = get_pass_struct(technique->pass_handles[index]);
5499 if (state_index >= pass->state_count)
5501 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index, pass->state_count);
5502 return E_FAIL;
5505 state = &pass->states[state_index];
5508 param = get_parameter_struct(state->parameter);
5510 switch (usage)
5512 case 0:
5513 TRACE("usage 0: type %s\n", debug_d3dxparameter_type(param->type));
5514 switch (param->type)
5516 case D3DXPT_VERTEXSHADER:
5517 case D3DXPT_PIXELSHADER:
5518 state->type = ST_CONSTANT;
5519 hr = d3dx9_parse_data(param, ptr, base->effect->device);
5520 break;
5522 case D3DXPT_BOOL:
5523 case D3DXPT_INT:
5524 case D3DXPT_FLOAT:
5525 case D3DXPT_STRING:
5526 state->type = ST_FXLC;
5527 hr = d3dx9_copy_data(param->data, ptr);
5528 break;
5530 default:
5531 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
5532 break;
5534 break;
5536 case 1:
5537 state->type = ST_PARAMETER;
5538 hr = d3dx9_copy_data(param->data, ptr);
5539 if (hr == D3D_OK)
5541 TRACE("Mapping to parameter %s\n", *(char **)param->data);
5543 break;
5545 default:
5546 FIXME("Unknown usage %x\n", usage);
5547 break;
5550 return hr;
5553 static HRESULT d3dx9_parse_effect(struct ID3DXBaseEffectImpl *base, const char *data, UINT data_size, DWORD start)
5555 const char *ptr = data + start;
5556 D3DXHANDLE *parameter_handles = NULL;
5557 D3DXHANDLE *technique_handles = NULL;
5558 D3DXHANDLE *objects = NULL;
5559 UINT stringcount, objectcount, resourcecount;
5560 HRESULT hr;
5561 UINT i;
5563 read_dword(&ptr, &base->parameter_count);
5564 TRACE("Parameter count: %u\n", base->parameter_count);
5566 read_dword(&ptr, &base->technique_count);
5567 TRACE("Technique count: %u\n", base->technique_count);
5569 skip_dword_unknown(&ptr, 1);
5571 read_dword(&ptr, &objectcount);
5572 TRACE("Object count: %u\n", objectcount);
5574 objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*objects) * objectcount);
5575 if (!objects)
5577 ERR("Out of memory\n");
5578 hr = E_OUTOFMEMORY;
5579 goto err_out;
5582 if (base->parameter_count)
5584 parameter_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter_handles) * base->parameter_count);
5585 if (!parameter_handles)
5587 ERR("Out of memory\n");
5588 hr = E_OUTOFMEMORY;
5589 goto err_out;
5592 for (i = 0; i < base->parameter_count; ++i)
5594 struct d3dx_parameter *parameter;
5596 parameter = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter));
5597 if (!parameter)
5599 ERR("Out of memory\n");
5600 hr = E_OUTOFMEMORY;
5601 goto err_out;
5604 parameter_handles[i] = get_parameter_handle(parameter);
5606 hr = d3dx9_parse_effect_parameter(parameter, data, &ptr, objects);
5607 if (hr != D3D_OK)
5609 WARN("Failed to parse parameter\n");
5610 goto err_out;
5615 if (base->technique_count)
5617 technique_handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*technique_handles) * base->technique_count);
5618 if (!technique_handles)
5620 ERR("Out of memory\n");
5621 hr = E_OUTOFMEMORY;
5622 goto err_out;
5625 for (i = 0; i < base->technique_count; ++i)
5627 struct d3dx_technique *technique;
5629 technique = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*technique));
5630 if (!technique)
5632 ERR("Out of memory\n");
5633 hr = E_OUTOFMEMORY;
5634 goto err_out;
5637 technique_handles[i] = get_technique_handle(technique);
5639 hr = d3dx9_parse_effect_technique(technique, data, &ptr, objects);
5640 if (hr != D3D_OK)
5642 WARN("Failed to parse technique\n");
5643 goto err_out;
5648 /* needed for further parsing */
5649 base->technique_handles = technique_handles;
5650 base->parameter_handles = parameter_handles;
5652 read_dword(&ptr, &stringcount);
5653 TRACE("String count: %u\n", stringcount);
5655 read_dword(&ptr, &resourcecount);
5656 TRACE("Resource count: %u\n", resourcecount);
5658 for (i = 0; i < stringcount; ++i)
5660 DWORD id;
5661 struct d3dx_parameter *param;
5663 read_dword(&ptr, &id);
5664 TRACE("Id: %u\n", id);
5666 param = get_parameter_struct(objects[id]);
5668 hr = d3dx9_parse_data(param, &ptr, base->effect->device);
5669 if (hr != D3D_OK)
5671 WARN("Failed to parse data\n");
5672 goto err_out;
5676 for (i = 0; i < resourcecount; ++i)
5678 TRACE("parse resource %u\n", i);
5680 hr = d3dx9_parse_resource(base, data, &ptr);
5681 if (hr != D3D_OK)
5683 WARN("Failed to parse data\n");
5684 goto err_out;
5688 HeapFree(GetProcessHeap(), 0, objects);
5690 return D3D_OK;
5692 err_out:
5694 if (technique_handles)
5696 for (i = 0; i < base->technique_count; ++i)
5698 free_technique(technique_handles[i]);
5700 HeapFree(GetProcessHeap(), 0, technique_handles);
5703 if (parameter_handles)
5705 for (i = 0; i < base->parameter_count; ++i)
5707 free_parameter(parameter_handles[i], FALSE, FALSE);
5709 HeapFree(GetProcessHeap(), 0, parameter_handles);
5712 base->technique_handles = NULL;
5713 base->parameter_handles = NULL;
5715 HeapFree(GetProcessHeap(), 0, objects);
5717 return hr;
5720 static HRESULT d3dx9_base_effect_init(struct ID3DXBaseEffectImpl *base,
5721 const char *data, SIZE_T data_size, struct ID3DXEffectImpl *effect)
5723 DWORD tag, offset;
5724 const char *ptr = data;
5725 HRESULT hr;
5727 TRACE("base %p, data %p, data_size %lu, effect %p\n", base, data, data_size, effect);
5729 base->ID3DXBaseEffect_iface.lpVtbl = &ID3DXBaseEffect_Vtbl;
5730 base->ref = 1;
5731 base->effect = effect;
5733 read_dword(&ptr, &tag);
5734 TRACE("Tag: %x\n", tag);
5736 if (tag != d3dx9_effect_version(9, 1))
5738 /* todo: compile hlsl ascii code */
5739 FIXME("HLSL ascii effects not supported, yet\n");
5741 /* Show the start of the shader for debugging info. */
5742 TRACE("effect:\n%s\n", debugstr_an(data, data_size > 40 ? 40 : data_size));
5744 else
5746 read_dword(&ptr, &offset);
5747 TRACE("Offset: %x\n", offset);
5749 hr = d3dx9_parse_effect(base, ptr, data_size, offset);
5750 if (hr != D3D_OK)
5752 FIXME("Failed to parse effect.\n");
5753 return hr;
5757 return D3D_OK;
5760 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, LPDIRECT3DDEVICE9 device,
5761 const char *data, SIZE_T data_size, LPD3DXEFFECTPOOL pool)
5763 HRESULT hr;
5764 struct ID3DXBaseEffectImpl *object = NULL;
5766 TRACE("effect %p, device %p, data %p, data_size %lu, pool %p\n", effect, device, data, data_size, pool);
5768 effect->ID3DXEffect_iface.lpVtbl = &ID3DXEffect_Vtbl;
5769 effect->ref = 1;
5771 if (pool) pool->lpVtbl->AddRef(pool);
5772 effect->pool = pool;
5774 IDirect3DDevice9_AddRef(device);
5775 effect->device = device;
5777 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5778 if (!object)
5780 ERR("Out of memory\n");
5781 hr = E_OUTOFMEMORY;
5782 goto err_out;
5785 hr = d3dx9_base_effect_init(object, data, data_size, effect);
5786 if (hr != D3D_OK)
5788 FIXME("Failed to parse effect.\n");
5789 goto err_out;
5792 effect->base_effect = &object->ID3DXBaseEffect_iface;
5794 /* initialize defaults - check because of unsupported ascii effects */
5795 if (object->technique_handles)
5797 effect->active_technique = object->technique_handles[0];
5798 effect->active_pass = NULL;
5801 return D3D_OK;
5803 err_out:
5805 HeapFree(GetProcessHeap(), 0, object);
5806 free_effect(effect);
5808 return hr;
5811 HRESULT WINAPI D3DXCreateEffectEx(LPDIRECT3DDEVICE9 device,
5812 LPCVOID srcdata,
5813 UINT srcdatalen,
5814 CONST D3DXMACRO* defines,
5815 LPD3DXINCLUDE include,
5816 LPCSTR skip_constants,
5817 DWORD flags,
5818 LPD3DXEFFECTPOOL pool,
5819 LPD3DXEFFECT* effect,
5820 LPD3DXBUFFER* compilation_errors)
5822 struct ID3DXEffectImpl *object;
5823 HRESULT hr;
5825 FIXME("(%p, %p, %u, %p, %p, %p, %#x, %p, %p, %p): semi-stub\n", device, srcdata, srcdatalen, defines, include,
5826 skip_constants, flags, pool, effect, compilation_errors);
5828 if (!device || !srcdata)
5829 return D3DERR_INVALIDCALL;
5831 if (!srcdatalen)
5832 return E_FAIL;
5834 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
5835 if (!effect)
5836 return D3D_OK;
5838 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5839 if (!object)
5841 ERR("Out of memory\n");
5842 return E_OUTOFMEMORY;
5845 hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, pool);
5846 if (FAILED(hr))
5848 WARN("Failed to initialize shader reflection\n");
5849 HeapFree(GetProcessHeap(), 0, object);
5850 return hr;
5853 *effect = &object->ID3DXEffect_iface;
5855 TRACE("Created ID3DXEffect %p\n", object);
5857 return D3D_OK;
5860 HRESULT WINAPI D3DXCreateEffect(LPDIRECT3DDEVICE9 device,
5861 LPCVOID srcdata,
5862 UINT srcdatalen,
5863 CONST D3DXMACRO* defines,
5864 LPD3DXINCLUDE include,
5865 DWORD flags,
5866 LPD3DXEFFECTPOOL pool,
5867 LPD3DXEFFECT* effect,
5868 LPD3DXBUFFER* compilation_errors)
5870 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device, srcdata, srcdatalen, defines,
5871 include, flags, pool, effect, compilation_errors);
5873 return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
5876 static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler, const char *data, SIZE_T data_size)
5878 HRESULT hr;
5879 struct ID3DXBaseEffectImpl *object = NULL;
5881 TRACE("effect %p, data %p, data_size %lu\n", compiler, data, data_size);
5883 compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
5884 compiler->ref = 1;
5886 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5887 if (!object)
5889 ERR("Out of memory\n");
5890 hr = E_OUTOFMEMORY;
5891 goto err_out;
5894 hr = d3dx9_base_effect_init(object, data, data_size, NULL);
5895 if (hr != D3D_OK)
5897 FIXME("Failed to parse effect.\n");
5898 goto err_out;
5901 compiler->base_effect = &object->ID3DXBaseEffect_iface;
5903 return D3D_OK;
5905 err_out:
5907 HeapFree(GetProcessHeap(), 0, object);
5908 free_effect_compiler(compiler);
5910 return hr;
5913 HRESULT WINAPI D3DXCreateEffectCompiler(LPCSTR srcdata,
5914 UINT srcdatalen,
5915 CONST D3DXMACRO *defines,
5916 LPD3DXINCLUDE include,
5917 DWORD flags,
5918 LPD3DXEFFECTCOMPILER *compiler,
5919 LPD3DXBUFFER *parse_errors)
5921 struct ID3DXEffectCompilerImpl *object;
5922 HRESULT hr;
5924 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
5925 srcdata, srcdatalen, defines, include, flags, compiler, parse_errors);
5927 if (!srcdata || !compiler)
5929 WARN("Invalid arguments supplied\n");
5930 return D3DERR_INVALIDCALL;
5933 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
5934 if (!object)
5936 ERR("Out of memory\n");
5937 return E_OUTOFMEMORY;
5940 hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen);
5941 if (FAILED(hr))
5943 WARN("Failed to initialize effect compiler\n");
5944 HeapFree(GetProcessHeap(), 0, object);
5945 return hr;
5948 *compiler = &object->ID3DXEffectCompiler_iface;
5950 TRACE("Created ID3DXEffectCompiler %p\n", object);
5952 return D3D_OK;
5955 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl;
5957 struct ID3DXEffectPoolImpl
5959 ID3DXEffectPool ID3DXEffectPool_iface;
5960 LONG ref;
5963 static inline struct ID3DXEffectPoolImpl *impl_from_ID3DXEffectPool(ID3DXEffectPool *iface)
5965 return CONTAINING_RECORD(iface, struct ID3DXEffectPoolImpl, ID3DXEffectPool_iface);
5968 /*** IUnknown methods ***/
5969 static HRESULT WINAPI ID3DXEffectPoolImpl_QueryInterface(ID3DXEffectPool *iface, REFIID riid, void **object)
5971 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
5973 if (IsEqualGUID(riid, &IID_IUnknown) ||
5974 IsEqualGUID(riid, &IID_ID3DXEffectPool))
5976 iface->lpVtbl->AddRef(iface);
5977 *object = iface;
5978 return S_OK;
5981 WARN("Interface %s not found\n", debugstr_guid(riid));
5983 return E_NOINTERFACE;
5986 static ULONG WINAPI ID3DXEffectPoolImpl_AddRef(ID3DXEffectPool *iface)
5988 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
5990 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
5992 return InterlockedIncrement(&This->ref);
5995 static ULONG WINAPI ID3DXEffectPoolImpl_Release(ID3DXEffectPool *iface)
5997 struct ID3DXEffectPoolImpl *This = impl_from_ID3DXEffectPool(iface);
5998 ULONG ref = InterlockedDecrement(&This->ref);
6000 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
6002 if (!ref)
6003 HeapFree(GetProcessHeap(), 0, This);
6005 return ref;
6008 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl =
6010 /*** IUnknown methods ***/
6011 ID3DXEffectPoolImpl_QueryInterface,
6012 ID3DXEffectPoolImpl_AddRef,
6013 ID3DXEffectPoolImpl_Release
6016 HRESULT WINAPI D3DXCreateEffectPool(LPD3DXEFFECTPOOL *pool)
6018 struct ID3DXEffectPoolImpl *object;
6020 TRACE("(%p)\n", pool);
6022 if (!pool)
6023 return D3DERR_INVALIDCALL;
6025 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
6026 if (!object)
6028 ERR("Out of memory\n");
6029 return E_OUTOFMEMORY;
6032 object->ID3DXEffectPool_iface.lpVtbl = &ID3DXEffectPool_Vtbl;
6033 object->ref = 1;
6035 *pool = &object->ID3DXEffectPool_iface;
6037 return S_OK;
6040 HRESULT WINAPI D3DXCreateEffectFromFileExW(LPDIRECT3DDEVICE9 device, LPCWSTR srcfile,
6041 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6042 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6044 LPVOID buffer;
6045 HRESULT ret;
6046 DWORD size;
6048 TRACE("(%s): relay\n", debugstr_w(srcfile));
6050 if (!device || !srcfile)
6051 return D3DERR_INVALIDCALL;
6053 ret = map_view_of_file(srcfile, &buffer, &size);
6055 if (FAILED(ret))
6056 return D3DXERR_INVALIDDATA;
6058 ret = D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6059 UnmapViewOfFile(buffer);
6061 return ret;
6064 HRESULT WINAPI D3DXCreateEffectFromFileExA(LPDIRECT3DDEVICE9 device, LPCSTR srcfile,
6065 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6066 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6068 LPWSTR srcfileW;
6069 HRESULT ret;
6070 DWORD len;
6072 TRACE("(void): relay\n");
6074 if (!srcfile)
6075 return D3DERR_INVALIDCALL;
6077 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6078 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6079 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6081 ret = D3DXCreateEffectFromFileExW(device, srcfileW, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6082 HeapFree(GetProcessHeap(), 0, srcfileW);
6084 return ret;
6087 HRESULT WINAPI D3DXCreateEffectFromFileW(LPDIRECT3DDEVICE9 device, LPCWSTR srcfile,
6088 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6089 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6091 TRACE("(void): relay\n");
6092 return D3DXCreateEffectFromFileExW(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6095 HRESULT WINAPI D3DXCreateEffectFromFileA(LPDIRECT3DDEVICE9 device, LPCSTR srcfile,
6096 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6097 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6099 TRACE("(void): relay\n");
6100 return D3DXCreateEffectFromFileExA(device, srcfile, defines, include, NULL, flags, pool, effect, compilationerrors);
6103 HRESULT WINAPI D3DXCreateEffectFromResourceExW(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCWSTR srcresource,
6104 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6105 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6107 HRSRC resinfo;
6109 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(srcresource));
6111 if (!device)
6112 return D3DERR_INVALIDCALL;
6114 resinfo = FindResourceW(srcmodule, srcresource, (LPCWSTR) RT_RCDATA);
6116 if (resinfo)
6118 LPVOID buffer;
6119 HRESULT ret;
6120 DWORD size;
6122 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6124 if (FAILED(ret))
6125 return D3DXERR_INVALIDDATA;
6127 return D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6130 return D3DXERR_INVALIDDATA;
6133 HRESULT WINAPI D3DXCreateEffectFromResourceExA(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCSTR srcresource,
6134 const D3DXMACRO *defines, LPD3DXINCLUDE include, LPCSTR skipconstants, DWORD flags,
6135 LPD3DXEFFECTPOOL pool, LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6137 HRSRC resinfo;
6139 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(srcresource));
6141 if (!device)
6142 return D3DERR_INVALIDCALL;
6144 resinfo = FindResourceA(srcmodule, srcresource, (LPCSTR) RT_RCDATA);
6146 if (resinfo)
6148 LPVOID buffer;
6149 HRESULT ret;
6150 DWORD size;
6152 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6154 if (FAILED(ret))
6155 return D3DXERR_INVALIDDATA;
6157 return D3DXCreateEffectEx(device, buffer, size, defines, include, skipconstants, flags, pool, effect, compilationerrors);
6160 return D3DXERR_INVALIDDATA;
6163 HRESULT WINAPI D3DXCreateEffectFromResourceW(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCWSTR srcresource,
6164 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6165 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6167 TRACE("(void): relay\n");
6168 return D3DXCreateEffectFromResourceExW(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6171 HRESULT WINAPI D3DXCreateEffectFromResourceA(LPDIRECT3DDEVICE9 device, HMODULE srcmodule, LPCSTR srcresource,
6172 const D3DXMACRO *defines, LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTPOOL pool,
6173 LPD3DXEFFECT *effect, LPD3DXBUFFER *compilationerrors)
6175 TRACE("(void): relay\n");
6176 return D3DXCreateEffectFromResourceExA(device, srcmodule, srcresource, defines, include, NULL, flags, pool, effect, compilationerrors);
6179 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(LPCWSTR srcfile, const D3DXMACRO *defines, LPD3DXINCLUDE include,
6180 DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6182 LPVOID buffer;
6183 HRESULT ret;
6184 DWORD size;
6186 TRACE("(%s): relay\n", debugstr_w(srcfile));
6188 if (!srcfile)
6189 return D3DERR_INVALIDCALL;
6191 ret = map_view_of_file(srcfile, &buffer, &size);
6193 if (FAILED(ret))
6194 return D3DXERR_INVALIDDATA;
6196 ret = D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6197 UnmapViewOfFile(buffer);
6199 return ret;
6202 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(LPCSTR srcfile, const D3DXMACRO *defines, LPD3DXINCLUDE include,
6203 DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6205 LPWSTR srcfileW;
6206 HRESULT ret;
6207 DWORD len;
6209 TRACE("(void): relay\n");
6211 if (!srcfile)
6212 return D3DERR_INVALIDCALL;
6214 len = MultiByteToWideChar(CP_ACP, 0, srcfile, -1, NULL, 0);
6215 srcfileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*srcfileW));
6216 MultiByteToWideChar(CP_ACP, 0, srcfile, -1, srcfileW, len);
6218 ret = D3DXCreateEffectCompilerFromFileW(srcfileW, defines, include, flags, effectcompiler, parseerrors);
6219 HeapFree(GetProcessHeap(), 0, srcfileW);
6221 return ret;
6224 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule, LPCSTR srcresource, const D3DXMACRO *defines,
6225 LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6227 HRSRC resinfo;
6229 TRACE("(%p, %s): relay\n", srcmodule, debugstr_a(srcresource));
6231 resinfo = FindResourceA(srcmodule, srcresource, (LPCSTR) RT_RCDATA);
6233 if (resinfo)
6235 LPVOID buffer;
6236 HRESULT ret;
6237 DWORD size;
6239 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6241 if (FAILED(ret))
6242 return D3DXERR_INVALIDDATA;
6244 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6247 return D3DXERR_INVALIDDATA;
6250 HRESULT WINAPI D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule, LPCWSTR srcresource, const D3DXMACRO *defines,
6251 LPD3DXINCLUDE include, DWORD flags, LPD3DXEFFECTCOMPILER *effectcompiler, LPD3DXBUFFER *parseerrors)
6253 HRSRC resinfo;
6255 TRACE("(%p, %s): relay\n", srcmodule, debugstr_w(srcresource));
6257 resinfo = FindResourceW(srcmodule, srcresource, (LPCWSTR) RT_RCDATA);
6259 if (resinfo)
6261 LPVOID buffer;
6262 HRESULT ret;
6263 DWORD size;
6265 ret = load_resource_into_memory(srcmodule, resinfo, &buffer, &size);
6267 if (FAILED(ret))
6268 return D3DXERR_INVALIDDATA;
6270 return D3DXCreateEffectCompiler(buffer, size, defines, include, flags, effectcompiler, parseerrors);
6273 return D3DXERR_INVALIDDATA;