[D3DX9_36] Sync with Wine Staging 1.7.55. CORE-10536
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 22 Nov 2015 15:41:58 +0000 (15:41 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 22 Nov 2015 15:41:58 +0000 (15:41 +0000)
svn path=/trunk/; revision=70032

reactos/dll/directx/wine/d3dx9_36/animation.c
reactos/dll/directx/wine/d3dx9_36/d3dx9_36.spec
reactos/dll/directx/wine/d3dx9_36/d3dx9_36_private.h
reactos/dll/directx/wine/d3dx9_36/effect.c
reactos/dll/directx/wine/d3dx9_36/font.c
reactos/dll/directx/wine/d3dx9_36/mesh.c
reactos/dll/directx/wine/d3dx9_36/shader.c
reactos/dll/directx/wine/d3dx9_36/skin.c
reactos/dll/directx/wine/d3dx9_36/surface.c
reactos/media/doc/README.WINE

index d1b44ab..e91a2cc 100644 (file)
@@ -24,6 +24,11 @@ struct d3dx9_animation_controller
 {
     ID3DXAnimationController ID3DXAnimationController_iface;
     LONG ref;
+
+    UINT max_outputs;
+    UINT max_sets;
+    UINT max_tracks;
+    UINT max_events;
 };
 
 static inline struct d3dx9_animation_controller *impl_from_ID3DXAnimationController(ID3DXAnimationController *iface)
@@ -50,24 +55,24 @@ static HRESULT WINAPI d3dx9_animation_controller_QueryInterface(ID3DXAnimationCo
 
 static ULONG WINAPI d3dx9_animation_controller_AddRef(ID3DXAnimationController *iface)
 {
-    struct d3dx9_animation_controller *animation = impl_from_ID3DXAnimationController(iface);
-    ULONG refcount = InterlockedIncrement(&animation->ref);
+    struct d3dx9_animation_controller *This = impl_from_ID3DXAnimationController(iface);
+    ULONG refcount = InterlockedIncrement(&This->ref);
 
-    TRACE("%p increasing refcount to %u.\n", animation, refcount);
+    TRACE("%p increasing refcount to %u.\n", This, refcount);
 
     return refcount;
 }
 
 static ULONG WINAPI d3dx9_animation_controller_Release(ID3DXAnimationController *iface)
 {
-    struct d3dx9_animation_controller *animation = impl_from_ID3DXAnimationController(iface);
-    ULONG refcount = InterlockedDecrement(&animation->ref);
+    struct d3dx9_animation_controller *This = impl_from_ID3DXAnimationController(iface);
+    ULONG refcount = InterlockedDecrement(&This->ref);
 
-    TRACE("%p decreasing refcount to %u.\n", animation, refcount);
+    TRACE("%p decreasing refcount to %u.\n", This, refcount);
 
     if (!refcount)
     {
-        HeapFree(GetProcessHeap(), 0, animation);
+        HeapFree(GetProcessHeap(), 0, This);
     }
 
     return refcount;
@@ -75,30 +80,38 @@ static ULONG WINAPI d3dx9_animation_controller_Release(ID3DXAnimationController
 
 static UINT WINAPI d3dx9_animation_controller_GetMaxNumAnimationOutputs(ID3DXAnimationController *iface)
 {
-    FIXME("iface %p stub.\n", iface);
+    struct d3dx9_animation_controller *This = impl_from_ID3DXAnimationController(iface);
 
-    return 0;
+    TRACE("iface %p.\n", iface);
+
+    return This->max_outputs;
 }
 
 static UINT WINAPI d3dx9_animation_controller_GetMaxNumAnimationSets(ID3DXAnimationController *iface)
 {
-    FIXME("iface %p stub.\n", iface);
+    struct d3dx9_animation_controller *This = impl_from_ID3DXAnimationController(iface);
 
-    return 0;
+    TRACE("iface %p.\n", iface);
+
+    return This->max_sets;
 }
 
 static UINT WINAPI d3dx9_animation_controller_GetMaxNumTracks(ID3DXAnimationController *iface)
 {
-    FIXME("iface %p stub.\n", iface);
+    struct d3dx9_animation_controller *This = impl_from_ID3DXAnimationController(iface);
 
-    return 0;
+    FIXME("iface %p.\n", iface);
+
+    return This->max_tracks;
 }
 
 static UINT WINAPI d3dx9_animation_controller_GetMaxNumEvents(ID3DXAnimationController *iface)
 {
-    FIXME("iface %p stub.\n", iface);
+    struct d3dx9_animation_controller *This = impl_from_ID3DXAnimationController(iface);
 
-    return 0;
+    FIXME("iface %p.\n", iface);
+
+    return This->max_events;
 }
 
 static HRESULT WINAPI d3dx9_animation_controller_RegisterAnimationOutput(ID3DXAnimationController *iface,
@@ -445,6 +458,10 @@ HRESULT WINAPI D3DXCreateAnimationController(UINT MaxNumAnimationOutputs, UINT M
 
     object->ID3DXAnimationController_iface.lpVtbl = &d3dx9_animation_controller_vtbl;
     object->ref = 1;
+    object->max_outputs = MaxNumAnimationOutputs;
+    object->max_sets    = MaxNumAnimationSets;
+    object->max_tracks  = MaxNumTracks;
+    object->max_events  = MaxNumEvents;
 
     *AnimationController = &object->ID3DXAnimationController_iface;
 
index 3704fde..f313d35 100644 (file)
@@ -66,8 +66,8 @@
 @ stdcall D3DXCreateFontIndirectA(ptr ptr ptr)
 @ stdcall D3DXCreateFontIndirectW(ptr ptr ptr)
 @ stdcall D3DXCreateFontW(ptr long long long long long long long long long wstr ptr)
-@ stdcall -stub D3DXCreateFragmentLinker(ptr long ptr)
-@ stdcall -stub D3DXCreateFragmentLinkerEx(ptr long long ptr)
+@ stdcall D3DXCreateFragmentLinker(ptr long ptr)
+@ stdcall D3DXCreateFragmentLinkerEx(ptr long long ptr)
 @ stdcall -stub D3DXCreateKeyframedAnimationSet(ptr long long long long ptr ptr)
 @ stdcall D3DXCreateLine(ptr ptr)
 @ stdcall D3DXCreateMatrixStack(long ptr)
 @ stdcall -stub D3DXSimplifyMesh(ptr ptr ptr ptr long long ptr)
 @ stdcall D3DXSphereBoundProbe(ptr float ptr ptr)
 @ stdcall -stub D3DXSplitMesh(ptr ptr long long ptr ptr ptr ptr ptr)
-@ stdcall -stub D3DXTessellateNPatches(ptr ptr long long ptr ptr)
+@ stdcall D3DXTessellateNPatches(ptr ptr float long ptr ptr)
 @ stdcall -stub D3DXTessellateRectPatch(ptr ptr ptr ptr ptr)
 @ stdcall -stub D3DXTessellateTriPatch(ptr ptr ptr ptr ptr)
 @ stdcall -stub D3DXTriPatchSize(ptr ptr ptr)
index 775436b..da25773 100644 (file)
@@ -128,4 +128,6 @@ const char *debug_d3dxparameter_registerset(D3DXREGISTER_SET r) DECLSPEC_HIDDEN;
 void set_number(void *outdata, D3DXPARAMETER_TYPE outtype,
         const void *indata, D3DXPARAMETER_TYPE intype) DECLSPEC_HIDDEN;
 
+HRESULT create_dummy_skin(ID3DXSkinInfo **iface) DECLSPEC_HIDDEN;
+
 #endif /* __WINE_D3DX9_36_PRIVATE_H */
index 7987158..d677982 100644 (file)
@@ -5094,7 +5094,7 @@ static HRESULT d3dx9_parse_resource(struct d3dx9_base_effect *base, const char *
     HRESULT hr = E_FAIL;
 
     read_dword(ptr, &technique_index);
-    TRACE("techn: %u\n", technique_index);
+    TRACE("technique_index: %u\n", technique_index);
 
     read_dword(ptr, &index);
     TRACE("index: %u\n", index);
index 9e9869e..6adaf1e 100644 (file)
@@ -207,7 +207,7 @@ static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite,
     TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x\n",
             iface,  sprite, debugstr_a(string), count, wine_dbgstr_rect(rect), format, color);
 
-    if (!string || !count)
+    if (!string || count <= 0)
         return 0;
 
     countW = MultiByteToWideChar(CP_ACP, 0, string, count, NULL, 0);
@@ -232,7 +232,7 @@ static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
     TRACE("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x\n",
             iface,  sprite, debugstr_w(string), count, wine_dbgstr_rect(rect), format, color);
 
-    if (!string || !count)
+    if (!string || count <= 0)
         return 0;
 
     /* Strip terminating NULL characters */
index d6f2a92..9a4c931 100644 (file)
@@ -3320,6 +3320,13 @@ static HRESULT parse_mesh(ID3DXFileData *filedata, struct mesh_data *mesh_data,
         goto end;
     }
 
+    if ((provide_flags & PROVIDE_SKININFO) && !mesh_data->skin_info)
+    {
+        hr = create_dummy_skin(&mesh_data->skin_info);
+        if (FAILED(hr))
+            goto end;
+    }
+
     hr = D3D_OK;
 
 end:
@@ -3898,11 +3905,9 @@ HRESULT WINAPI D3DXLoadMeshHierarchyFromXInMemory(const void *memory, DWORD memo
 
     if (!memory || !memory_size || !device || !frame_hierarchy || !alloc_hier)
         return D3DERR_INVALIDCALL;
-    if (load_user_data || anim_controller) {
-        if (load_user_data)
-            FIXME("Loading user data not implemented\n");
-        if (anim_controller)
-            FIXME("Animation controller creation not implemented\n");
+    if (load_user_data)
+    {
+        FIXME("Loading user data not implemented.\n");
         return E_NOTIMPL;
     }
 
@@ -3972,6 +3977,12 @@ HRESULT WINAPI D3DXLoadMeshHierarchyFromXInMemory(const void *memory, DWORD memo
         hr = D3D_OK;
     }
 
+    if (anim_controller)
+    {
+        *anim_controller = NULL;
+        FIXME("Animation controller creation not implemented.\n");
+    }
+
 cleanup:
     if (FAILED(hr) && first_frame) D3DXFrameDestroy(first_frame, alloc_hier);
     if (filedata) filedata->lpVtbl->Release(filedata);
@@ -4978,12 +4989,6 @@ HRESULT WINAPI D3DXCreateCylinder(struct IDirect3DDevice9 *device, float radius1
         return D3DERR_INVALIDCALL;
     }
 
-    if (adjacency)
-    {
-        FIXME("Case of adjacency != NULL not implemented.\n");
-        return E_NOTIMPL;
-    }
-
     number_of_vertices = 2 + (slices * (3 + stacks));
     number_of_faces = 2 * slices + stacks * (2 * slices);
 
@@ -5135,6 +5140,23 @@ HRESULT WINAPI D3DXCreateCylinder(struct IDirect3DDevice9 *device, float radius1
     free_sincos_table(&theta);
     cylinder->lpVtbl->UnlockIndexBuffer(cylinder);
     cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
+
+    if (adjacency)
+    {
+        if (FAILED(hr = D3DXCreateBuffer(number_of_faces * sizeof(DWORD) * 3, adjacency)))
+        {
+            cylinder->lpVtbl->Release(cylinder);
+            return hr;
+        }
+
+        if (FAILED(hr = cylinder->lpVtbl->GenerateAdjacency(cylinder, 0.0f, (*adjacency)->lpVtbl->GetBufferPointer(*adjacency))))
+        {
+            (*adjacency)->lpVtbl->Release(*adjacency);
+            cylinder->lpVtbl->Release(cylinder);
+            return hr;
+        }
+    }
+
     *mesh = cylinder;
 
     return D3D_OK;
@@ -5145,7 +5167,7 @@ HRESULT WINAPI D3DXCreateTeapot(struct IDirect3DDevice9 *device,
 {
     FIXME("(%p, %p, %p): stub\n", device, mesh, adjacency);
 
-    return E_NOTIMPL;
+    return D3DXCreateSphere(device, 1.0f, 4, 4, mesh, adjacency);
 }
 
 HRESULT WINAPI D3DXCreateTextA(struct IDirect3DDevice9 *device, HDC hdc, const char *text, float deviation,
@@ -5839,6 +5861,10 @@ static HRESULT triangulate(struct triangulation_array *triangulations)
     int i;
     struct point2d_index *idx_ptr;
 
+    /* Glyphs without outlines do not generate any vertices. */
+    if (!glyph->outlines.count)
+        return D3D_OK;
+
     for (i = 0; i < glyph->outlines.count; i++)
         nb_vertices += glyph->outlines.items[i].count;
 
@@ -6989,7 +7015,6 @@ HRESULT WINAPI D3DXWeldVertices(ID3DXMesh *mesh, DWORD flags, const D3DXWELDEPSI
     DWORD *point_reps = NULL;
     struct d3dx9_mesh *This = impl_from_ID3DXMesh(mesh);
     DWORD *vertex_face_map = NULL;
-    ID3DXBuffer *vertex_remap = NULL;
     BYTE *vertices = NULL;
 
     TRACE("mesh %p, flags %#x, epsilons %p, adjacency %p, adjacency_out %p, face_remap_out %p, vertex_remap_out %p.\n",
@@ -7156,7 +7181,6 @@ cleanup:
     HeapFree(GetProcessHeap(), 0, vertex_face_map);
     if (attributes) mesh->lpVtbl->UnlockAttributeBuffer(mesh);
     if (indices) mesh->lpVtbl->UnlockIndexBuffer(mesh);
-    if (vertex_remap) ID3DXBuffer_Release(vertex_remap);
     if (vertices) mesh->lpVtbl->UnlockVertexBuffer(mesh);
 
     return hr;
@@ -7227,36 +7251,281 @@ error:
     return hr;
 }
 
+static D3DXVECTOR3 *vertex_element_vec3(BYTE *vertices, const D3DVERTEXELEMENT9 *declaration,
+        DWORD vertex_stride, DWORD index)
+{
+    return (D3DXVECTOR3 *)(vertices + declaration->Offset + index * vertex_stride);
+}
+
+static D3DXVECTOR3 read_vec3(BYTE *vertices, const D3DVERTEXELEMENT9 *declaration,
+        DWORD vertex_stride, DWORD index)
+{
+    D3DXVECTOR3 vec3 = {0};
+    const D3DXVECTOR3 *src = vertex_element_vec3(vertices, declaration, vertex_stride, index);
+
+    switch (declaration->Type)
+    {
+        case D3DDECLTYPE_FLOAT1:
+            vec3.x = src->x;
+            break;
+        case D3DDECLTYPE_FLOAT2:
+            vec3.x = src->x;
+            vec3.y = src->y;
+            break;
+        case D3DDECLTYPE_FLOAT3:
+        case D3DDECLTYPE_FLOAT4:
+            vec3 = *src;
+            break;
+        default:
+            ERR("Cannot read vec3\n");
+            break;
+    }
+
+    return vec3;
+}
+
 /*************************************************************************
  * D3DXComputeTangentFrameEx    (D3DX9_36.@)
  */
-HRESULT WINAPI D3DXComputeTangentFrameEx(ID3DXMesh *Mesh, DWORD TextureInSemantic, DWORD TextureInIndex,
-               DWORD UPartialOutSemantic, DWORD UPartialOutIndex, DWORD VPartialOutSemantic, DWORD VPartialOutIndex,
-               DWORD NormalOutSemantic, DWORD NormalOutIndex, DWORD options, const DWORD *adjacency,
-               FLOAT PartialEdgeThreshold, FLOAT SingularPointThreshold, FLOAT NormalEdgeThreshold,
-               ID3DXMesh **MeshOut, ID3DXBuffer **VertexMapping)
-{
-    FIXME("Mesh %p, TextureInSemantic %u, TextureInIndex %u, UPartialOutSemantic %u, UPartialOutIndex %u, "
-            "VPartialOutSemantic %u, VPartialOutIndex %u, NormalOutSemantic %u, NormalOutIndex %u, "
-            "options %x, adjacency %p, PartialEdgeThreshold %f, SingularPointThreshold %f, NormalEdgeThreshold %f, "
-            "MeshOut %p, VertexMapping %p stub.\n",
-            Mesh, TextureInSemantic, TextureInIndex, UPartialOutSemantic, UPartialOutIndex, VPartialOutSemantic,
-            VPartialOutIndex, NormalOutSemantic, NormalOutIndex, options, adjacency, PartialEdgeThreshold,
-            SingularPointThreshold, NormalEdgeThreshold, MeshOut, VertexMapping);
+HRESULT WINAPI D3DXComputeTangentFrameEx(ID3DXMesh *mesh, DWORD texture_in_semantic, DWORD texture_in_index,
+        DWORD u_partial_out_semantic, DWORD u_partial_out_index, DWORD v_partial_out_semantic,
+        DWORD v_partial_out_index, DWORD normal_out_semantic, DWORD normal_out_index, DWORD options,
+        const DWORD *adjacency, float partial_edge_threshold, float singular_point_threshold,
+        float normal_edge_threshold, ID3DXMesh **mesh_out, ID3DXBuffer **vertex_mapping)
+{
+    HRESULT hr;
+    void *indices = NULL;
+    BYTE *vertices = NULL;
+    DWORD *point_reps = NULL;
+    size_t normal_size;
+    BOOL indices_are_32bit;
+    DWORD i, j, num_faces, num_vertices, vertex_stride;
+    D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE] = {D3DDECL_END()};
+    D3DVERTEXELEMENT9 *position_declaration = NULL, *normal_declaration = NULL;
+    DWORD weighting_method = options & (D3DXTANGENT_WEIGHT_EQUAL | D3DXTANGENT_WEIGHT_BY_AREA);
 
-    return E_NOTIMPL;
+    TRACE("mesh %p, texture_in_semantic %u, texture_in_index %u, u_partial_out_semantic %u, u_partial_out_index %u, "
+            "v_partial_out_semantic %u, v_partial_out_index %u, normal_out_semantic %u, normal_out_index %u, "
+            "options %#x, adjacency %p, partial_edge_threshold %f, singular_point_threshold %f, "
+            "normal_edge_threshold %f, mesh_out %p, vertex_mapping %p\n",
+            mesh, texture_in_semantic, texture_in_index, u_partial_out_semantic, u_partial_out_index,
+            v_partial_out_semantic, v_partial_out_index, normal_out_semantic, normal_out_index, options, adjacency,
+            partial_edge_threshold, singular_point_threshold, normal_edge_threshold, mesh_out, vertex_mapping);
+
+    if (!mesh)
+    {
+        WARN("mesh is NULL\n");
+        return D3DERR_INVALIDCALL;
+    }
+
+    if (weighting_method == (D3DXTANGENT_WEIGHT_EQUAL | D3DXTANGENT_WEIGHT_BY_AREA))
+    {
+        WARN("D3DXTANGENT_WEIGHT_BY_AREA and D3DXTANGENT_WEIGHT_EQUAL are mutally exclusive\n");
+        return D3DERR_INVALIDCALL;
+    }
+
+    if (u_partial_out_semantic != D3DX_DEFAULT)
+    {
+        FIXME("tangent vectors computation is not supported\n");
+        return E_NOTIMPL;
+    }
+
+    if (v_partial_out_semantic != D3DX_DEFAULT)
+    {
+        FIXME("binormal vectors computation is not supported\n");
+        return E_NOTIMPL;
+    }
+
+    if (options & ~(D3DXTANGENT_GENERATE_IN_PLACE | D3DXTANGENT_CALCULATE_NORMALS | D3DXTANGENT_WEIGHT_EQUAL | D3DXTANGENT_WEIGHT_BY_AREA))
+    {
+        FIXME("unsupported options %#x\n", options);
+        return E_NOTIMPL;
+    }
+
+    if (!(options & D3DXTANGENT_CALCULATE_NORMALS))
+    {
+        FIXME("only normals computation is supported\n");
+        return E_NOTIMPL;
+    }
+
+    if (!(options & D3DXTANGENT_GENERATE_IN_PLACE) || mesh_out || vertex_mapping)
+    {
+        FIXME("only D3DXTANGENT_GENERATE_IN_PLACE is supported\n");
+        return E_NOTIMPL;
+    }
+
+    if (FAILED(hr = mesh->lpVtbl->GetDeclaration(mesh, declaration)))
+        return hr;
+
+    for (i = 0; declaration[i].Stream != 0xff; i++)
+    {
+        if (declaration[i].Usage == D3DDECLUSAGE_POSITION && !declaration[i].UsageIndex)
+            position_declaration = &declaration[i];
+        if (declaration[i].Usage == normal_out_semantic && declaration[i].UsageIndex == normal_out_index)
+            normal_declaration = &declaration[i];
+    }
+
+    if (!position_declaration || !normal_declaration)
+        return D3DERR_INVALIDCALL;
+
+    if (normal_declaration->Type == D3DDECLTYPE_FLOAT3)
+    {
+        normal_size = sizeof(D3DXVECTOR3);
+    }
+    else if (normal_declaration->Type == D3DDECLTYPE_FLOAT4)
+    {
+        normal_size = sizeof(D3DXVECTOR4);
+    }
+    else
+    {
+        WARN("unsupported normals type %u\n", normal_declaration->Type);
+        return D3DERR_INVALIDCALL;
+    }
+
+    num_faces = mesh->lpVtbl->GetNumFaces(mesh);
+    num_vertices = mesh->lpVtbl->GetNumVertices(mesh);
+    vertex_stride = mesh->lpVtbl->GetNumBytesPerVertex(mesh);
+    indices_are_32bit = mesh->lpVtbl->GetOptions(mesh) & D3DXMESH_32BIT;
+
+    point_reps = HeapAlloc(GetProcessHeap(), 0, num_vertices * sizeof(*point_reps));
+    if (!point_reps)
+    {
+        hr = E_OUTOFMEMORY;
+        goto done;
+    }
+
+    if (adjacency)
+    {
+        if (FAILED(hr = mesh->lpVtbl->ConvertAdjacencyToPointReps(mesh, adjacency, point_reps)))
+            goto done;
+    }
+    else
+    {
+        for (i = 0; i < num_vertices; i++)
+            point_reps[i] = i;
+    }
+
+    if (FAILED(hr = mesh->lpVtbl->LockIndexBuffer(mesh, 0, &indices)))
+        goto done;
+
+    if (FAILED(hr = mesh->lpVtbl->LockVertexBuffer(mesh, 0, (void **)&vertices)))
+        goto done;
+
+    for (i = 0; i < num_vertices; i++)
+    {
+        static const D3DXVECTOR4 default_vector = {0.0f, 0.0f, 0.0f, 1.0f};
+        void *normal = vertices + normal_declaration->Offset + i * vertex_stride;
+
+        memcpy(normal, &default_vector, normal_size);
+    }
+
+    for (i = 0; i < num_faces; i++)
+    {
+        float denominator, weights[3];
+        D3DXVECTOR3 a, b, cross, face_normal;
+        const DWORD face_indices[3] =
+        {
+            read_ib(indices, indices_are_32bit, 3 * i + 0),
+            read_ib(indices, indices_are_32bit, 3 * i + 1),
+            read_ib(indices, indices_are_32bit, 3 * i + 2)
+        };
+        const D3DXVECTOR3 v0 = read_vec3(vertices, position_declaration, vertex_stride, face_indices[0]);
+        const D3DXVECTOR3 v1 = read_vec3(vertices, position_declaration, vertex_stride, face_indices[1]);
+        const D3DXVECTOR3 v2 = read_vec3(vertices, position_declaration, vertex_stride, face_indices[2]);
+
+        D3DXVec3Cross(&cross, D3DXVec3Subtract(&a, &v0, &v1), D3DXVec3Subtract(&b, &v0, &v2));
+
+        switch (weighting_method)
+        {
+            case D3DXTANGENT_WEIGHT_EQUAL:
+                weights[0] = weights[1] = weights[2] = 1.0f;
+                break;
+            case D3DXTANGENT_WEIGHT_BY_AREA:
+                weights[0] = weights[1] = weights[2] = D3DXVec3Length(&cross);
+                break;
+            default:
+                /* weight by angle */
+                denominator = D3DXVec3Length(&a) * D3DXVec3Length(&b);
+                if (!denominator)
+                    weights[0] = 0.0f;
+                else
+                    weights[0] = acosf(D3DXVec3Dot(&a, &b) / denominator);
+
+                D3DXVec3Subtract(&a, &v1, &v0);
+                D3DXVec3Subtract(&b, &v1, &v2);
+                denominator = D3DXVec3Length(&a) * D3DXVec3Length(&b);
+                if (!denominator)
+                    weights[1] = 0.0f;
+                else
+                    weights[1] = acosf(D3DXVec3Dot(&a, &b) / denominator);
+
+                D3DXVec3Subtract(&a, &v2, &v0);
+                D3DXVec3Subtract(&b, &v2, &v1);
+                denominator = D3DXVec3Length(&a) * D3DXVec3Length(&b);
+                if (!denominator)
+                    weights[2] = 0.0f;
+                else
+                    weights[2] = acosf(D3DXVec3Dot(&a, &b) / denominator);
+
+                break;
+        }
+
+        D3DXVec3Normalize(&face_normal, &cross);
+
+        for (j = 0; j < 3; j++)
+        {
+            D3DXVECTOR3 normal;
+            DWORD rep_index = point_reps[face_indices[j]];
+            D3DXVECTOR3 *rep_normal = vertex_element_vec3(vertices, normal_declaration, vertex_stride, rep_index);
+
+            D3DXVec3Scale(&normal, &face_normal, weights[j]);
+            D3DXVec3Add(rep_normal, rep_normal, &normal);
+        }
+    }
+
+    for (i = 0; i < num_vertices; i++)
+    {
+        DWORD rep_index = point_reps[i];
+        D3DXVECTOR3 *normal = vertex_element_vec3(vertices, normal_declaration, vertex_stride, i);
+        D3DXVECTOR3 *rep_normal = vertex_element_vec3(vertices, normal_declaration, vertex_stride, rep_index);
+
+        if (i == rep_index)
+            D3DXVec3Normalize(rep_normal, rep_normal);
+        else
+            *normal = *rep_normal;
+    }
+
+    hr = D3D_OK;
+
+done:
+    if (vertices)
+        mesh->lpVtbl->UnlockVertexBuffer(mesh);
+
+    if (indices)
+        mesh->lpVtbl->UnlockIndexBuffer(mesh);
+
+    HeapFree(GetProcessHeap(), 0, point_reps);
+
+    return hr;
 }
 
 /*************************************************************************
  * D3DXComputeNormals    (D3DX9_36.@)
  */
-HRESULT WINAPI D3DXComputeNormals(ID3DXBaseMesh *mesh, const DWORD *adjacency)
+HRESULT WINAPI D3DXComputeNormals(struct ID3DXBaseMesh *mesh, const DWORD *adjacency)
 {
-    TRACE("mesh %p, adjacency %p.\n", mesh, adjacency);
+    TRACE("mesh %p, adjacency %p\n", mesh, adjacency);
+
+    if (mesh && (ID3DXMeshVtbl *)mesh->lpVtbl != &D3DXMesh_Vtbl)
+    {
+        ERR("Invalid virtual table\n");
+        return D3DERR_INVALIDCALL;
+    }
 
-    return D3DXComputeTangentFrameEx((ID3DXMesh *)mesh, D3DX_DEFAULT, 0, D3DX_DEFAULT, 0, D3DX_DEFAULT, 0,
-                                     D3DDECLUSAGE_NORMAL, 0, D3DXTANGENT_GENERATE_IN_PLACE | D3DXTANGENT_CALCULATE_NORMALS,
-                                     adjacency, -1.01f, -0.01f, -1.01f, NULL, NULL);
+    return D3DXComputeTangentFrameEx((ID3DXMesh *)mesh, D3DX_DEFAULT, 0,
+            D3DX_DEFAULT, 0, D3DX_DEFAULT, 0, D3DDECLUSAGE_NORMAL, 0,
+            D3DXTANGENT_GENERATE_IN_PLACE | D3DXTANGENT_CALCULATE_NORMALS,
+            adjacency, -1.01f, -0.01f, -1.01f, NULL, NULL);
 }
 
 /*************************************************************************
@@ -7274,11 +7543,20 @@ HRESULT WINAPI D3DXComputeNormalMap(IDirect3DTexture9 *texture, IDirect3DTexture
 /*************************************************************************
  * D3DXIntersect    (D3DX9_36.@)
  */
-HRESULT WINAPI D3DXIntersect(ID3DXBaseMesh *Mesh, const D3DXVECTOR3 *RayPos, const D3DXVECTOR3 *RayDir, BOOL *Hit,
-        DWORD *FaceIndex, FLOAT *U, FLOAT *V, FLOAT *Dist, ID3DXBuffer **AllHits, DWORD *CountOfHits)
+HRESULT WINAPI D3DXIntersect(ID3DXBaseMesh *mesh, const D3DXVECTOR3 *ray_pos, const D3DXVECTOR3 *ray_dir,
+        BOOL *hit, DWORD *face_index, float *u, float *v, float *distance, ID3DXBuffer **all_hits, DWORD *count_of_hits)
+{
+    FIXME("mesh %p, ray_pos %p, ray_dir %p, hit %p, face_index %p, u %p, v %p, distance %p, all_hits %p, "
+            "count_of_hits %p stub!\n", mesh, ray_pos, ray_dir, hit, face_index, u, v, distance, all_hits, count_of_hits);
+
+    return E_NOTIMPL;
+}
+
+HRESULT WINAPI D3DXTessellateNPatches(ID3DXMesh *mesh, const DWORD *adjacency_in, float num_segs,
+        BOOL quadratic_normals, ID3DXMesh **mesh_out, ID3DXBuffer **adjacency_out)
 {
-    FIXME("Mesh %p, RayPos %p, RayDir %p, Hit %p, FaceIndex %p, U %p, V %p, Dist %p, AllHits %p, CountOfHits %p stub.\n",
-            Mesh, RayPos, RayDir, Hit, FaceIndex, U, V, Dist, AllHits, CountOfHits);
+    FIXME("mesh %p, adjacency_in %p, num_segs %f, quadratic_normals %d, mesh_out %p, adjacency_out %p stub.\n",
+            mesh, adjacency_in, num_segs, quadratic_normals, mesh_out, adjacency_out);
 
     return E_NOTIMPL;
 }
index 9f0084a..c66f6e0 100644 (file)
@@ -1122,7 +1122,7 @@ static UINT set(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,
             offset = min(desc->Elements - 1, offset);
             last = offset * desc->Rows * desc->Columns;
 
-            if ((is_pointer || (!is_pointer && inclass == D3DXPC_MATRIX_ROWS)) && desc->RegisterSet != D3DXRS_BOOL)
+            if ((is_pointer || inclass == D3DXPC_MATRIX_ROWS) && desc->RegisterSet != D3DXRS_BOOL)
             {
                 set(table, device, &constant->constants[0], NULL, intype, size, incol, inclass, 0, is_pointer);
             }
@@ -1162,7 +1162,7 @@ static UINT set(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device,
              * E.g.: struct {int i; int n} s;
              *       SetValue(device, "s", [1, 2], 8) => s = {1, 0};
              */
-            else if ((is_pointer || (!is_pointer && inclass == D3DXPC_MATRIX_ROWS)) && desc->RegisterSet != D3DXRS_BOOL)
+            else if ((is_pointer || inclass == D3DXPC_MATRIX_ROWS) && desc->RegisterSet != D3DXRS_BOOL)
             {
                 last = set(table, device, &constant->constants[0], indata, intype, size, incol, inclass,
                         index + last, is_pointer);
@@ -2103,6 +2103,27 @@ HRESULT WINAPI D3DXGetShaderConstantTable(const DWORD *byte_code, ID3DXConstantT
     return D3DXGetShaderConstantTableEx(byte_code, 0, constant_table);
 }
 
+HRESULT WINAPI D3DXCreateFragmentLinker(IDirect3DDevice9 *device, UINT size, ID3DXFragmentLinker **linker)
+{
+    FIXME("device %p, size %u, linker %p: stub.\n", device, size, linker);
+
+    if (linker)
+        *linker = NULL;
+
+
+    return E_NOTIMPL;
+}
+
+HRESULT WINAPI D3DXCreateFragmentLinkerEx(IDirect3DDevice9 *device, UINT size, DWORD flags, ID3DXFragmentLinker **linker)
+{
+    FIXME("device %p, size %u, flags %#x, linker %p: stub.\n", device, size, flags, linker);
+
+    if (linker)
+        *linker = NULL;
+
+    return E_NOTIMPL;
+}
+
 HRESULT WINAPI D3DXGetShaderSamplers(const DWORD *byte_code, const char **samplers, UINT *count)
 {
     UINT i, sampler_count = 0;
@@ -2157,7 +2178,7 @@ HRESULT WINAPI D3DXDisassembleShader(const DWORD *shader, BOOL colorcode, const
    return E_OUTOFMEMORY;
 }
 
-const DWORD* skip_instruction(const DWORD *byte_code, UINT shader_model)
+static const DWORD* skip_instruction(const DWORD *byte_code, UINT shader_model)
 {
     TRACE("Shader model %u\n", shader_model);
 
@@ -2177,13 +2198,13 @@ const DWORD* skip_instruction(const DWORD *byte_code, UINT shader_model)
     else
     {
         /* Handle remaining safe instructions */
-        while (*++byte_code & (1 << 31));
+        while (*++byte_code & (1u << 31));
     }
 
     return byte_code;
 }
 
-static UINT get_shader_semantics(const DWORD *byte_code, D3DXSEMANTIC *semantics, BOOL input)
+static UINT get_shader_semantics(const DWORD *byte_code, D3DXSEMANTIC *semantics, DWORD type)
 {
     const DWORD *ptr = byte_code;
     UINT shader_model = (*ptr >> 8) & 0xff;
@@ -2194,7 +2215,7 @@ static UINT get_shader_semantics(const DWORD *byte_code, D3DXSEMANTIC *semantics
 
     while (*ptr != D3DSIO_END)
     {
-        if (*ptr & (1 << 31))
+        if (*ptr & (1u << 31))
         {
             FIXME("Opcode expected but got %#x\n", *ptr);
             return 0;
@@ -2203,14 +2224,15 @@ static UINT get_shader_semantics(const DWORD *byte_code, D3DXSEMANTIC *semantics
         {
             DWORD param1 = *++ptr;
             DWORD param2 = *++ptr;
-            DWORD usage = param1 & 0x1f;
-            DWORD usage_index = (param1 >> 16) & 0xf;
-            DWORD reg_type = (((param2 >> 11) & 0x3) << 3) | ((param2 >> 28) & 0x7);
+            DWORD usage = (param1 & D3DSP_DCL_USAGE_MASK) >> D3DSP_DCL_USAGE_SHIFT;
+            DWORD usage_index = (param1 & D3DSP_DCL_USAGEINDEX_MASK) >> D3DSP_DCL_USAGEINDEX_SHIFT;
+            DWORD reg_type = ((param2 & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2)
+                    | ((param2 & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT);
 
             TRACE("D3DSIO_DCL param1: %#x, param2: %#x, usage: %u, usage_index: %u, reg_type: %u\n",
                    param1, param2, usage, usage_index, reg_type);
 
-            if ((input && (reg_type == D3DSPR_INPUT)) || (!input && (reg_type == D3DSPR_OUTPUT)))
+            if (reg_type == type)
             {
                 if (semantics)
                 {
@@ -2240,7 +2262,7 @@ HRESULT WINAPI D3DXGetShaderInputSemantics(const DWORD *byte_code, D3DXSEMANTIC
     if (!byte_code)
         return D3DERR_INVALIDCALL;
 
-    nb_semantics = get_shader_semantics(byte_code, semantics, TRUE);
+    nb_semantics = get_shader_semantics(byte_code, semantics, D3DSPR_INPUT);
 
     if (count)
         *count = nb_semantics;
@@ -2258,7 +2280,7 @@ HRESULT WINAPI D3DXGetShaderOutputSemantics(const DWORD *byte_code, D3DXSEMANTIC
     if (!byte_code)
         return D3DERR_INVALIDCALL;
 
-    nb_semantics = get_shader_semantics(byte_code, semantics, FALSE);
+    nb_semantics = get_shader_semantics(byte_code, semantics, D3DSPR_OUTPUT);
 
     if (count)
         *count = nb_semantics;
index 32a6f37..e3f8bf2 100644 (file)
@@ -90,7 +90,7 @@ static ULONG WINAPI d3dx9_skin_info_Release(ID3DXSkinInfo *iface)
             HeapFree(GetProcessHeap(), 0, skin->bones[i].vertices);
             HeapFree(GetProcessHeap(), 0, skin->bones[i].weights);
         }
-        HeapFree(GetProcessHeap(), 0, skin->bones);
+        if (skin->bones) HeapFree(GetProcessHeap(), 0, skin->bones);
         HeapFree(GetProcessHeap(), 0, skin);
     }
 
@@ -570,3 +570,23 @@ HRESULT WINAPI D3DXCreateSkinInfoFVF(DWORD num_vertices, DWORD fvf, DWORD num_bo
 
     return D3DXCreateSkinInfo(num_vertices, declaration, num_bones, skin_info);
 }
+
+HRESULT create_dummy_skin(ID3DXSkinInfo **iface)
+{
+    static const D3DVERTEXELEMENT9 empty_declaration = D3DDECL_END();
+    struct d3dx9_skin_info *object = NULL;
+
+    object = HeapAlloc(GetProcessHeap(), 0, sizeof(*object));
+    if (!object) return E_OUTOFMEMORY;
+
+    object->ID3DXSkinInfo_iface.lpVtbl = &d3dx9_skin_info_vtbl;
+    object->ref = 1;
+    object->num_vertices = 0;
+    object->num_bones = 0;
+    object->vertex_declaration[0] = empty_declaration;
+    object->fvf = 0;
+    object->bones = NULL;
+
+    *iface = &object->ID3DXSkinInfo_iface;
+    return D3D_OK;
+}
index 349a108..23fd13c 100644 (file)
@@ -143,15 +143,15 @@ static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
 {
     unsigned int i;
     static const DWORD known_fourcc[] = {
-        MAKEFOURCC('U','Y','V','Y'),
-        MAKEFOURCC('Y','U','Y','2'),
-        MAKEFOURCC('R','G','B','G'),
-        MAKEFOURCC('G','R','G','B'),
-        MAKEFOURCC('D','X','T','1'),
-        MAKEFOURCC('D','X','T','2'),
-        MAKEFOURCC('D','X','T','3'),
-        MAKEFOURCC('D','X','T','4'),
-        MAKEFOURCC('D','X','T','5'),
+        D3DFMT_UYVY,
+        D3DFMT_YUY2,
+        D3DFMT_R8G8_B8G8,
+        D3DFMT_G8R8_G8B8,
+        D3DFMT_DXT1,
+        D3DFMT_DXT2,
+        D3DFMT_DXT3,
+        D3DFMT_DXT4,
+        D3DFMT_DXT5,
         D3DFMT_R16F,
         D3DFMT_G16R16F,
         D3DFMT_A16B16G16R16F,
@@ -395,7 +395,7 @@ static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAG
     info->Width = header->width;
     info->Height = header->height;
     info->Depth = 1;
-    info->MipLevels = (header->flags & DDS_MIPMAPCOUNT) ?  header->miplevels : 1;
+    info->MipLevels = header->miplevels ? header->miplevels : 1;
 
     info->Format = dds_pixel_format_to_d3dformat(&header->pixel_format);
     if (info->Format == D3DFMT_UNKNOWN)
index 51e4a7f..a8841f1 100644 (file)
@@ -26,7 +26,7 @@ reactos/dll/directx/wine/d3d8           # Synced to WineStaging-1.7.47
 reactos/dll/directx/wine/d3d9           # Synced to WineStaging-1.7.47
 reactos/dll/directx/wine/d3dcompiler_43 # Synced to WineStaging-1.7.47
 reactos/dll/directx/wine/d3drm          # Synced to WineStaging-1.7.47
-reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to WineStaging-1.7.47
+reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to WineStaging-1.7.55
 reactos/dll/directx/wine/d3dxof         # Synced to WineStaging-1.7.47
 reactos/dll/directx/wine/ddraw          # Synced to WineStaging-1.7.47
 reactos/dll/directx/wine/devenum        # Synced to WineStaging-1.7.47