2 * Skin Info operations specific to D3DX9.
4 * Copyright (C) 2011 Dylan Smith
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
22 #include "d3dx9_36_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
35 typedef struct ID3DXSkinInfoImpl
37 ID3DXSkinInfo ID3DXSkinInfo_iface
;
41 D3DVERTEXELEMENT9 vertex_declaration
[MAX_FVF_DECL_SIZE
];
47 static inline struct ID3DXSkinInfoImpl
*impl_from_ID3DXSkinInfo(ID3DXSkinInfo
*iface
)
49 return CONTAINING_RECORD(iface
, struct ID3DXSkinInfoImpl
, ID3DXSkinInfo_iface
);
52 static HRESULT WINAPI
ID3DXSkinInfoImpl_QueryInterface(ID3DXSkinInfo
*iface
, REFIID riid
, void **ppobj
)
54 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(riid
), ppobj
);
56 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ID3DXSkinInfo
))
58 IUnknown_AddRef(iface
);
63 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
68 static ULONG WINAPI
ID3DXSkinInfoImpl_AddRef(ID3DXSkinInfo
*iface
)
70 struct ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
71 ULONG ref
= InterlockedIncrement(&This
->ref
);
73 TRACE("%p increasing refcount to %u\n", This
, ref
);
78 static ULONG WINAPI
ID3DXSkinInfoImpl_Release(ID3DXSkinInfo
*iface
)
80 struct ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
81 ULONG ref
= InterlockedDecrement(&This
->ref
);
83 TRACE("%p decreasing refcount to %u\n", This
, ref
);
87 for (i
= 0; i
< This
->num_bones
; i
++) {
88 HeapFree(GetProcessHeap(), 0, This
->bones
[i
].name
);
89 HeapFree(GetProcessHeap(), 0, This
->bones
[i
].vertices
);
90 HeapFree(GetProcessHeap(), 0, This
->bones
[i
].weights
);
92 HeapFree(GetProcessHeap(), 0, This
->bones
);
93 HeapFree(GetProcessHeap(), 0, This
);
99 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
, DWORD num_influences
, CONST DWORD
*vertices
, CONST FLOAT
*weights
)
101 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
103 DWORD
*new_vertices
= NULL
;
104 FLOAT
*new_weights
= NULL
;
106 TRACE("(%p, %u, %u, %p, %p)\n", This
, bone_num
, num_influences
, vertices
, weights
);
108 if (bone_num
>= This
->num_bones
|| !vertices
|| !weights
)
109 return D3DERR_INVALIDCALL
;
111 if (num_influences
) {
112 new_vertices
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*vertices
));
114 return E_OUTOFMEMORY
;
115 new_weights
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*weights
));
117 HeapFree(GetProcessHeap(), 0, new_vertices
);
118 return E_OUTOFMEMORY
;
120 memcpy(new_vertices
, vertices
, num_influences
* sizeof(*vertices
));
121 memcpy(new_weights
, weights
, num_influences
* sizeof(*weights
));
123 bone
= &This
->bones
[bone_num
];
124 bone
->num_influences
= num_influences
;
125 HeapFree(GetProcessHeap(), 0, bone
->vertices
);
126 HeapFree(GetProcessHeap(), 0, bone
->weights
);
127 bone
->vertices
= new_vertices
;
128 bone
->weights
= new_weights
;
133 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneVertexInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
, DWORD influence_num
, float weight
)
135 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
137 FIXME("(%p, %u, %u, %g): stub\n", This
, bone_num
, influence_num
, weight
);
142 static DWORD WINAPI
ID3DXSkinInfoImpl_GetNumBoneInfluences(ID3DXSkinInfo
*iface
, DWORD bone_num
)
144 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
146 TRACE("(%p, %u)\n", This
, bone_num
);
148 if (bone_num
>= This
->num_bones
)
151 return This
->bones
[bone_num
].num_influences
;
154 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetBoneInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
, DWORD
*vertices
, FLOAT
*weights
)
156 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
159 TRACE("(%p, %u, %p, %p)\n", This
, bone_num
, vertices
, weights
);
161 if (bone_num
>= This
->num_bones
|| !vertices
)
162 return D3DERR_INVALIDCALL
;
164 bone
= &This
->bones
[bone_num
];
165 if (!bone
->num_influences
)
168 memcpy(vertices
, bone
->vertices
, bone
->num_influences
* sizeof(*vertices
));
170 memcpy(weights
, bone
->weights
, bone
->num_influences
* sizeof(*weights
));
175 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetBoneVertexInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
,
176 DWORD influence_num
, float *weight
, DWORD
*vertex_num
)
178 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
180 FIXME("(%p, %u, %u, %p, %p): stub\n", This
, bone_num
, influence_num
, weight
, vertex_num
);
185 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetMaxVertexInfluences(ID3DXSkinInfo
*iface
, DWORD
*max_vertex_influences
)
187 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
189 FIXME("(%p, %p): stub\n", This
, max_vertex_influences
);
194 static DWORD WINAPI
ID3DXSkinInfoImpl_GetNumBones(ID3DXSkinInfo
*iface
)
196 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
198 TRACE("(%p)\n", This
);
200 return This
->num_bones
;
203 static HRESULT WINAPI
ID3DXSkinInfoImpl_FindBoneVertexInfluenceIndex(ID3DXSkinInfo
*iface
, DWORD bone_num
,
204 DWORD vertex_num
, DWORD
*influence_index
)
206 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
208 FIXME("(%p, %u, %u, %p): stub\n", This
, bone_num
, vertex_num
, influence_index
);
213 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetMaxFaceInfluences(struct ID3DXSkinInfo
*iface
,
214 struct IDirect3DIndexBuffer9
*index_buffer
, DWORD num_faces
, DWORD
*max_face_influences
)
216 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
218 FIXME("(%p, %p, %u, %p): stub\n", This
, index_buffer
, num_faces
, max_face_influences
);
223 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetMinBoneInfluence(ID3DXSkinInfo
*iface
, FLOAT min_influence
)
225 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
227 FIXME("(%p, %g): stub\n", This
, min_influence
);
232 static FLOAT WINAPI
ID3DXSkinInfoImpl_GetMinBoneInfluence(ID3DXSkinInfo
*iface
)
234 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
236 FIXME("(%p): stub\n", This
);
241 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_num
, LPCSTR name
)
243 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
247 TRACE("(%p, %u, %s)\n", This
, bone_num
, debugstr_a(name
));
249 if (bone_num
>= This
->num_bones
|| !name
)
250 return D3DERR_INVALIDCALL
;
252 size
= strlen(name
) + 1;
253 new_name
= HeapAlloc(GetProcessHeap(), 0, size
);
255 return E_OUTOFMEMORY
;
256 memcpy(new_name
, name
, size
);
257 HeapFree(GetProcessHeap(), 0, This
->bones
[bone_num
].name
);
258 This
->bones
[bone_num
].name
= new_name
;
263 static LPCSTR WINAPI
ID3DXSkinInfoImpl_GetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_num
)
265 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
267 TRACE("(%p, %u)\n", This
, bone_num
);
269 if (bone_num
>= This
->num_bones
)
272 return This
->bones
[bone_num
].name
;
275 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneOffsetMatrix(ID3DXSkinInfo
*iface
, DWORD bone_num
, CONST D3DXMATRIX
*bone_transform
)
277 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
279 TRACE("(%p, %u, %p)\n", This
, bone_num
, bone_transform
);
281 if (bone_num
>= This
->num_bones
|| !bone_transform
)
282 return D3DERR_INVALIDCALL
;
284 This
->bones
[bone_num
].transform
= *bone_transform
;
288 static LPD3DXMATRIX WINAPI
ID3DXSkinInfoImpl_GetBoneOffsetMatrix(ID3DXSkinInfo
*iface
, DWORD bone_num
)
290 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
292 TRACE("(%p, %u)\n", This
, bone_num
);
294 if (bone_num
>= This
->num_bones
)
297 return &This
->bones
[bone_num
].transform
;
300 static HRESULT WINAPI
ID3DXSkinInfoImpl_Clone(ID3DXSkinInfo
*iface
, ID3DXSkinInfo
**skin_info
)
302 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
304 FIXME("(%p, %p): stub\n", This
, skin_info
);
309 static HRESULT WINAPI
ID3DXSkinInfoImpl_Remap(ID3DXSkinInfo
*iface
, DWORD num_vertices
, DWORD
*vertex_remap
)
311 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
313 FIXME("(%p, %u, %p): stub\n", This
, num_vertices
, vertex_remap
);
318 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetFVF(ID3DXSkinInfo
*iface
, DWORD fvf
)
320 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
322 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
324 TRACE("(%p, %x)\n", This
, fvf
);
326 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
327 if (FAILED(hr
)) return hr
;
329 return iface
->lpVtbl
->SetDeclaration(iface
, declaration
);
332 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetDeclaration(ID3DXSkinInfo
*iface
, CONST D3DVERTEXELEMENT9
*declaration
)
334 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
338 TRACE("(%p, %p)\n", This
, declaration
);
341 return D3DERR_INVALIDCALL
;
342 for (count
= 0; declaration
[count
].Stream
!= 0xff; count
++) {
343 if (declaration
[count
].Stream
!= 0) {
344 WARN("Invalid vertex element %u; contains non-zero stream %u\n",
345 count
, declaration
[count
].Stream
);
346 return D3DERR_INVALIDCALL
;
351 memcpy(This
->vertex_declaration
, declaration
, count
* sizeof(*declaration
));
353 hr
= D3DXFVFFromDeclarator(This
->vertex_declaration
, &This
->fvf
);
360 static DWORD WINAPI
ID3DXSkinInfoImpl_GetFVF(ID3DXSkinInfo
*iface
)
362 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
364 TRACE("(%p)\n", This
);
369 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetDeclaration(ID3DXSkinInfo
*iface
, D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
])
371 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
374 TRACE("(%p)\n", This
);
376 while (This
->vertex_declaration
[count
++].Stream
!= 0xff);
377 memcpy(declaration
, This
->vertex_declaration
, count
* sizeof(declaration
[0]));
381 static HRESULT WINAPI
ID3DXSkinInfoImpl_UpdateSkinnedMesh(ID3DXSkinInfo
*iface
, CONST D3DXMATRIX
*bone_transforms
,
382 CONST D3DXMATRIX
*bone_inv_transpose_transforms
, LPCVOID vertices_src
, PVOID vertices_dest
)
384 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
386 FIXME("(%p, %p, %p, %p, %p): stub\n", This
, bone_transforms
, bone_inv_transpose_transforms
, vertices_src
, vertices_dest
);
391 static HRESULT WINAPI
ID3DXSkinInfoImpl_ConvertToBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
392 DWORD options
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
393 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
394 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
396 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
398 FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
399 This
, mesh_in
, options
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
400 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
405 static HRESULT WINAPI
ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
406 DWORD options
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
407 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
408 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
410 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
412 FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
413 This
, mesh_in
, options
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
414 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
419 static const struct ID3DXSkinInfoVtbl ID3DXSkinInfoImpl_Vtbl
=
421 /* IUnknown methods */
422 ID3DXSkinInfoImpl_QueryInterface
,
423 ID3DXSkinInfoImpl_AddRef
,
424 ID3DXSkinInfoImpl_Release
,
426 ID3DXSkinInfoImpl_SetBoneInfluence
,
427 ID3DXSkinInfoImpl_SetBoneVertexInfluence
,
428 ID3DXSkinInfoImpl_GetNumBoneInfluences
,
429 ID3DXSkinInfoImpl_GetBoneInfluence
,
430 ID3DXSkinInfoImpl_GetBoneVertexInfluence
,
431 ID3DXSkinInfoImpl_GetMaxVertexInfluences
,
432 ID3DXSkinInfoImpl_GetNumBones
,
433 ID3DXSkinInfoImpl_FindBoneVertexInfluenceIndex
,
434 ID3DXSkinInfoImpl_GetMaxFaceInfluences
,
435 ID3DXSkinInfoImpl_SetMinBoneInfluence
,
436 ID3DXSkinInfoImpl_GetMinBoneInfluence
,
437 ID3DXSkinInfoImpl_SetBoneName
,
438 ID3DXSkinInfoImpl_GetBoneName
,
439 ID3DXSkinInfoImpl_SetBoneOffsetMatrix
,
440 ID3DXSkinInfoImpl_GetBoneOffsetMatrix
,
441 ID3DXSkinInfoImpl_Clone
,
442 ID3DXSkinInfoImpl_Remap
,
443 ID3DXSkinInfoImpl_SetFVF
,
444 ID3DXSkinInfoImpl_SetDeclaration
,
445 ID3DXSkinInfoImpl_GetFVF
,
446 ID3DXSkinInfoImpl_GetDeclaration
,
447 ID3DXSkinInfoImpl_UpdateSkinnedMesh
,
448 ID3DXSkinInfoImpl_ConvertToBlendedMesh
,
449 ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh
452 HRESULT WINAPI
D3DXCreateSkinInfo(DWORD num_vertices
, const D3DVERTEXELEMENT9
*declaration
,
453 DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
456 ID3DXSkinInfoImpl
*object
= NULL
;
457 static const D3DVERTEXELEMENT9 empty_declaration
= D3DDECL_END();
459 TRACE("(%u, %p, %u, %p)\n", num_vertices
, declaration
, num_bones
, skin_info
);
461 if (!skin_info
|| !declaration
)
462 return D3DERR_INVALIDCALL
;
464 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
466 return E_OUTOFMEMORY
;
468 object
->ID3DXSkinInfo_iface
.lpVtbl
= &ID3DXSkinInfoImpl_Vtbl
;
470 object
->num_vertices
= num_vertices
;
471 object
->num_bones
= num_bones
;
472 object
->vertex_declaration
[0] = empty_declaration
;
475 object
->bones
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_bones
* sizeof(*object
->bones
));
476 if (!object
->bones
) {
481 hr
= ID3DXSkinInfoImpl_SetDeclaration(&object
->ID3DXSkinInfo_iface
, declaration
);
482 if (FAILED(hr
)) goto error
;
484 *skin_info
= &object
->ID3DXSkinInfo_iface
;
488 HeapFree(GetProcessHeap(), 0, object
->bones
);
489 HeapFree(GetProcessHeap(), 0, object
);
493 HRESULT WINAPI
D3DXCreateSkinInfoFVF(DWORD num_vertices
, DWORD fvf
, DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
496 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
498 TRACE("(%u, %x, %u, %p)\n", num_vertices
, fvf
, num_bones
, skin_info
);
500 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
504 return D3DXCreateSkinInfo(num_vertices
, declaration
, num_bones
, skin_info
);