Sync with trunk.
[reactos.git] / dll / directx / wine / d3dx9_36 / mesh.c
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)
     {