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 "d3dx9_36_private.h"
32 typedef struct ID3DXSkinInfoImpl
34 ID3DXSkinInfo ID3DXSkinInfo_iface
;
38 D3DVERTEXELEMENT9 vertex_declaration
[MAX_FVF_DECL_SIZE
];
44 static inline struct ID3DXSkinInfoImpl
*impl_from_ID3DXSkinInfo(ID3DXSkinInfo
*iface
)
46 return CONTAINING_RECORD(iface
, struct ID3DXSkinInfoImpl
, ID3DXSkinInfo_iface
);
49 static HRESULT WINAPI
ID3DXSkinInfoImpl_QueryInterface(ID3DXSkinInfo
*iface
, REFIID riid
, void **ppobj
)
51 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(riid
), ppobj
);
53 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ID3DXSkinInfo
))
55 IUnknown_AddRef(iface
);
60 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
65 static ULONG WINAPI
ID3DXSkinInfoImpl_AddRef(ID3DXSkinInfo
*iface
)
67 struct ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
68 ULONG ref
= InterlockedIncrement(&This
->ref
);
70 TRACE("%p increasing refcount to %u\n", This
, ref
);
75 static ULONG WINAPI
ID3DXSkinInfoImpl_Release(ID3DXSkinInfo
*iface
)
77 struct ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
78 ULONG ref
= InterlockedDecrement(&This
->ref
);
80 TRACE("%p decreasing refcount to %u\n", This
, ref
);
84 for (i
= 0; i
< This
->num_bones
; i
++) {
85 HeapFree(GetProcessHeap(), 0, This
->bones
[i
].name
);
86 HeapFree(GetProcessHeap(), 0, This
->bones
[i
].vertices
);
87 HeapFree(GetProcessHeap(), 0, This
->bones
[i
].weights
);
89 HeapFree(GetProcessHeap(), 0, This
->bones
);
90 HeapFree(GetProcessHeap(), 0, This
);
96 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
, DWORD num_influences
, CONST DWORD
*vertices
, CONST FLOAT
*weights
)
98 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
100 DWORD
*new_vertices
= NULL
;
101 FLOAT
*new_weights
= NULL
;
103 TRACE("(%p, %u, %u, %p, %p)\n", This
, bone_num
, num_influences
, vertices
, weights
);
105 if (bone_num
>= This
->num_bones
|| !vertices
|| !weights
)
106 return D3DERR_INVALIDCALL
;
108 if (num_influences
) {
109 new_vertices
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*vertices
));
111 return E_OUTOFMEMORY
;
112 new_weights
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*weights
));
114 HeapFree(GetProcessHeap(), 0, new_vertices
);
115 return E_OUTOFMEMORY
;
117 memcpy(new_vertices
, vertices
, num_influences
* sizeof(*vertices
));
118 memcpy(new_weights
, weights
, num_influences
* sizeof(*weights
));
120 bone
= &This
->bones
[bone_num
];
121 bone
->num_influences
= num_influences
;
122 HeapFree(GetProcessHeap(), 0, bone
->vertices
);
123 HeapFree(GetProcessHeap(), 0, bone
->weights
);
124 bone
->vertices
= new_vertices
;
125 bone
->weights
= new_weights
;
130 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneVertexInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
, DWORD influence_num
, float weight
)
132 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
134 FIXME("(%p, %u, %u, %g): stub\n", This
, bone_num
, influence_num
, weight
);
139 static DWORD WINAPI
ID3DXSkinInfoImpl_GetNumBoneInfluences(ID3DXSkinInfo
*iface
, DWORD bone_num
)
141 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
143 TRACE("(%p, %u)\n", This
, bone_num
);
145 if (bone_num
>= This
->num_bones
)
148 return This
->bones
[bone_num
].num_influences
;
151 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetBoneInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
, DWORD
*vertices
, FLOAT
*weights
)
153 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
156 TRACE("(%p, %u, %p, %p)\n", This
, bone_num
, vertices
, weights
);
158 if (bone_num
>= This
->num_bones
|| !vertices
)
159 return D3DERR_INVALIDCALL
;
161 bone
= &This
->bones
[bone_num
];
162 if (!bone
->num_influences
)
165 memcpy(vertices
, bone
->vertices
, bone
->num_influences
* sizeof(*vertices
));
167 memcpy(weights
, bone
->weights
, bone
->num_influences
* sizeof(*weights
));
172 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetBoneVertexInfluence(ID3DXSkinInfo
*iface
, DWORD bone_num
,
173 DWORD influence_num
, float *weight
, DWORD
*vertex_num
)
175 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
177 FIXME("(%p, %u, %u, %p, %p): stub\n", This
, bone_num
, influence_num
, weight
, vertex_num
);
182 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetMaxVertexInfluences(ID3DXSkinInfo
*iface
, DWORD
*max_vertex_influences
)
184 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
186 FIXME("(%p, %p): stub\n", This
, max_vertex_influences
);
191 static DWORD WINAPI
ID3DXSkinInfoImpl_GetNumBones(ID3DXSkinInfo
*iface
)
193 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
195 TRACE("(%p)\n", This
);
197 return This
->num_bones
;
200 static HRESULT WINAPI
ID3DXSkinInfoImpl_FindBoneVertexInfluenceIndex(ID3DXSkinInfo
*iface
, DWORD bone_num
,
201 DWORD vertex_num
, DWORD
*influence_index
)
203 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
205 FIXME("(%p, %u, %u, %p): stub\n", This
, bone_num
, vertex_num
, influence_index
);
210 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetMaxFaceInfluences(struct ID3DXSkinInfo
*iface
,
211 struct IDirect3DIndexBuffer9
*index_buffer
, DWORD num_faces
, DWORD
*max_face_influences
)
213 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
215 FIXME("(%p, %p, %u, %p): stub\n", This
, index_buffer
, num_faces
, max_face_influences
);
220 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetMinBoneInfluence(ID3DXSkinInfo
*iface
, FLOAT min_influence
)
222 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
224 FIXME("(%p, %g): stub\n", This
, min_influence
);
229 static FLOAT WINAPI
ID3DXSkinInfoImpl_GetMinBoneInfluence(ID3DXSkinInfo
*iface
)
231 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
233 FIXME("(%p): stub\n", This
);
238 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_num
, LPCSTR name
)
240 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
244 TRACE("(%p, %u, %s)\n", This
, bone_num
, debugstr_a(name
));
246 if (bone_num
>= This
->num_bones
|| !name
)
247 return D3DERR_INVALIDCALL
;
249 size
= strlen(name
) + 1;
250 new_name
= HeapAlloc(GetProcessHeap(), 0, size
);
252 return E_OUTOFMEMORY
;
253 memcpy(new_name
, name
, size
);
254 HeapFree(GetProcessHeap(), 0, This
->bones
[bone_num
].name
);
255 This
->bones
[bone_num
].name
= new_name
;
260 static LPCSTR WINAPI
ID3DXSkinInfoImpl_GetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_num
)
262 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
264 TRACE("(%p, %u)\n", This
, bone_num
);
266 if (bone_num
>= This
->num_bones
)
269 return This
->bones
[bone_num
].name
;
272 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetBoneOffsetMatrix(ID3DXSkinInfo
*iface
, DWORD bone_num
, CONST D3DXMATRIX
*bone_transform
)
274 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
276 TRACE("(%p, %u, %p)\n", This
, bone_num
, bone_transform
);
278 if (bone_num
>= This
->num_bones
|| !bone_transform
)
279 return D3DERR_INVALIDCALL
;
281 This
->bones
[bone_num
].transform
= *bone_transform
;
285 static D3DXMATRIX
* WINAPI
ID3DXSkinInfoImpl_GetBoneOffsetMatrix(ID3DXSkinInfo
*iface
, DWORD bone_num
)
287 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
289 TRACE("(%p, %u)\n", This
, bone_num
);
291 if (bone_num
>= This
->num_bones
)
294 return &This
->bones
[bone_num
].transform
;
297 static HRESULT WINAPI
ID3DXSkinInfoImpl_Clone(ID3DXSkinInfo
*iface
, ID3DXSkinInfo
**skin_info
)
299 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
301 FIXME("(%p, %p): stub\n", This
, skin_info
);
306 static HRESULT WINAPI
ID3DXSkinInfoImpl_Remap(ID3DXSkinInfo
*iface
, DWORD num_vertices
, DWORD
*vertex_remap
)
308 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
310 FIXME("(%p, %u, %p): stub\n", This
, num_vertices
, vertex_remap
);
315 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetFVF(ID3DXSkinInfo
*iface
, DWORD fvf
)
317 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
319 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
321 TRACE("(%p, %x)\n", This
, fvf
);
323 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
324 if (FAILED(hr
)) return hr
;
326 return iface
->lpVtbl
->SetDeclaration(iface
, declaration
);
329 static HRESULT WINAPI
ID3DXSkinInfoImpl_SetDeclaration(ID3DXSkinInfo
*iface
, CONST D3DVERTEXELEMENT9
*declaration
)
331 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
335 TRACE("(%p, %p)\n", This
, declaration
);
338 return D3DERR_INVALIDCALL
;
339 for (count
= 0; declaration
[count
].Stream
!= 0xff; count
++) {
340 if (declaration
[count
].Stream
!= 0) {
341 WARN("Invalid vertex element %u; contains non-zero stream %u\n",
342 count
, declaration
[count
].Stream
);
343 return D3DERR_INVALIDCALL
;
348 memcpy(This
->vertex_declaration
, declaration
, count
* sizeof(*declaration
));
350 hr
= D3DXFVFFromDeclarator(This
->vertex_declaration
, &This
->fvf
);
357 static DWORD WINAPI
ID3DXSkinInfoImpl_GetFVF(ID3DXSkinInfo
*iface
)
359 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
361 TRACE("(%p)\n", This
);
366 static HRESULT WINAPI
ID3DXSkinInfoImpl_GetDeclaration(ID3DXSkinInfo
*iface
, D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
])
368 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
371 TRACE("(%p)\n", This
);
373 while (This
->vertex_declaration
[count
++].Stream
!= 0xff);
374 memcpy(declaration
, This
->vertex_declaration
, count
* sizeof(declaration
[0]));
378 static HRESULT WINAPI
ID3DXSkinInfoImpl_UpdateSkinnedMesh(ID3DXSkinInfo
*iface
, CONST D3DXMATRIX
*bone_transforms
,
379 CONST D3DXMATRIX
*bone_inv_transpose_transforms
, LPCVOID vertices_src
, PVOID vertices_dest
)
381 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
383 FIXME("(%p, %p, %p, %p, %p): stub\n", This
, bone_transforms
, bone_inv_transpose_transforms
, vertices_src
, vertices_dest
);
388 static HRESULT WINAPI
ID3DXSkinInfoImpl_ConvertToBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
389 DWORD options
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
390 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
391 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
393 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
395 FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
396 This
, mesh_in
, options
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
397 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
402 static HRESULT WINAPI
ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
403 DWORD options
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
404 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
405 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
407 ID3DXSkinInfoImpl
*This
= impl_from_ID3DXSkinInfo(iface
);
409 FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
410 This
, mesh_in
, options
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
411 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
416 static const struct ID3DXSkinInfoVtbl ID3DXSkinInfoImpl_Vtbl
=
418 /* IUnknown methods */
419 ID3DXSkinInfoImpl_QueryInterface
,
420 ID3DXSkinInfoImpl_AddRef
,
421 ID3DXSkinInfoImpl_Release
,
423 ID3DXSkinInfoImpl_SetBoneInfluence
,
424 ID3DXSkinInfoImpl_SetBoneVertexInfluence
,
425 ID3DXSkinInfoImpl_GetNumBoneInfluences
,
426 ID3DXSkinInfoImpl_GetBoneInfluence
,
427 ID3DXSkinInfoImpl_GetBoneVertexInfluence
,
428 ID3DXSkinInfoImpl_GetMaxVertexInfluences
,
429 ID3DXSkinInfoImpl_GetNumBones
,
430 ID3DXSkinInfoImpl_FindBoneVertexInfluenceIndex
,
431 ID3DXSkinInfoImpl_GetMaxFaceInfluences
,
432 ID3DXSkinInfoImpl_SetMinBoneInfluence
,
433 ID3DXSkinInfoImpl_GetMinBoneInfluence
,
434 ID3DXSkinInfoImpl_SetBoneName
,
435 ID3DXSkinInfoImpl_GetBoneName
,
436 ID3DXSkinInfoImpl_SetBoneOffsetMatrix
,
437 ID3DXSkinInfoImpl_GetBoneOffsetMatrix
,
438 ID3DXSkinInfoImpl_Clone
,
439 ID3DXSkinInfoImpl_Remap
,
440 ID3DXSkinInfoImpl_SetFVF
,
441 ID3DXSkinInfoImpl_SetDeclaration
,
442 ID3DXSkinInfoImpl_GetFVF
,
443 ID3DXSkinInfoImpl_GetDeclaration
,
444 ID3DXSkinInfoImpl_UpdateSkinnedMesh
,
445 ID3DXSkinInfoImpl_ConvertToBlendedMesh
,
446 ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh
449 HRESULT WINAPI
D3DXCreateSkinInfo(DWORD num_vertices
, const D3DVERTEXELEMENT9
*declaration
,
450 DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
453 ID3DXSkinInfoImpl
*object
= NULL
;
454 static const D3DVERTEXELEMENT9 empty_declaration
= D3DDECL_END();
456 TRACE("(%u, %p, %u, %p)\n", num_vertices
, declaration
, num_bones
, skin_info
);
458 if (!skin_info
|| !declaration
)
459 return D3DERR_INVALIDCALL
;
461 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
463 return E_OUTOFMEMORY
;
465 object
->ID3DXSkinInfo_iface
.lpVtbl
= &ID3DXSkinInfoImpl_Vtbl
;
467 object
->num_vertices
= num_vertices
;
468 object
->num_bones
= num_bones
;
469 object
->vertex_declaration
[0] = empty_declaration
;
472 object
->bones
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_bones
* sizeof(*object
->bones
));
473 if (!object
->bones
) {
478 hr
= ID3DXSkinInfoImpl_SetDeclaration(&object
->ID3DXSkinInfo_iface
, declaration
);
479 if (FAILED(hr
)) goto error
;
481 *skin_info
= &object
->ID3DXSkinInfo_iface
;
485 HeapFree(GetProcessHeap(), 0, object
->bones
);
486 HeapFree(GetProcessHeap(), 0, object
);
490 HRESULT WINAPI
D3DXCreateSkinInfoFVF(DWORD num_vertices
, DWORD fvf
, DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
493 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
495 TRACE("(%u, %x, %u, %p)\n", num_vertices
, fvf
, num_bones
, skin_info
);
497 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
501 return D3DXCreateSkinInfo(num_vertices
, declaration
, num_bones
, skin_info
);