[D3DX9_36]
authorAmine Khaldi <amine.khaldi@reactos.org>
Sat, 19 Apr 2014 18:58:53 +0000 (18:58 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sat, 19 Apr 2014 18:58:53 +0000 (18:58 +0000)
* Sync with Wine 1.7.17.
CORE-8080

svn path=/trunk/; revision=62819

18 files changed:
reactos/dll/directx/wine/d3dx9_36/core.c
reactos/dll/directx/wine/d3dx9_36/d3dx9_36_main.c
reactos/dll/directx/wine/d3dx9_36/d3dx9_36_private.h
reactos/dll/directx/wine/d3dx9_36/effect.c
reactos/dll/directx/wine/d3dx9_36/line.c
reactos/dll/directx/wine/d3dx9_36/math.c
reactos/dll/directx/wine/d3dx9_36/mesh.c
reactos/dll/directx/wine/d3dx9_36/render.c
reactos/dll/directx/wine/d3dx9_36/shader.c
reactos/dll/directx/wine/d3dx9_36/skin.c
reactos/dll/directx/wine/d3dx9_36/sprite.c
reactos/dll/directx/wine/d3dx9_36/surface.c
reactos/dll/directx/wine/d3dx9_36/texture.c
reactos/dll/directx/wine/d3dx9_36/util.c
reactos/dll/directx/wine/d3dx9_36/version.rc
reactos/dll/directx/wine/d3dx9_36/volume.c
reactos/dll/directx/wine/d3dx9_36/xfile.c
reactos/media/doc/README.WINE

index d0167a4..51cb53a 100644 (file)
@@ -76,7 +76,7 @@ static ULONG WINAPI ID3DXBufferImpl_Release(ID3DXBuffer *iface)
     return ref;
 }
 
-static LPVOID WINAPI ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer *iface)
+static void * WINAPI ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer *iface)
 {
     struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
 
index e85b215..a335475 100644 (file)
@@ -25,7 +25,7 @@
 /***********************************************************************
  * DllMain.
  */
-BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
+BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
 {
     switch(reason)
     {
index a505372..fef9ac6 100644 (file)
@@ -84,7 +84,7 @@ struct pixel_format_desc {
 };
 
 HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN;
-HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, LPVOID *buffer, DWORD *length) DECLSPEC_HIDDEN;
+HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN;
 
 HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPEC_HIDDEN;
 
@@ -104,7 +104,8 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic
     const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette) DECLSPEC_HIDDEN;
 
 HRESULT load_texture_from_dds(IDirect3DTexture9 *texture, const void *src_data, const PALETTEENTRY *palette,
-    DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
+        DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info, unsigned int skip_levels,
+        unsigned int *loaded_miplevels) DECLSPEC_HIDDEN;
 HRESULT load_cube_texture_from_dds(IDirect3DCubeTexture9 *cube_texture, const void *src_data,
     const PALETTEENTRY *palette, DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
 HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
@@ -114,6 +115,7 @@ HRESULT load_volume_texture_from_dds(IDirect3DVolumeTexture9 *volume_texture, co
     const PALETTEENTRY *palette, DWORD filter, DWORD color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
 
 unsigned short float_32_to_16(const float in) DECLSPEC_HIDDEN;
+float float_16_to_32(const unsigned short in) DECLSPEC_HIDDEN;
 
 /* debug helpers */
 const char *debug_d3dxparameter_class(D3DXPARAMETER_CLASS c) DECLSPEC_HIDDEN;
@@ -121,6 +123,7 @@ const char *debug_d3dxparameter_type(D3DXPARAMETER_TYPE t) DECLSPEC_HIDDEN;
 const char *debug_d3dxparameter_registerset(D3DXREGISTER_SET r) DECLSPEC_HIDDEN;
 
 /* parameter type conversion helpers */
-void set_number(LPVOID outdata, D3DXPARAMETER_TYPE outtype, LPCVOID indata, D3DXPARAMETER_TYPE intype) DECLSPEC_HIDDEN;
+void set_number(void *outdata, D3DXPARAMETER_TYPE outtype,
+        const void *indata, D3DXPARAMETER_TYPE intype) DECLSPEC_HIDDEN;
 
 #endif /* __WINE_D3DX9_36_PRIVATE_H */
index eaaaa16..98d9c43 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright 2010 Christian Costa
- * Copyright 2011 Rico Schأ¼ller
+ * Copyright 2011 Rico Schüller
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 
 #include "d3dx9_36_private.h"
 
+#include <d3dcompiler.h>
+
 /* Constants for special INT/FLOAT conversation */
 #define INT_FLOAT_MULTI 255.0f
 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
 
+#define INITIAL_PARAM_TABLE_SIZE 16
+
 enum STATE_CLASS
 {
     SC_LIGHTENABLE,
@@ -83,6 +87,7 @@ enum STATE_TYPE
     ST_CONSTANT,
     ST_PARAMETER,
     ST_FXLC,
+    ST_ARRAY_SELECTOR,
 };
 
 struct d3dx_parameter
@@ -99,9 +104,21 @@ struct d3dx_parameter
     UINT member_count;
     DWORD flags;
     UINT bytes;
+    DWORD object_id;
+
+    D3DXHANDLE handle;
 
     struct d3dx_parameter *annotations;
     struct d3dx_parameter *members;
+
+    struct d3dx_parameter *referenced_param;
+};
+
+struct d3dx_object
+{
+    UINT size;
+    void *data;
+    struct d3dx_parameter *param;
 };
 
 struct d3dx_state
@@ -109,7 +126,7 @@ struct d3dx_state
     UINT operation;
     UINT index;
     enum STATE_TYPE type;
-    struct d3dx_parameter *parameter;
+    struct d3dx_parameter parameter;
 };
 
 struct d3dx_sampler
@@ -138,15 +155,25 @@ struct d3dx_technique
     struct d3dx_pass *passes;
 };
 
+struct param_table
+{
+    struct d3dx_parameter **table;
+    unsigned int count, size;
+};
+
 struct d3dx9_base_effect
 {
     struct ID3DXEffectImpl *effect;
 
     UINT parameter_count;
     UINT technique_count;
+    UINT object_count;
 
     struct d3dx_parameter *parameters;
     struct d3dx_technique *techniques;
+    struct d3dx_object *objects;
+
+    struct param_table param_table;
 };
 
 struct ID3DXEffectImpl
@@ -177,8 +204,9 @@ static struct d3dx_parameter *get_parameter_by_name(struct d3dx9_base_effect *ba
         struct d3dx_parameter *parameter, const char *name);
 static struct d3dx_parameter *get_annotation_by_name(UINT count, struct d3dx_parameter *parameters,
         const char *name);
-static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects);
-static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOOL child, enum STATE_TYPE st);
+static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
+        const char *data, const char **ptr, struct d3dx_object *objects);
+static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child);
 
 static const struct
 {
@@ -402,14 +430,9 @@ static void skip_dword_unknown(const char **ptr, unsigned int count)
     }
 }
 
-static inline struct d3dx_parameter *get_parameter_struct(D3DXHANDLE handle)
-{
-    return (struct d3dx_parameter *) handle;
-}
-
 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
 {
-    return (D3DXHANDLE) parameter;
+    return parameter ? parameter->handle : NULL;
 }
 
 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
@@ -468,81 +491,24 @@ static struct d3dx_pass *get_valid_pass(struct d3dx9_base_effect *base, D3DXHAND
     return NULL;
 }
 
-static struct d3dx_parameter *get_valid_sub_parameter(struct d3dx_parameter *param, D3DXHANDLE parameter)
-{
-    unsigned int i, count;
-    struct d3dx_parameter *p;
-
-    for (i = 0; i < param->annotation_count; ++i)
-    {
-        if (get_parameter_handle(&param->annotations[i]) == parameter)
-            return &param->annotations[i];
-
-        p = get_valid_sub_parameter(&param->annotations[i], parameter);
-        if (p) return p;
-    }
-
-    count = param->element_count ? param->element_count : param->member_count;
-    for (i = 0; i < count; ++i)
-    {
-        if (get_parameter_handle(&param->members[i]) == parameter)
-            return &param->members[i];
-
-        p = get_valid_sub_parameter(&param->members[i], parameter);
-        if (p) return p;
-    }
-
-    return NULL;
-}
-
 static struct d3dx_parameter *get_valid_parameter(struct d3dx9_base_effect *base, D3DXHANDLE parameter)
 {
-    unsigned int i, k, m;
-    struct d3dx_parameter *p;
-
-    for (i = 0; i < base->parameter_count; ++i)
-    {
-        if (get_parameter_handle(&base->parameters[i]) == parameter)
-            return &base->parameters[i];
-
-        p = get_valid_sub_parameter(&base->parameters[i], parameter);
-        if (p) return p;
-    }
-
-    for (i = 0; i < base->technique_count; ++i)
-    {
-        struct d3dx_technique *technique = &base->techniques[i];
-
-        for (k = 0; k < technique->pass_count; ++k)
-        {
-            struct d3dx_pass *pass = &technique->passes[k];
-
-            for (m = 0; m < pass->annotation_count; ++m)
-            {
-                if (get_parameter_handle(&pass->annotations[m]) == parameter)
-                    return &pass->annotations[m];
-
-                p = get_valid_sub_parameter(&pass->annotations[m], parameter);
-                if (p) return p;
-            }
-        }
+    struct d3dx_parameter **handle_param = (struct d3dx_parameter **)parameter;
 
-        for (k = 0; k < technique->annotation_count; ++k)
-        {
-            if (get_parameter_handle(&technique->annotations[k]) == parameter)
-                return &technique->annotations[k];
-
-            p = get_valid_sub_parameter(&technique->annotations[k], parameter);
-            if (p) return p;
-        }
-    }
+    if (handle_param >= base->param_table.table && handle_param < base->param_table.table + base->param_table.count)
+        return *handle_param;
 
     return get_parameter_by_name(base, NULL, parameter);
 }
 
 static void free_state(struct d3dx_state *state)
 {
-    free_parameter_state(state->parameter, FALSE, FALSE, state->type);
+    free_parameter(&state->parameter, FALSE, FALSE);
+}
+
+static void free_object(struct d3dx_object *object)
+{
+    HeapFree(GetProcessHeap(), 0, object->data);
 }
 
 static void free_sampler(struct d3dx_sampler *sampler)
@@ -557,16 +523,11 @@ static void free_sampler(struct d3dx_sampler *sampler)
 }
 
 static void free_parameter(struct d3dx_parameter *param, BOOL element, BOOL child)
-{
-    free_parameter_state(param, element, child, ST_CONSTANT);
-}
-
-static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOOL child, enum STATE_TYPE st)
 {
     unsigned int i;
 
-    TRACE("Free parameter %p, name %s, type %s, child %s, state_type %x\n", param, param->name,
-            debug_d3dxparameter_type(param->type), child ? "yes" : "no", st);
+    TRACE("Free parameter %p, name %s, type %s, child %s\n", param, param->name,
+            debug_d3dxparameter_type(param->type), child ? "yes" : "no");
 
     if (!param)
         return;
@@ -594,8 +555,7 @@ static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOO
         switch (param->type)
         {
             case D3DXPT_STRING:
-                HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
-                if (!child) HeapFree(GetProcessHeap(), 0, param->data);
+                HeapFree(GetProcessHeap(), 0, *(char **)param->data);
                 break;
 
             case D3DXPT_TEXTURE:
@@ -605,15 +565,7 @@ static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOO
             case D3DXPT_TEXTURECUBE:
             case D3DXPT_PIXELSHADER:
             case D3DXPT_VERTEXSHADER:
-                if (st == ST_CONSTANT)
-                {
-                    if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
-                }
-                else
-                {
-                    HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
-                }
-                if (!child) HeapFree(GetProcessHeap(), 0, param->data);
+                if (*(IUnknown **)param->data) IUnknown_Release(*(IUnknown **)param->data);
                 break;
 
             case D3DXPT_SAMPLER:
@@ -621,16 +573,7 @@ static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOO
             case D3DXPT_SAMPLER2D:
             case D3DXPT_SAMPLER3D:
             case D3DXPT_SAMPLERCUBE:
-                if (st == ST_CONSTANT)
-                {
-                    free_sampler((struct d3dx_sampler *)param->data);
-                }
-                else
-                {
-                    HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
-                }
-                /* samplers have always own data, so free that */
-                HeapFree(GetProcessHeap(), 0, param->data);
+                free_sampler((struct d3dx_sampler *)param->data);
                 break;
 
             default:
@@ -638,16 +581,10 @@ static void free_parameter_state(struct d3dx_parameter *param, BOOL element, BOO
                 break;
         }
     }
-    else
+
+    if (!child)
     {
-        if (!child)
-        {
-            if (st != ST_CONSTANT)
-            {
-                HeapFree(GetProcessHeap(), 0, *(LPSTR *)param->data);
-            }
-            HeapFree(GetProcessHeap(), 0, param->data);
-        }
+        HeapFree(GetProcessHeap(), 0, param->data);
     }
 
     /* only the parent has to release name and semantic */
@@ -722,6 +659,8 @@ static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
 
     TRACE("base %p.\n", base);
 
+    HeapFree(GetProcessHeap(), 0, base->param_table.table);
+
     if (base->parameters)
     {
         for (i = 0; i < base->parameter_count; ++i)
@@ -737,6 +676,16 @@ static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
         HeapFree(GetProcessHeap(), 0, base->techniques);
         base->techniques = NULL;
     }
+
+    if (base->objects)
+    {
+        for (i = 0; i < base->object_count; ++i)
+        {
+            free_object(&base->objects[i]);
+        }
+        HeapFree(GetProcessHeap(), 0, base->objects);
+        base->objects = NULL;
+    }
 }
 
 static void free_effect(struct ID3DXEffectImpl *effect)
@@ -778,7 +727,7 @@ static void get_vector(struct d3dx_parameter *param, D3DXVECTOR4 *vector)
     }
 }
 
-static void set_vector(struct d3dx_parameter *param, CONST D3DXVECTOR4 *vector)
+static void set_vector(struct d3dx_parameter *param, const D3DXVECTOR4 *vector)
 {
     UINT i;
 
@@ -806,7 +755,31 @@ static void get_matrix(struct d3dx_parameter *param, D3DXMATRIX *matrix, BOOL tr
     }
 }
 
-static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix, BOOL transpose)
+static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
+{
+    UINT i, k;
+
+    if (param->type == D3DXPT_FLOAT)
+    {
+        if (param->columns == 4)
+            memcpy(param->data, matrix->u.m, param->rows * 4 * sizeof(float));
+        else
+            for (i = 0; i < param->rows; ++i)
+                memcpy((float *)param->data + i * param->columns, matrix->u.m + i, param->columns * sizeof(float));
+        return;
+    }
+
+    for (i = 0; i < param->rows; ++i)
+    {
+        for (k = 0; k < param->columns; ++k)
+        {
+            set_number((FLOAT *)param->data + i * param->columns + k, param->type,
+                    &matrix->u.m[i][k], D3DXPT_FLOAT);
+        }
+    }
+}
+
+static void set_matrix_transpose(struct d3dx_parameter *param, const D3DXMATRIX *matrix)
 {
     UINT i, k;
 
@@ -815,7 +788,7 @@ static void set_matrix(struct d3dx_parameter *param, const D3DXMATRIX *matrix, B
         for (k = 0; k < param->columns; ++k)
         {
             set_number((FLOAT *)param->data + i * param->columns + k, param->type,
-                    transpose ? &matrix->u.m[k][i] : &matrix->u.m[i][k], D3DXPT_FLOAT);
+                    &matrix->u.m[k][i], D3DXPT_FLOAT);
         }
     }
 }
@@ -1082,7 +1055,7 @@ static D3DXHANDLE d3dx9_base_effect_get_parameter(struct d3dx9_base_effect *base
         }
     }
 
-    WARN("Invalid argument specified.\n");
+    WARN("Parameter not found.\n");
 
     return NULL;
 }
@@ -1160,7 +1133,7 @@ static D3DXHANDLE d3dx9_base_effect_get_parameter_by_semantic(struct d3dx9_base_
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return NULL;
 }
@@ -1187,7 +1160,7 @@ static D3DXHANDLE d3dx9_base_effect_get_parameter_element(struct d3dx9_base_effe
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return NULL;
 }
@@ -1216,7 +1189,7 @@ static D3DXHANDLE d3dx9_base_effect_get_technique_by_name(struct d3dx9_base_effe
         return t;
     }
 
-    WARN("Invalid argument specified.\n");
+    WARN("Technique not found.\n");
 
     return NULL;
 }
@@ -1232,7 +1205,7 @@ static D3DXHANDLE d3dx9_base_effect_get_pass(struct d3dx9_base_effect *base,
         return get_pass_handle(&tech->passes[index]);
     }
 
-    WARN("Invalid argument specified.\n");
+    WARN("Pass not found.\n");
 
     return NULL;
 }
@@ -1258,7 +1231,7 @@ static D3DXHANDLE d3dx9_base_effect_get_pass_by_name(struct d3dx9_base_effect *b
         }
     }
 
-    WARN("Invalid argument specified.\n");
+    WARN("Pass not found.\n");
 
     return NULL;
 }
@@ -1320,7 +1293,7 @@ static D3DXHANDLE d3dx9_base_effect_get_annotation(struct d3dx9_base_effect *bas
         return get_parameter_handle(&annotations[index]);
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Annotation not found.\n");
 
     return NULL;
 }
@@ -1347,7 +1320,7 @@ static D3DXHANDLE d3dx9_base_effect_get_annotation_by_name(struct d3dx9_base_eff
         return get_parameter_handle(annotation);
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Annotation not found.\n");
 
     return NULL;
 }
