eaaaa16a15ce7ccb98cfc2e75edc094b073159a7
[reactos.git] / reactos / dll / directx / wine / d3dx9_36 / effect.c
1 /*
2 * Copyright 2010 Christian Costa
3 * Copyright 2011 Rico Schأ¼ller
4 *
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.
9 *
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.
14 *
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
18 */
19
20 #include "d3dx9_36_private.h"
21
22 /* Constants for special INT/FLOAT conversation */
23 #define INT_FLOAT_MULTI 255.0f
24 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
25
26 enum STATE_CLASS
27 {
28 SC_LIGHTENABLE,
29 SC_FVF,
30 SC_LIGHT,
31 SC_MATERIAL,
32 SC_NPATCHMODE,
33 SC_PIXELSHADER,
34 SC_RENDERSTATE,
35 SC_SETSAMPLER,
36 SC_SAMPLERSTATE,
37 SC_TEXTURE,
38 SC_TEXTURESTAGE,
39 SC_TRANSFORM,
40 SC_VERTEXSHADER,
41 SC_SHADERCONST,
42 SC_UNKNOWN,
43 };
44
45 enum MATERIAL_TYPE
46 {
47 MT_DIFFUSE,
48 MT_AMBIENT,
49 MT_SPECULAR,
50 MT_EMISSIVE,
51 MT_POWER,
52 };
53
54 enum LIGHT_TYPE
55 {
56 LT_TYPE,
57 LT_DIFFUSE,
58 LT_SPECULAR,
59 LT_AMBIENT,
60 LT_POSITION,
61 LT_DIRECTION,
62 LT_RANGE,
63 LT_FALLOFF,
64 LT_ATTENUATION0,
65 LT_ATTENUATION1,
66 LT_ATTENUATION2,
67 LT_THETA,
68 LT_PHI,
69 };
70
71 enum SHADER_CONSTANT_TYPE
72 {
73 SCT_VSFLOAT,
74 SCT_VSBOOL,
75 SCT_VSINT,
76 SCT_PSFLOAT,
77 SCT_PSBOOL,
78 SCT_PSINT,
79 };
80
81 enum STATE_TYPE
82 {
83 ST_CONSTANT,
84 ST_PARAMETER,
85 ST_FXLC,
86 };
87
88 struct d3dx_parameter
89 {
90 char *name;
91 char *semantic;
92 void *data;
93 D3DXPARAMETER_CLASS class;
94 D3DXPARAMETER_TYPE type;
95 UINT rows;
96 UINT columns;
97 UINT element_count;
98 UINT annotation_count;
99 UINT member_count;
100 DWORD flags;
101 UINT bytes;
102
103 struct d3dx_parameter *annotations;
104 struct d3dx_parameter *members;
105 };
106
107 struct d3dx_state
108 {
109 UINT operation;
110 UINT index;
111 enum STATE_TYPE type;
112 struct d3dx_parameter *parameter;
113 };
114
115 struct d3dx_sampler
116 {
117 UINT state_count;
118 struct d3dx_state *states;
119 };
120
121 struct d3dx_pass
122 {
123 char *name;
124 UINT state_count;
125 UINT annotation_count;
126
127 struct d3dx_state *states;
128 struct d3dx_parameter *annotations;
129 };
130
131 struct d3dx_technique
132 {
133 char *name;
134 UINT pass_count;
135 UINT annotation_count;
136
137 struct d3dx_parameter *annotations;
138 struct d3dx_pass *passes;
139 };
140
141 struct d3dx9_base_effect
142 {
143 struct ID3DXEffectImpl *effect;
144
145 UINT parameter_count;
146 UINT technique_count;
147
148 struct d3dx_parameter *parameters;
149 struct d3dx_technique *techniques;
150 };
151
152 struct ID3DXEffectImpl
153 {
154 ID3DXEffect ID3DXEffect_iface;
155 LONG ref;
156
157 struct d3dx9_base_effect base_effect;
158
159 struct ID3DXEffectStateManager *manager;
160 struct IDirect3DDevice9 *device;
161 struct ID3DXEffectPool *pool;
162 struct d3dx_technique *active_technique;
163 struct d3dx_pass *active_pass;
164 BOOL started;
165 DWORD flags;
166 };
167
168 struct ID3DXEffectCompilerImpl
169 {
170 ID3DXEffectCompiler ID3DXEffectCompiler_iface;
171 LONG ref;
172
173 struct d3dx9_base_effect base_effect;
174 };
175
176 static struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
177 struct d3dx_parameter *parameter, const char *name);
178 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *parameters,
179 const char *name);
180 static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects);
181 static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOOL child, enum STATE_TYPE st);
182
183 static const struct
184 {
185 enum STATE_CLASS class;
186 UINT op;
187 const char *name;
188 }
189 state_table[] =
190 {
191 /* Render sates */
192 {SC_RENDERSTATE, D3DRS_ZENABLE, "D3DRS_ZENABLE"}, /* 0x0 */
193 {SC_RENDERSTATE, D3DRS_FILLMODE, "D3DRS_FILLMODE"},
194 {SC_RENDERSTATE, D3DRS_SHADEMODE, "D3DRS_SHADEMODE"},
195 {SC_RENDERSTATE, D3DRS_ZWRITEENABLE, "D3DRS_ZWRITEENABLE"},
196 {SC_RENDERSTATE, D3DRS_ALPHATESTENABLE, "D3DRS_ALPHATESTENABLE"},
197 {SC_RENDERSTATE, D3DRS_LASTPIXEL, "D3DRS_LASTPIXEL"},
198 {SC_RENDERSTATE, D3DRS_SRCBLEND, "D3DRS_SRCBLEND"},
199 {SC_RENDERSTATE, D3DRS_DESTBLEND, "D3DRS_DESTBLEND"},
200 {SC_RENDERSTATE, D3DRS_CULLMODE, "D3DRS_CULLMODE"},
201 {SC_RENDERSTATE, D3DRS_ZFUNC, "D3DRS_ZFUNC"},
202 {SC_RENDERSTATE, D3DRS_ALPHAREF, "D3DRS_ALPHAREF"},
203 {SC_RENDERSTATE, D3DRS_ALPHAFUNC, "D3DRS_ALPHAFUNC"},
204 {SC_RENDERSTATE, D3DRS_DITHERENABLE, "D3DRS_DITHERENABLE"},
205 {SC_RENDERSTATE, D3DRS_ALPHABLENDENABLE, "D3DRS_ALPHABLENDENABLE"},
206 {SC_RENDERSTATE, D3DRS_FOGENABLE, "D3DRS_FOGENABLE"},
207 {SC_RENDERSTATE, D3DRS_SPECULARENABLE, "D3DRS_SPECULARENABLE"},
208 {SC_RENDERSTATE, D3DRS_FOGCOLOR, "D3DRS_FOGCOLOR"}, /* 0x10 */
209 {SC_RENDERSTATE, D3DRS_FOGTABLEMODE, "D3DRS_FOGTABLEMODE"},
210 {SC_RENDERSTATE, D3DRS_FOGSTART, "D3DRS_FOGSTART"},
211 {SC_RENDERSTATE, D3DRS_FOGEND, "D3DRS_FOGEND"},
212 {SC_RENDERSTATE, D3DRS_FOGDENSITY, "D3DRS_FOGDENSITY"},
213 {SC_RENDERSTATE, D3DRS_RANGEFOGENABLE, "D3DRS_RANGEFOGENABLE"},
214 {SC_RENDERSTATE, D3DRS_STENCILENABLE, "D3DRS_STENCILENABLE"},
215 {SC_RENDERSTATE, D3DRS_STENCILFAIL, "D3DRS_STENCILFAIL"},
216 {SC_RENDERSTATE, D3DRS_STENCILZFAIL, "D3DRS_STENCILZFAIL"},
217 {SC_RENDERSTATE, D3DRS_STENCILPASS, "D3DRS_STENCILPASS"},
218 {SC_RENDERSTATE, D3DRS_STENCILFUNC, "D3DRS_STENCILFUNC"},
219 {SC_RENDERSTATE, D3DRS_STENCILREF, "D3DRS_STENCILREF"},
220 {SC_RENDERSTATE, D3DRS_STENCILMASK, "D3DRS_STENCILMASK"},
221 {SC_RENDERSTATE, D3DRS_STENCILWRITEMASK, "D3DRS_STENCILWRITEMASK"},
222 {SC_RENDERSTATE, D3DRS_TEXTUREFACTOR, "D3DRS_TEXTUREFACTOR"},
223 {SC_RENDERSTATE, D3DRS_WRAP0, "D3DRS_WRAP0"},
224 {SC_RENDERSTATE, D3DRS_WRAP1, "D3DRS_WRAP1"}, /* 0x20 */
225 {SC_RENDERSTATE, D3DRS_WRAP2, "D3DRS_WRAP2"},
226 {SC_RENDERSTATE, D3DRS_WRAP3, "D3DRS_WRAP3"},
227 {SC_RENDERSTATE, D3DRS_WRAP4, "D3DRS_WRAP4"},
228 {SC_RENDERSTATE, D3DRS_WRAP5, "D3DRS_WRAP5"},
229 {SC_RENDERSTATE, D3DRS_WRAP6, "D3DRS_WRAP6"},
230 {SC_RENDERSTATE, D3DRS_WRAP7, "D3DRS_WRAP7"},
231 {SC_RENDERSTATE, D3DRS_WRAP8, "D3DRS_WRAP8"},
232 {SC_RENDERSTATE, D3DRS_WRAP9, "D3DRS_WRAP9"},
233 {SC_RENDERSTATE, D3DRS_WRAP10, "D3DRS_WRAP10"},
234 {SC_RENDERSTATE, D3DRS_WRAP11, "D3DRS_WRAP11"},
235 {SC_RENDERSTATE, D3DRS_WRAP12, "D3DRS_WRAP12"},
236 {SC_RENDERSTATE, D3DRS_WRAP13, "D3DRS_WRAP13"},
237 {SC_RENDERSTATE, D3DRS_WRAP14, "D3DRS_WRAP14"},
238 {SC_RENDERSTATE, D3DRS_WRAP15, "D3DRS_WRAP15"},
239 {SC_RENDERSTATE, D3DRS_CLIPPING, "D3DRS_CLIPPING"},
240 {SC_RENDERSTATE, D3DRS_LIGHTING, "D3DRS_LIGHTING"}, /* 0x30 */
241 {SC_RENDERSTATE, D3DRS_AMBIENT, "D3DRS_AMBIENT"},
242 {SC_RENDERSTATE, D3DRS_FOGVERTEXMODE, "D3DRS_FOGVERTEXMODE"},
243 {SC_RENDERSTATE, D3DRS_COLORVERTEX, "D3DRS_COLORVERTEX"},
244 {SC_RENDERSTATE, D3DRS_LOCALVIEWER, "D3DRS_LOCALVIEWER"},
245 {SC_RENDERSTATE, D3DRS_NORMALIZENORMALS, "D3DRS_NORMALIZENORMALS"},
246 {SC_RENDERSTATE, D3DRS_DIFFUSEMATERIALSOURCE, "D3DRS_DIFFUSEMATERIALSOURCE"},
247 {SC_RENDERSTATE, D3DRS_SPECULARMATERIALSOURCE, "D3DRS_SPECULARMATERIALSOURCE"},
248 {SC_RENDERSTATE, D3DRS_AMBIENTMATERIALSOURCE, "D3DRS_AMBIENTMATERIALSOURCE"},
249 {SC_RENDERSTATE, D3DRS_EMISSIVEMATERIALSOURCE, "D3DRS_EMISSIVEMATERIALSOURCE"},
250 {SC_RENDERSTATE, D3DRS_VERTEXBLEND, "D3DRS_VERTEXBLEND"},
251 {SC_RENDERSTATE, D3DRS_CLIPPLANEENABLE, "D3DRS_CLIPPLANEENABLE"},
252 {SC_RENDERSTATE, D3DRS_POINTSIZE, "D3DRS_POINTSIZE"},
253 {SC_RENDERSTATE, D3DRS_POINTSIZE_MIN, "D3DRS_POINTSIZE_MIN"},
254 {SC_RENDERSTATE, D3DRS_POINTSIZE_MAX, "D3DRS_POINTSIZE_MAX"},
255 {SC_RENDERSTATE, D3DRS_POINTSPRITEENABLE, "D3DRS_POINTSPRITEENABLE"},
256 {SC_RENDERSTATE, D3DRS_POINTSCALEENABLE, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
257 {SC_RENDERSTATE, D3DRS_POINTSCALE_A, "D3DRS_POINTSCALE_A"},
258 {SC_RENDERSTATE, D3DRS_POINTSCALE_B, "D3DRS_POINTSCALE_B"},
259 {SC_RENDERSTATE, D3DRS_POINTSCALE_C, "D3DRS_POINTSCALE_C"},
260 {SC_RENDERSTATE, D3DRS_MULTISAMPLEANTIALIAS, "D3DRS_MULTISAMPLEANTIALIAS"},
261 {SC_RENDERSTATE, D3DRS_MULTISAMPLEMASK, "D3DRS_MULTISAMPLEMASK"},
262 {SC_RENDERSTATE, D3DRS_PATCHEDGESTYLE, "D3DRS_PATCHEDGESTYLE"},
263 {SC_RENDERSTATE, D3DRS_DEBUGMONITORTOKEN, "D3DRS_DEBUGMONITORTOKEN"},
264 {SC_RENDERSTATE, D3DRS_INDEXEDVERTEXBLENDENABLE, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
265 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE, "D3DRS_COLORWRITEENABLE"},
266 {SC_RENDERSTATE, D3DRS_TWEENFACTOR, "D3DRS_TWEENFACTOR"},
267 {SC_RENDERSTATE, D3DRS_BLENDOP, "D3DRS_BLENDOP"},
268 {SC_RENDERSTATE, D3DRS_POSITIONDEGREE, "D3DRS_POSITIONDEGREE"},
269 {SC_RENDERSTATE, D3DRS_NORMALDEGREE, "D3DRS_NORMALDEGREE"},
270 {SC_RENDERSTATE, D3DRS_SCISSORTESTENABLE, "D3DRS_SCISSORTESTENABLE"},
271 {SC_RENDERSTATE, D3DRS_SLOPESCALEDEPTHBIAS, "D3DRS_SLOPESCALEDEPTHBIAS"},
272 {SC_RENDERSTATE, D3DRS_ANTIALIASEDLINEENABLE, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
273 {SC_RENDERSTATE, D3DRS_MINTESSELLATIONLEVEL, "D3DRS_MINTESSELLATIONLEVEL"},
274 {SC_RENDERSTATE, D3DRS_MAXTESSELLATIONLEVEL, "D3DRS_MAXTESSELLATIONLEVEL"},
275 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_X, "D3DRS_ADAPTIVETESS_X"},
276 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Y, "D3DRS_ADAPTIVETESS_Y"},
277 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_Z, "D3DRS_ADAPTIVETESS_Z"},
278 {SC_RENDERSTATE, D3DRS_ADAPTIVETESS_W, "D3DRS_ADAPTIVETESS_W"},
279 {SC_RENDERSTATE, D3DRS_ENABLEADAPTIVETESSELLATION, "D3DRS_ENABLEADAPTIVETESSELLATION"},
280 {SC_RENDERSTATE, D3DRS_TWOSIDEDSTENCILMODE, "D3DRS_TWOSIDEDSTENCILMODE"},
281 {SC_RENDERSTATE, D3DRS_CCW_STENCILFAIL, "D3DRS_CCW_STENCILFAIL"},
282 {SC_RENDERSTATE, D3DRS_CCW_STENCILZFAIL, "D3DRS_CCW_STENCILZFAIL"},
283 {SC_RENDERSTATE, D3DRS_CCW_STENCILPASS, "D3DRS_CCW_STENCILPASS"},
284 {SC_RENDERSTATE, D3DRS_CCW_STENCILFUNC, "D3DRS_CCW_STENCILFUNC"},
285 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE1, "D3DRS_COLORWRITEENABLE1"},
286 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE2, "D3DRS_COLORWRITEENABLE2"},
287 {SC_RENDERSTATE, D3DRS_COLORWRITEENABLE3, "D3DRS_COLORWRITEENABLE3"},
288 {SC_RENDERSTATE, D3DRS_BLENDFACTOR, "D3DRS_BLENDFACTOR"}, /* 0x60 */
289 {SC_RENDERSTATE, D3DRS_SRGBWRITEENABLE, "D3DRS_SRGBWRITEENABLE"},
290 {SC_RENDERSTATE, D3DRS_DEPTHBIAS, "D3DRS_DEPTHBIAS"},
291 {SC_RENDERSTATE, D3DRS_SEPARATEALPHABLENDENABLE, "D3DRS_SEPARATEALPHABLENDENABLE"},
292 {SC_RENDERSTATE, D3DRS_SRCBLENDALPHA, "D3DRS_SRCBLENDALPHA"},
293 {SC_RENDERSTATE, D3DRS_DESTBLENDALPHA, "D3DRS_DESTBLENDALPHA"},
294 {SC_RENDERSTATE, D3DRS_BLENDOPALPHA, "D3DRS_BLENDOPALPHA"},
295 /* Texture stages */
296 {SC_TEXTURESTAGE, D3DTSS_COLOROP, "D3DTSS_COLOROP"},
297 {SC_TEXTURESTAGE, D3DTSS_COLORARG0, "D3DTSS_COLORARG0"},
298 {SC_TEXTURESTAGE, D3DTSS_COLORARG1, "D3DTSS_COLORARG1"},
299 {SC_TEXTURESTAGE, D3DTSS_COLORARG2, "D3DTSS_COLORARG2"},
300 {SC_TEXTURESTAGE, D3DTSS_ALPHAOP, "D3DTSS_ALPHAOP"},
301 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG0, "D3DTSS_ALPHAARG0"},
302 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG1, "D3DTSS_ALPHAARG1"},
303 {SC_TEXTURESTAGE, D3DTSS_ALPHAARG2, "D3DTSS_ALPHAARG2"},
304 {SC_TEXTURESTAGE, D3DTSS_RESULTARG, "D3DTSS_RESULTARG"},
305 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT00, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
306 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT01, "D3DTSS_BUMPENVMAT01"},
307 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT10, "D3DTSS_BUMPENVMAT10"},
308 {SC_TEXTURESTAGE, D3DTSS_BUMPENVMAT11, "D3DTSS_BUMPENVMAT11"},
309 {SC_TEXTURESTAGE, D3DTSS_TEXCOORDINDEX, "D3DTSS_TEXCOORDINDEX"},
310 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLSCALE, "D3DTSS_BUMPENVLSCALE"},
311 {SC_TEXTURESTAGE, D3DTSS_BUMPENVLOFFSET, "D3DTSS_BUMPENVLOFFSET"},
312 {SC_TEXTURESTAGE, D3DTSS_TEXTURETRANSFORMFLAGS, "D3DTSS_TEXTURETRANSFORMFLAGS"},
313 {SC_TEXTURESTAGE, D3DTSS_CONSTANT, "D3DTSS_CONSTANT"},
314 /* NPatchMode */
315 {SC_NPATCHMODE, 0, "NPatchMode"},
316 /* FVF */
317 {SC_FVF, 0, "FVF"},
318 /* Transform */
319 {SC_TRANSFORM, D3DTS_PROJECTION, "D3DTS_PROJECTION"},
320 {SC_TRANSFORM, D3DTS_VIEW, "D3DTS_VIEW"},
321 {SC_TRANSFORM, D3DTS_WORLD, "D3DTS_WORLD"},
322 {SC_TRANSFORM, D3DTS_TEXTURE0, "D3DTS_TEXTURE0"},
323 /* Material */
324 {SC_MATERIAL, MT_DIFFUSE, "MaterialDiffuse"},
325 {SC_MATERIAL, MT_AMBIENT, "MaterialAmbient"}, /* 0x80 */
326 {SC_MATERIAL, MT_SPECULAR, "MaterialSpecular"},
327 {SC_MATERIAL, MT_EMISSIVE, "MaterialEmissive"},
328 {SC_MATERIAL, MT_POWER, "MaterialPower"},
329 /* Light */
330 {SC_LIGHT, LT_TYPE, "LightType"},
331 {SC_LIGHT, LT_DIFFUSE, "LightDiffuse"},
332 {SC_LIGHT, LT_SPECULAR, "LightSpecular"},
333 {SC_LIGHT, LT_AMBIENT, "LightAmbient"},
334 {SC_LIGHT, LT_POSITION, "LightPosition"},
335 {SC_LIGHT, LT_DIRECTION, "LightDirection"},
336 {SC_LIGHT, LT_RANGE, "LightRange"},
337 {SC_LIGHT, LT_FALLOFF, "LightFallOff"},
338 {SC_LIGHT, LT_ATTENUATION0, "LightAttenuation0"},
339 {SC_LIGHT, LT_ATTENUATION1, "LightAttenuation1"},
340 {SC_LIGHT, LT_ATTENUATION2, "LightAttenuation2"},
341 {SC_LIGHT, LT_THETA, "LightTheta"},
342 {SC_LIGHT, LT_PHI, "LightPhi"}, /* 0x90 */
343 /* Ligthenable */
344 {SC_LIGHTENABLE, 0, "LightEnable"},
345 /* Vertexshader */
346 {SC_VERTEXSHADER, 0, "Vertexshader"},
347 /* Pixelshader */
348 {SC_PIXELSHADER, 0, "Pixelshader"},
349 /* Shader constants */
350 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstantF"},
351 {SC_SHADERCONST, SCT_VSBOOL, "VertexShaderConstantB"},
352 {SC_SHADERCONST, SCT_VSINT, "VertexShaderConstantI"},
353 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant"},
354 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant1"},
355 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant2"},
356 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant3"},
357 {SC_SHADERCONST, SCT_VSFLOAT, "VertexShaderConstant4"},
358 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstantF"},
359 {SC_SHADERCONST, SCT_PSBOOL, "PixelShaderConstantB"},
360 {SC_SHADERCONST, SCT_PSINT, "PixelShaderConstantI"},
361 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant"},
362 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant1"}, /* 0xa0 */
363 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant2"},
364 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant3"},
365 {SC_SHADERCONST, SCT_PSFLOAT, "PixelShaderConstant4"},
366 /* Texture */
367 {SC_TEXTURE, 0, "Texture"},
368 /* Sampler states */
369 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSU, "AddressU"},
370 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSV, "AddressV"},
371 {SC_SAMPLERSTATE, D3DSAMP_ADDRESSW, "AddressW"},
372 {SC_SAMPLERSTATE, D3DSAMP_BORDERCOLOR, "BorderColor"},
373 {SC_SAMPLERSTATE, D3DSAMP_MAGFILTER, "MagFilter"},
374 {SC_SAMPLERSTATE, D3DSAMP_MINFILTER, "MinFilter"},
375 {SC_SAMPLERSTATE, D3DSAMP_MIPFILTER, "MipFilter"},
376 {SC_SAMPLERSTATE, D3DSAMP_MIPMAPLODBIAS, "MipMapLodBias"},
377 {SC_SAMPLERSTATE, D3DSAMP_MAXMIPLEVEL, "MaxMipLevel"},
378 {SC_SAMPLERSTATE, D3DSAMP_MAXANISOTROPY, "MaxAnisotropy"},
379 {SC_SAMPLERSTATE, D3DSAMP_SRGBTEXTURE, "SRGBTexture"},
380 {SC_SAMPLERSTATE, D3DSAMP_ELEMENTINDEX, "ElementIndex"}, /* 0xb0 */
381 {SC_SAMPLERSTATE, D3DSAMP_DMAPOFFSET, "DMAPOffset"},
382 /* Set sampler */
383 {SC_SETSAMPLER, 0, "Sampler"},
384 };
385
386 static inline void read_dword(const char **ptr, DWORD *d)
387 {
388 memcpy(d, *ptr, sizeof(*d));
389 *ptr += sizeof(*d);
390 }
391
392 static void skip_dword_unknown(const char **ptr, unsigned int count)
393 {
394 unsigned int i;
395 DWORD d;
396
397 FIXME("Skipping %u unknown DWORDs:\n", count);
398 for (i = 0; i < count; ++i)
399 {
400 read_dword(ptr, &d);
401 FIXME("\t0x%08x\n", d);
402 }
403 }
404
405 static inline struct d3dx_parameter *get_parameter_struct(D3DXHANDLE handle)
406 {
407 return (struct d3dx_parameter *) handle;
408 }
409
410 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
411 {
412 return (D3DXHANDLE) parameter;
413 }
414
415 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
416 {
417 return (D3DXHANDLE) technique;
418 }
419
420 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
421 {
422 return (D3DXHANDLE) pass;
423 }
424
425 static struct d3dx_technique *get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
426 {
427 UINT i;
428
429 if (!name) return NULL;
430
431 for (i = 0; i < base->technique_count; ++i)
432 {
433 if (!strcmp(base->techniques[i].name, name))
434 return &base->techniques[i];
435 }
436
437 return NULL;
438 }
439
440 static struct d3dx_technique *get_valid_technique(struct d3dx9_base_effect *base, D3DXHANDLE technique)
441 {
442 unsigned int i;
443
444 for (i = 0; i < base->technique_count; ++i)
445 {
446 if (get_technique_handle(&base->techniques[i]) == technique)
447 return &base->techniques[i];
448 }
449
450 return get_technique_by_name(base, technique);
451 }
452
453 static struct d3dx_pass *get_valid_pass(struct d3dx9_base_effect *base, D3DXHANDLE pass)
454 {
455 unsigned int i, k;
456
457 for (i = 0; i < base->technique_count; ++i)
458 {
459 struct d3dx_technique *technique = &base->techniques[i];
460
461 for (k = 0; k < technique->pass_count; ++k)
462 {
463 if (get_pass_handle(&technique->passes[k]) == pass)
464 return &technique->passes[k];
465 }
466 }
467
468 return NULL;
469 }
470
471 static struct d3dx_parameter *get_valid_sub_parameter(struct d3dx_parameter *param, D3DXHANDLE parameter)
472 {
473 unsigned int i, count;
474 struct d3dx_parameter *p;
475
476 for (i = 0; i < param->annotation_count; ++i)
477 {
478 if (get_parameter_handle(&param->annotations[i]) == parameter)
479 return &param->annotations[i];
480
481 p = get_valid_sub_parameter(&param->annotations[i], parameter);
482 if (p) return p;
483 }
484
485 count = param->element_count ? param->element_count : param->member_count;
486 for (i = 0; i < count; ++i)
487 {
488 if (get_parameter_handle(&param->members[i]) == parameter)
489 return &param->members[i];
490
491 p = get_valid_sub_parameter(&param->members[i], parameter);
492 if (p) return p;
493 }
494
495 return NULL;
496 }
497
498 static struct d3dx_parameter *get_valid_parameter(struct d3dx9_base_effect *base, D3DXHANDLE parameter)
499 {
500 unsigned int i, k, m;
501 struct d3dx_parameter *p;
502
503 for (i = 0; i < base->parameter_count; ++i)
504 {
505 if (get_parameter_handle(&base->parameters[i]) == parameter)
506 return &base->parameters[i];
507
508 p = get_valid_sub_parameter(&base->parameters[i], parameter);
509 if (p) return p;
510 }
511
512 for (i = 0; i < base->technique_count; ++i)
513 {
514 struct d3dx_technique *technique = &base->techniques[i];
515
516 for (k = 0; k < technique->pass_count; ++k)
517 {
518 struct d3dx_pass *pass = &technique->passes[k];
519
520 for (m = 0; m < pass->annotation_count; ++m)
521 {
522 if (get_parameter_handle(&pass->annotations[m]) == parameter)
523 return &pass->annotations[m];
524
525 p = get_valid_sub_parameter(&pass->annotations[m], parameter);
526 if (p) return p;
527 }
528 }
529
530 for (k = 0; k < technique->annotation_count; ++k)
531 {
532 if (get_parameter_handle(&technique->annotations[k]) == parameter)
533 return &technique->annotations[k];
534
535 p = get_valid_sub_parameter(&technique->annotations[k], parameter);
536 if (p) return p;
537 }
538 }
539
540 return get_parameter_by_name(base, NULL, parameter);
541 }
542
543 static void free_state(struct d3dx_state *state)
544 {
545 free_parameter_state(state->parameter, FALSE, FALSE, state->type);
546 }
547
548 static void free_sampler(struct d3dx_sampler *sampler)
549 {
550 UINT i;
551
552 for (i = 0; i < sampler->state_count; ++i)
553 {
554 free_state(&sampler->states[i]);
555 }
556 HeapFree(GetProcessHeap(), 0, sampler->states);
557 }
558
559 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child)
560 {
561 free_parameter_state(param, element, child, ST_CONSTANT);
562 }
563
564 static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOOL child, enum STATE_TYPE st)
565 {
566 unsigned int i;
567
568 TRACE("Free parameter %p, name %s, type %s, child %s, state_type %x\n", param, param->name,
569 debug_d3dxparameter_type(param->type), child ? "yes" : "no", st);
570
571 if (!param)
572 return;
573
574 if (param->annotations)
575 {
576 for (i = 0; i < param->annotation_count; ++i)
577 free_parameter(&param->annotations[i], FALSE, FALSE);
578 HeapFree(GetProcessHeap(), 0, param->annotations);
579 param->annotations = NULL;
580 }
581
582 if (param->members)
583 {
584 unsigned int count = param->element_count ? param->element_count : param->member_count;
585
586 for (i = 0; i < count; ++i)
587 free_parameter(&param->members[i], param->element_count != 0, TRUE);
588 HeapFree(GetProcessHeap(), 0, param->members);
589 param->members = NULL;
590 }
591
592 if (param->class == D3DXPC_OBJECT && !param->element_count)
593 {
594 switch (param->type)
595 {
596 case D3DXPT_STRING:
597 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
598 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
599 break;
600
601 case D3DXPT_TEXTURE:
602 case D3DXPT_TEXTURE1D:
603 case D3DXPT_TEXTURE2D:
604 case D3DXPT_TEXTURE3D:
605 case D3DXPT_TEXTURECUBE:
606 case D3DXPT_PIXELSHADER:
607 case D3DXPT_VERTEXSHADER:
608 if (st == ST_CONSTANT)
609 {
610 if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
611 }
612 else
613 {
614 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
615 }
616 if (!child) HeapFree(GetProcessHeap(), 0, param->data);
617 break;
618
619 case D3DXPT_SAMPLER:
620 case D3DXPT_SAMPLER1D:
621 case D3DXPT_SAMPLER2D:
622 case D3DXPT_SAMPLER3D:
623 case D3DXPT_SAMPLERCUBE:
624 if (st == ST_CONSTANT)
625 {
626 free_sampler((struct d3dx_sampler *)param->data);
627 }
628 else
629 {
630 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
631 }
632 /* samplers have always own data, so free that */
633 HeapFree(GetProcessHeap(), 0, param->data);
634 break;
635
636 default:
637 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
638 break;
639 }
640 }
641 else
642 {
643 if (!child)
644 {
645 if (st != ST_CONSTANT)
646 {
647 HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
648 }
649 HeapFree(GetProcessHeap(), 0, param->data);
650 }
651 }
652
653 /* only the parent has to release name and semantic */
654 if (!element)
655 {
656 HeapFree(GetProcessHeap(), 0, param->name);
657 HeapFree(GetProcessHeap(), 0, param->semantic);
658 }
659 }
660
661 static void free_pass(struct d3dx_pass *pass)
662 {
663 unsigned int i;
664
665 TRACE("Free pass %p\n", pass);
666
667 if (!pass)
668 return;
669
670 if (pass->annotations)
671 {
672 for (i = 0; i < pass->annotation_count; ++i)
673 free_parameter(&pass->annotations[i], FALSE, FALSE);
674 HeapFree(GetProcessHeap(), 0, pass->annotations);
675 pass->annotations = NULL;
676 }
677
678 if (pass->states)
679 {
680 for (i = 0; i < pass->state_count; ++i)
681 free_state(&pass->states[i]);
682 HeapFree(GetProcessHeap(), 0, pass->states);
683 pass->states = NULL;
684 }
685
686 HeapFree(GetProcessHeap(), 0, pass->name);
687 pass->name = NULL;
688 }
689
690 static void free_technique(struct d3dx_technique *technique)
691 {
692 unsigned int i;
693
694 TRACE("Free technique %p\n", technique);
695
696 if (!technique)
697 return;
698
699 if (technique->annotations)
700 {
701 for (i = 0; i < technique->annotation_count; ++i)
702 free_parameter(&technique->annotations[i], FALSE, FALSE);
703 HeapFree(GetProcessHeap(), 0, technique->annotations);
704 technique->annotations = NULL;
705 }
706
707 if (technique->passes)
708 {
709 for (i = 0; i < technique->pass_count; ++i)
710 free_pass(&technique->passes[i]);
711 HeapFree(GetProcessHeap(), 0, technique->passes);
712 technique->passes = NULL;
713 }
714
715 HeapFree(GetProcessHeap(), 0, technique->name);
716 technique->name = NULL;
717 }
718
719 static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
720 {
721 unsigned int i;
722
723 TRACE("base %p.\n", base);
724
725 if (base->parameters)
726 {
727 for (i = 0; i < base->parameter_count; ++i)
728 free_parameter(&base->parameters[i], FALSE, FALSE);
729 HeapFree(GetProcessHeap(), 0, base->parameters);
730 base->parameters = NULL;
731 }
732
733 if (base->techniques)
734 {
735 for (i = 0; i < base->technique_count; ++i)
736 free_technique(&base->techniques[i]);
737 HeapFree(GetProcessHeap(), 0, base->techniques);
738 base->techniques = NULL;
739 }
740 }
741
742 static void free_effect(struct ID3DXEffectImpl *effect)
743 {
744 TRACE("Free effect %p\n", effect);
745
746 d3dx9_base_effect_cleanup(&effect->base_effect);
747
748 if (effect->pool)
749 {
750 effect->pool->lpVtbl->Release(effect->pool);
751 }
752
753 if (effect->manager)
754 {
755 IUnknown_Release(effect->manager);
756 }
757
758 IDirect3DDevice9_Release(effect->device);
759 }
760
761 static void free_effect_compiler(struct ID3DXEffectCompilerImpl *compiler)
762 {
763 TRACE("Free effect compiler %p\n", compiler);
764
765 d3dx9_base_effect_cleanup(&compiler->base_effect);
766 }
767
768 static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
769 {
770 UINT i;
771
772 for (i = 0; i < 4; ++i)
773 {
774 if (i < param->columns)
775 set_number((FLOAT *)vector + i, D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
776 else
777 ((FLOAT *)vector)[i] = 0.0f;
778 }
779 }
780
781 static void set_vector(struct d3dx_parameter *param, CONST D3DXVECTOR4 *vector)
782 {
783 UINT i;
784
785 for (i = 0; i < param->columns; ++i)
786 {
787 set_number((FLOAT *)param->data + i, param->type, (FLOAT *)vector + i, D3DXPT_FLOAT);
788 }
789 }
790
791 static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix, BOOL transpose)
792 {
793 UINT i, k;
794
795 for (i = 0; i < 4; ++i)
796 {
797 for (k = 0; k < 4; ++k)
798 {
799 FLOAT *tmp = transpose ? (FLOAT *)&matrix->u.m[k][i] : (FLOAT *)&matrix->u.m[i][k];
800
801 if ((i < param->rows) && (k < param->columns))
802 set_number(tmp, D3DXPT_FLOAT, (DWORD *)param->data + i * param->columns + k, param->type);
803 else
804 *tmp = 0.0f;
805 }
806 }
807 }
808
809 static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix, BOOL transpose)
810 {
811 UINT i, k;
812
813 for (i = 0; i < param->rows; ++i)
814 {
815 for (k = 0; k < param->columns; ++k)
816 {
817 set_number((FLOAT *)param->data + i * param->columns + k, param->type,
818 transpose ? &matrix->u.m[k][i] : &matrix->u.m[i][k], D3DXPT_FLOAT);
819 }
820 }
821 }
822
823 static struct d3dx_parameter *get_parameter_element_by_name(struct d3dx_parameter *parameter, const char *name)
824 {
825 UINT element;
826 struct d3dx_parameter *temp_parameter;
827 const char *part;
828
829 TRACE("parameter %p, name %s\n", parameter, debugstr_a(name));
830
831 if (!name || !*name) return NULL;
832
833 element = atoi(name);
834 part = strchr(name, ']') + 1;
835
836 /* check for empty [] && element range */
837 if ((part - name) > 1 && parameter->element_count > element)
838 {
839 temp_parameter = &parameter->members[element];
840
841 switch (*part++)
842 {
843 case '.':
844 return get_parameter_by_name(NULL, temp_parameter, part);
845
846 case '@':
847 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
848
849 case '\0':
850 TRACE("Returning parameter %p\n", temp_parameter);
851 return temp_parameter;
852
853 default:
854 FIXME("Unhandled case \"%c\"\n", *--part);
855 break;
856 }
857 }
858
859 TRACE("Parameter not found\n");
860 return NULL;
861 }
862
863 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *annotations,
864 const char *name)
865 {
866 UINT i, length;
867 struct d3dx_parameter *temp_parameter;
868 const char *part;
869
870 TRACE("count %u, annotations %p, name %s\n", count, annotations, debugstr_a(name));
871
872 if (!name || !*name) return NULL;
873
874 length = strcspn( name, "[.@" );
875 part = name + length;
876
877 for (i = 0; i < count; ++i)
878 {
879 temp_parameter = &annotations[i];
880
881 if (!strcmp(temp_parameter->name, name))
882 {
883 TRACE("Returning annotation %p\n", temp_parameter);
884 return temp_parameter;
885 }
886 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
887 {
888 switch (*part++)
889 {
890 case '.':
891 return get_parameter_by_name(NULL, temp_parameter, part);
892
893 case '[':
894 return get_parameter_element_by_name(temp_parameter, part);
895
896 default:
897 FIXME("Unhandled case \"%c\"\n", *--part);
898 break;
899 }
900 }
901 }
902
903 TRACE("Annotation not found\n");
904 return NULL;
905 }
906
907 static struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *base,
908 struct d3dx_parameter *parameter, const char *name)
909 {
910 UINT i, count, length;
911 struct d3dx_parameter *temp_parameter;
912 struct d3dx_parameter *parameters;
913 const char *part;
914
915 TRACE("base %p, parameter %p, name %s\n", base, parameter, debugstr_a(name));
916
917 if (!name || !*name) return NULL;
918
919 if (!parameter)
920 {
921 count = base->parameter_count;
922 parameters = base->parameters;
923 }
924 else
925 {
926 count = parameter->member_count;
927 parameters = parameter->members;
928 }
929
930 length = strcspn( name, "[.@" );
931 part = name + length;
932
933 for (i = 0; i < count; i++)
934 {
935 temp_parameter = &parameters[i];
936
937 if (!strcmp(temp_parameter->name, name))
938 {
939 TRACE("Returning parameter %p\n", temp_parameter);
940 return temp_parameter;
941 }
942 else if (strlen(temp_parameter->name) == length && !strncmp(temp_parameter->name, name, length))
943 {
944 switch (*part++)
945 {
946 case '.':
947 return get_parameter_by_name(NULL, temp_parameter, part);
948
949 case '@':
950 return get_annotation_by_name(temp_parameter->annotation_count, temp_parameter->annotations, part);
951
952 case '[':
953 return get_parameter_element_by_name(temp_parameter, part);
954
955 default:
956 FIXME("Unhandled case \"%c\"\n", *--part);
957 break;
958 }
959 }
960 }
961
962 TRACE("Parameter not found\n");
963 return NULL;
964 }
965
966 static inline DWORD d3dx9_effect_version(DWORD major, DWORD minor)
967 {
968 return (0xfeff0000 | ((major) << 8) | (minor));
969 }
970
971 static HRESULT d3dx9_base_effect_get_desc(struct d3dx9_base_effect *base, D3DXEFFECT_DESC *desc)
972 {
973 if (!desc)
974 {
975 WARN("Invalid argument specified.\n");
976 return D3DERR_INVALIDCALL;
977 }
978
979 FIXME("partial stub!\n");
980
981 /* TODO: add creator and function count. */
982 desc->Creator = NULL;
983 desc->Functions = 0;
984 desc->Parameters = base->parameter_count;
985 desc->Techniques = base->technique_count;
986
987 return D3D_OK;
988 }
989
990 static HRESULT d3dx9_base_effect_get_parameter_desc(struct d3dx9_base_effect *base,
991 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
992 {
993 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
994
995 if (!desc || !param)
996 {
997 WARN("Invalid argument specified.\n");
998 return D3DERR_INVALIDCALL;
999 }
1000
1001 desc->Name = param->name;
1002 desc->Semantic = param->semantic;
1003 desc->Class = param->class;
1004 desc->Type = param->type;
1005 desc->Rows = param->rows;
1006 desc->Columns = param->columns;
1007 desc->Elements = param->element_count;
1008 desc->Annotations = param->annotation_count;
1009 desc->StructMembers = param->member_count;
1010 desc->Flags = param->flags;
1011 desc->Bytes = param->bytes;
1012
1013 return D3D_OK;
1014 }
1015
1016 static HRESULT d3dx9_base_effect_get_technique_desc(struct d3dx9_base_effect *base,
1017 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
1018 {
1019 struct d3dx_technique *tech = technique ? get_valid_technique(base, technique) : &base->techniques[0];
1020
1021 if (!desc || !tech)
1022 {
1023 WARN("Invalid argument specified.\n");
1024 return D3DERR_INVALIDCALL;
1025 }
1026
1027 desc->Name = tech->name;
1028 desc->Passes = tech->pass_count;
1029 desc->Annotations = tech->annotation_count;
1030
1031 return D3D_OK;
1032 }
1033
1034 static HRESULT d3dx9_base_effect_get_pass_desc(struct d3dx9_base_effect *base,
1035 D3DXHANDLE pass, D3DXPASS_DESC *desc)
1036 {
1037 struct d3dx_pass *p = get_valid_pass(base, pass);
1038
1039 if (!desc || !p)
1040 {
1041 WARN("Invalid argument specified.\n");
1042 return D3DERR_INVALIDCALL;
1043 }
1044
1045 desc->Name = p->name;
1046 desc->Annotations = p->annotation_count;
1047
1048 FIXME("Pixel shader and vertex shader are not supported, yet.\n");
1049 desc->pVertexShaderFunction = NULL;
1050 desc->pPixelShaderFunction = NULL;
1051
1052 return D3D_OK;
1053 }
1054
1055 static HRESULT d3dx9_base_effect_get_function_desc(struct d3dx9_base_effect *base,
1056 D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
1057 {
1058 FIXME("stub!\n");
1059
1060 return E_NOTIMPL;
1061 }
1062
1063 static D3DXHANDLE d3dx9_base_effect_get_parameter(struct d3dx9_base_effect *base,
1064 D3DXHANDLE parameter, UINT index)
1065 {
1066 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1067
1068 if (!parameter)
1069 {
1070 if (index < base->parameter_count)
1071 {
1072 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1073 return get_parameter_handle(&base->parameters[index]);
1074 }
1075 }
1076 else
1077 {
1078 if (param && !param->element_count && index < param->member_count)
1079 {
1080 TRACE("Returning parameter %p.\n", &param->members[index]);
1081 return get_parameter_handle(&param->members[index]);
1082 }
1083 }
1084
1085 WARN("Invalid argument specified.\n");
1086
1087 return NULL;
1088 }
1089
1090 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_name(struct d3dx9_base_effect *base,
1091 D3DXHANDLE parameter, const char *name)
1092 {
1093 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1094 D3DXHANDLE handle;
1095
1096 if (!name)
1097 {
1098 handle = get_parameter_handle(param);
1099 TRACE("Returning parameter %p.\n", handle);
1100 return handle;
1101 }
1102
1103 handle = get_parameter_handle(get_parameter_by_name(base, param, name));
1104 TRACE("Returning parameter %p.\n", handle);
1105
1106 return handle;
1107 }
1108
1109 static D3DXHANDLE d3dx9_base_effect_get_parameter_by_semantic(struct d3dx9_base_effect *base,
1110 D3DXHANDLE parameter, const char *semantic)
1111 {
1112 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1113 struct d3dx_parameter *temp_param;
1114 UINT i;
1115
1116 if (!parameter)
1117 {
1118 for (i = 0; i < base->parameter_count; ++i)
1119 {
1120 temp_param = &base->parameters[i];
1121
1122 if (!temp_param->semantic)
1123 {
1124 if (!semantic)
1125 {
1126 TRACE("Returning parameter %p\n", temp_param);
1127 return get_parameter_handle(temp_param);
1128 }
1129 continue;
1130 }
1131
1132 if (!strcasecmp(temp_param->semantic, semantic))
1133 {
1134 TRACE("Returning parameter %p\n", temp_param);
1135 return get_parameter_handle(temp_param);
1136 }
1137 }
1138 }
1139 else if (param)
1140 {
1141 for (i = 0; i < param->member_count; ++i)
1142 {
1143 temp_param = &param->members[i];
1144
1145 if (!temp_param->semantic)
1146 {
1147 if (!semantic)
1148 {
1149 TRACE("Returning parameter %p\n", temp_param);
1150 return get_parameter_handle(temp_param);
1151 }
1152 continue;
1153 }
1154
1155 if (!strcasecmp(temp_param->semantic, semantic))
1156 {
1157 TRACE("Returning parameter %p\n", temp_param);
1158 return get_parameter_handle(temp_param);
1159 }
1160 }
1161 }
1162
1163 WARN("Invalid argument specified\n");
1164
1165 return NULL;
1166 }
1167
1168 static D3DXHANDLE d3dx9_base_effect_get_parameter_element(struct d3dx9_base_effect *base,
1169 D3DXHANDLE parameter, UINT index)
1170 {
1171 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1172
1173 if (!param)
1174 {
1175 if (index < base->parameter_count)
1176 {
1177 TRACE("Returning parameter %p.\n", &base->parameters[index]);
1178 return get_parameter_handle(&base->parameters[index]);
1179 }
1180 }
1181 else
1182 {
1183 if (index < param->element_count)
1184 {
1185 TRACE("Returning parameter %p.\n", &param->members[index]);
1186 return get_parameter_handle(&param->members[index]);
1187 }
1188 }
1189
1190 WARN("Invalid argument specified\n");
1191
1192 return NULL;
1193 }
1194
1195 static D3DXHANDLE d3dx9_base_effect_get_technique(struct d3dx9_base_effect *base, UINT index)
1196 {
1197 if (index >= base->technique_count)
1198 {
1199 WARN("Invalid argument specified.\n");
1200 return NULL;
1201 }
1202
1203 TRACE("Returning technique %p.\n", &base->techniques[index]);
1204
1205 return get_technique_handle(&base->techniques[index]);
1206 }
1207
1208 static D3DXHANDLE d3dx9_base_effect_get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
1209 {
1210 struct d3dx_technique *tech = get_technique_by_name(base, name);
1211
1212 if (tech)
1213 {
1214 D3DXHANDLE t = get_technique_handle(tech);
1215 TRACE("Returning technique %p\n", t);
1216 return t;
1217 }
1218
1219 WARN("Invalid argument specified.\n");
1220
1221 return NULL;
1222 }
1223
1224 static D3DXHANDLE d3dx9_base_effect_get_pass(struct d3dx9_base_effect *base,
1225 D3DXHANDLE technique, UINT index)
1226 {
1227 struct d3dx_technique *tech = get_valid_technique(base, technique);
1228
1229 if (tech && index < tech->pass_count)
1230 {
1231 TRACE("Returning pass %p\n", &tech->passes[index]);
1232 return get_pass_handle(&tech->passes[index]);
1233 }
1234
1235 WARN("Invalid argument specified.\n");
1236
1237 return NULL;
1238 }
1239
1240 static D3DXHANDLE d3dx9_base_effect_get_pass_by_name(struct d3dx9_base_effect *base,
1241 D3DXHANDLE technique, const char *name)
1242 {
1243 struct d3dx_technique *tech = get_valid_technique(base, technique);
1244
1245 if (tech && name)
1246 {
1247 unsigned int i;
1248
1249 for (i = 0; i < tech->pass_count; ++i)
1250 {
1251 struct d3dx_pass *pass = &tech->passes[i];
1252
1253 if (!strcmp(pass->name, name))
1254 {
1255 TRACE("Returning pass %p\n", pass);
1256 return get_pass_handle(pass);
1257 }
1258 }
1259 }
1260
1261 WARN("Invalid argument specified.\n");
1262
1263 return NULL;
1264 }
1265
1266 static D3DXHANDLE d3dx9_base_effect_get_function(struct d3dx9_base_effect *base, UINT index)
1267 {
1268 FIXME("stub!\n");
1269
1270 return NULL;
1271 }
1272
1273 static D3DXHANDLE d3dx9_base_effect_get_function_by_name(struct d3dx9_base_effect *base, const char *name)
1274 {
1275 FIXME("stub!\n");
1276
1277 return NULL;
1278 }
1279
1280 static UINT get_annotation_from_object(struct d3dx9_base_effect *base,
1281 D3DXHANDLE object, struct d3dx_parameter **annotations)
1282 {
1283 struct d3dx_parameter *param = get_valid_parameter(base, object);
1284 struct d3dx_pass *pass = get_valid_pass(base, object);
1285 struct d3dx_technique *technique = get_valid_technique(base, object);
1286
1287 if (pass)
1288 {
1289 *annotations = pass->annotations;
1290 return pass->annotation_count;
1291 }
1292 else if (technique)
1293 {
1294 *annotations = technique->annotations;
1295 return technique->annotation_count;
1296 }
1297 else if (param)
1298 {
1299 *annotations = param->annotations;
1300 return param->annotation_count;
1301 }
1302 else
1303 {
1304 FIXME("Functions are not handled, yet!\n");
1305 return 0;
1306 }
1307 }
1308
1309 static D3DXHANDLE d3dx9_base_effect_get_annotation(struct d3dx9_base_effect *base,
1310 D3DXHANDLE object, UINT index)
1311 {
1312 struct d3dx_parameter *annotations = NULL;
1313 UINT annotation_count = 0;
1314
1315 annotation_count = get_annotation_from_object(base, object, &annotations);
1316
1317 if (index < annotation_count)
1318 {
1319 TRACE("Returning parameter %p\n", &annotations[index]);
1320 return get_parameter_handle(&annotations[index]);
1321 }
1322
1323 WARN("Invalid argument specified\n");
1324
1325 return NULL;
1326 }
1327
1328 static D3DXHANDLE d3dx9_base_effect_get_annotation_by_name(struct d3dx9_base_effect *base,
1329 D3DXHANDLE object, const char *name)
1330 {
1331 struct d3dx_parameter *annotation = NULL;
1332 struct d3dx_parameter *annotations = NULL;
1333 UINT annotation_count = 0;
1334
1335 if (!name)
1336 {
1337 WARN("Invalid argument specified\n");
1338 return NULL;
1339 }
1340
1341 annotation_count = get_annotation_from_object(base, object, &annotations);
1342
1343 annotation = get_annotation_by_name(annotation_count, annotations, name);
1344 if (annotation)
1345 {
1346 TRACE("Returning parameter %p\n", annotation);
1347 return get_parameter_handle(annotation);
1348 }
1349
1350 WARN("Invalid argument specified\n");
1351
1352 return NULL;
1353 }
1354
1355 static HRESULT d3dx9_base_effect_set_value(struct d3dx9_base_effect *base,
1356 D3DXHANDLE parameter, const void *data, UINT bytes)
1357 {
1358 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1359
1360 if (!param)
1361 {
1362 WARN("Invalid parameter %p specified\n", parameter);
1363 return D3DERR_INVALIDCALL;
1364 }
1365
1366 /* samplers don't touch data */
1367 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1368 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1369 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1370 {
1371 TRACE("Sampler: returning E_FAIL\n");
1372 return E_FAIL;
1373 }
1374
1375 if (data && param->bytes <= bytes)
1376 {
1377 switch (param->type)
1378 {
1379 case D3DXPT_VOID:
1380 case D3DXPT_BOOL:
1381 case D3DXPT_INT:
1382 case D3DXPT_FLOAT:
1383 TRACE("Copy %u bytes\n", param->bytes);
1384 memcpy(param->data, data, param->bytes);
1385 break;
1386
1387 default:
1388 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1389 break;
1390 }
1391
1392 return D3D_OK;
1393 }
1394
1395 WARN("Invalid argument specified\n");
1396
1397 return D3DERR_INVALIDCALL;
1398 }
1399
1400 static HRESULT d3dx9_base_effect_get_value(struct d3dx9_base_effect *base,
1401 D3DXHANDLE parameter, void *data, UINT bytes)
1402 {
1403 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1404
1405 if (!param)
1406 {
1407 WARN("Invalid parameter %p specified\n", parameter);
1408 return D3DERR_INVALIDCALL;
1409 }
1410
1411 /* samplers don't touch data */
1412 if (param->class == D3DXPC_OBJECT && (param->type == D3DXPT_SAMPLER
1413 || param->type == D3DXPT_SAMPLER1D || param->type == D3DXPT_SAMPLER2D
1414 || param->type == D3DXPT_SAMPLER3D || param->type == D3DXPT_SAMPLERCUBE))
1415 {
1416 TRACE("Sampler: returning E_FAIL\n");
1417 return E_FAIL;
1418 }
1419
1420 if (data && param->bytes <= bytes)
1421 {
1422 TRACE("Type %s\n", debug_d3dxparameter_type(param->type));
1423
1424 switch (param->type)
1425 {
1426 case D3DXPT_VOID:
1427 case D3DXPT_BOOL:
1428 case D3DXPT_INT:
1429 case D3DXPT_FLOAT:
1430 case D3DXPT_STRING:
1431 break;
1432
1433 case D3DXPT_VERTEXSHADER:
1434 case D3DXPT_PIXELSHADER:
1435 case D3DXPT_TEXTURE:
1436 case D3DXPT_TEXTURE1D:
1437 case D3DXPT_TEXTURE2D:
1438 case D3DXPT_TEXTURE3D:
1439 case D3DXPT_TEXTURECUBE:
1440 {
1441 UINT i;
1442
1443 for (i = 0; i < (param->element_count ? param->element_count : 1); ++i)
1444 {
1445 IUnknown *unk = ((IUnknown **)param->data)[i];
1446 if (unk) IUnknown_AddRef(unk);
1447 }
1448 break;
1449 }
1450
1451 default:
1452 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
1453 break;
1454 }
1455
1456 TRACE("Copy %u bytes\n", param->bytes);
1457 memcpy(data, param->data, param->bytes);
1458 return D3D_OK;
1459 }
1460
1461 WARN("Invalid argument specified\n");
1462
1463 return D3DERR_INVALIDCALL;
1464 }
1465
1466 static HRESULT d3dx9_base_effect_set_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL b)
1467 {
1468 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1469
1470 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1471 {
1472 set_number(param->data, param->type, &b, D3DXPT_BOOL);
1473 return D3D_OK;
1474 }
1475
1476 WARN("Invalid argument specified\n");
1477
1478 return D3DERR_INVALIDCALL;
1479 }
1480
1481 static HRESULT d3dx9_base_effect_get_bool(struct d3dx9_base_effect *base, D3DXHANDLE parameter, BOOL *b)
1482 {
1483 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1484
1485 if (b && param && !param->element_count && param->rows == 1 && param->columns == 1)
1486 {
1487 set_number(b, D3DXPT_BOOL, param->data, param->type);
1488 TRACE("Returning %s\n", *b ? "TRUE" : "FALSE");
1489 return D3D_OK;
1490 }
1491
1492 WARN("Invalid argument specified\n");
1493
1494 return D3DERR_INVALIDCALL;
1495 }
1496
1497 static HRESULT d3dx9_base_effect_set_bool_array(struct d3dx9_base_effect *base,
1498 D3DXHANDLE parameter, const BOOL *b, UINT count)
1499 {
1500 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1501
1502 if (param)
1503 {
1504 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1505
1506 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1507
1508 switch (param->class)
1509 {
1510 case D3DXPC_SCALAR:
1511 case D3DXPC_VECTOR:
1512 case D3DXPC_MATRIX_ROWS:
1513 for (i = 0; i < size; ++i)
1514 {
1515 /* don't crop the input, use D3DXPT_INT instead of D3DXPT_BOOL */
1516 set_number((DWORD *)param->data + i, param->type, &b[i], D3DXPT_INT);
1517 }
1518 return D3D_OK;
1519
1520 case D3DXPC_OBJECT:
1521 case D3DXPC_STRUCT:
1522 break;
1523
1524 default:
1525 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1526 break;
1527 }
1528 }
1529
1530 WARN("Invalid argument specified\n");
1531
1532 return D3DERR_INVALIDCALL;
1533 }
1534
1535 static HRESULT d3dx9_base_effect_get_bool_array(struct d3dx9_base_effect *base,
1536 D3DXHANDLE parameter, BOOL *b, UINT count)
1537 {
1538 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1539
1540 if (b && param && (param->class == D3DXPC_SCALAR
1541 || param->class == D3DXPC_VECTOR
1542 || param->class == D3DXPC_MATRIX_ROWS
1543 || param->class == D3DXPC_MATRIX_COLUMNS))
1544 {
1545 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1546
1547 for (i = 0; i < size; ++i)
1548 {
1549 set_number(&b[i], D3DXPT_BOOL, (DWORD *)param->data + i, param->type);
1550 }
1551 return D3D_OK;
1552 }
1553
1554 WARN("Invalid argument specified\n");
1555
1556 return D3DERR_INVALIDCALL;
1557 }
1558
1559 static HRESULT d3dx9_base_effect_set_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT n)
1560 {
1561 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1562
1563 if (param && !param->element_count)
1564 {
1565 if (param->rows == 1 && param->columns == 1)
1566 {
1567 set_number(param->data, param->type, &n, D3DXPT_INT);
1568 return D3D_OK;
1569 }
1570
1571 /*
1572 * Split the value, if parameter is a vector with dimension 3 or 4.
1573 */
1574 if (param->type == D3DXPT_FLOAT &&
1575 ((param->class == D3DXPC_VECTOR && param->columns != 2) ||
1576 (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1577 {
1578 TRACE("Vector fixup\n");
1579
1580 *(FLOAT *)param->data = ((n & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1581 ((FLOAT *)param->data)[1] = ((n & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1582 ((FLOAT *)param->data)[2] = (n & 0xff) * INT_FLOAT_MULTI_INVERSE;
1583 if (param->rows * param->columns > 3)
1584 {
1585 ((FLOAT *)param->data)[3] = ((n & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1586 }
1587 return D3D_OK;
1588 }
1589 }
1590
1591 WARN("Invalid argument specified\n");
1592
1593 return D3DERR_INVALIDCALL;
1594 }
1595
1596 static HRESULT d3dx9_base_effect_get_int(struct d3dx9_base_effect *base, D3DXHANDLE parameter, INT *n)
1597 {
1598 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1599
1600 if (n && param && !param->element_count)
1601 {
1602 if (param->columns == 1 && param->rows == 1)
1603 {
1604 set_number(n, D3DXPT_INT, param->data, param->type);
1605 TRACE("Returning %i\n", *n);
1606 return D3D_OK;
1607 }
1608
1609 if (param->type == D3DXPT_FLOAT &&
1610 ((param->class == D3DXPC_VECTOR && param->columns != 2)
1611 || (param->class == D3DXPC_MATRIX_ROWS && param->rows != 2 && param->columns == 1)))
1612 {
1613 TRACE("Vector fixup\n");
1614
1615 /* all components (3,4) are clamped (0,255) and put in the INT */
1616 *n = (INT)(min(max(0.0f, *((FLOAT *)param->data + 2)), 1.0f) * INT_FLOAT_MULTI);
1617 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 1)), 1.0f) * INT_FLOAT_MULTI)) << 8;
1618 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 0)), 1.0f) * INT_FLOAT_MULTI)) << 16;
1619 if (param->columns * param->rows > 3)
1620 {
1621 *n += ((INT)(min(max(0.0f, *((FLOAT *)param->data + 3)), 1.0f) * INT_FLOAT_MULTI)) << 24;
1622 }
1623
1624 TRACE("Returning %i\n", *n);
1625 return D3D_OK;
1626 }
1627 }
1628
1629 WARN("Invalid argument specified\n");
1630
1631 return D3DERR_INVALIDCALL;
1632 }
1633
1634 static HRESULT d3dx9_base_effect_set_int_array(struct d3dx9_base_effect *base,
1635 D3DXHANDLE parameter, const INT *n, UINT count)
1636 {
1637 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1638
1639 if (param)
1640 {
1641 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1642
1643 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1644
1645 switch (param->class)
1646 {
1647 case D3DXPC_SCALAR:
1648 case D3DXPC_VECTOR:
1649 case D3DXPC_MATRIX_ROWS:
1650 for (i = 0; i < size; ++i)
1651 {
1652 set_number((DWORD *)param->data + i, param->type, &n[i], D3DXPT_INT);
1653 }
1654 return D3D_OK;
1655
1656 case D3DXPC_OBJECT:
1657 case D3DXPC_STRUCT:
1658 break;
1659
1660 default:
1661 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1662 break;
1663 }
1664 }
1665
1666 WARN("Invalid argument specified\n");
1667
1668 return D3DERR_INVALIDCALL;
1669 }
1670
1671 static HRESULT d3dx9_base_effect_get_int_array(struct d3dx9_base_effect *base,
1672 D3DXHANDLE parameter, INT *n, UINT count)
1673 {
1674 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1675
1676 if (n && param && (param->class == D3DXPC_SCALAR
1677 || param->class == D3DXPC_VECTOR
1678 || param->class == D3DXPC_MATRIX_ROWS
1679 || param->class == D3DXPC_MATRIX_COLUMNS))
1680 {
1681 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1682
1683 for (i = 0; i < size; ++i)
1684 {
1685 set_number(&n[i], D3DXPT_INT, (DWORD *)param->data + i, param->type);
1686 }
1687 return D3D_OK;
1688 }
1689
1690 WARN("Invalid argument specified\n");
1691
1692 return D3DERR_INVALIDCALL;
1693 }
1694
1695 static HRESULT d3dx9_base_effect_set_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float f)
1696 {
1697 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1698
1699 if (param && !param->element_count && param->rows == 1 && param->columns == 1)
1700 {
1701 set_number((DWORD *)param->data, param->type, &f, D3DXPT_FLOAT);
1702 return D3D_OK;
1703 }
1704
1705 WARN("Invalid argument specified\n");
1706
1707 return D3DERR_INVALIDCALL;
1708 }
1709
1710 static HRESULT d3dx9_base_effect_get_float(struct d3dx9_base_effect *base, D3DXHANDLE parameter, float *f)
1711 {
1712 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1713
1714 if (f && param && !param->element_count && param->columns == 1 && param->rows == 1)
1715 {
1716 set_number(f, D3DXPT_FLOAT, (DWORD *)param->data, param->type);
1717 TRACE("Returning %f\n", *f);
1718 return D3D_OK;
1719 }
1720
1721 WARN("Invalid argument specified\n");
1722
1723 return D3DERR_INVALIDCALL;
1724 }
1725
1726 static HRESULT d3dx9_base_effect_set_float_array(struct d3dx9_base_effect *base,
1727 D3DXHANDLE parameter, const float *f, UINT count)
1728 {
1729 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1730
1731 if (param)
1732 {
1733 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1734
1735 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1736
1737 switch (param->class)
1738 {
1739 case D3DXPC_SCALAR:
1740 case D3DXPC_VECTOR:
1741 case D3DXPC_MATRIX_ROWS:
1742 for (i = 0; i < size; ++i)
1743 {
1744 set_number((DWORD *)param->data + i, param->type, &f[i], D3DXPT_FLOAT);
1745 }
1746 return D3D_OK;
1747
1748 case D3DXPC_OBJECT:
1749 case D3DXPC_STRUCT:
1750 break;
1751
1752 default:
1753 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1754 break;
1755 }
1756 }
1757
1758 WARN("Invalid argument specified\n");
1759
1760 return D3DERR_INVALIDCALL;
1761 }
1762
1763 static HRESULT d3dx9_base_effect_get_float_array(struct d3dx9_base_effect *base,
1764 D3DXHANDLE parameter, float *f, UINT count)
1765 {
1766 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1767
1768 if (f && param && (param->class == D3DXPC_SCALAR
1769 || param->class == D3DXPC_VECTOR
1770 || param->class == D3DXPC_MATRIX_ROWS
1771 || param->class == D3DXPC_MATRIX_COLUMNS))
1772 {
1773 UINT i, size = min(count, param->bytes / sizeof(DWORD));
1774
1775 for (i = 0; i < size; ++i)
1776 {
1777 set_number(&f[i], D3DXPT_FLOAT, (DWORD *)param->data + i, param->type);
1778 }
1779 return D3D_OK;
1780 }
1781
1782 WARN("Invalid argument specified\n");
1783
1784 return D3DERR_INVALIDCALL;
1785 }
1786
1787 static HRESULT d3dx9_base_effect_set_vector(struct d3dx9_base_effect *base,
1788 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
1789 {
1790 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1791
1792 if (param && !param->element_count)
1793 {
1794 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1795
1796 switch (param->class)
1797 {
1798 case D3DXPC_SCALAR:
1799 case D3DXPC_VECTOR:
1800 if (param->type == D3DXPT_INT && param->bytes == 4)
1801 {
1802 DWORD tmp;
1803
1804 TRACE("INT fixup\n");
1805 tmp = (DWORD)(max(min(vector->z, 1.0f), 0.0f) * INT_FLOAT_MULTI);
1806 tmp += ((DWORD)(max(min(vector->y, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 8;
1807 tmp += ((DWORD)(max(min(vector->x, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 16;
1808 tmp += ((DWORD)(max(min(vector->w, 1.0f), 0.0f) * INT_FLOAT_MULTI)) << 24;
1809
1810 *(INT *)param->data = tmp;
1811 return D3D_OK;
1812 }
1813 set_vector(param, vector);
1814 return D3D_OK;
1815
1816 case D3DXPC_MATRIX_ROWS:
1817 case D3DXPC_OBJECT:
1818 case D3DXPC_STRUCT:
1819 break;
1820
1821 default:
1822 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1823 break;
1824 }
1825 }
1826
1827 WARN("Invalid argument specified\n");
1828
1829 return D3DERR_INVALIDCALL;
1830 }
1831
1832 static HRESULT d3dx9_base_effect_get_vector(struct d3dx9_base_effect *base,
1833 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
1834 {
1835 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1836
1837 if (vector && param && !param->element_count)
1838 {
1839 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1840
1841 switch (param->class)
1842 {
1843 case D3DXPC_SCALAR:
1844 case D3DXPC_VECTOR:
1845 if (param->type == D3DXPT_INT && param->bytes == 4)
1846 {
1847 TRACE("INT fixup\n");
1848 vector->x = (((*(INT *)param->data) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE;
1849 vector->y = (((*(INT *)param->data) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE;
1850 vector->z = ((*(INT *)param->data) & 0xff) * INT_FLOAT_MULTI_INVERSE;
1851 vector->w = (((*(INT *)param->data) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE;
1852 return D3D_OK;
1853 }
1854 get_vector(param, vector);
1855 return D3D_OK;
1856
1857 case D3DXPC_MATRIX_ROWS:
1858 case D3DXPC_OBJECT:
1859 case D3DXPC_STRUCT:
1860 break;
1861
1862 default:
1863 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1864 break;
1865 }
1866 }
1867
1868 WARN("Invalid argument specified\n");
1869
1870 return D3DERR_INVALIDCALL;
1871 }
1872
1873 static HRESULT d3dx9_base_effect_set_vector_array(struct d3dx9_base_effect *base,
1874 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
1875 {
1876 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1877
1878 if (param && param->element_count && param->element_count >= count)
1879 {
1880 UINT i;
1881
1882 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1883
1884 switch (param->class)
1885 {
1886 case D3DXPC_VECTOR:
1887 for (i = 0; i < count; ++i)
1888 {
1889 set_vector(&param->members[i], &vector[i]);
1890 }
1891 return D3D_OK;
1892
1893 case D3DXPC_SCALAR:
1894 case D3DXPC_MATRIX_ROWS:
1895 case D3DXPC_OBJECT:
1896 case D3DXPC_STRUCT:
1897 break;
1898
1899 default:
1900 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1901 break;
1902 }
1903 }
1904
1905 WARN("Invalid argument specified\n");
1906
1907 return D3DERR_INVALIDCALL;
1908 }
1909
1910 static HRESULT d3dx9_base_effect_get_vector_array(struct d3dx9_base_effect *base,
1911 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
1912 {
1913 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1914
1915 if (!count) return D3D_OK;
1916
1917 if (vector && param && count <= param->element_count)
1918 {
1919 UINT i;
1920
1921 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1922
1923 switch (param->class)
1924 {
1925 case D3DXPC_VECTOR:
1926 for (i = 0; i < count; ++i)
1927 {
1928 get_vector(&param->members[i], &vector[i]);
1929 }
1930 return D3D_OK;
1931
1932 case D3DXPC_SCALAR:
1933 case D3DXPC_MATRIX_ROWS:
1934 case D3DXPC_OBJECT:
1935 case D3DXPC_STRUCT:
1936 break;
1937
1938 default:
1939 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1940 break;
1941 }
1942 }
1943
1944 WARN("Invalid argument specified\n");
1945
1946 return D3DERR_INVALIDCALL;
1947 }
1948
1949 static HRESULT d3dx9_base_effect_set_matrix(struct d3dx9_base_effect *base,
1950 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
1951 {
1952 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1953
1954 if (param && !param->element_count)
1955 {
1956 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1957
1958 switch (param->class)
1959 {
1960 case D3DXPC_MATRIX_ROWS:
1961 set_matrix(param, matrix, FALSE);
1962 return D3D_OK;
1963
1964 case D3DXPC_SCALAR:
1965 case D3DXPC_VECTOR:
1966 case D3DXPC_OBJECT:
1967 case D3DXPC_STRUCT:
1968 break;
1969
1970 default:
1971 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
1972 break;
1973 }
1974 }
1975
1976 WARN("Invalid argument specified\n");
1977
1978 return D3DERR_INVALIDCALL;
1979 }
1980
1981 static HRESULT d3dx9_base_effect_get_matrix(struct d3dx9_base_effect *base,
1982 D3DXHANDLE parameter, D3DXMATRIX *matrix)
1983 {
1984 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
1985
1986 if (matrix && param && !param->element_count)
1987 {
1988 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
1989
1990 switch (param->class)
1991 {
1992 case D3DXPC_MATRIX_ROWS:
1993 get_matrix(param, matrix, FALSE);
1994 return D3D_OK;
1995
1996 case D3DXPC_SCALAR:
1997 case D3DXPC_VECTOR:
1998 case D3DXPC_OBJECT:
1999 case D3DXPC_STRUCT:
2000 break;
2001
2002 default:
2003 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2004 break;
2005 }
2006 }
2007
2008 WARN("Invalid argument specified\n");
2009
2010 return D3DERR_INVALIDCALL;
2011 }
2012
2013 static HRESULT d3dx9_base_effect_set_matrix_array(struct d3dx9_base_effect *base,
2014 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2015 {
2016 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2017
2018 if (param && param->element_count >= count)
2019 {
2020 UINT i;
2021
2022 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2023
2024 switch (param->class)
2025 {
2026 case D3DXPC_MATRIX_ROWS:
2027 for (i = 0; i < count; ++i)
2028 {
2029 set_matrix(&param->members[i], &matrix[i], FALSE);
2030 }
2031 return D3D_OK;
2032
2033 case D3DXPC_SCALAR:
2034 case D3DXPC_VECTOR:
2035 case D3DXPC_OBJECT:
2036 case D3DXPC_STRUCT:
2037 break;
2038
2039 default:
2040 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2041 break;
2042 }
2043 }
2044
2045 WARN("Invalid argument specified\n");
2046
2047 return D3DERR_INVALIDCALL;
2048 }
2049
2050 static HRESULT d3dx9_base_effect_get_matrix_array(struct d3dx9_base_effect *base,
2051 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2052 {
2053 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2054
2055 if (!count) return D3D_OK;
2056
2057 if (matrix && param && count <= param->element_count)
2058 {
2059 UINT i;
2060
2061 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2062
2063 switch (param->class)
2064 {
2065 case D3DXPC_MATRIX_ROWS:
2066 for (i = 0; i < count; ++i)
2067 {
2068 get_matrix(&param->members[i], &matrix[i], FALSE);
2069 }
2070 return D3D_OK;
2071
2072 case D3DXPC_SCALAR:
2073 case D3DXPC_VECTOR:
2074 case D3DXPC_OBJECT:
2075 case D3DXPC_STRUCT:
2076 break;
2077
2078 default:
2079 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2080 break;
2081 }
2082 }
2083
2084 WARN("Invalid argument specified\n");
2085
2086 return D3DERR_INVALIDCALL;
2087 }
2088
2089 static HRESULT d3dx9_base_effect_set_matrix_pointer_array(struct d3dx9_base_effect *base,
2090 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2091 {
2092 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2093
2094 if (param && count <= param->element_count)
2095 {
2096 UINT i;
2097
2098 switch (param->class)
2099 {
2100 case D3DXPC_MATRIX_ROWS:
2101 for (i = 0; i < count; ++i)
2102 {
2103 set_matrix(&param->members[i], matrix[i], FALSE);
2104 }
2105 return D3D_OK;
2106
2107 case D3DXPC_SCALAR:
2108 case D3DXPC_VECTOR:
2109 case D3DXPC_OBJECT:
2110 break;
2111
2112 default:
2113 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2114 break;
2115 }
2116 }
2117
2118 WARN("Invalid argument specified\n");
2119
2120 return D3DERR_INVALIDCALL;
2121 }
2122
2123 static HRESULT d3dx9_base_effect_get_matrix_pointer_array(struct d3dx9_base_effect *base,
2124 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2125 {
2126 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2127
2128 if (!count) return D3D_OK;
2129
2130 if (param && matrix && count <= param->element_count)
2131 {
2132 UINT i;
2133
2134 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2135
2136 switch (param->class)
2137 {
2138 case D3DXPC_MATRIX_ROWS:
2139 for (i = 0; i < count; ++i)
2140 {
2141 get_matrix(&param->members[i], matrix[i], FALSE);
2142 }
2143 return D3D_OK;
2144
2145 case D3DXPC_SCALAR:
2146 case D3DXPC_VECTOR:
2147 case D3DXPC_OBJECT:
2148 break;
2149
2150 default:
2151 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2152 break;
2153 }
2154 }
2155
2156 WARN("Invalid argument specified\n");
2157
2158 return D3DERR_INVALIDCALL;
2159 }
2160
2161 static HRESULT d3dx9_base_effect_set_matrix_transpose(struct d3dx9_base_effect *base,
2162 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2163 {
2164 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2165
2166 if (param && !param->element_count)
2167 {
2168 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2169
2170 switch (param->class)
2171 {
2172 case D3DXPC_MATRIX_ROWS:
2173 set_matrix(param, matrix, TRUE);
2174 return D3D_OK;
2175
2176 case D3DXPC_SCALAR:
2177 case D3DXPC_VECTOR:
2178 case D3DXPC_OBJECT:
2179 case D3DXPC_STRUCT:
2180 break;
2181
2182 default:
2183 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2184 break;
2185 }
2186 }
2187
2188 WARN("Invalid argument specified\n");
2189
2190 return D3DERR_INVALIDCALL;
2191 }
2192
2193 static HRESULT d3dx9_base_effect_get_matrix_transpose(struct d3dx9_base_effect *base,
2194 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2195 {
2196 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2197
2198 if (matrix && param && !param->element_count)
2199 {
2200 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2201
2202 switch (param->class)
2203 {
2204 case D3DXPC_SCALAR:
2205 case D3DXPC_VECTOR:
2206 get_matrix(param, matrix, FALSE);
2207 return D3D_OK;
2208
2209 case D3DXPC_MATRIX_ROWS:
2210 get_matrix(param, matrix, TRUE);
2211 return D3D_OK;
2212
2213 case D3DXPC_OBJECT:
2214 case D3DXPC_STRUCT:
2215 break;
2216
2217 default:
2218 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2219 break;
2220 }
2221 }
2222
2223 WARN("Invalid argument specified\n");
2224
2225 return D3DERR_INVALIDCALL;
2226 }
2227
2228 static HRESULT d3dx9_base_effect_set_matrix_transpose_array(struct d3dx9_base_effect *base,
2229 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2230 {
2231 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2232
2233 if (param && param->element_count >= count)
2234 {
2235 UINT i;
2236
2237 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2238
2239 switch (param->class)
2240 {
2241 case D3DXPC_MATRIX_ROWS:
2242 for (i = 0; i < count; ++i)
2243 {
2244 set_matrix(&param->members[i], &matrix[i], TRUE);
2245 }
2246 return D3D_OK;
2247
2248 case D3DXPC_SCALAR:
2249 case D3DXPC_VECTOR:
2250 case D3DXPC_OBJECT:
2251 case D3DXPC_STRUCT:
2252 break;
2253
2254 default:
2255 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2256 break;
2257 }
2258 }
2259
2260 WARN("Invalid argument specified\n");
2261
2262 return D3DERR_INVALIDCALL;
2263 }
2264
2265 static HRESULT d3dx9_base_effect_get_matrix_transpose_array(struct d3dx9_base_effect *base,
2266 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2267 {
2268 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2269
2270 if (!count) return D3D_OK;
2271
2272 if (matrix && param && count <= param->element_count)
2273 {
2274 UINT i;
2275
2276 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2277
2278 switch (param->class)
2279 {
2280 case D3DXPC_MATRIX_ROWS:
2281 for (i = 0; i < count; ++i)
2282 {
2283 get_matrix(&param->members[i], &matrix[i], TRUE);
2284 }
2285 return D3D_OK;
2286
2287 case D3DXPC_SCALAR:
2288 case D3DXPC_VECTOR:
2289 case D3DXPC_OBJECT:
2290 case D3DXPC_STRUCT:
2291 break;
2292
2293 default:
2294 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2295 break;
2296 }
2297 }
2298
2299 WARN("Invalid argument specified\n");
2300
2301 return D3DERR_INVALIDCALL;
2302 }
2303
2304 static HRESULT d3dx9_base_effect_set_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2305 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2306 {
2307 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2308
2309 if (param && count <= param->element_count)
2310 {
2311 UINT i;
2312
2313 switch (param->class)
2314 {
2315 case D3DXPC_MATRIX_ROWS:
2316 for (i = 0; i < count; ++i)
2317 {
2318 set_matrix(&param->members[i], matrix[i], TRUE);
2319 }
2320 return D3D_OK;
2321
2322 case D3DXPC_SCALAR:
2323 case D3DXPC_VECTOR:
2324 case D3DXPC_OBJECT:
2325 break;
2326
2327 default:
2328 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2329 break;
2330 }
2331 }
2332
2333 WARN("Invalid argument specified\n");
2334
2335 return D3DERR_INVALIDCALL;
2336 }
2337
2338 static HRESULT d3dx9_base_effect_get_matrix_transpose_pointer_array(struct d3dx9_base_effect *base,
2339 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2340 {
2341 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2342
2343 if (!count) return D3D_OK;
2344
2345 if (matrix && param && count <= param->element_count)
2346 {
2347 UINT i;
2348
2349 TRACE("Class %s\n", debug_d3dxparameter_class(param->class));
2350
2351 switch (param->class)
2352 {
2353 case D3DXPC_MATRIX_ROWS:
2354 for (i = 0; i < count; ++i)
2355 {
2356 get_matrix(&param->members[i], matrix[i], TRUE);
2357 }
2358 return D3D_OK;
2359
2360 case D3DXPC_SCALAR:
2361 case D3DXPC_VECTOR:
2362 case D3DXPC_OBJECT:
2363 break;
2364
2365 default:
2366 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param->class));
2367 break;
2368 }
2369 }
2370
2371 WARN("Invalid argument specified\n");
2372
2373 return D3DERR_INVALIDCALL;
2374 }
2375
2376 static HRESULT d3dx9_base_effect_set_string(struct d3dx9_base_effect *base,
2377 D3DXHANDLE parameter, const char *string)
2378 {
2379 FIXME("stub!\n");
2380
2381 return E_NOTIMPL;
2382 }
2383
2384 static HRESULT d3dx9_base_effect_get_string(struct d3dx9_base_effect *base,
2385 D3DXHANDLE parameter, const char **string)
2386 {
2387 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2388
2389 if (string && param && !param->element_count && param->type == D3DXPT_STRING)
2390 {
2391 *string = *(LPCSTR *)param->data;
2392 TRACE("Returning %s\n", debugstr_a(*string));
2393 return D3D_OK;
2394 }
2395
2396 WARN("Invalid argument specified\n");
2397
2398 return D3DERR_INVALIDCALL;
2399 }
2400
2401 static HRESULT d3dx9_base_effect_set_texture(struct d3dx9_base_effect *base,
2402 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
2403 {
2404 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2405
2406 if (param && !param->element_count &&
2407 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2408 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2409 || param->type == D3DXPT_TEXTURECUBE))
2410 {
2411 struct IDirect3DBaseTexture9 *oltexture = *(struct IDirect3DBaseTexture9 **)param->data;
2412
2413 if (texture) IDirect3DBaseTexture9_AddRef(texture);
2414 if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
2415
2416 *(struct IDirect3DBaseTexture9 **)param->data = texture;
2417
2418 return D3D_OK;
2419 }
2420
2421 WARN("Invalid argument specified\n");
2422
2423 return D3DERR_INVALIDCALL;
2424 }
2425
2426 static HRESULT d3dx9_base_effect_get_texture(struct d3dx9_base_effect *base,
2427 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
2428 {
2429 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2430
2431 if (texture && param && !param->element_count &&
2432 (param->type == D3DXPT_TEXTURE || param->type == D3DXPT_TEXTURE1D
2433 || param->type == D3DXPT_TEXTURE2D || param->type == D3DXPT_TEXTURE3D
2434 || param->type == D3DXPT_TEXTURECUBE))
2435 {
2436 *texture = *(struct IDirect3DBaseTexture9 **)param->data;
2437 if (*texture) IDirect3DBaseTexture9_AddRef(*texture);
2438 TRACE("Returning %p\n", *texture);
2439 return D3D_OK;
2440 }
2441
2442 WARN("Invalid argument specified\n");
2443
2444 return D3DERR_INVALIDCALL;
2445 }
2446
2447 static HRESULT d3dx9_base_effect_get_pixel_shader(struct d3dx9_base_effect *base,
2448 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
2449 {
2450 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2451
2452 if (shader && param && !param->element_count && param->type == D3DXPT_PIXELSHADER)
2453 {
2454 if ((*shader = *(struct IDirect3DPixelShader9 **)param->data))
2455 IDirect3DPixelShader9_AddRef(*shader);
2456 TRACE("Returning %p.\n", *shader);
2457 return D3D_OK;
2458 }
2459
2460 WARN("Invalid argument specified\n");
2461
2462 return D3DERR_INVALIDCALL;
2463 }
2464
2465 static HRESULT d3dx9_base_effect_get_vertex_shader(struct d3dx9_base_effect *base,
2466 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
2467 {
2468 struct d3dx_parameter *param = get_valid_parameter(base, parameter);
2469
2470 if (shader && param && !param->element_count && param->type == D3DXPT_VERTEXSHADER)
2471 {
2472 if ((*shader = *(struct IDirect3DVertexShader9 **)param->data))
2473 IDirect3DVertexShader9_AddRef(*shader);
2474 TRACE("Returning %p.\n", *shader);
2475 return D3D_OK;
2476 }
2477
2478 WARN("Invalid argument specified\n");
2479
2480 return D3DERR_INVALIDCALL;
2481 }
2482
2483 static HRESULT d3dx9_base_effect_set_array_range(struct d3dx9_base_effect *base,
2484 D3DXHANDLE parameter, UINT start, UINT end)
2485 {
2486 FIXME("stub!\n");
2487
2488 return E_NOTIMPL;
2489 }
2490
2491 static inline struct ID3DXEffectImpl *impl_from_ID3DXEffect(ID3DXEffect *iface)
2492 {
2493 return CONTAINING_RECORD(iface, struct ID3DXEffectImpl, ID3DXEffect_iface);
2494 }
2495
2496 /*** IUnknown methods ***/
2497 static HRESULT WINAPI ID3DXEffectImpl_QueryInterface(ID3DXEffect *iface, REFIID riid, void **object)
2498 {
2499 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
2500
2501 if (IsEqualGUID(riid, &IID_IUnknown) ||
2502 IsEqualGUID(riid, &IID_ID3DXEffect))
2503 {
2504 iface->lpVtbl->AddRef(iface);
2505 *object = iface;
2506 return S_OK;
2507 }
2508
2509 ERR("Interface %s not found\n", debugstr_guid(riid));
2510
2511 return E_NOINTERFACE;
2512 }
2513
2514 static ULONG WINAPI ID3DXEffectImpl_AddRef(ID3DXEffect *iface)
2515 {
2516 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2517
2518 TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
2519
2520 return InterlockedIncrement(&This->ref);
2521 }
2522
2523 static ULONG WINAPI ID3DXEffectImpl_Release(ID3DXEffect *iface)
2524 {
2525 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
2526 ULONG ref = InterlockedDecrement(&This->ref);
2527
2528 TRACE("(%p)->(): Release from %u\n", This, ref + 1);
2529
2530 if (!ref)
2531 {
2532 free_effect(This);
2533 HeapFree(GetProcessHeap(), 0, This);
2534 }
2535
2536 return ref;
2537 }
2538
2539 /*** ID3DXBaseEffect methods ***/
2540 static HRESULT WINAPI ID3DXEffectImpl_GetDesc(ID3DXEffect *iface, D3DXEFFECT_DESC *desc)
2541 {
2542 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2543
2544 TRACE("iface %p, desc %p.\n", iface, desc);
2545
2546 return d3dx9_base_effect_get_desc(&effect->base_effect, desc);
2547 }
2548
2549 static HRESULT WINAPI ID3DXEffectImpl_GetParameterDesc(ID3DXEffect *iface,
2550 D3DXHANDLE parameter, D3DXPARAMETER_DESC *desc)
2551 {
2552 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2553
2554 TRACE("iface %p, parameter %p, desc %p.\n", iface, parameter, desc);
2555
2556 return d3dx9_base_effect_get_parameter_desc(&effect->base_effect, parameter, desc);
2557 }
2558
2559 static HRESULT WINAPI ID3DXEffectImpl_GetTechniqueDesc(ID3DXEffect *iface,
2560 D3DXHANDLE technique, D3DXTECHNIQUE_DESC *desc)
2561 {
2562 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2563
2564 TRACE("iface %p, technique %p, desc %p.\n", iface, technique, desc);
2565
2566 return d3dx9_base_effect_get_technique_desc(&effect->base_effect, technique, desc);
2567 }
2568
2569 static HRESULT WINAPI ID3DXEffectImpl_GetPassDesc(ID3DXEffect *iface, D3DXHANDLE pass, D3DXPASS_DESC *desc)
2570 {
2571 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2572
2573 TRACE("iface %p, pass %p, desc %p.\n", iface, pass, desc);
2574
2575 return d3dx9_base_effect_get_pass_desc(&effect->base_effect, pass, desc);
2576 }
2577
2578 static HRESULT WINAPI ID3DXEffectImpl_GetFunctionDesc(ID3DXEffect *iface, D3DXHANDLE shader, D3DXFUNCTION_DESC *desc)
2579 {
2580 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2581
2582 TRACE("iface %p, shader %p, desc %p.\n", iface, shader, desc);
2583
2584 return d3dx9_base_effect_get_function_desc(&effect->base_effect, shader, desc);
2585 }
2586
2587 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameter(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2588 {
2589 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2590
2591 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
2592
2593 return d3dx9_base_effect_get_parameter(&effect->base_effect, parameter, index);
2594 }
2595
2596 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterByName(ID3DXEffect *iface,
2597 D3DXHANDLE parameter, const char *name)
2598 {
2599 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2600
2601 TRACE("iface %p, parameter %p, name %s.\n", iface, parameter, debugstr_a(name));
2602
2603 return d3dx9_base_effect_get_parameter_by_name(&effect->base_effect, parameter, name);
2604 }
2605
2606 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterBySemantic(ID3DXEffect *iface,
2607 D3DXHANDLE parameter, const char *semantic)
2608 {
2609 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2610
2611 TRACE("iface %p, parameter %p, semantic %s.\n", iface, parameter, debugstr_a(semantic));
2612
2613 return d3dx9_base_effect_get_parameter_by_semantic(&effect->base_effect, parameter, semantic);
2614 }
2615
2616 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetParameterElement(ID3DXEffect *iface, D3DXHANDLE parameter, UINT index)
2617 {
2618 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2619
2620 TRACE("iface %p, parameter %p, index %u.\n", iface, parameter, index);
2621
2622 return d3dx9_base_effect_get_parameter_element(&effect->base_effect, parameter, index);
2623 }
2624
2625 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechnique(ID3DXEffect *iface, UINT index)
2626 {
2627 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2628
2629 TRACE("iface %p, index %u.\n", iface, index);
2630
2631 return d3dx9_base_effect_get_technique(&effect->base_effect, index);
2632 }
2633
2634 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetTechniqueByName(ID3DXEffect *iface, const char *name)
2635 {
2636 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2637
2638 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
2639
2640 return d3dx9_base_effect_get_technique_by_name(&effect->base_effect, name);
2641 }
2642
2643 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPass(ID3DXEffect *iface, D3DXHANDLE technique, UINT index)
2644 {
2645 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2646
2647 TRACE("iface %p, technique %p, index %u.\n", iface, technique, index);
2648
2649 return d3dx9_base_effect_get_pass(&effect->base_effect, technique, index);
2650 }
2651
2652 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetPassByName(ID3DXEffect *iface,
2653 D3DXHANDLE technique, const char *name)
2654 {
2655 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2656
2657 TRACE("iface %p, technique %p, name %s.\n", iface, technique, debugstr_a(name));
2658
2659 return d3dx9_base_effect_get_pass_by_name(&effect->base_effect, technique, name);
2660 }
2661
2662 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunction(ID3DXEffect *iface, UINT index)
2663 {
2664 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2665
2666 TRACE("iface %p, index %u.\n", iface, index);
2667
2668 return d3dx9_base_effect_get_function(&effect->base_effect, index);
2669 }
2670
2671 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetFunctionByName(ID3DXEffect *iface, const char *name)
2672 {
2673 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2674
2675 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
2676
2677 return d3dx9_base_effect_get_function_by_name(&effect->base_effect, name);
2678 }
2679
2680 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotation(ID3DXEffect *iface, D3DXHANDLE object, UINT index)
2681 {
2682 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2683
2684 TRACE("iface %p, object %p, index %u.\n", iface, object, index);
2685
2686 return d3dx9_base_effect_get_annotation(&effect->base_effect, object, index);
2687 }
2688
2689 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetAnnotationByName(ID3DXEffect *iface,
2690 D3DXHANDLE object, const char *name)
2691 {
2692 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2693
2694 TRACE("iface %p, object %p, name %s.\n", iface, object, debugstr_a(name));
2695
2696 return d3dx9_base_effect_get_annotation_by_name(&effect->base_effect, object, name);
2697 }
2698
2699 static HRESULT WINAPI ID3DXEffectImpl_SetValue(ID3DXEffect *iface,
2700 D3DXHANDLE parameter, const void *data, UINT bytes)
2701 {
2702 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2703
2704 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
2705
2706 return d3dx9_base_effect_set_value(&effect->base_effect, parameter, data, bytes);
2707 }
2708
2709 static HRESULT WINAPI ID3DXEffectImpl_GetValue(ID3DXEffect *iface,
2710 D3DXHANDLE parameter, void *data, UINT bytes)
2711 {
2712 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2713
2714 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter, data, bytes);
2715
2716 return d3dx9_base_effect_get_value(&effect->base_effect, parameter, data, bytes);
2717 }
2718
2719 static HRESULT WINAPI ID3DXEffectImpl_SetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL b)
2720 {
2721 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2722
2723 TRACE("iface %p, parameter %p, b %#x.\n", iface, parameter, b);
2724
2725 return d3dx9_base_effect_set_bool(&effect->base_effect, parameter, b);
2726 }
2727
2728 static HRESULT WINAPI ID3DXEffectImpl_GetBool(ID3DXEffect *iface, D3DXHANDLE parameter, BOOL *b)
2729 {
2730 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2731
2732 TRACE("iface %p, parameter %p, b %p.\n", iface, parameter, b);
2733
2734 return d3dx9_base_effect_get_bool(&effect->base_effect, parameter, b);
2735 }
2736
2737 static HRESULT WINAPI ID3DXEffectImpl_SetBoolArray(ID3DXEffect *iface,
2738 D3DXHANDLE parameter, const BOOL *b, UINT count)
2739 {
2740 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2741
2742 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
2743
2744 return d3dx9_base_effect_set_bool_array(&effect->base_effect, parameter, b, count);
2745 }
2746
2747 static HRESULT WINAPI ID3DXEffectImpl_GetBoolArray(ID3DXEffect *iface,
2748 D3DXHANDLE parameter, BOOL *b, UINT count)
2749 {
2750 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2751
2752 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface, parameter, b, count);
2753
2754 return d3dx9_base_effect_get_bool_array(&effect->base_effect, parameter, b, count);
2755 }
2756
2757 static HRESULT WINAPI ID3DXEffectImpl_SetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT n)
2758 {
2759 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2760
2761 TRACE("iface %p, parameter %p, n %d.\n", iface, parameter, n);
2762
2763 return d3dx9_base_effect_set_int(&effect->base_effect, parameter, n);
2764 }
2765
2766 static HRESULT WINAPI ID3DXEffectImpl_GetInt(ID3DXEffect *iface, D3DXHANDLE parameter, INT *n)
2767 {
2768 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2769
2770 TRACE("iface %p, parameter %p, n %p.\n", iface, parameter, n);
2771
2772 return d3dx9_base_effect_get_int(&effect->base_effect, parameter, n);
2773 }
2774
2775 static HRESULT WINAPI ID3DXEffectImpl_SetIntArray(ID3DXEffect *iface,
2776 D3DXHANDLE parameter, const INT *n, UINT count)
2777 {
2778 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2779
2780 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
2781
2782 return d3dx9_base_effect_set_int_array(&effect->base_effect, parameter, n, count);
2783 }
2784
2785 static HRESULT WINAPI ID3DXEffectImpl_GetIntArray(ID3DXEffect *iface,
2786 D3DXHANDLE parameter, INT *n, UINT count)
2787 {
2788 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2789
2790 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface, parameter, n, count);
2791
2792 return d3dx9_base_effect_get_int_array(&effect->base_effect, parameter, n, count);
2793 }
2794
2795 static HRESULT WINAPI ID3DXEffectImpl_SetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float f)
2796 {
2797 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2798
2799 TRACE("iface %p, parameter %p, f %.8e.\n", iface, parameter, f);
2800
2801 return d3dx9_base_effect_set_float(&effect->base_effect, parameter, f);
2802 }
2803
2804 static HRESULT WINAPI ID3DXEffectImpl_GetFloat(ID3DXEffect *iface, D3DXHANDLE parameter, float *f)
2805 {
2806 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2807
2808 TRACE("iface %p, parameter %p, f %p.\n", iface, parameter, f);
2809
2810 return d3dx9_base_effect_get_float(&effect->base_effect, parameter, f);
2811 }
2812
2813 static HRESULT WINAPI ID3DXEffectImpl_SetFloatArray(ID3DXEffect *iface,
2814 D3DXHANDLE parameter, const float *f, UINT count)
2815 {
2816 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2817
2818 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
2819
2820 return d3dx9_base_effect_set_float_array(&effect->base_effect, parameter, f, count);
2821 }
2822
2823 static HRESULT WINAPI ID3DXEffectImpl_GetFloatArray(ID3DXEffect *iface,
2824 D3DXHANDLE parameter, float *f, UINT count)
2825 {
2826 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2827
2828 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface, parameter, f, count);
2829
2830 return d3dx9_base_effect_get_float_array(&effect->base_effect, parameter, f, count);
2831 }
2832
2833 static HRESULT WINAPI ID3DXEffectImpl_SetVector(ID3DXEffect *iface,
2834 D3DXHANDLE parameter, const D3DXVECTOR4 *vector)
2835 {
2836 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2837
2838 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
2839
2840 return d3dx9_base_effect_set_vector(&effect->base_effect, parameter, vector);
2841 }
2842
2843 static HRESULT WINAPI ID3DXEffectImpl_GetVector(ID3DXEffect *iface,
2844 D3DXHANDLE parameter, D3DXVECTOR4 *vector)
2845 {
2846 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2847
2848 TRACE("iface %p, parameter %p, vector %p.\n", iface, parameter, vector);
2849
2850 return d3dx9_base_effect_get_vector(&effect->base_effect, parameter, vector);
2851 }
2852
2853 static HRESULT WINAPI ID3DXEffectImpl_SetVectorArray(ID3DXEffect *iface,
2854 D3DXHANDLE parameter, const D3DXVECTOR4 *vector, UINT count)
2855 {
2856 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2857
2858 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
2859
2860 return d3dx9_base_effect_set_vector_array(&effect->base_effect, parameter, vector, count);
2861 }
2862
2863 static HRESULT WINAPI ID3DXEffectImpl_GetVectorArray(ID3DXEffect *iface,
2864 D3DXHANDLE parameter, D3DXVECTOR4 *vector, UINT count)
2865 {
2866 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2867
2868 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface, parameter, vector, count);
2869
2870 return d3dx9_base_effect_get_vector_array(&effect->base_effect, parameter, vector, count);
2871 }
2872
2873 static HRESULT WINAPI ID3DXEffectImpl_SetMatrix(ID3DXEffect *iface,
2874 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2875 {
2876 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2877
2878 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2879
2880 return d3dx9_base_effect_set_matrix(&effect->base_effect, parameter, matrix);
2881 }
2882
2883 static HRESULT WINAPI ID3DXEffectImpl_GetMatrix(ID3DXEffect *iface,
2884 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2885 {
2886 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2887
2888 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2889
2890 return d3dx9_base_effect_get_matrix(&effect->base_effect, parameter, matrix);
2891 }
2892
2893 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixArray(ID3DXEffect *iface,
2894 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2895 {
2896 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2897
2898 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2899
2900 return d3dx9_base_effect_set_matrix_array(&effect->base_effect, parameter, matrix, count);
2901 }
2902
2903 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixArray(ID3DXEffect *iface,
2904 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2905 {
2906 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2907
2908 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2909
2910 return d3dx9_base_effect_get_matrix_array(&effect->base_effect, parameter, matrix, count);
2911 }
2912
2913 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixPointerArray(ID3DXEffect *iface,
2914 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2915 {
2916 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2917
2918 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2919
2920 return d3dx9_base_effect_set_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
2921 }
2922
2923 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixPointerArray(ID3DXEffect *iface,
2924 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2925 {
2926 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2927
2928 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2929
2930 return d3dx9_base_effect_get_matrix_pointer_array(&effect->base_effect, parameter, matrix, count);
2931 }
2932
2933 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTranspose(ID3DXEffect *iface,
2934 D3DXHANDLE parameter, const D3DXMATRIX *matrix)
2935 {
2936 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2937
2938 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2939
2940 return d3dx9_base_effect_set_matrix_transpose(&effect->base_effect, parameter, matrix);
2941 }
2942
2943 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTranspose(ID3DXEffect *iface,
2944 D3DXHANDLE parameter, D3DXMATRIX *matrix)
2945 {
2946 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2947
2948 TRACE("iface %p, parameter %p, matrix %p.\n", iface, parameter, matrix);
2949
2950 return d3dx9_base_effect_get_matrix_transpose(&effect->base_effect, parameter, matrix);
2951 }
2952
2953 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposeArray(ID3DXEffect *iface,
2954 D3DXHANDLE parameter, const D3DXMATRIX *matrix, UINT count)
2955 {
2956 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2957
2958 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2959
2960 return d3dx9_base_effect_set_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
2961 }
2962
2963 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposeArray(ID3DXEffect *iface,
2964 D3DXHANDLE parameter, D3DXMATRIX *matrix, UINT count)
2965 {
2966 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2967
2968 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2969
2970 return d3dx9_base_effect_get_matrix_transpose_array(&effect->base_effect, parameter, matrix, count);
2971 }
2972
2973 static HRESULT WINAPI ID3DXEffectImpl_SetMatrixTransposePointerArray(ID3DXEffect *iface,
2974 D3DXHANDLE parameter, const D3DXMATRIX **matrix, UINT count)
2975 {
2976 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2977
2978 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2979
2980 return d3dx9_base_effect_set_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
2981 }
2982
2983 static HRESULT WINAPI ID3DXEffectImpl_GetMatrixTransposePointerArray(ID3DXEffect *iface,
2984 D3DXHANDLE parameter, D3DXMATRIX **matrix, UINT count)
2985 {
2986 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2987
2988 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter, matrix, count);
2989
2990 return d3dx9_base_effect_get_matrix_transpose_pointer_array(&effect->base_effect, parameter, matrix, count);
2991 }
2992
2993 static HRESULT WINAPI ID3DXEffectImpl_SetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char *string)
2994 {
2995 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
2996
2997 TRACE("iface %p, parameter %p, string %s.\n", iface, parameter, debugstr_a(string));
2998
2999 return d3dx9_base_effect_set_string(&effect->base_effect, parameter, string);
3000 }
3001
3002 static HRESULT WINAPI ID3DXEffectImpl_GetString(ID3DXEffect *iface, D3DXHANDLE parameter, const char **string)
3003 {
3004 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3005
3006 TRACE("iface %p, parameter %p, string %p.\n", iface, parameter, string);
3007
3008 return d3dx9_base_effect_get_string(&effect->base_effect, parameter, string);
3009 }
3010
3011 static HRESULT WINAPI ID3DXEffectImpl_SetTexture(struct ID3DXEffect *iface,
3012 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 *texture)
3013 {
3014 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3015
3016 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3017
3018 return d3dx9_base_effect_set_texture(&effect->base_effect, parameter, texture);
3019 }
3020
3021 static HRESULT WINAPI ID3DXEffectImpl_GetTexture(struct ID3DXEffect *iface,
3022 D3DXHANDLE parameter, struct IDirect3DBaseTexture9 **texture)
3023 {
3024 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3025
3026 TRACE("iface %p, parameter %p, texture %p.\n", iface, parameter, texture);
3027
3028 return d3dx9_base_effect_get_texture(&effect->base_effect, parameter, texture);
3029 }
3030
3031 static HRESULT WINAPI ID3DXEffectImpl_GetPixelShader(ID3DXEffect *iface,
3032 D3DXHANDLE parameter, struct IDirect3DPixelShader9 **shader)
3033 {
3034 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3035
3036 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3037
3038 return d3dx9_base_effect_get_pixel_shader(&effect->base_effect, parameter, shader);
3039 }
3040
3041 static HRESULT WINAPI ID3DXEffectImpl_GetVertexShader(struct ID3DXEffect *iface,
3042 D3DXHANDLE parameter, struct IDirect3DVertexShader9 **shader)
3043 {
3044 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3045
3046 TRACE("iface %p, parameter %p, shader %p.\n", iface, parameter, shader);
3047
3048 return d3dx9_base_effect_get_vertex_shader(&effect->base_effect, parameter, shader);
3049 }
3050
3051 static HRESULT WINAPI ID3DXEffectImpl_SetArrayRange(ID3DXEffect *iface, D3DXHANDLE parameter, UINT start, UINT end)
3052 {
3053 struct ID3DXEffectImpl *effect = impl_from_ID3DXEffect(iface);
3054
3055 TRACE("iface %p, parameter %p, start %u, end %u.\n", iface, parameter, start, end);
3056
3057 return d3dx9_base_effect_set_array_range(&effect->base_effect, parameter, start, end);
3058 }
3059
3060 /*** ID3DXEffect methods ***/
3061 static HRESULT WINAPI ID3DXEffectImpl_GetPool(ID3DXEffect *iface, ID3DXEffectPool **pool)
3062 {
3063 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3064
3065 TRACE("iface %p, pool %p\n", This, pool);
3066
3067 if (!pool)
3068 {
3069 WARN("Invalid argument supplied.\n");
3070 return D3DERR_INVALIDCALL;
3071 }
3072
3073 if (This->pool)
3074 {
3075 This->pool->lpVtbl->AddRef(This->pool);
3076 }
3077
3078 *pool = This->pool;
3079
3080 TRACE("Returning pool %p\n", *pool);
3081
3082 return S_OK;
3083 }
3084
3085 static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDLE technique)
3086 {
3087 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3088 struct d3dx9_base_effect *base = &This->base_effect;
3089 struct d3dx_technique *tech = get_valid_technique(base, technique);
3090
3091 TRACE("iface %p, technique %p\n", This, technique);
3092
3093 if (tech)
3094 {
3095 This->active_technique = tech;
3096 TRACE("Technique %p\n", tech);
3097 return D3D_OK;
3098 }
3099
3100 WARN("Invalid argument supplied.\n");
3101
3102 return D3DERR_INVALIDCALL;
3103 }
3104
3105 static D3DXHANDLE WINAPI ID3DXEffectImpl_GetCurrentTechnique(ID3DXEffect *iface)
3106 {
3107 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3108
3109 TRACE("iface %p\n", This);
3110
3111 return get_technique_handle(This->active_technique);
3112 }
3113
3114 static HRESULT WINAPI ID3DXEffectImpl_ValidateTechnique(ID3DXEffect* iface, D3DXHANDLE technique)
3115 {
3116 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3117
3118 FIXME("(%p)->(%p): stub\n", This, technique);
3119
3120 return D3D_OK;
3121 }
3122
3123 static HRESULT WINAPI ID3DXEffectImpl_FindNextValidTechnique(ID3DXEffect* iface, D3DXHANDLE technique, D3DXHANDLE* next_technique)
3124 {
3125 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3126
3127 FIXME("(%p)->(%p, %p): stub\n", This, technique, next_technique);
3128
3129 return E_NOTIMPL;
3130 }
3131
3132 static BOOL WINAPI ID3DXEffectImpl_IsParameterUsed(ID3DXEffect* iface, D3DXHANDLE parameter, D3DXHANDLE technique)
3133 {
3134 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3135
3136 FIXME("(%p)->(%p, %p): stub\n", This, parameter, technique);
3137
3138 return FALSE;
3139 }
3140
3141 static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DWORD flags)
3142 {
3143 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3144 struct d3dx_technique *technique = This->active_technique;
3145
3146 FIXME("iface %p, passes %p, flags %#x partial stub\n", iface, passes, flags);
3147
3148 if (passes && technique)
3149 {
3150 if (flags & ~(D3DXFX_DONOTSAVESTATE | D3DXFX_DONOTSAVESAMPLERSTATE | D3DXFX_DONOTSAVESHADERSTATE))
3151 WARN("Invalid flags (%#x) specified.\n", flags);
3152
3153 if (This->manager || flags & D3DXFX_DONOTSAVESTATE)
3154 {
3155 TRACE("State capturing disabled.\n");
3156 }
3157 else
3158 {
3159 FIXME("State capturing not supported, yet!\n");
3160 }
3161
3162 *passes = technique->pass_count;
3163 This->started = TRUE;
3164 This->flags = flags;
3165
3166 return D3D_OK;
3167 }
3168
3169 WARN("Invalid argument supplied.\n");
3170
3171 return D3DERR_INVALIDCALL;
3172 }
3173
3174 static HRESULT WINAPI ID3DXEffectImpl_BeginPass(ID3DXEffect *iface, UINT pass)
3175 {
3176 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3177 struct d3dx_technique *technique = This->active_technique;
3178
3179 TRACE("iface %p, pass %u\n", This, pass);
3180
3181 if (technique && pass < technique->pass_count && !This->active_pass)
3182 {
3183 This->active_pass = &technique->passes[pass];
3184
3185 FIXME("No states applied, yet!\n");
3186
3187 return D3D_OK;
3188 }
3189
3190 WARN("Invalid argument supplied.\n");
3191
3192 return D3DERR_INVALIDCALL;
3193 }
3194
3195 static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect* iface)
3196 {
3197 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3198
3199 FIXME("(%p)->(): stub\n", This);
3200
3201 return E_NOTIMPL;
3202 }
3203
3204 static HRESULT WINAPI ID3DXEffectImpl_EndPass(ID3DXEffect *iface)
3205 {
3206 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3207
3208 TRACE("iface %p\n", This);
3209
3210 if (This->active_pass)
3211 {
3212 This->active_pass = NULL;
3213 return D3D_OK;
3214 }
3215
3216 WARN("Invalid call.\n");
3217
3218 return D3DERR_INVALIDCALL;
3219 }
3220
3221 static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect *iface)
3222 {
3223 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3224
3225 FIXME("iface %p partial stub\n", iface);
3226
3227 if (!This->started)
3228 return D3D_OK;
3229
3230 if (This->manager || This->flags & D3DXFX_DONOTSAVESTATE)
3231 {
3232 TRACE("State restoring disabled.\n");
3233 }
3234 else
3235 {
3236 FIXME("State restoring not supported, yet!\n");
3237 }
3238
3239 This->started = FALSE;
3240
3241 return D3D_OK;
3242 }
3243
3244 static HRESULT WINAPI ID3DXEffectImpl_GetDevice(ID3DXEffect *iface, struct IDirect3DDevice9 **device)
3245 {
3246 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3247
3248 TRACE("iface %p, device %p\n", This, device);
3249
3250 if (!device)
3251 {
3252 WARN("Invalid argument supplied.\n");
3253 return D3DERR_INVALIDCALL;
3254 }
3255
3256 IDirect3DDevice9_AddRef(This->device);
3257
3258 *device = This->device;
3259
3260 TRACE("Returning device %p\n", *device);
3261
3262 return S_OK;
3263 }
3264
3265 static HRESULT WINAPI ID3DXEffectImpl_OnLostDevice(ID3DXEffect* iface)
3266 {
3267 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3268
3269 FIXME("(%p)->(): stub\n", This);
3270
3271 return E_NOTIMPL;
3272 }
3273
3274 static HRESULT WINAPI ID3DXEffectImpl_OnResetDevice(ID3DXEffect* iface)
3275 {
3276 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3277
3278 FIXME("(%p)->(): stub\n", This);
3279
3280 return E_NOTIMPL;
3281 }
3282
3283 static HRESULT WINAPI ID3DXEffectImpl_SetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager *manager)
3284 {
3285 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3286
3287 TRACE("iface %p, manager %p\n", This, manager);
3288
3289 if (manager) IUnknown_AddRef(manager);
3290 if (This->manager) IUnknown_Release(This->manager);
3291
3292 This->manager = manager;
3293
3294 return D3D_OK;
3295 }
3296
3297 static HRESULT WINAPI ID3DXEffectImpl_GetStateManager(ID3DXEffect *iface, ID3DXEffectStateManager **manager)
3298 {
3299 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3300
3301 TRACE("iface %p, manager %p\n", This, manager);
3302
3303 if (!manager)
3304 {
3305 WARN("Invalid argument supplied.\n");
3306 return D3DERR_INVALIDCALL;
3307 }
3308
3309 if (This->manager) IUnknown_AddRef(This->manager);
3310 *manager = This->manager;
3311
3312 return D3D_OK;
3313 }
3314
3315 static HRESULT WINAPI ID3DXEffectImpl_BeginParameterBlock(ID3DXEffect* iface)
3316 {
3317 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3318
3319 FIXME("(%p)->(): stub\n", This);
3320
3321 return E_NOTIMPL;
3322 }
3323
3324 static D3DXHANDLE WINAPI ID3DXEffectImpl_EndParameterBlock(ID3DXEffect* iface)
3325 {
3326 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3327
3328 FIXME("(%p)->(): stub\n", This);
3329
3330 return NULL;
3331 }
3332
3333 static HRESULT WINAPI ID3DXEffectImpl_ApplyParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3334 {
3335 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3336
3337 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3338
3339 return E_NOTIMPL;
3340 }
3341
3342 static HRESULT WINAPI ID3DXEffectImpl_DeleteParameterBlock(ID3DXEffect* iface, D3DXHANDLE parameter_block)
3343 {
3344 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3345
3346 FIXME("(%p)->(%p): stub\n", This, parameter_block);
3347
3348 return E_NOTIMPL;
3349 }
3350
3351 static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect *iface,
3352 struct IDirect3DDevice9 *device, struct ID3DXEffect **effect)
3353 {
3354 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3355
3356 FIXME("(%p)->(%p, %p): stub\n", This, device, effect);
3357
3358 return E_NOTIMPL;
3359 }
3360
3361 static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect* iface, D3DXHANDLE parameter, LPCVOID data, UINT byte_offset, UINT bytes)
3362 {
3363 struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
3364
3365 FIXME("(%p)->(%p, %p, %u, %u): stub\n", This, parameter, data, byte_offset, bytes);
3366
3367 return E_NOTIMPL;
3368 }
3369
3370 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl =
3371 {
3372 /*** IUnknown methods ***/
3373 ID3DXEffectImpl_QueryInterface,
3374 ID3DXEffectImpl_AddRef,
3375 ID3DXEffectImpl_Release,
3376 /*** ID3DXBaseEffect methods ***/
3377 ID3DXEffectImpl_GetDesc,
3378 ID3DXEffectImpl_GetParameterDesc,
3379 ID3DXEffectImpl_GetTechniqueDesc,
3380 ID3DXEffectImpl_GetPassDesc,
3381 ID3DXEffectImpl_GetFunctionDesc,
3382 ID3DXEffectImpl_GetParameter,
3383 ID3DXEffectImpl_GetParameterByName,
3384 ID3DXEffectImpl_GetParameterBySemantic,
3385 ID3DXEffectImpl_GetParameterElement,
3386 ID3DXEffectImpl_GetTechnique,
3387 ID3DXEffectImpl_GetTechniqueByName,
3388 ID3DXEffectImpl_GetPass,
3389 ID3DXEffectImpl_GetPassByName,
3390 ID3DXEffectImpl_GetFunction,
3391 ID3DXEffectImpl_GetFunctionByName,
3392 ID3DXEffectImpl_GetAnnotation,
3393 ID3DXEffectImpl_GetAnnotationByName,
3394 ID3DXEffectImpl_SetValue,
3395 ID3DXEffectImpl_GetValue,
3396 ID3DXEffectImpl_SetBool,
3397 ID3DXEffectImpl_GetBool,
3398 ID3DXEffectImpl_SetBoolArray,
3399 ID3DXEffectImpl_GetBoolArray,
3400 ID3DXEffectImpl_SetInt,
3401 ID3DXEffectImpl_GetInt,
3402 ID3DXEffectImpl_SetIntArray,
3403 ID3DXEffectImpl_GetIntArray,
3404 ID3DXEffectImpl_SetFloat,
3405 ID3DXEffectImpl_GetFloat,
3406 ID3DXEffectImpl_SetFloatArray,
3407 ID3DXEffectImpl_GetFloatArray,
3408 ID3DXEffectImpl_SetVector,
3409 ID3DXEffectImpl_GetVector,
3410 ID3DXEffectImpl_SetVectorArray,
3411 ID3DXEffectImpl_GetVectorArray,
3412 ID3DXEffectImpl_SetMatrix,
3413 ID3DXEffectImpl_GetMatrix,
3414 ID3DXEffectImpl_SetMatrixArray,
3415 ID3DXEffectImpl_GetMatrixArray,
3416 ID3DXEffectImpl_SetMatrixPointerArray,
3417 ID3DXEffectImpl_GetMatrixPointerArray,
3418 ID3DXEffectImpl_SetMatrixTranspose,
3419 ID3DXEffectImpl_GetMatrixTranspose,
3420 ID3DXEffectImpl_SetMatrixTransposeArray,
3421 ID3DXEffectImpl_GetMatrixTransposeArray,
3422 ID3DXEffectImpl_SetMatrixTransposePointerArray,
3423 ID3DXEffectImpl_GetMatrixTransposePointerArray,
3424 ID3DXEffectImpl_SetString,
3425 ID3DXEffectImpl_GetString,
3426 ID3DXEffectImpl_SetTexture,
3427 ID3DXEffectImpl_GetTexture,
3428 ID3DXEffectImpl_GetPixelShader,
3429 ID3DXEffectImpl_GetVertexShader,
3430 ID3DXEffectImpl_SetArrayRange,
3431 /*** ID3DXEffect methods ***/
3432 ID3DXEffectImpl_GetPool,
3433 ID3DXEffectImpl_SetTechnique,
3434 ID3DXEffectImpl_GetCurrentTechnique,
3435 ID3DXEffectImpl_ValidateTechnique,
3436 ID3DXEffectImpl_FindNextValidTechnique,
3437 ID3DXEffectImpl_IsParameterUsed,
3438 ID3DXEffectImpl_Begin,
3439 ID3DXEffectImpl_BeginPass,
3440 ID3DXEffectImpl_CommitChanges,
3441 ID3DXEffectImpl_EndPass,
3442 ID3DXEffectImpl_End,
3443 ID3DXEffectImpl_GetDevice,
3444 ID3DXEffectImpl_OnLostDevice,
3445 ID3DXEffectImpl_OnResetDevice,
3446 ID3DXEffectImpl_SetStateManager,
3447 ID3DXEffectImpl_GetStateManager,
3448 ID3DXEffectImpl_BeginParameterBlock,
3449 ID3DXEffectImpl_EndParameterBlock,
3450 ID3DXEffectImpl_ApplyParameterBlock,
3451 ID3DXEffectImpl_DeleteParameterBlock,