2 * Copyright 2010 Christian Costa
3 * Copyright 2011 Rico Schüller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3dx9_private.h"
25 #include "d3dcompiler.h"
27 #include "wine/list.h"
29 /* Constants for special INT/FLOAT conversation */
30 #define INT_FLOAT_MULTI 255.0f
31 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
33 static const char parameter_magic_string
[4] = {'@', '!', '#', '\xFF'};
34 static const char parameter_block_magic_string
[4] = {'@', '!', '#', '\xFE'};
36 #define PARAMETER_FLAG_SHARED 1
38 #define INITIAL_POOL_SIZE 16
39 #define INITIAL_PARAM_BLOCK_SIZE 1024
41 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
88 enum SHADER_CONSTANT_TYPE
110 struct d3dx_parameter
*param
;
111 BOOL creation_failed
;
118 enum STATE_TYPE type
;
119 struct d3dx_parameter parameter
;
120 struct d3dx_parameter
*referenced_param
;
126 struct d3dx_state
*states
;
133 UINT annotation_count
;
135 struct d3dx_state
*states
;
136 struct d3dx_parameter
*annotations
;
138 ULONG64 update_version
;
141 struct d3dx_technique
145 UINT annotation_count
;
147 struct d3dx_parameter
*annotations
;
148 struct d3dx_pass
*passes
;
150 struct IDirect3DStateBlock9
*saved_state
;
153 struct d3dx_parameter_block
155 char magic_string
[ARRAY_SIZE(parameter_block_magic_string
)];
156 struct d3dx_effect
*effect
;
163 struct d3dx_recorded_parameter
165 struct d3dx_parameter
*param
;
171 ID3DXEffect ID3DXEffect_iface
;
174 unsigned int parameter_count
;
175 unsigned int technique_count
;
176 unsigned int object_count
;
177 struct d3dx_top_level_parameter
*parameters
;
178 struct d3dx_technique
*techniques
;
179 struct d3dx_object
*objects
;
182 struct wine_rb_tree param_tree
;
184 unsigned int full_name_tmp_size
;
186 struct ID3DXEffectStateManager
*manager
;
187 struct IDirect3DDevice9
*device
;
188 struct d3dx_effect_pool
*pool
;
189 struct d3dx_technique
*active_technique
;
190 struct d3dx_pass
*active_pass
;
193 ULONG64 version_counter
;
195 D3DLIGHT9 current_light
[8];
196 unsigned int light_updated
;
197 D3DMATERIAL9 current_material
;
198 BOOL material_updated
;
200 struct list parameter_block_list
;
201 struct d3dx_parameter_block
*current_parameter_block
;
204 #define INITIAL_SHARED_DATA_SIZE 4
206 struct d3dx_effect_pool
208 ID3DXEffectPool ID3DXEffectPool_iface
;
211 struct d3dx_shared_data
*shared_data
;
214 ULONG64 version_counter
;
217 struct ID3DXEffectCompilerImpl
219 ID3DXEffectCompiler ID3DXEffectCompiler_iface
;
223 static HRESULT
d3dx_parse_state(struct d3dx_effect
*effect
, struct d3dx_state
*state
,
224 const char *data
, const char **ptr
, struct d3dx_object
*objects
);
225 static void free_parameter(struct d3dx_parameter
*param
, BOOL element
, BOOL child
);
227 typedef BOOL (*walk_parameter_dep_func
)(void *data
, struct d3dx_parameter
*param
);
231 enum STATE_CLASS
class;
238 {SC_RENDERSTATE
, D3DRS_ZENABLE
, "D3DRS_ZENABLE"}, /* 0x0 */
239 {SC_RENDERSTATE
, D3DRS_FILLMODE
, "D3DRS_FILLMODE"},
240 {SC_RENDERSTATE
, D3DRS_SHADEMODE
, "D3DRS_SHADEMODE"},
241 {SC_RENDERSTATE
, D3DRS_ZWRITEENABLE
, "D3DRS_ZWRITEENABLE"},
242 {SC_RENDERSTATE
, D3DRS_ALPHATESTENABLE
, "D3DRS_ALPHATESTENABLE"},
243 {SC_RENDERSTATE
, D3DRS_LASTPIXEL
, "D3DRS_LASTPIXEL"},
244 {SC_RENDERSTATE
, D3DRS_SRCBLEND
, "D3DRS_SRCBLEND"},
245 {SC_RENDERSTATE
, D3DRS_DESTBLEND
, "D3DRS_DESTBLEND"},
246 {SC_RENDERSTATE
, D3DRS_CULLMODE
, "D3DRS_CULLMODE"},
247 {SC_RENDERSTATE
, D3DRS_ZFUNC
, "D3DRS_ZFUNC"},
248 {SC_RENDERSTATE
, D3DRS_ALPHAREF
, "D3DRS_ALPHAREF"},
249 {SC_RENDERSTATE
, D3DRS_ALPHAFUNC
, "D3DRS_ALPHAFUNC"},
250 {SC_RENDERSTATE
, D3DRS_DITHERENABLE
, "D3DRS_DITHERENABLE"},
251 {SC_RENDERSTATE
, D3DRS_ALPHABLENDENABLE
, "D3DRS_ALPHABLENDENABLE"},
252 {SC_RENDERSTATE
, D3DRS_FOGENABLE
, "D3DRS_FOGENABLE"},
253 {SC_RENDERSTATE
, D3DRS_SPECULARENABLE
, "D3DRS_SPECULARENABLE"},
254 {SC_RENDERSTATE
, D3DRS_FOGCOLOR
, "D3DRS_FOGCOLOR"}, /* 0x10 */
255 {SC_RENDERSTATE
, D3DRS_FOGTABLEMODE
, "D3DRS_FOGTABLEMODE"},
256 {SC_RENDERSTATE
, D3DRS_FOGSTART
, "D3DRS_FOGSTART"},
257 {SC_RENDERSTATE
, D3DRS_FOGEND
, "D3DRS_FOGEND"},
258 {SC_RENDERSTATE
, D3DRS_FOGDENSITY
, "D3DRS_FOGDENSITY"},
259 {SC_RENDERSTATE
, D3DRS_RANGEFOGENABLE
, "D3DRS_RANGEFOGENABLE"},
260 {SC_RENDERSTATE
, D3DRS_STENCILENABLE
, "D3DRS_STENCILENABLE"},
261 {SC_RENDERSTATE
, D3DRS_STENCILFAIL
, "D3DRS_STENCILFAIL"},
262 {SC_RENDERSTATE
, D3DRS_STENCILZFAIL
, "D3DRS_STENCILZFAIL"},
263 {SC_RENDERSTATE
, D3DRS_STENCILPASS
, "D3DRS_STENCILPASS"},
264 {SC_RENDERSTATE
, D3DRS_STENCILFUNC
, "D3DRS_STENCILFUNC"},
265 {SC_RENDERSTATE
, D3DRS_STENCILREF
, "D3DRS_STENCILREF"},
266 {SC_RENDERSTATE
, D3DRS_STENCILMASK
, "D3DRS_STENCILMASK"},
267 {SC_RENDERSTATE
, D3DRS_STENCILWRITEMASK
, "D3DRS_STENCILWRITEMASK"},
268 {SC_RENDERSTATE
, D3DRS_TEXTUREFACTOR
, "D3DRS_TEXTUREFACTOR"},
269 {SC_RENDERSTATE
, D3DRS_WRAP0
, "D3DRS_WRAP0"},
270 {SC_RENDERSTATE
, D3DRS_WRAP1
, "D3DRS_WRAP1"}, /* 0x20 */
271 {SC_RENDERSTATE
, D3DRS_WRAP2
, "D3DRS_WRAP2"},
272 {SC_RENDERSTATE
, D3DRS_WRAP3
, "D3DRS_WRAP3"},
273 {SC_RENDERSTATE
, D3DRS_WRAP4
, "D3DRS_WRAP4"},
274 {SC_RENDERSTATE
, D3DRS_WRAP5
, "D3DRS_WRAP5"},
275 {SC_RENDERSTATE
, D3DRS_WRAP6
, "D3DRS_WRAP6"},
276 {SC_RENDERSTATE
, D3DRS_WRAP7
, "D3DRS_WRAP7"},
277 {SC_RENDERSTATE
, D3DRS_WRAP8
, "D3DRS_WRAP8"},
278 {SC_RENDERSTATE
, D3DRS_WRAP9
, "D3DRS_WRAP9"},
279 {SC_RENDERSTATE
, D3DRS_WRAP10
, "D3DRS_WRAP10"},
280 {SC_RENDERSTATE
, D3DRS_WRAP11
, "D3DRS_WRAP11"},
281 {SC_RENDERSTATE
, D3DRS_WRAP12
, "D3DRS_WRAP12"},
282 {SC_RENDERSTATE
, D3DRS_WRAP13
, "D3DRS_WRAP13"},
283 {SC_RENDERSTATE
, D3DRS_WRAP14
, "D3DRS_WRAP14"},
284 {SC_RENDERSTATE
, D3DRS_WRAP15
, "D3DRS_WRAP15"},
285 {SC_RENDERSTATE
, D3DRS_CLIPPING
, "D3DRS_CLIPPING"},
286 {SC_RENDERSTATE
, D3DRS_LIGHTING
, "D3DRS_LIGHTING"}, /* 0x30 */
287 {SC_RENDERSTATE
, D3DRS_AMBIENT
, "D3DRS_AMBIENT"},
288 {SC_RENDERSTATE
, D3DRS_FOGVERTEXMODE
, "D3DRS_FOGVERTEXMODE"},
289 {SC_RENDERSTATE
, D3DRS_COLORVERTEX
, "D3DRS_COLORVERTEX"},
290 {SC_RENDERSTATE
, D3DRS_LOCALVIEWER
, "D3DRS_LOCALVIEWER"},
291 {SC_RENDERSTATE
, D3DRS_NORMALIZENORMALS
, "D3DRS_NORMALIZENORMALS"},
292 {SC_RENDERSTATE
, D3DRS_DIFFUSEMATERIALSOURCE
, "D3DRS_DIFFUSEMATERIALSOURCE"},
293 {SC_RENDERSTATE
, D3DRS_SPECULARMATERIALSOURCE
, "D3DRS_SPECULARMATERIALSOURCE"},
294 {SC_RENDERSTATE
, D3DRS_AMBIENTMATERIALSOURCE
, "D3DRS_AMBIENTMATERIALSOURCE"},
295 {SC_RENDERSTATE
, D3DRS_EMISSIVEMATERIALSOURCE
, "D3DRS_EMISSIVEMATERIALSOURCE"},
296 {SC_RENDERSTATE
, D3DRS_VERTEXBLEND
, "D3DRS_VERTEXBLEND"},
297 {SC_RENDERSTATE
, D3DRS_CLIPPLANEENABLE
, "D3DRS_CLIPPLANEENABLE"},
298 {SC_RENDERSTATE
, D3DRS_POINTSIZE
, "D3DRS_POINTSIZE"},
299 {SC_RENDERSTATE
, D3DRS_POINTSIZE_MIN
, "D3DRS_POINTSIZE_MIN"},
300 {SC_RENDERSTATE
, D3DRS_POINTSIZE_MAX
, "D3DRS_POINTSIZE_MAX"},
301 {SC_RENDERSTATE
, D3DRS_POINTSPRITEENABLE
, "D3DRS_POINTSPRITEENABLE"},
302 {SC_RENDERSTATE
, D3DRS_POINTSCALEENABLE
, "D3DRS_POINTSCALEENABLE"}, /* 0x40 */
303 {SC_RENDERSTATE
, D3DRS_POINTSCALE_A
, "D3DRS_POINTSCALE_A"},
304 {SC_RENDERSTATE
, D3DRS_POINTSCALE_B
, "D3DRS_POINTSCALE_B"},
305 {SC_RENDERSTATE
, D3DRS_POINTSCALE_C
, "D3DRS_POINTSCALE_C"},
306 {SC_RENDERSTATE
, D3DRS_MULTISAMPLEANTIALIAS
, "D3DRS_MULTISAMPLEANTIALIAS"},
307 {SC_RENDERSTATE
, D3DRS_MULTISAMPLEMASK
, "D3DRS_MULTISAMPLEMASK"},
308 {SC_RENDERSTATE
, D3DRS_PATCHEDGESTYLE
, "D3DRS_PATCHEDGESTYLE"},
309 {SC_RENDERSTATE
, D3DRS_DEBUGMONITORTOKEN
, "D3DRS_DEBUGMONITORTOKEN"},
310 {SC_RENDERSTATE
, D3DRS_INDEXEDVERTEXBLENDENABLE
, "D3DRS_INDEXEDVERTEXBLENDENABLE"},
311 {SC_RENDERSTATE
, D3DRS_COLORWRITEENABLE
, "D3DRS_COLORWRITEENABLE"},
312 {SC_RENDERSTATE
, D3DRS_TWEENFACTOR
, "D3DRS_TWEENFACTOR"},
313 {SC_RENDERSTATE
, D3DRS_BLENDOP
, "D3DRS_BLENDOP"},
314 {SC_RENDERSTATE
, D3DRS_POSITIONDEGREE
, "D3DRS_POSITIONDEGREE"},
315 {SC_RENDERSTATE
, D3DRS_NORMALDEGREE
, "D3DRS_NORMALDEGREE"},
316 {SC_RENDERSTATE
, D3DRS_SCISSORTESTENABLE
, "D3DRS_SCISSORTESTENABLE"},
317 {SC_RENDERSTATE
, D3DRS_SLOPESCALEDEPTHBIAS
, "D3DRS_SLOPESCALEDEPTHBIAS"},
318 {SC_RENDERSTATE
, D3DRS_ANTIALIASEDLINEENABLE
, "D3DRS_ANTIALIASEDLINEENABLE"}, /* 0x50 */
319 {SC_RENDERSTATE
, D3DRS_MINTESSELLATIONLEVEL
, "D3DRS_MINTESSELLATIONLEVEL"},
320 {SC_RENDERSTATE
, D3DRS_MAXTESSELLATIONLEVEL
, "D3DRS_MAXTESSELLATIONLEVEL"},
321 {SC_RENDERSTATE
, D3DRS_ADAPTIVETESS_X
, "D3DRS_ADAPTIVETESS_X"},
322 {SC_RENDERSTATE
, D3DRS_ADAPTIVETESS_Y
, "D3DRS_ADAPTIVETESS_Y"},
323 {SC_RENDERSTATE
, D3DRS_ADAPTIVETESS_Z
, "D3DRS_ADAPTIVETESS_Z"},
324 {SC_RENDERSTATE
, D3DRS_ADAPTIVETESS_W
, "D3DRS_ADAPTIVETESS_W"},
325 {SC_RENDERSTATE
, D3DRS_ENABLEADAPTIVETESSELLATION
, "D3DRS_ENABLEADAPTIVETESSELLATION"},
326 {SC_RENDERSTATE
, D3DRS_TWOSIDEDSTENCILMODE
, "D3DRS_TWOSIDEDSTENCILMODE"},
327 {SC_RENDERSTATE
, D3DRS_CCW_STENCILFAIL
, "D3DRS_CCW_STENCILFAIL"},
328 {SC_RENDERSTATE
, D3DRS_CCW_STENCILZFAIL
, "D3DRS_CCW_STENCILZFAIL"},
329 {SC_RENDERSTATE
, D3DRS_CCW_STENCILPASS
, "D3DRS_CCW_STENCILPASS"},
330 {SC_RENDERSTATE
, D3DRS_CCW_STENCILFUNC
, "D3DRS_CCW_STENCILFUNC"},
331 {SC_RENDERSTATE
, D3DRS_COLORWRITEENABLE1
, "D3DRS_COLORWRITEENABLE1"},
332 {SC_RENDERSTATE
, D3DRS_COLORWRITEENABLE2
, "D3DRS_COLORWRITEENABLE2"},
333 {SC_RENDERSTATE
, D3DRS_COLORWRITEENABLE3
, "D3DRS_COLORWRITEENABLE3"},
334 {SC_RENDERSTATE
, D3DRS_BLENDFACTOR
, "D3DRS_BLENDFACTOR"}, /* 0x60 */
335 {SC_RENDERSTATE
, D3DRS_SRGBWRITEENABLE
, "D3DRS_SRGBWRITEENABLE"},
336 {SC_RENDERSTATE
, D3DRS_DEPTHBIAS
, "D3DRS_DEPTHBIAS"},
337 {SC_RENDERSTATE
, D3DRS_SEPARATEALPHABLENDENABLE
, "D3DRS_SEPARATEALPHABLENDENABLE"},
338 {SC_RENDERSTATE
, D3DRS_SRCBLENDALPHA
, "D3DRS_SRCBLENDALPHA"},
339 {SC_RENDERSTATE
, D3DRS_DESTBLENDALPHA
, "D3DRS_DESTBLENDALPHA"},
340 {SC_RENDERSTATE
, D3DRS_BLENDOPALPHA
, "D3DRS_BLENDOPALPHA"},
342 {SC_TEXTURESTAGE
, D3DTSS_COLOROP
, "D3DTSS_COLOROP"},
343 {SC_TEXTURESTAGE
, D3DTSS_COLORARG0
, "D3DTSS_COLORARG0"},
344 {SC_TEXTURESTAGE
, D3DTSS_COLORARG1
, "D3DTSS_COLORARG1"},
345 {SC_TEXTURESTAGE
, D3DTSS_COLORARG2
, "D3DTSS_COLORARG2"},
346 {SC_TEXTURESTAGE
, D3DTSS_ALPHAOP
, "D3DTSS_ALPHAOP"},
347 {SC_TEXTURESTAGE
, D3DTSS_ALPHAARG0
, "D3DTSS_ALPHAARG0"},
348 {SC_TEXTURESTAGE
, D3DTSS_ALPHAARG1
, "D3DTSS_ALPHAARG1"},
349 {SC_TEXTURESTAGE
, D3DTSS_ALPHAARG2
, "D3DTSS_ALPHAARG2"},
350 {SC_TEXTURESTAGE
, D3DTSS_RESULTARG
, "D3DTSS_RESULTARG"},
351 {SC_TEXTURESTAGE
, D3DTSS_BUMPENVMAT00
, "D3DTSS_BUMPENVMAT00"}, /* 0x70 */
352 {SC_TEXTURESTAGE
, D3DTSS_BUMPENVMAT01
, "D3DTSS_BUMPENVMAT01"},
353 {SC_TEXTURESTAGE
, D3DTSS_BUMPENVMAT10
, "D3DTSS_BUMPENVMAT10"},
354 {SC_TEXTURESTAGE
, D3DTSS_BUMPENVMAT11
, "D3DTSS_BUMPENVMAT11"},
355 {SC_TEXTURESTAGE
, D3DTSS_TEXCOORDINDEX
, "D3DTSS_TEXCOORDINDEX"},
356 {SC_TEXTURESTAGE
, D3DTSS_BUMPENVLSCALE
, "D3DTSS_BUMPENVLSCALE"},
357 {SC_TEXTURESTAGE
, D3DTSS_BUMPENVLOFFSET
, "D3DTSS_BUMPENVLOFFSET"},
358 {SC_TEXTURESTAGE
, D3DTSS_TEXTURETRANSFORMFLAGS
, "D3DTSS_TEXTURETRANSFORMFLAGS"},
359 {SC_TEXTURESTAGE
, D3DTSS_CONSTANT
, "D3DTSS_CONSTANT"},
361 {SC_NPATCHMODE
, 0, "NPatchMode"},
365 {SC_TRANSFORM
, D3DTS_PROJECTION
, "D3DTS_PROJECTION"},
366 {SC_TRANSFORM
, D3DTS_VIEW
, "D3DTS_VIEW"},
367 {SC_TRANSFORM
, D3DTS_WORLD
, "D3DTS_WORLD"},
368 {SC_TRANSFORM
, D3DTS_TEXTURE0
, "D3DTS_TEXTURE0"},
370 {SC_MATERIAL
, MT_DIFFUSE
, "MaterialDiffuse"},
371 {SC_MATERIAL
, MT_AMBIENT
, "MaterialAmbient"}, /* 0x80 */
372 {SC_MATERIAL
, MT_SPECULAR
, "MaterialSpecular"},
373 {SC_MATERIAL
, MT_EMISSIVE
, "MaterialEmissive"},
374 {SC_MATERIAL
, MT_POWER
, "MaterialPower"},
376 {SC_LIGHT
, LT_TYPE
, "LightType"},
377 {SC_LIGHT
, LT_DIFFUSE
, "LightDiffuse"},
378 {SC_LIGHT
, LT_SPECULAR
, "LightSpecular"},
379 {SC_LIGHT
, LT_AMBIENT
, "LightAmbient"},
380 {SC_LIGHT
, LT_POSITION
, "LightPosition"},
381 {SC_LIGHT
, LT_DIRECTION
, "LightDirection"},
382 {SC_LIGHT
, LT_RANGE
, "LightRange"},
383 {SC_LIGHT
, LT_FALLOFF
, "LightFallOff"},
384 {SC_LIGHT
, LT_ATTENUATION0
, "LightAttenuation0"},
385 {SC_LIGHT
, LT_ATTENUATION1
, "LightAttenuation1"},
386 {SC_LIGHT
, LT_ATTENUATION2
, "LightAttenuation2"},
387 {SC_LIGHT
, LT_THETA
, "LightTheta"},
388 {SC_LIGHT
, LT_PHI
, "LightPhi"}, /* 0x90 */
390 {SC_LIGHTENABLE
, 0, "LightEnable"},
392 {SC_VERTEXSHADER
, 0, "Vertexshader"},
394 {SC_PIXELSHADER
, 0, "Pixelshader"},
395 /* Shader constants */
396 {SC_SHADERCONST
, SCT_VSFLOAT
, "VertexShaderConstantF"},
397 {SC_SHADERCONST
, SCT_VSBOOL
, "VertexShaderConstantB"},
398 {SC_SHADERCONST
, SCT_VSINT
, "VertexShaderConstantI"},
399 {SC_SHADERCONST
, SCT_VSFLOAT
, "VertexShaderConstant"},
400 {SC_SHADERCONST
, SCT_VSFLOAT
, "VertexShaderConstant1"},
401 {SC_SHADERCONST
, SCT_VSFLOAT
, "VertexShaderConstant2"},
402 {SC_SHADERCONST
, SCT_VSFLOAT
, "VertexShaderConstant3"},
403 {SC_SHADERCONST
, SCT_VSFLOAT
, "VertexShaderConstant4"},
404 {SC_SHADERCONST
, SCT_PSFLOAT
, "PixelShaderConstantF"},
405 {SC_SHADERCONST
, SCT_PSBOOL
, "PixelShaderConstantB"},
406 {SC_SHADERCONST
, SCT_PSINT
, "PixelShaderConstantI"},
407 {SC_SHADERCONST
, SCT_PSFLOAT
, "PixelShaderConstant"},
408 {SC_SHADERCONST
, SCT_PSFLOAT
, "PixelShaderConstant1"}, /* 0xa0 */
409 {SC_SHADERCONST
, SCT_PSFLOAT
, "PixelShaderConstant2"},
410 {SC_SHADERCONST
, SCT_PSFLOAT
, "PixelShaderConstant3"},
411 {SC_SHADERCONST
, SCT_PSFLOAT
, "PixelShaderConstant4"},
413 {SC_TEXTURE
, 0, "Texture"},
415 {SC_SAMPLERSTATE
, D3DSAMP_ADDRESSU
, "AddressU"},
416 {SC_SAMPLERSTATE
, D3DSAMP_ADDRESSV
, "AddressV"},
417 {SC_SAMPLERSTATE
, D3DSAMP_ADDRESSW
, "AddressW"},
418 {SC_SAMPLERSTATE
, D3DSAMP_BORDERCOLOR
, "BorderColor"},
419 {SC_SAMPLERSTATE
, D3DSAMP_MAGFILTER
, "MagFilter"},
420 {SC_SAMPLERSTATE
, D3DSAMP_MINFILTER
, "MinFilter"},
421 {SC_SAMPLERSTATE
, D3DSAMP_MIPFILTER
, "MipFilter"},
422 {SC_SAMPLERSTATE
, D3DSAMP_MIPMAPLODBIAS
, "MipMapLodBias"},
423 {SC_SAMPLERSTATE
, D3DSAMP_MAXMIPLEVEL
, "MaxMipLevel"},
424 {SC_SAMPLERSTATE
, D3DSAMP_MAXANISOTROPY
, "MaxAnisotropy"},
425 {SC_SAMPLERSTATE
, D3DSAMP_SRGBTEXTURE
, "SRGBTexture"},
426 {SC_SAMPLERSTATE
, D3DSAMP_ELEMENTINDEX
, "ElementIndex"}, /* 0xb0 */
427 {SC_SAMPLERSTATE
, D3DSAMP_DMAPOFFSET
, "DMAPOffset"},
429 {SC_SETSAMPLER
, 0, "Sampler"},
432 static inline void read_dword(const char **ptr
, DWORD
*d
)
434 memcpy(d
, *ptr
, sizeof(*d
));
438 static void skip_dword_unknown(const char **ptr
, unsigned int count
)
443 WARN("Skipping %u unknown DWORDs:\n", count
);
444 for (i
= 0; i
< count
; ++i
)
447 WARN("\t0x%08x\n", d
);
451 static inline D3DXHANDLE
get_parameter_handle(struct d3dx_parameter
*parameter
)
453 return (D3DXHANDLE
)parameter
;
456 static inline D3DXHANDLE
get_technique_handle(struct d3dx_technique
*technique
)
458 return (D3DXHANDLE
)technique
;
461 static inline D3DXHANDLE
get_pass_handle(struct d3dx_pass
*pass
)
463 return (D3DXHANDLE
)pass
;
466 static struct d3dx_technique
*get_technique_by_name(struct d3dx_effect
*effect
, const char *name
)
470 if (!name
) return NULL
;
472 for (i
= 0; i
< effect
->technique_count
; ++i
)
474 if (!strcmp(effect
->techniques
[i
].name
, name
))
475 return &effect
->techniques
[i
];
481 static struct d3dx_technique
*get_valid_technique(struct d3dx_effect
*effect
, D3DXHANDLE technique
)
485 for (i
= 0; i
< effect
->technique_count
; ++i
)
487 if (get_technique_handle(&effect
->techniques
[i
]) == technique
)
488 return &effect
->techniques
[i
];
491 return get_technique_by_name(effect
, technique
);
494 static struct d3dx_pass
*get_valid_pass(struct d3dx_effect
*effect
, D3DXHANDLE pass
)
498 for (i
= 0; i
< effect
->technique_count
; ++i
)
500 struct d3dx_technique
*technique
= &effect
->techniques
[i
];
502 for (k
= 0; k
< technique
->pass_count
; ++k
)
504 if (get_pass_handle(&technique
->passes
[k
]) == pass
)
505 return &technique
->passes
[k
];
512 static struct d3dx_parameter
*get_valid_parameter(struct d3dx_effect
*effect
, D3DXHANDLE parameter
)
514 struct d3dx_parameter
*handle_param
= (struct d3dx_parameter
*)parameter
;
516 if (handle_param
&& !strncmp(handle_param
->magic_string
, parameter_magic_string
,
517 sizeof(parameter_magic_string
)))
520 return effect
->flags
& D3DXFX_LARGEADDRESSAWARE
? NULL
: get_parameter_by_name(effect
, NULL
, parameter
);
523 static struct d3dx_parameter_block
*get_valid_parameter_block(D3DXHANDLE handle
)
525 struct d3dx_parameter_block
*block
= (struct d3dx_parameter_block
*)handle
;
527 return block
&& !strncmp(block
->magic_string
, parameter_block_magic_string
,
528 sizeof(parameter_block_magic_string
)) ? block
: NULL
;
531 static void free_state(struct d3dx_state
*state
)
533 free_parameter(&state
->parameter
, FALSE
, FALSE
);
536 static void free_object(struct d3dx_object
*object
)
538 HeapFree(GetProcessHeap(), 0, object
->data
);
541 static void free_sampler(struct d3dx_sampler
*sampler
)
545 for (i
= 0; i
< sampler
->state_count
; ++i
)
547 free_state(&sampler
->states
[i
]);
549 heap_free(sampler
->states
);
552 static void d3dx_pool_release_shared_parameter(struct d3dx_top_level_parameter
*param
);
554 static void free_parameter_object_data(struct d3dx_parameter
*param
, const void *data
, unsigned int bytes
)
556 unsigned int i
, count
;
558 if (param
->class != D3DXPC_OBJECT
)
561 count
= min(param
->element_count
? param
->element_count
: 1, bytes
/ sizeof(void *));
563 for (i
= 0; i
< count
; ++i
)
568 heap_free(((char **)data
)[i
]);
572 case D3DXPT_TEXTURE1D
:
573 case D3DXPT_TEXTURE2D
:
574 case D3DXPT_TEXTURE3D
:
575 case D3DXPT_TEXTURECUBE
:
576 case D3DXPT_PIXELSHADER
:
577 case D3DXPT_VERTEXSHADER
:
578 if (*(IUnknown
**)data
)
579 IUnknown_Release(((IUnknown
**)data
)[i
]);
583 case D3DXPT_SAMPLER1D
:
584 case D3DXPT_SAMPLER2D
:
585 case D3DXPT_SAMPLER3D
:
586 case D3DXPT_SAMPLERCUBE
:
588 free_sampler((struct d3dx_sampler
*)data
);
592 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param
->type
));
598 static void free_parameter_data(struct d3dx_parameter
*param
, BOOL child
)
603 if (!param
->element_count
)
604 free_parameter_object_data(param
, param
->data
, param
->bytes
);
606 if (!child
|| is_param_type_sampler(param
->type
))
607 heap_free(param
->data
);
610 static void free_parameter(struct d3dx_parameter
*param
, BOOL element
, BOOL child
)
614 TRACE("Free parameter %p, name %s, type %s, element %#x, child %#x.\n", param
, param
->name
,
615 debug_d3dxparameter_type(param
->type
), element
, child
);
617 if (param
->param_eval
)
618 d3dx_free_param_eval(param
->param_eval
);
622 unsigned int count
= param
->element_count
? param
->element_count
: param
->member_count
;
624 for (i
= 0; i
< count
; ++i
)
625 free_parameter(¶m
->members
[i
], param
->element_count
!= 0, TRUE
);
626 HeapFree(GetProcessHeap(), 0, param
->members
);
629 heap_free(param
->full_name
);
630 free_parameter_data(param
, child
);
632 /* only the parent has to release name and semantic */
635 HeapFree(GetProcessHeap(), 0, param
->name
);
636 HeapFree(GetProcessHeap(), 0, param
->semantic
);
640 static void free_top_level_parameter(struct d3dx_top_level_parameter
*param
)
642 if (param
->annotations
)
646 for (i
= 0; i
< param
->annotation_count
; ++i
)
647 free_parameter(¶m
->annotations
[i
], FALSE
, FALSE
);
648 HeapFree(GetProcessHeap(), 0, param
->annotations
);
650 d3dx_pool_release_shared_parameter(param
);
651 free_parameter(¶m
->param
, FALSE
, FALSE
);
654 static void free_pass(struct d3dx_pass
*pass
)
658 TRACE("Free pass %p\n", pass
);
663 if (pass
->annotations
)
665 for (i
= 0; i
< pass
->annotation_count
; ++i
)
666 free_parameter(&pass
->annotations
[i
], FALSE
, FALSE
);
667 HeapFree(GetProcessHeap(), 0, pass
->annotations
);
668 pass
->annotations
= NULL
;
673 for (i
= 0; i
< pass
->state_count
; ++i
)
674 free_state(&pass
->states
[i
]);
675 HeapFree(GetProcessHeap(), 0, pass
->states
);
679 HeapFree(GetProcessHeap(), 0, pass
->name
);
683 static void free_technique(struct d3dx_technique
*technique
)
687 TRACE("Free technique %p\n", technique
);
692 if (technique
->saved_state
)
694 IDirect3DStateBlock9_Release(technique
->saved_state
);
695 technique
->saved_state
= NULL
;
698 if (technique
->annotations
)
700 for (i
= 0; i
< technique
->annotation_count
; ++i
)
701 free_parameter(&technique
->annotations
[i
], FALSE
, FALSE
);
702 HeapFree(GetProcessHeap(), 0, technique
->annotations
);
703 technique
->annotations
= NULL
;
706 if (technique
->passes
)
708 for (i
= 0; i
< technique
->pass_count
; ++i
)
709 free_pass(&technique
->passes
[i
]);
710 HeapFree(GetProcessHeap(), 0, technique
->passes
);
711 technique
->passes
= NULL
;
714 HeapFree(GetProcessHeap(), 0, technique
->name
);
715 technique
->name
= NULL
;
718 static unsigned int get_recorded_parameter_size(const struct d3dx_recorded_parameter
*record
)
720 return sizeof(*record
) + record
->bytes
;
723 static void free_parameter_block(struct d3dx_parameter_block
*block
)
725 struct d3dx_recorded_parameter
*record
;
730 record
= (struct d3dx_recorded_parameter
*)block
->buffer
;
731 while ((BYTE
*)record
< block
->buffer
+ block
->offset
)
733 free_parameter_object_data(record
->param
, record
+ 1, record
->bytes
);
734 record
= (struct d3dx_recorded_parameter
*)((BYTE
*)record
+ get_recorded_parameter_size(record
));
736 assert((BYTE
*)record
== block
->buffer
+ block
->offset
);
738 heap_free(block
->buffer
);
742 static void d3dx_effect_cleanup(struct d3dx_effect
*effect
)
744 struct d3dx_parameter_block
*block
, *cursor
;
745 ID3DXEffectPool
*pool
;
748 TRACE("effect %p.\n", effect
);
750 free_parameter_block(effect
->current_parameter_block
);
751 LIST_FOR_EACH_ENTRY_SAFE(block
, cursor
, &effect
->parameter_block_list
, struct d3dx_parameter_block
, entry
)
753 list_remove(&block
->entry
);
754 free_parameter_block(block
);
757 heap_free(effect
->full_name_tmp
);
759 if (effect
->parameters
)
761 for (i
= 0; i
< effect
->parameter_count
; ++i
)
762 free_top_level_parameter(&effect
->parameters
[i
]);
763 heap_free(effect
->parameters
);
766 if (effect
->techniques
)
768 for (i
= 0; i
< effect
->technique_count
; ++i
)
769 free_technique(&effect
->techniques
[i
]);
770 heap_free(effect
->techniques
);
775 for (i
= 0; i
< effect
->object_count
; ++i
)
776 free_object(&effect
->objects
[i
]);
777 heap_free(effect
->objects
);
782 pool
= &effect
->pool
->ID3DXEffectPool_iface
;
783 pool
->lpVtbl
->Release(pool
);
787 IUnknown_Release(effect
->manager
);
789 IDirect3DDevice9_Release(effect
->device
);
793 static void get_vector(struct d3dx_parameter
*param
, D3DXVECTOR4
*vector
)
797 for (i
= 0; i
< 4; ++i
)
799 if (i
< param
->columns
)
800 set_number((FLOAT
*)vector
+ i
, D3DXPT_FLOAT
, (DWORD
*)param
->data
+ i
, param
->type
);
802 ((FLOAT
*)vector
)[i
] = 0.0f
;
806 static void set_vector(struct d3dx_parameter
*param
, const D3DXVECTOR4
*vector
, void *dst_data
)
810 for (i
= 0; i
< param
->columns
; ++i
)
811 set_number((FLOAT
*)dst_data
+ i
, param
->type
, (FLOAT
*)vector
+ i
, D3DXPT_FLOAT
);
814 static void get_matrix(struct d3dx_parameter
*param
, D3DXMATRIX
*matrix
, BOOL transpose
)
818 for (i
= 0; i
< 4; ++i
)
820 for (k
= 0; k
< 4; ++k
)
822 FLOAT
*tmp
= transpose
? (FLOAT
*)&matrix
->u
.m
[k
][i
] : (FLOAT
*)&matrix
->u
.m
[i
][k
];
824 if ((i
< param
->rows
) && (k
< param
->columns
))
825 set_number(tmp
, D3DXPT_FLOAT
, (DWORD
*)param
->data
+ i
* param
->columns
+ k
, param
->type
);
832 static void set_matrix(struct d3dx_parameter
*param
, const D3DXMATRIX
*matrix
, void *dst_data
)
836 if (param
->type
== D3DXPT_FLOAT
)
838 if (param
->columns
== 4)
840 memcpy(dst_data
, matrix
->u
.m
, param
->rows
* 4 * sizeof(float));
844 for (i
= 0; i
< param
->rows
; ++i
)
845 memcpy((float *)dst_data
+ i
* param
->columns
, matrix
->u
.m
+ i
, param
->columns
* sizeof(float));
850 for (i
= 0; i
< param
->rows
; ++i
)
852 for (k
= 0; k
< param
->columns
; ++k
)
853 set_number((FLOAT
*)dst_data
+ i
* param
->columns
+ k
, param
->type
,
854 &matrix
->u
.m
[i
][k
], D3DXPT_FLOAT
);
858 static void set_matrix_transpose(struct d3dx_parameter
*param
, const D3DXMATRIX
*matrix
, void *dst_data
)
862 for (i
= 0; i
< param
->rows
; ++i
)
864 for (k
= 0; k
< param
->columns
; ++k
)
866 set_number((FLOAT
*)dst_data
+ i
* param
->columns
+ k
, param
->type
,
867 &matrix
->u
.m
[k
][i
], D3DXPT_FLOAT
);
872 static HRESULT
set_string(char **param_data
, const char *string
)
874 heap_free(*param_data
);
875 *param_data
= heap_alloc(strlen(string
) + 1);
878 ERR("Out of memory.\n");
879 return E_OUTOFMEMORY
;
881 strcpy(*param_data
, string
);
885 static HRESULT
set_value(struct d3dx_parameter
*param
, const void *data
, unsigned int bytes
,
888 unsigned int i
, count
;
890 bytes
= min(bytes
, param
->bytes
);
891 count
= min(param
->element_count
? param
->element_count
: 1, bytes
/ sizeof(void *));
896 case D3DXPT_TEXTURE1D
:
897 case D3DXPT_TEXTURE2D
:
898 case D3DXPT_TEXTURE3D
:
899 case D3DXPT_TEXTURECUBE
:
900 for (i
= 0; i
< count
; ++i
)
902 IUnknown
*old_texture
= ((IUnknown
**)dst_data
)[i
];
903 IUnknown
*new_texture
= ((IUnknown
**)data
)[i
];
905 if (new_texture
== old_texture
)
909 IUnknown_AddRef(new_texture
);
911 IUnknown_Release(old_texture
);
918 TRACE("Copy %u bytes.\n", bytes
);
919 memcpy(dst_data
, data
, bytes
);
926 for (i
= 0; i
< count
; ++i
)
927 if (FAILED(hr
= set_string(&((char **)dst_data
)[i
], ((const char **)data
)[i
])))
933 FIXME("Unhandled type %s.\n", debug_d3dxparameter_type(param
->type
));
940 static struct d3dx_parameter
*get_parameter_element_by_name(struct d3dx_effect
*effect
,
941 struct d3dx_parameter
*parameter
, const char *name
)
944 struct d3dx_parameter
*temp_parameter
;
947 TRACE("parameter %p, name %s\n", parameter
, debugstr_a(name
));
949 if (!name
|| !*name
) return NULL
;
951 element
= atoi(name
);
952 part
= strchr(name
, ']') + 1;
954 /* check for empty [] && element range */
955 if ((part
- name
) > 1 && parameter
->element_count
> element
)
957 temp_parameter
= ¶meter
->members
[element
];
962 return get_parameter_by_name(effect
, temp_parameter
, part
);
965 TRACE("Returning parameter %p\n", temp_parameter
);
966 return temp_parameter
;
969 FIXME("Unhandled case \"%c\"\n", *--part
);
974 TRACE("Parameter not found\n");
978 static struct d3dx_parameter
*get_annotation_by_name(struct d3dx_effect
*effect
, unsigned int count
,
979 struct d3dx_parameter
*annotations
, const char *name
)
982 struct d3dx_parameter
*temp_parameter
;
985 TRACE("count %u, annotations %p, name %s\n", count
, annotations
, debugstr_a(name
));
987 if (!name
|| !*name
) return NULL
;
989 length
= strcspn( name
, "[.@" );
990 part
= name
+ length
;
992 for (i
= 0; i
< count
; ++i
)
994 temp_parameter
= &annotations
[i
];
996 if (!strcmp(temp_parameter
->name
, name
))
998 TRACE("Returning annotation %p\n", temp_parameter
);
999 return temp_parameter
;
1001 else if (strlen(temp_parameter
->name
) == length
&& !strncmp(temp_parameter
->name
, name
, length
))
1006 return get_parameter_by_name(effect
, temp_parameter
, part
);
1009 return get_parameter_element_by_name(effect
, temp_parameter
, part
);
1012 FIXME("Unhandled case \"%c\"\n", *--part
);
1018 TRACE("Annotation not found\n");
1022 struct d3dx_parameter
*get_parameter_by_name(struct d3dx_effect
* effect
,
1023 struct d3dx_parameter
*parameter
, const char *name
)
1025 struct d3dx_parameter
*temp_parameter
;
1026 unsigned int name_len
, param_name_len
;
1027 unsigned int i
, count
, length
;
1028 struct wine_rb_entry
*entry
;
1029 unsigned int full_name_size
;
1033 TRACE("effect %p, parameter %p, name %s.\n", effect
, parameter
, debugstr_a(name
));
1035 if (!name
|| !*name
) return NULL
;
1039 if ((entry
= wine_rb_get(&effect
->param_tree
, name
)))
1040 return WINE_RB_ENTRY_VALUE(entry
, struct d3dx_parameter
, rb_entry
);
1044 if (parameter
->full_name
)
1046 name_len
= strlen(name
);
1047 param_name_len
= strlen(parameter
->full_name
);
1048 full_name_size
= name_len
+ param_name_len
+ 2;
1049 if (effect
->full_name_tmp_size
< full_name_size
)
1051 if (!(full_name
= heap_realloc(effect
->full_name_tmp
, full_name_size
)))
1053 ERR("Out of memory.\n");
1056 effect
->full_name_tmp
= full_name
;
1057 effect
->full_name_tmp_size
= full_name_size
;
1061 full_name
= effect
->full_name_tmp
;
1063 memcpy(full_name
, parameter
->full_name
, param_name_len
);
1064 full_name
[param_name_len
] = '.';
1065 memcpy(full_name
+ param_name_len
+ 1, name
, name_len
);
1066 full_name
[param_name_len
+ 1 + name_len
] = 0;
1068 if ((entry
= wine_rb_get(&effect
->param_tree
, full_name
)))
1069 return WINE_RB_ENTRY_VALUE(entry
, struct d3dx_parameter
, rb_entry
);
1073 /* Pass / technique annotations are not stored in the parameters tree,
1074 * do a linear search. */
1075 count
= parameter
->member_count
;
1077 length
= strcspn( name
, "[." );
1078 part
= name
+ length
;
1080 for (i
= 0; i
< count
; i
++)
1082 temp_parameter
= ¶meter
->members
[i
];
1084 if (!strcmp(temp_parameter
->name
, name
))
1086 TRACE("Returning parameter %p\n", temp_parameter
);
1087 return temp_parameter
;
1089 else if (strlen(temp_parameter
->name
) == length
&& !strncmp(temp_parameter
->name
, name
, length
))
1094 return get_parameter_by_name(effect
, temp_parameter
, part
);
1097 return get_parameter_element_by_name(effect
, temp_parameter
, part
);
1100 FIXME("Unhandled case \"%c\"\n", *--part
);
1106 TRACE("Parameter not found\n");
1110 static inline DWORD
d3dx9_effect_version(DWORD major
, DWORD minor
)
1112 return (0xfeff0000 | ((major
) << 8) | (minor
));
1115 static HRESULT
d3dx9_get_param_value_ptr(struct d3dx_pass
*pass
, struct d3dx_state
*state
,
1116 void **param_value
, struct d3dx_parameter
**out_param
,
1117 BOOL update_all
, BOOL
*param_dirty
)
1119 struct d3dx_parameter
*param
= &state
->parameter
;
1121 *param_value
= NULL
;
1123 *param_dirty
= FALSE
;
1125 switch (state
->type
)
1128 param
= state
->referenced_param
;
1129 *param_dirty
= is_param_dirty(param
, pass
->update_version
);
1133 *param_value
= param
->data
;
1135 case ST_ARRAY_SELECTOR
:
1137 unsigned int array_idx
;
1138 static const struct d3dx_parameter array_idx_param
=
1139 {"", NULL
, NULL
, NULL
, NULL
, D3DXPC_SCALAR
, D3DXPT_INT
, 1, 1, 0, 0, 0, sizeof(array_idx
)};
1141 struct d3dx_parameter
*ref_param
, *selected_param
;
1143 if (!param
->param_eval
)
1145 FIXME("Preshader structure is null.\n");
1146 return D3DERR_INVALIDCALL
;
1148 /* We override with the update_version of the pass because we want
1149 * to force index recomputation and check for out of bounds. */
1150 if (is_param_eval_input_dirty(param
->param_eval
, pass
->update_version
))
1152 if (FAILED(hr
= d3dx_evaluate_parameter(param
->param_eval
, &array_idx_param
, &array_idx
)))
1157 array_idx
= state
->index
;
1159 ref_param
= state
->referenced_param
;
1160 TRACE("Array index %u, stored array index %u, element_count %u.\n", array_idx
, state
->index
,
1161 ref_param
->element_count
);
1162 /* According to the tests, native d3dx handles the case of array index evaluated to -1
1163 * in a specific way, always selecting first array element and not returning error. */
1164 if (array_idx
== ~0u)
1166 WARN("Array index is -1, setting to 0.\n");
1170 if (array_idx
>= ref_param
->element_count
)
1172 WARN("Computed array index %u is larger than array size %u.\n",
1173 array_idx
, ref_param
->element_count
);
1176 selected_param
= &ref_param
->members
[array_idx
];
1177 *param_dirty
= state
->index
!= array_idx
|| is_param_dirty(selected_param
, pass
->update_version
);
1178 state
->index
= array_idx
;
1180 *param_value
= selected_param
->data
;
1181 *out_param
= selected_param
;
1185 if (param
->param_eval
)
1188 *param_value
= param
->data
;
1189 /* We check with the update_version of the pass because the
1190 * same preshader might be used by both the vertex and the
1191 * pixel shader (that can happen e.g. for sampler states). */
1192 if (update_all
|| is_param_eval_input_dirty(param
->param_eval
, pass
->update_version
))
1194 *param_dirty
= TRUE
;
1195 return d3dx_evaluate_parameter(param
->param_eval
, param
, *param_value
);
1202 FIXME("No preshader for FXLC parameter.\n");
1203 return D3DERR_INVALIDCALL
;
1209 static unsigned int get_annotation_from_object(struct d3dx_effect
*effect
, D3DXHANDLE object
,
1210 struct d3dx_parameter
**annotations
)
1212 struct d3dx_parameter
*param
= get_valid_parameter(effect
, object
);
1213 struct d3dx_pass
*pass
= get_valid_pass(effect
, object
);
1214 struct d3dx_technique
*technique
= get_valid_technique(effect
, object
);
1218 *annotations
= pass
->annotations
;
1219 return pass
->annotation_count
;
1223 *annotations
= technique
->annotations
;
1224 return technique
->annotation_count
;
1228 if (is_top_level_parameter(param
))
1230 struct d3dx_top_level_parameter
*top_param
1231 = top_level_parameter_from_parameter(param
);
1233 *annotations
= top_param
->annotations
;
1234 return top_param
->annotation_count
;
1238 *annotations
= NULL
;
1244 FIXME("Functions are not handled, yet!\n");
1249 static BOOL
walk_parameter_tree(struct d3dx_parameter
*param
, walk_parameter_dep_func param_func
,
1253 unsigned int member_count
;
1255 if (param_func(data
, param
))
1258 member_count
= param
->element_count
? param
->element_count
: param
->member_count
;
1259 for (i
= 0; i
< member_count
; ++i
)
1261 if (walk_parameter_tree(¶m
->members
[i
], param_func
, data
))
1267 static ULONG64
*get_version_counter_ptr(struct d3dx_effect
*effect
)
1269 return effect
->pool
? &effect
->pool
->version_counter
: &effect
->version_counter
;
1272 static ULONG64
next_effect_update_version(struct d3dx_effect
*effect
)
1274 return next_update_version(get_version_counter_ptr(effect
));
1277 static void *record_parameter(struct d3dx_effect
*effect
, struct d3dx_parameter
*param
, unsigned int bytes
)
1279 struct d3dx_parameter_block
*block
= effect
->current_parameter_block
;
1280 struct d3dx_recorded_parameter new_record
, *record
;
1281 unsigned int new_size
, alloc_size
;
1283 new_record
.param
= param
;
1284 new_record
.bytes
= bytes
;
1285 new_size
= block
->offset
+ get_recorded_parameter_size(&new_record
);
1287 if (new_size
> block
->size
)
1291 alloc_size
= max(block
->size
* 2, max(new_size
, INITIAL_PARAM_BLOCK_SIZE
));
1293 new_alloc
= heap_realloc(block
->buffer
, alloc_size
);
1295 new_alloc
= heap_alloc(alloc_size
);
1299 ERR("Out of memory.\n");
1302 /* Data update functions may want to free some references upon setting value. */
1303 memset(new_alloc
+ block
->size
, 0, alloc_size
- block
->size
);
1305 block
->size
= alloc_size
;
1306 block
->buffer
= new_alloc
;
1308 record
= (struct d3dx_recorded_parameter
*)(block
->buffer
+ block
->offset
);
1309 *record
= new_record
;
1310 block
->offset
= new_size
;
1314 static void set_dirty(struct d3dx_parameter
*param
)
1316 struct d3dx_shared_data
*shared_data
;
1317 struct d3dx_top_level_parameter
*top_param
= param
->top_level_param
;
1318 ULONG64 new_update_version
= next_update_version(top_param
->version_counter
);
1320 if ((shared_data
= top_param
->shared_data
))
1321 shared_data
->update_version
= new_update_version
;
1323 top_param
->update_version
= new_update_version
;
1326 static void *param_get_data_and_dirtify(struct d3dx_effect
*effect
, struct d3dx_parameter
*param
,
1327 unsigned int bytes
, BOOL value_changed
)
1329 assert(bytes
<= param
->bytes
);
1331 if (value_changed
&& !effect
->current_parameter_block
)
1334 return effect
->current_parameter_block
? record_parameter(effect
, param
, bytes
) : param
->data
;
1337 static void d3dx9_set_light_parameter(enum LIGHT_TYPE op
, D3DLIGHT9
*light
, void *value
)
1341 unsigned int offset
;
1346 {FIELD_OFFSET(D3DLIGHT9
, Type
), "LC_TYPE"},
1347 {FIELD_OFFSET(D3DLIGHT9
, Diffuse
), "LT_DIFFUSE"},
1348 {FIELD_OFFSET(D3DLIGHT9
, Specular
), "LT_SPECULAR"},
1349 {FIELD_OFFSET(D3DLIGHT9
, Ambient
), "LT_AMBIENT"},
1350 {FIELD_OFFSET(D3DLIGHT9
, Position
), "LT_POSITION"},
1351 {FIELD_OFFSET(D3DLIGHT9
, Direction
), "LT_DIRECTION"},
1352 {FIELD_OFFSET(D3DLIGHT9
, Range
), "LT_RANGE"},
1353 {FIELD_OFFSET(D3DLIGHT9
, Falloff
), "LT_FALLOFF"},
1354 {FIELD_OFFSET(D3DLIGHT9
, Attenuation0
), "LT_ATTENUATION0"},
1355 {FIELD_OFFSET(D3DLIGHT9
, Attenuation1
), "LT_ATTENUATION1"},
1356 {FIELD_OFFSET(D3DLIGHT9
, Attenuation2
), "LT_ATTENUATION2"},
1357 {FIELD_OFFSET(D3DLIGHT9
, Theta
), "LT_THETA"},
1358 {FIELD_OFFSET(D3DLIGHT9
, Phi
), "LT_PHI"}
1363 TRACE("LT_TYPE %u.\n", *(D3DLIGHTTYPE
*)value
);
1364 light
->Type
= *(D3DLIGHTTYPE
*)value
;
1370 D3DCOLORVALUE c
= *(D3DCOLORVALUE
*)value
;
1372 TRACE("%s (%.8e %.8e %.8e %.8e).\n", light_tbl
[op
].name
, c
.r
, c
.g
, c
.b
, c
.a
);
1373 *(D3DCOLORVALUE
*)((BYTE
*)light
+ light_tbl
[op
].offset
) = c
;
1379 D3DVECTOR v
= *(D3DVECTOR
*)value
;
1381 TRACE("%s (%.8e %.8e %.8e).\n", light_tbl
[op
].name
, v
.x
, v
.y
, v
.z
);
1382 *(D3DVECTOR
*)((BYTE
*)light
+ light_tbl
[op
].offset
) = v
;
1387 case LT_ATTENUATION0
:
1388 case LT_ATTENUATION1
:
1389 case LT_ATTENUATION2
:
1393 float v
= *(float *)value
;
1394 TRACE("%s %.8e.\n", light_tbl
[op
].name
, v
);
1395 *(float *)((BYTE
*)light
+ light_tbl
[op
].offset
) = v
;
1399 WARN("Unknown light parameter %u.\n", op
);
1404 static void d3dx9_set_material_parameter(enum MATERIAL_TYPE op
, D3DMATERIAL9
*material
, void *value
)
1408 unsigned int offset
;
1413 {FIELD_OFFSET(D3DMATERIAL9
, Diffuse
), "MT_DIFFUSE"},
1414 {FIELD_OFFSET(D3DMATERIAL9
, Ambient
), "MT_AMBIENT"},
1415 {FIELD_OFFSET(D3DMATERIAL9
, Specular
), "MT_SPECULAR"},
1416 {FIELD_OFFSET(D3DMATERIAL9
, Emissive
), "MT_EMISSIVE"},
1417 {FIELD_OFFSET(D3DMATERIAL9
, Power
), "MT_POWER"}
1424 float v
= *(float *)value
;
1426 TRACE("%s %.8e.\n", material_tbl
[op
].name
, v
);
1427 material
->Power
= v
;
1435 D3DCOLORVALUE c
= *(D3DCOLORVALUE
*)value
;
1437 TRACE("%s, value (%.8e %.8e %.8e %.8e).\n", material_tbl
[op
].name
, c
.r
, c
.g
, c
.b
, c
.a
);
1438 *(D3DCOLORVALUE
*)((BYTE
*)material
+ material_tbl
[op
].offset
) = c
;
1442 WARN("Unknown material parameter %u.\n", op
);
1447 static HRESULT
d3dx_set_shader_const_state(struct d3dx_effect
*effect
, enum SHADER_CONSTANT_TYPE op
, UINT index
,
1448 struct d3dx_parameter
*param
, void *value_ptr
)
1452 D3DXPARAMETER_TYPE type
;
1458 {D3DXPT_FLOAT
, sizeof(float) * 4, "SCT_VSFLOAT"},
1459 {D3DXPT_BOOL
, sizeof(BOOL
), "SCT_VSBOOL"},
1460 {D3DXPT_INT
, sizeof(int) * 4, "SCT_VSINT"},
1461 {D3DXPT_FLOAT
, sizeof(float) * 4, "SCT_PSFLOAT"},
1462 {D3DXPT_BOOL
, sizeof(BOOL
), "SCT_PSBOOL"},
1463 {D3DXPT_INT
, sizeof(int) * 4, "SCT_PSINT"},
1466 BOOL is_heap_buffer
= FALSE
;
1467 unsigned int element_count
;
1468 void *buffer
= value_ptr
;
1472 assert(op
< ARRAY_SIZE(const_tbl
));
1473 element_count
= param
->bytes
/ const_tbl
[op
].elem_size
;
1474 TRACE("%s, index %u, element_count %u.\n", const_tbl
[op
].name
, index
, element_count
);
1475 if (param
->type
!= const_tbl
[op
].type
)
1477 FIXME("Unexpected param type %u.\n", param
->type
);
1478 return D3DERR_INVALIDCALL
;
1481 if (param
->bytes
% const_tbl
[op
].elem_size
|| element_count
> 1)
1483 unsigned int param_data_size
;
1485 TRACE("Parameter size %u, rows %u, cols %u.\n", param
->bytes
, param
->rows
, param
->columns
);
1487 if (param
->bytes
% const_tbl
[op
].elem_size
)
1489 if (element_count
> 1)
1491 WARN("Setting %u elements.\n", element_count
);
1492 buffer
= HeapAlloc(GetProcessHeap(), 0, const_tbl
[op
].elem_size
* element_count
);
1495 ERR("Out of memory.\n");
1496 return E_OUTOFMEMORY
;
1498 is_heap_buffer
= TRUE
;
1502 assert(const_tbl
[op
].elem_size
<= sizeof(value
));
1505 param_data_size
= min(param
->bytes
, const_tbl
[op
].elem_size
);
1506 memcpy(buffer
, value_ptr
, param_data_size
);
1507 memset((unsigned char *)buffer
+ param_data_size
, 0,
1508 const_tbl
[op
].elem_size
* element_count
- param_data_size
);
1514 ret
= SET_D3D_STATE(effect
, SetVertexShaderConstantF
, index
, (const float *)buffer
, element_count
);
1517 ret
= SET_D3D_STATE(effect
, SetVertexShaderConstantB
, index
, (const BOOL
*)buffer
, element_count
);
1520 ret
= SET_D3D_STATE(effect
, SetVertexShaderConstantI
, index
, (const int *)buffer
, element_count
);
1523 ret
= SET_D3D_STATE(effect
, SetPixelShaderConstantF
, index
, (const float *)buffer
, element_count
);
1526 ret
= SET_D3D_STATE(effect
, SetPixelShaderConstantB
, index
, (const BOOL
*)buffer
, element_count
);
1529 ret
= SET_D3D_STATE(effect
, SetPixelShaderConstantI
, index
, (const int *)buffer
, element_count
);
1532 ret
= D3DERR_INVALIDCALL
;
1537 HeapFree(GetProcessHeap(), 0, buffer
);
1542 static HRESULT
d3dx9_apply_state(struct d3dx_effect
*effect
, struct d3dx_pass
*pass
,
1543 struct d3dx_state
*state
, unsigned int parent_index
, BOOL update_all
);
1545 static HRESULT
d3dx_set_shader_constants(struct d3dx_effect
*effect
, struct d3dx_pass
*pass
,
1546 struct d3dx_parameter
*param
, BOOL vs
, BOOL update_all
)
1549 struct d3dx_parameter
**params
;
1550 D3DXCONSTANT_DESC
*cdesc
;
1551 unsigned int parameters_count
;
1554 if (!param
->param_eval
)
1556 FIXME("param_eval structure is null.\n");
1557 return D3DERR_INVALIDCALL
;
1559 if (FAILED(hr
= d3dx_param_eval_set_shader_constants(effect
->manager
, effect
->device
,
1560 param
->param_eval
, update_all
)))
1562 params
= param
->param_eval
->shader_inputs
.inputs_param
;
1563 cdesc
= param
->param_eval
->shader_inputs
.inputs
;
1564 parameters_count
= param
->param_eval
->shader_inputs
.input_count
;
1566 for (i
= 0; i
< parameters_count
; ++i
)
1568 if (params
[i
] && params
[i
]->class == D3DXPC_OBJECT
&& is_param_type_sampler(params
[i
]->type
))
1570 struct d3dx_sampler
*sampler
;
1571 unsigned int sampler_idx
;
1573 for (sampler_idx
= 0; sampler_idx
< cdesc
[i
].RegisterCount
; ++sampler_idx
)
1575 sampler
= params
[i
]->element_count
? params
[i
]->members
[sampler_idx
].data
: params
[i
]->data
;
1576 TRACE("sampler %s, register index %u, state count %u.\n", debugstr_a(params
[i
]->name
),
1577 cdesc
[i
].RegisterIndex
, sampler
->state_count
);
1578 for (j
= 0; j
< sampler
->state_count
; ++j
)
1580 if (FAILED(hr
= d3dx9_apply_state(effect
, pass
, &sampler
->states
[j
],
1581 cdesc
[i
].RegisterIndex
+ sampler_idx
+ (vs
? D3DVERTEXTEXTURESAMPLER0
: 0),
1591 static HRESULT
d3dx9_apply_state(struct d3dx_effect
*effect
, struct d3dx_pass
*pass
,
1592 struct d3dx_state
*state
, unsigned int parent_index
, BOOL update_all
)
1594 struct d3dx_parameter
*param
;
1599 TRACE("operation %u, index %u, type %u.\n", state
->operation
, state
->index
, state
->type
);
1601 if (FAILED(hr
= d3dx9_get_param_value_ptr(pass
, state
, ¶m_value
, ¶m
,
1602 update_all
, ¶m_dirty
)))
1604 if (!update_all
&& hr
== E_FAIL
)
1606 /* Native d3dx9 returns D3D_OK from CommitChanges() involving
1607 * out of bounds array access and does not touch the affected
1609 WARN("Returning D3D_OK on out of bounds array access.\n");
1615 if (!(update_all
|| param_dirty
1616 || state_table
[state
->operation
].class == SC_VERTEXSHADER
1617 || state_table
[state
->operation
].class == SC_PIXELSHADER
1618 || state_table
[state
->operation
].class == SC_SETSAMPLER
))
1621 switch (state_table
[state
->operation
].class)
1623 case SC_RENDERSTATE
:
1624 TRACE("%s, operation %u, value %u.\n", state_table
[state
->operation
].name
,
1625 state_table
[state
->operation
].op
, *(DWORD
*)param_value
);
1626 return SET_D3D_STATE(effect
, SetRenderState
, state_table
[state
->operation
].op
, *(DWORD
*)param_value
);
1628 TRACE("%s, value %#x.\n", state_table
[state
->operation
].name
, *(DWORD
*)param_value
);
1629 return SET_D3D_STATE(effect
, SetFVF
, *(DWORD
*)param_value
);
1634 unit
= parent_index
== ~0u ? state
->index
: parent_index
;
1635 TRACE("%s, unit %u, value %p.\n", state_table
[state
->operation
].name
, unit
,
1636 *(IDirect3DBaseTexture9
**)param_value
);
1637 return SET_D3D_STATE(effect
, SetTexture
, unit
, *(IDirect3DBaseTexture9
**)param_value
);
1639 case SC_TEXTURESTAGE
:
1640 TRACE("%s, stage %u, value %u.\n", state_table
[state
->operation
].name
, state
->index
, *(DWORD
*)param_value
);
1641 return SET_D3D_STATE(effect
, SetTextureStageState
, state
->index
,
1642 state_table
[state
->operation
].op
, *(DWORD
*)param_value
);
1645 struct d3dx_sampler
*sampler
;
1649 sampler
= (struct d3dx_sampler
*)param_value
;
1650 TRACE("%s, sampler %u, applying %u states.\n", state_table
[state
->operation
].name
, state
->index
,
1651 sampler
->state_count
);
1653 for (i
= 0; i
< sampler
->state_count
; i
++)
1655 if (FAILED(hr
= d3dx9_apply_state(effect
, pass
, &sampler
->states
[i
], state
->index
, update_all
)))
1660 case SC_SAMPLERSTATE
:
1664 sampler
= parent_index
== ~0u ? state
->index
: parent_index
;
1665 TRACE("%s, sampler %u, value %u.\n", state_table
[state
->operation
].name
, sampler
, *(DWORD
*)param_value
);
1666 return SET_D3D_STATE(effect
, SetSamplerState
, sampler
, state_table
[state
->operation
].op
,
1667 *(DWORD
*)param_value
);
1669 case SC_VERTEXSHADER
:
1670 TRACE("%s, shader %p.\n", state_table
[state
->operation
].name
, *(IDirect3DVertexShader9
**)param_value
);
1671 if ((update_all
|| param_dirty
)
1672 && FAILED(hr
= SET_D3D_STATE(effect
, SetVertexShader
,
1673 *(IDirect3DVertexShader9
**)param_value
)))
1674 ERR("Could not set vertex shader, hr %#x.\n", hr
);
1675 else if (*(IDirect3DVertexShader9
**)param_value
)
1676 hr
= d3dx_set_shader_constants(effect
, pass
, param
, TRUE
, update_all
|| param_dirty
);
1678 case SC_PIXELSHADER
:
1679 TRACE("%s, shader %p.\n", state_table
[state
->operation
].name
, *(IDirect3DPixelShader9
**)param_value
);
1680 if ((update_all
|| param_dirty
)
1681 && FAILED(hr
= SET_D3D_STATE(effect
, SetPixelShader
,
1682 *(IDirect3DPixelShader9
**)param_value
)))
1683 ERR("Could not set pixel shader, hr %#x.\n", hr
);
1684 else if (*(IDirect3DPixelShader9
**)param_value
)
1685 hr
= d3dx_set_shader_constants(effect
, pass
, param
, FALSE
, update_all
|| param_dirty
);
1688 TRACE("%s, state %u.\n", state_table
[state
->operation
].name
, state
->index
);
1689 return SET_D3D_STATE(effect
, SetTransform
, state_table
[state
->operation
].op
+ state
->index
,
1690 (D3DMATRIX
*)param_value
);
1691 case SC_LIGHTENABLE
:
1692 TRACE("%s, index %u, value %u.\n", state_table
[state
->operation
].name
, state
->index
, *(BOOL
*)param_value
);
1693 return SET_D3D_STATE(effect
, LightEnable
, state
->index
, *(BOOL
*)param_value
);
1696 TRACE("%s, index %u, op %u.\n", state_table
[state
->operation
].name
, state
->index
,
1697 state_table
[state
->operation
].op
);
1698 d3dx9_set_light_parameter(state_table
[state
->operation
].op
,
1699 &effect
->current_light
[state
->index
], param_value
);
1700 effect
->light_updated
|= 1u << state
->index
;
1705 TRACE("%s, index %u, op %u.\n", state_table
[state
->operation
].name
, state
->index
,
1706 state_table
[state
->operation
].op
);
1707 d3dx9_set_material_parameter(state_table
[state
->operation
].op
,
1708 &effect
->current_material
, param_value
);
1709 effect
->material_updated
= TRUE
;
1713 TRACE("%s, nsegments %f.\n", state_table
[state
->operation
].name
, *(float *)param_value
);
1714 return SET_D3D_STATE(effect
, SetNPatchMode
, *(float *)param_value
);
1715 case SC_SHADERCONST
:
1716 TRACE("%s, index %u, op %u.\n", state_table
[state
->operation
].name
, state
->index
,
1717 state_table
[state
->operation
].op
);
1718 return d3dx_set_shader_const_state(effect
, state_table
[state
->operation
].op
, state
->index
,
1719 param
, param_value
);
1721 FIXME("%s not handled.\n", state_table
[state
->operation
].name
);
1727 static HRESULT
d3dx9_apply_pass_states(struct d3dx_effect
*effect
, struct d3dx_pass
*pass
, BOOL update_all
)
1732 ULONG64 new_update_version
= next_effect_update_version(effect
);
1734 TRACE("effect %p, pass %p, state_count %u.\n", effect
, pass
, pass
->state_count
);
1737 for (i
= 0; i
< pass
->state_count
; ++i
)
1739 if (FAILED(hr
= d3dx9_apply_state(effect
, pass
, &pass
->states
[i
], ~0u, update_all
)))
1741 WARN("Error applying state, hr %#x.\n", hr
);
1746 if (effect
->light_updated
)
1748 for (i
= 0; i
< ARRAY_SIZE(effect
->current_light
); ++i
)
1750 if ((effect
->light_updated
& (1u << i
))
1751 && FAILED(hr
= SET_D3D_STATE(effect
, SetLight
, i
, &effect
->current_light
[i
])))
1753 WARN("Error setting light, hr %#x.\n", hr
);
1757 effect
->light_updated
= 0;
1760 if (effect
->material_updated
1761 && FAILED(hr
= SET_D3D_STATE(effect
, SetMaterial
, &effect
->current_material
)))
1763 WARN("Error setting material, hr %#x.\n", hr
);
1766 effect
->material_updated
= FALSE
;
1768 pass
->update_version
= new_update_version
;
1772 static void param_set_data_pointer(struct d3dx_parameter
*param
, unsigned char *data
, BOOL child
, BOOL free_data
)
1774 unsigned char *member_data
= data
;
1775 unsigned int i
, count
;
1777 count
= param
->element_count
? param
->element_count
: param
->member_count
;
1778 for (i
= 0; i
< count
; ++i
)
1780 param_set_data_pointer(¶m
->members
[i
], member_data
, TRUE
, free_data
);
1782 member_data
+= param
->members
[i
].bytes
;
1785 free_parameter_data(param
, child
);
1789 static BOOL
is_same_parameter(void *param1_
, struct d3dx_parameter
*param2
)
1791 struct d3dx_parameter
*param1
= (struct d3dx_parameter
*)param1_
;
1793 unsigned int i
, member_count
;
1795 matches
= !strcmp(param1
->name
, param2
->name
) && param1
->class == param2
->class
1796 && param1
->type
== param2
->type
&& param1
->rows
== param2
->rows
1797 && param1
->columns
== param2
->columns
&& param1
->element_count
== param2
->element_count
1798 && param1
->member_count
== param2
->member_count
;
1800 member_count
= param1
->element_count
? param1
->element_count
: param1
->member_count
;
1802 if (!matches
|| !member_count
)
1805 for (i
= 0; i
< member_count
; ++i
)
1807 if (!is_same_parameter(¶m1
->members
[i
], ¶m2
->members
[i
]))
1813 static HRESULT
d3dx_pool_sync_shared_parameter(struct d3dx_effect_pool
*pool
, struct d3dx_top_level_parameter
*param
)
1815 unsigned int i
, free_entry_index
;
1816 unsigned int new_size
, new_count
;
1818 if (!(param
->param
.flags
& PARAMETER_FLAG_SHARED
) || !pool
|| is_param_type_sampler(param
->param
.type
))
1821 free_entry_index
= pool
->size
;
1822 for (i
= 0; i
< pool
->size
; ++i
)
1824 if (!pool
->shared_data
[i
].count
)
1825 free_entry_index
= i
;
1826 else if (is_same_parameter(¶m
->param
, &pool
->shared_data
[i
].parameters
[0]->param
))
1829 if (i
== pool
->size
)
1831 i
= free_entry_index
;
1832 if (i
== pool
->size
)
1834 struct d3dx_shared_data
*new_alloc
;
1838 new_size
= INITIAL_POOL_SIZE
;
1839 new_alloc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1840 sizeof(*pool
->shared_data
) * new_size
);
1843 ERR("Out of memory.\n");
1844 return E_OUTOFMEMORY
;
1849 new_size
= pool
->size
* 2;
1850 new_alloc
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, pool
->shared_data
,
1851 sizeof(*pool
->shared_data
) * new_size
);
1854 ERR("Out of memory.\n");
1855 return E_OUTOFMEMORY
;
1857 if (new_alloc
!= pool
->shared_data
)
1861 for (j
= 0; j
< pool
->size
; ++j
)
1862 for (k
= 0; k
< new_alloc
[j
].count
; ++k
)
1863 new_alloc
[j
].parameters
[k
]->shared_data
= &new_alloc
[j
];
1866 pool
->shared_data
= new_alloc
;
1867 pool
->size
= new_size
;
1869 pool
->shared_data
[i
].data
= param
->param
.data
;
1873 param_set_data_pointer(¶m
->param
, pool
->shared_data
[i
].data
, FALSE
, TRUE
);
1875 new_count
= ++pool
->shared_data
[i
].count
;
1876 if (new_count
>= pool
->shared_data
[i
].size
)
1878 if (!pool
->shared_data
[i
].size
)
1880 new_size
= INITIAL_SHARED_DATA_SIZE
;
1881 pool
->shared_data
[i
].parameters
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1882 sizeof(*pool
->shared_data
[i
].parameters
) * INITIAL_SHARED_DATA_SIZE
);
1886 new_size
= pool
->shared_data
[i
].size
* 2;
1887 pool
->shared_data
[i
].parameters
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1888 pool
->shared_data
[i
].parameters
,
1889 sizeof(*pool
->shared_data
[i
].parameters
) * new_size
);
1891 pool
->shared_data
[i
].size
= new_size
;
1894 param
->shared_data
= &pool
->shared_data
[i
];
1895 pool
->shared_data
[i
].parameters
[new_count
- 1] = param
;
1897 TRACE("name %s, parameter idx %u, new refcount %u.\n", debugstr_a(param
->param
.name
), i
,
1903 static BOOL
param_zero_data_func(void *dummy
, struct d3dx_parameter
*param
)
1909 static void d3dx_pool_release_shared_parameter(struct d3dx_top_level_parameter
*param
)
1911 unsigned int new_count
;
1913 if (!(param
->param
.flags
& PARAMETER_FLAG_SHARED
) || !param
->shared_data
)
1915 new_count
= --param
->shared_data
->count
;
1917 TRACE("param %p, param->shared_data %p, new_count %d.\n", param
, param
->shared_data
, new_count
);
1923 for (i
= 0; i
< new_count
; ++i
)
1925 if (param
->shared_data
->parameters
[i
] == param
)
1927 memmove(¶m
->shared_data
->parameters
[i
],
1928 ¶m
->shared_data
->parameters
[i
+ 1],
1929 sizeof(param
->shared_data
->parameters
[i
]) * (new_count
- i
));
1933 walk_parameter_tree(¶m
->param
, param_zero_data_func
, NULL
);
1937 HeapFree(GetProcessHeap(), 0, param
->shared_data
->parameters
);
1938 /* Zeroing table size is required as the entry in pool parameters table can be reused. */
1939 param
->shared_data
->size
= 0;
1940 param
->shared_data
= NULL
;
1944 static inline struct d3dx_effect_pool
*impl_from_ID3DXEffectPool(ID3DXEffectPool
*iface
)
1946 return CONTAINING_RECORD(iface
, struct d3dx_effect_pool
, ID3DXEffectPool_iface
);
1949 static inline struct d3dx_effect_pool
*unsafe_impl_from_ID3DXEffectPool(ID3DXEffectPool
*iface
);
1951 static inline struct d3dx_effect
*impl_from_ID3DXEffect(ID3DXEffect
*iface
)
1953 return CONTAINING_RECORD(iface
, struct d3dx_effect
, ID3DXEffect_iface
);
1956 /*** IUnknown methods ***/
1957 static HRESULT WINAPI
d3dx_effect_QueryInterface(ID3DXEffect
*iface
, REFIID riid
, void **object
)
1959 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), object
);
1961 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
1962 IsEqualGUID(riid
, &IID_ID3DXEffect
))
1964 iface
->lpVtbl
->AddRef(iface
);
1969 ERR("Interface %s not found\n", debugstr_guid(riid
));
1971 return E_NOINTERFACE
;
1974 static ULONG WINAPI
d3dx_effect_AddRef(ID3DXEffect
*iface
)
1976 struct d3dx_effect
*This
= impl_from_ID3DXEffect(iface
);
1978 TRACE("(%p)->(): AddRef from %u\n", This
, This
->ref
);
1980 return InterlockedIncrement(&This
->ref
);
1983 static ULONG WINAPI
d3dx_effect_Release(ID3DXEffect
*iface
)
1985 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
1986 ULONG refcount
= InterlockedDecrement(&effect
->ref
);
1988 TRACE("%p decreasing refcount to %u.\n", effect
, refcount
);
1991 d3dx_effect_cleanup(effect
);
1996 /*** ID3DXBaseEffect methods ***/
1997 static HRESULT WINAPI
d3dx_effect_GetDesc(ID3DXEffect
*iface
, D3DXEFFECT_DESC
*desc
)
1999 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2001 FIXME("iface %p, desc %p partial stub.\n", iface
, desc
);
2005 WARN("Invalid argument specified.\n");
2006 return D3DERR_INVALIDCALL
;
2009 /* TODO: add creator and function count. */
2010 desc
->Creator
= NULL
;
2011 desc
->Functions
= 0;
2012 desc
->Parameters
= effect
->parameter_count
;
2013 desc
->Techniques
= effect
->technique_count
;
2018 static HRESULT WINAPI
d3dx_effect_GetParameterDesc(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
2019 D3DXPARAMETER_DESC
*desc
)
2021 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2022 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2024 TRACE("iface %p, parameter %p, desc %p.\n", iface
, parameter
, desc
);
2026 if (!desc
|| !param
)
2028 WARN("Invalid argument specified.\n");
2029 return D3DERR_INVALIDCALL
;
2032 desc
->Name
= param
->name
;
2033 desc
->Semantic
= param
->semantic
;
2034 desc
->Class
= param
->class;
2035 desc
->Type
= param
->type
;
2036 desc
->Rows
= param
->rows
;
2037 desc
->Columns
= param
->columns
;
2038 desc
->Elements
= param
->element_count
;
2039 desc
->Annotations
= is_top_level_parameter(param
)
2040 ? top_level_parameter_from_parameter(param
)->annotation_count
: 0;
2041 desc
->StructMembers
= param
->member_count
;
2042 desc
->Flags
= param
->flags
;
2043 desc
->Bytes
= param
->bytes
;
2048 static HRESULT WINAPI
d3dx_effect_GetTechniqueDesc(ID3DXEffect
*iface
, D3DXHANDLE technique
,
2049 D3DXTECHNIQUE_DESC
*desc
)
2051 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2052 struct d3dx_technique
*tech
= technique
? get_valid_technique(effect
, technique
) : &effect
->techniques
[0];
2054 TRACE("iface %p, technique %p, desc %p.\n", iface
, technique
, desc
);
2058 WARN("Invalid argument specified.\n");
2059 return D3DERR_INVALIDCALL
;
2062 desc
->Name
= tech
->name
;
2063 desc
->Passes
= tech
->pass_count
;
2064 desc
->Annotations
= tech
->annotation_count
;
2069 static HRESULT WINAPI
d3dx_effect_GetPassDesc(ID3DXEffect
*iface
, D3DXHANDLE pass_handle
, D3DXPASS_DESC
*desc
)
2071 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2072 struct d3dx_pass
*pass
= get_valid_pass(effect
, pass_handle
);
2075 TRACE("iface %p, pass %p, desc %p.\n", iface
, pass
, desc
);
2079 WARN("Invalid argument specified.\n");
2080 return D3DERR_INVALIDCALL
;
2083 desc
->Name
= pass
->name
;
2084 desc
->Annotations
= pass
->annotation_count
;
2086 desc
->pVertexShaderFunction
= NULL
;
2087 desc
->pPixelShaderFunction
= NULL
;
2089 if (effect
->flags
& D3DXFX_NOT_CLONEABLE
)
2092 for (i
= 0; i
< pass
->state_count
; ++i
)
2094 struct d3dx_state
*state
= &pass
->states
[i
];
2096 if (state_table
[state
->operation
].class == SC_VERTEXSHADER
2097 || state_table
[state
->operation
].class == SC_PIXELSHADER
)
2099 struct d3dx_parameter
*param
;
2105 if (FAILED(hr
= d3dx9_get_param_value_ptr(pass
, &pass
->states
[i
], ¶m_value
, ¶m
,
2106 FALSE
, ¶m_dirty
)))
2109 data
= param
->object_id
? effect
->objects
[param
->object_id
].data
: NULL
;
2110 if (state_table
[state
->operation
].class == SC_VERTEXSHADER
)
2111 desc
->pVertexShaderFunction
= data
;
2113 desc
->pPixelShaderFunction
= data
;
2120 static HRESULT WINAPI
d3dx_effect_GetFunctionDesc(ID3DXEffect
*iface
, D3DXHANDLE shader
,
2121 D3DXFUNCTION_DESC
*desc
)
2123 FIXME("iface %p, shader %p, desc %p stub.\n", iface
, shader
, desc
);
2128 static D3DXHANDLE WINAPI
d3dx_effect_GetParameter(ID3DXEffect
*iface
, D3DXHANDLE parameter
, UINT index
)
2130 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2131 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2133 TRACE("iface %p, parameter %p, index %u.\n", iface
, parameter
, index
);
2137 if (index
< effect
->parameter_count
)
2139 TRACE("Returning parameter %p.\n", &effect
->parameters
[index
]);
2140 return get_parameter_handle(&effect
->parameters
[index
].param
);
2145 if (param
&& !param
->element_count
&& index
< param
->member_count
)
2147 TRACE("Returning parameter %p.\n", ¶m
->members
[index
]);
2148 return get_parameter_handle(¶m
->members
[index
]);
2152 WARN("Parameter not found.\n");
2157 static D3DXHANDLE WINAPI
d3dx_effect_GetParameterByName(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
2160 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2161 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2164 TRACE("iface %p, parameter %p, name %s.\n", iface
, parameter
, debugstr_a(name
));
2168 handle
= get_parameter_handle(param
);
2169 TRACE("Returning parameter %p.\n", handle
);
2173 handle
= get_parameter_handle(get_parameter_by_name(effect
, param
, name
));
2174 TRACE("Returning parameter %p.\n", handle
);
2179 static D3DXHANDLE WINAPI
d3dx_effect_GetParameterBySemantic(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
2180 const char *semantic
)
2182 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2183 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2184 struct d3dx_parameter
*temp_param
;
2187 TRACE("iface %p, parameter %p, semantic %s.\n", iface
, parameter
, debugstr_a(semantic
));
2191 for (i
= 0; i
< effect
->parameter_count
; ++i
)
2193 temp_param
= &effect
->parameters
[i
].param
;
2195 if (!temp_param
->semantic
)
2199 TRACE("Returning parameter %p\n", temp_param
);
2200 return get_parameter_handle(temp_param
);
2205 if (!stricmp(temp_param
->semantic
, semantic
))
2207 TRACE("Returning parameter %p\n", temp_param
);
2208 return get_parameter_handle(temp_param
);
2214 for (i
= 0; i
< param
->member_count
; ++i
)
2216 temp_param
= ¶m
->members
[i
];
2218 if (!temp_param
->semantic
)
2222 TRACE("Returning parameter %p\n", temp_param
);
2223 return get_parameter_handle(temp_param
);
2228 if (!stricmp(temp_param
->semantic
, semantic
))
2230 TRACE("Returning parameter %p\n", temp_param
);
2231 return get_parameter_handle(temp_param
);
2236 WARN("Parameter not found.\n");
2241 static D3DXHANDLE WINAPI
d3dx_effect_GetParameterElement(ID3DXEffect
*iface
, D3DXHANDLE parameter
, UINT index
)
2243 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2244 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2246 TRACE("iface %p, parameter %p, index %u.\n", iface
, parameter
, index
);
2250 if (index
< effect
->parameter_count
)
2252 TRACE("Returning parameter %p.\n", &effect
->parameters
[index
]);
2253 return get_parameter_handle(&effect
->parameters
[index
].param
);
2258 if (index
< param
->element_count
)
2260 TRACE("Returning parameter %p.\n", ¶m
->members
[index
]);
2261 return get_parameter_handle(¶m
->members
[index
]);
2265 WARN("Parameter not found.\n");
2270 static D3DXHANDLE WINAPI
d3dx_effect_GetTechnique(ID3DXEffect
*iface
, UINT index
)
2272 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2274 TRACE("iface %p, index %u.\n", iface
, index
);
2276 if (index
>= effect
->technique_count
)
2278 WARN("Invalid argument specified.\n");
2282 TRACE("Returning technique %p.\n", &effect
->techniques
[index
]);
2284 return get_technique_handle(&effect
->techniques
[index
]);
2287 static D3DXHANDLE WINAPI
d3dx_effect_GetTechniqueByName(ID3DXEffect
*iface
, const char *name
)
2289 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2290 struct d3dx_technique
*tech
= get_technique_by_name(effect
, name
);
2292 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
2296 D3DXHANDLE t
= get_technique_handle(tech
);
2297 TRACE("Returning technique %p\n", t
);
2301 WARN("Technique not found.\n");
2306 static D3DXHANDLE WINAPI
d3dx_effect_GetPass(ID3DXEffect
*iface
, D3DXHANDLE technique
, UINT index
)
2308 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2309 struct d3dx_technique
*tech
= get_valid_technique(effect
, technique
);
2311 TRACE("iface %p, technique %p, index %u.\n", iface
, technique
, index
);
2313 if (tech
&& index
< tech
->pass_count
)
2315 TRACE("Returning pass %p\n", &tech
->passes
[index
]);
2316 return get_pass_handle(&tech
->passes
[index
]);
2319 WARN("Pass not found.\n");
2324 static D3DXHANDLE WINAPI
d3dx_effect_GetPassByName(ID3DXEffect
*iface
, D3DXHANDLE technique
, const char *name
)
2326 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2327 struct d3dx_technique
*tech
= get_valid_technique(effect
, technique
);
2329 TRACE("iface %p, technique %p, name %s.\n", iface
, technique
, debugstr_a(name
));
2335 for (i
= 0; i
< tech
->pass_count
; ++i
)
2337 struct d3dx_pass
*pass
= &tech
->passes
[i
];
2339 if (!strcmp(pass
->name
, name
))
2341 TRACE("Returning pass %p\n", pass
);
2342 return get_pass_handle(pass
);
2347 WARN("Pass not found.\n");
2352 static D3DXHANDLE WINAPI
d3dx_effect_GetFunction(ID3DXEffect
*iface
, UINT index
)
2354 FIXME("iface %p, index %u stub.\n", iface
, index
);
2359 static D3DXHANDLE WINAPI
d3dx_effect_GetFunctionByName(ID3DXEffect
*iface
, const char *name
)
2361 FIXME("iface %p, name %s stub.\n", iface
, debugstr_a(name
));
2366 static D3DXHANDLE WINAPI
d3dx_effect_GetAnnotation(ID3DXEffect
*iface
, D3DXHANDLE object
, UINT index
)
2368 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2369 struct d3dx_parameter
*annotations
= NULL
;
2370 unsigned int annotation_count
;
2372 TRACE("iface %p, object %p, index %u.\n", iface
, object
, index
);
2374 annotation_count
= get_annotation_from_object(effect
, object
, &annotations
);
2376 if (index
< annotation_count
)
2378 TRACE("Returning parameter %p\n", &annotations
[index
]);
2379 return get_parameter_handle(&annotations
[index
]);
2382 WARN("Annotation not found.\n");
2387 static D3DXHANDLE WINAPI
d3dx_effect_GetAnnotationByName(ID3DXEffect
*iface
, D3DXHANDLE object
,
2390 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2391 struct d3dx_parameter
*annotation
= NULL
;
2392 struct d3dx_parameter
*annotations
= NULL
;
2393 unsigned int annotation_count
;
2395 TRACE("iface %p, object %p, name %s.\n", iface
, object
, debugstr_a(name
));
2399 WARN("Invalid argument specified\n");
2403 annotation_count
= get_annotation_from_object(effect
, object
, &annotations
);
2405 annotation
= get_annotation_by_name(effect
, annotation_count
, annotations
, name
);
2408 TRACE("Returning parameter %p\n", annotation
);
2409 return get_parameter_handle(annotation
);
2412 WARN("Annotation not found.\n");
2417 static HRESULT WINAPI
d3dx_effect_SetValue(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
2418 const void *data
, UINT bytes
)
2420 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2421 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2423 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface
, parameter
, data
, bytes
);
2427 WARN("Invalid parameter %p specified.\n", parameter
);
2428 return D3DERR_INVALIDCALL
;
2430 if (param
->class == D3DXPC_OBJECT
&& is_param_type_sampler(param
->type
))
2432 WARN("Parameter is a sampler, returning E_FAIL.\n");
2436 if (data
&& param
->bytes
<= bytes
)
2437 return set_value(param
, data
, bytes
, param_get_data_and_dirtify(effect
, param
, param
->bytes
, TRUE
));
2439 WARN("Invalid argument specified.\n");
2441 return D3DERR_INVALIDCALL
;
2444 static HRESULT WINAPI
d3dx_effect_GetValue(ID3DXEffect
*iface
, D3DXHANDLE parameter
, void *data
, UINT bytes
)
2446 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2447 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2449 TRACE("iface %p, parameter %p, data %p, bytes %u.\n", iface
, parameter
, data
, bytes
);
2453 WARN("Invalid parameter %p specified.\n", parameter
);
2454 return D3DERR_INVALIDCALL
;
2456 if (param
->class == D3DXPC_OBJECT
&& is_param_type_sampler(param
->type
))
2458 WARN("Parameter is a sampler, returning E_FAIL.\n");
2462 if (data
&& param
->bytes
<= bytes
)
2464 TRACE("Type %s.\n", debug_d3dxparameter_type(param
->type
));
2466 switch (param
->type
)
2475 case D3DXPT_VERTEXSHADER
:
2476 case D3DXPT_PIXELSHADER
:
2477 case D3DXPT_TEXTURE
:
2478 case D3DXPT_TEXTURE1D
:
2479 case D3DXPT_TEXTURE2D
:
2480 case D3DXPT_TEXTURE3D
:
2481 case D3DXPT_TEXTURECUBE
:
2485 for (i
= 0; i
< (param
->element_count
? param
->element_count
: 1); ++i
)
2487 IUnknown
*unk
= ((IUnknown
**)param
->data
)[i
];
2489 IUnknown_AddRef(unk
);
2495 FIXME("Unhandled type %s.\n", debug_d3dxparameter_type(param
->type
));
2499 TRACE("Copy %u bytes.\n", param
->bytes
);
2500 memcpy(data
, param
->data
, param
->bytes
);
2504 WARN("Parameter not found.\n");
2506 return D3DERR_INVALIDCALL
;
2509 static HRESULT WINAPI
d3dx_effect_SetBool(ID3DXEffect
*iface
, D3DXHANDLE parameter
, BOOL b
)
2511 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2512 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2514 TRACE("iface %p, parameter %p, b %#x.\n", iface
, parameter
, b
);
2516 if (param
&& !param
->element_count
&& param
->rows
== 1 && param
->columns
== 1)
2518 set_number(param_get_data_and_dirtify(effect
, param
, sizeof(int), TRUE
),
2519 param
->type
, &b
, D3DXPT_BOOL
);
2523 WARN("Parameter not found.\n");
2525 return D3DERR_INVALIDCALL
;
2528 static HRESULT WINAPI
d3dx_effect_GetBool(ID3DXEffect
*iface
, D3DXHANDLE parameter
, BOOL
*b
)
2530 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2531 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2533 TRACE("iface %p, parameter %p, b %p.\n", iface
, parameter
, b
);
2535 if (b
&& param
&& !param
->element_count
&& param
->rows
== 1 && param
->columns
== 1)
2537 set_number(b
, D3DXPT_BOOL
, param
->data
, param
->type
);
2538 TRACE("Returning %s\n", *b
? "TRUE" : "FALSE");
2542 WARN("Parameter not found.\n");
2544 return D3DERR_INVALIDCALL
;
2547 static HRESULT WINAPI
d3dx_effect_SetBoolArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
, const BOOL
*b
, UINT count
)
2549 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2550 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2553 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface
, parameter
, b
, count
);
2557 unsigned int i
, size
= min(count
, param
->bytes
/ sizeof(DWORD
));
2559 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
2561 switch (param
->class)
2565 case D3DXPC_MATRIX_ROWS
:
2566 data
= param_get_data_and_dirtify(effect
, param
, size
* sizeof(int), TRUE
);
2567 for (i
= 0; i
< size
; ++i
)
2569 /* don't crop the input, use D3DXPT_INT instead of D3DXPT_BOOL */
2570 set_number(data
+ i
, param
->type
, &b
[i
], D3DXPT_INT
);
2579 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
2584 WARN("Parameter not found.\n");
2586 return D3DERR_INVALIDCALL
;
2589 static HRESULT WINAPI
d3dx_effect_GetBoolArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
, BOOL
*b
, UINT count
)
2591 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2592 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2594 TRACE("iface %p, parameter %p, b %p, count %u.\n", iface
, parameter
, b
, count
);
2596 if (b
&& param
&& (param
->class == D3DXPC_SCALAR
2597 || param
->class == D3DXPC_VECTOR
2598 || param
->class == D3DXPC_MATRIX_ROWS
2599 || param
->class == D3DXPC_MATRIX_COLUMNS
))
2601 unsigned int i
, size
= min(count
, param
->bytes
/ sizeof(DWORD
));
2603 for (i
= 0; i
< size
; ++i
)
2605 set_number(&b
[i
], D3DXPT_BOOL
, (DWORD
*)param
->data
+ i
, param
->type
);
2610 WARN("Parameter not found.\n");
2612 return D3DERR_INVALIDCALL
;
2615 static HRESULT WINAPI
d3dx_effect_SetInt(ID3DXEffect
*iface
, D3DXHANDLE parameter
, INT n
)
2617 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2618 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2620 TRACE("iface %p, parameter %p, n %d.\n", iface
, parameter
, n
);
2622 if (param
&& !param
->element_count
)
2624 if (param
->rows
== 1 && param
->columns
== 1)
2628 set_number(&value
, param
->type
, &n
, D3DXPT_INT
);
2629 *(DWORD
*)param_get_data_and_dirtify(effect
, param
, sizeof(int),
2630 value
!= *(DWORD
*)param
->data
) = value
;
2634 /* Split the value if parameter is a vector with dimension 3 or 4. */
2635 if (param
->type
== D3DXPT_FLOAT
2636 && ((param
->class == D3DXPC_VECTOR
&& param
->columns
!= 2)
2637 || (param
->class == D3DXPC_MATRIX_ROWS
&& param
->rows
!= 2 && param
->columns
== 1)))
2641 TRACE("Vector fixup.\n");
2643 data
= param_get_data_and_dirtify(effect
, param
,
2644 min(4, param
->rows
* param
->columns
) * sizeof(float), TRUE
);
2646 data
[0] = ((n
& 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE
;
2647 data
[1] = ((n
& 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE
;
2648 data
[2] = (n
& 0xff) * INT_FLOAT_MULTI_INVERSE
;
2649 if (param
->rows
* param
->columns
> 3)
2650 data
[3] = ((n
& 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE
;
2656 WARN("Parameter not found.\n");
2658 return D3DERR_INVALIDCALL
;
2661 static HRESULT WINAPI
d3dx_effect_GetInt(ID3DXEffect
*iface
, D3DXHANDLE parameter
, INT
*n
)
2663 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2664 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2666 TRACE("iface %p, parameter %p, n %p.\n", iface
, parameter
, n
);
2668 if (n
&& param
&& !param
->element_count
)
2670 if (param
->columns
== 1 && param
->rows
== 1)
2672 set_number(n
, D3DXPT_INT
, param
->data
, param
->type
);
2673 TRACE("Returning %d.\n", *n
);
2677 if (param
->type
== D3DXPT_FLOAT
&&
2678 ((param
->class == D3DXPC_VECTOR
&& param
->columns
!= 2)
2679 || (param
->class == D3DXPC_MATRIX_ROWS
&& param
->rows
!= 2 && param
->columns
== 1)))
2681 TRACE("Vector fixup.\n");
2683 *n
= min(max(0.0f
, *((float *)param
->data
+ 2)), 1.0f
) * INT_FLOAT_MULTI
;
2684 *n
+= ((int)(min(max(0.0f
, *((float *)param
->data
+ 1)), 1.0f
) * INT_FLOAT_MULTI
)) << 8;
2685 *n
+= ((int)(min(max(0.0f
, *((float *)param
->data
+ 0)), 1.0f
) * INT_FLOAT_MULTI
)) << 16;
2686 if (param
->columns
* param
->rows
> 3)
2687 *n
+= ((int)(min(max(0.0f
, *((float *)param
->data
+ 3)), 1.0f
) * INT_FLOAT_MULTI
)) << 24;
2689 TRACE("Returning %d.\n", *n
);
2694 WARN("Parameter not found.\n");
2696 return D3DERR_INVALIDCALL
;
2699 static HRESULT WINAPI
d3dx_effect_SetIntArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
, const INT
*n
, UINT count
)
2701 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2702 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2705 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface
, parameter
, n
, count
);
2709 unsigned int i
, size
= min(count
, param
->bytes
/ sizeof(DWORD
));
2711 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
2713 switch (param
->class)
2717 case D3DXPC_MATRIX_ROWS
:
2718 data
= param_get_data_and_dirtify(effect
, param
, size
* sizeof(int), TRUE
);
2719 for (i
= 0; i
< size
; ++i
)
2720 set_number(data
+ i
, param
->type
, &n
[i
], D3DXPT_INT
);
2728 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
2733 WARN("Parameter not found.\n");
2735 return D3DERR_INVALIDCALL
;
2738 static HRESULT WINAPI
d3dx_effect_GetIntArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
, INT
*n
, UINT count
)
2740 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2741 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2743 TRACE("iface %p, parameter %p, n %p, count %u.\n", iface
, parameter
, n
, count
);
2745 if (n
&& param
&& (param
->class == D3DXPC_SCALAR
2746 || param
->class == D3DXPC_VECTOR
2747 || param
->class == D3DXPC_MATRIX_ROWS
2748 || param
->class == D3DXPC_MATRIX_COLUMNS
))
2750 unsigned int i
, size
= min(count
, param
->bytes
/ sizeof(DWORD
));
2752 for (i
= 0; i
< size
; ++i
)
2753 set_number(&n
[i
], D3DXPT_INT
, (DWORD
*)param
->data
+ i
, param
->type
);
2757 WARN("Parameter not found.\n");
2759 return D3DERR_INVALIDCALL
;
2762 static HRESULT WINAPI
d3dx_effect_SetFloat(ID3DXEffect
*iface
, D3DXHANDLE parameter
, float f
)
2764 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2765 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2767 TRACE("iface %p, parameter %p, f %.8e.\n", iface
, parameter
, f
);
2769 if (param
&& !param
->element_count
&& param
->rows
== 1 && param
->columns
== 1)
2773 set_number(&value
, param
->type
, &f
, D3DXPT_FLOAT
);
2774 *(DWORD
*)param_get_data_and_dirtify(effect
, param
, sizeof(float),
2775 value
!= *(DWORD
*)param
->data
) = value
;
2779 WARN("Parameter not found.\n");
2781 return D3DERR_INVALIDCALL
;
2784 static HRESULT WINAPI
d3dx_effect_GetFloat(ID3DXEffect
*iface
, D3DXHANDLE parameter
, float *f
)
2786 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2787 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2789 TRACE("iface %p, parameter %p, f %p.\n", iface
, parameter
, f
);
2791 if (f
&& param
&& !param
->element_count
&& param
->columns
== 1 && param
->rows
== 1)
2793 set_number(f
, D3DXPT_FLOAT
, (DWORD
*)param
->data
, param
->type
);
2794 TRACE("Returning %f.\n", *f
);
2798 WARN("Parameter not found.\n");
2800 return D3DERR_INVALIDCALL
;
2803 static HRESULT WINAPI
d3dx_effect_SetFloatArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
2804 const float *f
, UINT count
)
2806 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2807 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2810 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface
, parameter
, f
, count
);
2814 unsigned int i
, size
= min(count
, param
->bytes
/ sizeof(DWORD
));
2816 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
2818 switch (param
->class)
2822 case D3DXPC_MATRIX_ROWS
:
2823 data
= param_get_data_and_dirtify(effect
, param
, size
* sizeof(float), TRUE
);
2824 for (i
= 0; i
< size
; ++i
)
2825 set_number(data
+ i
, param
->type
, &f
[i
], D3DXPT_FLOAT
);
2833 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
2838 WARN("Parameter not found.\n");
2840 return D3DERR_INVALIDCALL
;
2843 static HRESULT WINAPI
d3dx_effect_GetFloatArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
, float *f
, UINT count
)
2845 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2846 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2848 TRACE("iface %p, parameter %p, f %p, count %u.\n", iface
, parameter
, f
, count
);
2850 if (f
&& param
&& (param
->class == D3DXPC_SCALAR
2851 || param
->class == D3DXPC_VECTOR
2852 || param
->class == D3DXPC_MATRIX_ROWS
2853 || param
->class == D3DXPC_MATRIX_COLUMNS
))
2855 unsigned int i
, size
= min(count
, param
->bytes
/ sizeof(DWORD
));
2857 for (i
= 0; i
< size
; ++i
)
2858 set_number(&f
[i
], D3DXPT_FLOAT
, (DWORD
*)param
->data
+ i
, param
->type
);
2862 WARN("Parameter not found.\n");
2864 return D3DERR_INVALIDCALL
;
2867 static HRESULT WINAPI
d3dx_effect_SetVector(ID3DXEffect
*iface
, D3DXHANDLE parameter
, const D3DXVECTOR4
*vector
)
2869 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2870 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2872 TRACE("iface %p, parameter %p, vector %p.\n", iface
, parameter
, vector
);
2874 if (param
&& !param
->element_count
)
2876 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
2878 switch (param
->class)
2882 if (param
->type
== D3DXPT_INT
&& param
->bytes
== 4)
2886 TRACE("INT fixup.\n");
2887 tmp
= max(min(vector
->z
, 1.0f
), 0.0f
) * INT_FLOAT_MULTI
;
2888 tmp
+= ((DWORD
)(max(min(vector
->y
, 1.0f
), 0.0f
) * INT_FLOAT_MULTI
)) << 8;
2889 tmp
+= ((DWORD
)(max(min(vector
->x
, 1.0f
), 0.0f
) * INT_FLOAT_MULTI
)) << 16;
2890 tmp
+= ((DWORD
)(max(min(vector
->w
, 1.0f
), 0.0f
) * INT_FLOAT_MULTI
)) << 24;
2892 *(int *)param_get_data_and_dirtify(effect
, param
, sizeof(int), TRUE
) = tmp
;
2895 if (param
->type
== D3DXPT_FLOAT
)
2897 memcpy(param_get_data_and_dirtify(effect
, param
, param
->columns
* sizeof(float), TRUE
),
2898 vector
, param
->columns
* sizeof(float));
2902 set_vector(param
, vector
, param_get_data_and_dirtify(effect
, param
, param
->columns
* sizeof(float), TRUE
));
2905 case D3DXPC_MATRIX_ROWS
:
2911 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
2916 WARN("Parameter not found.\n");
2918 return D3DERR_INVALIDCALL
;
2921 static HRESULT WINAPI
d3dx_effect_GetVector(ID3DXEffect
*iface
, D3DXHANDLE parameter
, D3DXVECTOR4
*vector
)
2923 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2924 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2926 TRACE("iface %p, parameter %p, vector %p.\n", iface
, parameter
, vector
);
2928 if (vector
&& param
&& !param
->element_count
)
2930 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
2932 switch (param
->class)
2936 if (param
->type
== D3DXPT_INT
&& param
->bytes
== 4)
2938 TRACE("INT fixup.\n");
2939 vector
->x
= (((*(int *)param
->data
) & 0xff0000) >> 16) * INT_FLOAT_MULTI_INVERSE
;
2940 vector
->y
= (((*(int *)param
->data
) & 0xff00) >> 8) * INT_FLOAT_MULTI_INVERSE
;
2941 vector
->z
= ((*(int *)param
->data
) & 0xff) * INT_FLOAT_MULTI_INVERSE
;
2942 vector
->w
= (((*(int *)param
->data
) & 0xff000000) >> 24) * INT_FLOAT_MULTI_INVERSE
;
2945 get_vector(param
, vector
);
2948 case D3DXPC_MATRIX_ROWS
:
2954 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
2959 WARN("Parameter not found.\n");
2961 return D3DERR_INVALIDCALL
;
2964 static HRESULT WINAPI
d3dx_effect_SetVectorArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
2965 const D3DXVECTOR4
*vector
, UINT count
)
2967 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
2968 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
2970 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface
, parameter
, vector
, count
);
2972 if (param
&& param
->element_count
&& param
->element_count
>= count
)
2977 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
2979 switch (param
->class)
2982 data
= param_get_data_and_dirtify(effect
, param
, count
* param
->columns
* sizeof(float), TRUE
);
2984 if (param
->type
== D3DXPT_FLOAT
)
2986 if (param
->columns
== 4)
2988 memcpy(data
, vector
, count
* 4 * sizeof(float));
2992 for (i
= 0; i
< count
; ++i
)
2993 memcpy((float *)data
+ param
->columns
* i
, vector
+ i
,
2994 param
->columns
* sizeof(float));
2999 for (i
= 0; i
< count
; ++i
)
3000 set_vector(¶m
->members
[i
], &vector
[i
], data
+ i
* param
->columns
* sizeof(float));
3005 case D3DXPC_MATRIX_ROWS
:
3011 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3016 WARN("Parameter not found.\n");
3018 return D3DERR_INVALIDCALL
;
3021 static HRESULT WINAPI
d3dx_effect_GetVectorArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3022 D3DXVECTOR4
*vector
, UINT count
)
3024 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3025 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3027 TRACE("iface %p, parameter %p, vector %p, count %u.\n", iface
, parameter
, vector
, count
);
3032 if (vector
&& param
&& count
<= param
->element_count
)
3036 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3038 switch (param
->class)
3041 for (i
= 0; i
< count
; ++i
)
3042 get_vector(¶m
->members
[i
], &vector
[i
]);
3046 case D3DXPC_MATRIX_ROWS
:
3052 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3057 WARN("Parameter not found.\n");
3059 return D3DERR_INVALIDCALL
;
3062 static HRESULT WINAPI
d3dx_effect_SetMatrix(ID3DXEffect
*iface
, D3DXHANDLE parameter
, const D3DXMATRIX
*matrix
)
3064 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3065 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3067 TRACE("iface %p, parameter %p, matrix %p.\n", iface
, parameter
, matrix
);
3069 if (param
&& !param
->element_count
)
3071 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3073 switch (param
->class)
3075 case D3DXPC_MATRIX_ROWS
:
3076 set_matrix(param
, matrix
, param_get_data_and_dirtify(effect
, param
,
3077 param
->rows
* param
->columns
* sizeof(float), TRUE
));
3087 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3092 WARN("Parameter not found.\n");
3094 return D3DERR_INVALIDCALL
;
3097 static HRESULT WINAPI
d3dx_effect_GetMatrix(ID3DXEffect
*iface
, D3DXHANDLE parameter
, D3DXMATRIX
*matrix
)
3099 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3100 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3102 TRACE("iface %p, parameter %p, matrix %p.\n", iface
, parameter
, matrix
);
3104 if (matrix
&& param
&& !param
->element_count
)
3106 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3108 switch (param
->class)
3110 case D3DXPC_MATRIX_ROWS
:
3111 get_matrix(param
, matrix
, FALSE
);
3121 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3126 WARN("Parameter not found.\n");
3128 return D3DERR_INVALIDCALL
;
3131 static HRESULT WINAPI
d3dx_effect_SetMatrixArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3132 const D3DXMATRIX
*matrix
, UINT count
)
3134 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3135 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3137 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3139 if (param
&& param
->element_count
>= count
)
3144 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3146 switch (param
->class)
3148 case D3DXPC_MATRIX_ROWS
:
3149 data
= param_get_data_and_dirtify(effect
, param
, count
* param
->rows
3150 * param
->columns
* sizeof(float), TRUE
);
3152 for (i
= 0; i
< count
; ++i
)
3153 set_matrix(¶m
->members
[i
], &matrix
[i
],
3154 data
+ i
* param
->rows
* param
->columns
* sizeof(float));
3165 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3170 WARN("Parameter not found.\n");
3172 return D3DERR_INVALIDCALL
;
3175 static HRESULT WINAPI
d3dx_effect_GetMatrixArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3176 D3DXMATRIX
*matrix
, UINT count
)
3178 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3179 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3181 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3186 if (matrix
&& param
&& count
<= param
->element_count
)
3190 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3192 switch (param
->class)
3194 case D3DXPC_MATRIX_ROWS
:
3195 for (i
= 0; i
< count
; ++i
)
3196 get_matrix(¶m
->members
[i
], &matrix
[i
], FALSE
);
3206 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3211 WARN("Parameter not found.\n");
3213 return D3DERR_INVALIDCALL
;
3216 static HRESULT WINAPI
d3dx_effect_SetMatrixPointerArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3217 const D3DXMATRIX
**matrix
, UINT count
)
3219 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3220 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3222 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3224 if (param
&& count
<= param
->element_count
)
3229 switch (param
->class)
3231 case D3DXPC_MATRIX_ROWS
:
3232 data
= param_get_data_and_dirtify(effect
, param
, count
* param
->rows
3233 * param
->columns
* sizeof(float), TRUE
);
3235 for (i
= 0; i
< count
; ++i
)
3236 set_matrix(¶m
->members
[i
], matrix
[i
], data
+ i
* param
->rows
3237 * param
->columns
* sizeof(float));
3247 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3252 WARN("Parameter not found.\n");
3254 return D3DERR_INVALIDCALL
;
3257 static HRESULT WINAPI
d3dx_effect_GetMatrixPointerArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3258 D3DXMATRIX
**matrix
, UINT count
)
3260 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3261 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3263 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3268 if (param
&& matrix
&& count
<= param
->element_count
)
3272 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3274 switch (param
->class)
3276 case D3DXPC_MATRIX_ROWS
:
3277 for (i
= 0; i
< count
; ++i
)
3278 get_matrix(¶m
->members
[i
], matrix
[i
], FALSE
);
3287 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3292 WARN("Parameter not found.\n");
3294 return D3DERR_INVALIDCALL
;
3297 static HRESULT WINAPI
d3dx_effect_SetMatrixTranspose(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3298 const D3DXMATRIX
*matrix
)
3300 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3301 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3303 TRACE("iface %p, parameter %p, matrix %p.\n", iface
, parameter
, matrix
);
3305 if (param
&& !param
->element_count
)
3307 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3309 switch (param
->class)
3311 case D3DXPC_MATRIX_ROWS
:
3312 set_matrix_transpose(param
, matrix
, param_get_data_and_dirtify(effect
, param
,
3313 param
->rows
* param
->columns
* sizeof(float), TRUE
));
3323 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3328 WARN("Parameter not found.\n");
3330 return D3DERR_INVALIDCALL
;
3333 static HRESULT WINAPI
d3dx_effect_GetMatrixTranspose(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3336 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3337 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3339 TRACE("iface %p, parameter %p, matrix %p.\n", iface
, parameter
, matrix
);
3341 if (matrix
&& param
&& !param
->element_count
)
3343 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3345 switch (param
->class)
3349 get_matrix(param
, matrix
, FALSE
);
3352 case D3DXPC_MATRIX_ROWS
:
3353 get_matrix(param
, matrix
, TRUE
);
3361 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3366 WARN("Parameter not found.\n");
3368 return D3DERR_INVALIDCALL
;
3371 static HRESULT WINAPI
d3dx_effect_SetMatrixTransposeArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3372 const D3DXMATRIX
*matrix
, UINT count
)
3374 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3375 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3377 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3379 if (param
&& param
->element_count
>= count
)
3384 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3386 switch (param
->class)
3388 case D3DXPC_MATRIX_ROWS
:
3389 data
= param_get_data_and_dirtify(effect
, param
, count
* param
->rows
3390 * param
->columns
* sizeof(float), TRUE
);
3392 for (i
= 0; i
< count
; ++i
)
3393 set_matrix_transpose(¶m
->members
[i
], &matrix
[i
], data
3394 + i
* param
->rows
* param
->columns
* sizeof(float));
3405 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3410 WARN("Parameter not found.\n");
3412 return D3DERR_INVALIDCALL
;
3415 static HRESULT WINAPI
d3dx_effect_GetMatrixTransposeArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3416 D3DXMATRIX
*matrix
, UINT count
)
3418 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3419 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3421 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3426 if (matrix
&& param
&& count
<= param
->element_count
)
3430 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3432 switch (param
->class)
3434 case D3DXPC_MATRIX_ROWS
:
3435 for (i
= 0; i
< count
; ++i
)
3436 get_matrix(¶m
->members
[i
], &matrix
[i
], TRUE
);
3446 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3451 WARN("Parameter not found.\n");
3453 return D3DERR_INVALIDCALL
;
3456 static HRESULT WINAPI
d3dx_effect_SetMatrixTransposePointerArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3457 const D3DXMATRIX
**matrix
, UINT count
)
3459 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3460 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3462 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3464 if (param
&& count
<= param
->element_count
)
3469 switch (param
->class)
3471 case D3DXPC_MATRIX_ROWS
:
3472 data
= param_get_data_and_dirtify(effect
, param
, count
* param
->rows
3473 * param
->columns
* sizeof(float), TRUE
);
3475 for (i
= 0; i
< count
; ++i
)
3476 set_matrix_transpose(¶m
->members
[i
], matrix
[i
], data
3477 + i
* param
->rows
* param
->columns
* sizeof(float));
3487 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3492 WARN("Parameter not found.\n");
3494 return D3DERR_INVALIDCALL
;
3497 static HRESULT WINAPI
d3dx_effect_GetMatrixTransposePointerArray(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3498 D3DXMATRIX
**matrix
, UINT count
)
3500 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3501 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3503 TRACE("iface %p, parameter %p, matrix %p, count %u.\n", iface
, parameter
, matrix
, count
);
3508 if (matrix
&& param
&& count
<= param
->element_count
)
3512 TRACE("Class %s.\n", debug_d3dxparameter_class(param
->class));
3514 switch (param
->class)
3516 case D3DXPC_MATRIX_ROWS
:
3517 for (i
= 0; i
< count
; ++i
)
3518 get_matrix(¶m
->members
[i
], matrix
[i
], TRUE
);
3527 FIXME("Unhandled class %s.\n", debug_d3dxparameter_class(param
->class));
3532 WARN("Parameter not found.\n");
3534 return D3DERR_INVALIDCALL
;
3537 static HRESULT WINAPI
d3dx_effect_SetString(ID3DXEffect
*iface
, D3DXHANDLE parameter
, const char *string
)
3539 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3540 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3542 TRACE("iface %p, parameter %p, string %s.\n", iface
, parameter
, debugstr_a(string
));
3544 if (param
&& param
->type
== D3DXPT_STRING
)
3545 return set_string(param_get_data_and_dirtify(effect
, param
, sizeof(void *), TRUE
), string
);
3547 WARN("Parameter not found.\n");
3549 return D3DERR_INVALIDCALL
;
3552 static HRESULT WINAPI
d3dx_effect_GetString(ID3DXEffect
*iface
, D3DXHANDLE parameter
, const char **string
)
3554 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3555 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3557 TRACE("iface %p, parameter %p, string %p.\n", iface
, parameter
, string
);
3559 if (string
&& param
&& !param
->element_count
&& param
->type
== D3DXPT_STRING
)
3561 *string
= *(const char **)param
->data
;
3562 TRACE("Returning %s.\n", debugstr_a(*string
));
3566 WARN("Parameter not found.\n");
3568 return D3DERR_INVALIDCALL
;
3571 static HRESULT WINAPI
d3dx_effect_SetTexture(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3572 IDirect3DBaseTexture9
*texture
)
3574 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3575 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3577 TRACE("iface %p, parameter %p, texture %p.\n", iface
, parameter
, texture
);
3579 if (param
&& !param
->element_count
3580 && (param
->type
== D3DXPT_TEXTURE
|| param
->type
== D3DXPT_TEXTURE1D
3581 || param
->type
== D3DXPT_TEXTURE2D
|| param
->type
== D3DXPT_TEXTURE3D
3582 || param
->type
== D3DXPT_TEXTURECUBE
))
3584 IDirect3DBaseTexture9
**data
= param_get_data_and_dirtify(effect
, param
,
3585 sizeof(void *), texture
!= *(IDirect3DBaseTexture9
**)param
->data
);
3586 IDirect3DBaseTexture9
*old_texture
= *data
;
3590 if (texture
== old_texture
)
3594 IDirect3DBaseTexture9_AddRef(texture
);
3596 IDirect3DBaseTexture9_Release(old_texture
);
3601 WARN("Parameter not found.\n");
3603 return D3DERR_INVALIDCALL
;
3606 static HRESULT WINAPI
d3dx_effect_GetTexture(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3607 IDirect3DBaseTexture9
**texture
)
3609 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3610 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3612 TRACE("iface %p, parameter %p, texture %p.\n", iface
, parameter
, texture
);
3614 if (texture
&& param
&& !param
->element_count
3615 && (param
->type
== D3DXPT_TEXTURE
|| param
->type
== D3DXPT_TEXTURE1D
3616 || param
->type
== D3DXPT_TEXTURE2D
|| param
->type
== D3DXPT_TEXTURE3D
3617 || param
->type
== D3DXPT_TEXTURECUBE
))
3619 *texture
= *(IDirect3DBaseTexture9
**)param
->data
;
3621 IDirect3DBaseTexture9_AddRef(*texture
);
3622 TRACE("Returning %p.\n", *texture
);
3626 WARN("Parameter not found.\n");
3628 return D3DERR_INVALIDCALL
;
3631 static HRESULT WINAPI
d3dx_effect_GetPixelShader(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3632 IDirect3DPixelShader9
**shader
)
3634 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3635 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3637 TRACE("iface %p, parameter %p, shader %p.\n", iface
, parameter
, shader
);
3639 if (shader
&& param
&& !param
->element_count
&& param
->type
== D3DXPT_PIXELSHADER
)
3641 if ((*shader
= *(IDirect3DPixelShader9
**)param
->data
))
3642 IDirect3DPixelShader9_AddRef(*shader
);
3643 TRACE("Returning %p.\n", *shader
);
3647 WARN("Parameter not found.\n");
3649 return D3DERR_INVALIDCALL
;
3652 static HRESULT WINAPI
d3dx_effect_GetVertexShader(ID3DXEffect
*iface
, D3DXHANDLE parameter
,
3653 IDirect3DVertexShader9
**shader
)
3655 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3656 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3658 TRACE("iface %p, parameter %p, shader %p.\n", iface
, parameter
, shader
);
3660 if (shader
&& param
&& !param
->element_count
&& param
->type
== D3DXPT_VERTEXSHADER
)
3662 if ((*shader
= *(IDirect3DVertexShader9
**)param
->data
))
3663 IDirect3DVertexShader9_AddRef(*shader
);
3664 TRACE("Returning %p.\n", *shader
);
3668 WARN("Parameter not found.\n");
3670 return D3DERR_INVALIDCALL
;
3673 static HRESULT WINAPI
d3dx_effect_SetArrayRange(ID3DXEffect
*iface
, D3DXHANDLE parameter
, UINT start
, UINT end
)
3675 FIXME("iface %p, parameter %p, start %u, end %u stub.\n", iface
, parameter
, start
, end
);
3680 /*** ID3DXEffect methods ***/
3681 static HRESULT WINAPI
d3dx_effect_GetPool(ID3DXEffect
*iface
, ID3DXEffectPool
**pool
)
3683 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3685 TRACE("iface %p, pool %p.\n", effect
, pool
);
3689 WARN("Invalid argument supplied.\n");
3690 return D3DERR_INVALIDCALL
;
3696 *pool
= &effect
->pool
->ID3DXEffectPool_iface
;
3697 (*pool
)->lpVtbl
->AddRef(*pool
);
3700 TRACE("Returning pool %p.\n", *pool
);
3705 static HRESULT WINAPI
d3dx_effect_SetTechnique(ID3DXEffect
*iface
, D3DXHANDLE technique
)
3707 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3708 struct d3dx_technique
*tech
= get_valid_technique(effect
, technique
);
3710 TRACE("iface %p, technique %p\n", iface
, technique
);
3714 effect
->active_technique
= tech
;
3715 TRACE("Technique %p\n", tech
);
3719 WARN("Technique not found.\n");
3721 return D3DERR_INVALIDCALL
;
3724 static D3DXHANDLE WINAPI
d3dx_effect_GetCurrentTechnique(ID3DXEffect
*iface
)
3726 struct d3dx_effect
*This
= impl_from_ID3DXEffect(iface
);
3728 TRACE("iface %p\n", This
);
3730 return get_technique_handle(This
->active_technique
);
3733 static HRESULT WINAPI
d3dx_effect_ValidateTechnique(ID3DXEffect
*iface
, D3DXHANDLE technique
)
3735 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3736 struct d3dx_technique
*tech
= get_valid_technique(effect
, technique
);
3737 HRESULT ret
= D3D_OK
;
3740 FIXME("iface %p, technique %p semi-stub.\n", iface
, technique
);
3744 ret
= D3DERR_INVALIDCALL
;
3747 for (i
= 0; i
< tech
->pass_count
; ++i
)
3749 struct d3dx_pass
*pass
= &tech
->passes
[i
];
3751 for (j
= 0; j
< pass
->state_count
; ++j
)
3753 struct d3dx_state
*state
= &pass
->states
[j
];
3755 if (state_table
[state
->operation
].class == SC_VERTEXSHADER
3756 || state_table
[state
->operation
].class == SC_PIXELSHADER
)
3758 struct d3dx_parameter
*param
;
3763 if (FAILED(hr
= d3dx9_get_param_value_ptr(pass
, &pass
->states
[j
], ¶m_value
, ¶m
,
3764 FALSE
, ¶m_dirty
)))
3767 if (param
->object_id
&& effect
->objects
[param
->object_id
].creation_failed
)
3776 TRACE("Returning %#x.\n", ret
);
3780 static HRESULT WINAPI
d3dx_effect_FindNextValidTechnique(ID3DXEffect
*iface
, D3DXHANDLE technique
,
3781 D3DXHANDLE
*next_technique
)
3783 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3784 struct d3dx_technique
*prev_tech
, *tech
;
3787 TRACE("iface %p, technique %p, next_technique %p.\n", iface
, technique
, next_technique
);
3791 if (!(prev_tech
= get_valid_technique(effect
, technique
)))
3792 return D3DERR_INVALIDCALL
;
3794 for (i
= 0; i
< effect
->technique_count
; ++i
)
3796 tech
= &effect
->techniques
[i
];
3797 if (tech
== prev_tech
)
3809 for (; i
< effect
->technique_count
; ++i
)
3811 tech
= &effect
->techniques
[i
];
3812 if (SUCCEEDED(d3dx_effect_ValidateTechnique(iface
, get_technique_handle(tech
))))
3814 *next_technique
= get_technique_handle(tech
);
3819 *next_technique
= get_technique_handle(&effect
->techniques
[0]);
3823 static BOOL
walk_parameter_dep(struct d3dx_parameter
*param
, walk_parameter_dep_func param_func
,
3826 static BOOL
walk_param_eval_dep(struct d3dx_param_eval
*param_eval
, walk_parameter_dep_func param_func
,
3829 struct d3dx_parameter
**params
;
3830 unsigned int i
, param_count
;
3835 params
= param_eval
->shader_inputs
.inputs_param
;
3836 param_count
= param_eval
->shader_inputs
.input_count
;
3837 for (i
= 0; i
< param_count
; ++i
)
3839 if (walk_parameter_dep(params
[i
], param_func
, data
))
3843 params
= param_eval
->pres
.inputs
.inputs_param
;
3844 param_count
= param_eval
->pres
.inputs
.input_count
;
3845 for (i
= 0; i
< param_count
; ++i
)
3847 if (walk_parameter_dep(params
[i
], param_func
, data
))
3853 static BOOL
walk_state_dep(struct d3dx_state
*state
, walk_parameter_dep_func param_func
,
3856 if (state
->type
== ST_CONSTANT
&& is_param_type_sampler(state
->parameter
.type
))
3858 if (walk_parameter_dep(&state
->parameter
, param_func
, data
))
3861 else if (state
->type
== ST_ARRAY_SELECTOR
|| state
->type
== ST_PARAMETER
)
3863 if (walk_parameter_dep(state
->referenced_param
, param_func
, data
))
3866 return walk_param_eval_dep(state
->parameter
.param_eval
, param_func
, data
);
3869 static BOOL
walk_parameter_dep(struct d3dx_parameter
*param
, walk_parameter_dep_func param_func
,
3873 unsigned int member_count
;
3875 param
= ¶m
->top_level_param
->param
;
3876 if (param_func(data
, param
))
3879 if (walk_param_eval_dep(param
->param_eval
, param_func
, data
))
3882 if (param
->class == D3DXPC_OBJECT
&& is_param_type_sampler(param
->type
))
3884 struct d3dx_sampler
*sampler
;
3885 unsigned int sampler_idx
;
3886 unsigned int samplers_count
= max(param
->element_count
, 1);
3888 for (sampler_idx
= 0; sampler_idx
< samplers_count
; ++sampler_idx
)
3890 sampler
= param
->element_count
? param
->members
[sampler_idx
].data
: param
->data
;
3891 for (i
= 0; i
< sampler
->state_count
; ++i
)
3893 if (walk_state_dep(&sampler
->states
[i
], param_func
, data
))
3900 member_count
= param
->element_count
? param
->element_count
: param
->member_count
;
3901 for (i
= 0; i
< member_count
; ++i
)
3903 if (walk_param_eval_dep(param
->members
[i
].param_eval
, param_func
, data
))
3910 static BOOL
is_parameter_used(struct d3dx_parameter
*param
, struct d3dx_technique
*tech
)
3913 struct d3dx_pass
*pass
;
3915 if (!tech
|| !param
)
3918 for (i
= 0; i
< tech
->pass_count
; ++i
)
3920 pass
= &tech
->passes
[i
];
3921 for (j
= 0; j
< pass
->state_count
; ++j
)
3923 if (walk_state_dep(&pass
->states
[j
], is_same_parameter
, param
))
3930 static BOOL WINAPI
d3dx_effect_IsParameterUsed(ID3DXEffect
*iface
, D3DXHANDLE parameter
, D3DXHANDLE technique
)
3932 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3933 struct d3dx_parameter
*param
= get_valid_parameter(effect
, parameter
);
3934 struct d3dx_technique
*tech
= get_valid_technique(effect
, technique
);
3937 TRACE("iface %p, parameter %p, technique %p.\n", iface
, parameter
, technique
);
3938 TRACE("param %p, name %s, tech %p.\n", param
, param
? debugstr_a(param
->name
) : "", tech
);
3940 ret
= is_parameter_used(param
, tech
);
3941 TRACE("Returning %#x.\n", ret
);
3945 static HRESULT WINAPI
d3dx_effect_Begin(ID3DXEffect
*iface
, UINT
*passes
, DWORD flags
)
3947 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
3948 struct d3dx_technique
*technique
= effect
->active_technique
;
3950 TRACE("iface %p, passes %p, flags %#x.\n", iface
, passes
, flags
);
3954 if (flags
& ~(D3DXFX_DONOTSAVESTATE
| D3DXFX_DONOTSAVESAMPLERSTATE
| D3DXFX_DONOTSAVESHADERSTATE
))
3955 WARN("Invalid flags (%#x) specified.\n", flags
);
3957 if (flags
& D3DXFX_DONOTSAVESTATE
)
3959 TRACE("State capturing disabled.\n");
3966 if (!technique
->saved_state
)
3968 ID3DXEffectStateManager
*manager
;
3970 manager
= effect
->manager
;
3971 effect
->manager
= NULL
;
3972 if (FAILED(hr
= IDirect3DDevice9_BeginStateBlock(effect
->device
)))
3973 ERR("BeginStateBlock failed, hr %#x.\n", hr
);
3974 for (i
= 0; i
< technique
->pass_count
; i
++)
3975 d3dx9_apply_pass_states(effect
, &technique
->passes
[i
], TRUE
);
3976 if (FAILED(hr
= IDirect3DDevice9_EndStateBlock(effect
->device
, &technique
->saved_state
)))
3977 ERR("EndStateBlock failed, hr %#x.\n", hr
);
3978 effect
->manager
= manager
;
3980 if (FAILED(hr
= IDirect3DStateBlock9_Capture(technique
->saved_state
)))
3981 ERR("StateBlock Capture failed, hr %#x.\n", hr
);
3985 *passes
= technique
->pass_count
;
3986 effect
->started
= TRUE
;
3987 effect
->begin_flags
= flags
;
3992 WARN("Invalid argument supplied.\n");
3994 return D3DERR_INVALIDCALL
;
3997 static HRESULT WINAPI
d3dx_effect_BeginPass(ID3DXEffect
*iface
, UINT pass
)
3999 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4000 struct d3dx_technique
*technique
= effect
->active_technique
;
4002 TRACE("iface %p, pass %u\n", effect
, pass
);
4004 if (technique
&& pass
< technique
->pass_count
&& !effect
->active_pass
)
4008 memset(effect
->current_light
, 0, sizeof(effect
->current_light
));
4009 memset(&effect
->current_material
, 0, sizeof(effect
->current_material
));
4011 if (SUCCEEDED(hr
= d3dx9_apply_pass_states(effect
, &technique
->passes
[pass
], TRUE
)))
4012 effect
->active_pass
= &technique
->passes
[pass
];
4016 WARN("Invalid argument supplied.\n");
4018 return D3DERR_INVALIDCALL
;
4021 static HRESULT WINAPI
d3dx_effect_CommitChanges(ID3DXEffect
*iface
)
4023 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4025 TRACE("iface %p.\n", iface
);
4027 if (!effect
->active_pass
)
4029 WARN("Called without an active pass.\n");
4032 return d3dx9_apply_pass_states(effect
, effect
->active_pass
, FALSE
);
4035 static HRESULT WINAPI
d3dx_effect_EndPass(ID3DXEffect
*iface
)
4037 struct d3dx_effect
*This
= impl_from_ID3DXEffect(iface
);
4039 TRACE("iface %p\n", This
);
4041 if (This
->active_pass
)
4043 This
->active_pass
= NULL
;
4047 WARN("Invalid call.\n");
4049 return D3DERR_INVALIDCALL
;
4052 static HRESULT WINAPI
d3dx_effect_End(ID3DXEffect
*iface
)
4054 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4055 struct d3dx_technique
*technique
= effect
->active_technique
;
4057 TRACE("iface %p.\n", iface
);
4059 if (!effect
->started
)
4062 if (effect
->begin_flags
& D3DXFX_DONOTSAVESTATE
)
4064 TRACE("State restoring disabled.\n");
4070 if (technique
&& technique
->saved_state
)
4072 if (FAILED(hr
= IDirect3DStateBlock9_Apply(technique
->saved_state
)))
4073 ERR("State block apply failed, hr %#x.\n", hr
);
4076 ERR("No saved state.\n");
4079 effect
->started
= FALSE
;
4084 static HRESULT WINAPI
d3dx_effect_GetDevice(ID3DXEffect
*iface
, struct IDirect3DDevice9
**device
)
4086 struct d3dx_effect
*This
= impl_from_ID3DXEffect(iface
);
4088 TRACE("iface %p, device %p\n", This
, device
);
4092 WARN("Invalid argument supplied.\n");
4093 return D3DERR_INVALIDCALL
;
4096 IDirect3DDevice9_AddRef(This
->device
);
4098 *device
= This
->device
;
4100 TRACE("Returning device %p\n", *device
);
4105 static BOOL
param_on_lost_device(void *data
, struct d3dx_parameter
*param
)
4107 struct IDirect3DVolumeTexture9
*volume_texture
;
4108 struct IDirect3DCubeTexture9
*cube_texture
;
4109 struct IDirect3DTexture9
*texture
;
4110 D3DSURFACE_DESC surface_desc
;
4111 D3DVOLUME_DESC volume_desc
;
4113 if (param
->class == D3DXPC_OBJECT
&& !param
->element_count
)
4115 switch (param
->type
)
4117 case D3DXPT_TEXTURE
:
4118 case D3DXPT_TEXTURE1D
:
4119 case D3DXPT_TEXTURE2D
:
4120 texture
= *(IDirect3DTexture9
**)param
->data
;
4123 IDirect3DTexture9_GetLevelDesc(texture
, 0, &surface_desc
);
4124 if (surface_desc
.Pool
!= D3DPOOL_DEFAULT
)
4127 case D3DXPT_TEXTURE3D
:
4128 volume_texture
= *(IDirect3DVolumeTexture9
**)param
->data
;
4129 if (!volume_texture
)
4131 IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 0, &volume_desc
);
4132 if (volume_desc
.Pool
!= D3DPOOL_DEFAULT
)
4135 case D3DXPT_TEXTURECUBE
:
4136 cube_texture
= *(IDirect3DCubeTexture9
**)param
->data
;
4139 IDirect3DTexture9_GetLevelDesc(cube_texture
, 0, &surface_desc
);
4140 if (surface_desc
.Pool
!= D3DPOOL_DEFAULT
)
4146 IUnknown_Release(*(IUnknown
**)param
->data
);
4147 *(IUnknown
**)param
->data
= NULL
;
4152 static HRESULT WINAPI
d3dx_effect_OnLostDevice(ID3DXEffect
*iface
)
4154 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4157 TRACE("iface %p.\n", iface
);
4159 for (i
= 0; i
< effect
->parameter_count
; ++i
)
4160 walk_parameter_tree(&effect
->parameters
[i
].param
, param_on_lost_device
, NULL
);
4165 static HRESULT WINAPI
d3dx_effect_OnResetDevice(ID3DXEffect
*iface
)
4167 struct d3dx_effect
*This
= impl_from_ID3DXEffect(iface
);
4169 FIXME("(%p)->(): stub\n", This
);
4174 static HRESULT WINAPI
d3dx_effect_SetStateManager(ID3DXEffect
*iface
, ID3DXEffectStateManager
*manager
)
4176 struct d3dx_effect
*This
= impl_from_ID3DXEffect(iface
);
4178 TRACE("iface %p, manager %p\n", This
, manager
);
4180 if (manager
) IUnknown_AddRef(manager
);
4181 if (This
->manager
) IUnknown_Release(This
->manager
);
4183 This
->manager
= manager
;
4188 static HRESULT WINAPI
d3dx_effect_GetStateManager(ID3DXEffect
*iface
, ID3DXEffectStateManager
**manager
)
4190 struct d3dx_effect
*This
= impl_from_ID3DXEffect(iface
);
4192 TRACE("iface %p, manager %p\n", This
, manager
);
4196 WARN("Invalid argument supplied.\n");
4197 return D3DERR_INVALIDCALL
;
4200 if (This
->manager
) IUnknown_AddRef(This
->manager
);
4201 *manager
= This
->manager
;
4206 static HRESULT WINAPI
d3dx_effect_BeginParameterBlock(ID3DXEffect
*iface
)
4208 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4210 TRACE("iface %p.\n", iface
);
4212 if (effect
->current_parameter_block
)
4214 WARN("Parameter block is already started.\n");
4215 return D3DERR_INVALIDCALL
;
4218 effect
->current_parameter_block
= heap_alloc_zero(sizeof(*effect
->current_parameter_block
));
4219 memcpy(effect
->current_parameter_block
->magic_string
, parameter_block_magic_string
,
4220 sizeof(parameter_block_magic_string
));
4221 effect
->current_parameter_block
->effect
= effect
;
4226 static D3DXHANDLE WINAPI
d3dx_effect_EndParameterBlock(ID3DXEffect
*iface
)
4228 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4229 struct d3dx_parameter_block
*ret
;
4231 TRACE("iface %p.\n", iface
);
4233 if (!effect
->current_parameter_block
)
4235 WARN("No active parameter block.\n");
4238 ret
= effect
->current_parameter_block
;
4240 ret
->buffer
= heap_realloc(ret
->buffer
, ret
->offset
);
4241 ret
->size
= ret
->offset
;
4243 effect
->current_parameter_block
= NULL
;
4244 list_add_tail(&effect
->parameter_block_list
, &ret
->entry
);
4245 return (D3DXHANDLE
)ret
;
4248 static HRESULT WINAPI
d3dx_effect_ApplyParameterBlock(ID3DXEffect
*iface
, D3DXHANDLE parameter_block
)
4250 struct d3dx_parameter_block
*block
= get_valid_parameter_block(parameter_block
);
4251 struct d3dx_recorded_parameter
*record
;
4253 TRACE("iface %p, parameter_block %p.\n", iface
, parameter_block
);
4255 if (!block
|| !block
->offset
)
4256 return D3DERR_INVALIDCALL
;
4258 record
= (struct d3dx_recorded_parameter
*)block
->buffer
;
4259 while ((BYTE
*)record
< block
->buffer
+ block
->offset
)
4261 set_value(record
->param
, record
+ 1, record
->bytes
,
4262 param_get_data_and_dirtify(block
->effect
, record
->param
, record
->bytes
, TRUE
));
4263 record
= (struct d3dx_recorded_parameter
*)((BYTE
*)record
+ get_recorded_parameter_size(record
));
4265 assert((BYTE
*)record
== block
->buffer
+ block
->offset
);
4269 #if D3DX_SDK_VERSION >= 26
4270 static HRESULT WINAPI
d3dx_effect_DeleteParameterBlock(ID3DXEffect
*iface
, D3DXHANDLE parameter_block
)
4272 struct d3dx_parameter_block
*block
= get_valid_parameter_block(parameter_block
);
4273 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4274 struct d3dx_parameter_block
*b
;
4276 TRACE("iface %p, parameter_block %p.\n", iface
, parameter_block
);
4279 return D3DERR_INVALIDCALL
;
4281 LIST_FOR_EACH_ENTRY(b
, &effect
->parameter_block_list
, struct d3dx_parameter_block
, entry
)
4285 list_remove(&b
->entry
);
4286 free_parameter_block(b
);
4291 WARN("Block is not found in issued block list, not freeing memory.\n");
4292 return D3DERR_INVALIDCALL
;
4296 static HRESULT WINAPI
d3dx_effect_CloneEffect(ID3DXEffect
*iface
, IDirect3DDevice9
*device
,
4297 ID3DXEffect
**new_effect
)
4299 struct d3dx_effect
*effect
= impl_from_ID3DXEffect(iface
);
4301 FIXME("iface %p, device %p, new_effect %p stub.\n", effect
, device
, new_effect
);
4304 return D3DERR_INVALIDCALL
;
4306 if (effect
->flags
& D3DXFX_NOT_CLONEABLE
)
4310 return D3DERR_INVALIDCALL
;
4315 #if D3DX_SDK_VERSION >= 27
4316 static HRESULT WINAPI
d3dx_effect_SetRawValue(ID3DXEffect
*iface
, D3DXHANDLE parameter
, const void *data
,
4317 UINT byte_offset
, UINT bytes
)
4319 FIXME("iface %p, parameter %p, data %p, byte_offset %u, bytes %u stub!\n",
4320 iface
, parameter
, data
, byte_offset
, bytes
);
4326 static const struct ID3DXEffectVtbl ID3DXEffect_Vtbl
=
4328 /*** IUnknown methods ***/
4329 d3dx_effect_QueryInterface
,
4331 d3dx_effect_Release
,
4332 /*** ID3DXBaseEffect methods ***/
4333 d3dx_effect_GetDesc
,
4334 d3dx_effect_GetParameterDesc
,
4335 d3dx_effect_GetTechniqueDesc
,
4336 d3dx_effect_GetPassDesc
,
4337 d3dx_effect_GetFunctionDesc
,
4338 d3dx_effect_GetParameter
,
4339 d3dx_effect_GetParameterByName
,
4340 d3dx_effect_GetParameterBySemantic
,
4341 d3dx_effect_GetParameterElement
,
4342 d3dx_effect_GetTechnique
,
4343 d3dx_effect_GetTechniqueByName
,
4344 d3dx_effect_GetPass
,
4345 d3dx_effect_GetPassByName
,
4346 d3dx_effect_GetFunction
,
4347 d3dx_effect_GetFunctionByName
,
4348 d3dx_effect_GetAnnotation
,
4349 d3dx_effect_GetAnnotationByName
,
4350 d3dx_effect_SetValue
,
4351 d3dx_effect_GetValue
,
4352 d3dx_effect_SetBool
,
4353 d3dx_effect_GetBool
,
4354 d3dx_effect_SetBoolArray
,
4355 d3dx_effect_GetBoolArray
,
4358 d3dx_effect_SetIntArray
,
4359 d3dx_effect_GetIntArray
,
4360 d3dx_effect_SetFloat
,
4361 d3dx_effect_GetFloat
,
4362 d3dx_effect_SetFloatArray
,
4363 d3dx_effect_GetFloatArray
,
4364 d3dx_effect_SetVector
,
4365 d3dx_effect_GetVector
,
4366 d3dx_effect_SetVectorArray
,
4367 d3dx_effect_GetVectorArray
,
4368 d3dx_effect_SetMatrix
,
4369 d3dx_effect_GetMatrix
,
4370 d3dx_effect_SetMatrixArray
,
4371 d3dx_effect_GetMatrixArray
,
4372 d3dx_effect_SetMatrixPointerArray
,
4373 d3dx_effect_GetMatrixPointerArray
,
4374 d3dx_effect_SetMatrixTranspose
,
4375 d3dx_effect_GetMatrixTranspose
,
4376 d3dx_effect_SetMatrixTransposeArray
,
4377 d3dx_effect_GetMatrixTransposeArray
,
4378 d3dx_effect_SetMatrixTransposePointerArray
,
4379 d3dx_effect_GetMatrixTransposePointerArray
,
4380 d3dx_effect_SetString
,
4381 d3dx_effect_GetString
,
4382 d3dx_effect_SetTexture
,
4383 d3dx_effect_GetTexture
,
4384 d3dx_effect_GetPixelShader
,
4385 d3dx_effect_GetVertexShader
,
4386 d3dx_effect_SetArrayRange
,
4387 /*** ID3DXEffect methods ***/
4388 d3dx_effect_GetPool
,
4389 d3dx_effect_SetTechnique
,
4390 d3dx_effect_GetCurrentTechnique
,
4391 d3dx_effect_ValidateTechnique
,
4392 d3dx_effect_FindNextValidTechnique
,
4393 d3dx_effect_IsParameterUsed
,
4395 d3dx_effect_BeginPass
,
4396 d3dx_effect_CommitChanges
,
4397 d3dx_effect_EndPass
,
4399 d3dx_effect_GetDevice
,
4400 d3dx_effect_OnLostDevice
,
4401 d3dx_effect_OnResetDevice
,
4402 d3dx_effect_SetStateManager
,
4403 d3dx_effect_GetStateManager
,
4404 d3dx_effect_BeginParameterBlock
,
4405 d3dx_effect_EndParameterBlock
,
4406 d3dx_effect_ApplyParameterBlock
,
4407 #if D3DX_SDK_VERSION >= 26
4408 d3dx_effect_DeleteParameterBlock
,
4410 d3dx_effect_CloneEffect
,
4411 #if D3DX_SDK_VERSION >= 27
4412 d3dx_effect_SetRawValue
4416 static inline struct ID3DXEffectCompilerImpl
*impl_from_ID3DXEffectCompiler(ID3DXEffectCompiler
*iface
)
4418 return CONTAINING_RECORD(iface
, struct ID3DXEffectCompilerImpl
, ID3DXEffectCompiler_iface
);
4421 /*** IUnknown methods ***/
4422 static HRESULT WINAPI
ID3DXEffectCompilerImpl_QueryInterface(ID3DXEffectCompiler
*iface
, REFIID riid
, void **object
)
4424 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
4426 if (IsEqualGUID(riid
, &IID_IUnknown
)
4427 || IsEqualGUID(riid
, &IID_ID3DXEffectCompiler
))
4429 iface
->lpVtbl
->AddRef(iface
);
4434 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
4437 return E_NOINTERFACE
;
4440 static ULONG WINAPI
ID3DXEffectCompilerImpl_AddRef(ID3DXEffectCompiler
*iface
)
4442 struct ID3DXEffectCompilerImpl
*compiler
= impl_from_ID3DXEffectCompiler(iface
);
4443 ULONG refcount
= InterlockedIncrement(&compiler
->ref
);
4445 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
4450 static ULONG WINAPI
ID3DXEffectCompilerImpl_Release(ID3DXEffectCompiler
*iface
)
4452 struct ID3DXEffectCompilerImpl
*compiler
= impl_from_ID3DXEffectCompiler(iface
);
4453 ULONG refcount
= InterlockedDecrement(&compiler
->ref
);
4455 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
4459 heap_free(compiler
);
4465 /*** ID3DXBaseEffect methods ***/
4466 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetDesc(ID3DXEffectCompiler
*iface
, D3DXEFFECT_DESC
*desc
)
4468 FIXME("iface %p, desc %p stub!\n", iface
, desc
);
4473 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetParameterDesc(ID3DXEffectCompiler
*iface
,
4474 D3DXHANDLE parameter
, D3DXPARAMETER_DESC
*desc
)
4476 FIXME("iface %p, parameter %p, desc %p stub!\n", iface
, parameter
, desc
);
4481 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetTechniqueDesc(ID3DXEffectCompiler
*iface
,
4482 D3DXHANDLE technique
, D3DXTECHNIQUE_DESC
*desc
)
4484 FIXME("iface %p, technique %p, desc %p stub!\n", iface
, technique
, desc
);
4489 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetPassDesc(ID3DXEffectCompiler
*iface
,
4490 D3DXHANDLE pass
, D3DXPASS_DESC
*desc
)
4492 FIXME("iface %p, pass %p, desc %p stub!\n", iface
, pass
, desc
);
4497 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetFunctionDesc(ID3DXEffectCompiler
*iface
,
4498 D3DXHANDLE shader
, D3DXFUNCTION_DESC
*desc
)
4500 FIXME("iface %p, shader %p, desc %p stub!\n", iface
, shader
, desc
);
4505 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetParameter(ID3DXEffectCompiler
*iface
,
4506 D3DXHANDLE parameter
, UINT index
)
4508 FIXME("iface %p, parameter %p, index %u stub!\n", iface
, parameter
, index
);
4513 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetParameterByName(ID3DXEffectCompiler
*iface
,
4514 D3DXHANDLE parameter
, const char *name
)
4516 FIXME("iface %p, parameter %p, name %s stub!\n", iface
, parameter
, debugstr_a(name
));
4521 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetParameterBySemantic(ID3DXEffectCompiler
*iface
,
4522 D3DXHANDLE parameter
, const char *semantic
)
4524 FIXME("iface %p, parameter %p, semantic %s stub!\n", iface
, parameter
, debugstr_a(semantic
));
4529 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetParameterElement(ID3DXEffectCompiler
*iface
,
4530 D3DXHANDLE parameter
, UINT index
)
4532 FIXME("iface %p, parameter %p, index %u stub!\n", iface
, parameter
, index
);
4537 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetTechnique(ID3DXEffectCompiler
*iface
, UINT index
)
4539 FIXME("iface %p, index %u stub!\n", iface
, index
);
4544 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetTechniqueByName(ID3DXEffectCompiler
*iface
, const char *name
)
4546 FIXME("iface %p, name %s stub!\n", iface
, debugstr_a(name
));
4551 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetPass(ID3DXEffectCompiler
*iface
, D3DXHANDLE technique
, UINT index
)
4553 FIXME("iface %p, technique %p, index %u stub!\n", iface
, technique
, index
);
4558 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetPassByName(ID3DXEffectCompiler
*iface
,
4559 D3DXHANDLE technique
, const char *name
)
4561 FIXME("iface %p, technique %p, name %s stub!\n", iface
, technique
, debugstr_a(name
));
4566 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetFunction(ID3DXEffectCompiler
*iface
, UINT index
)
4568 FIXME("iface %p, index %u stub!\n", iface
, index
);
4573 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetFunctionByName(ID3DXEffectCompiler
*iface
, const char *name
)
4575 FIXME("iface %p, name %s stub!\n", iface
, debugstr_a(name
));
4580 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetAnnotation(ID3DXEffectCompiler
*iface
,
4581 D3DXHANDLE object
, UINT index
)
4583 FIXME("iface %p, object %p, index %u stub!\n", iface
, object
, index
);
4588 static D3DXHANDLE WINAPI
ID3DXEffectCompilerImpl_GetAnnotationByName(ID3DXEffectCompiler
*iface
,
4589 D3DXHANDLE object
, const char *name
)
4591 FIXME("iface %p, object %p, name %s stub!\n", iface
, object
, debugstr_a(name
));
4596 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetValue(ID3DXEffectCompiler
*iface
,
4597 D3DXHANDLE parameter
, const void *data
, UINT bytes
)
4599 FIXME("iface %p, parameter %p, data %p, bytes %u stub!\n", iface
, parameter
, data
, bytes
);
4604 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetValue(ID3DXEffectCompiler
*iface
,
4605 D3DXHANDLE parameter
, void *data
, UINT bytes
)
4607 FIXME("iface %p, parameter %p, data %p, bytes %u stub!\n", iface
, parameter
, data
, bytes
);
4612 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetBool(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, BOOL b
)
4614 FIXME("iface %p, parameter %p, b %#x stub!\n", iface
, parameter
, b
);
4619 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetBool(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, BOOL
*b
)
4621 FIXME("iface %p, parameter %p, b %p stub!\n", iface
, parameter
, b
);
4626 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetBoolArray(ID3DXEffectCompiler
*iface
,
4627 D3DXHANDLE parameter
, const BOOL
*b
, UINT count
)
4629 FIXME("iface %p, parameter %p, b %p, count %u stub!\n", iface
, parameter
, b
, count
);
4634 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetBoolArray(ID3DXEffectCompiler
*iface
,
4635 D3DXHANDLE parameter
, BOOL
*b
, UINT count
)
4637 FIXME("iface %p, parameter %p, b %p, count %u stub!\n", iface
, parameter
, b
, count
);
4642 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetInt(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, INT n
)
4644 FIXME("iface %p, parameter %p, n %d stub!\n", iface
, parameter
, n
);
4649 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetInt(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, INT
*n
)
4651 FIXME("iface %p, parameter %p, n %p stub!\n", iface
, parameter
, n
);
4656 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetIntArray(ID3DXEffectCompiler
*iface
,
4657 D3DXHANDLE parameter
, const INT
*n
, UINT count
)
4659 FIXME("iface %p, parameter %p, n %p, count %u stub!\n", iface
, parameter
, n
, count
);
4664 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetIntArray(ID3DXEffectCompiler
*iface
,
4665 D3DXHANDLE parameter
, INT
*n
, UINT count
)
4667 FIXME("iface %p, parameter %p, n %p, count %u stub!\n", iface
, parameter
, n
, count
);
4672 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetFloat(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, float f
)
4674 FIXME("iface %p, parameter %p, f %.8e stub!\n", iface
, parameter
, f
);
4679 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetFloat(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, float *f
)
4681 FIXME("iface %p, parameter %p, f %p stub!\n", iface
, parameter
, f
);
4686 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetFloatArray(ID3DXEffectCompiler
*iface
,
4687 D3DXHANDLE parameter
, const float *f
, UINT count
)
4689 FIXME("iface %p, parameter %p, f %p, count %u stub!\n", iface
, parameter
, f
, count
);
4694 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetFloatArray(ID3DXEffectCompiler
*iface
,
4695 D3DXHANDLE parameter
, float *f
, UINT count
)
4697 FIXME("iface %p, parameter %p, f %p, count %u stub!\n", iface
, parameter
, f
, count
);
4702 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetVector(ID3DXEffectCompiler
*iface
,
4703 D3DXHANDLE parameter
, const D3DXVECTOR4
*vector
)
4705 FIXME("iface %p, parameter %p, vector %p stub!\n", iface
, parameter
, vector
);
4710 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetVector(ID3DXEffectCompiler
*iface
,
4711 D3DXHANDLE parameter
, D3DXVECTOR4
*vector
)
4713 FIXME("iface %p, parameter %p, vector %p stub!\n", iface
, parameter
, vector
);
4718 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetVectorArray(ID3DXEffectCompiler
*iface
,
4719 D3DXHANDLE parameter
, const D3DXVECTOR4
*vector
, UINT count
)
4721 FIXME("iface %p, parameter %p, vector %p, count %u stub!\n", iface
, parameter
, vector
, count
);
4726 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetVectorArray(ID3DXEffectCompiler
*iface
,
4727 D3DXHANDLE parameter
, D3DXVECTOR4
*vector
, UINT count
)
4729 FIXME("iface %p, parameter %p, vector %p, count %u stub!\n", iface
, parameter
, vector
, count
);
4734 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetMatrix(ID3DXEffectCompiler
*iface
,
4735 D3DXHANDLE parameter
, const D3DXMATRIX
*matrix
)
4737 FIXME("iface %p, parameter %p, matrix %p stub!\n", iface
, parameter
, matrix
);
4742 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetMatrix(ID3DXEffectCompiler
*iface
,
4743 D3DXHANDLE parameter
, D3DXMATRIX
*matrix
)
4745 FIXME("iface %p, parameter %p, matrix %p stub!\n", iface
, parameter
, matrix
);
4750 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetMatrixArray(ID3DXEffectCompiler
*iface
,
4751 D3DXHANDLE parameter
, const D3DXMATRIX
*matrix
, UINT count
)
4753 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4758 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetMatrixArray(ID3DXEffectCompiler
*iface
,
4759 D3DXHANDLE parameter
, D3DXMATRIX
*matrix
, UINT count
)
4761 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4766 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetMatrixPointerArray(ID3DXEffectCompiler
*iface
,
4767 D3DXHANDLE parameter
, const D3DXMATRIX
**matrix
, UINT count
)
4769 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4774 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetMatrixPointerArray(ID3DXEffectCompiler
*iface
,
4775 D3DXHANDLE parameter
, D3DXMATRIX
**matrix
, UINT count
)
4777 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4782 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetMatrixTranspose(ID3DXEffectCompiler
*iface
,
4783 D3DXHANDLE parameter
, const D3DXMATRIX
*matrix
)
4785 FIXME("iface %p, parameter %p, matrix %p stub!\n", iface
, parameter
, matrix
);
4790 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetMatrixTranspose(ID3DXEffectCompiler
*iface
,
4791 D3DXHANDLE parameter
, D3DXMATRIX
*matrix
)
4793 FIXME("iface %p, parameter %p, matrix %p stub!\n", iface
, parameter
, matrix
);
4798 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetMatrixTransposeArray(ID3DXEffectCompiler
*iface
,
4799 D3DXHANDLE parameter
, const D3DXMATRIX
*matrix
, UINT count
)
4801 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4806 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetMatrixTransposeArray(ID3DXEffectCompiler
*iface
,
4807 D3DXHANDLE parameter
, D3DXMATRIX
*matrix
, UINT count
)
4809 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4814 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray(ID3DXEffectCompiler
*iface
,
4815 D3DXHANDLE parameter
, const D3DXMATRIX
**matrix
, UINT count
)
4817 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4822 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray(ID3DXEffectCompiler
*iface
,
4823 D3DXHANDLE parameter
, D3DXMATRIX
**matrix
, UINT count
)
4825 FIXME("iface %p, parameter %p, matrix %p, count %u stub!\n", iface
, parameter
, matrix
, count
);
4830 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetString(ID3DXEffectCompiler
*iface
,
4831 D3DXHANDLE parameter
, const char *string
)
4833 FIXME("iface %p, parameter %p, string %s stub!\n", iface
, parameter
, debugstr_a(string
));
4838 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetString(ID3DXEffectCompiler
*iface
,
4839 D3DXHANDLE parameter
, const char **string
)
4841 FIXME("iface %p, parameter %p, string %p stub!\n", iface
, parameter
, string
);
4846 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetTexture(struct ID3DXEffectCompiler
*iface
,
4847 D3DXHANDLE parameter
, struct IDirect3DBaseTexture9
*texture
)
4849 FIXME("iface %p, parameter %p, texture %p stub!\n", iface
, parameter
, texture
);
4854 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetTexture(struct ID3DXEffectCompiler
*iface
,
4855 D3DXHANDLE parameter
, struct IDirect3DBaseTexture9
**texture
)
4857 FIXME("iface %p, parameter %p, texture %p stub!\n", iface
, parameter
, texture
);
4862 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetPixelShader(ID3DXEffectCompiler
*iface
,
4863 D3DXHANDLE parameter
, struct IDirect3DPixelShader9
**shader
)
4865 FIXME("iface %p, parameter %p, shader %p stub!\n", iface
, parameter
, shader
);
4870 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetVertexShader(struct ID3DXEffectCompiler
*iface
,
4871 D3DXHANDLE parameter
, struct IDirect3DVertexShader9
**shader
)
4873 FIXME("iface %p, parameter %p, shader %p stub!\n", iface
, parameter
, shader
);
4878 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetArrayRange(ID3DXEffectCompiler
*iface
,
4879 D3DXHANDLE parameter
, UINT start
, UINT end
)
4881 FIXME("iface %p, parameter %p, start %u, end %u stub!\n", iface
, parameter
, start
, end
);
4886 /*** ID3DXEffectCompiler methods ***/
4887 static HRESULT WINAPI
ID3DXEffectCompilerImpl_SetLiteral(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, BOOL literal
)
4889 FIXME("iface %p, parameter %p, literal %#x stub!\n", iface
, parameter
, literal
);
4894 static HRESULT WINAPI
ID3DXEffectCompilerImpl_GetLiteral(ID3DXEffectCompiler
*iface
, D3DXHANDLE parameter
, BOOL
*literal
)
4896 FIXME("iface %p, parameter %p, literal %p stub!\n", iface
, parameter
, literal
);
4901 static HRESULT WINAPI
ID3DXEffectCompilerImpl_CompileEffect(ID3DXEffectCompiler
*iface
, DWORD flags
,
4902 ID3DXBuffer
**effect
, ID3DXBuffer
**error_msgs
)
4904 FIXME("iface %p, flags %#x, effect %p, error_msgs %p stub!\n", iface
, flags
, effect
, error_msgs
);
4909 static HRESULT WINAPI
ID3DXEffectCompilerImpl_CompileShader(ID3DXEffectCompiler
*iface
, D3DXHANDLE function
,
4910 const char *target
, DWORD flags
, ID3DXBuffer
**shader
, ID3DXBuffer
**error_msgs
,
4911 ID3DXConstantTable
**constant_table
)
4913 FIXME("iface %p, function %p, target %s, flags %#x, shader %p, error_msgs %p, constant_table %p stub!\n",
4914 iface
, function
, debugstr_a(target
), flags
, shader
, error_msgs
, constant_table
);
4919 static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl
=
4921 /*** IUnknown methods ***/
4922 ID3DXEffectCompilerImpl_QueryInterface
,
4923 ID3DXEffectCompilerImpl_AddRef
,
4924 ID3DXEffectCompilerImpl_Release
,
4925 /*** ID3DXBaseEffect methods ***/
4926 ID3DXEffectCompilerImpl_GetDesc
,
4927 ID3DXEffectCompilerImpl_GetParameterDesc
,
4928 ID3DXEffectCompilerImpl_GetTechniqueDesc
,
4929 ID3DXEffectCompilerImpl_GetPassDesc
,
4930 ID3DXEffectCompilerImpl_GetFunctionDesc
,
4931 ID3DXEffectCompilerImpl_GetParameter
,
4932 ID3DXEffectCompilerImpl_GetParameterByName
,
4933 ID3DXEffectCompilerImpl_GetParameterBySemantic
,
4934 ID3DXEffectCompilerImpl_GetParameterElement
,
4935 ID3DXEffectCompilerImpl_GetTechnique
,
4936 ID3DXEffectCompilerImpl_GetTechniqueByName
,
4937 ID3DXEffectCompilerImpl_GetPass
,
4938 ID3DXEffectCompilerImpl_GetPassByName
,
4939 ID3DXEffectCompilerImpl_GetFunction
,
4940 ID3DXEffectCompilerImpl_GetFunctionByName
,
4941 ID3DXEffectCompilerImpl_GetAnnotation
,
4942 ID3DXEffectCompilerImpl_GetAnnotationByName
,
4943 ID3DXEffectCompilerImpl_SetValue
,
4944 ID3DXEffectCompilerImpl_GetValue
,
4945 ID3DXEffectCompilerImpl_SetBool
,
4946 ID3DXEffectCompilerImpl_GetBool
,
4947 ID3DXEffectCompilerImpl_SetBoolArray
,
4948 ID3DXEffectCompilerImpl_GetBoolArray
,
4949 ID3DXEffectCompilerImpl_SetInt
,
4950 ID3DXEffectCompilerImpl_GetInt
,
4951 ID3DXEffectCompilerImpl_SetIntArray
,
4952 ID3DXEffectCompilerImpl_GetIntArray
,
4953 ID3DXEffectCompilerImpl_SetFloat
,
4954 ID3DXEffectCompilerImpl_GetFloat
,
4955 ID3DXEffectCompilerImpl_SetFloatArray
,
4956 ID3DXEffectCompilerImpl_GetFloatArray
,
4957 ID3DXEffectCompilerImpl_SetVector
,
4958 ID3DXEffectCompilerImpl_GetVector
,
4959 ID3DXEffectCompilerImpl_SetVectorArray
,
4960 ID3DXEffectCompilerImpl_GetVectorArray
,
4961 ID3DXEffectCompilerImpl_SetMatrix
,
4962 ID3DXEffectCompilerImpl_GetMatrix
,
4963 ID3DXEffectCompilerImpl_SetMatrixArray
,
4964 ID3DXEffectCompilerImpl_GetMatrixArray
,
4965 ID3DXEffectCompilerImpl_SetMatrixPointerArray
,
4966 ID3DXEffectCompilerImpl_GetMatrixPointerArray
,
4967 ID3DXEffectCompilerImpl_SetMatrixTranspose
,
4968 ID3DXEffectCompilerImpl_GetMatrixTranspose
,
4969 ID3DXEffectCompilerImpl_SetMatrixTransposeArray
,
4970 ID3DXEffectCompilerImpl_GetMatrixTransposeArray
,
4971 ID3DXEffectCompilerImpl_SetMatrixTransposePointerArray
,
4972 ID3DXEffectCompilerImpl_GetMatrixTransposePointerArray
,
4973 ID3DXEffectCompilerImpl_SetString
,
4974 ID3DXEffectCompilerImpl_GetString
,
4975 ID3DXEffectCompilerImpl_SetTexture
,
4976 ID3DXEffectCompilerImpl_GetTexture
,
4977 ID3DXEffectCompilerImpl_GetPixelShader
,
4978 ID3DXEffectCompilerImpl_GetVertexShader
,
4979 ID3DXEffectCompilerImpl_SetArrayRange
,
4980 /*** ID3DXEffectCompiler methods ***/
4981 ID3DXEffectCompilerImpl_SetLiteral
,
4982 ID3DXEffectCompilerImpl_GetLiteral
,
4983 ID3DXEffectCompilerImpl_CompileEffect
,
4984 ID3DXEffectCompilerImpl_CompileShader
,
4987 static HRESULT
d3dx_parse_sampler(struct d3dx_effect
*effect
, struct d3dx_sampler
*sampler
,
4988 const char *data
, const char **ptr
, struct d3dx_object
*objects
)
4993 read_dword(ptr
, &sampler
->state_count
);
4994 TRACE("Count: %u\n", sampler
->state_count
);
4996 sampler
->states
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*sampler
->states
) * sampler
->state_count
);
4997 if (!sampler
->states
)
4999 ERR("Out of memory\n");
5000 return E_OUTOFMEMORY
;
5003 for (i
= 0; i
< sampler
->state_count
; ++i
)
5005 hr
= d3dx_parse_state(effect
, &sampler
->states
[i
], data
, ptr
, objects
);
5008 WARN("Failed to parse state %u\n", i
);
5017 for (i
= 0; i
< sampler
->state_count
; ++i
)
5019 free_state(&sampler
->states
[i
]);
5021 HeapFree(GetProcessHeap(), 0, sampler
->states
);
5022 sampler
->states
= NULL
;
5027 static HRESULT
d3dx_parse_value(struct d3dx_effect
*effect
, struct d3dx_parameter
*param
,
5028 void *value
, const char *data
, const char **ptr
, struct d3dx_object
*objects
)
5034 if (param
->element_count
)
5036 param
->data
= value
;
5038 for (i
= 0; i
< param
->element_count
; ++i
)
5040 struct d3dx_parameter
*member
= ¶m
->members
[i
];
5042 hr
= d3dx_parse_value(effect
, member
, value
? (char *)value
+ old_size
: NULL
, data
, ptr
, objects
);
5045 WARN("Failed to parse value %u\n", i
);
5049 old_size
+= member
->bytes
;
5055 switch(param
->class)
5059 case D3DXPC_MATRIX_ROWS
:
5060 case D3DXPC_MATRIX_COLUMNS
:
5061 param
->data
= value
;
5065 param
->data
= value
;
5067 for (i
= 0; i
< param
->member_count
; ++i
)
5069 struct d3dx_parameter
*member
= ¶m
->members
[i
];
5071 hr
= d3dx_parse_value(effect
, member
, (char *)value
+ old_size
, data
, ptr
, objects
);
5074 WARN("Failed to parse value %u\n", i
);
5078 old_size
+= member
->bytes
;
5083 switch (param
->type
)
5086 case D3DXPT_TEXTURE
:
5087 case D3DXPT_TEXTURE1D
:
5088 case D3DXPT_TEXTURE2D
:
5089 case D3DXPT_TEXTURE3D
:
5090 case D3DXPT_TEXTURECUBE
:
5091 case D3DXPT_PIXELSHADER
:
5092 case D3DXPT_VERTEXSHADER
:
5093 read_dword(ptr
, ¶m
->object_id
);
5094 TRACE("Id: %u\n", param
->object_id
);
5095 objects
[param
->object_id
].param
= param
;
5096 param
->data
= value
;
5099 case D3DXPT_SAMPLER
:
5100 case D3DXPT_SAMPLER1D
:
5101 case D3DXPT_SAMPLER2D
:
5102 case D3DXPT_SAMPLER3D
:
5103 case D3DXPT_SAMPLERCUBE
:
5105 struct d3dx_sampler
*sampler
;
5107 sampler
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*sampler
));
5109 return E_OUTOFMEMORY
;
5111 hr
= d3dx_parse_sampler(effect
, sampler
, data
, ptr
, objects
);
5114 HeapFree(GetProcessHeap(), 0, sampler
);
5115 WARN("Failed to parse sampler\n");
5119 param
->data
= sampler
;
5124 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param
->type
));
5130 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param
->class));
5137 static HRESULT
d3dx_parse_init_value(struct d3dx_effect
*effect
, struct d3dx_parameter
*param
,
5138 const char *data
, const char *ptr
, struct d3dx_object
*objects
)
5140 UINT size
= param
->bytes
;
5144 TRACE("param size: %u\n", size
);
5148 value
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
5151 ERR("Failed to allocate data memory.\n");
5152 return E_OUTOFMEMORY
;
5155 switch(param
->class)
5162 case D3DXPC_MATRIX_ROWS
:
5163 case D3DXPC_MATRIX_COLUMNS
:
5165 TRACE("Data: %s.\n", debugstr_an(ptr
, size
));
5166 memcpy(value
, ptr
, size
);
5170 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param
->class));
5175 hr
= d3dx_parse_value(effect
, param
, value
, data
, &ptr
, objects
);
5178 WARN("Failed to parse value\n");
5179 HeapFree(GetProcessHeap(), 0, value
);
5186 static HRESULT
d3dx9_parse_name(char **name
, const char *ptr
)
5190 read_dword(&ptr
, &size
);
5191 TRACE("Name size: %#x\n", size
);
5198 *name
= HeapAlloc(GetProcessHeap(), 0, size
);
5201 ERR("Failed to allocate name memory.\n");
5202 return E_OUTOFMEMORY
;
5205 TRACE("Name: %s.\n", debugstr_an(ptr
, size
));
5206 memcpy(*name
, ptr
, size
);
5211 static HRESULT
d3dx9_copy_data(struct d3dx_effect
*effect
, unsigned int object_id
, const char **ptr
)
5213 struct d3dx_object
*object
= &effect
->objects
[object_id
];
5215 if (object
->size
|| object
->data
)
5218 FIXME("Overwriting object id %u!\n", object_id
);
5220 TRACE("Overwriting object id 0.\n");
5222 HeapFree(GetProcessHeap(), 0, object
->data
);
5223 object
->data
= NULL
;
5226 read_dword(ptr
, &object
->size
);
5227 TRACE("Data size: %#x.\n", object
->size
);
5232 object
->data
= HeapAlloc(GetProcessHeap(), 0, object
->size
);
5235 ERR("Failed to allocate object memory.\n");
5236 return E_OUTOFMEMORY
;
5239 TRACE("Data: %s.\n", debugstr_an(*ptr
, object
->size
));
5240 memcpy(object
->data
, *ptr
, object
->size
);
5242 *ptr
+= ((object
->size
+ 3) & ~3);
5247 static void param_set_magic_number(struct d3dx_parameter
*param
)
5249 memcpy(param
->magic_string
, parameter_magic_string
, sizeof(parameter_magic_string
));
5252 static int param_rb_compare(const void *key
, const struct wine_rb_entry
*entry
)
5254 const char *name
= key
;
5255 struct d3dx_parameter
*param
= WINE_RB_ENTRY_VALUE(entry
, struct d3dx_parameter
, rb_entry
);
5257 return strcmp(name
, param
->full_name
);
5260 static void add_param_to_tree(struct d3dx_effect
*effect
, struct d3dx_parameter
*param
,
5261 struct d3dx_parameter
*parent
, char separator
, unsigned int element
)
5263 const char *parent_name
= parent
? parent
->full_name
: NULL
;
5266 TRACE("Adding parameter %p (%s - parent %p, element %u) to the rbtree.\n",
5267 param
, debugstr_a(param
->name
), parent
, element
);
5271 unsigned int parent_name_len
= strlen(parent_name
);
5272 unsigned int name_len
= strlen(param
->name
);
5273 unsigned int part_str_len
;
5277 if (separator
== '[')
5279 sprintf(part_str
, "[%u]", element
);
5280 part_str_len
= strlen(part_str
);
5285 part_str
[0] = separator
;
5289 len
= parent_name_len
+ part_str_len
+ name_len
+ 1;
5291 if (!(param
->full_name
= heap_alloc(len
)))
5293 ERR("Out of memory.\n");
5297 memcpy(param
->full_name
, parent_name
, parent_name_len
);
5298 memcpy(param
->full_name
+ parent_name_len
, part_str
, part_str_len
);
5299 memcpy(param
->full_name
+ parent_name_len
+ part_str_len
, param
->name
, name_len
);
5300 param
->full_name
[len
- 1] = 0;
5304 unsigned int len
= strlen(param
->name
) + 1;
5306 if (!(param
->full_name
= heap_alloc(len
)))
5308 ERR("Out of memory.\n");
5312 memcpy(param
->full_name
, param
->name
, len
);
5314 TRACE("Full name is %s.\n", param
->full_name
);
5315 wine_rb_put(&effect
->param_tree
, param
->full_name
, ¶m
->rb_entry
);
5317 if (is_top_level_parameter(param
))
5318 for (i
= 0; i
< param
->top_level_param
->annotation_count
; ++i
)
5319 add_param_to_tree(effect
, ¶m
->top_level_param
->annotations
[i
], param
, '@', 0);
5321 if (param
->element_count
)
5322 for (i
= 0; i
< param
->element_count
; ++i
)
5323 add_param_to_tree(effect
, ¶m
->members
[i
], param
, '[', i
);
5325 for (i
= 0; i
< param
->member_count
; ++i
)
5326 add_param_to_tree(effect
, ¶m
->members
[i
], param
, '.', 0);
5329 static HRESULT
d3dx_parse_effect_typedef(struct d3dx_effect
*effect
, struct d3dx_parameter
*param
,
5330 const char *data
, const char **ptr
, struct d3dx_parameter
*parent
, UINT flags
)
5336 param
->flags
= flags
;
5340 read_dword(ptr
, (DWORD
*)¶m
->type
);
5341 TRACE("Type: %s\n", debug_d3dxparameter_type(param
->type
));
5343 read_dword(ptr
, (DWORD
*)¶m
->class);
5344 TRACE("Class: %s\n", debug_d3dxparameter_class(param
->class));
5346 read_dword(ptr
, &offset
);
5347 TRACE("Type name offset: %#x\n", offset
);
5348 hr
= d3dx9_parse_name(¶m
->name
, data
+ offset
);
5351 WARN("Failed to parse name\n");
5355 read_dword(ptr
, &offset
);
5356 TRACE("Type semantic offset: %#x\n", offset
);
5357 hr
= d3dx9_parse_name(¶m
->semantic
, data
+ offset
);
5360 WARN("Failed to parse semantic\n");
5364 read_dword(ptr
, ¶m
->element_count
);
5365 TRACE("Elements: %u\n", param
->element_count
);
5367 switch (param
->class)
5370 read_dword(ptr
, ¶m
->columns
);
5371 TRACE("Columns: %u\n", param
->columns
);
5373 read_dword(ptr
, ¶m
->rows
);
5374 TRACE("Rows: %u\n", param
->rows
);
5376 /* sizeof(DWORD) * rows * columns */
5377 param
->bytes
= 4 * param
->rows
* param
->columns
;
5381 case D3DXPC_MATRIX_ROWS
:
5382 case D3DXPC_MATRIX_COLUMNS
:
5383 read_dword(ptr
, ¶m
->rows
);
5384 TRACE("Rows: %u\n", param
->rows
);
5386 read_dword(ptr
, ¶m
->columns
);
5387 TRACE("Columns: %u\n", param
->columns
);
5389 /* sizeof(DWORD) * rows * columns */
5390 param
->bytes
= 4 * param
->rows
* param
->columns
;
5394 read_dword(ptr
, ¶m
->member_count
);
5395 TRACE("Members: %u\n", param
->member_count
);
5399 switch (param
->type
)
5402 case D3DXPT_PIXELSHADER
:
5403 case D3DXPT_VERTEXSHADER
:
5404 case D3DXPT_TEXTURE
:
5405 case D3DXPT_TEXTURE1D
:
5406 case D3DXPT_TEXTURE2D
:
5407 case D3DXPT_TEXTURE3D
:
5408 case D3DXPT_TEXTURECUBE
:
5409 param
->bytes
= sizeof(void *);
5412 case D3DXPT_SAMPLER
:
5413 case D3DXPT_SAMPLER1D
:
5414 case D3DXPT_SAMPLER2D
:
5415 case D3DXPT_SAMPLER3D
:
5416 case D3DXPT_SAMPLERCUBE
:
5421 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param
->type
));
5427 FIXME("Unhandled class %s\n", debug_d3dxparameter_class(param
->class));
5434 param
->type
= parent
->type
;
5435 param
->class = parent
->class;
5436 param
->name
= parent
->name
;
5437 param
->semantic
= parent
->semantic
;
5438 param
->element_count
= 0;
5439 param
->member_count
= parent
->member_count
;
5440 param
->bytes
= parent
->bytes
;
5441 param
->rows
= parent
->rows
;
5442 param
->columns
= parent
->columns
;
5445 if (param
->element_count
)
5447 unsigned int param_bytes
= 0;
5448 const char *save_ptr
= *ptr
;
5450 param
->members
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*param
->members
) * param
->element_count
);
5451 if (!param
->members
)
5453 ERR("Out of memory\n");
5458 for (i
= 0; i
< param
->element_count
; ++i
)
5462 param_set_magic_number(¶m
->members
[i
]);
5463 hr
= d3dx_parse_effect_typedef(effect
, ¶m
->members
[i
], data
, ptr
, param
, flags
);
5466 WARN("Failed to parse member %u\n", i
);
5470 param_bytes
+= param
->members
[i
].bytes
;
5473 param
->bytes
= param_bytes
;
5475 else if (param
->member_count
)
5477 param
->members
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*param
->members
) * param
->member_count
);
5478 if (!param
->members
)
5480 ERR("Out of memory\n");
5485 for (i
= 0; i
< param
->member_count
; ++i
)
5487 param_set_magic_number(¶m
->members
[i
]);
5488 hr
= d3dx_parse_effect_typedef(effect
, ¶m
->members
[i
], data
, ptr
, NULL
, flags
);
5491 WARN("Failed to parse member %u\n", i
);
5495 param
->bytes
+= param
->members
[i
].bytes
;
5504 unsigned int count
= param
->element_count
? param
->element_count
: param
->member_count
;
5506 for (i
= 0; i
< count
; ++i
)
5507 free_parameter(¶m
->members
[i
], param
->element_count
!= 0, TRUE
);
5508 HeapFree(GetProcessHeap(), 0, param
->members
);
5509 param
->members
= NULL
;
5514 HeapFree(GetProcessHeap(), 0, param
->name
);
5515 HeapFree(GetProcessHeap(), 0, param
->semantic
);
5518 param
->semantic
= NULL
;
5523 static HRESULT
d3dx_parse_effect_annotation(struct d3dx_effect
*effect
, struct d3dx_parameter
*anno
,
5524 const char *data
, const char **ptr
, struct d3dx_object
*objects
)
5530 anno
->flags
= D3DX_PARAMETER_ANNOTATION
;
5532 read_dword(ptr
, &offset
);
5533 TRACE("Typedef offset: %#x\n", offset
);
5534 ptr2
= data
+ offset
;
5535 hr
= d3dx_parse_effect_typedef(effect
, anno
, data
, &ptr2
, NULL
, D3DX_PARAMETER_ANNOTATION
);
5538 WARN("Failed to parse type definition\n");
5542 read_dword(ptr
, &offset
);
5543 TRACE("Value offset: %#x\n", offset
);
5544 hr
= d3dx_parse_init_value(effect
, anno
, data
, data
+ offset
, objects
);
5547 WARN("Failed to parse value\n");
5554 static HRESULT
d3dx_parse_state(struct d3dx_effect
*effect
, struct d3dx_state
*state
,
5555 const char *data
, const char **ptr
, struct d3dx_object
*objects
)
5557 struct d3dx_parameter
*param
= &state
->parameter
;
5558 enum STATE_CLASS state_class
;
5564 state
->type
= ST_CONSTANT
;
5566 read_dword(ptr
, &state
->operation
);
5567 if (state
->operation
>= ARRAY_SIZE(state_table
))
5569 WARN("Unknown state operation %u.\n", state
->operation
);
5570 return D3DERR_INVALIDCALL
;
5573 TRACE("Operation: %#x (%s)\n", state
->operation
, state_table
[state
->operation
].name
);
5575 read_dword(ptr
, &state
->index
);
5576 TRACE("Index: %#x\n", state
->index
);
5578 read_dword(ptr
, &offset
);
5579 TRACE("Typedef offset: %#x\n", offset
);
5580 ptr2
= data
+ offset
;
5581 hr
= d3dx_parse_effect_typedef(effect
, param
, data
, &ptr2
, NULL
, 0);
5584 WARN("Failed to parse type definition\n");
5588 read_dword(ptr
, &offset
);
5589 TRACE("Value offset: %#x\n", offset
);
5590 hr
= d3dx_parse_init_value(effect
, param
, data
, data
+ offset
, objects
);
5593 WARN("Failed to parse value\n");
5597 if (((state_class
= state_table
[state
->operation
].class) == SC_VERTEXSHADER
5598 || state_class
== SC_PIXELSHADER
|| state_class
== SC_TEXTURE
)
5599 && param
->bytes
< sizeof(void *))
5601 if (param
->type
!= D3DXPT_INT
|| *(unsigned int *)param
->data
)
5603 FIXME("Unexpected parameter for object, param->type %#x, param->class %#x, *param->data %#x.\n",
5604 param
->type
, param
->class, *(unsigned int *)param
->data
);
5605 hr
= D3DXERR_INVALIDDATA
;
5609 new_data
= heap_realloc(param
->data
, sizeof(void *));
5612 ERR("Out of memory.\n");
5616 memset(new_data
, 0, sizeof(void *));
5617 param
->data
= new_data
;
5618 param
->bytes
= sizeof(void *);
5625 free_parameter(param
, FALSE
, FALSE
);
5630 static HRESULT
d3dx_parse_effect_parameter(struct d3dx_effect
*effect
, struct d3dx_top_level_parameter
*param
,
5631 const char *data
, const char **ptr
, struct d3dx_object
*objects
)
5638 read_dword(ptr
, &offset
);
5639 TRACE("Typedef offset: %#x.\n", offset
);
5640 ptr2
= data
+ offset
;
5642 read_dword(ptr
, &offset
);
5643 TRACE("Value offset: %#x.\n", offset
);
5645 read_dword(ptr
, ¶m
->param
.flags
);
5646 TRACE("Flags: %#x.\n", param
->param
.flags
);
5648 read_dword(ptr
, ¶m
->annotation_count
);
5649 TRACE("Annotation count: %u.\n", param
->annotation_count
);
5651 hr
= d3dx_parse_effect_typedef(effect
, ¶m
->param
, data
, &ptr2
, NULL
, param
->param
.flags
);
5654 WARN("Failed to parse type definition.\n");
5658 hr
= d3dx_parse_init_value(effect
, ¶m
->param
, data
, data
+ offset
, objects
);
5661 WARN("Failed to parse value.\n");
5665 if (param
->annotation_count
)
5667 param
->annotations
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
5668 sizeof(*param
->annotations
) * param
->annotation_count
);
5669 if (!param
->annotations
)
5671 ERR("Out of memory.\n");
5676 for (i
= 0; i
< param
->annotation_count
; ++i
)
5678 param_set_magic_number(¶m
->annotations
[i
]);
5679 hr
= d3dx_parse_effect_annotation(effect
, ¶m
->annotations
[i
], data
, ptr
, objects
);
5682 WARN("Failed to parse annotation.\n");
5692 if (param
->annotations
)
5694 for (i
= 0; i
< param
->annotation_count
; ++i
)
5695 free_parameter(¶m
->annotations
[i
], FALSE
, FALSE
);
5696 HeapFree(GetProcessHeap(), 0, param
->annotations
);
5697 param
->annotations
= NULL
;
5703 static HRESULT
d3dx_parse_effect_pass(struct d3dx_effect
*effect
, struct d3dx_pass
*pass
,
5704 const char *data
, const char **ptr
, struct d3dx_object
*objects
)
5709 struct d3dx_state
*states
= NULL
;
5712 read_dword(ptr
, &offset
);
5713 TRACE("Pass name offset: %#x\n", offset
);
5714 hr
= d3dx9_parse_name(&name
, data
+ offset
);
5717 WARN("Failed to parse name\n");
5721 read_dword(ptr
, &pass
->annotation_count
);
5722 TRACE("Annotation count: %u\n", pass
->annotation_count
);
5724 read_dword(ptr
, &pass
->state_count
);
5725 TRACE("State count: %u\n", pass
->state_count
);
5727 if (pass
->annotation_count
)
5729 pass
->annotations
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
5730 sizeof(*pass
->annotations
) * pass
->annotation_count
);
5731 if (!pass
->annotations
)
5733 ERR("Out of memory\n");
5738 for (i
= 0; i
< pass
->annotation_count
; ++i
)
5740 param_set_magic_number(&pass
->annotations
[i
]);
5741 hr
= d3dx_parse_effect_annotation(effect
, &pass
->annotations
[i
], data
, ptr
, objects
);
5744 WARN("Failed to parse annotation %u\n", i
);
5750 if (pass
->state_count
)
5752 states
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*states
) * pass
->state_count
);
5755 ERR("Out of memory\n");
5760 for (i
= 0; i
< pass
->state_count
; ++i
)
5762 hr
= d3dx_parse_state(effect
, &states
[i
], data
, ptr
, objects
);
5765 WARN("Failed to parse annotation %u\n", i
);
5772 pass
->states
= states
;
5778 if (pass
->annotations
)
5780 for (i
= 0; i
< pass
->annotation_count
; ++i
)
5781 free_parameter(&pass
->annotations
[i
], FALSE
, FALSE
);
5782 HeapFree(GetProcessHeap(), 0, pass
->annotations
);
5783 pass
->annotations
= NULL
;
5788 for (i
= 0; i
< pass
->state_count
; ++i
)
5790 free_state(&states
[i
]);
5792 HeapFree(GetProcessHeap(), 0, states
);
5795 HeapFree(GetProcessHeap(), 0, name
);
5800 static HRESULT
d3dx_parse_effect_technique(struct d3dx_effect
*effect
, struct d3dx_technique
*technique
,
5801 const char *data
, const char **ptr
, struct d3dx_object
*objects
)
5808 read_dword(ptr
, &offset
);
5809 TRACE("Technique name offset: %#x\n", offset
);
5810 hr
= d3dx9_parse_name(&name
, data
+ offset
);
5813 WARN("Failed to parse name\n");
5817 read_dword(ptr
, &technique
->annotation_count
);
5818 TRACE("Annotation count: %u\n", technique
->annotation_count
);
5820 read_dword(ptr
, &technique
->pass_count
);
5821 TRACE("Pass count: %u\n", technique
->pass_count
);
5823 if (technique
->annotation_count
)
5825 technique
->annotations
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
5826 sizeof(*technique
->annotations
) * technique
->annotation_count
);
5827 if (!technique
->annotations
)
5829 ERR("Out of memory\n");
5834 for (i
= 0; i
< technique
->annotation_count
; ++i
)
5836 param_set_magic_number(&technique
->annotations
[i
]);
5837 hr
= d3dx_parse_effect_annotation(effect
, &technique
->annotations
[i
], data
, ptr
, objects
);
5840 WARN("Failed to parse annotation %u\n", i
);
5846 if (technique
->pass_count
)
5848 technique
->passes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
5849 sizeof(*technique
->passes
) * technique
->pass_count
);
5850 if (!technique
->passes
)
5852 ERR("Out of memory\n");
5857 for (i
= 0; i
< technique
->pass_count
; ++i
)
5859 hr
= d3dx_parse_effect_pass(effect
, &technique
->passes
[i
], data
, ptr
, objects
);
5862 WARN("Failed to parse pass %u\n", i
);
5868 technique
->name
= name
;
5874 if (technique
->passes
)
5876 for (i
= 0; i
< technique
->pass_count
; ++i
)
5877 free_pass(&technique
->passes
[i
]);
5878 HeapFree(GetProcessHeap(), 0, technique
->passes
);
5879 technique
->passes
= NULL
;
5882 if (technique
->annotations
)
5884 for (i
= 0; i
< technique
->annotation_count
; ++i
)
5885 free_parameter(&technique
->annotations
[i
], FALSE
, FALSE
);
5886 HeapFree(GetProcessHeap(), 0, technique
->annotations
);
5887 technique
->annotations
= NULL
;
5890 HeapFree(GetProcessHeap(), 0, name
);
5895 static HRESULT
d3dx9_create_object(struct d3dx_effect
*effect
, struct d3dx_object
*object
)
5897 struct d3dx_parameter
*param
= object
->param
;
5898 IDirect3DDevice9
*device
= effect
->device
;
5901 if (*(char **)param
->data
)
5902 ERR("Parameter data already allocated.\n");
5904 switch (param
->type
)
5907 *(char **)param
->data
= HeapAlloc(GetProcessHeap(), 0, object
->size
);
5908 if (!*(char **)param
->data
)
5910 ERR("Out of memory.\n");
5911 return E_OUTOFMEMORY
;
5913 memcpy(*(char **)param
->data
, object
->data
, object
->size
);
5915 case D3DXPT_VERTEXSHADER
:
5916 if (FAILED(hr
= IDirect3DDevice9_CreateVertexShader(device
, object
->data
,
5917 (IDirect3DVertexShader9
**)param
->data
)))
5919 WARN("Failed to create vertex shader.\n");
5920 object
->creation_failed
= TRUE
;
5923 case D3DXPT_PIXELSHADER
:
5924 if (FAILED(hr
= IDirect3DDevice9_CreatePixelShader(device
, object
->data
,
5925 (IDirect3DPixelShader9
**)param
->data
)))
5927 WARN("Failed to create pixel shader.\n");
5928 object
->creation_failed
= TRUE
;
5937 static HRESULT
d3dx_parse_array_selector(struct d3dx_effect
*effect
, struct d3dx_state
*state
,
5938 const char **skip_constants
, unsigned int skip_constants_count
)
5941 struct d3dx_parameter
*param
= &state
->parameter
;
5942 struct d3dx_object
*object
= &effect
->objects
[param
->object_id
];
5943 char *ptr
= object
->data
;
5946 TRACE("Parsing array entry selection state for parameter %p.\n", param
);
5948 string_size
= *(DWORD
*)ptr
;
5949 state
->referenced_param
= get_parameter_by_name(effect
, NULL
, ptr
+ 4);
5950 if (state
->referenced_param
)
5952 TRACE("Mapping to parameter %s.\n", debugstr_a(state
->referenced_param
->name
));
5956 FIXME("Referenced parameter %s not found.\n", ptr
+ 4);
5957 return D3DXERR_INVALIDDATA
;
5959 TRACE("Unknown DWORD: 0x%.8x.\n", *(DWORD
*)(ptr
+ string_size
));
5961 if (string_size
% sizeof(DWORD
))
5962 FIXME("Unaligned string_size %u.\n", string_size
);
5963 if (FAILED(ret
= d3dx_create_param_eval(effect
, (DWORD
*)(ptr
+ string_size
) + 1,
5964 object
->size
- (string_size
+ sizeof(DWORD
)), D3DXPT_INT
, ¶m
->param_eval
,
5965 get_version_counter_ptr(effect
), NULL
, 0)))
5968 param
= state
->referenced_param
;
5969 if (param
->type
== D3DXPT_VERTEXSHADER
|| param
->type
== D3DXPT_PIXELSHADER
)
5973 for (i
= 0; i
< param
->element_count
; i
++)
5975 if (param
->members
[i
].type
!= param
->type
)
5977 FIXME("Unexpected member parameter type %u, expected %u.\n", param
->members
[i
].type
, param
->type
);
5978 return D3DXERR_INVALIDDATA
;
5980 if (!param
->members
[i
].param_eval
)
5982 TRACE("Creating preshader for object %u.\n", param
->members
[i
].object_id
);
5983 object
= &effect
->objects
[param
->members
[i
].object_id
];
5984 if (FAILED(ret
= d3dx_create_param_eval(effect
, object
->data
, object
->size
, param
->type
,
5985 ¶m
->members
[i
].param_eval
, get_version_counter_ptr(effect
),
5986 skip_constants
, skip_constants_count
)))
5994 static HRESULT
d3dx_parse_resource(struct d3dx_effect
*effect
, const char *data
, const char **ptr
,
5995 const char **skip_constants
, unsigned int skip_constants_count
)
5997 DWORD technique_index
;
5998 DWORD index
, state_index
, usage
, element_index
;
5999 struct d3dx_state
*state
;
6000 struct d3dx_parameter
*param
;
6001 struct d3dx_object
*object
;
6002 HRESULT hr
= E_FAIL
;
6004 read_dword(ptr
, &technique_index
);
6005 TRACE("technique_index: %u\n", technique_index
);
6007 read_dword(ptr
, &index
);
6008 TRACE("index: %u\n", index
);
6010 read_dword(ptr
, &element_index
);
6011 TRACE("element_index: %u\n", element_index
);
6013 read_dword(ptr
, &state_index
);
6014 TRACE("state_index: %u\n", state_index
);
6016 read_dword(ptr
, &usage
);
6017 TRACE("usage: %u\n", usage
);
6019 if (technique_index
== 0xffffffff)
6021 struct d3dx_parameter
*parameter
;
6022 struct d3dx_sampler
*sampler
;
6024 if (index
>= effect
->parameter_count
)
6026 FIXME("Index out of bounds: index %u >= parameter_count %u\n", index
, effect
->parameter_count
);
6030 parameter
= &effect
->parameters
[index
].param
;
6031 if (element_index
!= 0xffffffff)
6033 if (element_index
>= parameter
->element_count
&& parameter
->element_count
!= 0)
6035 FIXME("Index out of bounds: element_index %u >= element_count %u\n", element_index
, parameter
->element_count
);
6039 if (parameter
->element_count
)
6040 parameter
= ¶meter
->members
[element_index
];
6043 sampler
= parameter
->data
;
6044 if (state_index
>= sampler
->state_count
)
6046 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index
, sampler
->state_count
);
6050 state
= &sampler
->states
[state_index
];
6054 struct d3dx_technique
*technique
;
6055 struct d3dx_pass
*pass
;
6057 if (technique_index
>= effect
->technique_count
)
6059 FIXME("Index out of bounds: technique_index %u >= technique_count %u.\n", technique_index
,
6060 effect
->technique_count
);
6064 technique
= &effect
->techniques
[technique_index
];
6065 if (index
>= technique
->pass_count
)
6067 FIXME("Index out of bounds: index %u >= pass_count %u\n", index
, technique
->pass_count
);
6071 pass
= &technique
->passes
[index
];
6072 if (state_index
>= pass
->state_count
)
6074 FIXME("Index out of bounds: state_index %u >= state_count %u\n", state_index
, pass
->state_count
);
6078 state
= &pass
->states
[state_index
];
6081 TRACE("State operation %#x (%s).\n", state
->operation
, state_table
[state
->operation
].name
);
6082 param
= &state
->parameter
;
6083 TRACE("Using object id %u.\n", param
->object_id
);
6084 object
= &effect
->objects
[param
->object_id
];
6086 TRACE("Usage %u: class %s, type %s.\n", usage
, debug_d3dxparameter_class(param
->class),
6087 debug_d3dxparameter_type(param
->type
));
6091 switch (param
->type
)
6093 case D3DXPT_VERTEXSHADER
:
6094 case D3DXPT_PIXELSHADER
:
6095 state
->type
= ST_CONSTANT
;
6096 if (FAILED(hr
= d3dx9_copy_data(effect
, param
->object_id
, ptr
)))
6101 if (FAILED(hr
= d3dx9_create_object(effect
, object
)))
6103 if (FAILED(hr
= d3dx_create_param_eval(effect
, object
->data
, object
->size
, param
->type
,
6104 ¶m
->param_eval
, get_version_counter_ptr(effect
),
6105 skip_constants
, skip_constants_count
)))
6114 state
->type
= ST_FXLC
;
6115 if (FAILED(hr
= d3dx9_copy_data(effect
, param
->object_id
, ptr
)))
6117 if (FAILED(hr
= d3dx_create_param_eval(effect
, object
->data
, object
->size
, param
->type
,
6118 ¶m
->param_eval
, get_version_counter_ptr(effect
), NULL
, 0)))
6123 FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param
->type
));
6129 state
->type
= ST_PARAMETER
;
6130 if (FAILED(hr
= d3dx9_copy_data(effect
, param
->object_id
, ptr
)))
6133 TRACE("Looking for parameter %s.\n", debugstr_a(object
->data
));
6134 state
->referenced_param
= get_parameter_by_name(effect
, NULL
, object
->data
);
6135 if (state
->referenced_param
)
6137 struct d3dx_parameter
*refpar
= state
->referenced_param
;
6139 TRACE("Mapping to parameter %p, having object id %u.\n", refpar
, refpar
->object_id
);
6140 if (refpar
->type
== D3DXPT_VERTEXSHADER
|| refpar
->type
== D3DXPT_PIXELSHADER
)
6142 struct d3dx_object
*refobj
= &effect
->objects
[refpar
->object_id
];
6144 if (!refpar
->param_eval
)
6146 if (FAILED(hr
= d3dx_create_param_eval(effect
, refobj
->data
, refobj
->size
,
6147 refpar
->type
, &refpar
->param_eval
, get_version_counter_ptr(effect
),
6148 skip_constants
, skip_constants_count
)))
6155 FIXME("Referenced parameter %s not found.\n", (char *)object
->data
);
6156 return D3DXERR_INVALIDDATA
;
6161 state
->type
= ST_ARRAY_SELECTOR
;
6162 if (FAILED(hr
= d3dx9_copy_data(effect
, param
->object_id
, ptr
)))
6164 hr
= d3dx_parse_array_selector(effect
, state
, skip_constants
, skip_constants_count
);
6168 FIXME("Unknown usage %x\n", usage
);
6175 static BOOL
param_set_top_level_param(void *top_level_param
, struct d3dx_parameter
*param
)
6177 param
->top_level_param
= top_level_param
;
6181 static HRESULT
d3dx_parse_effect(struct d3dx_effect
*effect
, const char *data
, UINT data_size
,
6182 DWORD start
, const char **skip_constants
, unsigned int skip_constants_count
)
6184 const char *ptr
= data
+ start
;
6185 UINT stringcount
, resourcecount
;
6189 read_dword(&ptr
, &effect
->parameter_count
);
6190 TRACE("Parameter count: %u.\n", effect
->parameter_count
);
6192 read_dword(&ptr
, &effect
->technique_count
);
6193 TRACE("Technique count: %u.\n", effect
->technique_count
);
6195 skip_dword_unknown(&ptr
, 1);
6197 read_dword(&ptr
, &effect
->object_count
);
6198 TRACE("Object count: %u.\n", effect
->object_count
);
6200 effect
->objects
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
6201 sizeof(*effect
->objects
) * effect
->object_count
);
6202 if (!effect
->objects
)
6204 ERR("Out of memory.\n");
6209 wine_rb_init(&effect
->param_tree
, param_rb_compare
);
6210 if (effect
->parameter_count
)
6212 effect
->parameters
= heap_alloc_zero(sizeof(*effect
->parameters
) * effect
->parameter_count
);
6213 if (!effect
->parameters
)
6215 ERR("Out of memory.\n");
6220 for (i
= 0; i
< effect
->parameter_count
; ++i
)
6222 param_set_magic_number(&effect
->parameters
[i
].param
);
6223 hr
= d3dx_parse_effect_parameter(effect
, &effect
->parameters
[i
], data
, &ptr
, effect
->objects
);
6226 WARN("Failed to parse parameter %u.\n", i
);
6229 walk_parameter_tree(&effect
->parameters
[i
].param
, param_set_top_level_param
, &effect
->parameters
[i
]);
6230 add_param_to_tree(effect
, &effect
->parameters
[i
].param
, NULL
, 0, 0);
6234 if (effect
->technique_count
)
6236 effect
->techniques
= heap_alloc_zero(sizeof(*effect
->techniques
) * effect
->technique_count
);
6237 if (!effect
->techniques
)
6239 ERR("Out of memory.\n");
6244 for (i
= 0; i
< effect
->technique_count
; ++i
)
6246 TRACE("Parsing technique %u.\n", i
);
6247 hr
= d3dx_parse_effect_technique(effect
, &effect
->techniques
[i
], data
, &ptr
, effect
->objects
);
6250 WARN("Failed to parse technique %u.\n", i
);
6256 read_dword(&ptr
, &stringcount
);
6257 TRACE("String count: %u.\n", stringcount
);
6259 read_dword(&ptr
, &resourcecount
);
6260 TRACE("Resource count: %u.\n", resourcecount
);
6262 for (i
= 0; i
< stringcount
; ++i
)
6266 read_dword(&ptr
, &id
);
6267 TRACE("id: %u.\n", id
);
6269 if (FAILED(hr
= d3dx9_copy_data(effect
, id
, &ptr
)))
6272 if (effect
->objects
[id
].data
)
6274 if (FAILED(hr
= d3dx9_create_object(effect
, &effect
->objects
[id
])))
6279 for (i
= 0; i
< resourcecount
; ++i
)
6281 TRACE("parse resource %u.\n", i
);
6283 hr
= d3dx_parse_resource(effect
, data
, &ptr
, skip_constants
, skip_constants_count
);
6286 WARN("Failed to parse resource %u.\n", i
);
6291 for (i
= 0; i
< effect
->parameter_count
; ++i
)
6293 if (FAILED(hr
= d3dx_pool_sync_shared_parameter(effect
->pool
, &effect
->parameters
[i
])))
6295 effect
->parameters
[i
].version_counter
= get_version_counter_ptr(effect
);
6296 set_dirty(&effect
->parameters
[i
].param
);
6302 if (effect
->techniques
)
6304 for (i
= 0; i
< effect
->technique_count
; ++i
)
6305 free_technique(&effect
->techniques
[i
]);
6306 heap_free(effect
->techniques
);
6307 effect
->techniques
= NULL
;
6310 if (effect
->parameters
)
6312 for (i
= 0; i
< effect
->parameter_count
; ++i
)
6314 free_top_level_parameter(&effect
->parameters
[i
]);
6316 heap_free(effect
->parameters
);
6317 effect
->parameters
= NULL
;
6320 if (effect
->objects
)
6322 for (i
= 0; i
< effect
->object_count
; ++i
)
6324 free_object(&effect
->objects
[i
]);
6326 HeapFree(GetProcessHeap(), 0, effect
->objects
);
6327 effect
->objects
= NULL
;
6333 #define INITIAL_CONST_NAMES_SIZE 4
6335 static char *next_valid_constant_name(char **string
)
6337 char *ret
= *string
;
6340 while (*ret
&& !isalpha(*ret
) && *ret
!= '_')
6346 while (isalpha(*next
) || isdigit(*next
) || *next
== '_')
6354 static const char **parse_skip_constants_string(char *skip_constants_string
, unsigned int *names_count
)
6356 const char **names
, **new_alloc
;
6359 unsigned int size
= INITIAL_CONST_NAMES_SIZE
;
6361 names
= HeapAlloc(GetProcessHeap(), 0, sizeof(*names
) * size
);
6366 s
= skip_constants_string
;
6367 while ((name
= next_valid_constant_name(&s
)))
6369 if (*names_count
== size
)
6372 new_alloc
= HeapReAlloc(GetProcessHeap(), 0, names
, sizeof(*names
) * size
);
6375 HeapFree(GetProcessHeap(), 0, names
);
6380 names
[(*names_count
)++] = name
;
6382 new_alloc
= HeapReAlloc(GetProcessHeap(), 0, names
, *names_count
* sizeof(*names
));
6388 static HRESULT
d3dx9_effect_init(struct d3dx_effect
*effect
, struct IDirect3DDevice9
*device
,
6389 const char *data
, SIZE_T data_size
, const D3D_SHADER_MACRO
*defines
, ID3DInclude
*include
,
6390 UINT eflags
, ID3DBlob
**errors
, struct ID3DXEffectPool
*pool
, const char *skip_constants_string
)
6392 #if D3DX_SDK_VERSION <= 36
6393 UINT compile_flags
= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY
;
6395 UINT compile_flags
= 0;
6397 ID3DBlob
*bytecode
= NULL
, *temp_errors
= NULL
;
6398 unsigned int skip_constants_count
= 0;
6399 char *skip_constants_buffer
= NULL
;
6400 const char **skip_constants
= NULL
;
6401 const char *ptr
= data
;
6406 TRACE("effect %p, device %p, data %p, data_size %lu, defines %p, include %p, eflags %#x, errors %p, "
6407 "pool %p, skip_constants %s.\n",
6408 effect
, device
, data
, data_size
, defines
, include
, eflags
, errors
, pool
,
6409 debugstr_a(skip_constants_string
));
6411 effect
->ID3DXEffect_iface
.lpVtbl
= &ID3DXEffect_Vtbl
;
6416 effect
->pool
= unsafe_impl_from_ID3DXEffectPool(pool
);
6417 pool
->lpVtbl
->AddRef(pool
);
6420 IDirect3DDevice9_AddRef(device
);
6421 effect
->device
= device
;
6423 effect
->flags
= eflags
;
6425 list_init(&effect
->parameter_block_list
);
6427 read_dword(&ptr
, &tag
);
6428 TRACE("Tag: %x\n", tag
);
6430 if (tag
!= d3dx9_effect_version(9, 1))
6432 TRACE("HLSL ASCII effect, trying to compile it.\n");
6433 hr
= D3DCompile(data
, data_size
, NULL
, defines
, include
,
6434 NULL
, "fx_2_0", compile_flags
, eflags
, &bytecode
, &temp_errors
);
6437 WARN("Failed to compile ASCII effect.\n");
6439 ID3D10Blob_Release(bytecode
);
6442 const char *error_string
= ID3D10Blob_GetBufferPointer(temp_errors
);
6443 const char *string_ptr
;
6445 while (*error_string
)
6447 string_ptr
= error_string
;
6448 while (*string_ptr
&& *string_ptr
!= '\n' && *string_ptr
!= '\r'
6449 && string_ptr
- error_string
< 80)
6451 TRACE("%s\n", debugstr_an(error_string
, string_ptr
- error_string
));
6452 error_string
= string_ptr
;
6453 while (*error_string
== '\n' || *error_string
== '\r')
6458 *errors
= temp_errors
;
6459 else if (temp_errors
)
6460 ID3D10Blob_Release(temp_errors
);
6465 FIXME("No output from effect compilation.\n");
6466 return D3DERR_INVALIDCALL
;
6469 *errors
= temp_errors
;
6470 else if (temp_errors
)
6471 ID3D10Blob_Release(temp_errors
);
6473 ptr
= ID3D10Blob_GetBufferPointer(bytecode
);
6474 read_dword(&ptr
, &tag
);
6475 TRACE("Tag: %x\n", tag
);
6478 if (skip_constants_string
)
6480 skip_constants_buffer
= HeapAlloc(GetProcessHeap(), 0,
6481 sizeof(*skip_constants_buffer
) * (strlen(skip_constants_string
) + 1));
6482 if (!skip_constants_buffer
)
6485 ID3D10Blob_Release(bytecode
);
6486 return E_OUTOFMEMORY
;
6488 strcpy(skip_constants_buffer
, skip_constants_string
);
6490 if (!(skip_constants
= parse_skip_constants_string(skip_constants_buffer
, &skip_constants_count
)))
6492 HeapFree(GetProcessHeap(), 0, skip_constants_buffer
);
6494 ID3D10Blob_Release(bytecode
);
6495 return E_OUTOFMEMORY
;
6498 read_dword(&ptr
, &offset
);
6499 TRACE("Offset: %x\n", offset
);
6501 hr
= d3dx_parse_effect(effect
, ptr
, data_size
, offset
, skip_constants
, skip_constants_count
);
6503 ID3D10Blob_Release(bytecode
);
6506 FIXME("Failed to parse effect.\n");
6507 HeapFree(GetProcessHeap(), 0, skip_constants_buffer
);
6508 HeapFree(GetProcessHeap(), 0, skip_constants
);
6512 for (i
= 0; i
< skip_constants_count
; ++i
)
6514 struct d3dx_parameter
*param
;
6515 param
= get_parameter_by_name(effect
, NULL
, skip_constants
[i
]);
6518 for (j
= 0; j
< effect
->technique_count
; ++j
)
6520 if (is_parameter_used(param
, &effect
->techniques
[j
]))
6522 WARN("skip_constants parameter %s is used in technique %u.\n",
6523 debugstr_a(skip_constants
[i
]), j
);
6524 HeapFree(GetProcessHeap(), 0, skip_constants_buffer
);
6525 HeapFree(GetProcessHeap(), 0, skip_constants
);
6526 return D3DERR_INVALIDCALL
;
6532 TRACE("skip_constants parameter %s not found.\n",
6533 debugstr_a(skip_constants
[i
]));
6537 HeapFree(GetProcessHeap(), 0, skip_constants_buffer
);
6538 HeapFree(GetProcessHeap(), 0, skip_constants
);
6540 /* initialize defaults - check because of unsupported ascii effects */
6541 if (effect
->techniques
)
6543 effect
->active_technique
= &effect
->techniques
[0];
6544 effect
->active_pass
= NULL
;
6550 HRESULT WINAPI
D3DXCreateEffectEx(struct IDirect3DDevice9
*device
, const void *srcdata
, UINT srcdatalen
,
6551 const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, const char *skip_constants
, DWORD flags
,
6552 struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilation_errors
)
6554 struct d3dx_effect
*object
;
6557 TRACE("device %p, srcdata %p, srcdatalen %u, defines %p, include %p,"
6558 " skip_constants %p, flags %#x, pool %p, effect %p, compilation_errors %p.\n",
6559 device
, srcdata
, srcdatalen
, defines
, include
,
6560 skip_constants
, flags
, pool
, effect
, compilation_errors
);
6562 if (compilation_errors
)
6563 *compilation_errors
= NULL
;
6565 if (!device
|| !srcdata
)
6566 return D3DERR_INVALIDCALL
;
6571 /* Native dll allows effect to be null so just return D3D_OK after doing basic checks */
6575 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
6577 return E_OUTOFMEMORY
;
6579 hr
= d3dx9_effect_init(object
, device
, srcdata
, srcdatalen
, (const D3D_SHADER_MACRO
*)defines
,
6580 (ID3DInclude
*)include
, flags
, (ID3DBlob
**)compilation_errors
, pool
, skip_constants
);
6583 WARN("Failed to create effect object, hr %#x.\n", hr
);
6584 d3dx_effect_cleanup(object
);
6588 *effect
= &object
->ID3DXEffect_iface
;
6590 TRACE("Created ID3DXEffect %p\n", object
);
6595 HRESULT WINAPI
D3DXCreateEffect(struct IDirect3DDevice9
*device
, const void *srcdata
, UINT srcdatalen
,
6596 const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, DWORD flags
,
6597 struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilation_errors
)
6599 TRACE("(%p, %p, %u, %p, %p, %#x, %p, %p, %p): Forwarded to D3DXCreateEffectEx\n", device
, srcdata
, srcdatalen
, defines
,
6600 include
, flags
, pool
, effect
, compilation_errors
);
6602 return D3DXCreateEffectEx(device
, srcdata
, srcdatalen
, defines
, include
, NULL
, flags
, pool
, effect
, compilation_errors
);
6605 static HRESULT
d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl
*compiler
,
6606 const char *data
, SIZE_T data_size
, const D3D_SHADER_MACRO
*defines
, ID3DInclude
*include
,
6607 UINT eflags
, ID3DBlob
**error_messages
)
6609 TRACE("compiler %p, data %p, data_size %lu, defines %p, include %p, eflags %#x, error_messages %p.\n",
6610 compiler
, data
, data_size
, defines
, include
, eflags
, error_messages
);
6612 compiler
->ID3DXEffectCompiler_iface
.lpVtbl
= &ID3DXEffectCompiler_Vtbl
;
6615 FIXME("ID3DXEffectCompiler implementation is only a stub.\n");
6620 HRESULT WINAPI
D3DXCreateEffectCompiler(const char *srcdata
, UINT srcdatalen
, const D3DXMACRO
*defines
,
6621 ID3DXInclude
*include
, DWORD flags
, ID3DXEffectCompiler
**compiler
, ID3DXBuffer
**parse_errors
)
6623 struct ID3DXEffectCompilerImpl
*object
;
6626 TRACE("srcdata %p, srcdatalen %u, defines %p, include %p, flags %#x, compiler %p, parse_errors %p\n",
6627 srcdata
, srcdatalen
, defines
, include
, flags
, compiler
, parse_errors
);
6629 if (!srcdata
|| !compiler
)
6631 WARN("Invalid arguments supplied\n");
6632 return D3DERR_INVALIDCALL
;
6635 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
6637 return E_OUTOFMEMORY
;
6639 hr
= d3dx9_effect_compiler_init(object
, srcdata
, srcdatalen
, (const D3D_SHADER_MACRO
*)defines
,
6640 (ID3DInclude
*)include
, flags
, (ID3DBlob
**)parse_errors
);
6643 WARN("Failed to initialize effect compiler\n");
6644 HeapFree(GetProcessHeap(), 0, object
);
6648 *compiler
= &object
->ID3DXEffectCompiler_iface
;
6650 TRACE("Created ID3DXEffectCompiler %p\n", object
);
6655 /*** IUnknown methods ***/
6656 static HRESULT WINAPI
d3dx_effect_pool_QueryInterface(ID3DXEffectPool
*iface
, REFIID riid
, void **object
)
6658 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
6660 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
6661 IsEqualGUID(riid
, &IID_ID3DXEffectPool
))
6663 iface
->lpVtbl
->AddRef(iface
);
6668 WARN("Interface %s not found\n", debugstr_guid(riid
));
6670 return E_NOINTERFACE
;
6673 static ULONG WINAPI
d3dx_effect_pool_AddRef(ID3DXEffectPool
*iface
)
6675 struct d3dx_effect_pool
*pool
= impl_from_ID3DXEffectPool(iface
);
6676 ULONG refcount
= InterlockedIncrement(&pool
->refcount
);
6678 TRACE("%p increasing refcount to %u.\n", pool
, refcount
);
6683 static void free_effect_pool(struct d3dx_effect_pool
*pool
)
6687 for (i
= 0; i
< pool
->size
; ++i
)
6689 if (pool
->shared_data
[i
].count
)
6693 WARN("Releasing pool with referenced parameters.\n");
6695 param_set_data_pointer(&pool
->shared_data
[i
].parameters
[0]->param
, NULL
, FALSE
, TRUE
);
6696 pool
->shared_data
[i
].parameters
[0]->shared_data
= NULL
;
6698 for (j
= 1; j
< pool
->shared_data
[i
].count
; ++j
)
6700 walk_parameter_tree(&pool
->shared_data
[i
].parameters
[j
]->param
, param_zero_data_func
, NULL
);
6701 pool
->shared_data
[i
].parameters
[j
]->shared_data
= NULL
;
6703 HeapFree(GetProcessHeap(), 0, pool
->shared_data
[i
].parameters
);
6706 HeapFree(GetProcessHeap(), 0, pool
->shared_data
);
6707 HeapFree(GetProcessHeap(), 0, pool
);
6710 static ULONG WINAPI
d3dx_effect_pool_Release(ID3DXEffectPool
*iface
)
6712 struct d3dx_effect_pool
*pool
= impl_from_ID3DXEffectPool(iface
);
6713 ULONG refcount
= InterlockedDecrement(&pool
->refcount
);
6715 TRACE("%p decreasing refcount to %u.\n", pool
, refcount
);
6718 free_effect_pool(pool
);
6723 static const struct ID3DXEffectPoolVtbl ID3DXEffectPool_Vtbl
=
6725 /*** IUnknown methods ***/
6726 d3dx_effect_pool_QueryInterface
,
6727 d3dx_effect_pool_AddRef
,
6728 d3dx_effect_pool_Release
6731 static inline struct d3dx_effect_pool
*unsafe_impl_from_ID3DXEffectPool(ID3DXEffectPool
*iface
)
6736 assert(iface
->lpVtbl
== &ID3DXEffectPool_Vtbl
);
6737 return impl_from_ID3DXEffectPool(iface
);
6740 HRESULT WINAPI
D3DXCreateEffectPool(ID3DXEffectPool
**pool
)
6742 struct d3dx_effect_pool
*object
;
6744 TRACE("pool %p.\n", pool
);
6747 return D3DERR_INVALIDCALL
;
6749 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
6751 return E_OUTOFMEMORY
;
6753 object
->ID3DXEffectPool_iface
.lpVtbl
= &ID3DXEffectPool_Vtbl
;
6754 object
->refcount
= 1;
6756 *pool
= &object
->ID3DXEffectPool_iface
;
6761 HRESULT WINAPI
D3DXCreateEffectFromFileExW(struct IDirect3DDevice9
*device
, const WCHAR
*srcfile
,
6762 const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, const char *skipconstants
, DWORD flags
,
6763 struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6765 struct d3dx_include_from_file include_from_file
;
6771 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6772 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6773 device
, debugstr_w(srcfile
), defines
, include
, debugstr_a(skipconstants
),
6774 flags
, pool
, effect
, compilationerrors
);
6776 if (!device
|| !srcfile
)
6777 return D3DERR_INVALIDCALL
;
6781 include_from_file
.ID3DXInclude_iface
.lpVtbl
= &d3dx_include_from_file_vtbl
;
6782 include
= &include_from_file
.ID3DXInclude_iface
;
6785 size
= WideCharToMultiByte(CP_ACP
, 0, srcfile
, -1, NULL
, 0, NULL
, NULL
);
6786 filename_a
= heap_alloc(size
);
6788 return E_OUTOFMEMORY
;
6789 WideCharToMultiByte(CP_ACP
, 0, srcfile
, -1, filename_a
, size
, NULL
, NULL
);
6791 EnterCriticalSection(&from_file_mutex
);
6792 ret
= ID3DXInclude_Open(include
, D3DXINC_LOCAL
, filename_a
, NULL
, &buffer
, &size
);
6795 LeaveCriticalSection(&from_file_mutex
);
6796 heap_free(filename_a
);
6797 return D3DXERR_INVALIDDATA
;
6800 ret
= D3DXCreateEffectEx(device
, buffer
, size
, defines
, include
, skipconstants
, flags
, pool
,
6801 effect
, compilationerrors
);
6803 ID3DXInclude_Close(include
, buffer
);
6804 LeaveCriticalSection(&from_file_mutex
);
6805 heap_free(filename_a
);
6809 HRESULT WINAPI
D3DXCreateEffectFromFileExA(struct IDirect3DDevice9
*device
, const char *srcfile
,
6810 const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, const char *skipconstants
, DWORD flags
,
6811 struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6817 TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
6818 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6819 device
, debugstr_a(srcfile
), defines
, include
, debugstr_a(skipconstants
),
6820 flags
, pool
, effect
, compilationerrors
);
6823 return D3DERR_INVALIDCALL
;
6825 len
= MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, NULL
, 0);
6826 srcfileW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(*srcfileW
));
6827 MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, srcfileW
, len
);
6829 ret
= D3DXCreateEffectFromFileExW(device
, srcfileW
, defines
, include
, skipconstants
, flags
, pool
, effect
, compilationerrors
);
6830 HeapFree(GetProcessHeap(), 0, srcfileW
);
6835 HRESULT WINAPI
D3DXCreateEffectFromFileW(struct IDirect3DDevice9
*device
, const WCHAR
*srcfile
,
6836 const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, DWORD flags
, struct ID3DXEffectPool
*pool
,
6837 struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6839 TRACE("(void): relay\n");
6840 return D3DXCreateEffectFromFileExW(device
, srcfile
, defines
, include
, NULL
, flags
, pool
, effect
, compilationerrors
);
6843 HRESULT WINAPI
D3DXCreateEffectFromFileA(struct IDirect3DDevice9
*device
, const char *srcfile
,
6844 const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, DWORD flags
, struct ID3DXEffectPool
*pool
,
6845 struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6847 TRACE("(void): relay\n");
6848 return D3DXCreateEffectFromFileExA(device
, srcfile
, defines
, include
, NULL
, flags
, pool
, effect
, compilationerrors
);
6851 HRESULT WINAPI
D3DXCreateEffectFromResourceExW(struct IDirect3DDevice9
*device
, HMODULE srcmodule
,
6852 const WCHAR
*srcresource
, const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, const char *skipconstants
,
6853 DWORD flags
, struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6859 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6860 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6861 device
, srcmodule
, debugstr_w(srcresource
), defines
, include
, debugstr_a(skipconstants
),
6862 flags
, pool
, effect
, compilationerrors
);
6865 return D3DERR_INVALIDCALL
;
6867 if (!(resinfo
= FindResourceW(srcmodule
, srcresource
, (const WCHAR
*)RT_RCDATA
)))
6868 return D3DXERR_INVALIDDATA
;
6870 if (FAILED(load_resource_into_memory(srcmodule
, resinfo
, &buffer
, &size
)))
6871 return D3DXERR_INVALIDDATA
;
6873 return D3DXCreateEffectEx(device
, buffer
, size
, defines
, include
,
6874 skipconstants
, flags
, pool
, effect
, compilationerrors
);
6877 HRESULT WINAPI
D3DXCreateEffectFromResourceExA(struct IDirect3DDevice9
*device
, HMODULE srcmodule
,
6878 const char *srcresource
, const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, const char *skipconstants
,
6879 DWORD flags
, struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6885 TRACE("device %p, srcmodule %p, srcresource %s, defines %p, include %p, skipconstants %s, "
6886 "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
6887 device
, srcmodule
, debugstr_a(srcresource
), defines
, include
, debugstr_a(skipconstants
),
6888 flags
, pool
, effect
, compilationerrors
);
6891 return D3DERR_INVALIDCALL
;
6893 if (!(resinfo
= FindResourceA(srcmodule
, srcresource
, (const char *)RT_RCDATA
)))
6894 return D3DXERR_INVALIDDATA
;
6896 if (FAILED(load_resource_into_memory(srcmodule
, resinfo
, &buffer
, &size
)))
6897 return D3DXERR_INVALIDDATA
;
6899 return D3DXCreateEffectEx(device
, buffer
, size
, defines
, include
,
6900 skipconstants
, flags
, pool
, effect
, compilationerrors
);
6903 HRESULT WINAPI
D3DXCreateEffectFromResourceW(struct IDirect3DDevice9
*device
, HMODULE srcmodule
,
6904 const WCHAR
*srcresource
, const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, DWORD flags
,
6905 struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6907 TRACE("(void): relay\n");
6908 return D3DXCreateEffectFromResourceExW(device
, srcmodule
, srcresource
, defines
, include
, NULL
, flags
, pool
, effect
, compilationerrors
);
6911 HRESULT WINAPI
D3DXCreateEffectFromResourceA(struct IDirect3DDevice9
*device
, HMODULE srcmodule
,
6912 const char *srcresource
, const D3DXMACRO
*defines
, struct ID3DXInclude
*include
, DWORD flags
,
6913 struct ID3DXEffectPool
*pool
, struct ID3DXEffect
**effect
, struct ID3DXBuffer
**compilationerrors
)
6915 TRACE("(void): relay\n");
6916 return D3DXCreateEffectFromResourceExA(device
, srcmodule
, srcresource
, defines
, include
, NULL
, flags
, pool
, effect
, compilationerrors
);
6919 HRESULT WINAPI
D3DXCreateEffectCompilerFromFileW(const WCHAR
*srcfile
, const D3DXMACRO
*defines
,
6920 ID3DXInclude
*include
, DWORD flags
, ID3DXEffectCompiler
**effectcompiler
, ID3DXBuffer
**parseerrors
)
6926 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6927 debugstr_w(srcfile
), defines
, include
, flags
, effectcompiler
, parseerrors
);
6930 return D3DERR_INVALIDCALL
;
6932 ret
= map_view_of_file(srcfile
, &buffer
, &size
);
6935 return D3DXERR_INVALIDDATA
;
6937 ret
= D3DXCreateEffectCompiler(buffer
, size
, defines
, include
, flags
, effectcompiler
, parseerrors
);
6938 UnmapViewOfFile(buffer
);
6943 HRESULT WINAPI
D3DXCreateEffectCompilerFromFileA(const char *srcfile
, const D3DXMACRO
*defines
,
6944 ID3DXInclude
*include
, DWORD flags
, ID3DXEffectCompiler
**effectcompiler
, ID3DXBuffer
**parseerrors
)
6950 TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6951 debugstr_a(srcfile
), defines
, include
, flags
, effectcompiler
, parseerrors
);
6954 return D3DERR_INVALIDCALL
;
6956 len
= MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, NULL
, 0);
6957 srcfileW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(*srcfileW
));
6958 MultiByteToWideChar(CP_ACP
, 0, srcfile
, -1, srcfileW
, len
);
6960 ret
= D3DXCreateEffectCompilerFromFileW(srcfileW
, defines
, include
, flags
, effectcompiler
, parseerrors
);
6961 HeapFree(GetProcessHeap(), 0, srcfileW
);
6966 HRESULT WINAPI
D3DXCreateEffectCompilerFromResourceA(HMODULE srcmodule
, const char *srcresource
,
6967 const D3DXMACRO
*defines
, ID3DXInclude
*include
, DWORD flags
,
6968 ID3DXEffectCompiler
**effectcompiler
, ID3DXBuffer
**parseerrors
)
6974 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6975 srcmodule
, debugstr_a(srcresource
), defines
, include
, flags
, effectcompiler
, parseerrors
);
6977 if (!(resinfo
= FindResourceA(srcmodule
, srcresource
, (const char *)RT_RCDATA
)))
6978 return D3DXERR_INVALIDDATA
;
6980 if (FAILED(load_resource_into_memory(srcmodule
, resinfo
, &buffer
, &size
)))
6981 return D3DXERR_INVALIDDATA
;
6983 return D3DXCreateEffectCompiler(buffer
, size
, defines
, include
, flags
, effectcompiler
, parseerrors
);
6986 HRESULT WINAPI
D3DXCreateEffectCompilerFromResourceW(HMODULE srcmodule
, const WCHAR
*srcresource
,
6987 const D3DXMACRO
*defines
, ID3DXInclude
*include
, DWORD flags
,
6988 ID3DXEffectCompiler
**effectcompiler
, ID3DXBuffer
**parseerrors
)
6994 TRACE("srcmodule %p, srcresource %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
6995 srcmodule
, debugstr_w(srcresource
), defines
, include
, flags
, effectcompiler
, parseerrors
);
6997 if (!(resinfo
= FindResourceW(srcmodule
, srcresource
, (const WCHAR
*)RT_RCDATA
)))
6998 return D3DXERR_INVALIDDATA
;
7000 if (FAILED(load_resource_into_memory(srcmodule
, resinfo
, &buffer
, &size
)))
7001 return D3DXERR_INVALIDDATA
;
7003 return D3DXCreateEffectCompiler(buffer
, size
, defines
, include
, flags
, effectcompiler
, parseerrors
);
7006 HRESULT WINAPI
D3DXDisassembleEffect(ID3DXEffect
*effect
, BOOL enable_color_code
, ID3DXBuffer
**disassembly
)
7008 FIXME("(%p, %u, %p): stub\n", effect
, enable_color_code
, disassembly
);
7010 return D3DXERR_INVALIDDATA
;