@@ -1458,7 +1431,7 @@ static HRESULT d3dx9_base_effect_get_value(struct d3dx9_base_effect *base,
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1473,7 +1446,7 @@ static HRESULT d3dx9_base_effect_set_bool(struct d3dx9_base_effect *base, D3DXHA
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1489,7 +1462,7 @@ static HRESULT d3dx9_base_effect_get_bool(struct d3dx9_base_effect *base, D3DXHA
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1527,7 +1500,7 @@ static HRESULT d3dx9_base_effect_set_bool_array(struct d3dx9_base_effect *base,
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1551,7 +1524,7 @@ static HRESULT d3dx9_base_effect_get_bool_array(struct d3dx9_base_effect *base,
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1588,7 +1561,7 @@ static HRESULT d3dx9_base_effect_set_int(struct d3dx9_base_effect *base, D3DXHAN
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1626,7 +1599,7 @@ static HRESULT d3dx9_base_effect_get_int(struct d3dx9_base_effect *base, D3DXHAN
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1663,7 +1636,7 @@ static HRESULT d3dx9_base_effect_set_int_array(struct d3dx9_base_effect *base,
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1687,7 +1660,7 @@ static HRESULT d3dx9_base_effect_get_int_array(struct d3dx9_base_effect *base,
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1702,7 +1675,7 @@ static HRESULT d3dx9_base_effect_set_float(struct d3dx9_base_effect *base, D3DXH
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1718,7 +1691,7 @@ static HRESULT d3dx9_base_effect_get_float(struct d3dx9_base_effect *base, D3DXH
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1755,7 +1728,7 @@ static HRESULT d3dx9_base_effect_set_float_array(struct d3dx9_base_effect *base,
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1779,7 +1752,7 @@ static HRESULT d3dx9_base_effect_get_float_array(struct d3dx9_base_effect *base,
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1810,6 +1783,12 @@ static HRESULT d3dx9_base_effect_set_vector(struct d3dx9_base_effect *base,
                     *(INT *)param->data = tmp;
                     return D3D_OK;
                 }
+                if (param->type == D3DXPT_FLOAT)
+                {
+                    memcpy(param->data, vector, param->columns * sizeof(float));
+                    return D3D_OK;
+                }
+
                 set_vector(param, vector);
                 return D3D_OK;
 
@@ -1824,7 +1803,7 @@ static HRESULT d3dx9_base_effect_set_vector(struct d3dx9_base_effect *base,
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1865,7 +1844,7 @@ static HRESULT d3dx9_base_effect_get_vector(struct d3dx9_base_effect *base,
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1884,6 +1863,17 @@ static HRESULT d3dx9_base_effect_set_vector_array(struct d3dx9_base_effect *base
         switch (param->class)
         {
             case D3DXPC_VECTOR:
+                if (param->type == D3DXPT_FLOAT)
+                {
+                    if (param->columns == 4)
+                        memcpy(param->data, vector, count * 4 * sizeof(float));
+                    else
+                        for (i = 0; i < count; ++i)
+                            memcpy((float *)param->data + param->columns * i, vector + i,
+                                    param->columns * sizeof(float));
+                    return D3D_OK;
+                }
+
                 for (i = 0; i < count; ++i)
                 {
                     set_vector(&param->members[i], &vector[i]);
@@ -1902,7 +1892,7 @@ static HRESULT d3dx9_base_effect_set_vector_array(struct d3dx9_base_effect *base
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1941,7 +1931,7 @@ static HRESULT d3dx9_base_effect_get_vector_array(struct d3dx9_base_effect *base
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -1958,7 +1948,7 @@ static HRESULT d3dx9_base_effect_set_matrix(struct d3dx9_base_effect *base,
         switch (param->class)
         {
             case D3DXPC_MATRIX_ROWS:
-                set_matrix(param, matrix, FALSE);
+                set_matrix(param, matrix);
                 return D3D_OK;
 
             case D3DXPC_SCALAR:
@@ -1973,7 +1963,7 @@ static HRESULT d3dx9_base_effect_set_matrix(struct d3dx9_base_effect *base,
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2005,7 +1995,7 @@ static HRESULT d3dx9_base_effect_get_matrix(struct d3dx9_base_effect *base,
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2026,7 +2016,7 @@ static HRESULT d3dx9_base_effect_set_matrix_array(struct d3dx9_base_effect *base
             case D3DXPC_MATRIX_ROWS:
                 for (i = 0; i < count; ++i)
                 {
-                    set_matrix(&param->members[i], &matrix[i], FALSE);
+                    set_matrix(&param->members[i], &matrix[i]);
                 }
                 return D3D_OK;
 
@@ -2042,7 +2032,7 @@ static HRESULT d3dx9_base_effect_set_matrix_array(struct d3dx9_base_effect *base
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2081,7 +2071,7 @@ static HRESULT d3dx9_base_effect_get_matrix_array(struct d3dx9_base_effect *base
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2100,7 +2090,7 @@ static HRESULT d3dx9_base_effect_set_matrix_pointer_array(struct d3dx9_base_effe
             case D3DXPC_MATRIX_ROWS:
                 for (i = 0; i < count; ++i)
                 {
-                    set_matrix(&param->members[i], matrix[i], FALSE);
+                    set_matrix(&param->members[i], matrix[i]);
                 }
                 return D3D_OK;
 
@@ -2115,7 +2105,7 @@ static HRESULT d3dx9_base_effect_set_matrix_pointer_array(struct d3dx9_base_effe
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2153,7 +2143,7 @@ static HRESULT d3dx9_base_effect_get_matrix_pointer_array(struct d3dx9_base_effe
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2170,7 +2160,7 @@ static HRESULT d3dx9_base_effect_set_matrix_transpose(struct d3dx9_base_effect *
         switch (param->class)
         {
             case D3DXPC_MATRIX_ROWS:
-                set_matrix(param, matrix, TRUE);
+                set_matrix_transpose(param, matrix);
                 return D3D_OK;
 
             case D3DXPC_SCALAR:
@@ -2185,7 +2175,7 @@ static HRESULT d3dx9_base_effect_set_matrix_transpose(struct d3dx9_base_effect *
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2220,7 +2210,7 @@ static HRESULT d3dx9_base_effect_get_matrix_transpose(struct d3dx9_base_effect *
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2241,7 +2231,7 @@ static HRESULT d3dx9_base_effect_set_matrix_transpose_array(struct d3dx9_base_ef
             case D3DXPC_MATRIX_ROWS:
                 for (i = 0; i < count; ++i)
                 {
-                    set_matrix(&param->members[i], &matrix[i], TRUE);
+                    set_matrix_transpose(&param->members[i], &matrix[i]);
                 }
                 return D3D_OK;
 
@@ -2257,7 +2247,7 @@ static HRESULT d3dx9_base_effect_set_matrix_transpose_array(struct d3dx9_base_ef
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2296,7 +2286,7 @@ static HRESULT d3dx9_base_effect_get_matrix_transpose_array(struct d3dx9_base_ef
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2315,7 +2305,7 @@ static HRESULT d3dx9_base_effect_set_matrix_transpose_pointer_array(struct d3dx9
             case D3DXPC_MATRIX_ROWS:
                 for (i = 0; i < count; ++i)
                 {
-                    set_matrix(&param->members[i], matrix[i], TRUE);
+                    set_matrix_transpose(&param->members[i], matrix[i]);
                 }
                 return D3D_OK;
 
@@ -2330,7 +2320,7 @@ static HRESULT d3dx9_base_effect_set_matrix_transpose_pointer_array(struct d3dx9
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2368,7 +2358,7 @@ static HRESULT d3dx9_base_effect_get_matrix_transpose_pointer_array(struct d3dx9
         }
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2388,12 +2378,12 @@ static HRESULT d3dx9_base_effect_get_string(struct d3dx9_base_effect *base,
 
     if (string && param && !param->element_count && param->type == D3DXPT_STRING)
     {
-        *string = *(LPCSTR *)param->data;
-        TRACE("Returning %s\n", debugstr_a(*string));
+        *string = *(const char **)param->data;
+        TRACE("Returning %s.\n", debugstr_a(*string));
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2410,6 +2400,9 @@ static HRESULT d3dx9_base_effect_set_texture(struct d3dx9_base_effect *base,
     {
         struct IDirect3DBaseTexture9 *oltexture = *(struct IDirect3DBaseTexture9 **)param->data;
 
+        if (texture == oltexture)
+            return D3D_OK;
+
         if (texture) IDirect3DBaseTexture9_AddRef(texture);
         if (oltexture) IDirect3DBaseTexture9_Release(oltexture);
 
@@ -2418,7 +2411,7 @@ static HRESULT d3dx9_base_effect_set_texture(struct d3dx9_base_effect *base,
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2439,7 +2432,7 @@ static HRESULT d3dx9_base_effect_get_texture(struct d3dx9_base_effect *base,
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2457,7 +2450,7 @@ static HRESULT d3dx9_base_effect_get_pixel_shader(struct d3dx9_base_effect *base
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -2475,7 +2468,7 @@ static HRESULT d3dx9_base_effect_get_vertex_shader(struct d3dx9_base_effect *bas
         return D3D_OK;
     }
 
-    WARN("Invalid argument specified\n");
+    WARN("Parameter not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -3097,7 +3090,7 @@ static HRESULT WINAPI ID3DXEffectImpl_SetTechnique(ID3DXEffect *iface, D3DXHANDL
         return D3D_OK;
     }
 
-    WARN("Invalid argument supplied.\n");
+    WARN("Technique not found.\n");
 
     return D3DERR_INVALIDCALL;
 }
@@ -3143,7 +3136,7 @@ static HRESULT WINAPI ID3DXEffectImpl_Begin(ID3DXEffect *iface, UINT *passes, DW
     struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
     struct d3dx_technique *technique = This->active_technique;
 
-    FIXME("iface %p, passes %p, flags %#x partial stub\n", iface, passes, flags);
+    TRACE("iface %p, passes %p, flags %#x.\n", iface, passes, flags);
 
     if (passes && technique)
     {
@@ -3198,6 +3191,12 @@ static HRESULT WINAPI ID3DXEffectImpl_CommitChanges(ID3DXEffect* iface)
 
     FIXME("(%p)->(): stub\n", This);
 
+    if (!This->active_pass)
+    {
+        WARN("Called without an active pass.\n");
+        return D3D_OK;
+    }
+
     return E_NOTIMPL;
 }
 
@@ -3222,7 +3221,7 @@ static HRESULT WINAPI ID3DXEffectImpl_End(ID3DXEffect *iface)
 {
     struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
 
-    FIXME("iface %p partial stub\n", iface);
+    TRACE("iface %p.\n", iface);
 
     if (!This->started)
         return D3D_OK;
@@ -3358,11 +3357,11 @@ static HRESULT WINAPI ID3DXEffectImpl_CloneEffect(ID3DXEffect *iface,
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect* iface, D3DXHANDLE parameter, LPCVOID data, UINT byte_offset, UINT bytes)
+static HRESULT WINAPI ID3DXEffectImpl_SetRawValue(ID3DXEffect *iface,
+        D3DXHANDLE parameter, const void *data, UINT byte_offset, UINT bytes)
 {
-    struct ID3DXEffectImpl *This = impl_from_ID3DXEffect(iface);
-
-    FIXME("(%p)->(%p, %p, %u, %u): stub\n", This, parameter, data, byte_offset, bytes);
+    FIXME("iface %p, parameter %p, data %p, byte_offset %u, bytes %u stub!\n",
+            iface, parameter, data, byte_offset, bytes);
 
     return E_NOTIMPL;
 }
@@ -4139,17 +4138,17 @@ static const struct ID3DXEffectCompilerVtbl ID3DXEffectCompiler_Vtbl =
     ID3DXEffectCompilerImpl_CompileShader,
 };
 
-static HRESULT d3dx9_parse_sampler(struct d3dx_sampler *sampler, const char *data, const char **ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_sampler(struct d3dx9_base_effect *base, struct d3dx_sampler *sampler,
+        const char *data, const char **ptr, struct d3dx_object *objects)
 {
     HRESULT hr;
     UINT i;
-    struct d3dx_state *states;
 
     read_dword(ptr, &sampler->state_count);
     TRACE("Count: %u\n", sampler->state_count);
 
-    states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*states) * sampler->state_count);
-    if (!states)
+    sampler->states = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sampler->states) * sampler->state_count);
+    if (!sampler->states)
     {
         ERR("Out of memory\n");
         return E_OUTOFMEMORY;
@@ -4157,7 +4156,7 @@ static HRESULT d3dx9_parse_sampler(struct d3dx_sampler *sampler, const char *dat
 
     for (i = 0; i < sampler->state_count; ++i)
     {
-        hr = d3dx9_parse_state(&states[i], data, ptr, objects);
+        hr = d3dx9_parse_state(base, &sampler->states[i], data, ptr, objects);
         if (hr != D3D_OK)
         {
             WARN("Failed to parse state %u\n", i);
@@ -4165,28 +4164,26 @@ static HRESULT d3dx9_parse_sampler(struct d3dx_sampler *sampler, const char *dat
         }
     }
 
-    sampler->states = states;
-
     return D3D_OK;
 
 err_out:
 
     for (i = 0; i < sampler->state_count; ++i)
     {
-        free_state(&states[i]);
+        free_state(&sampler->states[i]);
     }
-
-    HeapFree(GetProcessHeap(), 0, states);
+    HeapFree(GetProcessHeap(), 0, sampler->states);
+    sampler->states = NULL;
 
     return hr;
 }
 
-static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, const char *data, const char **ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
+        void *value, const char *data, const char **ptr, struct d3dx_object *objects)
 {
     unsigned int i;
     HRESULT hr;
     UINT old_size = 0;
-    DWORD id;
 
     if (param->element_count)
     {
@@ -4196,7 +4193,7 @@ static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, cons
         {
             struct d3dx_parameter *member = &param->members[i];
 
-            hr = d3dx9_parse_value(member, value ? (char *)value + old_size : NULL, data, ptr, objects);
+            hr = d3dx9_parse_value(base, member, value ? (char *)value + old_size : NULL, data, ptr, objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse value %u\n", i);
@@ -4225,7 +4222,7 @@ static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, cons
             {
                 struct d3dx_parameter *member = &param->members[i];
 
-                hr = d3dx9_parse_value(member, (char *)value + old_size, data, ptr, objects);
+                hr = d3dx9_parse_value(base, member, (char *)value + old_size, data, ptr, objects);
                 if (hr != D3D_OK)
                 {
                     WARN("Failed to parse value %u\n", i);
@@ -4247,9 +4244,9 @@ static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, cons
                 case D3DXPT_TEXTURECUBE:
                 case D3DXPT_PIXELSHADER:
                 case D3DXPT_VERTEXSHADER:
-                    read_dword(ptr, &id);
-                    TRACE("Id: %u\n", id);
-                    objects[id] = get_parameter_handle(param);
+                    read_dword(ptr, &param->object_id);
+                    TRACE("Id: %u\n", param->object_id);
+                    objects[param->object_id].param = param;
                     param->data = value;
                     break;
 
@@ -4265,7 +4262,7 @@ static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, cons
                     if (!sampler)
                         return E_OUTOFMEMORY;
 
-                    hr = d3dx9_parse_sampler(sampler, data, ptr, objects);
+                    hr = d3dx9_parse_sampler(base, sampler, data, ptr, objects);
                     if (hr != D3D_OK)
                     {
                         HeapFree(GetProcessHeap(), 0, sampler);
@@ -4291,7 +4288,8 @@ static HRESULT d3dx9_parse_value(struct d3dx_parameter *param, void *value, cons
     return D3D_OK;
 }
 
-static HRESULT d3dx9_parse_init_value(struct d3dx_parameter *param, const char *data, const char *ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_init_value(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
+        const char *data, const char *ptr, struct d3dx_object *objects)
 {
     UINT size = param->bytes;
     HRESULT hr;
@@ -4328,7 +4326,7 @@ static HRESULT d3dx9_parse_init_value(struct d3dx_parameter *param, const char *
         }
     }
 
-    hr = d3dx9_parse_value(param, value, data, &ptr, objects);
+    hr = d3dx9_parse_value(base, param, value, data, &ptr, objects);
     if (hr != D3D_OK)
     {
         WARN("Failed to parse value\n");
@@ -4364,86 +4362,89 @@ static HRESULT d3dx9_parse_name(char **name, const char *ptr)
     return D3D_OK;
 }
 
-static HRESULT d3dx9_copy_data(char **str, const char **ptr)
+static HRESULT d3dx9_copy_data(struct d3dx_object *object, const char **ptr)
 {
-    DWORD size;
+    if (object->size || object->data)
+        FIXME("Object already initialized!\n");
 
-    read_dword(ptr, &size);
-    TRACE("Data size: %#x\n", size);
+    read_dword(ptr, &object->size);
+    TRACE("Data size: %#x\n", object->size);
+
+    if (!object->size)
+        return D3D_OK;
 
-    *str = HeapAlloc(GetProcessHeap(), 0, size);
-    if (!*str)
+    object->data = HeapAlloc(GetProcessHeap(), 0, object->size);
+    if (!object->data)
     {
-        ERR("Failed to allocate name memory.\n");
+        ERR("Failed to allocate object memory.\n");
         return E_OUTOFMEMORY;
     }
 
-    TRACE("Data: %s.\n", debugstr_an(*ptr, size));
-    memcpy(*str, *ptr, size);
+    TRACE("Data: %s.\n", debugstr_an(*ptr, object->size));
+    memcpy(object->data, *ptr, object->size);
 
-    *ptr += ((size + 3) & ~3);
+    *ptr += ((object->size + 3) & ~3);
 
     return D3D_OK;
 }
 
-static HRESULT d3dx9_parse_data(struct d3dx_parameter *param, const char **ptr, struct IDirect3DDevice9 *device)
+static void add_param_to_table(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
 {
-    DWORD size;
-    HRESULT hr;
-
-    TRACE("Parse data for parameter %s, type %s\n", debugstr_a(param->name), debug_d3dxparameter_type(param->type));
+    struct param_table *table = &base->param_table;
 
-    read_dword(ptr, &size);
-    TRACE("Data size: %#x\n", size);
-
-    if (!size)
+    if (table->count >= table->size)
     {
-        TRACE("Size is 0\n");
-        *(void **)param->data = NULL;
-        return D3D_OK;
-    }
-
-    switch (param->type)
-    {
-        case D3DXPT_STRING:
-            /* re-read with size (sizeof(DWORD) = 4) */
-            hr = d3dx9_parse_name((LPSTR *)param->data, *ptr - 4);
-            if (hr != D3D_OK)
-            {
-                WARN("Failed to parse string data\n");
-                return hr;
-            }
-            break;
+        unsigned int new_size;
+        struct d3dx_parameter **new_alloc;
 
-        case D3DXPT_VERTEXSHADER:
-            if (FAILED(hr = IDirect3DDevice9_CreateVertexShader(device, (DWORD *)*ptr, param->data)))
+        if (!table->size)
+        {
+            new_size = INITIAL_PARAM_TABLE_SIZE;
+            new_alloc = HeapAlloc(GetProcessHeap(), 0, sizeof(*table->table) * new_size);
+            if (!new_alloc)
             {
-                WARN("Failed to create vertex shader\n");
-                return hr;
+                ERR("Out of memory.\n");
+                return;
             }
-            break;
-
-        case D3DXPT_PIXELSHADER:
-            if (FAILED(hr = IDirect3DDevice9_CreatePixelShader(device, (DWORD *)*ptr, param->data)))
+        }
+        else
+        {
+            new_size = table->size * 2;
+            new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * new_size);
+            if (!new_alloc)
             {
-                WARN("Failed to create pixel shader\n");
-                return hr;
+                ERR("Out of memory.\n");
+                return;
             }
-            break;
-
-        default:
-            FIXME("Unhandled type %s\n", debug_d3dxparameter_type(param->type));
-            break;
+        }
+        table->table = new_alloc;
+        table->size = new_size;
     }
 
+    table->table[table->count++] = param;
+}
 
-    *ptr += ((size + 3) & ~3);
+static void sync_param_handles(struct d3dx9_base_effect *base)
+{
+    struct param_table *table = &base->param_table;
+    struct d3dx_parameter **new_alloc;
+    unsigned int i;
 
-    return D3D_OK;
+    if (table->count)
+    {
+        new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * table->count);
+        if (new_alloc)
+            table->table = new_alloc;
+        else
+            ERR("Out of memory.\n");
+    }
+
+    for (i = 0; i < table->count; ++i)
+        table->table[i]->handle = (D3DXHANDLE)&table->table[i];
 }
 
-static HRESULT d3dx9_parse_effect_typedef(struct d3dx_parameter *param, const char *data, const char **ptr,
-        struct d3dx_parameter *parent, UINT flags)
+static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
+       const char *data, const char **ptr, struct d3dx_parameter *parent, UINT flags)
 {
     DWORD offset;
     HRESULT hr;
@@ -4453,10 +4454,10 @@ static HRESULT d3dx9_parse_effect_typedef(struct d3dx_parameter *param, const ch
 
     if (!parent)
     {
-        read_dword(ptr, &param->type);
+        read_dword(ptr, (DWORD *)&param->type);
         TRACE("Type: %s\n", debug_d3dxparameter_type(param->type));
 
-        read_dword(ptr, &param->class);
+        read_dword(ptr, (DWORD *)&param->class);
         TRACE("Class: %s\n", debug_d3dxparameter_class(param->class));
 
         read_dword(ptr, &offset);
@@ -4576,7 +4577,8 @@ static HRESULT d3dx9_parse_effect_typedef(struct d3dx_parameter *param, const ch
         {
             *ptr = save_ptr;
 
-            hr = d3dx9_parse_effect_typedef(&param->members[i], data, ptr, param, flags);
+            add_param_to_table(base, &param->members[i]);
+            hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, param, flags);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse member %u\n", i);
@@ -4600,7 +4602,8 @@ static HRESULT d3dx9_parse_effect_typedef(struct d3dx_parameter *param, const ch
 
         for (i = 0; i < param->member_count; ++i)
         {
-            hr = d3dx9_parse_effect_typedef(&param->members[i], data, ptr, NULL, flags);
+            add_param_to_table(base, &param->members[i]);
+            hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, NULL, flags);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse member %u\n", i);
@@ -4635,7 +4638,8 @@ err_out:
     return hr;
 }
 
-static HRESULT d3dx9_parse_effect_annotation(struct d3dx_parameter *anno, const char *data, const char **ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_effect_annotation(struct d3dx9_base_effect *base, struct d3dx_parameter *anno,
+        const char *data, const char **ptr, struct d3dx_object *objects)
 {
     DWORD offset;
     const char *ptr2;
@@ -4646,7 +4650,7 @@ static HRESULT d3dx9_parse_effect_annotation(struct d3dx_parameter *anno, const
     read_dword(ptr, &offset);
     TRACE("Typedef offset: %#x\n", offset);
     ptr2 = data + offset;
-    hr = d3dx9_parse_effect_typedef(anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
+    hr = d3dx9_parse_effect_typedef(base, anno, data, &ptr2, NULL, D3DX_PARAMETER_ANNOTATION);
     if (hr != D3D_OK)
     {
         WARN("Failed to parse type definition\n");
@@ -4655,7 +4659,7 @@ static HRESULT d3dx9_parse_effect_annotation(struct d3dx_parameter *anno, const
 
     read_dword(ptr, &offset);
     TRACE("Value offset: %#x\n", offset);
-    hr = d3dx9_parse_init_value(anno, data, data + offset, objects);
+    hr = d3dx9_parse_init_value(base, anno, data, data + offset, objects);
     if (hr != D3D_OK)
     {
         WARN("Failed to parse value\n");
@@ -4665,16 +4669,12 @@ static HRESULT d3dx9_parse_effect_annotation(struct d3dx_parameter *anno, const
     return D3D_OK;
 }
 
-static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, const char **ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_state(struct d3dx9_base_effect *base, struct d3dx_state *state,
+        const char *data, const char **ptr, struct d3dx_object *objects)
 {
     DWORD offset;
     const char *ptr2;
     HRESULT hr;
-    struct d3dx_parameter *parameter;
-
-    parameter = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*parameter));
-    if (!parameter)
-        return E_OUTOFMEMORY;
 
     state->type = ST_CONSTANT;
 
@@ -4687,7 +4687,7 @@ static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, con
     read_dword(ptr, &offset);
     TRACE("Typedef offset: %#x\n", offset);
     ptr2 = data + offset;
-    hr = d3dx9_parse_effect_typedef(parameter, data, &ptr2, NULL, 0);
+    hr = d3dx9_parse_effect_typedef(base, &state->parameter, data, &ptr2, NULL, 0);
     if (hr != D3D_OK)
     {
         WARN("Failed to parse type definition\n");
@@ -4696,25 +4696,24 @@ static HRESULT d3dx9_parse_state(struct d3dx_state *state, const char *data, con
 
     read_dword(ptr, &offset);
     TRACE("Value offset: %#x\n", offset);
-    hr = d3dx9_parse_init_value(parameter, data, data + offset, objects);
+    hr = d3dx9_parse_init_value(base, &state->parameter, data, data + offset, objects);
     if (hr != D3D_OK)
     {
         WARN("Failed to parse value\n");
         goto err_out;
     }
 
-    state->parameter = parameter;
-
     return D3D_OK;
 
 err_out:
 
-    free_parameter(parameter, FALSE, FALSE);
+    free_parameter(&state->parameter, FALSE, FALSE);
 
     return hr;
 }
 
-static HRESULT d3dx9_parse_effect_parameter(struct d3dx_parameter *param, const char *data, const char **ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_effect_parameter(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
+        const char *data, const char **ptr, struct d3dx_object *objects)
 {
     DWORD offset;
     HRESULT hr;
@@ -4734,14 +4733,14 @@ static HRESULT d3dx9_parse_effect_parameter(struct d3dx_parameter *param, const
     read_dword(ptr, &param->annotation_count);
     TRACE("Annotation count: %u\n", param->annotation_count);
 
-    hr = d3dx9_parse_effect_typedef(param, data, &ptr2, NULL, param->flags);
+    hr = d3dx9_parse_effect_typedef(base, param, data, &ptr2, NULL, param->flags);
     if (hr != D3D_OK)
     {
         WARN("Failed to parse type definition\n");
         return hr;
     }
 
-    hr = d3dx9_parse_init_value(param, data, data + offset, objects);
+    hr = d3dx9_parse_init_value(base, param, data, data + offset, objects);
     if (hr != D3D_OK)
     {
         WARN("Failed to parse value\n");
@@ -4761,7 +4760,8 @@ static HRESULT d3dx9_parse_effect_parameter(struct d3dx_parameter *param, const
 
         for (i = 0; i < param->annotation_count; ++i)
         {
-            hr = d3dx9_parse_effect_annotation(&param->annotations[i], data, ptr, objects);
+            add_param_to_table(base, &param->annotations[i]);
+            hr = d3dx9_parse_effect_annotation(base, &param->annotations[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse annotation\n");
@@ -4785,7 +4785,8 @@ err_out:
     return hr;
 }
 
-static HRESULT d3dx9_parse_effect_pass(struct d3dx_pass *pass, const char *data, const char **ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_effect_pass(struct d3dx9_base_effect *base, struct d3dx_pass *pass,
+        const char *data, const char **ptr, struct d3dx_object *objects)
 {
     DWORD offset;
     HRESULT hr;
@@ -4821,7 +4822,8 @@ static HRESULT d3dx9_parse_effect_pass(struct d3dx_pass *pass, const char *data,
 
         for (i = 0; i < pass->annotation_count; ++i)
         {
-            hr = d3dx9_parse_effect_annotation(&pass->annotations[i], data, ptr, objects);
+            add_param_to_table(base, &pass->annotations[i]);
+            hr = d3dx9_parse_effect_annotation(base, &pass->annotations[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse annotation %u\n", i);
@@ -4842,7 +4844,7 @@ static HRESULT d3dx9_parse_effect_pass(struct d3dx_pass *pass, const char *data,
 
         for (i = 0; i < pass->state_count; ++i)
         {
-            hr = d3dx9_parse_state(&states[i], data, ptr, objects);
+            hr = d3dx9_parse_state(base, &states[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse annotation %u\n", i);
@@ -4880,7 +4882,8 @@ err_out:
     return hr;
 }
 
-static HRESULT d3dx9_parse_effect_technique(struct d3dx_technique *technique, const char *data, const char **ptr, D3DXHANDLE *objects)
+static HRESULT d3dx9_parse_effect_technique(struct d3dx9_base_effect *base, struct d3dx_technique *technique,
+        const char *data, const char **ptr, struct d3dx_object *objects)
 {
     DWORD offset;
     HRESULT hr;
@@ -4915,7 +4918,8 @@ static HRESULT d3dx9_parse_effect_technique(struct d3dx_technique *technique, co
 
         for (i = 0; i < technique->annotation_count; ++i)
         {
-            hr = d3dx9_parse_effect_annotation(&technique->annotations[i], data, ptr, objects);
+            add_param_to_table(base, &technique->annotations[i]);
+            hr = d3dx9_parse_effect_annotation(base, &technique->annotations[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse annotation %u\n", i);
@@ -4937,7 +4941,7 @@ static HRESULT d3dx9_parse_effect_technique(struct d3dx_technique *technique, co
 
         for (i = 0; i < technique->pass_count; ++i)
         {
-            hr = d3dx9_parse_effect_pass(&technique->passes[i], data, ptr, objects);
+            hr = d3dx9_parse_effect_pass(base, &technique->passes[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse pass %u\n", i);
@@ -4973,12 +4977,81 @@ err_out:
     return hr;
 }
 
+static HRESULT d3dx9_create_object(struct d3dx9_base_effect *base, struct d3dx_object *object)
+{
+    struct d3dx_parameter *param = object->param;
+    struct IDirect3DDevice9 *device = base->effect->device;
+    HRESULT hr;
+
+    if (*(char **)param->data)
+        ERR("Parameter data already allocated.\n");
+
+    switch (param->type)
+    {
+        case D3DXPT_STRING:
+            *(char **)param->data = HeapAlloc(GetProcessHeap(), 0, object->size);
+            if (!*(char **)param->data)
+            {
+                ERR("Out of memory.\n");
+                return E_OUTOFMEMORY;
+            }
+            memcpy(*(char **)param->data, object->data, object->size);
+            break;
+        case D3DXPT_VERTEXSHADER:
+            if (FAILED(hr = IDirect3DDevice9_CreateVertexShader(device, object->data,
+                    (IDirect3DVertexShader9 **)param->data)))
+            {
+                WARN("Failed to create vertex shader.\n");
+                return hr;
+            }
+            break;
+        case D3DXPT_PIXELSHADER:
+            if (FAILED(hr = IDirect3DDevice9_CreatePixelShader(device, object->data,
+                    (IDirect3DPixelShader9 **)param->data)))
+            {
+                WARN("Failed to create pixel shader.\n");
+                return hr;
+            }
+            break;
+        default:
+            break;
+    }
+    return D3D_OK;
+}
+
+static HRESULT d3dx9_parse_array_selector(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
+{
+    DWORD string_size;
+    struct d3dx_object *object = &base->objects[param->object_id];
+    char *ptr = object->data;
+
+    TRACE("Parsing array entry selection state for parameter %p.\n", param);
+
+    string_size = *(DWORD *)ptr;
+    param->referenced_param = get_parameter_by_name(base, NULL, ptr + 4);
+    if (param->referenced_param)
+    {
+        TRACE("Mapping to parameter %s.\n", debugstr_a(param->referenced_param->name));
+    }
+    else
+    {
+        FIXME("Referenced parameter %s not found.\n", ptr + 4);
+        return D3DXERR_INVALIDDATA;
+    }
+    TRACE("Unknown DWORD: 0x%.8x.\n", *(DWORD *)(ptr + string_size));
+
+    FIXME("Parse preshader.\n");
+
+    return D3D_OK;
+}
+
 static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *data, const char **ptr)
 {
     DWORD technique_index;
     DWORD index, state_index, usage, element_index;
     struct d3dx_state *state;
     struct d3dx_parameter *param;
+    struct d3dx_object *object;
     HRESULT hr = E_FAIL;
 
     read_dword(ptr, &technique_index);
@@ -5056,18 +5129,26 @@ static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *
         state = &pass->states[state_index];
     }
 
-    param = state->parameter;
+    TRACE("State operation %#x (%s).\n", state->operation, state_table[state->operation].name);
+    param = &state->parameter;
+    TRACE("Using object id %u.\n", param->object_id);
+    object = &base->objects[param->object_id];
 
+    TRACE("Usage %u: class %s, type %s.\n", usage, debug_d3dxparameter_class(param->class),
+            debug_d3dxparameter_type(param->type));
     switch (usage)
     {
         case 0:
-            TRACE("usage 0: type %s\n", debug_d3dxparameter_type(param->type));
             switch (param->type)
             {
                 case D3DXPT_VERTEXSHADER:
                 case D3DXPT_PIXELSHADER:
                     state->type = ST_CONSTANT;
-                    hr = d3dx9_parse_data(param, ptr, base->effect->device);
+                    if (FAILED(hr = d3dx9_copy_data(&base->objects[param->object_id], ptr)))
+                        return hr;
+
+                    if (object->data)
+                        hr = d3dx9_create_object(base, object);
                     break;
 
                 case D3DXPT_BOOL:
@@ -5075,7 +5156,7 @@ static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *
                 case D3DXPT_FLOAT:
                 case D3DXPT_STRING:
                     state->type = ST_FXLC;
-                    hr = d3dx9_copy_data(param->data, ptr);
+                    hr = d3dx9_copy_data(&base->objects[param->object_id], ptr);
                     break;
 
                 default:
@@ -5086,13 +5167,29 @@ static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *
 
         case 1:
             state->type = ST_PARAMETER;
-            hr = d3dx9_copy_data(param->data, ptr);
-            if (hr == D3D_OK)
+            if (FAILED(hr = d3dx9_copy_data(&base->objects[param->object_id], ptr)))
+                return hr;
+
+            TRACE("Looking for parameter %s.\n", debugstr_a(object->data));
+            param->referenced_param = get_parameter_by_name(base, NULL, object->data);
+            if (param->referenced_param)
             {
-                TRACE("Mapping to parameter %s\n", *(char **)param->data);
+                TRACE("Mapping to parameter %p.\n", param->referenced_param);
+            }
+            else
+            {
+                FIXME("Referenced parameter %s not found.\n", (char *)object->data);
+                return D3DXERR_INVALIDDATA;
             }
             break;
 
+        case 2:
+            state->type = ST_ARRAY_SELECTOR;
+            if (FAILED(hr = d3dx9_copy_data(object, ptr)))
+                return hr;
+            hr = d3dx9_parse_array_selector(base, param);
+            break;
+
         default:
             FIXME("Unknown usage %x\n", usage);
             break;
@@ -5104,8 +5201,7 @@ static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *
 static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *data, UINT data_size, DWORD start)
 {
     const char *ptr = data + start;
-    D3DXHANDLE *objects = NULL;
-    UINT stringcount, objectcount, resourcecount;
+    UINT stringcount, resourcecount;
     HRESULT hr;
     UINT i;
 
@@ -5117,11 +5213,11 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
 
     skip_dword_unknown(&ptr, 1);
 
-    read_dword(&ptr, &objectcount);
-    TRACE("Object count: %u\n", objectcount);
+    read_dword(&ptr, &base->object_count);
+    TRACE("Object count: %u\n", base->object_count);
 
-    objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*objects) * objectcount);
-    if (!objects)
+    base->objects = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*base->objects) * base->object_count);
+    if (!base->objects)
     {
         ERR("Out of memory\n");
         hr = E_OUTOFMEMORY;
@@ -5141,7 +5237,8 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
 
         for (i = 0; i < base->parameter_count; ++i)
         {
-            hr = d3dx9_parse_effect_parameter(&base->parameters[i], data, &ptr, objects);
+            add_param_to_table(base, &base->parameters[i]);
+            hr = d3dx9_parse_effect_parameter(base, &base->parameters[i], data, &ptr, base->objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse parameter %u\n", i);
@@ -5163,7 +5260,8 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
 
         for (i = 0; i < base->technique_count; ++i)
         {
-            hr = d3dx9_parse_effect_technique(&base->techniques[i], data, &ptr, objects);
+            TRACE("Parsing technique %u.\n", i);
+            hr = d3dx9_parse_effect_technique(base, &base->techniques[i], data, &ptr, base->objects);
             if (hr != D3D_OK)
             {
                 WARN("Failed to parse technique %u\n", i);
@@ -5172,6 +5270,8 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
         }
     }
 
+    sync_param_handles(base);
+
     read_dword(&ptr, &stringcount);
     TRACE("String count: %u\n", stringcount);
 
@@ -5181,18 +5281,17 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
     for (i = 0; i < stringcount; ++i)
     {
         DWORD id;
-        struct d3dx_parameter *param;
 
         read_dword(&ptr, &id);
         TRACE("Id: %u\n", id);
 
-        param = get_parameter_struct(objects[id]);
+        if (FAILED(hr = d3dx9_copy_data(&base->objects[id], &ptr)))
+            goto err_out;
 
-        hr = d3dx9_parse_data(param, &ptr, base->effect->device);
-        if (hr != D3D_OK)
+        if (base->objects[id].data)
         {
-            WARN("Failed to parse data %u\n", i);
-            goto err_out;
+            if (FAILED(hr = d3dx9_create_object(base, &base->objects[id])))
+                goto err_out;
         }
     }
 
@@ -5208,8 +5307,6 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
         }
     }
 
-    HeapFree(GetProcessHeap(), 0, objects);
-
     return D3D_OK;
 
 err_out:
@@ -5232,17 +5329,27 @@ err_out:
         base->parameters = NULL;
     }
 
-    HeapFree(GetProcessHeap(), 0, objects);
+    if (base->objects)
+    {
+        for (i = 0; i < base->object_count; ++i)
+        {
+            free_object(&base->objects[i]);
+        }
+        HeapFree(GetProcessHeap(), 0, base->objects);
+        base->objects = NULL;
+    }
 
     return hr;
 }
 
 static HRESULT d3dx9_base_effect_init(struct d3dx9_base_effect *base,
-        const char *data, SIZE_T data_size, struct ID3DXEffectImpl *effect)
+        const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
+        UINT eflags, ID3DBlob **errors, struct ID3DXEffectImpl *effect)
 {
     DWORD tag, offset;
     const char *ptr = data;
     HRESULT hr;
+    ID3DBlob *bytecode = NULL, *temp_errors = NULL;
 
     TRACE("base %p, data %p, data_size %lu, effect %p\n", base, data, data_size, effect);
 
@@ -5253,30 +5360,55 @@ static HRESULT d3dx9_base_effect_init(struct d3dx9_base_effect *base,
 
     if (tag != d3dx9_effect_version(9, 1))
     {
-        /* todo: compile hlsl ascii code */
-        FIXME("HLSL ascii effects not supported, yet\n");
-
-        /* Show the start of the shader for debugging info. */
-        TRACE("effect:\n%s\n", debugstr_an(data, data_size > 40 ? 40 : data_size));
-    }
-    else
-    {
-        read_dword(&ptr, &offset);
-        TRACE("Offset: %x\n", offset);
-
-        hr = d3dx9_parse_effect(base, ptr, data_size, offset);
-        if (hr != D3D_OK)
+        TRACE("HLSL ASCII effect, trying to compile it.\n");
+        hr = D3DCompile(data, data_size, NULL, defines, include,
+                "main", "fx_2_0", 0, eflags, &bytecode, &temp_errors);
+        if (FAILED(hr))
         {
-            FIXME("Failed to parse effect.\n");
+            WARN("Failed to compile ASCII effect.\n");
+            if (bytecode)
+                ID3D10Blob_Release(bytecode);
+            if (temp_errors)
+                TRACE("%s\n", (char *)ID3D10Blob_GetBufferPointer(temp_errors));
+            if (errors)
+                *errors = temp_errors;
+            else if (temp_errors)
+                ID3D10Blob_Release(temp_errors);
             return hr;
         }
+        if (!bytecode)
+        {
+            FIXME("No output from effect compilation.\n");
+            return D3DERR_INVALIDCALL;
+        }
+        if (errors)
+            *errors = temp_errors;
+        else if (temp_errors)
+            ID3D10Blob_Release(temp_errors);
+
+        ptr = ID3D10Blob_GetBufferPointer(bytecode);
+        read_dword(&ptr, &tag);
+        TRACE("Tag: %x\n", tag);
+    }
+
+    read_dword(&ptr, &offset);
+    TRACE("Offset: %x\n", offset);
+
+    hr = d3dx9_parse_effect(base, ptr, data_size, offset);
+    if (bytecode)
+        ID3D10Blob_Release(bytecode);
+    if (hr != D3D_OK)
+    {
+        FIXME("Failed to parse effect.\n");
+        return hr;
     }
 
     return D3D_OK;
 }
 
 static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, struct IDirect3DDevice9 *device,
-        const char *data, SIZE_T data_size, struct ID3DXEffectPool *pool)
+        const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
+        UINT eflags, ID3DBlob **error_messages, struct ID3DXEffectPool *pool)
 {
     HRESULT hr;
 
@@ -5291,7 +5423,8 @@ static HRESULT d3dx9_effect_init(struct ID3DXEffectImpl *effect, struct IDirect3
     IDirect3DDevice9_AddRef(device);
     effect->device = device;
 
-    if (FAILED(hr = d3dx9_base_effect_init(&effect->base_effect, data, data_size, effect)))
+    if (FAILED(hr = d3dx9_base_effect_init(&effect->base_effect, data, data_size, defines, include,
+            eflags, error_messages, effect)))
     {
         FIXME("Failed to parse effect, hr %#x.\n", hr);
         free_effect(effect);
@@ -5315,8 +5448,10 @@ HRESULT WINAPI D3DXCreateEffectEx(struct IDirect3DDevice9 *device, const void *s
     struct ID3DXEffectImpl *object;
     HRESULT hr;
 
-    FIXME("(%p, %p, %u, %p, %p, %p, %#x, %p, %p, %p): semi-stub\n", device, srcdata, srcdatalen, defines, include,
-        skip_constants, flags, pool, effect, compilation_errors);
+    TRACE("device %p, srcdata %p, srcdatalen %u, defines %p, include %p,"
+            " skip_constants %p, flags %#x, pool %p, effect %p, compilation_errors %p.\n",
+            device, srcdata, srcdatalen, defines, include,
+            skip_constants, flags, pool, effect, compilation_errors);
 
     if (compilation_errors)
         *compilation_errors = NULL;
@@ -5331,14 +5466,18 @@ HRESULT WINAPI D3DXCreateEffectEx(struct IDirect3DDevice9 *device, const void *s
     if (!effect)
         return D3D_OK;
 
+    if (skip_constants)
+        FIXME("skip_constants is not NULL, not supported yet.\n");
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
         return E_OUTOFMEMORY;
 
-    hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, pool);
+    hr = d3dx9_effect_init(object, device, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
+            (ID3DInclude *)include, flags, (ID3DBlob **)compilation_errors, pool);
     if (FAILED(hr))
     {
-        WARN("Failed to initialize shader reflection\n");
+        WARN("Failed to create effect object.\n");
         HeapFree(GetProcessHeap(), 0, object);
         return hr;
     }
@@ -5360,7 +5499,9 @@ HRESULT WINAPI D3DXCreateEffect(struct IDirect3DDevice9 *device, const void *src
     return D3DXCreateEffectEx(device, srcdata, srcdatalen, defines, include, NULL, flags, pool, effect, compilation_errors);
 }
 
-static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler, const char *data, SIZE_T data_size)
+static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compiler,
+        const char *data, SIZE_T data_size, const D3D_SHADER_MACRO *defines, ID3DInclude *include,
+        UINT eflags, ID3DBlob **error_messages)
 {
     HRESULT hr;
 
@@ -5369,7 +5510,8 @@ static HRESULT d3dx9_effect_compiler_init(struct ID3DXEffectCompilerImpl *compil
     compiler->ID3DXEffectCompiler_iface.lpVtbl = &ID3DXEffectCompiler_Vtbl;
     compiler->ref = 1;
 
-    if (FAILED(hr = d3dx9_base_effect_init(&compiler->base_effect, data, data_size, NULL)))
+    if (FAILED(hr = d3dx9_base_effect_init(&compiler->base_effect, data, data_size, defines,
+            include, eflags, error_messages, NULL)))
     {
         FIXME("Failed to parse effect, hr %#x.\n", hr);
         free_effect_compiler(compiler);
@@ -5398,7 +5540,8 @@ HRESULT WINAPI D3DXCreateEffectCompiler(const char *srcdata, UINT srcdatalen, co
     if (!object)
         return E_OUTOFMEMORY;
 
-    hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen);
+    hr = d3dx9_effect_compiler_init(object, srcdata, srcdatalen, (const D3D_SHADER_MACRO *)defines,
+            (ID3DInclude *)include, flags, (ID3DBlob **)parse_errors);
     if (FAILED(hr))
     {
         WARN("Failed to initialize effect compiler\n");
@@ -5497,11 +5640,14 @@ HRESULT WINAPI D3DXCreateEffectFromFileExW(struct IDirect3DDevice9 *device, cons
         const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
         struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
 {
-    LPVOID buffer;
+    void *buffer;
     HRESULT ret;
     DWORD size;
 
-    TRACE("(%s): relay\n", debugstr_w(srcfile));
+    TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
+            "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
+            device, debugstr_w(srcfile), defines, include, debugstr_a(skipconstants),
+            flags, pool, effect, compilationerrors);
 
     if (!device || !srcfile)
         return D3DERR_INVALIDCALL;
@@ -5521,11 +5667,14 @@ HRESULT WINAPI D3DXCreateEffectFromFileExA(struct IDirect3DDevice9 *device, cons
         const D3DXMACRO *defines, struct ID3DXInclude *include, const char *skipconstants, DWORD flags,
         struct ID3DXEffectPool *pool, struct ID3DXEffect **effect, struct ID3DXBuffer **compilationerrors)
 {
-    LPWSTR srcfileW;
+    WCHAR *srcfileW;
     HRESULT ret;
     DWORD len;
 
-    TRACE("(void): relay\n");
+    TRACE("device %p, srcfile %s, defines %p, include %p, skipconstants %s, "
+            "flags %#x, pool %p, effect %p, compilationerrors %p.\n",
+            device, debugstr_a(srcfile), defines, include, debugstr_a(skipconstants),
+            flags, pool, effect, compilationerrors);
 
     if (!srcfile)
         return D3DERR_INVALIDCALL;
@@ -5627,11 +5776,12 @@ HRESULT WINAPI D3DXCreateEffectFromResourceA(struct IDirect3DDevice9 *device, HM
 HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(const WCHAR *srcfile, const D3DXMACRO *defines,
         ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
 {
-    LPVOID buffer;
+    void *buffer;
     HRESULT ret;
     DWORD size;
 
-    TRACE("(%s): relay\n", debugstr_w(srcfile));
+    TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
+            debugstr_w(srcfile), defines, include, flags, effectcompiler, parseerrors);
 
     if (!srcfile)
         return D3DERR_INVALIDCALL;
@@ -5650,11 +5800,12 @@ HRESULT WINAPI D3DXCreateEffectCompilerFromFileW(const WCHAR *srcfile, const D3D
 HRESULT WINAPI D3DXCreateEffectCompilerFromFileA(const char *srcfile, const D3DXMACRO *defines,
         ID3DXInclude *include, DWORD flags, ID3DXEffectCompiler **effectcompiler, ID3DXBuffer **parseerrors)
 {
-    LPWSTR srcfileW;
+    WCHAR *srcfileW;
     HRESULT ret;
     DWORD len;
 
-    TRACE("(void): relay\n");
+    TRACE("srcfile %s, defines %p, include %p, flags %#x, effectcompiler %p, parseerrors %p.\n",
+            debugstr_a(srcfile), defines, include, flags, effectcompiler, parseerrors);
 
     if (!srcfile)
         return D3DERR_INVALIDCALL;
index cac954e..e1b691a 100644 (file)
 
 #include "d3dx9_36_private.h"
 
-typedef struct ID3DXLineImpl {
+struct d3dx9_line
+{
     ID3DXLine ID3DXLine_iface;
     LONG ref;
 
     IDirect3DDevice9 *device;
     IDirect3DStateBlock9 *state;
-} ID3DXLineImpl;
+};
 
-static inline ID3DXLineImpl *impl_from_ID3DXLine(ID3DXLine *iface)
+static inline struct d3dx9_line *impl_from_ID3DXLine(ID3DXLine *iface)
 {
-    return CONTAINING_RECORD(iface, ID3DXLineImpl, ID3DXLine_iface);
+    return CONTAINING_RECORD(iface, struct d3dx9_line, ID3DXLine_iface);
 }
 
-/*** IUnknown methods ***/
-static HRESULT WINAPI ID3DXLineImpl_QueryInterface(ID3DXLine* iface, REFIID riid, LPVOID* object)
+static HRESULT WINAPI d3dx9_line_QueryInterface(ID3DXLine *iface, REFIID riid, void **out)
 {
-    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
+    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
 
-    if (IsEqualGUID(riid, &IID_IUnknown) ||
-        IsEqualGUID(riid, &IID_ID3DXLine))
+    if (IsEqualGUID(riid, &IID_ID3DXLine)
+            || IsEqualGUID(riid, &IID_IUnknown))
     {
         ID3DXLine_AddRef(iface);
-        *object = iface;
+        *out = iface;
         return S_OK;
     }
 
-    ERR("Interface %s not found\n", debugstr_guid(riid));
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
 
+    *out = NULL;
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI ID3DXLineImpl_AddRef(ID3DXLine* iface)
+static ULONG WINAPI d3dx9_line_AddRef(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
+    struct d3dx9_line *line = impl_from_ID3DXLine(iface);
+    ULONG refcount = InterlockedIncrement(&line->ref);
 
-    TRACE("(%p)->(): AddRef from %u\n", This, This->ref);
+    TRACE("%p increasing refcount to %u.\n", line, refcount);
 
-    return InterlockedIncrement(&This->ref);
+    return refcount;
 }
 
-static ULONG WINAPI ID3DXLineImpl_Release(ID3DXLine* iface)
+static ULONG WINAPI d3dx9_line_Release(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-    ULONG ref = InterlockedDecrement(&This->ref);
+    struct d3dx9_line *line = impl_from_ID3DXLine(iface);
+    ULONG refcount = InterlockedDecrement(&line->ref);
 
-    TRACE("(%p)->(): Release from %u\n", This, ref + 1);
+    TRACE("%p decreasing refcount to %u.\n", line, refcount);
 
-    if (!ref)
+    if (!refcount)
     {
-        IDirect3DDevice9_Release(This->device);
-        HeapFree(GetProcessHeap(), 0, This);
+        IDirect3DDevice9_Release(line->device);
+        HeapFree(GetProcessHeap(), 0, line);
     }
 
-    return ref;
+    return refcount;
 }
 
-/*** ID3DXLine methods ***/
-static HRESULT WINAPI ID3DXLineImpl_GetDevice(struct ID3DXLine *iface, struct IDirect3DDevice9 **device)
+static HRESULT WINAPI d3dx9_line_GetDevice(struct ID3DXLine *iface, struct IDirect3DDevice9 **device)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
+    struct d3dx9_line *line = impl_from_ID3DXLine(iface);
 
-    TRACE ("(%p)->(%p)\n", This, device);
+    TRACE("iface %p, device %p.\n", iface, line);
 
-    if (device == NULL) return D3DERR_INVALIDCALL;
+    if (!device)
+        return D3DERR_INVALIDCALL;
 
-    *device = This->device;
-    IDirect3DDevice9_AddRef(This->device);
+    *device = line->device;
+    IDirect3DDevice9_AddRef(line->device);
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_Begin(ID3DXLine* iface)
+static HRESULT WINAPI d3dx9_line_Begin(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    HRESULT hr;
+    struct d3dx9_line *line = impl_from_ID3DXLine(iface);
     D3DXMATRIX identity, projection;
     D3DVIEWPORT9 vp;
 
-    TRACE ("(%p)->()\n", This);
+    TRACE("iface %p.\n", iface);
 
-    if (This->state != NULL) /* We already began. Return error. */
+    if (line->state)
         return D3DERR_INVALIDCALL;
 
-    hr = IDirect3DDevice9_CreateStateBlock(This->device, D3DSBT_ALL, &This->state);
-    if (FAILED(hr)) return D3DXERR_INVALIDDATA;
+    if (FAILED(IDirect3DDevice9_CreateStateBlock(line->device, D3DSBT_ALL, &line->state)))
+        return D3DXERR_INVALIDDATA;
 
-    hr = IDirect3DDevice9_GetViewport(This->device, &vp);
-    if (FAILED(hr)) goto failed;
+    if (FAILED(IDirect3DDevice9_GetViewport(line->device, &vp)))
+        goto failed;
 
     D3DXMatrixIdentity(&identity);
-    D3DXMatrixOrthoOffCenterLH(&projection,
-                               0.0, vp.Width, /* Min and max x */
-                               vp.Height, 0.0, /* Min and max y. Screen y is on top so this is inverted */
-                               0.0, 1.0); /* Min and max z */
-
-    hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_WORLD, &identity);
-    if (FAILED(hr)) goto failed;
-
-    hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_VIEW, &identity);
-    if (FAILED(hr)) goto failed;
-
-    hr = IDirect3DDevice9_SetTransform(This->device, D3DTS_PROJECTION, &projection);
-    if (FAILED(hr)) goto failed;
-
-    /* Windows sets similar states so we do the same */
-
-    hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_LIGHTING, FALSE);
-    if (FAILED(hr)) goto failed;
-
-    hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_FOGENABLE, FALSE);
-    if (FAILED(hr)) goto failed;
-
-    hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_SHADEMODE, D3DSHADE_FLAT);
-    if (FAILED(hr)) goto failed;
-
-    hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_ALPHABLENDENABLE, TRUE);
-    if (FAILED(hr)) goto failed;
-
-    hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
-    if (FAILED(hr)) goto failed;
-
-    hr = IDirect3DDevice9_SetRenderState(This->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
-    if (FAILED(hr)) goto failed;
+    D3DXMatrixOrthoOffCenterLH(&projection, 0.0, (FLOAT)vp.Width, (FLOAT)vp.Height, 0.0, 0.0, 1.0);
+
+    if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_WORLD, &identity)))
+        goto failed;
+    if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_VIEW, &identity)))
+        goto failed;
+    if (FAILED(IDirect3DDevice9_SetTransform(line->device, D3DTS_PROJECTION, &projection)))
+        goto failed;
+
+    if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_LIGHTING, FALSE)))
+        goto failed;
+    if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_FOGENABLE, FALSE)))
+        goto failed;
+    if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_SHADEMODE, D3DSHADE_FLAT)))
+        goto failed;
+    if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_ALPHABLENDENABLE, TRUE)))
+        goto failed;
+    if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)))
+        goto failed;
+    if (FAILED(IDirect3DDevice9_SetRenderState(line->device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)))
+        goto failed;
 
     return D3D_OK;
+
 failed:
-    IDirect3DStateBlock9_Apply(This->state);
-    IDirect3DStateBlock9_Release(This->state);
-    This->state = NULL;
+    IDirect3DStateBlock9_Apply(line->state);
+    IDirect3DStateBlock9_Release(line->state);
+    line->state = NULL;
     return D3DXERR_INVALIDDATA;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_Draw(ID3DXLine* iface, CONST D3DXVECTOR2* vertexlist, DWORD vertexlistcount, D3DCOLOR color)
+static HRESULT WINAPI d3dx9_line_Draw(ID3DXLine *iface, const D3DXVECTOR2 *vertex_list,
+        DWORD vertex_list_count, D3DCOLOR color)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(%p, %u, %#x): stub\n", This, vertexlist, vertexlistcount, color);
+    FIXME("iface %p, vertex_list %p, vertex_list_count %u, color 0x%08x stub!\n",
+            iface, vertex_list, vertex_list_count, color);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_DrawTransform(ID3DXLine* iface, CONST D3DXVECTOR3* vertexlist, DWORD vertexlistcount,
-                                                  CONST D3DXMATRIX* transform, D3DCOLOR color)
+static HRESULT WINAPI d3dx9_line_DrawTransform(ID3DXLine *iface, const D3DXVECTOR3 *vertex_list,
+        DWORD vertex_list_count, const D3DXMATRIX *transform, D3DCOLOR color)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(%p, %u, %p, %#x): stub\n", This, vertexlist, vertexlistcount, transform, color);
+    FIXME("iface %p, vertex_list %p, vertex_list_count %u, transform %p, color 0x%08x stub!\n",
+            iface, vertex_list, vertex_list_count, transform, color);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_SetPattern(ID3DXLine* iface, DWORD pattern)
+static HRESULT WINAPI d3dx9_line_SetPattern(ID3DXLine *iface, DWORD pattern)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(%#x): stub\n", This, pattern);
+    FIXME("iface %p, pattern 0x%08x stub!\n", iface, pattern);
 
     return E_NOTIMPL;
 }
 
-static DWORD WINAPI ID3DXLineImpl_GetPattern(ID3DXLine* iface)
+static DWORD WINAPI d3dx9_line_GetPattern(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
-    return 0xFFFFFFFF;
+    return 0xffffffff;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_SetPatternScale(ID3DXLine* iface, FLOAT scale)
+static HRESULT WINAPI d3dx9_line_SetPatternScale(ID3DXLine *iface, float scale)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(%f): stub\n", This, scale);
+    FIXME("iface %p, scale %.8e stub!\n", iface, scale);
 
     return E_NOTIMPL;
 }
 
-static FLOAT WINAPI ID3DXLineImpl_GetPatternScale(ID3DXLine* iface)
+static float WINAPI d3dx9_line_GetPatternScale(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
     return 1.0f;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_SetWidth(ID3DXLine* iface, FLOAT width)
+static HRESULT WINAPI d3dx9_line_SetWidth(ID3DXLine *iface, float width)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(%f): stub\n", This, width);
+    FIXME("iface %p, width %.8e stub!\n", iface, width);
 
     return E_NOTIMPL;
 }
 
-static FLOAT WINAPI ID3DXLineImpl_GetWidth(ID3DXLine* iface)
+static float WINAPI d3dx9_line_GetWidth(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
     return 1.0f;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_SetAntialias(ID3DXLine* iface, BOOL antialias)
+static HRESULT WINAPI d3dx9_line_SetAntialias(ID3DXLine *iface, BOOL antialias)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(%u): stub\n", This, antialias);
+    FIXME("iface %p, antialias %#x stub!\n", iface, antialias);
 
     return E_NOTIMPL;
 }
 
-static BOOL WINAPI ID3DXLineImpl_GetAntialias(ID3DXLine* iface)
+static BOOL WINAPI d3dx9_line_GetAntialias(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
     return FALSE;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_SetGLLines(ID3DXLine* iface, BOOL gl_lines)
+static HRESULT WINAPI d3dx9_line_SetGLLines(ID3DXLine *iface, BOOL gl_lines)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(%u): stub\n", This, gl_lines);
+    FIXME("iface %p, gl_lines %#x stub!\n", iface, gl_lines);
 
     return E_NOTIMPL;
 }
 
-static BOOL WINAPI ID3DXLineImpl_GetGLLines(ID3DXLine* iface)
+static BOOL WINAPI d3dx9_line_GetGLLines(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
     return FALSE;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_End(ID3DXLine* iface)
+static HRESULT WINAPI d3dx9_line_End(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
+    struct d3dx9_line *line = impl_from_ID3DXLine(iface);
 
     HRESULT hr;
 
-    TRACE ("(%p)->()\n", This);
+    TRACE("iface %p.\n", iface);
 
-    if (This->state == NULL) /* We haven't begun yet. */
+    if (!line->state)
         return D3DERR_INVALIDCALL;
 
-    hr = IDirect3DStateBlock9_Apply(This->state);
-    IDirect3DStateBlock9_Release(This->state);
-    This->state = NULL;
+    hr = IDirect3DStateBlock9_Apply(line->state);
+    IDirect3DStateBlock9_Release(line->state);
+    line->state = NULL;
 
-    if (FAILED(hr)) return D3DXERR_INVALIDDATA;
-    else return D3D_OK;
+    if (FAILED(hr))
+        return D3DXERR_INVALIDDATA;
+
+    return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXLineImpl_OnLostDevice(ID3DXLine* iface)
+static HRESULT WINAPI d3dx9_line_OnLostDevice(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
     return E_NOTIMPL;
 }
-static HRESULT WINAPI ID3DXLineImpl_OnResetDevice(ID3DXLine* iface)
+static HRESULT WINAPI d3dx9_line_OnResetDevice(ID3DXLine *iface)
 {
-    ID3DXLineImpl *This = impl_from_ID3DXLine(iface);
-
-    FIXME("(%p)->(): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
     return E_NOTIMPL;
 }
 
-static const struct ID3DXLineVtbl ID3DXLine_Vtbl =
+static const struct ID3DXLineVtbl d3dx9_line_vtbl =
 {
-    /*** IUnknown methods ***/
-    ID3DXLineImpl_QueryInterface,
-    ID3DXLineImpl_AddRef,
-    ID3DXLineImpl_Release,
-    /*** ID3DXLine methods ***/
-    ID3DXLineImpl_GetDevice,
-    ID3DXLineImpl_Begin,
-    ID3DXLineImpl_Draw,
-    ID3DXLineImpl_DrawTransform,
-    ID3DXLineImpl_SetPattern,
-    ID3DXLineImpl_GetPattern,
-    ID3DXLineImpl_SetPatternScale,
-    ID3DXLineImpl_GetPatternScale,
-    ID3DXLineImpl_SetWidth,
-    ID3DXLineImpl_GetWidth,
-    ID3DXLineImpl_SetAntialias,
-    ID3DXLineImpl_GetAntialias,
-    ID3DXLineImpl_SetGLLines,
-    ID3DXLineImpl_GetGLLines,
-    ID3DXLineImpl_End,
-    ID3DXLineImpl_OnLostDevice,
-    ID3DXLineImpl_OnResetDevice
+    d3dx9_line_QueryInterface,
+    d3dx9_line_AddRef,
+    d3dx9_line_Release,
+    d3dx9_line_GetDevice,
+    d3dx9_line_Begin,
+    d3dx9_line_Draw,
+    d3dx9_line_DrawTransform,
+    d3dx9_line_SetPattern,
+    d3dx9_line_GetPattern,
+    d3dx9_line_SetPatternScale,
+    d3dx9_line_GetPatternScale,
+    d3dx9_line_SetWidth,
+    d3dx9_line_GetWidth,
+    d3dx9_line_SetAntialias,
+    d3dx9_line_GetAntialias,
+    d3dx9_line_SetGLLines,
+    d3dx9_line_GetGLLines,
+    d3dx9_line_End,
+    d3dx9_line_OnLostDevice,
+    d3dx9_line_OnResetDevice,
 };
 
 HRESULT WINAPI D3DXCreateLine(struct IDirect3DDevice9 *device, struct ID3DXLine **line)
 {
-    ID3DXLineImpl* object;
+    struct d3dx9_line *object;
 
-    TRACE("(%p, %p)\n", device, line);
+    TRACE("device %p, line %p.\n", device, line);
 
     if (!device || !line)
         return D3DERR_INVALIDCALL;
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXLineImpl));
-    if (!object)
+    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
         return E_OUTOFMEMORY;
 
-    object->ID3DXLine_iface.lpVtbl = &ID3DXLine_Vtbl;
+    object->ID3DXLine_iface.lpVtbl = &d3dx9_line_vtbl;
     object->ref = 1;
     object->device = device;
-    object->state = NULL; /* We only initialize it on Begin */
     IDirect3DDevice9_AddRef(device);
 
     *line = &object->ID3DXLine_iface;
index e168062..2e11821 100644 (file)
@@ -155,7 +155,7 @@ D3DXMATRIX * WINAPI D3DXMatrixAffineTransformation2D(D3DXMATRIX *out, FLOAT scal
 
     s = sinf(rotation / 2.0f);
     tmp1 = 1.0f - 2.0f * s * s;
-    tmp2 = 2.0 * s * cosf(rotation / 2.0f);
+    tmp2 = 2.0f * s * cosf(rotation / 2.0f);
 
     D3DXMatrixIdentity(out);
     out->u.m[0][0] = scaling * tmp1;
@@ -480,8 +480,8 @@ D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovLH(D3DXMATRIX *pout, FLOAT fovy, FLOA
     TRACE("pout %p, fovy %f, aspect %f, zn %f, zf %f\n", pout, fovy, aspect, zn, zf);
 
     D3DXMatrixIdentity(pout);
-    pout->u.m[0][0] = 1.0f / (aspect * tan(fovy/2.0f));
-    pout->u.m[1][1] = 1.0f / tan(fovy/2.0f);
+    pout->u.m[0][0] = 1.0f / (aspect * tanf(fovy/2.0f));
+    pout->u.m[1][1] = 1.0f / tanf(fovy/2.0f);
     pout->u.m[2][2] = zf / (zf - zn);
     pout->u.m[2][3] = 1.0f;
     pout->u.m[3][2] = (zf * zn) / (zn - zf);
@@ -494,8 +494,8 @@ D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovRH(D3DXMATRIX *pout, FLOAT fovy, FLOA
     TRACE("pout %p, fovy %f, aspect %f, zn %f, zf %f\n", pout, fovy, aspect, zn, zf);
 
     D3DXMatrixIdentity(pout);
-    pout->u.m[0][0] = 1.0f / (aspect * tan(fovy/2.0f));
-    pout->u.m[1][1] = 1.0f / tan(fovy/2.0f);
+    pout->u.m[0][0] = 1.0f / (aspect * tanf(fovy/2.0f));
+    pout->u.m[1][1] = 1.0f / tanf(fovy/2.0f);
     pout->u.m[2][2] = zf / (zn - zf);
     pout->u.m[2][3] = -1.0f;
     pout->u.m[3][2] = (zf * zn) / (zn - zf);
@@ -640,10 +640,10 @@ D3DXMATRIX* WINAPI D3DXMatrixRotationX(D3DXMATRIX *pout, FLOAT angle)
     TRACE("pout %p, angle %f\n", pout, angle);
 
     D3DXMatrixIdentity(pout);
-    pout->u.m[1][1] = cos(angle);
-    pout->u.m[2][2] = cos(angle);
-    pout->u.m[1][2] = sin(angle);
-    pout->u.m[2][1] = -sin(angle);
+    pout->u.m[1][1] = cosf(angle);
+    pout->u.m[2][2] = cosf(angle);
+    pout->u.m[1][2] = sinf(angle);
+    pout->u.m[2][1] = -sinf(angle);
     return pout;
 }
 
@@ -652,10 +652,10 @@ D3DXMATRIX* WINAPI D3DXMatrixRotationY(D3DXMATRIX *pout, FLOAT angle)
     TRACE("pout %p, angle %f\n", pout, angle);
 
     D3DXMatrixIdentity(pout);
-    pout->u.m[0][0] = cos(angle);
-    pout->u.m[2][2] = cos(angle);
-    pout->u.m[0][2] = -sin(angle);
-    pout->u.m[2][0] = sin(angle);
+    pout->u.m[0][0] = cosf(angle);
+    pout->u.m[2][2] = cosf(angle);
+    pout->u.m[0][2] = -sinf(angle);
+    pout->u.m[2][0] = sinf(angle);
     return pout;
 }
 
@@ -697,10 +697,10 @@ D3DXMATRIX* WINAPI D3DXMatrixRotationZ(D3DXMATRIX *pout, FLOAT angle)
     TRACE("pout %p, angle %f\n", pout, angle);
 
     D3DXMatrixIdentity(pout);
-    pout->u.m[0][0] = cos(angle);
-    pout->u.m[1][1] = cos(angle);
-    pout->u.m[0][1] = sin(angle);
-    pout->u.m[1][0] = -sin(angle);
+    pout->u.m[0][0] = cosf(angle);
+    pout->u.m[1][1] = cosf(angle);
+    pout->u.m[0][1] = sinf(angle);
+    pout->u.m[1][0] = -sinf(angle);
     return pout;
 }
 
@@ -881,15 +881,15 @@ D3DXMATRIX* WINAPI D3DXMatrixTransformation2D(D3DXMATRIX *pout, const D3DXVECTOR
         trans.z=0.0f;
     }
 
-    rot.w=cos(rotation/2.0f);
+    rot.w=cosf(rotation/2.0f);
     rot.x=0.0f;
     rot.y=0.0f;
-    rot.z=sin(rotation/2.0f);
+    rot.z=sinf(rotation/2.0f);
 
-    sca_rot.w=cos(scalingrotation/2.0f);
+    sca_rot.w=cosf(scalingrotation/2.0f);
     sca_rot.x=0.0f;
     sca_rot.y=0.0f;
-    sca_rot.z=sin(scalingrotation/2.0f);
+    sca_rot.z=sinf(scalingrotation/2.0f);
 
     D3DXMatrixTransformation(pout, &sca_center, &sca_rot, &sca, &rot_center, &rot, &trans);
 
@@ -1648,7 +1648,7 @@ void WINAPI D3DXQuaternionToAxisAngle(const D3DXQUATERNION *pq, D3DXVECTOR3 *pax
     paxis->x = pq->x;
     paxis->y = pq->y;
     paxis->z = pq->z;
-    *pangle = 2.0f * acos(pq->w);
+    *pangle = 2.0f * acosf(pq->w);
 }
 
 /*_________________D3DXVec2_____________________*/
@@ -2121,7 +2121,7 @@ D3DXVECTOR4* WINAPI D3DXVec4TransformArray(D3DXVECTOR4* out, UINT outstride, con
 unsigned short float_32_to_16(const float in)
 {
     int exp = 0, origexp;
-    float tmp = fabs(in);
+    float tmp = fabsf(in);
     int sign = (copysignf(1, in) < 0);
     unsigned int mantissa;
     unsigned short ret;
@@ -2219,7 +2219,7 @@ D3DXFLOAT16 *WINAPI D3DXFloat32To16Array(D3DXFLOAT16 *pout, const FLOAT *pin, UI
 
 /* Native d3dx9's D3DXFloat16to32Array lacks support for NaN and Inf. Specifically, e = 16 is treated as a
  * regular number - e.g., 0x7fff is converted to 131008.0 and 0xffff to -131008.0. */
-static inline float float_16_to_32(const unsigned short in)
+float float_16_to_32(const unsigned short in)
 {
     const unsigned short s = (in & 0x8000);
     const unsigned short e = (in & 0x7C00) >> 10;
@@ -2279,7 +2279,7 @@ FLOAT WINAPI D3DXSHDot(UINT order, const FLOAT *a, const FLOAT *b)
     return s;
 }
 
-static void weightedcapintegrale(FLOAT *out, FLOAT order, FLOAT angle)
+static void weightedcapintegrale(FLOAT *out, UINT order, FLOAT angle)
 {
     FLOAT coeff[3];
 
@@ -2387,9 +2387,9 @@ FLOAT* WINAPI D3DXSHEvalDirection(FLOAT *out, UINT order, const D3DXVECTOR3 *dir
 
     out[9] = -sqrtf(70.0f / D3DX_PI) / 8.0f * dir->y * (3.0f * dirxx - diryy);
     out[10] = sqrtf(105.0f / D3DX_PI) / 2.0f * dirxy * dir->z;
-    out[11] = -sqrtf(42.0 / D3DX_PI) / 8.0f * dir->y * (-1.0f + 5.0f * dirzz);
+    out[11] = -sqrtf(42.0f / D3DX_PI) / 8.0f * dir->y * (-1.0f + 5.0f * dirzz);
     out[12] = sqrtf(7.0f / D3DX_PI) / 4.0f * dir->z * (5.0f * dirzz - 3.0f);
-    out[13] = sqrtf(42.0 / D3DX_PI) / 8.0f * dir->x * (1.0f - 5.0f * dirzz);
+    out[13] = sqrtf(42.0f / D3DX_PI) / 8.0f * dir->x * (1.0f - 5.0f * dirzz);
     out[14] = sqrtf(105.0f / D3DX_PI) / 4.0f * dir->z * (dirxx - diryy);
     out[15] = -sqrtf(70.0f / D3DX_PI) / 8.0f * dir->x * (dirxx - 3.0f * diryy);
     if (order == 4)
@@ -2402,7 +2402,7 @@ FLOAT* WINAPI D3DXSHEvalDirection(FLOAT *out, UINT order, const D3DXVECTOR3 *dir
     out[20] = 3.0f / (16.0f * sqrtf(D3DX_PI)) * (35.0f * dirzzzz - 30.f * dirzz + 3.0f);
     out[21] = 0.375f * sqrtf(10.0f / D3DX_PI) * dirxz * (3.0f - 7.0f * dirzz);
     out[22] = 0.375f * sqrtf(5.0f / D3DX_PI) * (dirxx - diryy) * (7.0f * dirzz - 1.0f);
-    out[23] = 3.0 * dir->z * out[15];
+    out[23] = 3.0f * dir->z * out[15];
     out[24] = 3.0f / 16.0f * sqrtf(35.0f / D3DX_PI) * (dirxxxx - 6.0f * dirxyxy + diryyyy);
     if (order == 5)
         return out;
@@ -2416,7 +2416,7 @@ FLOAT* WINAPI D3DXSHEvalDirection(FLOAT *out, UINT order, const D3DXVECTOR3 *dir
     out[31] = sqrtf(165.0f / D3DX_PI) / 16.0f * dir->x * (14.0f * dirzz - 21.0f * dirzzzz - 1.0f);
     out[32] = sqrtf(1155.0f / D3DX_PI) / 8.0f * dir->z * (dirxx - diryy) * (3.0f * dirzz - 1.0f);
     out[33] = sqrtf(770.0f / D3DX_PI) / 32.0f * dir->x * (dirxx - 3.0f * diryy) * (1.0f - 9.0f * dirzz);
-    out[34] = 3.0f / 16.0f * sqrtf(385.0f / D3DX_PI) * dir->z * (dirxxxx - 6.0 * dirxyxy + diryyyy);
+    out[34] = 3.0f / 16.0f * sqrtf(385.0f / D3DX_PI) * dir->z * (dirxxxx - 6.0f * dirxyxy + diryyyy);
     out[35] = -3.0f/ 32.0f * sqrtf(154.0f / D3DX_PI) * dir->x * (dirxxxx - 10.0f * dirxyxy + 5.0f * diryyyy);
 
     return out;
@@ -2622,8 +2622,8 @@ FLOAT * WINAPI D3DXSHMultiply3(FLOAT *out, const FLOAT *a, const FLOAT *b)
     t = a[4] * b[5] + a[5] * b[4];
     out[7] += 0.15607834f * t;
 
-    ta = 0.28209479f * a[0] + 0.09011186 * a[6] - 0.15607835f * a[8];
-    tb = 0.28209479f * b[0] + 0.09011186 * b[6] - 0.15607835f * b[8];
+    ta = 0.28209479f * a[0] + 0.09011186f * a[6] - 0.15607835f * a[8];
+    tb = 0.28209479f * b[0] + 0.09011186f * b[6] - 0.15607835f * b[8];
     out[5] += ta * b[5] + tb * a[5];
     t = a[5] * b[5];
     out[0] += 0.28209479f * t;
@@ -2637,8 +2637,8 @@ FLOAT * WINAPI D3DXSHMultiply3(FLOAT *out, const FLOAT *a, const FLOAT *b)
     out[0] += 0.28209480f * t;
     out[6] += 0.18022376f * t;
 
-    ta = 0.28209479f * a[0] + 0.09011186 * a[6] + 0.15607835f * a[8];
-    tb = 0.28209479f * b[0] + 0.09011186 * b[6] + 0.15607835f * b[8];
+    ta = 0.28209479f * a[0] + 0.09011186f * a[6] + 0.15607835f * a[8];
+    tb = 0.28209479f * b[0] + 0.09011186f * b[6] + 0.15607835f * b[8];
     out[7] += ta * b[7] + tb * a[7];
     t = a[7] * b[7];
     out[0] += 0.28209479f * t;
@@ -2981,7 +2981,7 @@ static void rotate_X(FLOAT *out, UINT order, FLOAT a, FLOAT *in)
 
     out[25] = a * 0.7015607357f * in[30] - a * 0.6846531630f * in[32] + a * 0.1976423711f * in[34];
     out[26] = -0.5f * in[26] + 0.8660253882f * in[28];
-    out[27] = a * 0.5229125023f * in[30] + a * 0.3061861992f * in[32] - a * 0.7954951525 * in[34];
+    out[27] = a * 0.5229125023f * in[30] + a * 0.3061861992f * in[32] - a * 0.7954951525f * in[34];
     out[28] = 0.8660253882f * in[26] + 0.5f * in[28];
     out[29] = a * 0.4841229022f * in[30] + a * 0.6614378691f * in[32] + a * 0.5728219748f * in[34];
     out[30] = -a * 0.7015607357f * in[25] - a * 0.5229125023f * in[27] - a * 0.4841229022f * in[29];
index ba97552..aa74c7a 100644 (file)
@@ -37,9 +37,7 @@
 #include "rmxftmpl.h"
 #include "wine/list.h"
 
-#define fmax(a, b) ((a) > (b) ? (a) : (b))
-
-typedef struct ID3DXMeshImpl
+struct d3dx9_mesh
 {
     ID3DXMesh ID3DXMesh_iface;
     LONG ref;
@@ -59,7 +57,7 @@ typedef struct ID3DXMeshImpl
     int attrib_buffer_lock_count;
     DWORD attrib_table_size;
     D3DXATTRIBUTERANGE *attrib_table;
-} ID3DXMeshImpl;
+};
 
 const UINT d3dx_decltype_size[] =
 {
@@ -82,21 +80,21 @@ const UINT d3dx_decltype_size[] =
    /* D3DDECLTYPE_FLOAT16_4 */ 4 * sizeof(D3DXFLOAT16),
 };
 
-static inline ID3DXMeshImpl *impl_from_ID3DXMesh(ID3DXMesh *iface)
+static inline struct d3dx9_mesh *impl_from_ID3DXMesh(ID3DXMesh *iface)
 {
-    return CONTAINING_RECORD(iface, ID3DXMeshImpl, ID3DXMesh_iface);
+    return CONTAINING_RECORD(iface, struct d3dx9_mesh, ID3DXMesh_iface);
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_QueryInterface(ID3DXMesh *iface, REFIID riid, LPVOID *object)
+static HRESULT WINAPI d3dx9_mesh_QueryInterface(ID3DXMesh *iface, REFIID riid, void **out)
 {
-    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), object);
+    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
 
     if (IsEqualGUID(riid, &IID_IUnknown) ||
         IsEqualGUID(riid, &IID_ID3DXBaseMesh) ||
         IsEqualGUID(riid, &IID_ID3DXMesh))
     {
         iface->lpVtbl->AddRef(iface);
-        *object = iface;
+        *out = iface;
         return S_OK;
     }
 
@@ -105,47 +103,47 @@ static HRESULT WINAPI ID3DXMeshImpl_QueryInterface(ID3DXMesh *iface, REFIID riid
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI ID3DXMeshImpl_AddRef(ID3DXMesh *iface)
+static ULONG WINAPI d3dx9_mesh_AddRef(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
+    ULONG refcount = InterlockedIncrement(&mesh->ref);
 
-    TRACE("(%p)->(): AddRef from %d\n", This, This->ref);
+    TRACE("%p increasing refcount to %u.\n", mesh, refcount);
 
-    return InterlockedIncrement(&This->ref);
+    return refcount;
 }
 
-static ULONG WINAPI ID3DXMeshImpl_Release(ID3DXMesh *iface)
+static ULONG WINAPI d3dx9_mesh_Release(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
-    ULONG ref = InterlockedDecrement(&This->ref);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
+    ULONG refcount = InterlockedDecrement(&mesh->ref);
 
-    TRACE("(%p)->(): Release from %d\n", This, ref + 1);
+    TRACE("%p decreasing refcount to %u.\n", mesh, refcount);
 
-    if (!ref)
+    if (!refcount)
     {
-        IDirect3DIndexBuffer9_Release(This->index_buffer);
-        IDirect3DVertexBuffer9_Release(This->vertex_buffer);
-        if (This->vertex_declaration)
-            IDirect3DVertexDeclaration9_Release(This->vertex_declaration);
-        IDirect3DDevice9_Release(This->device);
-        HeapFree(GetProcessHeap(), 0, This->attrib_buffer);
-        HeapFree(GetProcessHeap(), 0, This->attrib_table);
-        HeapFree(GetProcessHeap(), 0, This);
+        IDirect3DIndexBuffer9_Release(mesh->index_buffer);
+        IDirect3DVertexBuffer9_Release(mesh->vertex_buffer);
+        if (mesh->vertex_declaration)
+            IDirect3DVertexDeclaration9_Release(mesh->vertex_declaration);
+        IDirect3DDevice9_Release(mesh->device);
+        HeapFree(GetProcessHeap(), 0, mesh->attrib_buffer);
+        HeapFree(GetProcessHeap(), 0, mesh->attrib_table);
+        HeapFree(GetProcessHeap(), 0, mesh);
     }
 
-    return ref;
+    return refcount;
 }
 
-/*** ID3DXBaseMesh ***/
-static HRESULT WINAPI ID3DXMeshImpl_DrawSubset(ID3DXMesh *iface, DWORD attrib_id)
+static HRESULT WINAPI d3dx9_mesh_DrawSubset(ID3DXMesh *iface, DWORD attrib_id)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *This = impl_from_ID3DXMesh(iface);
     HRESULT hr;
     DWORD face_start;
     DWORD face_end = 0;
     DWORD vertex_size;
 
-    TRACE("(%p)->(%u)\n", This, attrib_id);
+    TRACE("iface %p, attrib_id %u.\n", iface, attrib_id);
 
     if (!This->vertex_declaration)
     {
@@ -185,31 +183,31 @@ static HRESULT WINAPI ID3DXMeshImpl_DrawSubset(ID3DXMesh *iface, DWORD attrib_id
     return D3D_OK;
 }
 
-static DWORD WINAPI ID3DXMeshImpl_GetNumFaces(ID3DXMesh *iface)
+static DWORD WINAPI d3dx9_mesh_GetNumFaces(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->numfaces;
+    return mesh->numfaces;
 }
 
-static DWORD WINAPI ID3DXMeshImpl_GetNumVertices(ID3DXMesh *iface)
+static DWORD WINAPI d3dx9_mesh_GetNumVertices(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->numvertices;
+    return mesh->numvertices;
 }
 
-static DWORD WINAPI ID3DXMeshImpl_GetFVF(ID3DXMesh *iface)
+static DWORD WINAPI d3dx9_mesh_GetFVF(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->fvf;
+    return mesh->fvf;
 }
 
 static void copy_declaration(D3DVERTEXELEMENT9 *dst, const D3DVERTEXELEMENT9 *src, UINT num_elem)
@@ -217,61 +215,63 @@ static void copy_declaration(D3DVERTEXELEMENT9 *dst, const D3DVERTEXELEMENT9 *sr
     memcpy(dst, src, num_elem * sizeof(*src));
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_GetDeclaration(ID3DXMesh *iface, D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE])
+static HRESULT WINAPI d3dx9_mesh_GetDeclaration(ID3DXMesh *iface, D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE])
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p, declaration %p.\n", iface, declaration);
 
-    if (declaration == NULL) return D3DERR_INVALIDCALL;
+    if (!declaration)
+        return D3DERR_INVALIDCALL;
 
-    copy_declaration(declaration, This->cached_declaration, This->num_elem);
+    copy_declaration(declaration, mesh->cached_declaration, mesh->num_elem);
 
     return D3D_OK;
 }
 
-static DWORD WINAPI ID3DXMeshImpl_GetNumBytesPerVertex(ID3DXMesh *iface)
+static DWORD WINAPI d3dx9_mesh_GetNumBytesPerVertex(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("iface (%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->vertex_declaration_size;
+    return mesh->vertex_declaration_size;
 }
 
-static DWORD WINAPI ID3DXMeshImpl_GetOptions(ID3DXMesh *iface)
+static DWORD WINAPI d3dx9_mesh_GetOptions(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->options;
+    return mesh->options;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_GetDevice(struct ID3DXMesh *iface, struct IDirect3DDevice9 **device)
+static HRESULT WINAPI d3dx9_mesh_GetDevice(struct ID3DXMesh *iface, struct IDirect3DDevice9 **device)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)->(%p)\n", This, device);
+    TRACE("iface %p, device %p.\n", iface, device);
 
-    if (device == NULL) return D3DERR_INVALIDCALL;
-    *device = This->device;
-    IDirect3DDevice9_AddRef(This->device);
+    if (!device)
+        return D3DERR_INVALIDCALL;
+    *device = mesh->device;
+    IDirect3DDevice9_AddRef(mesh->device);
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_CloneMeshFVF(struct ID3DXMesh *iface, DWORD options, DWORD fvf,
+static HRESULT WINAPI d3dx9_mesh_CloneMeshFVF(struct ID3DXMesh *iface, DWORD options, DWORD fvf,
         struct IDirect3DDevice9 *device, struct ID3DXMesh **clone_mesh)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
     HRESULT hr;
     D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE];
 
-    TRACE("(%p)->(%x,%x,%p,%p)\n", This, options, fvf, device, clone_mesh);
+    TRACE("iface %p, options %#x, fvf %#x, device %p, clone_mesh %p.\n",
+            iface, options, fvf, device, clone_mesh);
 
-    hr = D3DXDeclaratorFromFVF(fvf, declaration);
-    if (FAILED(hr)) return hr;
+    if (FAILED(hr = D3DXDeclaratorFromFVF(fvf, declaration)))
+        return hr;
 
     return iface->lpVtbl->CloneMesh(iface, options, declaration, device, clone_mesh);
 }
@@ -336,7 +336,7 @@ static INT simple_round(FLOAT value)
     return res;
 }
 
-static void convert_float4(BYTE *dst, CONST D3DXVECTOR4 *src, D3DDECLTYPE type_dst)
+static void convert_float4(BYTE *dst, const D3DXVECTOR4 *src, D3DDECLTYPE type_dst)
 {
     BOOL fixme_once = FALSE;
 
@@ -650,7 +650,7 @@ cleanup:
     return hr;
 }
 
-static BOOL declaration_equals(CONST D3DVERTEXELEMENT9 *declaration1, CONST D3DVERTEXELEMENT9 *declaration2)
+static BOOL declaration_equals(const D3DVERTEXELEMENT9 *declaration1, const D3DVERTEXELEMENT9 *declaration2)
 {
     UINT size1 = 0, size2 = 0;
 
@@ -669,11 +669,11 @@ static BOOL declaration_equals(CONST D3DVERTEXELEMENT9 *declaration1, CONST D3DV
     return FALSE;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_CloneMesh(struct ID3DXMesh *iface, DWORD options,
+static HRESULT WINAPI d3dx9_mesh_CloneMesh(struct ID3DXMesh *iface, DWORD options,
         const D3DVERTEXELEMENT9 *declaration, struct IDirect3DDevice9 *device, struct ID3DXMesh **clone_mesh_out)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
-    ID3DXMeshImpl *cloned_this;
+    struct d3dx9_mesh *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *cloned_this;
     ID3DXMesh *clone_mesh;
     D3DVERTEXELEMENT9 orig_declaration[MAX_FVF_DECL_SIZE] = { D3DDECL_END() };
     void *data_in, *data_out;
@@ -681,7 +681,8 @@ static HRESULT WINAPI ID3DXMeshImpl_CloneMesh(struct ID3DXMesh *iface, DWORD opt
     HRESULT hr;
     BOOL same_declaration;
 
-    TRACE("(%p)->(%x,%p,%p,%p)\n", This, options, declaration, device, clone_mesh_out);
+    TRACE("iface %p, options %#x, declaration %p, device %p, clone_mesh_out %p.\n",
+            iface, options, declaration, device, clone_mesh_out);
 
     if (!clone_mesh_out)
         return D3DERR_INVALIDCALL;
@@ -765,81 +766,87 @@ error:
     return hr;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_GetVertexBuffer(struct ID3DXMesh *iface,
+static HRESULT WINAPI d3dx9_mesh_GetVertexBuffer(struct ID3DXMesh *iface,
         struct IDirect3DVertexBuffer9 **vertex_buffer)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)->(%p)\n", This, vertex_buffer);
+    TRACE("iface %p, vertex_buffer %p.\n", iface, vertex_buffer);
 
-    if (vertex_buffer == NULL) return D3DERR_INVALIDCALL;
-    *vertex_buffer = This->vertex_buffer;
-    IDirect3DVertexBuffer9_AddRef(This->vertex_buffer);
+    if (!vertex_buffer)
+        return D3DERR_INVALIDCALL;
+    *vertex_buffer = mesh->vertex_buffer;
+    IDirect3DVertexBuffer9_AddRef(mesh->vertex_buffer);
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_GetIndexBuffer(struct ID3DXMesh *iface,
+static HRESULT WINAPI d3dx9_mesh_GetIndexBuffer(struct ID3DXMesh *iface,
         struct IDirect3DIndexBuffer9 **index_buffer)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)->(%p)\n", This, index_buffer);
+    TRACE("iface %p, index_buffer %p.\n", iface, index_buffer);
 
-    if (index_buffer == NULL) return D3DERR_INVALIDCALL;
-    *index_buffer = This->index_buffer;
-    IDirect3DIndexBuffer9_AddRef(This->index_buffer);
+    if (!index_buffer)
+        return D3DERR_INVALIDCALL;
+    *index_buffer = mesh->index_buffer;
+    IDirect3DIndexBuffer9_AddRef(mesh->index_buffer);
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_LockVertexBuffer(ID3DXMesh *iface, DWORD flags, LPVOID *data)
+static HRESULT WINAPI d3dx9_mesh_LockVertexBuffer(ID3DXMesh *iface, DWORD flags, void **data)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)->(%u,%p)\n", This, flags, data);
+    TRACE("iface %p, flags %#x, data %p.\n", iface, flags, data);
 
-    return IDirect3DVertexBuffer9_Lock(This->vertex_buffer, 0, 0, data, flags);
+    return IDirect3DVertexBuffer9_Lock(mesh->vertex_buffer, 0, 0, data, flags);
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_UnlockVertexBuffer(ID3DXMesh *iface)
+static HRESULT WINAPI d3dx9_mesh_UnlockVertexBuffer(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return IDirect3DVertexBuffer9_Unlock(This->vertex_buffer);
+    return IDirect3DVertexBuffer9_Unlock(mesh->vertex_buffer);
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_LockIndexBuffer(ID3DXMesh *iface, DWORD flags, LPVOID *data)
+static HRESULT WINAPI d3dx9_mesh_LockIndexBuffer(ID3DXMesh *iface, DWORD flags, void **data)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)->(%u,%p)\n", This, flags, data);
+    TRACE("iface %p, flags %#x, data %p.\n", iface, flags, data);
 
-    return IDirect3DIndexBuffer9_Lock(This->index_buffer, 0, 0, data, flags);
+    return IDirect3DIndexBuffer9_Lock(mesh->index_buffer, 0, 0, data, flags);
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_UnlockIndexBuffer(ID3DXMesh *iface)
+static HRESULT WINAPI d3dx9_mesh_UnlockIndexBuffer(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return IDirect3DIndexBuffer9_Unlock(This->index_buffer);
+    return IDirect3DIndexBuffer9_Unlock(mesh->index_buffer);
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_GetAttributeTable(ID3DXMesh *iface, D3DXATTRIBUTERANGE *attrib_table, DWORD *attrib_table_size)
+/* FIXME: This looks just wrong, we never check *attrib_table_size before
+ * copying the data. */
+static HRESULT WINAPI d3dx9_mesh_GetAttributeTable(ID3DXMesh *iface,
+        D3DXATTRIBUTERANGE *attrib_table, DWORD *attrib_table_size)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)->(%p,%p)\n", This, attrib_table, attrib_table_size);
+    TRACE("iface %p, attrib_table %p, attrib_table_size %p.\n",
+            iface, attrib_table, attrib_table_size);
 
     if (attrib_table_size)
-        *attrib_table_size = This->attrib_table_size;
+        *attrib_table_size = mesh->attrib_table_size;
 
     if (attrib_table)
-        CopyMemory(attrib_table, This->attrib_table, This->attrib_table_size * sizeof(*attrib_table));
+        memcpy(attrib_table, mesh->attrib_table, mesh->attrib_table_size * sizeof(*attrib_table));
 
     return D3D_OK;
 }
@@ -867,7 +874,8 @@ struct edge_face_map
  * is at most one edge to face mapping, i.e. an edge can only belong to one
  * face.
  */
-static HRESULT init_edge_face_map(struct edge_face_map *edge_face_map, CONST DWORD *index_buffer, CONST DWORD *point_reps, CONST DWORD num_faces)
+static HRESULT init_edge_face_map(struct edge_face_map *edge_face_map, const DWORD *index_buffer,
+        const DWORD *point_reps, DWORD num_faces)
 {
     DWORD face, edge;
     DWORD i;
@@ -907,7 +915,7 @@ static HRESULT init_edge_face_map(struct edge_face_map *edge_face_map, CONST DWO
     return D3D_OK;
 }
 
-static DWORD find_adjacent_face(struct edge_face_map *edge_face_map, DWORD vertex1, DWORD vertex2, CONST DWORD num_faces)
+static DWORD find_adjacent_face(struct edge_face_map *edge_face_map, DWORD vertex1, DWORD vertex2, DWORD num_faces)
 {
     struct edge_face *edge_face_ptr;
 
@@ -937,9 +945,9 @@ static DWORD *generate_identity_point_reps(DWORD num_vertices)
         return id_point_reps;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_ConvertPointRepsToAdjacency(ID3DXMesh *iface, CONST DWORD *point_reps, DWORD *adjacency)
+static HRESULT WINAPI d3dx9_mesh_ConvertPointRepsToAdjacency(ID3DXMesh *iface,
+        const DWORD *point_reps, DWORD *adjacency)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
     HRESULT hr;
     DWORD num_faces = iface->lpVtbl->GetNumFaces(iface);
     DWORD num_vertices = iface->lpVtbl->GetNumVertices(iface);
@@ -950,10 +958,10 @@ static HRESULT WINAPI ID3DXMeshImpl_ConvertPointRepsToAdjacency(ID3DXMesh *iface
     DWORD face;
     DWORD edge;
     struct edge_face_map edge_face_map = {0};
-    CONST DWORD *point_reps_ptr = NULL;
+    const DWORD *point_reps_ptr = NULL;
     DWORD *id_point_reps = NULL;
 
-    TRACE("(%p)->(%p,%p)\n", This, point_reps, adjacency);
+    TRACE("iface %p, point_reps %p, adjacency %p.\n", iface, point_reps, adjacency);
 
     if (!adjacency) return D3DERR_INVALIDCALL;
 
@@ -1038,9 +1046,8 @@ cleanup:
  * vertex 5 is replaced by vertex 3 then index 5 would contain 3. If no vertex
  * replaces it, then it contains the same number as the index itself, e.g.
  * index 5 would contain 5. */
-static HRESULT propagate_face_vertices(CONST DWORD *adjacency, DWORD *point_reps,
-                                    CONST DWORD *indices, DWORD *new_indices,
-                                    CONST DWORD face, CONST DWORD numfaces)
+static HRESULT propagate_face_vertices(const DWORD *adjacency, DWORD *point_reps,
+        const DWORD *indices, DWORD *new_indices, DWORD face, DWORD numfaces)
 {
     const unsigned int VERTS_PER_FACE = 3;
     DWORD edge, opp_edge;
@@ -1088,8 +1095,10 @@ static HRESULT propagate_face_vertices(CONST DWORD *adjacency, DWORD *point_reps
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_ConvertAdjacencyToPointReps(ID3DXMesh *iface, CONST DWORD *adjacency, DWORD *point_reps)
+static HRESULT WINAPI d3dx9_mesh_ConvertAdjacencyToPointReps(ID3DXMesh *iface,
+        const DWORD *adjacency, DWORD *point_reps)
 {
+    struct d3dx9_mesh *This = impl_from_ID3DXMesh(iface);
     HRESULT hr;
     DWORD face;
     DWORD i;
@@ -1098,9 +1107,7 @@ static HRESULT WINAPI ID3DXMeshImpl_ConvertAdjacencyToPointReps(ID3DXMesh *iface
     DWORD *new_indices = NULL;
     const unsigned int VERTS_PER_FACE = 3;
 
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
-
-    TRACE("(%p)->(%p,%p)\n", This, adjacency, point_reps);
+    TRACE("iface %p, adjacency %p, point_reps %p.\n", iface, adjacency, point_reps);
 
     if (!adjacency)
     {
@@ -1209,9 +1216,9 @@ static int compare_vertex_keys(const void *a, const void *b)
     return left->key < right->key ? -1 : 1;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_GenerateAdjacency(ID3DXMesh *iface, FLOAT epsilon, DWORD *adjacency)
+static HRESULT WINAPI d3dx9_mesh_GenerateAdjacency(ID3DXMesh *iface, float epsilon, DWORD *adjacency)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *This = impl_from_ID3DXMesh(iface);
     HRESULT hr;
     BYTE *vertices = NULL;
     const DWORD *indices = NULL;
@@ -1225,7 +1232,7 @@ static HRESULT WINAPI ID3DXMeshImpl_GenerateAdjacency(ID3DXMesh *iface, FLOAT ep
     const FLOAT epsilon_sq = epsilon * epsilon;
     DWORD i;
 
-    TRACE("(%p)->(%f,%p)\n", This, epsilon, adjacency);
+    TRACE("iface %p, epsilon %.8e, adjacency %p.\n", iface, epsilon, adjacency);
 
     if (!adjacency)
         return D3DERR_INVALIDCALL;
@@ -1355,14 +1362,14 @@ cleanup:
     return hr;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_UpdateSemantics(ID3DXMesh *iface, D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE])
+static HRESULT WINAPI d3dx9_mesh_UpdateSemantics(ID3DXMesh *iface, D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE])
 {
+    struct d3dx9_mesh *This = impl_from_ID3DXMesh(iface);
     HRESULT hr;
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
     UINT vertex_declaration_size;
     int i;
 
-    TRACE("(%p)->(%p)\n", This, declaration);
+    TRACE("iface %p, declaration %p.\n", iface, declaration);
 
     if (!declaration)
     {
@@ -1414,53 +1421,54 @@ static HRESULT WINAPI ID3DXMeshImpl_UpdateSemantics(ID3DXMesh *iface, D3DVERTEXE
     return D3D_OK;
 }
 
-/*** ID3DXMesh ***/
-static HRESULT WINAPI ID3DXMeshImpl_LockAttributeBuffer(ID3DXMesh *iface, DWORD flags, DWORD **data)
+static HRESULT WINAPI d3dx9_mesh_LockAttributeBuffer(ID3DXMesh *iface, DWORD flags, DWORD **data)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
 
-    TRACE("(%p)->(%u,%p)\n", This, flags, data);
+    TRACE("iface %p, flags %#x, data %p.\n", iface, flags, data);
 
-    InterlockedIncrement(&This->attrib_buffer_lock_count);
+    InterlockedIncrement(&mesh->attrib_buffer_lock_count);
 
-    if (!(flags & D3DLOCK_READONLY)) {
-        D3DXATTRIBUTERANGE *attrib_table = This->attrib_table;
-        This->attrib_table_size = 0;
-        This->attrib_table = NULL;
+    if (!(flags & D3DLOCK_READONLY))
+    {
+        D3DXATTRIBUTERANGE *attrib_table = mesh->attrib_table;
+        mesh->attrib_table_size = 0;
+        mesh->attrib_table = NULL;
         HeapFree(GetProcessHeap(), 0, attrib_table);
     }
 
-    *data = This->attrib_buffer;
+    *data = mesh->attrib_buffer;
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_UnlockAttributeBuffer(ID3DXMesh *iface)
+static HRESULT WINAPI d3dx9_mesh_UnlockAttributeBuffer(ID3DXMesh *iface)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
     int lock_count;
 
-    TRACE("(%p)\n", This);
-
-    lock_count = InterlockedDecrement(&This->attrib_buffer_lock_count);
+    TRACE("iface %p.\n", iface);
 
-    if (lock_count < 0) {
-        InterlockedIncrement(&This->attrib_buffer_lock_count);
+    lock_count = InterlockedDecrement(&mesh->attrib_buffer_lock_count);
+    if (lock_count < 0)
+    {
+        InterlockedIncrement(&mesh->attrib_buffer_lock_count);
         return D3DERR_INVALIDCALL;
     }
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_Optimize(ID3DXMesh *iface, DWORD flags, const DWORD *adjacency_in,
+static HRESULT WINAPI d3dx9_mesh_Optimize(ID3DXMesh *iface, DWORD flags, const DWORD *adjacency_in,
         DWORD *adjacency_out, DWORD *face_remap, ID3DXBuffer **vertex_remap, ID3DXMesh **opt_mesh)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
     HRESULT hr;
     D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE] = { D3DDECL_END() };
     ID3DXMesh *optimized_mesh;
 
-    TRACE("(%p)->(%x,%p,%p,%p,%p,%p)\n", This, flags, adjacency_in, adjacency_out, face_remap, vertex_remap, opt_mesh);
+    TRACE("iface %p, flags %#x, adjacency_in %p, adjacency_out %p, face_remap %p, vertex_remap %p, opt_mesh %p.\n",
+            iface, flags, adjacency_in, adjacency_out, face_remap, vertex_remap, opt_mesh);
 
     if (!opt_mesh)
         return D3DERR_INVALIDCALL;
@@ -1468,8 +1476,8 @@ static HRESULT WINAPI ID3DXMeshImpl_Optimize(ID3DXMesh *iface, DWORD flags, cons
     hr = iface->lpVtbl->GetDeclaration(iface, declaration);
     if (FAILED(hr)) return hr;
 
-    hr = iface->lpVtbl->CloneMesh(iface, This->options, declaration, This->device, &optimized_mesh);
-    if (FAILED(hr)) return hr;
+    if (FAILED(hr = iface->lpVtbl->CloneMesh(iface, mesh->options, declaration, mesh->device, &optimized_mesh)))
+        return hr;
 
     hr = optimized_mesh->lpVtbl->OptimizeInplace(optimized_mesh, flags, adjacency_in, adjacency_out, face_remap, vertex_remap);
     if (SUCCEEDED(hr))
@@ -1481,7 +1489,8 @@ static HRESULT WINAPI ID3DXMeshImpl_Optimize(ID3DXMesh *iface, DWORD flags, cons
 
 /* Creates a vertex_remap that removes unused vertices.
  * Indices are updated according to the vertex_remap. */
-static HRESULT compact_mesh(ID3DXMeshImpl *This, DWORD *indices, DWORD *new_num_vertices, ID3DXBuffer **vertex_remap)
+static HRESULT compact_mesh(struct d3dx9_mesh *This, DWORD *indices,
+        DWORD *new_num_vertices, ID3DXBuffer **vertex_remap)
 {
     HRESULT hr;
     DWORD *vertex_remap_ptr;
@@ -1590,18 +1599,23 @@ static int attrib_entry_compare(const DWORD **a, const DWORD **b)
 }
 
 /* Create face_remap, a new attribute buffer for attribute sort optimization. */
-static HRESULT remap_faces_for_attrsort(ID3DXMeshImpl *This, const DWORD *indices,
-        const DWORD *attrib_buffer, DWORD **sorted_attrib_buffer, DWORD **face_remap)
+static HRESULT remap_faces_for_attrsort(struct d3dx9_mesh *This, const DWORD *indices,
+        DWORD *attrib_buffer, DWORD **sorted_attrib_buffer, DWORD **face_remap)
 {
-    const DWORD **sorted_attrib_ptr_buffer = NULL;
+    DWORD **sorted_attrib_ptr_buffer = NULL;
     DWORD i;
 
-    *face_remap = HeapAlloc(GetProcessHeap(), 0, This->numfaces * sizeof(**face_remap));
     sorted_attrib_ptr_buffer = HeapAlloc(GetProcessHeap(), 0, This->numfaces * sizeof(*sorted_attrib_ptr_buffer));
-    if (!*face_remap || !sorted_attrib_ptr_buffer) {
+    if (!sorted_attrib_ptr_buffer)
+        return E_OUTOFMEMORY;
+
+    *face_remap = HeapAlloc(GetProcessHeap(), 0, This->numfaces * sizeof(**face_remap));
+    if (!*face_remap)
+    {
         HeapFree(GetProcessHeap(), 0, sorted_attrib_ptr_buffer);
         return E_OUTOFMEMORY;
     }
+
     for (i = 0; i < This->numfaces; i++)
         sorted_attrib_ptr_buffer[i] = &attrib_buffer[i];
     qsort(sorted_attrib_ptr_buffer, This->numfaces, sizeof(*sorted_attrib_ptr_buffer),
@@ -1621,10 +1635,10 @@ static HRESULT remap_faces_for_attrsort(ID3DXMeshImpl *This, const DWORD *indice
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_OptimizeInplace(ID3DXMesh *iface, DWORD flags, const DWORD *adjacency_in,
+static HRESULT WINAPI d3dx9_mesh_OptimizeInplace(ID3DXMesh *iface, DWORD flags, const DWORD *adjacency_in,
         DWORD *adjacency_out, DWORD *face_remap_out, ID3DXBuffer **vertex_remap_out)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *This = impl_from_ID3DXMesh(iface);
     void *indices = NULL;
     DWORD *attrib_buffer = NULL;
     HRESULT hr;
@@ -1637,7 +1651,8 @@ static HRESULT WINAPI ID3DXMeshImpl_OptimizeInplace(ID3DXMesh *iface, DWORD flag
     DWORD *sorted_attrib_buffer = NULL;
     DWORD i;
 
-    TRACE("(%p)->(%x,%p,%p,%p,%p)\n", This, flags, adjacency_in, adjacency_out, face_remap_out, vertex_remap_out);
+    TRACE("iface %p, flags %#x, adjacency_in %p, adjacency_out %p, face_remap_out %p, vertex_remap_out %p.\n",
+            iface, flags, adjacency_in, adjacency_out, face_remap_out, vertex_remap_out);
 
     if (!flags)
         return D3DERR_INVALIDCALL;
@@ -1818,12 +1833,13 @@ cleanup:
     return hr;
 }
 
-static HRESULT WINAPI ID3DXMeshImpl_SetAttributeTable(ID3DXMesh *iface, CONST D3DXATTRIBUTERANGE *attrib_table, DWORD attrib_table_size)
+static HRESULT WINAPI d3dx9_mesh_SetAttributeTable(ID3DXMesh *iface,
+        const D3DXATTRIBUTERANGE *attrib_table, DWORD attrib_table_size)
 {
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(iface);
+    struct d3dx9_mesh *mesh = impl_from_ID3DXMesh(iface);
     D3DXATTRIBUTERANGE *new_table = NULL;
 
-    TRACE("(%p)->(%p,%u)\n", This, attrib_table, attrib_table_size);
+    TRACE("iface %p, attrib_table %p, attrib_table_size %u.\n", iface, attrib_table, attrib_table_size);
 
     if (attrib_table_size) {
         size_t size = attrib_table_size * sizeof(*attrib_table);
@@ -1836,53 +1852,46 @@ static HRESULT WINAPI ID3DXMeshImpl_SetAttributeTable(ID3DXMesh *iface, CONST D3
     } else if (attrib_table) {
         return D3DERR_INVALIDCALL;
     }
-    HeapFree(GetProcessHeap(), 0, This->attrib_table);
-    This->attrib_table = new_table;
-    This->attrib_table_size = attrib_table_size;
+    HeapFree(GetProcessHeap(), 0, mesh->attrib_table);
+    mesh->attrib_table = new_table;
+    mesh->attrib_table_size = attrib_table_size;
 
     return D3D_OK;
 }
 
 static const struct ID3DXMeshVtbl D3DXMesh_Vtbl =
 {
-    /*** IUnknown methods ***/
-    ID3DXMeshImpl_QueryInterface,
-    ID3DXMeshImpl_AddRef,
-    ID3DXMeshImpl_Release,
-    /*** ID3DXBaseMesh ***/
-    ID3DXMeshImpl_DrawSubset,
-    ID3DXMeshImpl_GetNumFaces,
-    ID3DXMeshImpl_GetNumVertices,
-    ID3DXMeshImpl_GetFVF,
-    ID3DXMeshImpl_GetDeclaration,
-    ID3DXMeshImpl_GetNumBytesPerVertex,
-    ID3DXMeshImpl_GetOptions,
-    ID3DXMeshImpl_GetDevice,
-    ID3DXMeshImpl_CloneMeshFVF,
-    ID3DXMeshImpl_CloneMesh,
-    ID3DXMeshImpl_GetVertexBuffer,
-    ID3DXMeshImpl_GetIndexBuffer,
-    ID3DXMeshImpl_LockVertexBuffer,
-    ID3DXMeshImpl_UnlockVertexBuffer,
-    ID3DXMeshImpl_LockIndexBuffer,
-    ID3DXMeshImpl_UnlockIndexBuffer,
-    ID3DXMeshImpl_GetAttributeTable,
-    ID3DXMeshImpl_ConvertPointRepsToAdjacency,
-    ID3DXMeshImpl_ConvertAdjacencyToPointReps,
-    ID3DXMeshImpl_GenerateAdjacency,
-    ID3DXMeshImpl_UpdateSemantics,
-    /*** ID3DXMesh ***/
-    ID3DXMeshImpl_LockAttributeBuffer,
-    ID3DXMeshImpl_UnlockAttributeBuffer,
-    ID3DXMeshImpl_Optimize,
-    ID3DXMeshImpl_OptimizeInplace,
-    ID3DXMeshImpl_SetAttributeTable
+    d3dx9_mesh_QueryInterface,
+    d3dx9_mesh_AddRef,
+    d3dx9_mesh_Release,
+    d3dx9_mesh_DrawSubset,
+    d3dx9_mesh_GetNumFaces,
+    d3dx9_mesh_GetNumVertices,
+    d3dx9_mesh_GetFVF,
+    d3dx9_mesh_GetDeclaration,
+    d3dx9_mesh_GetNumBytesPerVertex,
+    d3dx9_mesh_GetOptions,
+    d3dx9_mesh_GetDevice,
+    d3dx9_mesh_CloneMeshFVF,
+    d3dx9_mesh_CloneMesh,
+    d3dx9_mesh_GetVertexBuffer,
+    d3dx9_mesh_GetIndexBuffer,
+    d3dx9_mesh_LockVertexBuffer,
+    d3dx9_mesh_UnlockVertexBuffer,
+    d3dx9_mesh_LockIndexBuffer,
+    d3dx9_mesh_UnlockIndexBuffer,
+    d3dx9_mesh_GetAttributeTable,
+    d3dx9_mesh_ConvertPointRepsToAdjacency,
+    d3dx9_mesh_ConvertAdjacencyToPointReps,
+    d3dx9_mesh_GenerateAdjacency,
+    d3dx9_mesh_UpdateSemantics,
+    d3dx9_mesh_LockAttributeBuffer,
+    d3dx9_mesh_UnlockAttributeBuffer,
+    d3dx9_mesh_Optimize,
+    d3dx9_mesh_OptimizeInplace,
+    d3dx9_mesh_SetAttributeTable,
 };
 
-/*************************************************************************
- * D3DXBoxBoundProbe
- */
-BOOL WINAPI D3DXBoxBoundProbe(CONST D3DXVECTOR3 *pmin, CONST D3DXVECTOR3 *pmax, CONST D3DXVECTOR3 *prayposition, CONST D3DXVECTOR3 *praydirection)
 
 /* Algorithm taken from the article: An Efficient and Robust Ray-Box Intersection Algorithm
 Amy Williams             University of Utah
@@ -1898,9 +1907,9 @@ This algorithm is free of patents or of copyrights, as confirmed by Peter Shirle
 
 Algorithm: Consider the box as the intersection of three slabs. Clip the ray
 against each slab, if there's anything left of the ray after we're
-done we've got an intersection of the ray with the box.
-*/
-
+done we've got an intersection of the ray with the box. */
+BOOL WINAPI D3DXBoxBoundProbe(const D3DXVECTOR3 *pmin, const D3DXVECTOR3 *pmax,
+        const D3DXVECTOR3 *prayposition, const D3DXVECTOR3 *praydirection)
 {
     FLOAT div, tmin, tmax, tymin, tymax, tzmin, tzmax;
 
@@ -1952,10 +1961,8 @@ done we've got an intersection of the ray with the box.
     return TRUE;
 }
 
-/*************************************************************************
- * D3DXComputeBoundingBox
- */
-HRESULT WINAPI D3DXComputeBoundingBox(CONST D3DXVECTOR3 *pfirstposition, DWORD numvertices, DWORD dwstride, D3DXVECTOR3 *pmin, D3DXVECTOR3 *pmax)
+HRESULT WINAPI D3DXComputeBoundingBox(const D3DXVECTOR3 *pfirstposition,
+        DWORD numvertices, DWORD dwstride, D3DXVECTOR3 *pmin, D3DXVECTOR3 *pmax)
 {
     D3DXVECTOR3 vec;
     unsigned int i;
@@ -1982,10 +1989,8 @@ HRESULT WINAPI D3DXComputeBoundingBox(CONST D3DXVECTOR3 *pfirstposition, DWORD n
     return D3D_OK;
 }
 
-/*************************************************************************
- * D3DXComputeBoundingSphere
- */
-HRESULT WINAPI D3DXComputeBoundingSphere(CONST D3DXVECTOR3* pfirstposition, DWORD numvertices, DWORD dwstride, D3DXVECTOR3 *pcenter, FLOAT *pradius)
+HRESULT WINAPI D3DXComputeBoundingSphere(const D3DXVECTOR3 *pfirstposition,
+        DWORD numvertices, DWORD dwstride, D3DXVECTOR3 *pcenter, float *pradius)
 {
     D3DXVECTOR3 temp;
     FLOAT d;
@@ -2359,10 +2364,8 @@ UINT WINAPI D3DXGetDeclLength(const D3DVERTEXELEMENT9 *decl)
     return element - decl;
 }
 
-/*************************************************************************
- * D3DXIntersectTri
- */
-BOOL WINAPI D3DXIntersectTri(CONST D3DXVECTOR3 *p0, CONST D3DXVECTOR3 *p1, CONST D3DXVECTOR3 *p2, CONST D3DXVECTOR3 *praypos, CONST D3DXVECTOR3 *praydir, FLOAT *pu, FLOAT *pv, FLOAT *pdist)
+BOOL WINAPI D3DXIntersectTri(const D3DXVECTOR3 *p0, const D3DXVECTOR3 *p1, const D3DXVECTOR3 *p2,
+        const D3DXVECTOR3 *praypos, const D3DXVECTOR3 *praydir, float *pu, float *pv, float *pdist)
 {
     D3DXMATRIX m;
     D3DXVECTOR4 vec;
@@ -2396,7 +2399,7 @@ BOOL WINAPI D3DXIntersectTri(CONST D3DXVECTOR3 *p0, CONST D3DXVECTOR3 *p1, CONST
         {
             *pu = vec.x;
             *pv = vec.y;
-            *pdist = fabs( vec.z );
+            *pdist = fabsf( vec.z );
             return TRUE;
         }
     }
@@ -2404,10 +2407,8 @@ BOOL WINAPI D3DXIntersectTri(CONST D3DXVECTOR3 *p0, CONST D3DXVECTOR3 *p1, CONST
     return FALSE;
 }
 
-/*************************************************************************
- * D3DXSphereBoundProbe
- */
-BOOL WINAPI D3DXSphereBoundProbe(CONST D3DXVECTOR3 *pcenter, FLOAT radius, CONST D3DXVECTOR3 *prayposition, CONST D3DXVECTOR3 *praydirection)
+BOOL WINAPI D3DXSphereBoundProbe(const D3DXVECTOR3 *pcenter, float radius,
+        const D3DXVECTOR3 *prayposition, const D3DXVECTOR3 *praydirection)
 {
     D3DXVECTOR3 difference;
     FLOAT a, b, c, d;
@@ -2436,7 +2437,7 @@ HRESULT WINAPI D3DXCreateMesh(DWORD numfaces, DWORD numvertices, DWORD options,
     IDirect3DVertexBuffer9 *vertex_buffer;
     IDirect3DIndexBuffer9 *index_buffer;
     DWORD *attrib_buffer;
-    ID3DXMeshImpl *object;
+    struct d3dx9_mesh *object;
     DWORD index_usage = 0;
     D3DPOOL index_pool = D3DPOOL_DEFAULT;
     D3DFORMAT index_format = D3DFMT_INDEX16;
@@ -2444,7 +2445,8 @@ HRESULT WINAPI D3DXCreateMesh(DWORD numfaces, DWORD numvertices, DWORD options,
     D3DPOOL vertex_pool = D3DPOOL_DEFAULT;
     int i;
 
-    TRACE("(%d, %d, %x, %p, %p, %p)\n", numfaces, numvertices, options, declaration, device, mesh);
+    TRACE("numfaces %u, numvertices %u, options %#x, declaration %p, device %p, mesh %p.\n",
+            numfaces, numvertices, options, declaration, device, mesh);
 
     if (numfaces == 0 || numvertices == 0 || declaration == NULL || device == NULL || mesh == NULL ||
         /* D3DXMESH_VB_SHARE is for cloning, and D3DXMESH_USEHWONLY is for ConvertToBlendedMesh */
@@ -2550,7 +2552,7 @@ HRESULT WINAPI D3DXCreateMesh(DWORD numfaces, DWORD numvertices, DWORD options,
     }
 
     attrib_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, numfaces * sizeof(*attrib_buffer));
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXMeshImpl));
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (object == NULL || attrib_buffer == NULL)
     {
         HeapFree(GetProcessHeap(), 0, object);
@@ -2630,7 +2632,7 @@ struct mesh_data {
     DWORD nb_bones;
 };
 
-static HRESULT parse_texture_filename(ID3DXFileData *filedata, LPSTR *filename_out)
+static HRESULT parse_texture_filename(ID3DXFileData *filedata, char **filename_out)
 {
     HRESULT hr;
     SIZE_T data_size;
@@ -2650,12 +2652,13 @@ static HRESULT parse_texture_filename(ID3DXFileData *filedata, LPSTR *filename_o
     if (FAILED(hr)) return hr;
 
     /* FIXME: String must be retrieved directly instead of through a pointer once ID3DXFILE is fixed */
-    if (data_size < sizeof(LPSTR)) {
+    if (data_size < sizeof(filename_in))
+    {
         WARN("truncated data (%lu bytes)\n", data_size);
         filedata->lpVtbl->Unlock(filedata);
         return E_FAIL;
     }
-    filename_in = *(LPSTR*)data;
+    filename_in = *(char **)data;
 
     filename = HeapAlloc(GetProcessHeap(), 0, strlen(filename_in) + 1);
     if (!filename) {
@@ -2678,8 +2681,7 @@ static HRESULT parse_material(ID3DXFileData *filedata, D3DXMATERIAL *material)
     const BYTE *data;
     GUID type;
     ID3DXFileData *child;
-    SIZE_T nb_children;
-    int i;
+    SIZE_T i, nb_children;
 
     material->pTextureFilename = NULL;
 
@@ -3390,7 +3392,7 @@ static HRESULT generate_effects(ID3DXBuffer *materials, DWORD num_materials,
 
         for (j = 0; j < ARRAY_SIZE(material_effects); j++)
         {
-            defaults->pParamName = (LPSTR)out_ptr;
+            defaults->pParamName = (char *)out_ptr;
             strcpy(defaults->pParamName, material_effects[j].param_name);
             defaults->pValue = defaults->pParamName + material_effects[j].name_size;
             defaults->Type = D3DXEDT_FLOATS;
@@ -3400,8 +3402,9 @@ static HRESULT generate_effects(ID3DXBuffer *materials, DWORD num_materials,
             defaults++;
         }
 
-        if (material_ptr->pTextureFilename) {
-            defaults->pParamName = (LPSTR)out_ptr;
+        if (material_ptr->pTextureFilename)
+        {
+            defaults->pParamName = (char *)out_ptr;
             strcpy(defaults->pParamName, texture_paramname);
             defaults->pValue = defaults->pParamName + sizeof(texture_paramname);
             defaults->Type = D3DXEDT_STRING;
@@ -3665,12 +3668,14 @@ HRESULT WINAPI D3DXLoadMeshHierarchyFromXA(const char *filename, DWORD options,
         struct ID3DXAllocateHierarchy *alloc_hier, struct ID3DXLoadUserData *load_user_data,
         D3DXFRAME **frame_hierarchy, struct ID3DXAnimationController **anim_controller)
 {
+    WCHAR *filenameW;
     HRESULT hr;
     int len;
-    LPWSTR filenameW;
 
-    TRACE("(%s, %x, %p, %p, %p, %p, %p)\n", debugstr_a(filename), options,
-          device, alloc_hier, load_user_data, frame_hierarchy, anim_controller);
+    TRACE("filename %s, options %#x, device %p, alloc_hier %p, "
+            "load_user_data %p, frame_hierarchy %p, anim_controller %p.\n",
+            debugstr_a(filename), options, device, alloc_hier,
+            load_user_data, frame_hierarchy, anim_controller);
 
     if (!filename)
         return D3DERR_INVALIDCALL;
@@ -3691,12 +3696,14 @@ HRESULT WINAPI D3DXLoadMeshHierarchyFromXW(const WCHAR *filename, DWORD options,
         struct ID3DXAllocateHierarchy *alloc_hier, struct ID3DXLoadUserData *load_user_data,
         D3DXFRAME **frame_hierarchy, struct ID3DXAnimationController **anim_controller)
 {
+    void *buffer;
     HRESULT hr;
     DWORD size;
-    LPVOID buffer;
 
-    TRACE("(%s, %x, %p, %p, %p, %p, %p)\n", debugstr_w(filename), options,
-          device, alloc_hier, load_user_data, frame_hierarchy, anim_controller);
+    TRACE("filename %s, options %#x, device %p, alloc_hier %p, "
+            "load_user_data %p, frame_hierarchy %p, anim_controller %p.\n",
+            debugstr_w(filename), options, device, alloc_hier,
+            load_user_data, frame_hierarchy, anim_controller);
 
     if (!filename)
         return D3DERR_INVALIDCALL;
@@ -3814,8 +3821,7 @@ static HRESULT load_frame(struct ID3DXFileData *filedata, DWORD options, struct
     D3DXFRAME *frame = NULL;
     D3DXMESHCONTAINER **next_container;
     D3DXFRAME **next_child;
-    SIZE_T nb_children;
-    int i;
+    SIZE_T i, nb_children;
 
     hr = filedata_get_name(filedata, &name);
     if (FAILED(hr)) return hr;
@@ -3872,9 +3878,8 @@ HRESULT WINAPI D3DXLoadMeshHierarchyFromXInMemory(const void *memory, DWORD memo
     D3DXF_FILELOADMEMORY source;
     D3DXFRAME *first_frame = NULL;
     D3DXFRAME **next_frame = &first_frame;
-    SIZE_T nb_children;
+    SIZE_T i, nb_children;
     GUID guid;
-    int i;
 
     TRACE("(%p, %u, %x, %p, %p, %p, %p, %p)\n", memory, memory_size, options,
           device, alloc_hier, load_user_data, frame_hierarchy, anim_controller);
@@ -4017,12 +4022,14 @@ HRESULT WINAPI D3DXLoadMeshFromXA(const char *filename, DWORD options, struct ID
         struct ID3DXBuffer **adjacency, struct ID3DXBuffer **materials, struct ID3DXBuffer **effect_instances,
         DWORD *num_materials, struct ID3DXMesh **mesh)
 {
+    WCHAR *filenameW;
     HRESULT hr;
     int len;
-    LPWSTR filenameW;
 
-    TRACE("(%s, %x, %p, %p, %p, %p, %p, %p)\n", debugstr_a(filename), options,
-          device, adjacency, materials, effect_instances, num_materials, mesh);
+    TRACE("filename %s, options %#x, device %p, adjacency %p, materials %p, "
+            "effect_instances %p, num_materials %p, mesh %p.\n",
+            debugstr_a(filename), options, device, adjacency, materials,
+            effect_instances, num_materials, mesh);
 
     if (!filename)
         return D3DERR_INVALIDCALL;
@@ -4043,12 +4050,14 @@ HRESULT WINAPI D3DXLoadMeshFromXW(const WCHAR *filename, DWORD options, struct I
         struct ID3DXBuffer **adjacency, struct ID3DXBuffer **materials, struct ID3DXBuffer **effect_instances,
         DWORD *num_materials, struct ID3DXMesh **mesh)
 {
+    void *buffer;
     HRESULT hr;
     DWORD size;
-    LPVOID buffer;
 
-    TRACE("(%s, %x, %p, %p, %p, %p, %p, %p)\n", debugstr_w(filename), options,
-          device, adjacency, materials, effect_instances, num_materials, mesh);
+    TRACE("filename %s, options %#x, device %p, adjacency %p, materials %p, "
+            "effect_instances %p, num_materials %p, mesh %p.\n",
+            debugstr_w(filename), options, device, adjacency, materials,
+            effect_instances, num_materials, mesh);
 
     if (!filename)
         return D3DERR_INVALIDCALL;
@@ -4071,12 +4080,13 @@ HRESULT WINAPI D3DXLoadMeshFromXResource(HMODULE module, const char *name, const
 {
     HRESULT hr;
     HRSRC resinfo;
+    void *buffer;
     DWORD size;
-    LPVOID buffer;
 
-    TRACE("(%p, %s, %s, %x, %p, %p, %p, %p, %p, %p)\n",
-          module, debugstr_a(name), debugstr_a(type), options, device,
-          adjacency, materials, effect_instances, num_materials, mesh);
+    TRACE("module %p, name %s, type %s, options %#x, device %p, adjacency %p, "
+            "materials %p, effect_instances %p, num_materials %p, mesh %p.\n",
+            module, debugstr_a(name), debugstr_a(type), options, device, adjacency,
+            materials, effect_instances, num_materials, mesh);
 
     resinfo = FindResourceA(module, name, type);
     if (!resinfo) return D3DXERR_INVALIDDATA;
@@ -4106,8 +4116,7 @@ static HRESULT parse_frame(struct ID3DXFileData *filedata, DWORD options, struct
     D3DXMATRIX transform = *parent_transform;
     ID3DXFileData *child;
     GUID type;
-    SIZE_T nb_children;
-    int i;
+    SIZE_T i, nb_children;
 
     hr = filedata->lpVtbl->GetChildren(filedata, &nb_children);
     if (FAILED(hr))
@@ -4172,9 +4181,8 @@ HRESULT WINAPI D3DXLoadMeshFromXInMemory(const void *memory, DWORD memory_size,
     void *concat_indices = NULL;
     DWORD index_offset;
     DWORD concat_vertex_size;
-    SIZE_T nb_children;
+    SIZE_T i, nb_children;
     GUID guid;
-    int i;
 
     TRACE("(%p, %u, %x, %p, %p, %p, %p, %p, %p)\n", memory, memory_size, options,
           device, adjacency_out, materials_out, effects_out, num_materials_out, mesh_out);
@@ -4507,20 +4515,106 @@ cleanup:
     return hr;
 }
 
-HRESULT WINAPI D3DXCreateBox(struct IDirect3DDevice9 *device, float width, float height,
-        float depth, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
-{
-    FIXME("(%p, %f, %f, %f, %p, %p): stub\n", device, width, height, depth, mesh, adjacency);
-
-    return E_NOTIMPL;
-}
-
 struct vertex
 {
     D3DXVECTOR3 position;
     D3DXVECTOR3 normal;
 };
 
+HRESULT WINAPI D3DXCreateBox(struct IDirect3DDevice9 *device, float width, float height,
+        float depth, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
+{
+    HRESULT hr;
+    ID3DXMesh *box;
+    struct vertex *vertices;
+    WORD (*faces)[3];
+    DWORD *adjacency_buf;
+    unsigned int i, face;
+    static const D3DXVECTOR3 unit_box[] =
+    {
+        {-0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f,  0.5f}, {-0.5f,  0.5f,  0.5f}, {-0.5f,  0.5f, -0.5f},
+        {-0.5f,  0.5f, -0.5f}, {-0.5f,  0.5f,  0.5f}, { 0.5f,  0.5f,  0.5f}, { 0.5f,  0.5f, -0.5f},
+        { 0.5f,  0.5f, -0.5f}, { 0.5f,  0.5f,  0.5f}, { 0.5f, -0.5f,  0.5f}, { 0.5f, -0.5f, -0.5f},
+        {-0.5f, -0.5f,  0.5f}, {-0.5f, -0.5f, -0.5f}, { 0.5f, -0.5f, -0.5f}, { 0.5f, -0.5f,  0.5f},
+        {-0.5f, -0.5f,  0.5f}, { 0.5f, -0.5f,  0.5f}, { 0.5f,  0.5f,  0.5f}, {-0.5f,  0.5f,  0.5f},
+        {-0.5f, -0.5f, -0.5f}, {-0.5f,  0.5f, -0.5f}, { 0.5f,  0.5f, -0.5f}, { 0.5f, -0.5f, -0.5f}
+    };
+    static const D3DXVECTOR3 normals[] =
+    {
+        {-1.0f,  0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f}, { 1.0f, 0.0f,  0.0f},
+        { 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, -1.0f}
+    };
+    static const DWORD adjacency_table[] =
+    {
+        6, 9, 1, 2, 10, 0, 1,  9,  3, 4, 10,  2,
+        3, 8, 5, 7, 11, 4, 0, 11,  7, 5,  8,  6,
+        7, 4, 9, 2,  0, 8, 1,  3, 11, 5,  6, 10
+    };
+
+    TRACE("device %p, width %f, height %f, depth %f, mesh %p, adjacency %p\n",
+                    device, width, height, depth, mesh, adjacency);
+
+    if (!device || width < 0.0f || height < 0.0f || depth < 0.0f || !mesh)
+    {
+        return D3DERR_INVALIDCALL;
+    }
+
+    if (FAILED(hr = D3DXCreateMeshFVF(12, 24, D3DXMESH_MANAGED, D3DFVF_XYZ | D3DFVF_NORMAL, device, &box)))
+    {
+        return hr;
+    }
+
+    if (FAILED(hr = box->lpVtbl->LockVertexBuffer(box, 0, (void **)&vertices)))
+    {
+        box->lpVtbl->Release(box);
+        return hr;
+    }
+
+    if (FAILED(hr = box->lpVtbl->LockIndexBuffer(box, 0, (void **)&faces)))
+    {
+        box->lpVtbl->UnlockVertexBuffer(box);
+        box->lpVtbl->Release(box);
+        return hr;
+    }
+
+    for (i = 0; i < 24; i++)
+    {
+        vertices[i].position.x = width * unit_box[i].x;
+        vertices[i].position.y = height * unit_box[i].y;
+        vertices[i].position.z = depth * unit_box[i].z;
+        vertices[i].normal.x = normals[i / 4].x;
+        vertices[i].normal.y = normals[i / 4].y;
+        vertices[i].normal.z = normals[i / 4].z;
+    }
+
+    face = 0;
+    for (i = 0; i < 12; i++)
+    {
+        faces[i][0] = face++;
+        faces[i][1] = face++;
+        faces[i][2] = (i % 2) ? face - 4 : face;
+    }
+
+    box->lpVtbl->UnlockIndexBuffer(box);
+    box->lpVtbl->UnlockVertexBuffer(box);
+
+    if (adjacency)
+    {
+        if (FAILED(hr = D3DXCreateBuffer(sizeof(adjacency_table), adjacency)))
+        {
+            box->lpVtbl->Release(box);
+            return hr;
+        }
+
+        adjacency_buf = ID3DXBuffer_GetBufferPointer(*adjacency);
+        memcpy(adjacency_buf, adjacency_table, sizeof(adjacency_table));
+    }
+
+    *mesh = box;
+
+    return D3D_OK;
+}
+
 typedef WORD face[3];
 
 struct sincos_table
@@ -4556,8 +4650,8 @@ static BOOL compute_sincos_table(struct sincos_table *sincos_table, float angle_
     angle = angle_start;
     for (i = 0; i < n; i++)
     {
-        sincos_table->sin[i] = sin(angle);
-        sincos_table->cos[i] = cos(angle);
+        sincos_table->sin[i] = sinf(angle);
+        sincos_table->cos[i] = cosf(angle);
         angle += angle_step;
     }
 
@@ -4605,15 +4699,13 @@ HRESULT WINAPI D3DXCreateSphere(struct IDirect3DDevice9 *device, float radius, U
         return hr;
     }
 
-    hr = sphere->lpVtbl->LockVertexBuffer(sphere, 0, (LPVOID *)&vertices);
-    if (FAILED(hr))
+    if (FAILED(hr = sphere->lpVtbl->LockVertexBuffer(sphere, 0, (void **)&vertices)))
     {
         sphere->lpVtbl->Release(sphere);
         return hr;
     }
 
-    hr = sphere->lpVtbl->LockIndexBuffer(sphere, 0, (LPVOID *)&faces);
-    if (FAILED(hr))
+    if (FAILED(hr = sphere->lpVtbl->LockIndexBuffer(sphere, 0, (void **)&faces)))
     {
         sphere->lpVtbl->UnlockVertexBuffer(sphere);
         sphere->lpVtbl->Release(sphere);
@@ -4621,8 +4713,8 @@ HRESULT WINAPI D3DXCreateSphere(struct IDirect3DDevice9 *device, float radius, U
     }
 
     /* phi = angle on xz plane wrt z axis */
-    phi_step = -2 * M_PI / slices;
-    phi_start = M_PI / 2;
+    phi_step = -2.0f * D3DX_PI / slices;
+    phi_start = D3DX_PI / 2.0f;
 
     if (!compute_sincos_table(&phi, phi_start, phi_step, slices))
     {
@@ -4633,7 +4725,7 @@ HRESULT WINAPI D3DXCreateSphere(struct IDirect3DDevice9 *device, float radius, U
     }
 
     /* theta = angle on xy plane wrt x axis */
-    theta_step = M_PI / stacks;
+    theta_step = D3DX_PI / stacks;
     theta = theta_step;
 
     vertex = 0;
@@ -4649,8 +4741,8 @@ HRESULT WINAPI D3DXCreateSphere(struct IDirect3DDevice9 *device, float radius, U
 
     for (stack = 0; stack < stacks - 1; stack++)
     {
-        sin_theta = sin(theta);
-        cos_theta = cos(theta);
+        sin_theta = sinf(theta);
+        cos_theta = cosf(theta);
 
         for (slice = 0; slice < slices; slice++)
         {
@@ -4776,15 +4868,13 @@ HRESULT WINAPI D3DXCreateCylinder(struct IDirect3DDevice9 *device, float radius1
         return hr;
     }
 
-    hr = cylinder->lpVtbl->LockVertexBuffer(cylinder, 0, (LPVOID *)&vertices);
-    if (FAILED(hr))
+    if (FAILED(hr = cylinder->lpVtbl->LockVertexBuffer(cylinder, 0, (void **)&vertices)))
     {
         cylinder->lpVtbl->Release(cylinder);
         return hr;
     }
 
-    hr = cylinder->lpVtbl->LockIndexBuffer(cylinder, 0, (LPVOID *)&faces);
-    if (FAILED(hr))
+    if (FAILED(hr = cylinder->lpVtbl->LockIndexBuffer(cylinder, 0, (void **)&faces)))
     {
         cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
         cylinder->lpVtbl->Release(cylinder);
@@ -4792,8 +4882,8 @@ HRESULT WINAPI D3DXCreateCylinder(struct IDirect3DDevice9 *device, float radius1
     }
 
     /* theta = angle on xy plane wrt x axis */
-    theta_step = -2 * M_PI / slices;
-    theta_start = M_PI / 2;
+    theta_step = -2.0f * D3DX_PI / slices;
+    theta_start = D3DX_PI / 2.0f;
 
     if (!compute_sincos_table(&theta, theta_start, theta_step, slices))
     {
@@ -4935,12 +5025,12 @@ HRESULT WINAPI D3DXCreateTeapot(struct IDirect3DDevice9 *device,
 HRESULT WINAPI D3DXCreateTextA(struct IDirect3DDevice9 *device, HDC hdc, const char *text, float deviation,
         float extrusion, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency, GLYPHMETRICSFLOAT *glyphmetrics)
 {
+    WCHAR *textW;
     HRESULT hr;
     int len;
-    LPWSTR textW;
 
-    TRACE("(%p, %p, %s, %f, %f, %p, %p, %p)\n", device, hdc,
-          debugstr_a(text), deviation, extrusion, mesh, adjacency, glyphmetrics);
+    TRACE("device %p, hdc %p, text %s, deviation %.8e, extrusion %.8e, mesh %p, adjacency %p, glyphmetrics %p.\n",
+            device, hdc, debugstr_a(text), deviation, extrusion, mesh, adjacency, glyphmetrics);
 
     if (!text)
         return D3DERR_INVALIDCALL;
@@ -5114,7 +5204,7 @@ static HRESULT add_vertex_index(struct word_array *array, WORD vertex_index)
 C_ASSERT(sizeof(FIXED) == sizeof(float));
 C_ASSERT(sizeof(POINTFX) == sizeof(D3DXVECTOR2));
 
-static inline D3DXVECTOR2 *convert_fixed_to_float(POINTFX *pt, int count, float emsquare)
+static inline D3DXVECTOR2 *convert_fixed_to_float(POINTFX *pt, int count, unsigned int emsquare)
 {
     D3DXVECTOR2 *ret = (D3DXVECTOR2*)pt;
     while (count--) {
@@ -5219,7 +5309,8 @@ static BOOL attempt_line_merge(struct outline *outline,
 }
 
 static HRESULT create_outline(struct glyphinfo *glyph, void *raw_outline, int datasize,
-                              float max_deviation_sq, float emsquare, const struct cos_table *cos_table)
+                              float max_deviation_sq, unsigned int emsquare,
+                              const struct cos_table *cos_table)
 {
     TTPOLYGONHEADER *header = (TTPOLYGONHEADER *)raw_outline;
 
@@ -5763,9 +5854,9 @@ HRESULT WINAPI D3DXCreateTextW(struct IDirect3DDevice9 *device, HDC hdc, const W
     face *face_ptr;
     float max_deviation_sq;
     const struct cos_table cos_table = {
-        cos(D3DXToRadian(0.5f)),
-        cos(D3DXToRadian(45.0f)),
-        cos(D3DXToRadian(90.0f)),
+        cosf(D3DXToRadian(0.5f)),
+        cosf(D3DXToRadian(45.0f)),
+        cosf(D3DXToRadian(90.0f)),
     };
     int f1, f2;
 
@@ -5883,12 +5974,10 @@ HRESULT WINAPI D3DXCreateTextW(struct IDirect3DDevice9 *device, HDC hdc, const W
     if (FAILED(hr))
         goto error;
 
-    hr = mesh->lpVtbl->LockVertexBuffer(mesh, 0, (LPVOID *)&vertices);
-    if (FAILED(hr))
+    if (FAILED(hr = mesh->lpVtbl->LockVertexBuffer(mesh, 0, (void **)&vertices)))
         goto error;
 
-    hr = mesh->lpVtbl->LockIndexBuffer(mesh, 0, (LPVOID *)&faces);
-    if (FAILED(hr))
+    if (FAILED(hr = mesh->lpVtbl->LockIndexBuffer(mesh, 0, (void **)&faces)))
         goto error;
 
     /* convert 2D vertices and faces into 3D mesh */
@@ -6147,7 +6236,7 @@ static BOOL weld_float4(void *to, void *from, FLOAT epsilon)
     FLOAT diff_y = fabsf(v1->y - v2->y);
     FLOAT diff_z = fabsf(v1->z - v2->z);
     FLOAT diff_w = fabsf(v1->w - v2->w);
-    FLOAT max_abs_diff = fmax(diff_x, diff_y);
+    FLOAT max_abs_diff = max(diff_x, diff_y);
     max_abs_diff = max(diff_z, max_abs_diff);
     max_abs_diff = max(diff_w, max_abs_diff);
 
@@ -6386,9 +6475,9 @@ static BOOL weld_float16_2(void *to, void *from, FLOAT epsilon)
     FLOAT diff_x;
     FLOAT diff_y;
     FLOAT max_abs_diff;
-    const UINT NUM_ELEM = 2;
-    FLOAT v1[2];
-    FLOAT v2[2];
+#define NUM_ELEM 2
+    FLOAT v1[NUM_ELEM];
+    FLOAT v2[NUM_ELEM];
 
     D3DXFloat16To32Array(v1, v1_float16, NUM_ELEM);
     D3DXFloat16To32Array(v2, v2_float16, NUM_ELEM);
@@ -6405,6 +6494,7 @@ static BOOL weld_float16_2(void *to, void *from, FLOAT epsilon)
     }
 
     return FALSE;
+#undef NUM_ELEM
 }
 
 static BOOL weld_float16_4(void *to, void *from, FLOAT epsilon)
@@ -6416,9 +6506,9 @@ static BOOL weld_float16_4(void *to, void *from, FLOAT epsilon)
     FLOAT diff_z;
     FLOAT diff_w;
     FLOAT max_abs_diff;
-    const UINT NUM_ELEM = 4;
-    FLOAT v1[4];
-    FLOAT v2[4];
+#define NUM_ELEM 4
+    FLOAT v1[NUM_ELEM];
+    FLOAT v2[NUM_ELEM];
 
     D3DXFloat16To32Array(v1, v1_float16, NUM_ELEM);
     D3DXFloat16To32Array(v2, v2_float16, NUM_ELEM);
@@ -6439,6 +6529,7 @@ static BOOL weld_float16_4(void *to, void *from, FLOAT epsilon)
     }
 
     return FALSE;
+#undef NUM_ELEM
 }
 
 /* Sets the vertex components to the same value if they are within epsilon. */
@@ -6663,13 +6754,13 @@ HRESULT WINAPI D3DXWeldVertices(ID3DXMesh *mesh, DWORD flags, const D3DXWELDEPSI
     BOOL indices_are_32bit = mesh->lpVtbl->GetOptions(mesh) & D3DXMESH_32BIT;
     DWORD optimize_flags;
     DWORD *point_reps = NULL;
-    ID3DXMeshImpl *This = impl_from_ID3DXMesh(mesh);
+    struct d3dx9_mesh *This = impl_from_ID3DXMesh(mesh);
     DWORD *vertex_face_map = NULL;
     ID3DXBuffer *vertex_remap = NULL;
     BYTE *vertices = NULL;
 
-    TRACE("(%p, %x, %p, %p, %p, %p, %p)\n", mesh, flags, epsilons,
-           adjacency, adjacency_out, face_remap_out, vertex_remap_out);
+    TRACE("mesh %p, flags %#x, epsilons %p, adjacency %p, adjacency_out %p, face_remap_out %p, vertex_remap_out %p.\n",
+            mesh, flags, epsilons, adjacency, adjacency_out, face_remap_out, vertex_remap_out);
 
     if (flags == 0)
     {
@@ -6858,20 +6949,17 @@ cleanup:
  *   The face re-ordering does not use the vertex cache optimally.
  *
  */
-HRESULT WINAPI D3DXOptimizeFaces(LPCVOID indices,
-                                 UINT num_faces,
-                                 UINT num_vertices,
-                                 BOOL indices_are_32bit,
-                                 DWORD *face_remap)
+HRESULT WINAPI D3DXOptimizeFaces(const void *indices, UINT num_faces,
+        UINT num_vertices, BOOL indices_are_32bit, DWORD *face_remap)
 {
     UINT i;
     UINT j = num_faces - 1;
     UINT limit_16_bit = 2 << 15; /* According to MSDN */
     HRESULT hr = D3D_OK;
 
-    FIXME("(%p, %u, %u, %s, %p): semi-stub. Face order will not be optimal.\n",
-          indices, num_faces, num_vertices,
-          indices_are_32bit ? "TRUE" : "FALSE", face_remap);
+    FIXME("indices %p, num_faces %u, num_vertices %u, indices_are_32bit %#x, face_remap %p semi-stub. "
+            "Face order will not be optimal.\n",
+            indices, num_faces, num_vertices, indices_are_32bit, face_remap);
 
     if (!indices_are_32bit && num_faces >= limit_16_bit)
     {
index 00cece9..02e6caa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Jأ³zef Kucia
+ * Copyright (C) 2012 Józef Kucia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
index 1ef3159..36b1007 100644 (file)
 #include "d3dx9_36_private.h"
 #include "d3dcompiler.h"
 
-/* This function is not declared in the SDK headers yet */
-HRESULT WINAPI D3DAssemble(LPCVOID data, SIZE_T datasize, LPCSTR filename,
-                           const D3D_SHADER_MACRO *defines, ID3DInclude *include,
-                           UINT flags,
-                           ID3DBlob **shader, ID3DBlob **error_messages);
+
+/* This function is not declared in the SDK headers yet. */
+HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename,
+        const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags,
+        ID3DBlob **shader, ID3DBlob **error_messages);
 
 static inline BOOL is_valid_bytecode(DWORD token)
 {
@@ -142,6 +142,7 @@ const char * WINAPI D3DXGetVertexShaderProfile(struct IDirect3DDevice9 *device)
 HRESULT WINAPI D3DXFindShaderComment(const DWORD *byte_code, DWORD fourcc, const void **data, UINT *size)
 {
     const DWORD *ptr = byte_code;
+    DWORD version;
 
     TRACE("byte_code %p, fourcc %x, data %p, size %p\n", byte_code, fourcc, data, size);
 
@@ -149,7 +150,18 @@ HRESULT WINAPI D3DXFindShaderComment(const DWORD *byte_code, DWORD fourcc, const
     if (size) *size = 0;
 
     if (!byte_code) return D3DERR_INVALIDCALL;
-    if (!is_valid_bytecode(*byte_code)) return D3DXERR_INVALIDDATA;
+
+    version = *ptr >> 16;
+    if (version != 0x4658         /* FX */
+            && version != 0x5458  /* TX */
+            && version != 0x7ffe
+            && version != 0x7fff
+            && version != 0xfffe  /* VS */
+            && version != 0xffff) /* PS */
+    {
+        WARN("Invalid data supplied\n");
+        return D3DXERR_INVALIDDATA;
+    }
 
     while (*++ptr != D3DSIO_END)
     {
@@ -162,7 +174,7 @@ HRESULT WINAPI D3DXFindShaderComment(const DWORD *byte_code, DWORD fourcc, const
             if (*(ptr + 1) == fourcc)
             {
                 UINT ctab_size = (comment_size - 1) * sizeof(DWORD);
-                LPCVOID ctab_data = ptr + 2;
+                const void *ctab_data = ptr + 2;
                 if (size)
                     *size = ctab_size;
                 if (data)
@@ -196,14 +208,13 @@ HRESULT WINAPI D3DXAssembleShader(const char *data, UINT data_len, const D3DXMAC
 }
 
 /* D3DXInclude private implementation, used to implement
-   D3DXAssembleShaderFromFile from D3DXAssembleShader */
-/* To be able to correctly resolve include search paths we have to store
-   the pathname of each include file. We store the pathname pointer right
-   before the file data. */
-static HRESULT WINAPI d3dincludefromfile_open(ID3DXInclude *iface,
-                                              D3DXINCLUDE_TYPE include_type,
-                                              LPCSTR filename, LPCVOID parent_data,
-                                              LPCVOID *data, UINT *bytes) {
+ * D3DXAssembleShaderFromFile() from D3DXAssembleShader(). */
+/* To be able to correctly resolve include search paths we have to store the
+ * pathname of each include file. We store the pathname pointer right before
+ * the file data. */
+static HRESULT WINAPI d3dincludefromfile_open(ID3DXInclude *iface, D3DXINCLUDE_TYPE include_type,
+        const char *filename, const void *parent_data, const void **data, UINT *bytes)
+{
     const char *p, *parent_name = "";
     char *pathname = NULL;
     char **buffer = NULL;
@@ -253,7 +264,8 @@ error:
     return HRESULT_FROM_WIN32(GetLastError());
 }
 
-static HRESULT WINAPI d3dincludefromfile_close(ID3DXInclude *iface, LPCVOID data) {
+static HRESULT WINAPI d3dincludefromfile_close(ID3DXInclude *iface, const void *data)
+{
     HeapFree(GetProcessHeap(), 0, *((char **)data - 1));
     HeapFree(GetProcessHeap(), 0, (char **)data - 1);
     return S_OK;
@@ -271,10 +283,13 @@ struct D3DXIncludeImpl {
 HRESULT WINAPI D3DXAssembleShaderFromFileA(const char *filename, const D3DXMACRO *defines,
         ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
 {
-    LPWSTR filename_w = NULL;
+    WCHAR *filename_w;
     DWORD len;
     HRESULT ret;
 
+    TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
+            debugstr_a(filename), defines, include, flags, shader, error_messages);
+
     if (!filename) return D3DXERR_INVALIDDATA;
 
     len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
@@ -291,13 +306,14 @@ HRESULT WINAPI D3DXAssembleShaderFromFileA(const char *filename, const D3DXMACRO
 HRESULT WINAPI D3DXAssembleShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
         ID3DXInclude *include, DWORD flags, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
 {
-    void *buffer;
+    const void *buffer;
     DWORD len;
     HRESULT hr;
     struct D3DXIncludeImpl includefromfile;
+    char *filename_a;
 
-    if(FAILED(map_view_of_file(filename, &buffer, &len)))
-        return D3DXERR_INVALIDDATA;
+    TRACE("filename %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
+            debugstr_w(filename), defines, include, flags, shader, error_messages);
 
     if(!include)
     {
@@ -305,10 +321,23 @@ HRESULT WINAPI D3DXAssembleShaderFromFileW(const WCHAR *filename, const D3DXMACR
         include = &includefromfile.ID3DXInclude_iface;
     }
 
-    hr = D3DXAssembleShader(buffer, len, defines, include, flags,
-                            shader, error_messages);
+    len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
+    filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
+    if (!filename_a)
+        return E_OUTOFMEMORY;
+    WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
+
+    hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
+    if (FAILED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, filename_a);
+        return D3DXERR_INVALIDDATA;
+    }
+
+    hr = D3DXAssembleShader(buffer, len, defines, include, flags, shader, error_messages);
 
-    UnmapViewOfFile(buffer);
+    ID3DXInclude_Close(include, buffer);
+    HeapFree(GetProcessHeap(), 0, filename_a);
     return hr;
 }
 
@@ -319,7 +348,10 @@ HRESULT WINAPI D3DXAssembleShaderFromResourceA(HMODULE module, const char *resou
     HRSRC res;
     DWORD len;
 
-    if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
+    TRACE("module %p, resource %s, defines %p, include %p, flags %#x, shader %p, error_messages %p.\n",
+            module, debugstr_a(resource), defines, include, flags, shader, error_messages);
+
+    if (!(res = FindResourceA(module, resource, (const char *)RT_RCDATA)))
         return D3DXERR_INVALIDDATA;
     if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
         return D3DXERR_INVALIDDATA;
@@ -351,8 +383,10 @@ HRESULT WINAPI D3DXCompileShader(const char *data, UINT length, const D3DXMACRO
 {
     HRESULT hr;
 
-    TRACE("data %p, length %u, defines %p, include %p, function %s, profile %s, flags %#x, shader %p, error_msgs %p, constant_table %p\n",
-          data, length, defines, include, function, profile, flags, shader, error_msgs, constant_table);
+    TRACE("data %s, length %u, defines %p, include %p, function %s, profile %s, "
+            "flags %#x, shader %p, error_msgs %p, constant_table %p.\n",
+            debugstr_a(data), length, defines, include, debugstr_a(function), debugstr_a(profile),
+            flags, shader, error_msgs, constant_table);
 
     hr = D3DCompile(data, length, NULL, (D3D_SHADER_MACRO *)defines, (ID3DInclude *)include,
                     function, profile, flags, 0, (ID3DBlob **)shader, (ID3DBlob **)error_msgs);
@@ -374,10 +408,15 @@ HRESULT WINAPI D3DXCompileShaderFromFileA(const char *filename, const D3DXMACRO
         ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
         ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
 {
-    LPWSTR filename_w = NULL;
+    WCHAR *filename_w;
     DWORD len;
     HRESULT ret;
 
+    TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
+            "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
+            debugstr_a(filename), defines, include, debugstr_a(entrypoint),
+            debugstr_a(profile), flags, shader, error_messages, constant_table);
+
     if (!filename) return D3DXERR_INVALIDDATA;
 
     len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
@@ -397,14 +436,16 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
         ID3DXInclude *include, const char *entrypoint, const char *profile, DWORD flags,
         ID3DXBuffer **shader, ID3DXBuffer **error_messages, ID3DXConstantTable **constant_table)
 {
-    void *buffer;
+    const void *buffer;
     DWORD len, filename_len;
     HRESULT hr;
     struct D3DXIncludeImpl includefromfile;
     char *filename_a;
 
-    if (FAILED(map_view_of_file(filename, &buffer, &len)))
-        return D3DXERR_INVALIDDATA;
+    TRACE("filename %s, defines %p, include %p, entrypoint %s, profile %s, "
+            "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
+            debugstr_w(filename), defines, include, debugstr_a(entrypoint), debugstr_a(profile),
+            flags, shader, error_messages, constant_table);
 
     if (!include)
     {
@@ -415,12 +456,16 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
     filename_len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
     filename_a = HeapAlloc(GetProcessHeap(), 0, filename_len * sizeof(char));
     if (!filename_a)
-    {
-        UnmapViewOfFile(buffer);
         return E_OUTOFMEMORY;
-    }
     WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, filename_len, NULL, NULL);
 
+    hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
+    if (FAILED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, filename_a);
+        return D3DXERR_INVALIDDATA;
+    }
+
     hr = D3DCompile(buffer, len, filename_a, (const D3D_SHADER_MACRO *)defines,
                     (ID3DInclude *)include, entrypoint, profile, flags, 0,
                     (ID3DBlob **)shader, (ID3DBlob **)error_messages);
@@ -429,8 +474,8 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
         hr = D3DXGetShaderConstantTable(ID3DXBuffer_GetBufferPointer(*shader),
                                         constant_table);
 
+    ID3DXInclude_Close(include, buffer);
     HeapFree(GetProcessHeap(), 0, filename_a);
-    UnmapViewOfFile(buffer);
     return hr;
 }
 
@@ -442,7 +487,12 @@ HRESULT WINAPI D3DXCompileShaderFromResourceA(HMODULE module, const char *resour
     HRSRC res;
     DWORD len;
 
-    if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
+    TRACE("module %p, resource %s, defines %p, include %p, entrypoint %s, profile %s, "
+            "flags %#x, shader %p, error_messages %p, constant_table %p.\n",
+            module, debugstr_a(resource), defines, include, debugstr_a(entrypoint), debugstr_a(profile),
+            flags, shader, error_messages, constant_table);
+
+    if (!(res = FindResourceA(module, resource, (const char *)RT_RCDATA)))
         return D3DXERR_INVALIDDATA;
     if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
         return D3DXERR_INVALIDDATA;
@@ -474,7 +524,9 @@ HRESULT WINAPI D3DXCompileShaderFromResourceW(HMODULE module, const WCHAR *resou
 HRESULT WINAPI D3DXPreprocessShader(const char *data, UINT data_len, const D3DXMACRO *defines,
         ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
 {
-    TRACE("Forward to D3DPreprocess\n");
+    TRACE("data %s, data_len %u, defines %p, include %p, shader %p, error_messages %p.\n",
+            debugstr_a(data), data_len, defines, include, shader, error_messages);
+
     return D3DPreprocess(data, data_len, NULL,
                          (const D3D_SHADER_MACRO *)defines, (ID3DInclude *)include,
                          (ID3DBlob **)shader, (ID3DBlob **)error_messages);
@@ -487,6 +539,9 @@ HRESULT WINAPI D3DXPreprocessShaderFromFileA(const char *filename, const D3DXMAC
     DWORD len;
     HRESULT ret;
 
+    TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
+            debugstr_a(filename), defines, include, shader, error_messages);
+
     if (!filename) return D3DXERR_INVALIDDATA;
 
     len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
@@ -503,13 +558,14 @@ HRESULT WINAPI D3DXPreprocessShaderFromFileA(const char *filename, const D3DXMAC
 HRESULT WINAPI D3DXPreprocessShaderFromFileW(const WCHAR *filename, const D3DXMACRO *defines,
         ID3DXInclude *include, ID3DXBuffer **shader, ID3DXBuffer **error_messages)
 {
-    void *buffer;
+    const void *buffer;
     DWORD len;
     HRESULT hr;
     struct D3DXIncludeImpl includefromfile;
+    char *filename_a;
 
-    if (FAILED(map_view_of_file(filename, &buffer, &len)))
-        return D3DXERR_INVALIDDATA;
+    TRACE("filename %s, defines %p, include %p, shader %p, error_messages %p.\n",
+            debugstr_w(filename), defines, include, shader, error_messages);
 
     if (!include)
     {
@@ -517,12 +573,26 @@ HRESULT WINAPI D3DXPreprocessShaderFromFileW(const WCHAR *filename, const D3DXMA
         include = &includefromfile.ID3DXInclude_iface;
     }
 
+    len = WideCharToMultiByte(CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL);
+    filename_a = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
+    if (!filename_a)
+        return E_OUTOFMEMORY;
+    WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
+
+    hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
+    if (FAILED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, filename_a);
+        return D3DXERR_INVALIDDATA;
+    }
+
     hr = D3DPreprocess(buffer, len, NULL,
                        (const D3D_SHADER_MACRO *)defines,
                        (ID3DInclude *) include,
                        (ID3DBlob **)shader, (ID3DBlob **)error_messages);
 
-    UnmapViewOfFile(buffer);
+    ID3DXInclude_Close(include, buffer);
+    HeapFree(GetProcessHeap(), 0, filename_a);
     return hr;
 }
 
@@ -533,7 +603,10 @@ HRESULT WINAPI D3DXPreprocessShaderFromResourceA(HMODULE module, const char *res
     HRSRC res;
     DWORD len;
 
-    if (!(res = FindResourceA(module, resource, (LPCSTR)RT_RCDATA)))
+    TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
+            module, debugstr_a(resource), defines, include, shader, error_messages);
+
+    if (!(res = FindResourceA(module, resource, (const char *)RT_RCDATA)))
         return D3DXERR_INVALIDDATA;
     if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
         return D3DXERR_INVALIDDATA;
@@ -548,6 +621,9 @@ HRESULT WINAPI D3DXPreprocessShaderFromResourceW(HMODULE module, const WCHAR *re
     HRSRC res;
     DWORD len;
 
+    TRACE("module %p, resource %s, defines %p, include %p, shader %p, error_messages %p.\n",
+            module, debugstr_w(resource), defines, include, shader, error_messages);
+
     if (!(res = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
         return D3DXERR_INVALIDDATA;
     if (FAILED(load_resource_into_memory(module, res, &buffer, &len)))
@@ -615,12 +691,13 @@ static inline D3DXHANDLE handle_from_constant(struct ctab_constant *constant)
     return (D3DXHANDLE)constant;
 }
 
-static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl *, struct ctab_constant *, LPCSTR);
+static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl *table,
+        struct ctab_constant *constant, const char *name);
 
-static struct ctab_constant *get_constant_element_by_name(struct ctab_constant *constant, LPCSTR name)
+static struct ctab_constant *get_constant_element_by_name(struct ctab_constant *constant, const char *name)
 {
+    const char *part;
     UINT element;
-    LPCSTR part;
 
     TRACE("constant %p, name %s\n", constant, debugstr_a(name));
 
@@ -656,11 +733,11 @@ static struct ctab_constant *get_constant_element_by_name(struct ctab_constant *
 }
 
 static struct ctab_constant *get_constant_by_name(struct ID3DXConstantTableImpl *table,
-        struct ctab_constant *constant, LPCSTR name)
+        struct ctab_constant *constant, const char *name)
 {
     UINT i, count, length;
     struct ctab_constant *handles;
-    LPCSTR part;
+    const char *part;
 
     TRACE("table %p, constant %p, name %s\n", table, constant, debugstr_a(name));
 
@@ -788,13 +865,13 @@ static ULONG WINAPI ID3DXConstantTableImpl_Release(ID3DXConstantTable *iface)
 }
 
 /*** ID3DXBuffer methods ***/
-static LPVOID WINAPI ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable *iface)
+static void * WINAPI ID3DXConstantTableImpl_GetBufferPointer(ID3DXConstantTable *iface)
 {
-    struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
+    struct ID3DXConstantTableImpl *table = impl_from_ID3DXConstantTable(iface);
 
-    TRACE("(%p)->()\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->ctab;
+    return table->ctab;
 }
 
 static DWORD WINAPI ID3DXConstantTableImpl_GetBufferSize(ID3DXConstantTable *iface)
@@ -889,12 +966,13 @@ static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable *
     return NULL;
 }
 
-static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable *iface, D3DXHANDLE constant, LPCSTR name)
+static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable *iface,
+        D3DXHANDLE constant, const char *name)
 {
     struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface);
     struct ctab_constant *c = get_valid_constant(This, constant);
 
-    TRACE("(%p)->(%p, %s)\n", This, constant, name);
+    TRACE("iface %p, constant %p, name %s.\n", iface, constant, debugstr_a(name));
 
     c = get_constant_by_name(This, c, name);
     TRACE("Returning constant %p\n", c);
@@ -939,7 +1017,7 @@ static UINT set(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,
     UINT l, i, regcount = 1, regsize = 1, cin = 1, rin = 1, ret, last = 0;
     DWORD tmp;
 
-    /* size to small to set anything */
+    /* size too small to set anything */
     if (*size < desc->Rows * desc->Columns)
     {
         *size = 0;
@@ -1059,7 +1137,7 @@ static UINT set(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,
             break;
 
         case D3DXPC_MATRIX_COLUMNS:
-            regcount = desc->Columns;
+            regcount = min(desc->RegisterCount, desc->Columns);
             if (inclass == D3DXPC_MATRIX_ROWS) rin = incol;
             else cin = incol;
             regsize = desc->Rows;
@@ -1685,7 +1763,7 @@ static const struct ID3DXConstantTableVtbl ID3DXConstantTable_Vtbl =
 };
 
 static HRESULT parse_ctab_constant_type(const char *ctab, DWORD typeoffset, struct ctab_constant *constant,
-        BOOL is_element, WORD index, WORD max, DWORD *offset, DWORD nameoffset, UINT regset)
+        BOOL is_element, WORD index, WORD max_index, DWORD *offset, DWORD nameoffset, UINT regset)
 {
     const D3DXSHADER_TYPEINFO *type = (LPD3DXSHADER_TYPEINFO)(ctab + typeoffset);
     const D3DXSHADER_STRUCTMEMBERINFO *memberinfo = NULL;
@@ -1734,7 +1812,7 @@ static HRESULT parse_ctab_constant_type(const char *ctab, DWORD typeoffset, stru
         for (i = 0; i < count; ++i)
         {
             hr = parse_ctab_constant_type(ctab, memberinfo ? memberinfo[i].TypeInfo : typeoffset,
-                    &constant->constants[i], memberinfo == NULL, index + size, max, offset,
+                    &constant->constants[i], memberinfo == NULL, index + size, max_index, offset,
                     memberinfo ? memberinfo[i].Name : nameoffset, regset);
             if (hr != D3D_OK)
                 goto error;
@@ -1769,7 +1847,7 @@ static HRESULT parse_ctab_constant_type(const char *ctab, DWORD typeoffset, stru
 
                     case D3DXPC_MATRIX_ROWS:
                         offsetdiff = type->Rows * 4;
-                        size = is_element ? type->Rows : max(type->Rows, type->Columns);
+                        size = type->Rows;
                         break;
 
                     case D3DXPC_MATRIX_COLUMNS:
@@ -1803,7 +1881,7 @@ static HRESULT parse_ctab_constant_type(const char *ctab, DWORD typeoffset, stru
         if (offset) *offset += offsetdiff * 4;
     }
 
-    constant->desc.RegisterCount = max(0, min(max - index, size));
+    constant->desc.RegisterCount = max(0, min(max_index - index, size));
     constant->desc.Bytes = 4 * constant->desc.Elements * type->Rows * type->Columns;
 
     return D3D_OK;
@@ -1825,8 +1903,8 @@ error:
 HRESULT WINAPI D3DXGetShaderConstantTableEx(const DWORD *byte_code, DWORD flags, ID3DXConstantTable **constant_table)
 {
     struct ID3DXConstantTableImpl *object = NULL;
+    const void *data;
     HRESULT hr;
-    LPCVOID data;
     UINT size;
     const D3DXSHADER_CONSTANTTABLE *ctab_header;
     const D3DXSHADER_CONSTANTINFO *constant_info;
index 3ac5799..1258236 100644 (file)
@@ -29,7 +29,7 @@ struct bone
     FLOAT *weights;
 };
 
-typedef struct ID3DXSkinInfoImpl
+struct d3dx9_skin_info
 {
     ID3DXSkinInfo ID3DXSkinInfo_iface;
     LONG ref;
@@ -39,21 +39,21 @@ typedef struct ID3DXSkinInfoImpl
     DWORD num_vertices;
     DWORD num_bones;
     struct bone *bones;
-} ID3DXSkinInfoImpl;
+};
 
-static inline struct ID3DXSkinInfoImpl *impl_from_ID3DXSkinInfo(ID3DXSkinInfo *iface)
+static inline struct d3dx9_skin_info *impl_from_ID3DXSkinInfo(ID3DXSkinInfo *iface)
 {
-    return CONTAINING_RECORD(iface, struct ID3DXSkinInfoImpl, ID3DXSkinInfo_iface);
+    return CONTAINING_RECORD(iface, struct d3dx9_skin_info, ID3DXSkinInfo_iface);
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_QueryInterface(ID3DXSkinInfo *iface, REFIID riid, void **ppobj)
+static HRESULT WINAPI d3dx9_skin_info_QueryInterface(ID3DXSkinInfo *iface, REFIID riid, void **out)
 {
-    TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppobj);
+    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
 
     if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ID3DXSkinInfo))
     {
         IUnknown_AddRef(iface);
-        *ppobj = iface;
+        *out = iface;
         return D3D_OK;
     }
 
@@ -62,47 +62,52 @@ static HRESULT WINAPI ID3DXSkinInfoImpl_QueryInterface(ID3DXSkinInfo *iface, REF
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI ID3DXSkinInfoImpl_AddRef(ID3DXSkinInfo *iface)
+static ULONG WINAPI d3dx9_skin_info_AddRef(ID3DXSkinInfo *iface)
 {
-    struct ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-    ULONG ref = InterlockedIncrement(&This->ref);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
+    ULONG refcount = InterlockedIncrement(&skin->ref);
 
-    TRACE("%p increasing refcount to %u\n", This, ref);
+    TRACE("%p increasing refcount to %u.\n", skin, refcount);
 
-    return ref;
+    return refcount;
 }
 
-static ULONG WINAPI ID3DXSkinInfoImpl_Release(ID3DXSkinInfo *iface)
+static ULONG WINAPI d3dx9_skin_info_Release(ID3DXSkinInfo *iface)
 {
-    struct ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-    ULONG ref = InterlockedDecrement(&This->ref);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
+    ULONG refcount = InterlockedDecrement(&skin->ref);
 
-    TRACE("%p decreasing refcount to %u\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", skin, refcount);
 
-    if (ref == 0) {
+    if (!refcount)
+    {
         DWORD i;
-        for (i = 0; i < This->num_bones; i++) {
-            HeapFree(GetProcessHeap(), 0, This->bones[i].name);
-            HeapFree(GetProcessHeap(), 0, This->bones[i].vertices);
-            HeapFree(GetProcessHeap(), 0, This->bones[i].weights);
+
+        for (i = 0; i < skin->num_bones; ++i)
+        {
+            HeapFree(GetProcessHeap(), 0, skin->bones[i].name);
+            HeapFree(GetProcessHeap(), 0, skin->bones[i].vertices);
+            HeapFree(GetProcessHeap(), 0, skin->bones[i].weights);
         }
-        HeapFree(GetProcessHeap(), 0, This->bones);
-        HeapFree(GetProcessHeap(), 0, This);
+        HeapFree(GetProcessHeap(), 0, skin->bones);
+        HeapFree(GetProcessHeap(), 0, skin);
     }
 
-    return ref;
+    return refcount;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneInfluence(ID3DXSkinInfo *iface, DWORD bone_num, DWORD num_influences, CONST DWORD *vertices, CONST FLOAT *weights)
+static HRESULT WINAPI d3dx9_skin_info_SetBoneInfluence(ID3DXSkinInfo *iface,
+        DWORD bone_num, DWORD num_influences, const DWORD *vertices, const float *weights)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
     struct bone *bone;
     DWORD *new_vertices = NULL;
     FLOAT *new_weights = NULL;
 
-    TRACE("(%p, %u, %u, %p, %p)\n", This, bone_num, num_influences, vertices, weights);
+    TRACE("iface %p, bone_num %u, num_influences %u, vertices %p, weights %p.\n",
+            iface, bone_num, num_influences, vertices, weights);
 
-    if (bone_num >= This->num_bones || !vertices || !weights)
+    if (bone_num >= skin->num_bones || !vertices || !weights)
         return D3DERR_INVALIDCALL;
 
     if (num_influences) {
@@ -117,7 +122,7 @@ static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneInfluence(ID3DXSkinInfo *iface, D
         memcpy(new_vertices, vertices, num_influences * sizeof(*vertices));
         memcpy(new_weights, weights, num_influences * sizeof(*weights));
     }
-    bone = &This->bones[bone_num];
+    bone = &skin->bones[bone_num];
     bone->num_influences = num_influences;
     HeapFree(GetProcessHeap(), 0, bone->vertices);
     HeapFree(GetProcessHeap(), 0, bone->weights);
@@ -127,38 +132,40 @@ static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneInfluence(ID3DXSkinInfo *iface, D
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneVertexInfluence(ID3DXSkinInfo *iface, DWORD bone_num, DWORD influence_num, float weight)
+static HRESULT WINAPI d3dx9_skin_info_SetBoneVertexInfluence(ID3DXSkinInfo *iface,
+        DWORD bone_num, DWORD influence_num, float weight)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %u, %u, %g): stub\n", This, bone_num, influence_num, weight);
+    FIXME("iface %p, bone_num %u, influence_num %u, weight %.8e stub!\n",
+            iface, bone_num, influence_num, weight);
 
     return E_NOTIMPL;
 }
 
-static DWORD WINAPI ID3DXSkinInfoImpl_GetNumBoneInfluences(ID3DXSkinInfo *iface, DWORD bone_num)
+static DWORD WINAPI d3dx9_skin_info_GetNumBoneInfluences(ID3DXSkinInfo *iface, DWORD bone_num)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
 
-    TRACE("(%p, %u)\n", This, bone_num);
+    TRACE("iface %p, bone_num %u.\n", iface, bone_num);
 
-    if (bone_num >= This->num_bones)
+    if (bone_num >= skin->num_bones)
         return 0;
 
-    return This->bones[bone_num].num_influences;
+    return skin->bones[bone_num].num_influences;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_GetBoneInfluence(ID3DXSkinInfo *iface, DWORD bone_num, DWORD *vertices, FLOAT *weights)
+static HRESULT WINAPI d3dx9_skin_info_GetBoneInfluence(ID3DXSkinInfo *iface,
+        DWORD bone_num, DWORD *vertices, float *weights)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
     struct bone *bone;
 
-    TRACE("(%p, %u, %p, %p)\n", This, bone_num, vertices, weights);
+    TRACE("iface %p, bone_num %u, vertices %p, weights %p.\n",
+            iface, bone_num, vertices, weights);
 
-    if (bone_num >= This->num_bones || !vertices)
+    if (bone_num >= skin->num_bones || !vertices)
         return D3DERR_INVALIDCALL;
 
-    bone = &This->bones[bone_num];
+    bone = &skin->bones[bone_num];
     if (!bone->num_influences)
         return D3D_OK;
 
@@ -169,81 +176,72 @@ static HRESULT WINAPI ID3DXSkinInfoImpl_GetBoneInfluence(ID3DXSkinInfo *iface, D
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_GetBoneVertexInfluence(ID3DXSkinInfo *iface, DWORD bone_num,
-        DWORD influence_num, float *weight, DWORD *vertex_num)
+static HRESULT WINAPI d3dx9_skin_info_GetBoneVertexInfluence(ID3DXSkinInfo *iface,
+        DWORD bone_num, DWORD influence_num, float *weight, DWORD *vertex_num)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %u, %u, %p, %p): stub\n", This, bone_num, influence_num, weight, vertex_num);
+    FIXME("iface %p, bone_num %u, influence_num %u, weight %p, vertex_num %p stub!\n",
+            iface, bone_num, influence_num, weight, vertex_num);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_GetMaxVertexInfluences(ID3DXSkinInfo *iface, DWORD *max_vertex_influences)
+static HRESULT WINAPI d3dx9_skin_info_GetMaxVertexInfluences(ID3DXSkinInfo *iface, DWORD *max_vertex_influences)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %p): stub\n", This, max_vertex_influences);
+    FIXME("iface %p, max_vertex_influences %p stub!\n", iface, max_vertex_influences);
 
     return E_NOTIMPL;
 }
 
-static DWORD WINAPI ID3DXSkinInfoImpl_GetNumBones(ID3DXSkinInfo *iface)
+static DWORD WINAPI d3dx9_skin_info_GetNumBones(ID3DXSkinInfo *iface)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->num_bones;
+    return skin->num_bones;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_FindBoneVertexInfluenceIndex(ID3DXSkinInfo *iface, DWORD bone_num,
-        DWORD vertex_num, DWORD *influence_index)
+static HRESULT WINAPI d3dx9_skin_info_FindBoneVertexInfluenceIndex(ID3DXSkinInfo *iface,
+        DWORD bone_num, DWORD vertex_num, DWORD *influence_index)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %u, %u, %p): stub\n", This, bone_num, vertex_num, influence_index);
+    FIXME("iface %p, bone_num %u, vertex_num %u, influence_index %p stub!\n",
+            iface, bone_num, vertex_num, influence_index);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_GetMaxFaceInfluences(struct ID3DXSkinInfo *iface,
+static HRESULT WINAPI d3dx9_skin_info_GetMaxFaceInfluences(struct ID3DXSkinInfo *iface,
         struct IDirect3DIndexBuffer9 *index_buffer, DWORD num_faces, DWORD *max_face_influences)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %p, %u, %p): stub\n", This, index_buffer, num_faces, max_face_influences);
+    FIXME("iface %p, index_buffer %p, num_faces %u, max_face_influences %p stub!\n",
+            iface, index_buffer, num_faces, max_face_influences);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_SetMinBoneInfluence(ID3DXSkinInfo *iface, FLOAT min_influence)
+static HRESULT WINAPI d3dx9_skin_info_SetMinBoneInfluence(ID3DXSkinInfo *iface, float min_influence)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %g): stub\n", This, min_influence);
+    FIXME("iface %p, min_influence %.8e stub!\n", iface, min_influence);
 
     return E_NOTIMPL;
 }
 
-static FLOAT WINAPI ID3DXSkinInfoImpl_GetMinBoneInfluence(ID3DXSkinInfo *iface)
+static float WINAPI d3dx9_skin_info_GetMinBoneInfluence(ID3DXSkinInfo *iface)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p): stub\n", This);
+    FIXME("iface %p stub!\n", iface);
 
     return 0.0f;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneName(ID3DXSkinInfo *iface, DWORD bone_num, LPCSTR name)
+static HRESULT WINAPI d3dx9_skin_info_SetBoneName(ID3DXSkinInfo *iface, DWORD bone_idx, const char *name)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
     char *new_name;
     size_t size;
 
-    TRACE("(%p, %u, %s)\n", This, bone_num, debugstr_a(name));
+    TRACE("iface %p, bone_idx %u, name %s.\n", iface, bone_idx, debugstr_a(name));
 
-    if (bone_num >= This->num_bones || !name)
+    if (bone_idx >= skin->num_bones || !name)
         return D3DERR_INVALIDCALL;
 
     size = strlen(name) + 1;
@@ -251,74 +249,70 @@ static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneName(ID3DXSkinInfo *iface, DWORD
     if (!new_name)
         return E_OUTOFMEMORY;
     memcpy(new_name, name, size);
-    HeapFree(GetProcessHeap(), 0, This->bones[bone_num].name);
-    This->bones[bone_num].name = new_name;
+    HeapFree(GetProcessHeap(), 0, skin->bones[bone_idx].name);
+    skin->bones[bone_idx].name = new_name;
 
     return D3D_OK;
 }
 
-static LPCSTR WINAPI ID3DXSkinInfoImpl_GetBoneName(ID3DXSkinInfo *iface, DWORD bone_num)
+static const char * WINAPI d3dx9_skin_info_GetBoneName(ID3DXSkinInfo *iface, DWORD bone_idx)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
 
-    TRACE("(%p, %u)\n", This, bone_num);
+    TRACE("iface %p, bone_idx %u.\n", iface, bone_idx);
 
-    if (bone_num >= This->num_bones)
+    if (bone_idx >= skin->num_bones)
         return NULL;
 
-    return This->bones[bone_num].name;
+    return skin->bones[bone_idx].name;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneOffsetMatrix(ID3DXSkinInfo *iface, DWORD bone_num, CONST D3DXMATRIX *bone_transform)
+static HRESULT WINAPI d3dx9_skin_info_SetBoneOffsetMatrix(ID3DXSkinInfo *iface,
+        DWORD bone_num, const D3DXMATRIX *bone_transform)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
 
-    TRACE("(%p, %u, %p)\n", This, bone_num, bone_transform);
+    TRACE("iface %p, bone_num %u, bone_transform %p.\n", iface, bone_num, bone_transform);
 
-    if (bone_num >= This->num_bones || !bone_transform)
+    if (bone_num >= skin->num_bones || !bone_transform)
         return D3DERR_INVALIDCALL;
 
-    This->bones[bone_num].transform = *bone_transform;
+    skin->bones[bone_num].transform = *bone_transform;
     return D3D_OK;
 }
 
-static D3DXMATRIX * WINAPI ID3DXSkinInfoImpl_GetBoneOffsetMatrix(ID3DXSkinInfo *iface, DWORD bone_num)
+static D3DXMATRIX * WINAPI d3dx9_skin_info_GetBoneOffsetMatrix(ID3DXSkinInfo *iface, DWORD bone_num)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
 
-    TRACE("(%p, %u)\n", This, bone_num);
+    TRACE("iface %p, bone_num %u.\n", iface, bone_num);
 
-    if (bone_num >= This->num_bones)
+    if (bone_num >= skin->num_bones)
         return NULL;
 
-    return &This->bones[bone_num].transform;
+    return &skin->bones[bone_num].transform;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_Clone(ID3DXSkinInfo *iface, ID3DXSkinInfo **skin_info)
+static HRESULT WINAPI d3dx9_skin_info_Clone(ID3DXSkinInfo *iface, ID3DXSkinInfo **skin_info)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %p): stub\n", This, skin_info);
+    FIXME("iface %p, skin_info %p stub!\n", iface, skin_info);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_Remap(ID3DXSkinInfo *iface, DWORD num_vertices, DWORD *vertex_remap)
+static HRESULT WINAPI d3dx9_skin_info_Remap(ID3DXSkinInfo *iface, DWORD num_vertices, DWORD *vertex_remap)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %u, %p): stub\n", This, num_vertices, vertex_remap);
+    FIXME("iface %p, num_vertices %u, vertex_remap %p stub!\n", iface, num_vertices, vertex_remap);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_SetFVF(ID3DXSkinInfo *iface, DWORD fvf)
+static HRESULT WINAPI d3dx9_skin_info_SetFVF(ID3DXSkinInfo *iface, DWORD fvf)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
     HRESULT hr;
     D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE];
 
-    TRACE("(%p, %x)\n", This, fvf);
+    TRACE("iface %p, fvf %#x.\n", iface, fvf);
 
     hr = D3DXDeclaratorFromFVF(fvf, declaration);
     if (FAILED(hr)) return hr;
@@ -326,13 +320,13 @@ static HRESULT WINAPI ID3DXSkinInfoImpl_SetFVF(ID3DXSkinInfo *iface, DWORD fvf)
     return iface->lpVtbl->SetDeclaration(iface, declaration);
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_SetDeclaration(ID3DXSkinInfo *iface, CONST D3DVERTEXELEMENT9 *declaration)
+static HRESULT WINAPI d3dx9_skin_info_SetDeclaration(ID3DXSkinInfo *iface, const D3DVERTEXELEMENT9 *declaration)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
     HRESULT hr;
     int count;
 
-    TRACE("(%p, %p)\n", This, declaration);
+    TRACE("iface %p, declaration %p.\n", iface, declaration);
 
     if (!declaration)
         return D3DERR_INVALIDCALL;
@@ -345,115 +339,111 @@ static HRESULT WINAPI ID3DXSkinInfoImpl_SetDeclaration(ID3DXSkinInfo *iface, CON
     }
     count++;
 
-    memcpy(This->vertex_declaration, declaration, count * sizeof(*declaration));
+    memcpy(skin->vertex_declaration, declaration, count * sizeof(*declaration));
 
-    hr = D3DXFVFFromDeclarator(This->vertex_declaration, &This->fvf);
-    if (FAILED(hr))
-        This->fvf = 0;
+    if (FAILED(hr = D3DXFVFFromDeclarator(skin->vertex_declaration, &skin->fvf)))
+        skin->fvf = 0;
 
     return D3D_OK;
 }
 
-static DWORD WINAPI ID3DXSkinInfoImpl_GetFVF(ID3DXSkinInfo *iface)
+static DWORD WINAPI d3dx9_skin_info_GetFVF(ID3DXSkinInfo *iface)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p.\n", iface);
 
-    return This->fvf;
+    return skin->fvf;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_GetDeclaration(ID3DXSkinInfo *iface, D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE])
+static HRESULT WINAPI d3dx9_skin_info_GetDeclaration(ID3DXSkinInfo *iface,
+        D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE])
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
+    struct d3dx9_skin_info *skin = impl_from_ID3DXSkinInfo(iface);
     UINT count = 0;
 
-    TRACE("(%p)\n", This);
+    TRACE("iface %p, declaration %p.\n", iface, declaration);
 
-    while (This->vertex_declaration[count++].Stream != 0xff);
-    memcpy(declaration, This->vertex_declaration, count * sizeof(declaration[0]));
+    while (skin->vertex_declaration[count++].Stream != 0xff);
+    memcpy(declaration, skin->vertex_declaration, count * sizeof(declaration[0]));
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_UpdateSkinnedMesh(ID3DXSkinInfo *iface, CONST D3DXMATRIX *bone_transforms,
-        CONST D3DXMATRIX *bone_inv_transpose_transforms, LPCVOID vertices_src, PVOID vertices_dest)
+static HRESULT WINAPI d3dx9_skin_info_UpdateSkinnedMesh(ID3DXSkinInfo *iface, const D3DXMATRIX *bone_transforms,
+        const D3DXMATRIX *bone_inv_transpose_transforms, const void *src_vertices, void *dst_vertices)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %p, %p, %p, %p): stub\n", This, bone_transforms, bone_inv_transpose_transforms, vertices_src, vertices_dest);
+    FIXME("iface %p, bone_transforms %p, bone_inv_transpose_transforms %p, src_vertices %p, dst_vertices %p stub!\n",
+            iface, bone_transforms, bone_inv_transpose_transforms, src_vertices, dst_vertices);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_ConvertToBlendedMesh(ID3DXSkinInfo *iface, ID3DXMesh *mesh_in,
+static HRESULT WINAPI d3dx9_skin_info_ConvertToBlendedMesh(ID3DXSkinInfo *iface, ID3DXMesh *mesh_in,
         DWORD options, const DWORD *adjacency_in, DWORD *adjacency_out, DWORD *face_remap,
         ID3DXBuffer **vertex_remap, DWORD *max_face_infl, DWORD *num_bone_combinations,
         ID3DXBuffer **bone_combination_table, ID3DXMesh **mesh_out)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
-          This, mesh_in, options, adjacency_in, adjacency_out, face_remap, vertex_remap,
-          max_face_infl, num_bone_combinations, bone_combination_table, mesh_out);
+    FIXME("iface %p, mesh_in %p, options %#x, adjacency_in %p, adjacency_out %p, face_remap %p, vertex_remap %p, "
+            "max_face_infl %p, num_bone_combinations %p, bone_combination_table %p, mesh_out %p stub!\n",
+            iface, mesh_in, options, adjacency_in, adjacency_out, face_remap, vertex_remap,
+            max_face_infl, num_bone_combinations, bone_combination_table, mesh_out);
 
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh(ID3DXSkinInfo *iface, ID3DXMesh *mesh_in,
+static HRESULT WINAPI d3dx9_skin_info_ConvertToIndexedBlendedMesh(ID3DXSkinInfo *iface, ID3DXMesh *mesh_in,
         DWORD options, const DWORD *adjacency_in, DWORD *adjacency_out, DWORD *face_remap,
         ID3DXBuffer **vertex_remap, DWORD *max_face_infl, DWORD *num_bone_combinations,
         ID3DXBuffer **bone_combination_table, ID3DXMesh **mesh_out)
 {
-    ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
-
-    FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
-          This, mesh_in, options, adjacency_in, adjacency_out, face_remap, vertex_remap,
-          max_face_infl, num_bone_combinations, bone_combination_table, mesh_out);
+    FIXME("iface %p, mesh_in %p, options %#x, adjacency_in %p, adjacency_out %p, face_remap %p, vertex_remap %p, "
+            "max_face_infl %p, num_bone_combinations %p, bone_combination_table %p, mesh_out %p stub!\n",
+            iface, mesh_in, options, adjacency_in, adjacency_out, face_remap, vertex_remap,
+            max_face_infl, num_bone_combinations, bone_combination_table, mesh_out);
 
     return E_NOTIMPL;
 }
 
-static const struct ID3DXSkinInfoVtbl ID3DXSkinInfoImpl_Vtbl =
-{
-    /* IUnknown methods */
-    ID3DXSkinInfoImpl_QueryInterface,
-    ID3DXSkinInfoImpl_AddRef,
-    ID3DXSkinInfoImpl_Release,
-    /* ID3DXSkinInfo */
-    ID3DXSkinInfoImpl_SetBoneInfluence,
-    ID3DXSkinInfoImpl_SetBoneVertexInfluence,
-    ID3DXSkinInfoImpl_GetNumBoneInfluences,
-    ID3DXSkinInfoImpl_GetBoneInfluence,
-    ID3DXSkinInfoImpl_GetBoneVertexInfluence,
-    ID3DXSkinInfoImpl_GetMaxVertexInfluences,
-    ID3DXSkinInfoImpl_GetNumBones,
-    ID3DXSkinInfoImpl_FindBoneVertexInfluenceIndex,
-    ID3DXSkinInfoImpl_GetMaxFaceInfluences,
-    ID3DXSkinInfoImpl_SetMinBoneInfluence,
-    ID3DXSkinInfoImpl_GetMinBoneInfluence,
-    ID3DXSkinInfoImpl_SetBoneName,
-    ID3DXSkinInfoImpl_GetBoneName,
-    ID3DXSkinInfoImpl_SetBoneOffsetMatrix,
-    ID3DXSkinInfoImpl_GetBoneOffsetMatrix,
-    ID3DXSkinInfoImpl_Clone,
-    ID3DXSkinInfoImpl_Remap,
-    ID3DXSkinInfoImpl_SetFVF,
-    ID3DXSkinInfoImpl_SetDeclaration,
-    ID3DXSkinInfoImpl_GetFVF,
-    ID3DXSkinInfoImpl_GetDeclaration,
-    ID3DXSkinInfoImpl_UpdateSkinnedMesh,
-    ID3DXSkinInfoImpl_ConvertToBlendedMesh,
-    ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh
+static const struct ID3DXSkinInfoVtbl d3dx9_skin_info_vtbl =
+{
+    d3dx9_skin_info_QueryInterface,
+    d3dx9_skin_info_AddRef,
+    d3dx9_skin_info_Release,
+    d3dx9_skin_info_SetBoneInfluence,
+    d3dx9_skin_info_SetBoneVertexInfluence,
+    d3dx9_skin_info_GetNumBoneInfluences,
+    d3dx9_skin_info_GetBoneInfluence,
+    d3dx9_skin_info_GetBoneVertexInfluence,
+    d3dx9_skin_info_GetMaxVertexInfluences,
+    d3dx9_skin_info_GetNumBones,
+    d3dx9_skin_info_FindBoneVertexInfluenceIndex,
+    d3dx9_skin_info_GetMaxFaceInfluences,
+    d3dx9_skin_info_SetMinBoneInfluence,
+    d3dx9_skin_info_GetMinBoneInfluence,
+    d3dx9_skin_info_SetBoneName,
+    d3dx9_skin_info_GetBoneName,
+    d3dx9_skin_info_SetBoneOffsetMatrix,
+    d3dx9_skin_info_GetBoneOffsetMatrix,
+    d3dx9_skin_info_Clone,
+    d3dx9_skin_info_Remap,
+    d3dx9_skin_info_SetFVF,
+    d3dx9_skin_info_SetDeclaration,
+    d3dx9_skin_info_GetFVF,
+    d3dx9_skin_info_GetDeclaration,
+    d3dx9_skin_info_UpdateSkinnedMesh,
+    d3dx9_skin_info_ConvertToBlendedMesh,
+    d3dx9_skin_info_ConvertToIndexedBlendedMesh,
 };
 
 HRESULT WINAPI D3DXCreateSkinInfo(DWORD num_vertices, const D3DVERTEXELEMENT9 *declaration,
         DWORD num_bones, ID3DXSkinInfo **skin_info)
 {
     HRESULT hr;
-    ID3DXSkinInfoImpl *object = NULL;
     static const D3DVERTEXELEMENT9 empty_declaration = D3DDECL_END();
+    struct d3dx9_skin_info *object = NULL;
 
-    TRACE("(%u, %p, %u, %p)\n", num_vertices, declaration, num_bones, skin_info);
+    TRACE("num_vertices %u, declaration %p, num_bones %u, skin_info %p.\n",
+            num_vertices, declaration, num_bones, skin_info);
 
     if (!skin_info || !declaration)
         return D3DERR_INVALIDCALL;
@@ -462,7 +452,7 @@ HRESULT WINAPI D3DXCreateSkinInfo(DWORD num_vertices, const D3DVERTEXELEMENT9 *d
     if (!object)
         return E_OUTOFMEMORY;
 
-    object->ID3DXSkinInfo_iface.lpVtbl = &ID3DXSkinInfoImpl_Vtbl;
+    object->ID3DXSkinInfo_iface.lpVtbl = &d3dx9_skin_info_vtbl;
     object->ref = 1;
     object->num_vertices = num_vertices;
     object->num_bones = num_bones;
@@ -475,8 +465,8 @@ HRESULT WINAPI D3DXCreateSkinInfo(DWORD num_vertices, const D3DVERTEXELEMENT9 *d
         goto error;
     }
 
-    hr = ID3DXSkinInfoImpl_SetDeclaration(&object->ID3DXSkinInfo_iface, declaration);
-    if (FAILED(hr)) goto error;
+    if (FAILED(hr = d3dx9_skin_info_SetDeclaration(&object->ID3DXSkinInfo_iface, declaration)))
+        goto error;
 
     *skin_info = &object->ID3DXSkinInfo_iface;
 
index f320eaf..4fdec6a 100644 (file)
 /* the combination of all possible D3DXSPRITE flags */
 #define D3DXSPRITE_FLAGLIMIT 511
 
-typedef struct _SPRITEVERTEX {
+struct sprite_vertex
+{
     D3DXVECTOR3 pos;
     DWORD col;
     D3DXVECTOR2 tex;
-} SPRITEVERTEX;
+};
 
-typedef struct _SPRITE {
+struct sprite
+{
     IDirect3DTexture9 *texture;
     UINT texw, texh;
     RECT rect;
@@ -36,9 +38,9 @@ typedef struct _SPRITE {
     D3DXVECTOR3 pos;
     D3DCOLOR color;
     D3DXMATRIX transform;
-} SPRITE;
+};
 
-typedef struct ID3DXSpriteImpl
+struct d3dx9_sprite
 {
     ID3DXSprite ID3DXSprite_iface;
     LONG ref;
@@ -56,17 +58,17 @@ typedef struct ID3DXSpriteImpl
     DWORD maxanisotropy;
     DWORD alphacmp_caps;
 
-    SPRITE *sprites;
+    struct sprite *sprites;
     int sprite_count;      /* number of sprites to be drawn */
     int allocated_sprites; /* number of (pre-)allocated sprites */
-} ID3DXSpriteImpl;
+};
 
-static inline ID3DXSpriteImpl *impl_from_ID3DXSprite(ID3DXSprite *iface)
+static inline struct d3dx9_sprite *impl_from_ID3DXSprite(ID3DXSprite *iface)
 {
-    return CONTAINING_RECORD(iface, ID3DXSpriteImpl, ID3DXSprite_iface);
+    return CONTAINING_RECORD(iface, struct d3dx9_sprite, ID3DXSprite_iface);
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_QueryInterface(ID3DXSprite *iface, REFIID riid, void **out)
+static HRESULT WINAPI d3dx9_sprite_QueryInterface(ID3DXSprite *iface, REFIID riid, void **out)
 {
     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
 
@@ -84,93 +86,108 @@ static HRESULT WINAPI ID3DXSpriteImpl_QueryInterface(ID3DXSprite *iface, REFIID
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI ID3DXSpriteImpl_AddRef(ID3DXSprite *iface)
+static ULONG WINAPI d3dx9_sprite_AddRef(ID3DXSprite *iface)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
-    ULONG ref=InterlockedIncrement(&This->ref);
-    TRACE("(%p)->(): AddRef from %d\n", This, ref-1);
-    return ref;
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
+    ULONG refcount = InterlockedIncrement(&sprite->ref);
+
+    TRACE("%p increasing refcount to %u.\n", sprite, refcount);
+
+    return refcount;
 }
 
-static ULONG WINAPI ID3DXSpriteImpl_Release(ID3DXSprite *iface)
+static ULONG WINAPI d3dx9_sprite_Release(ID3DXSprite *iface)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
-    ULONG ref=InterlockedDecrement(&This->ref);
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
+    ULONG refcount = InterlockedDecrement(&sprite->ref);
 
-    TRACE("(%p)->(): ReleaseRef to %d\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", sprite, refcount);
 
-    if(ref==0) {
-        if(This->sprites) {
+    if (!refcount)
+    {
+        if (sprite->sprites)
+        {
             int i;
-            for(i=0;i<This->sprite_count;i++)
-                if(This->sprites[i].texture)
-                    IDirect3DTexture9_Release(This->sprites[i].texture);
 
-            HeapFree(GetProcessHeap(), 0, This->sprites);
+            for (i = 0; i < sprite->sprite_count; ++i)
+            {
+                if (sprite->sprites[i].texture)
+                    IDirect3DTexture9_Release(sprite->sprites[i].texture);
+            }
+
+            HeapFree(GetProcessHeap(), 0, sprite->sprites);
         }
-        if(This->stateblock) IDirect3DStateBlock9_Release(This->stateblock);
-        if(This->vdecl) IDirect3DVertexDeclaration9_Release(This->vdecl);
-        if(This->device) IDirect3DDevice9_Release(This->device);
-        HeapFree(GetProcessHeap(), 0, This);
+
+        if (sprite->stateblock)
+            IDirect3DStateBlock9_Release(sprite->stateblock);
+        if (sprite->vdecl)
+            IDirect3DVertexDeclaration9_Release(sprite->vdecl);
+        if (sprite->device)
+            IDirect3DDevice9_Release(sprite->device);
+        HeapFree(GetProcessHeap(), 0, sprite);
     }
-    return ref;
+
+    return refcount;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_GetDevice(struct ID3DXSprite *iface, struct IDirect3DDevice9 **device)
+static HRESULT WINAPI d3dx9_sprite_GetDevice(struct ID3DXSprite *iface, struct IDirect3DDevice9 **device)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
 
-    TRACE("(%p)->(%p)\n", This, device);
+    TRACE("iface %p, device %p.\n", iface, device);
 
-    if(device==NULL) return D3DERR_INVALIDCALL;
-    *device=This->device;
-    IDirect3DDevice9_AddRef(This->device);
+    if (!device)
+        return D3DERR_INVALIDCALL;
+    *device = sprite->device;
+    IDirect3DDevice9_AddRef(sprite->device);
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_GetTransform(ID3DXSprite *iface, D3DXMATRIX *transform)
+static HRESULT WINAPI d3dx9_sprite_GetTransform(ID3DXSprite *iface, D3DXMATRIX *transform)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
 
-    TRACE("(%p)->(%p)\n", This, transform);
+    TRACE("iface %p, transform %p.\n", iface, transform);
 
-    if(transform==NULL) return D3DERR_INVALIDCALL;
-    *transform=This->transform;
+    if (!transform)
+        return D3DERR_INVALIDCALL;
+    *transform = sprite->transform;
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_SetTransform(ID3DXSprite *iface, CONST D3DXMATRIX *transform)
+static HRESULT WINAPI d3dx9_sprite_SetTransform(ID3DXSprite *iface, const D3DXMATRIX *transform)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
 
-    TRACE("(%p)->(%p)\n", This, transform);
+    TRACE("iface %p, transform %p.\n", iface, transform);
 
-    if(transform==NULL) return D3DERR_INVALIDCALL;
-    This->transform=*transform;
+    if (!transform)
+        return D3DERR_INVALIDCALL;
+    sprite->transform = *transform;
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_SetWorldViewRH(ID3DXSprite *iface, CONST D3DXMATRIX *world,
-        CONST D3DXMATRIX *view)
+static HRESULT WINAPI d3dx9_sprite_SetWorldViewRH(ID3DXSprite *iface,
+        const D3DXMATRIX *world, const D3DXMATRIX *view)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
-    FIXME("(%p)->(%p, %p): stub\n", This, world, view);
+    FIXME("iface %p, world %p, view %p stub!\n", iface, world, view);
+
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_SetWorldViewLH(ID3DXSprite *iface, CONST D3DXMATRIX *world,
-        CONST D3DXMATRIX *view)
+static HRESULT WINAPI d3dx9_sprite_SetWorldViewLH(ID3DXSprite *iface,
+        const D3DXMATRIX *world, const D3DXMATRIX *view)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
-    FIXME("(%p)->(%p, %p): stub\n", This, world, view);
+    FIXME("iface %p, world %p, view %p stub!\n", iface, world, view);
+
     return E_NOTIMPL;
 }
 
 /* Helper function */
-static void set_states(ID3DXSpriteImpl *object)
+static void set_states(struct d3dx9_sprite *object)
 {
     D3DXMATRIX mat;
     D3DVIEWPORT9 vp;
@@ -251,12 +268,12 @@ static void set_states(ID3DXSpriteImpl *object)
     IDirect3DDevice9_SetTransform(object->device, D3DTS_PROJECTION, &mat);
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_Begin(ID3DXSprite *iface, DWORD flags)
+static HRESULT WINAPI d3dx9_sprite_Begin(ID3DXSprite *iface, DWORD flags)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *This = impl_from_ID3DXSprite(iface);
     HRESULT hr;
 
-    TRACE("(%p)->(%#x)\n", This, flags);
+    TRACE("iface %p, flags %#x.\n", iface, flags);
 
     if(flags>D3DXSPRITE_FLAGLIMIT || This->ready) return D3DERR_INVALIDCALL;
 
@@ -273,7 +290,7 @@ D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often)
                 D3DXSPRITE_DONOTMODIFY_RENDERSTATE | D3DXSPRITE_OBJECTSPACE |
                 D3DXSPRITE_SORT_DEPTH_BACKTOFRONT))
         FIXME("Flags unsupported: %#x\n", flags);
-    /* These flags should only matter to performances */
+    /* These flags should only matter to performance */
     else if(flags & (D3DXSPRITE_SORT_DEPTH_FRONTTOBACK | D3DXSPRITE_SORT_TEXTURE))
         TRACE("Flags unsupported: %#x\n", flags);
 
@@ -297,7 +314,7 @@ D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often)
             set_states(This);
 
             IDirect3DDevice9_SetVertexDeclaration(This->device, This->vdecl);
-            IDirect3DDevice9_SetStreamSource(This->device, 0, NULL, 0, sizeof(SPRITEVERTEX));
+            IDirect3DDevice9_SetStreamSource(This->device, 0, NULL, 0, sizeof(struct sprite_vertex));
             IDirect3DDevice9_SetIndices(This->device, NULL);
             IDirect3DDevice9_SetTexture(This->device, 0, NULL);
 
@@ -315,10 +332,10 @@ D3DXSPRITE_SORT_TEXTURE: sort by texture (so that it doesn't change too often)
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_Draw(ID3DXSprite *iface, IDirect3DTexture9 *texture,
+static HRESULT WINAPI d3dx9_sprite_Draw(ID3DXSprite *iface, IDirect3DTexture9 *texture,
         const RECT *rect, const D3DXVECTOR3 *center, const D3DXVECTOR3 *position, D3DCOLOR color)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *This = impl_from_ID3DXSprite(iface);
     D3DSURFACE_DESC texdesc;
 
     TRACE("iface %p, texture %p, rect %s, center %p, position %p, color 0x%08x.\n",
@@ -327,12 +344,16 @@ static HRESULT WINAPI ID3DXSpriteImpl_Draw(ID3DXSprite *iface, IDirect3DTexture9
     if(texture==NULL) return D3DERR_INVALIDCALL;
     if(!This->ready) return D3DERR_INVALIDCALL;
 
-    if(This->allocated_sprites==0) {
-        This->sprites=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 32*sizeof(SPRITE));
-        This->allocated_sprites=32;
-    } else if(This->allocated_sprites<=This->sprite_count) {
-        This->allocated_sprites=This->allocated_sprites*3/2;
-        This->sprites=HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->sprites, This->allocated_sprites*sizeof(SPRITE));
+    if (!This->allocated_sprites)
+    {
+        This->sprites = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 32 * sizeof(*This->sprites));
+        This->allocated_sprites = 32;
+    }
+    else if (This->allocated_sprites <= This->sprite_count)
+    {
+        This->allocated_sprites += This->allocated_sprites / 2;
+        This->sprites = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+                This->sprites, This->allocated_sprites * sizeof(*This->sprites));
     }
     This->sprites[This->sprite_count].texture=texture;
     if(!(This->flags & D3DXSPRITE_DO_NOT_ADDREF_TEXTURE))
@@ -377,19 +398,19 @@ static HRESULT WINAPI ID3DXSpriteImpl_Draw(ID3DXSprite *iface, IDirect3DTexture9
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface)
+static HRESULT WINAPI d3dx9_sprite_Flush(ID3DXSprite *iface)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
-    SPRITEVERTEX *vertices;
+    struct d3dx9_sprite *This = impl_from_ID3DXSprite(iface);
+    struct sprite_vertex *vertices;
     int i, count=0, start;
 
-    TRACE("(%p)->()\n", This);
+    TRACE("iface %p.\n", iface);
 
     if(!This->ready) return D3DERR_INVALIDCALL;
     if(!This->sprite_count) return D3D_OK;
 
 /* TODO: use of a vertex buffer here */
-    vertices=HeapAlloc(GetProcessHeap(), 0, sizeof(SPRITEVERTEX)*6*This->sprite_count);
+    vertices = HeapAlloc(GetProcessHeap(), 0, sizeof(*vertices) * 6 * This->sprite_count);
 
     for(start=0;start<This->sprite_count;start+=count,count=0) {
         i=start;
@@ -426,9 +447,8 @@ static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface)
             vertices[6*i+4]=vertices[6*i];
             vertices[6*i+5]=vertices[6*i+2];
 
-            D3DXVec3TransformCoordArray(&vertices[6*i].pos, sizeof(SPRITEVERTEX),
-                                        &vertices[6*i].pos, sizeof(SPRITEVERTEX),
-                                        &This->sprites[i].transform, 6);
+            D3DXVec3TransformCoordArray(&vertices[6 * i].pos, sizeof(*vertices),
+                    &vertices[6 * i].pos, sizeof(*vertices), &This->sprites[i].transform, 6);
             count++;
             i++;
         }
@@ -436,7 +456,8 @@ static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface)
         IDirect3DDevice9_SetTexture(This->device, 0, (struct IDirect3DBaseTexture9 *)This->sprites[start].texture);
         IDirect3DDevice9_SetVertexDeclaration(This->device, This->vdecl);
 
-        IDirect3DDevice9_DrawPrimitiveUP(This->device, D3DPT_TRIANGLELIST, 2*count, vertices+6*start, sizeof(SPRITEVERTEX));
+        IDirect3DDevice9_DrawPrimitiveUP(This->device, D3DPT_TRIANGLELIST,
+                2 * count, vertices + 6 * start, sizeof(*vertices));
     }
     HeapFree(GetProcessHeap(), 0, vertices);
 
@@ -451,34 +472,37 @@ static HRESULT WINAPI ID3DXSpriteImpl_Flush(ID3DXSprite *iface)
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_End(ID3DXSprite *iface)
+static HRESULT WINAPI d3dx9_sprite_End(ID3DXSprite *iface)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
 
-    TRACE("(%p)->()\n", This);
+    TRACE("iface %p.\n", iface);
 
-    if(!This->ready) return D3DERR_INVALIDCALL;
+    if (!sprite->ready)
+        return D3DERR_INVALIDCALL;
 
     ID3DXSprite_Flush(iface);
 
-    if(!(This->flags & D3DXSPRITE_DONOTSAVESTATE))
-        if(This->stateblock) IDirect3DStateBlock9_Apply(This->stateblock); /* Restore old state */
+    if (sprite->stateblock && !(sprite->flags & D3DXSPRITE_DONOTSAVESTATE))
+        IDirect3DStateBlock9_Apply(sprite->stateblock); /* Restore old state */
 
-    This->ready=FALSE;
+    sprite->ready = FALSE;
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_OnLostDevice(ID3DXSprite *iface)
+static HRESULT WINAPI d3dx9_sprite_OnLostDevice(ID3DXSprite *iface)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
 
-    TRACE("(%p)->()\n", This);
+    TRACE("iface %p.\n", iface);
 
-    if(This->stateblock) IDirect3DStateBlock9_Release(This->stateblock);
-    if(This->vdecl) IDirect3DVertexDeclaration9_Release(This->vdecl);
-    This->vdecl=NULL;
-    This->stateblock=NULL;
+    if (sprite->stateblock)
+        IDirect3DStateBlock9_Release(sprite->stateblock);
+    if (sprite->vdecl)
+        IDirect3DVertexDeclaration9_Release(sprite->vdecl);
+    sprite->vdecl = NULL;
+    sprite->stateblock = NULL;
 
     /* Reset some variables */
     ID3DXSprite_OnResetDevice(iface);
@@ -486,21 +510,22 @@ static HRESULT WINAPI ID3DXSpriteImpl_OnLostDevice(ID3DXSprite *iface)
     return D3D_OK;
 }
 
-static HRESULT WINAPI ID3DXSpriteImpl_OnResetDevice(ID3DXSprite *iface)
+static HRESULT WINAPI d3dx9_sprite_OnResetDevice(ID3DXSprite *iface)
 {
-    ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface);
+    struct d3dx9_sprite *sprite = impl_from_ID3DXSprite(iface);
     int i;
 
-    TRACE("(%p)->()\n", This);
+    TRACE("iface %p.\n", iface);
 
-    for(i=0;i<This->sprite_count;i++)
-        if(This->sprites[i].texture)
-            IDirect3DTexture9_Release(This->sprites[i].texture);
-
-    This->sprite_count=0;
+    for (i = 0; i < sprite->sprite_count; ++i)
+    {
+        if (sprite->sprites[i].texture)
+            IDirect3DTexture9_Release(sprite->sprites[i].texture);
+    }
 
-    This->flags=0;
-    This->ready=FALSE;
+    sprite->sprite_count = 0;
+    sprite->flags = 0;
+    sprite->ready = FALSE;
 
     /* keep matrices */
     /* device objects get restored on Begin */
@@ -508,41 +533,39 @@ static HRESULT WINAPI ID3DXSpriteImpl_OnResetDevice(ID3DXSprite *iface)
     return D3D_OK;
 }
 
-static const ID3DXSpriteVtbl D3DXSprite_Vtbl =
+static const ID3DXSpriteVtbl d3dx9_sprite_vtbl =
 {
-    /*** IUnknown methods ***/
-    ID3DXSpriteImpl_QueryInterface,
-    ID3DXSpriteImpl_AddRef,
-    ID3DXSpriteImpl_Release,
-    /*** ID3DXSprite methods ***/
-    ID3DXSpriteImpl_GetDevice,
-    ID3DXSpriteImpl_GetTransform,
-    ID3DXSpriteImpl_SetTransform,
-    ID3DXSpriteImpl_SetWorldViewRH,
-    ID3DXSpriteImpl_SetWorldViewLH,
-    ID3DXSpriteImpl_Begin,
-    ID3DXSpriteImpl_Draw,
-    ID3DXSpriteImpl_Flush,
-    ID3DXSpriteImpl_End,
-    ID3DXSpriteImpl_OnLostDevice,
-    ID3DXSpriteImpl_OnResetDevice
+    d3dx9_sprite_QueryInterface,
+    d3dx9_sprite_AddRef,
+    d3dx9_sprite_Release,
+    d3dx9_sprite_GetDevice,
+    d3dx9_sprite_GetTransform,
+    d3dx9_sprite_SetTransform,
+    d3dx9_sprite_SetWorldViewRH,
+    d3dx9_sprite_SetWorldViewLH,
+    d3dx9_sprite_Begin,
+    d3dx9_sprite_Draw,
+    d3dx9_sprite_Flush,
+    d3dx9_sprite_End,
+    d3dx9_sprite_OnLostDevice,
+    d3dx9_sprite_OnResetDevice,
 };
 
 HRESULT WINAPI D3DXCreateSprite(struct IDirect3DDevice9 *device, struct ID3DXSprite **sprite)
 {
-    ID3DXSpriteImpl *object;
+    struct d3dx9_sprite *object;
     D3DCAPS9 caps;
 
-    TRACE("(%p, %p)\n", device, sprite);
+    TRACE("device %p, sprite %p.\n", device, sprite);
 
     if(device==NULL || sprite==NULL) return D3DERR_INVALIDCALL;
 
-    object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXSpriteImpl));
-    if(object==NULL) {
-        *sprite=NULL;
+    if (!(object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    {
+        *sprite = NULL;
         return E_OUTOFMEMORY;
     }
-    object->ID3DXSprite_iface.lpVtbl = &D3DXSprite_Vtbl;
+    object->ID3DXSprite_iface.lpVtbl = &d3dx9_sprite_vtbl;
     object->ref=1;
     object->device=device;
     IUnknown_AddRef(device);
index bd141c1..29914c5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009-2010 Tony Wasserka
- * Copyright (C) 2012 Jأ³zef Kucia
+ * Copyright (C) 2012 Józef Kucia
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -149,7 +149,13 @@ static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
         MAKEFOURCC('D','X','T','2'),
         MAKEFOURCC('D','X','T','3'),
         MAKEFOURCC('D','X','T','4'),
-        MAKEFOURCC('D','X','T','5')
+        MAKEFOURCC('D','X','T','5'),
+        D3DFMT_R16F,
+        D3DFMT_G16R16F,
+        D3DFMT_A16B16G16R16F,
+        D3DFMT_R32F,
+        D3DFMT_G32R32F,
+        D3DFMT_A32B32G32R32F,
     };
 
     for (i = 0; i < sizeof(known_fourcc) / sizeof(known_fourcc[0]); i++)
@@ -255,6 +261,11 @@ static D3DFORMAT dds_bump_to_d3dformat(const struct dds_pixel_format *pixel_form
 
 static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format)
 {
+    TRACE("pixel_format: size %u, flags %#x, fourcc %#x, bpp %u.\n", pixel_format->size,
+            pixel_format->flags, pixel_format->fourcc, pixel_format->bpp);
+    TRACE("rmask %#x, gmask %#x, bmask %#x, amask %#x.\n", pixel_format->rmask, pixel_format->gmask,
+            pixel_format->bmask, pixel_format->amask);
+
     if (pixel_format->flags & DDS_PF_FOURCC)
         return dds_fourcc_to_d3dformat(pixel_format->fourcc);
     if (pixel_format->flags & DDS_PF_RGB)
@@ -524,8 +535,8 @@ HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *d
 }
 
 HRESULT load_texture_from_dds(IDirect3DTexture9 *texture, const void *src_data, const PALETTEENTRY *palette,
-    DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info)
-
+        DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info, unsigned int skip_levels,
+        unsigned int *loaded_miplevels)
 {
     HRESULT hr;
     RECT src_rect;
@@ -538,31 +549,45 @@ HRESULT load_texture_from_dds(IDirect3DTexture9 *texture, const void *src_data,
     const struct dds_header *header = src_data;
     const BYTE *pixels = (BYTE *)(header + 1);
 
-    /* Loading a cube texture as a simple texture is also supported (only first face texture is taken) */
-    if ((src_info->ResourceType != D3DRTYPE_TEXTURE) && (src_info->ResourceType != D3DRTYPE_CUBETEXTURE))
+    /* Loading a cube texture as a simple texture is also supported
+     * (only first face texture is taken). Same with volume textures. */
+    if ((src_info->ResourceType != D3DRTYPE_TEXTURE)
+            && (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
+            && (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE))
+    {
+        WARN("Trying to load a %u resource as a 2D texture, returning failure.\n", src_info->ResourceType);
         return D3DXERR_INVALIDDATA;
+    }
 
     width = src_info->Width;
     height = src_info->Height;
     mip_levels = min(src_info->MipLevels, IDirect3DTexture9_GetLevelCount(texture));
-    for (mip_level = 0; mip_level < mip_levels; mip_level++)
+    if (src_info->ResourceType == D3DRTYPE_VOLUMETEXTURE)
+        mip_levels = 1;
+    for (mip_level = 0; mip_level < mip_levels + skip_levels; ++mip_level)
     {
         hr = calculate_dds_surface_size(src_info->Format, width, height, &src_pitch, &mip_level_size);
         if (FAILED(hr)) return hr;
 
-        SetRect(&src_rect, 0, 0, width, height);
+        if (mip_level >= skip_levels)
+        {
+            SetRect(&src_rect, 0, 0, width, height);
 
-        IDirect3DTexture9_GetSurfaceLevel(texture, mip_level, &surface);
-        hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
-            NULL, &src_rect, filter, color_key);
-        IDirect3DSurface9_Release(surface);
-        if (FAILED(hr)) return hr;
+            IDirect3DTexture9_GetSurfaceLevel(texture, mip_level - skip_levels, &surface);
+            hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
+                    NULL, &src_rect, filter, color_key);
+            IDirect3DSurface9_Release(surface);
+            if (FAILED(hr))
+                return hr;
+        }
 
         pixels += mip_level_size;
         width = max(1, width / 2);
         height = max(1, height / 2);
     }
 
+    *loaded_miplevels = mip_levels - skip_levels;
+
     return D3D_OK;
 }
 
@@ -895,13 +920,13 @@ HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize,
  *            D3DERR_INVALIDCALL, if file is NULL
  *
  */
-HRESULT WINAPI D3DXGetImageInfoFromFileA(LPCSTR file, D3DXIMAGE_INFO *info)
+HRESULT WINAPI D3DXGetImageInfoFromFileA(const char *file, D3DXIMAGE_INFO *info)
 {
-    LPWSTR widename;
+    WCHAR *widename;
     HRESULT hr;
     int strlength;
 
-    TRACE("(%s, %p): relay\n", debugstr_a(file), info);
+    TRACE("file %s, info %p.\n", debugstr_a(file), info);
 
     if( !file ) return D3DERR_INVALIDCALL;
 
@@ -1010,7 +1035,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(IDirect3DSurface9 *pDestSurface,
         const RECT *pSrcRect, DWORD dwFilter, D3DCOLOR Colorkey, D3DXIMAGE_INFO *pSrcInfo)
 {
     D3DXIMAGE_INFO imginfo;
-    HRESULT hr;
+    HRESULT hr, com_init;
 
     IWICImagingFactory *factory = NULL;
     IWICBitmapDecoder *decoder;
@@ -1063,7 +1088,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(IDirect3DSurface9 *pDestSurface,
     if (imginfo.ImageFileFormat == D3DXIFF_DIB)
         convert_dib_to_bmp((void**)&pSrcData, &SrcDataSize);
 
-    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+    com_init = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
 
     if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory)))
         goto cleanup_err;
@@ -1166,7 +1191,8 @@ cleanup_err:
     if (factory)
         IWICImagingFactory_Release(factory);
 
-    CoUninitialize();
+    if (SUCCEEDED(com_init))
+        CoUninitialize();
 
     if (imginfo.ImageFileFormat == D3DXIFF_DIB)
         HeapFree(GetProcessHeap(), 0, (void*)pSrcData);
@@ -1184,7 +1210,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileA(IDirect3DSurface9 *dst_surface,
         const PALETTEENTRY *dst_palette, const RECT *dst_rect, const char *src_file,
         const RECT *src_rect, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info)
 {
-    LPWSTR pWidename;
+    WCHAR *src_file_w;
     HRESULT hr;
     int strlength;
 
@@ -1197,12 +1223,12 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileA(IDirect3DSurface9 *dst_surface,
         return D3DERR_INVALIDCALL;
 
     strlength = MultiByteToWideChar(CP_ACP, 0, src_file, -1, NULL, 0);
-    pWidename = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*pWidename));
-    MultiByteToWideChar(CP_ACP, 0, src_file, -1, pWidename, strlength);
+    src_file_w = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*src_file_w));
+    MultiByteToWideChar(CP_ACP, 0, src_file, -1, src_file_w, strlength);
 
     hr = D3DXLoadSurfaceFromFileW(dst_surface, dst_palette, dst_rect,
-            pWidename, src_rect, filter, color_key, src_info);
-    HeapFree(GetProcessHeap(), 0, pWidename);
+            src_file_w, src_rect, filter, color_key, src_info);
+    HeapFree(GetProcessHeap(), 0, src_file_w);
 
     return hr;
 }
@@ -1330,40 +1356,13 @@ static void init_argb_conversion_info(const struct pixel_format_desc *srcformat,
     }
 }
 
-static DWORD dword_from_bytes(CONST BYTE *src, UINT bytes_per_pixel)
-{
-    DWORD ret = 0;
-    static BOOL fixme_once;
-
-    if(bytes_per_pixel > sizeof(DWORD)) {
-        if(!fixme_once++) FIXME("Unsupported image: %u bytes per pixel\n", bytes_per_pixel);
-        bytes_per_pixel = sizeof(DWORD);
-    }
-
-    memcpy(&ret, src, bytes_per_pixel);
-    return ret;
-}
-
-static void dword_to_bytes(BYTE *dst, DWORD dword, UINT bytes_per_pixel)
-{
-    static BOOL fixme_once;
-
-    if(bytes_per_pixel > sizeof(DWORD)) {
-        if(!fixme_once++) FIXME("Unsupported image: %u bytes per pixel\n", bytes_per_pixel);
-        ZeroMemory(dst, bytes_per_pixel);
-        bytes_per_pixel = sizeof(DWORD);
-    }
-
-    memcpy(dst, &dword, bytes_per_pixel);
-}
-
 /************************************************************
  * get_relevant_argb_components
  *
  * Extracts the relevant components from the source color and
  * drops the less significant bits if they aren't used by the destination format.
  */
-static void get_relevant_argb_components(CONST struct argb_conversion_info *info, CONST DWORD col, DWORD *out)
+static void get_relevant_argb_components(const struct argb_conversion_info *info, DWORD col, DWORD *out)
 {
     UINT i = 0;
     for(;i < 4;i++)
@@ -1377,7 +1376,7 @@ static void get_relevant_argb_components(CONST struct argb_conversion_info *info
  * Recombines the output of get_relevant_argb_components and converts
  * it to the destination format.
  */
-static DWORD make_argb_color(CONST struct argb_conversion_info *info, CONST DWORD *in)
+static DWORD make_argb_color(const struct argb_conversion_info *info, const DWORD *in)
 {
     UINT i;
     DWORD val = 0;
@@ -1394,55 +1393,78 @@ static DWORD make_argb_color(CONST struct argb_conversion_info *info, CONST DWOR
     return val;
 }
 
-static void format_to_vec4(const struct pixel_format_desc *format, const DWORD *src, struct vec4 *dst)
+/* It doesn't work for components bigger than 32 bits (or somewhat smaller but unaligned). */
+static void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst)
 {
-    DWORD mask;
+    DWORD mask, tmp;
+    unsigned int c;
 
-    if (format->bits[1])
+    for (c = 0; c < 4; ++c)
     {
-        mask = (1 << format->bits[1]) - 1;
-        dst->x = (float)((*src >> format->shift[1]) & mask) / mask;
-    }
-    else
-        dst->x = 1.0f;
+        static const unsigned int component_offsets[4] = {3, 0, 1, 2};
+        float *dst_component = (float *)dst + component_offsets[c];
 
-    if (format->bits[2])
-    {
-        mask = (1 << format->bits[2]) - 1;
-        dst->y = (float)((*src >> format->shift[2]) & mask) / mask;
-    }
-    else
-        dst->y = 1.0f;
+        if (format->bits[c])
+        {
+            mask = ~0u >> (32 - format->bits[c]);
 
-    if (format->bits[3])
-    {
-        mask = (1 << format->bits[3]) - 1;
-        dst->z = (float)((*src >> format->shift[3]) & mask) / mask;
-    }
-    else
-        dst->z = 1.0f;
+            memcpy(&tmp, src + format->shift[c] / 8,
+                    min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8));
 
-    if (format->bits[0])
-    {
-        mask = (1 << format->bits[0]) - 1;
-        dst->w = (float)((*src >> format->shift[0]) & mask) / mask;
+            if (format->type == FORMAT_ARGBF16)
+                *dst_component = float_16_to_32(tmp);
+            else if (format->type == FORMAT_ARGBF)
+                *dst_component = *(float *)&tmp;
+            else
+                *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask;
+        }
+        else
+            *dst_component = 1.0f;
     }
-    else
-        dst->w = 1.0f;
 }
 
-static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, DWORD *dst)
+/* It doesn't work for components bigger than 32 bits. */
+static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst)
 {
-    *dst = 0;
-
-    if (format->bits[1])
-        *dst |= (DWORD)(src->x * ((1 << format->bits[1]) - 1) + 0.5f) << format->shift[1];
-    if (format->bits[2])
-        *dst |= (DWORD)(src->y * ((1 << format->bits[2]) - 1) + 0.5f) << format->shift[2];
-    if (format->bits[3])
-        *dst |= (DWORD)(src->z * ((1 << format->bits[3]) - 1) + 0.5f) << format->shift[3];
-    if (format->bits[0])
-        *dst |= (DWORD)(src->w * ((1 << format->bits[0]) - 1) + 0.5f) << format->shift[0];
+    DWORD v, mask32;
+    unsigned int c, i;
+
+    memset(dst, 0, format->bytes_per_pixel);
+
+    for (c = 0; c < 4; ++c)
+    {
+        static const unsigned int component_offsets[4] = {3, 0, 1, 2};
+        const float src_component = *((const float *)src + component_offsets[c]);
+
+        if (!format->bits[c])
+            continue;
+
+        mask32 = ~0u >> (32 - format->bits[c]);
+
+        if (format->type == FORMAT_ARGBF16)
+            v = float_32_to_16(src_component);
+        else if (format->type == FORMAT_ARGBF)
+            v = *(DWORD *)&src_component;
+        else
+            v = (DWORD)(src_component * ((1 << format->bits[c]) - 1) + 0.5f);
+
+        for (i = format->shift[c] / 8 * 8; i < format->shift[c] + format->bits[c]; i += 8)
+        {
+            BYTE mask, byte;
+
+            if (format->shift[c] > i)
+            {
+                mask = mask32 << (format->shift[c] - i);
+                byte = (v << (format->shift[c] - i)) & mask;
+            }
+            else
+            {
+                mask = mask32 >> (i - format->shift[c]);
+                byte = (v >> (i - format->shift[c])) & mask;
+            }
+            dst[i / 8] |= byte;
+        }
+    }
 }
 
 /************************************************************
@@ -1491,7 +1513,7 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit
 {
     struct argb_conversion_info conv_info, ck_conv_info;
     const struct pixel_format_desc *ck_format = NULL;
-    DWORD channels[4], pixel;
+    DWORD channels[4];
     UINT min_width, min_height, min_depth;
     UINT x, y, z;
 
@@ -1516,30 +1538,32 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit
         for (y = 0; y < min_height; y++) {
             const BYTE *src_ptr = src_slice_ptr + y * src_row_pitch;
             BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
-            DWORD val;
 
             for (x = 0; x < min_width; x++) {
-                /* extract source color components */
-                pixel = dword_from_bytes(src_ptr, src_format->bytes_per_pixel);
-
-                if (!src_format->to_rgba && !dst_format->from_rgba)
+                if (!src_format->to_rgba && !dst_format->from_rgba
+                        && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
                 {
-                    get_relevant_argb_components(&conv_info, pixel, channels);
+                    DWORD val;
+
+                    get_relevant_argb_components(&conv_info, *(DWORD *)src_ptr, channels);
                     val = make_argb_color(&conv_info, channels);
 
                     if (color_key)
                     {
-                        get_relevant_argb_components(&ck_conv_info, pixel, channels);
-                        pixel = make_argb_color(&ck_conv_info, channels);
-                        if (pixel == color_key)
+                        DWORD ck_pixel;
+
+                        get_relevant_argb_components(&ck_conv_info, *(DWORD *)src_ptr, channels);
+                        ck_pixel = make_argb_color(&ck_conv_info, channels);
+                        if (ck_pixel == color_key)
                             val &= ~conv_info.destmask[0];
                     }
+                    memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
                 }
                 else
                 {
                     struct vec4 color, tmp;
 
-                    format_to_vec4(src_format, &pixel, &color);
+                    format_to_vec4(src_format, src_ptr, &color);
                     if (src_format->to_rgba)
                         src_format->to_rgba(&color, &tmp, palette);
                     else
@@ -1547,8 +1571,10 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit
 
                     if (ck_format)
                     {
-                        format_from_vec4(ck_format, &tmp, &pixel);
-                        if (pixel == color_key)
+                        DWORD ck_pixel;
+
+                        format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
+                        if (ck_pixel == color_key)
                             tmp.w = 0.0f;
                     }
 
@@ -1557,11 +1583,10 @@ void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pit
                     else
                         color = tmp;
 
-                    format_from_vec4(dst_format, &color, &val);
+                    format_from_vec4(dst_format, &color, dst_ptr);
                 }
 
-                dword_to_bytes(dst_ptr, val, dst_format->bytes_per_pixel);
-                src_ptr  +=  src_format->bytes_per_pixel;
+                src_ptr += src_format->bytes_per_pixel;
                 dst_ptr += dst_format->bytes_per_pixel;
             }
 
@@ -1591,7 +1616,7 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic
 {
     struct argb_conversion_info conv_info, ck_conv_info;
     const struct pixel_format_desc *ck_format = NULL;
-    DWORD channels[4], pixel;
+    DWORD channels[4];
     UINT x, y, z;
 
     ZeroMemory(channels, sizeof(channels));
@@ -1617,29 +1642,31 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic
             for (x = 0; x < dst_size->width; x++)
             {
                 const BYTE *src_ptr = src_row_ptr + (x * src_size->width / dst_size->width) * src_format->bytes_per_pixel;
-                DWORD val;
-
-                /* extract source color components */
-                pixel = dword_from_bytes(src_ptr, src_format->bytes_per_pixel);
 
-                if (!src_format->to_rgba && !dst_format->from_rgba)
+                if (!src_format->to_rgba && !dst_format->from_rgba
+                        && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
                 {
-                    get_relevant_argb_components(&conv_info, pixel, channels);
+                    DWORD val;
+
+                    get_relevant_argb_components(&conv_info, *(DWORD *)src_ptr, channels);
                     val = make_argb_color(&conv_info, channels);
 
                     if (color_key)
                     {
-                        get_relevant_argb_components(&ck_conv_info, pixel, channels);
-                        pixel = make_argb_color(&ck_conv_info, channels);
-                        if (pixel == color_key)
+                        DWORD ck_pixel;
+
+                        get_relevant_argb_components(&ck_conv_info, *(DWORD *)src_ptr, channels);
+                        ck_pixel = make_argb_color(&ck_conv_info, channels);
+                        if (ck_pixel == color_key)
                             val &= ~conv_info.destmask[0];
                     }
+                    memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
                 }
                 else
                 {
                     struct vec4 color, tmp;
 
-                    format_to_vec4(src_format, &pixel, &color);
+                    format_to_vec4(src_format, src_ptr, &color);
                     if (src_format->to_rgba)
                         src_format->to_rgba(&color, &tmp, palette);
                     else
@@ -1647,8 +1674,10 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic
 
                     if (ck_format)
                     {
-                        format_from_vec4(ck_format, &tmp, &pixel);
-                        if (pixel == color_key)
+                        DWORD ck_pixel;
+
+                        format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
+                        if (ck_pixel == color_key)
                             tmp.w = 0.0f;
                     }
 
@@ -1657,10 +1686,9 @@ void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slic
                     else
                         color = tmp;
 
-                    format_from_vec4(dst_format, &color, &val);
+                    format_from_vec4(dst_format, &color, dst_ptr);
                 }
 
-                dword_to_bytes(dst_ptr, val, dst_format->bytes_per_pixel);
                 dst_ptr += dst_format->bytes_per_pixel;
             }
         }
index bc3daf6..5ed137e 100644 (file)
@@ -191,6 +191,7 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN
     D3DDISPLAYMODE mode;
     HRESULT hr;
     D3DFORMAT usedformat = D3DFMT_UNKNOWN;
+    const struct pixel_format_desc *fmt;
 
     TRACE("(%p, %p, %p, %p, %u, %p, %u)\n", device, width, height, miplevels, usage, format, pool);
 
@@ -207,73 +208,6 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN
     if ((pool != D3DPOOL_DEFAULT) && (pool != D3DPOOL_MANAGED) && (pool != D3DPOOL_SYSTEMMEM) && (pool != D3DPOOL_SCRATCH))
         return D3DERR_INVALIDCALL;
 
-    /* width and height */
-    if (FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
-        return D3DERR_INVALIDCALL;
-
-    /* 256 x 256 default width/height */
-    if ((w == D3DX_DEFAULT) && (h == D3DX_DEFAULT))
-        w = h = 256;
-    else if (w == D3DX_DEFAULT)
-        w = (height ? h : 256);
-    else if (h == D3DX_DEFAULT)
-        h = (width ? w : 256);
-
-    /* ensure width/height is power of 2 */
-    if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(w)))
-        w = make_pow2(w);
-
-    if (w > caps.MaxTextureWidth)
-        w = caps.MaxTextureWidth;
-
-    if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(h)))
-        h = make_pow2(h);
-
-    if (h > caps.MaxTextureHeight)
-        h = caps.MaxTextureHeight;
-
-    /* texture must be square? */
-    if (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
-    {
-        if (w > h)
-            h = w;
-        else
-            w = h;
-    }
-
-    if (width)
-        *width = w;
-
-    if (height)
-        *height = h;
-
-    /* miplevels */
-    if (miplevels && (usage & D3DUSAGE_AUTOGENMIPMAP))
-    {
-        if (*miplevels > 1)
-            *miplevels = 0;
-    }
-    else if (miplevels)
-    {
-        UINT max_mipmaps = 1;
-
-        if (!width && !height)
-            max_mipmaps = 9;    /* number of mipmaps in a 256x256 texture */
-        else
-        {
-            UINT max_dimen = max(w, h);
-
-            while (max_dimen > 1)
-            {
-                max_dimen >>= 1;
-                max_mipmaps++;
-            }
-        }
-
-        if (*miplevels == 0 || *miplevels > max_mipmaps)
-            *miplevels = max_mipmaps;
-    }
-
     /* format */
     if (format)
     {
@@ -299,17 +233,18 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN
     if ((usedformat == D3DFMT_UNKNOWN) || (usedformat == D3DX_DEFAULT))
         usedformat = D3DFMT_A8R8G8B8;
 
+    fmt = get_format_info(usedformat);
+
     hr = IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType, mode.Format,
         usage, D3DRTYPE_TEXTURE, usedformat);
-
     if (FAILED(hr))
     {
-        /* Heuristic to choose the fallback format */
-        const struct pixel_format_desc *fmt = get_format_info(usedformat);
         BOOL allow_24bits;
         int bestscore = INT_MIN, i = 0, j;
         unsigned int channels;
-        const struct pixel_format_desc *curfmt;
+        const struct pixel_format_desc *curfmt, *bestfmt = NULL;
+
+        TRACE("Requested format not supported, looking for a fallback.\n");
 
         if (!fmt)
         {
@@ -354,11 +289,83 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN
             {
                 bestscore = score;
                 usedformat = curfmt->format;
+                bestfmt = curfmt;
             }
         }
+        fmt = bestfmt;
         hr = D3D_OK;
     }
 
+    if (FAILED(IDirect3DDevice9_GetDeviceCaps(device, &caps)))
+        return D3DERR_INVALIDCALL;
+
+    if ((w == D3DX_DEFAULT) && (h == D3DX_DEFAULT))
+        w = h = 256;
+    else if (w == D3DX_DEFAULT)
+        w = (height ? h : 256);
+    else if (h == D3DX_DEFAULT)
+        h = (width ? w : 256);
+
+    if (fmt->block_width != 1 || fmt->block_height != 1)
+    {
+        if (w < fmt->block_width)
+            w = fmt->block_width;
+        if (h < fmt->block_height)
+            h = fmt->block_height;
+    }
+
+    if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(w)))
+        w = make_pow2(w);
+
+    if (w > caps.MaxTextureWidth)
+        w = caps.MaxTextureWidth;
+
+    if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(h)))
+        h = make_pow2(h);
+
+    if (h > caps.MaxTextureHeight)
+        h = caps.MaxTextureHeight;
+
+    if (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
+    {
+        if (w > h)
+            h = w;
+        else
+            w = h;
+    }
+
+    if (width)
+        *width = w;
+
+    if (height)
+        *height = h;
+
+    if (miplevels && (usage & D3DUSAGE_AUTOGENMIPMAP))
+    {
+        if (*miplevels > 1)
+            *miplevels = 0;
+    }
+    else if (miplevels)
+    {
+        UINT max_mipmaps = 1;
+
+        if (!width && !height)
+            max_mipmaps = 9;    /* number of mipmaps in a 256x256 texture */
+        else
+        {
+            UINT max_dimen = max(w, h);
+
+            while (max_dimen > 1)
+            {
+                max_dimen >>= 1;
+                max_mipmaps++;
+            }
+        }
+
+        if (*miplevels == 0 || *miplevels > max_mipmaps)
+            *miplevels = max_mipmaps;
+    }
+
 cleanup:
 
     if (d3d)
@@ -518,21 +525,24 @@ HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *devi
     BOOL file_format = FALSE, file_miplevels = FALSE;
     BOOL dynamic_texture;
     D3DXIMAGE_INFO imginfo;
-    UINT loaded_miplevels;
+    UINT loaded_miplevels, skip_levels;
     D3DCAPS9 caps;
     HRESULT hr;
 
-    TRACE("(%p, %p, %u, %u, %u, %u, %x, %x, %x, %u, %u, %x, %p, %p, %p)\n", device, srcdata, srcdatasize, width,
-        height, miplevels, usage, format, pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
+    TRACE("device %p, srcdata %p, srcdatasize %u, width %u, height %u, miplevels %u,"
+            " usage %#x, format %#x, pool %#x, filter %#x, mipfilter %#x, colorkey %#x,"
+            " srcinfo %p, palette %p, texture %p.\n",
+            device, srcdata, srcdatasize, width, height, miplevels, usage, format, pool,
+            filter, mipfilter, colorkey, srcinfo, palette, texture);
 
     /* check for invalid parameters */
     if (!device || !texture || !srcdata || !srcdatasize)
         return D3DERR_INVALIDCALL;
 
     hr = D3DXGetImageInfoFromFileInMemory(srcdata, srcdatasize, &imginfo);
-
     if (FAILED(hr))
     {
+        FIXME("Unrecognized file format, returning failure.\n");
         *texture = NULL;
         return hr;
     }
@@ -577,11 +587,26 @@ HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *devi
         miplevels = imginfo.MipLevels;
     }
 
+    skip_levels = mipfilter != D3DX_DEFAULT ? mipfilter >> D3DX_SKIP_DDS_MIP_LEVELS_SHIFT : 0;
+    if (skip_levels && imginfo.MipLevels > skip_levels)
+    {
+        TRACE("Skipping the first %u (of %u) levels of a DDS mipmapped texture.\n",
+                skip_levels, imginfo.MipLevels);
+        TRACE("Texture level 0 dimensions are %ux%u.\n", imginfo.Width, imginfo.Height);
+        width >>= skip_levels;
+        height >>= skip_levels;
+        miplevels -= skip_levels;
+    }
+    else
+    {
+        skip_levels = 0;
+    }
+
     /* fix texture creation parameters */
     hr = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, usage, &format, pool);
-
     if (FAILED(hr))
     {
+        FIXME("Couldn't find suitable texture parameters.\n");
         *texture = NULL;
         return hr;
     }
@@ -591,6 +616,12 @@ HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *devi
         FIXME("Generation of mipmaps for compressed pixel formats is not implemented yet\n");
         miplevels = imginfo.MipLevels;
     }
+    if (imginfo.ResourceType == D3DRTYPE_VOLUMETEXTURE
+            && D3DFMT_DXT1 <= imginfo.Format && imginfo.Format <= D3DFMT_DXT5 && miplevels > 1)
+    {
+        FIXME("Generation of mipmaps for compressed pixel formats is not implemented yet.\n");
+        miplevels = 1;
+    }
 
     if (((file_width) && (width != imginfo.Width))    ||
         ((file_height) && (height != imginfo.Height)) ||
@@ -618,34 +649,37 @@ HRESULT WINAPI D3DXCreateTextureFromFileInMemoryEx(struct IDirect3DDevice9 *devi
 
     if (FAILED(hr))
     {
+        FIXME("Texture creation failed.\n");
         *texture = NULL;
         return hr;
     }
 
-    /* Load the file */
+    TRACE("Texture created correctly. Now loading the texture data into it.\n");
     if (imginfo.ImageFileFormat != D3DXIFF_DDS)
     {
         IDirect3DTexture9_GetSurfaceLevel(*texptr, 0, &surface);
         hr = D3DXLoadSurfaceFromFileInMemory(surface, palette, NULL, srcdata, srcdatasize, NULL, filter, colorkey, NULL);
         IDirect3DSurface9_Release(surface);
+        loaded_miplevels = min(IDirect3DTexture9_GetLevelCount(*texptr), imginfo.MipLevels);
     }
     else
     {
-        hr = load_texture_from_dds(*texptr, srcdata, palette, filter, colorkey, &imginfo);
+        hr = load_texture_from_dds(*texptr, srcdata, palette, filter, colorkey, &imginfo, skip_levels,
+                &loaded_miplevels);
     }
 
     if (FAILED(hr))
     {
+        FIXME("Texture loading failed.\n");
         IDirect3DTexture9_Release(*texptr);
         *texture = NULL;
         return hr;
     }
 
-    loaded_miplevels = min(IDirect3DTexture9_GetLevelCount(*texptr), imginfo.MipLevels);
     hr = D3DXFilterTexture((IDirect3DBaseTexture9*) *texptr, palette, loaded_miplevels - 1, mipfilter);
-
     if (FAILED(hr))
     {
+        FIXME("Texture filtering failed.\n");
         IDirect3DTexture9_Release(*texptr);
         *texture = NULL;
         return hr;
@@ -687,13 +721,14 @@ HRESULT WINAPI D3DXCreateTextureFromFileExW(struct IDirect3DDevice9 *device, con
         D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
         PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
 {
+    void *buffer;
     HRESULT hr;
     DWORD size;
-    LPVOID buffer;
 
-    TRACE("(%p, %s, %u, %u, %u, %x, %x, %x, %u, %u, %x, %p, %p, %p): relay\n",
-            device, debugstr_w(srcfile), width, height, miplevels, usage, format, pool, filter,
-            mipfilter, colorkey, srcinfo, palette, texture);
+    TRACE("device %p, srcfile %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
+            "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
+            device, debugstr_w(srcfile), width, height, miplevels, usage, format,
+            pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
 
     if (!srcfile)
         return D3DERR_INVALIDCALL;
@@ -715,13 +750,14 @@ HRESULT WINAPI D3DXCreateTextureFromFileExA(struct IDirect3DDevice9 *device, con
         D3DPOOL pool, DWORD filter, DWORD mipfilter, D3DCOLOR colorkey, D3DXIMAGE_INFO *srcinfo,
         PALETTEENTRY *palette, struct IDirect3DTexture9 **texture)
 {
-    LPWSTR widename;
+    WCHAR *widename;
     HRESULT hr;
     DWORD len;
 
-    TRACE("(%p, %s, %u, %u, %u, %x, %x, %x, %u, %u, %x, %p, %p, %p): relay\n",
-            device, debugstr_a(srcfile), width, height, miplevels, usage, format, pool, filter,
-            mipfilter, colorkey, srcinfo, palette, texture);
+    TRACE("device %p, srcfile %s, width %u, height %u, miplevels %u, usage %#x, format %#x, "
+            "pool %#x, filter %#x, mipfilter %#x, colorkey 0x%08x, srcinfo %p, palette %p, texture %p.\n",
+            device, debugstr_a(srcfile), width, height, miplevels, usage, format,
+            pool, filter, mipfilter, colorkey, srcinfo, palette, texture);
 
     if (!device || !srcfile || !texture)
         return D3DERR_INVALIDCALL;
index 783122a..a137418 100644 (file)
@@ -78,7 +78,11 @@ static const struct pixel_format_desc formats[] =
     {D3DFMT_DXT3,          { 0,  0,  0,  0}, { 0,  0,  0,  0},  1, 4, 4, 16, FORMAT_DXT,     NULL,         NULL      },
     {D3DFMT_DXT4,          { 0,  0,  0,  0}, { 0,  0,  0,  0},  1, 4, 4, 16, FORMAT_DXT,     NULL,         NULL      },
     {D3DFMT_DXT5,          { 0,  0,  0,  0}, { 0,  0,  0,  0},  1, 4, 4, 16, FORMAT_DXT,     NULL,         NULL      },
+    {D3DFMT_R16F,          { 0, 16,  0,  0}, { 0,  0,  0,  0},  2, 1, 1,  2, FORMAT_ARGBF16, NULL,         NULL      },
+    {D3DFMT_G16R16F,       { 0, 16, 16,  0}, { 0,  0, 16,  0},  4, 1, 1,  4, FORMAT_ARGBF16, NULL,         NULL      },
     {D3DFMT_A16B16G16R16F, {16, 16, 16, 16}, {48,  0, 16, 32},  8, 1, 1,  8, FORMAT_ARGBF16, NULL,         NULL      },
+    {D3DFMT_R32F,          { 0, 32,  0,  0}, { 0,  0,  0,  0},  4, 1, 1,  4, FORMAT_ARGBF,   NULL,         NULL      },
+    {D3DFMT_G32R32F,       { 0, 32, 32,  0}, { 0,  0, 32,  0},  8, 1, 1,  8, FORMAT_ARGBF,   NULL,         NULL      },
     {D3DFMT_A32B32G32R32F, {32, 32, 32, 32}, {96,  0, 32, 64}, 16, 1, 1, 16, FORMAT_ARGBF,   NULL,         NULL      },
     {D3DFMT_P8,            { 8,  8,  8,  8}, { 0,  0,  0,  0},  1, 1, 1,  1, FORMAT_INDEX,   NULL,         index_to_rgba},
     /* marks last element */
@@ -153,7 +157,7 @@ error:
  *   The memory doesn't need to be freed by the caller manually
  *
  */
-HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, LPVOID *buffer, DWORD *length)
+HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length)
 {
     HGLOBAL resource;
 
@@ -282,7 +286,7 @@ const char *debug_d3dxparameter_registerset(D3DXREGISTER_SET r)
 #undef WINE_D3DX_TO_STR
 
 /* parameter type conversion helpers */
-static BOOL get_bool(D3DXPARAMETER_TYPE type, LPCVOID data)
+static BOOL get_bool(D3DXPARAMETER_TYPE type, const void *data)
 {
     switch (type)
     {
@@ -300,12 +304,12 @@ static BOOL get_bool(D3DXPARAMETER_TYPE type, LPCVOID data)
     }
 }
 
-static INT get_int(D3DXPARAMETER_TYPE type, LPCVOID data)
+static INT get_int(D3DXPARAMETER_TYPE type, const void *data)
 {
     switch (type)
     {
         case D3DXPT_FLOAT:
-            return *(FLOAT *)data;
+            return (INT)(*(FLOAT *)data);
 
         case D3DXPT_INT:
         case D3DXPT_VOID:
@@ -320,7 +324,7 @@ static INT get_int(D3DXPARAMETER_TYPE type, LPCVOID data)
     }
 }
 
-static FLOAT get_float(D3DXPARAMETER_TYPE type, LPCVOID data)
+static FLOAT get_float(D3DXPARAMETER_TYPE type, const void *data)
 {
     switch (type)
     {
@@ -329,10 +333,10 @@ static FLOAT get_float(D3DXPARAMETER_TYPE type, LPCVOID data)
             return *(FLOAT *)data;
 
         case D3DXPT_INT:
-            return *(INT *)data;
+            return (FLOAT)(*(INT *)data);
 
         case D3DXPT_BOOL:
-            return get_bool(type, data);
+            return (FLOAT)get_bool(type, data);
 
         default:
             FIXME("Unhandled type %s.\n", debug_d3dxparameter_type(type));
@@ -340,10 +344,8 @@ static FLOAT get_float(D3DXPARAMETER_TYPE type, LPCVOID data)
     }
 }
 
-void set_number(LPVOID outdata, D3DXPARAMETER_TYPE outtype, LPCVOID indata, D3DXPARAMETER_TYPE intype)
+void set_number(void *outdata, D3DXPARAMETER_TYPE outtype, const void *indata, D3DXPARAMETER_TYPE intype)
 {
-    TRACE("Changing from type %s to type %s\n", debug_d3dxparameter_type(intype), debug_d3dxparameter_type(outtype));
-
     if (outtype == intype)
     {
         *(DWORD *)outdata = *(DWORD *)indata;
index 8ca195d..38c2942 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #define WINE_FILEDESCRIPTION_STR "Wine D3DX9"
-#define WINE_FILENAME_STR "d3dx9.dll"
+#define WINE_FILENAME_STR "d3dx9_36.dll"
 #define WINE_FILEVERSION 9,19,949,2111
 #define WINE_FILEVERSION_STR "9.19.949.2111"
 #define WINE_PRODUCTVERSION 9,19,949,2111
index d409e29..756f270 100644 (file)
@@ -235,6 +235,10 @@ HRESULT WINAPI D3DXLoadVolumeFromFileInMemory(IDirect3DVolume9 *dst_volume,
     D3DBOX box;
     D3DXIMAGE_INFO image_info;
 
+    TRACE("dst_volume %p, dst_palette %p, dst_box %p, src_data %p, src_data_size %u, src_box %p,\n",
+            dst_volume, dst_palette, dst_box, src_data, src_data_size, src_box);
+    TRACE("filter %#x, color_key %#x, src_info %p.\n", filter, color_key, src_info);
+
     if (!dst_volume || !src_data) return D3DERR_INVALIDCALL;
 
     hr = D3DXGetImageInfoFromFileInMemory(src_data, src_data_size, &image_info);
index 956f510..7cc0ba8 100644 (file)
@@ -43,119 +43,119 @@ static HRESULT error_dxfile_to_d3dxfile(HRESULT error)
     }
 }
 
-typedef struct {
+struct d3dx9_file
+{
     ID3DXFile ID3DXFile_iface;
     LONG ref;
     IDirectXFile *dxfile;
-} ID3DXFileImpl;
+};
 
-typedef struct {
+struct d3dx9_file_enum_object
+{
     ID3DXFileEnumObject ID3DXFileEnumObject_iface;
     LONG ref;
     ULONG nb_children;
     ID3DXFileData **children;
-} ID3DXFileEnumObjectImpl;
+};
 
-typedef struct {
+struct d3dx9_file_data
+{
     ID3DXFileData ID3DXFileData_iface;
     LONG ref;
     BOOL reference;
     IDirectXFileData *dxfile_data;
     ULONG nb_children;
     ID3DXFileData **children;
-} ID3DXFileDataImpl;
-
+};
 
-static inline ID3DXFileImpl* impl_from_ID3DXFile(ID3DXFile *iface)
+static inline struct d3dx9_file *impl_from_ID3DXFile(ID3DXFile *iface)
 {
-    return CONTAINING_RECORD(iface, ID3DXFileImpl, ID3DXFile_iface);
+    return CONTAINING_RECORD(iface, struct d3dx9_file, ID3DXFile_iface);
 }
 
-static inline ID3DXFileEnumObjectImpl* impl_from_ID3DXFileEnumObject(ID3DXFileEnumObject *iface)
+static inline struct d3dx9_file_enum_object *impl_from_ID3DXFileEnumObject(ID3DXFileEnumObject *iface)
 {
-    return CONTAINING_RECORD(iface, ID3DXFileEnumObjectImpl, ID3DXFileEnumObject_iface);
+    return CONTAINING_RECORD(iface, struct d3dx9_file_enum_object, ID3DXFileEnumObject_iface);
 }
 
-static inline ID3DXFileDataImpl* impl_from_ID3DXFileData(ID3DXFileData *iface)
+static inline struct d3dx9_file_data *impl_from_ID3DXFileData(ID3DXFileData *iface)
 {
-    return CONTAINING_RECORD(iface, ID3DXFileDataImpl, ID3DXFileData_iface);
+    return CONTAINING_RECORD(iface, struct d3dx9_file_data, ID3DXFileData_iface);
 }
 
-/*** IUnknown methods ***/
-
-static HRESULT WINAPI ID3DXFileDataImpl_QueryInterface(ID3DXFileData *iface, REFIID riid, void **ret_iface)
+static HRESULT WINAPI d3dx9_file_data_QueryInterface(ID3DXFileData *iface, REFIID riid, void **out)
 {
-    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
+    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
 
-    if (IsEqualGUID(riid, &IID_IUnknown) ||
-        IsEqualGUID(riid, &IID_ID3DXFileData))
+    if (IsEqualGUID(riid, &IID_ID3DXFileData)
+            || IsEqualGUID(riid, &IID_IUnknown))
     {
         iface->lpVtbl->AddRef(iface);
-        *ret_iface = iface;
+        *out = iface;
         return S_OK;
     }
 
-    WARN("(%p)->(%s, %p), not found\n", iface, debugstr_guid(riid), ret_iface);
-    *ret_iface = NULL;
+    WARN("Interface %s not found.\n", debugstr_guid(riid));
+
+    *out = NULL;
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI ID3DXFileDataImpl_AddRef(ID3DXFileData *iface)
+static ULONG WINAPI d3dx9_file_data_AddRef(ID3DXFileData *iface)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
-    ULONG ref = InterlockedIncrement(&This->ref);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
+    ULONG refcount = InterlockedIncrement(&file_data->ref);
 
-    TRACE("(%p)->(): new ref = %u\n", iface, ref);
+    TRACE("%p increasing refcount to %u.\n", file_data, refcount);
 
-    return ref;
+    return refcount;
 }
 
-static ULONG WINAPI ID3DXFileDataImpl_Release(ID3DXFileData *iface)
+static ULONG WINAPI d3dx9_file_data_Release(ID3DXFileData *iface)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
-    ULONG ref = InterlockedDecrement(&This->ref);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
+    ULONG refcount = InterlockedDecrement(&file_data->ref);
 
-    TRACE("(%p)->(): new ref = %u\n", iface, ref);
+    TRACE("%p decreasing refcount to %u.\n", file_data, refcount);
 
-    if (!ref)
+    if (!refcount)
     {
         ULONG i;
 
-        for (i = 0; i < This->nb_children; i++)
-            (This->children[i])->lpVtbl->Release(This->children[i]);
-        HeapFree(GetProcessHeap(), 0, This->children);
-        IDirectXFileData_Release(This->dxfile_data);
-        HeapFree(GetProcessHeap(), 0, This);
+        for (i = 0; i < file_data->nb_children; ++i)
+        {
+            ID3DXFileData *child = file_data->children[i];
+            child->lpVtbl->Release(child);
+        }
+        HeapFree(GetProcessHeap(), 0, file_data->children);
+        IDirectXFileData_Release(file_data->dxfile_data);
+        HeapFree(GetProcessHeap(), 0, file_data);
     }
 
-    return ref;
+    return refcount;
 }
 
-
-/*** ID3DXFileData methods ***/
-
-static HRESULT WINAPI ID3DXFileDataImpl_GetEnum(ID3DXFileData *iface, ID3DXFileEnumObject **enum_object)
+static HRESULT WINAPI d3dx9_file_data_GetEnum(ID3DXFileData *iface, ID3DXFileEnumObject **enum_object)
 {
-    FIXME("(%p)->(%p): stub\n", iface, enum_object);
+    FIXME("iface %p, enum_object %p stub!\n", iface, enum_object);
 
     return E_NOTIMPL;
 }
 
-
-static HRESULT WINAPI ID3DXFileDataImpl_GetName(ID3DXFileData *iface, char *name, SIZE_T *size)
+static HRESULT WINAPI d3dx9_file_data_GetName(ID3DXFileData *iface, char *name, SIZE_T *size)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
     DWORD dxfile_size;
     HRESULT ret;
 
-    TRACE("(%p)->(%p, %p)\n", iface, name, size);
+    TRACE("iface %p, name %p, size %p.\n", iface, name, size);
 
     if (!size)
         return D3DXFERR_BADVALUE;
 
     dxfile_size = *size;
 
-    ret = IDirectXFileData_GetName(This->dxfile_data, name, &dxfile_size);
+    ret = IDirectXFileData_GetName(file_data->dxfile_data, name, &dxfile_size);
     if (ret != DXFILE_OK)
         return error_dxfile_to_d3dxfile(ret);
 
@@ -173,37 +173,35 @@ static HRESULT WINAPI ID3DXFileDataImpl_GetName(ID3DXFileData *iface, char *name
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileDataImpl_GetId(ID3DXFileData *iface, GUID *guid)
+static HRESULT WINAPI d3dx9_file_data_GetId(ID3DXFileData *iface, GUID *guid)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
     HRESULT ret;
 
-    TRACE("(%p)->(%p)\n", iface, guid);
+    TRACE("iface %p, guid %p.\n", iface, guid);
 
     if (!guid)
         return E_POINTER;
 
-    ret = IDirectXFileData_GetId(This->dxfile_data, guid);
+    ret = IDirectXFileData_GetId(file_data->dxfile_data, guid);
     if (ret != DXFILE_OK)
         return error_dxfile_to_d3dxfile(ret);
 
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileDataImpl_Lock(ID3DXFileData *iface, SIZE_T *size, const void **data)
+static HRESULT WINAPI d3dx9_file_data_Lock(ID3DXFileData *iface, SIZE_T *size, const void **data)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
     DWORD dxfile_size;
     HRESULT ret;
 
-    TRACE("(%p)->(%p, %p)\n", iface, size, data);
+    TRACE("iface %p, size %p, data %p.\n", iface, size, data);
 
     if (!size || !data)
         return E_POINTER;
 
-    ret = IDirectXFileData_GetData(This->dxfile_data, NULL, &dxfile_size, (void**)data);
+    ret = IDirectXFileData_GetData(file_data->dxfile_data, NULL, &dxfile_size, (void **)data);
     if (ret != DXFILE_OK)
         return error_dxfile_to_d3dxfile(ret);
 
@@ -212,26 +210,24 @@ static HRESULT WINAPI ID3DXFileDataImpl_Lock(ID3DXFileData *iface, SIZE_T *size,
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileDataImpl_Unlock(ID3DXFileData *iface)
+static HRESULT WINAPI d3dx9_file_data_Unlock(ID3DXFileData *iface)
 {
-    TRACE("(%p)->()\n", iface);
+    TRACE("iface %p.\n", iface);
 
     /* Nothing to do */
 
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileDataImpl_GetType(ID3DXFileData *iface, GUID *guid)
+static HRESULT WINAPI d3dx9_file_data_GetType(ID3DXFileData *iface, GUID *guid)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
     const GUID *dxfile_guid;
     HRESULT ret;
 
-    TRACE("(%p)->(%p)\n", iface, guid);
+    TRACE("iface %p, guid %p.\n", iface, guid);
 
-    ret = IDirectXFileData_GetType(This->dxfile_data, &dxfile_guid);
+    ret = IDirectXFileData_GetType(file_data->dxfile_data, &dxfile_guid);
     if (ret != DXFILE_OK)
         return error_dxfile_to_d3dxfile(ret);
 
@@ -240,72 +236,67 @@ static HRESULT WINAPI ID3DXFileDataImpl_GetType(ID3DXFileData *iface, GUID *guid
     return S_OK;
 }
 
-
-static BOOL WINAPI ID3DXFileDataImpl_IsReference(ID3DXFileData *iface)
+static BOOL WINAPI d3dx9_file_data_IsReference(ID3DXFileData *iface)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
 
-    TRACE("(%p)->()\n", iface);
+    TRACE("iface %p.\n", iface);
 
-    return This->reference;
+    return file_data->reference;
 }
 
-
-static HRESULT WINAPI ID3DXFileDataImpl_GetChildren(ID3DXFileData *iface, SIZE_T *children)
+static HRESULT WINAPI d3dx9_file_data_GetChildren(ID3DXFileData *iface, SIZE_T *children)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
 
-    TRACE("(%p)->(%p)\n", iface, children);
+    TRACE("iface %p, children %p.\n", iface, children);
 
     if (!children)
         return E_POINTER;
 
-    *children = This->nb_children;
+    *children = file_data->nb_children;
 
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileDataImpl_GetChild(ID3DXFileData *iface, SIZE_T id, ID3DXFileData **object)
+static HRESULT WINAPI d3dx9_file_data_GetChild(ID3DXFileData *iface, SIZE_T id, ID3DXFileData **object)
 {
-    ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
+    struct d3dx9_file_data *file_data = impl_from_ID3DXFileData(iface);
 
-    TRACE("(%p)->(%lu, %p)\n", iface, id, object);
+    TRACE("iface %p, id %#lx, object %p.\n", iface, id, object);
 
     if (!object)
         return E_POINTER;
 
-    *object = This->children[id];
+    *object = file_data->children[id];
     (*object)->lpVtbl->AddRef(*object);
 
     return S_OK;
 }
 
-
-static const ID3DXFileDataVtbl ID3DXFileData_Vtbl =
-{
-    ID3DXFileDataImpl_QueryInterface,
-    ID3DXFileDataImpl_AddRef,
-    ID3DXFileDataImpl_Release,
-    ID3DXFileDataImpl_GetEnum,
-    ID3DXFileDataImpl_GetName,
-    ID3DXFileDataImpl_GetId,
-    ID3DXFileDataImpl_Lock,
-    ID3DXFileDataImpl_Unlock,
-    ID3DXFileDataImpl_GetType,
-    ID3DXFileDataImpl_IsReference,
-    ID3DXFileDataImpl_GetChildren,
-    ID3DXFileDataImpl_GetChild
+static const ID3DXFileDataVtbl d3dx9_file_data_vtbl =
+{
+    d3dx9_file_data_QueryInterface,
+    d3dx9_file_data_AddRef,
+    d3dx9_file_data_Release,
+    d3dx9_file_data_GetEnum,
+    d3dx9_file_data_GetName,
+    d3dx9_file_data_GetId,
+    d3dx9_file_data_Lock,
+    d3dx9_file_data_Unlock,
+    d3dx9_file_data_GetType,
+    d3dx9_file_data_IsReference,
+    d3dx9_file_data_GetChildren,
+    d3dx9_file_data_GetChild,
 };
 
-
-static HRESULT ID3DXFileDataImpl_Create(IDirectXFileObject *dxfile_object, ID3DXFileData **ret_iface)
+static HRESULT d3dx9_file_data_create(IDirectXFileObject *dxfile_object, ID3DXFileData **ret_iface)
 {
-    ID3DXFileDataImpl *object;
+    struct d3dx9_file_data *object;
     IDirectXFileObject *data_object;
     HRESULT ret;
 
-    TRACE("(%p, %p)\n", dxfile_object, ret_iface);
+    TRACE("dxfile_object %p, ret_iface %p.\n", dxfile_object, ret_iface);
 
     *ret_iface = NULL;
 
@@ -313,7 +304,7 @@ static HRESULT ID3DXFileDataImpl_Create(IDirectXFileObject *dxfile_object, ID3DX
     if (!object)
         return E_OUTOFMEMORY;
 
-    object->ID3DXFileData_iface.lpVtbl = &ID3DXFileData_Vtbl;
+    object->ID3DXFileData_iface.lpVtbl = &d3dx9_file_data_vtbl;
     object->ref = 1;
 
     ret = IDirectXFileObject_QueryInterface(dxfile_object, &IID_IDirectXFileData, (void **)&object->dxfile_data);
@@ -351,8 +342,7 @@ static HRESULT ID3DXFileDataImpl_Create(IDirectXFileObject *dxfile_object, ID3DX
             ret = E_OUTOFMEMORY;
             break;
         }
-        ret = ID3DXFileDataImpl_Create(data_object, &object->children[object->nb_children]);
-        if (ret != S_OK)
+        if (FAILED(ret = d3dx9_file_data_create(data_object, &object->children[object->nb_children])))
             break;
         object->nb_children++;
     }
@@ -370,181 +360,170 @@ static HRESULT ID3DXFileDataImpl_Create(IDirectXFileObject *dxfile_object, ID3DX
     return S_OK;
 }
 
-
-/*** IUnknown methods ***/
-
-static HRESULT WINAPI ID3DXFileEnumObjectImpl_QueryInterface(ID3DXFileEnumObject *iface, REFIID riid, void **ret_iface)
+static HRESULT WINAPI d3dx9_file_enum_object_QueryInterface(ID3DXFileEnumObject *iface, REFIID riid, void **out)
 {
-    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
+    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
 
-    if (IsEqualGUID(riid, &IID_IUnknown) ||
-        IsEqualGUID(riid, &IID_ID3DXFileEnumObject))
+    if (IsEqualGUID(riid, &IID_ID3DXFileEnumObject)
+            || IsEqualGUID(riid, &IID_IUnknown))
     {
         iface->lpVtbl->AddRef(iface);
-        *ret_iface = iface;
+        *out = iface;
         return S_OK;
     }
 
-    WARN("(%p)->(%s, %p), not found\n", iface, debugstr_guid(riid), ret_iface);
-    *ret_iface = NULL;
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *out = NULL;
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI ID3DXFileEnumObjectImpl_AddRef(ID3DXFileEnumObject *iface)
+static ULONG WINAPI d3dx9_file_enum_object_AddRef(ID3DXFileEnumObject *iface)
 {
-    ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
-    ULONG ref = InterlockedIncrement(&This->ref);
+    struct d3dx9_file_enum_object *file_enum = impl_from_ID3DXFileEnumObject(iface);
+    ULONG refcount = InterlockedIncrement(&file_enum->ref);
 
-    TRACE("(%p)->(): new ref = %u\n", iface, ref);
+    TRACE("%p increasing refcount to %u.\n", file_enum, refcount);
 
-    return ref;
+    return refcount;
 }
 
-static ULONG WINAPI ID3DXFileEnumObjectImpl_Release(ID3DXFileEnumObject *iface)
+static ULONG WINAPI d3dx9_file_enum_object_Release(ID3DXFileEnumObject *iface)
 {
-    ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
-    ULONG ref = InterlockedDecrement(&This->ref);
+    struct d3dx9_file_enum_object *file_enum = impl_from_ID3DXFileEnumObject(iface);
+    ULONG refcount = InterlockedDecrement(&file_enum->ref);
 
-    TRACE("(%p)->(): new ref = %u\n", iface, ref);
+    TRACE("%p decreasing refcount to %u.\n", file_enum, refcount);
 
-    if (!ref)
+    if (!refcount)
     {
         ULONG i;
 
-        for (i = 0; i < This->nb_children; i++)
-            (This->children[i])->lpVtbl->Release(This->children[i]);
-        HeapFree(GetProcessHeap(), 0, This->children);
-        HeapFree(GetProcessHeap(), 0, This);
+        for (i = 0; i < file_enum->nb_children; ++i)
+        {
+            ID3DXFileData *child = file_enum->children[i];
+            child->lpVtbl->Release(child);
+        }
+        HeapFree(GetProcessHeap(), 0, file_enum->children);
+        HeapFree(GetProcessHeap(), 0, file_enum);
     }
 
-    return ref;
+    return refcount;
 }
 
-
-/*** ID3DXFileEnumObject methods ***/
-
-static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetFile(ID3DXFileEnumObject *iface, ID3DXFile **file)
+static HRESULT WINAPI d3dx9_file_enum_object_GetFile(ID3DXFileEnumObject *iface, ID3DXFile **file)
 {
-    FIXME("(%p)->(%p): stub\n", iface, file);
+    FIXME("iface %p, file %p stub!\n", iface, file);
 
     return E_NOTIMPL;
 }
 
-
-static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetChildren(ID3DXFileEnumObject *iface, SIZE_T *children)
+static HRESULT WINAPI d3dx9_file_enum_object_GetChildren(ID3DXFileEnumObject *iface, SIZE_T *children)
 {
-    ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
+    struct d3dx9_file_enum_object *file_enum = impl_from_ID3DXFileEnumObject(iface);
 
-    TRACE("(%p)->(%p)\n", iface, children);
+    TRACE("iface %p, children %p.\n", iface, children);
 
     if (!children)
         return E_POINTER;
 
-    *children = This->nb_children;
+    *children = file_enum->nb_children;
 
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetChild(ID3DXFileEnumObject *iface, SIZE_T id, ID3DXFileData **object)
+static HRESULT WINAPI d3dx9_file_enum_object_GetChild(ID3DXFileEnumObject *iface, SIZE_T id, ID3DXFileData **object)
 {
-    ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
+    struct d3dx9_file_enum_object *file_enum = impl_from_ID3DXFileEnumObject(iface);
 
-    TRACE("(%p)->(%lu, %p)\n", iface, id, object);
+    TRACE("iface %p, id %#lx, object %p.\n", iface, id, object);
 
     if (!object)
         return E_POINTER;
 
-    *object = This->children[id];
+    *object = file_enum->children[id];
     (*object)->lpVtbl->AddRef(*object);
 
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetDataObjectById(ID3DXFileEnumObject *iface, REFGUID guid, ID3DXFileData **object)
+static HRESULT WINAPI d3dx9_file_enum_object_GetDataObjectById(ID3DXFileEnumObject *iface,
+        REFGUID guid, ID3DXFileData **object)
 {
-    FIXME("(%p)->(%s, %p): stub\n", iface, debugstr_guid(guid), object);
+    FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
 
     return E_NOTIMPL;
 }
 
-
-static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetDataObjectByName(ID3DXFileEnumObject *iface, const char *name, ID3DXFileData **object)
+static HRESULT WINAPI d3dx9_file_enum_object_GetDataObjectByName(ID3DXFileEnumObject *iface,
+        const char *name, ID3DXFileData **object)
 {
-    FIXME("(%p)->(%s, %p): stub\n", iface, debugstr_a(name), object);
+    FIXME("iface %p, name %s, object %p stub!\n", iface, debugstr_a(name), object);
 
     return E_NOTIMPL;
 }
 
-
-static const ID3DXFileEnumObjectVtbl ID3DXFileEnumObject_Vtbl =
+static const ID3DXFileEnumObjectVtbl d3dx9_file_enum_object_vtbl =
 {
-    ID3DXFileEnumObjectImpl_QueryInterface,
-    ID3DXFileEnumObjectImpl_AddRef,
-    ID3DXFileEnumObjectImpl_Release,
-    ID3DXFileEnumObjectImpl_GetFile,
-    ID3DXFileEnumObjectImpl_GetChildren,
-    ID3DXFileEnumObjectImpl_GetChild,
-    ID3DXFileEnumObjectImpl_GetDataObjectById,
-    ID3DXFileEnumObjectImpl_GetDataObjectByName
+    d3dx9_file_enum_object_QueryInterface,
+    d3dx9_file_enum_object_AddRef,
+    d3dx9_file_enum_object_Release,
+    d3dx9_file_enum_object_GetFile,
+    d3dx9_file_enum_object_GetChildren,
+    d3dx9_file_enum_object_GetChild,
+    d3dx9_file_enum_object_GetDataObjectById,
+    d3dx9_file_enum_object_GetDataObjectByName,
 };
 
-
-/*** IUnknown methods ***/
-
-static HRESULT WINAPI ID3DXFileImpl_QueryInterface(ID3DXFile *iface, REFIID riid, void **ret_iface)
+static HRESULT WINAPI d3dx9_file_QueryInterface(ID3DXFile *iface, REFIID riid, void **out)
 {
-    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
+    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
 
-    if (IsEqualGUID(riid, &IID_IUnknown) ||
-        IsEqualGUID(riid, &IID_ID3DXFile))
+    if (IsEqualGUID(riid, &IID_ID3DXFile)
+            || IsEqualGUID(riid, &IID_IUnknown))
     {
         iface->lpVtbl->AddRef(iface);
-        *ret_iface = iface;
+        *out = iface;
         return S_OK;
     }
 
-    WARN("(%p)->(%s, %p), not found\n", iface, debugstr_guid(riid), ret_iface);
-    *ret_iface = NULL;
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+
+    *out = NULL;
     return E_NOINTERFACE;
 }
 
-
-static ULONG WINAPI ID3DXFileImpl_AddRef(ID3DXFile *iface)
+static ULONG WINAPI d3dx9_file_AddRef(ID3DXFile *iface)
 {
-    ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
-    ULONG ref = InterlockedIncrement(&This->ref);
+    struct d3dx9_file *file = impl_from_ID3DXFile(iface);
+    ULONG refcount = InterlockedIncrement(&file->ref);
 
-    TRACE("(%p)->(): new ref = %u\n", iface, ref);
+    TRACE("%p increasing refcount to %u.\n", file, refcount);
 
-    return ref;
+    return refcount;
 }
 
-
-static ULONG WINAPI ID3DXFileImpl_Release(ID3DXFile *iface)
+static ULONG WINAPI d3dx9_file_Release(ID3DXFile *iface)
 {
-    ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
-    ULONG ref = InterlockedDecrement(&This->ref);
+    struct d3dx9_file *file = impl_from_ID3DXFile(iface);
+    ULONG refcount = InterlockedDecrement(&file->ref);
 
-    TRACE("(%p)->(): new ref = %u\n", iface, ref);
+    TRACE("%p decreasing refcount to %u.\n", file, refcount);
 
-    if (!ref)
+    if (!refcount)
     {
-        IDirectXFile_Release(This->dxfile);
-        HeapFree(GetProcessHeap(), 0, This);
+        IDirectXFile_Release(file->dxfile);
+        HeapFree(GetProcessHeap(), 0, file);
     }
 
-    return ref;
+    return refcount;
 }
 
-
-/*** ID3DXFile methods ***/
-
-static HRESULT WINAPI ID3DXFileImpl_CreateEnumObject(ID3DXFile *iface, const void *source, D3DXF_FILELOADOPTIONS options, ID3DXFileEnumObject **enum_object)
+static HRESULT WINAPI d3dx9_file_CreateEnumObject(ID3DXFile *iface, const void *source,
+        D3DXF_FILELOADOPTIONS options, ID3DXFileEnumObject **enum_object)
 {
-    ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
-    ID3DXFileEnumObjectImpl *object;
+    struct d3dx9_file *file = impl_from_ID3DXFile(iface);
+    struct d3dx9_file_enum_object *object;
     IDirectXFileEnumObject *dxfile_enum_object;
     void *dxfile_source;
     DXFILELOADOPTIONS dxfile_options;
@@ -553,7 +532,7 @@ static HRESULT WINAPI ID3DXFileImpl_CreateEnumObject(ID3DXFile *iface, const voi
     IDirectXFileData *data_object;
     HRESULT ret;
 
-    TRACE("(%p)->(%p, %x, %p)\n", iface, source, options, enum_object);
+    TRACE("iface %p, source %p, options %#x, enum_object %p.\n", iface, source, options, enum_object);
 
     if (!enum_object)
         return E_POINTER;
@@ -594,10 +573,10 @@ static HRESULT WINAPI ID3DXFileImpl_CreateEnumObject(ID3DXFile *iface, const voi
     if (!object)
         return E_OUTOFMEMORY;
 
-    object->ID3DXFileEnumObject_iface.lpVtbl = &ID3DXFileEnumObject_Vtbl;
+    object->ID3DXFileEnumObject_iface.lpVtbl = &d3dx9_file_enum_object_vtbl;
     object->ref = 1;
 
-    ret = IDirectXFile_CreateEnumObject(This->dxfile, dxfile_source, dxfile_options, &dxfile_enum_object);
+    ret = IDirectXFile_CreateEnumObject(file->dxfile, dxfile_source, dxfile_options, &dxfile_enum_object);
 
     if (ret != S_OK)
     {
@@ -617,8 +596,8 @@ static HRESULT WINAPI ID3DXFileImpl_CreateEnumObject(ID3DXFile *iface, const voi
             ret = E_OUTOFMEMORY;
             break;
         }
-        ret = ID3DXFileDataImpl_Create((IDirectXFileObject*)data_object, &object->children[object->nb_children]);
-        if (ret != S_OK)
+        if (FAILED(ret = d3dx9_file_data_create((IDirectXFileObject*)data_object,
+                &object->children[object->nb_children])))
             break;
         object->nb_children++;
     }
@@ -635,23 +614,23 @@ static HRESULT WINAPI ID3DXFileImpl_CreateEnumObject(ID3DXFile *iface, const voi
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileImpl_CreateSaveObject(ID3DXFile *iface, const void *data, D3DXF_FILESAVEOPTIONS options, D3DXF_FILEFORMAT format, ID3DXFileSaveObject **save_object)
+static HRESULT WINAPI d3dx9_file_CreateSaveObject(ID3DXFile *iface, const void *data,
+        D3DXF_FILESAVEOPTIONS options, D3DXF_FILEFORMAT format, ID3DXFileSaveObject **save_object)
 {
-    FIXME("(%p)->(%p, %x, %u, %p): stub\n", iface, data, options, format, save_object);
+    FIXME("iface %p, data %p, options %#x, format %#x, save_object %p stub!\n",
+            iface, data, options, format, save_object);
 
     return E_NOTIMPL;
 }
 
-
-static HRESULT WINAPI ID3DXFileImpl_RegisterTemplates(ID3DXFile *iface, const void *data, SIZE_T size)
+static HRESULT WINAPI d3dx9_file_RegisterTemplates(ID3DXFile *iface, const void *data, SIZE_T size)
 {
-    ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
+    struct d3dx9_file *file = impl_from_ID3DXFile(iface);
     HRESULT ret;
 
-    TRACE("(%p)->(%p, %lu)\n", iface, data, size);
+    TRACE("iface %p, data %p, size %lu.\n", iface, data, size);
 
-    ret = IDirectXFile_RegisterTemplates(This->dxfile, (void*)data, size);
+    ret = IDirectXFile_RegisterTemplates(file->dxfile, (void *)data, size);
     if (ret != DXFILE_OK)
     {
         WARN("Error %#x\n", ret);
@@ -661,32 +640,30 @@ static HRESULT WINAPI ID3DXFileImpl_RegisterTemplates(ID3DXFile *iface, const vo
     return S_OK;
 }
 
-
-static HRESULT WINAPI ID3DXFileImpl_RegisterEnumTemplates(ID3DXFile *iface, ID3DXFileEnumObject *enum_object)
+static HRESULT WINAPI d3dx9_file_RegisterEnumTemplates(ID3DXFile *iface, ID3DXFileEnumObject *enum_object)
 {
-    FIXME("(%p)->(%p): stub\n", iface, enum_object);
+    FIXME("iface %p, enum_object %p stub!\n", iface, enum_object);
 
     return E_NOTIMPL;
 }
 
-
-static const ID3DXFileVtbl ID3DXFile_Vtbl =
+static const ID3DXFileVtbl d3dx9_file_vtbl =
 {
-    ID3DXFileImpl_QueryInterface,
-    ID3DXFileImpl_AddRef,
-    ID3DXFileImpl_Release,
-    ID3DXFileImpl_CreateEnumObject,
-    ID3DXFileImpl_CreateSaveObject,
-    ID3DXFileImpl_RegisterTemplates,
-    ID3DXFileImpl_RegisterEnumTemplates
+    d3dx9_file_QueryInterface,
+    d3dx9_file_AddRef,
+    d3dx9_file_Release,
+    d3dx9_file_CreateEnumObject,
+    d3dx9_file_CreateSaveObject,
+    d3dx9_file_RegisterTemplates,
+    d3dx9_file_RegisterEnumTemplates,
 };
 
 HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
 {
-    ID3DXFileImpl *object;
+    struct d3dx9_file *object;
     HRESULT ret;
 
-    TRACE("(%p)\n", d3dxfile);
+    TRACE("d3dxfile %p.\n", d3dxfile);
 
     if (!d3dxfile)
         return E_POINTER;
@@ -706,7 +683,7 @@ HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
         return E_FAIL;
     }
 
-    object->ID3DXFile_iface.lpVtbl = &ID3DXFile_Vtbl;
+    object->ID3DXFile_iface.lpVtbl = &d3dx9_file_vtbl;
     object->ref = 1;
 
     *d3dxfile = &object->ID3DXFile_iface;
index 43bbfd0..4ce0a8b 100644 (file)
@@ -31,7 +31,7 @@ reactos/dll/directx/wine/amstream       # Synced to Wine-1.7.17
 reactos/dll/directx/wine/d3d8           # Synced to Wine-1.7.17
 reactos/dll/directx/wine/d3d9           # Synced to Wine-1.7.17
 reactos/dll/directx/wine/d3dcompiler_43 # Synced to Wine-1.7.17
-reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to Wine-1.7.1
+reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to Wine-1.7.17
 reactos/dll/directx/wine/d3dxof         # Synced to Wine-1.7.1
 reactos/dll/directx/wine/ddraw          # Synced to Wine-1.7.17
 reactos/dll/directx/wine/devenum        # Synced to Wine-1.7.1