From 999d043e571b74f71640037754669a5642acd238 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Wed, 22 Jun 2011 14:24:12 -0400 Subject: [PATCH] d3dx9: Implement D3DXCreateSkinInfo functions. --- dlls/d3dx9_36/skin.c | 386 ++++++++++++++++++++++++++++++++++++++++++- include/d3dx9mesh.h | 2 +- 2 files changed, 383 insertions(+), 5 deletions(-) diff --git a/dlls/d3dx9_36/skin.c b/dlls/d3dx9_36/skin.c index 24b930eeda..04ccfab783 100644 --- a/dlls/d3dx9_36/skin.c +++ b/dlls/d3dx9_36/skin.c @@ -23,17 +23,395 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3dx); +typedef struct ID3DXSkinInfoImpl +{ + ID3DXSkinInfo ID3DXSkinInfo_iface; + LONG ref; + + DWORD fvf; + D3DVERTEXELEMENT9 vertex_declaration[MAX_FVF_DECL_SIZE]; + DWORD num_vertices; + DWORD num_bones; +} ID3DXSkinInfoImpl; + +static inline struct ID3DXSkinInfoImpl *impl_from_ID3DXSkinInfo(ID3DXSkinInfo *iface) +{ + return CONTAINING_RECORD(iface, struct ID3DXSkinInfoImpl, ID3DXSkinInfo_iface); +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_QueryInterface(ID3DXSkinInfo *iface, REFIID riid, void **ppobj) +{ + TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppobj); + + if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ID3DXSkinInfo)) + { + IUnknown_AddRef(iface); + *ppobj = iface; + return D3D_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid)); + + return E_NOINTERFACE; +} + +static ULONG WINAPI ID3DXSkinInfoImpl_AddRef(ID3DXSkinInfo *iface) +{ + struct ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("%p increasing refcount to %u\n", This, ref); + + return ref; +} + +static ULONG WINAPI ID3DXSkinInfoImpl_Release(ID3DXSkinInfo *iface) +{ + struct ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("%p decreasing refcount to %u\n", This, ref); + + if (ref == 0) { + HeapFree(GetProcessHeap(), 0, This); + } + + return ref; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneInfluence(ID3DXSkinInfo *iface, DWORD bone_num, DWORD num_influences, CONST DWORD *vertices, CONST FLOAT *weights) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %u, %u, %p, %p): stub\n", This, bone_num, num_influences, vertices, weights); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_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); + + return E_NOTIMPL; +} + +static DWORD WINAPI ID3DXSkinInfoImpl_GetNumBoneInfluences(ID3DXSkinInfo *iface, DWORD bone_num) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %u): stub\n", This, bone_num); + + return 0; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_GetBoneInfluence(ID3DXSkinInfo *iface, DWORD bone_num, DWORD *vertices, FLOAT *weights) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %u, %p, %p): stub\n", This, bone_num, vertices, weights); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_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); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_GetMaxVertexInfluences(ID3DXSkinInfo *iface, DWORD *max_vertex_influences) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %p): stub\n", This, max_vertex_influences); + + return E_NOTIMPL; +} + +static DWORD WINAPI ID3DXSkinInfoImpl_GetNumBones(ID3DXSkinInfo *iface) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + TRACE("(%p)\n", This); + + return This->num_bones; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_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); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_GetMaxFaceInfluences(ID3DXSkinInfo *iface, LPDIRECT3DINDEXBUFFER9 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); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_SetMinBoneInfluence(ID3DXSkinInfo *iface, FLOAT min_influence) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %g): stub\n", This, min_influence); + + return E_NOTIMPL; +} + +static FLOAT WINAPI ID3DXSkinInfoImpl_GetMinBoneInfluence(ID3DXSkinInfo *iface) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p): stub\n", This); + + return 0.0f; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneName(ID3DXSkinInfo *iface, DWORD bone_num, LPCSTR name) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %u, %s): stub\n", This, bone_num, debugstr_a(name)); + + return E_NOTIMPL; +} + +static LPCSTR WINAPI ID3DXSkinInfoImpl_GetBoneName(ID3DXSkinInfo *iface, DWORD bone_num) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %u): stub\n", This, bone_num); + + return NULL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneOffsetMatrix(ID3DXSkinInfo *iface, DWORD bone_num, CONST D3DXMATRIX *bone_transform) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %u, %p): stub\n", This, bone_num, bone_transform); + + return E_NOTIMPL; +} + +static LPD3DXMATRIX WINAPI ID3DXSkinInfoImpl_GetBoneOffsetMatrix(ID3DXSkinInfo *iface, DWORD bone_num) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %u): stub\n", This, bone_num); + + return NULL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_Clone(ID3DXSkinInfo *iface, LPD3DXSKININFO *skin_info) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + FIXME("(%p, %p): stub\n", This, skin_info); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_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); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_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); + + hr = D3DXDeclaratorFromFVF(fvf, declaration); + if (FAILED(hr)) return hr; + + return iface->lpVtbl->SetDeclaration(iface, declaration); +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_SetDeclaration(ID3DXSkinInfo *iface, CONST D3DVERTEXELEMENT9 *declaration) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + HRESULT hr; + int count; + + TRACE("(%p, %p)\n", This, declaration); + + if (!declaration) + return D3DERR_INVALIDCALL; + for (count = 0; declaration[count].Stream != 0xff; count++) { + if (declaration[count].Stream != 0) { + WARN("Invalid vertex element %u; contains non-zero stream %u\n", + count, declaration[count].Stream); + return D3DERR_INVALIDCALL; + } + } + count++; + + memcpy(This->vertex_declaration, declaration, count * sizeof(*declaration)); + + hr = D3DXFVFFromDeclarator(This->vertex_declaration, &This->fvf); + if (FAILED(hr)) + This->fvf = 0; + + return D3D_OK; +} + +static DWORD WINAPI ID3DXSkinInfoImpl_GetFVF(ID3DXSkinInfo *iface) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + + TRACE("(%p)\n", This); + + return This->fvf; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_GetDeclaration(ID3DXSkinInfo *iface, D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE]) +{ + ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface); + UINT count = 0; + + TRACE("(%p)\n", This); + + while (This->vertex_declaration[count++].Stream != 0xff); + memcpy(declaration, This->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) +{ + 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); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_ConvertToBlendedMesh(ID3DXSkinInfo *iface, LPD3DXMESH mesh_in, + DWORD options, CONST DWORD *adjacency_in, LPDWORD adjacency_out, DWORD *face_remap, + LPD3DXBUFFER *vertex_remap, DWORD *max_face_infl, DWORD *num_bone_combinations, + LPD3DXBUFFER *bone_combination_table, LPD3DXMESH *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); + + return E_NOTIMPL; +} + +static HRESULT WINAPI ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh(ID3DXSkinInfo *iface, LPD3DXMESH mesh_in, + DWORD options, CONST DWORD *adjacency_in, LPDWORD adjacency_out, DWORD *face_remap, + LPD3DXBUFFER *vertex_remap, DWORD *max_face_infl, DWORD *num_bone_combinations, + LPD3DXBUFFER *bone_combination_table, LPD3DXMESH *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); + + 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 +}; + HRESULT WINAPI D3DXCreateSkinInfo(DWORD num_vertices, CONST D3DVERTEXELEMENT9 *declaration, DWORD num_bones, LPD3DXSKININFO *skin_info) { - FIXME("(%u, %p, %u, %p): stub\n", num_vertices, declaration, num_bones, skin_info); + HRESULT hr; + ID3DXSkinInfoImpl *object = NULL; + static const D3DVERTEXELEMENT9 empty_declaration = D3DDECL_END(); - return E_NOTIMPL; + TRACE("(%u, %p, %u, %p)\n", num_vertices, declaration, num_bones, skin_info); + + if (!skin_info || !declaration) + return D3DERR_INVALIDCALL; + + object = HeapAlloc(GetProcessHeap(), 0, sizeof(*object)); + if (!object) + return E_OUTOFMEMORY; + + object->ID3DXSkinInfo_iface.lpVtbl = &ID3DXSkinInfoImpl_Vtbl; + object->ref = 1; + object->num_vertices = num_vertices; + object->num_bones = num_bones; + object->vertex_declaration[0] = empty_declaration; + object->fvf = 0; + + hr = ID3DXSkinInfoImpl_SetDeclaration(&object->ID3DXSkinInfo_iface, declaration); + if (FAILED(hr)) { + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + *skin_info = &object->ID3DXSkinInfo_iface; + + return D3D_OK; } HRESULT WINAPI D3DXCreateSkinInfoFVF(DWORD num_vertices, DWORD fvf, DWORD num_bones, LPD3DXSKININFO *skin_info) { - FIXME("(%u, %x, %u, %p): stub\n", num_vertices, fvf, num_bones, skin_info); + HRESULT hr; + D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE]; - return E_NOTIMPL; + TRACE("(%u, %x, %u, %p)\n", num_vertices, fvf, num_bones, skin_info); + + hr = D3DXDeclaratorFromFVF(fvf, declaration); + if (FAILED(hr)) + return hr; + + return D3DXCreateSkinInfo(num_vertices, declaration, num_bones, skin_info); } diff --git a/include/d3dx9mesh.h b/include/d3dx9mesh.h index 445272d206..f7be81e294 100644 --- a/include/d3dx9mesh.h +++ b/include/d3dx9mesh.h @@ -515,7 +515,7 @@ DECLARE_INTERFACE_(ID3DXSkinInfo, IUnknown) STDMETHOD(FindBoneVertexInfluenceIndex)(THIS_ DWORD bone_num, DWORD vertex_num, DWORD* influence_index) PURE; STDMETHOD(GetMaxFaceInfluences)(THIS_ LPDIRECT3DINDEXBUFFER9 index_buffer, DWORD num_faces, DWORD* max_face_influences) PURE; STDMETHOD(SetMinBoneInfluence)(THIS_ FLOAT min_influence) PURE; - STDMETHOD_(DWORD, GetMinBoneInfluence)(THIS) PURE; + STDMETHOD_(FLOAT, GetMinBoneInfluence)(THIS) PURE; STDMETHOD(SetBoneName)(THIS_ DWORD bone, LPCSTR name) PURE; STDMETHOD_(LPCSTR, GetBoneName)(THIS_ DWORD bone) PURE; STDMETHOD(SetBoneOffsetMatrix)(THIS_ DWORD bone, CONST D3DXMATRIX* bone_transform) PURE;