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