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
22 #include "d3dx9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
35 struct d3dx9_skin_info
37 ID3DXSkinInfo ID3DXSkinInfo_iface
;
41 D3DVERTEXELEMENT9 vertex_declaration
[MAX_FVF_DECL_SIZE
];
47 static inline struct d3dx9_skin_info
*impl_from_ID3DXSkinInfo(ID3DXSkinInfo
*iface
)
49 return CONTAINING_RECORD(iface
, struct d3dx9_skin_info
, ID3DXSkinInfo_iface
);
52 static HRESULT WINAPI
d3dx9_skin_info_QueryInterface(ID3DXSkinInfo
*iface
, REFIID riid
, void **out
)
54 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
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
d3dx9_skin_info_AddRef(ID3DXSkinInfo
*iface
)
70 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
71 ULONG refcount
= InterlockedIncrement(&skin
->ref
);
73 TRACE("%p increasing refcount to %u.\n", skin
, refcount
);
78 static ULONG WINAPI
d3dx9_skin_info_Release(ID3DXSkinInfo
*iface
)
80 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
81 ULONG refcount
= InterlockedDecrement(&skin
->ref
);
83 TRACE("%p decreasing refcount to %u.\n", skin
, refcount
);
89 for (i
= 0; i
< skin
->num_bones
; ++i
)
91 HeapFree(GetProcessHeap(), 0, skin
->bones
[i
].name
);
92 HeapFree(GetProcessHeap(), 0, skin
->bones
[i
].vertices
);
93 HeapFree(GetProcessHeap(), 0, skin
->bones
[i
].weights
);
95 HeapFree(GetProcessHeap(), 0, skin
->bones
);
96 HeapFree(GetProcessHeap(), 0, skin
);
102 static HRESULT WINAPI
d3dx9_skin_info_SetBoneInfluence(ID3DXSkinInfo
*iface
,
103 DWORD bone_num
, DWORD num_influences
, const DWORD
*vertices
, const float *weights
)
105 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
107 DWORD
*new_vertices
= NULL
;
108 FLOAT
*new_weights
= NULL
;
110 TRACE("iface %p, bone_num %u, num_influences %u, vertices %p, weights %p.\n",
111 iface
, bone_num
, num_influences
, vertices
, weights
);
113 if (bone_num
>= skin
->num_bones
|| !vertices
|| !weights
)
114 return D3DERR_INVALIDCALL
;
116 if (num_influences
) {
117 new_vertices
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*vertices
));
119 return E_OUTOFMEMORY
;
120 new_weights
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*weights
));
122 HeapFree(GetProcessHeap(), 0, new_vertices
);
123 return E_OUTOFMEMORY
;
125 memcpy(new_vertices
, vertices
, num_influences
* sizeof(*vertices
));
126 memcpy(new_weights
, weights
, num_influences
* sizeof(*weights
));
128 bone
= &skin
->bones
[bone_num
];
129 bone
->num_influences
= num_influences
;
130 HeapFree(GetProcessHeap(), 0, bone
->vertices
);
131 HeapFree(GetProcessHeap(), 0, bone
->weights
);
132 bone
->vertices
= new_vertices
;
133 bone
->weights
= new_weights
;
138 static HRESULT WINAPI
d3dx9_skin_info_SetBoneVertexInfluence(ID3DXSkinInfo
*iface
,
139 DWORD bone_num
, DWORD influence_num
, float weight
)
141 FIXME("iface %p, bone_num %u, influence_num %u, weight %.8e stub!\n",
142 iface
, bone_num
, influence_num
, weight
);
147 static DWORD WINAPI
d3dx9_skin_info_GetNumBoneInfluences(ID3DXSkinInfo
*iface
, DWORD bone_num
)
149 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
151 TRACE("iface %p, bone_num %u.\n", iface
, bone_num
);
153 if (bone_num
>= skin
->num_bones
)
156 return skin
->bones
[bone_num
].num_influences
;
159 static HRESULT WINAPI
d3dx9_skin_info_GetBoneInfluence(ID3DXSkinInfo
*iface
,
160 DWORD bone_num
, DWORD
*vertices
, float *weights
)
162 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
165 TRACE("iface %p, bone_num %u, vertices %p, weights %p.\n",
166 iface
, bone_num
, vertices
, weights
);
168 if (bone_num
>= skin
->num_bones
|| !vertices
)
169 return D3DERR_INVALIDCALL
;
171 bone
= &skin
->bones
[bone_num
];
172 if (!bone
->num_influences
)
175 memcpy(vertices
, bone
->vertices
, bone
->num_influences
* sizeof(*vertices
));
177 memcpy(weights
, bone
->weights
, bone
->num_influences
* sizeof(*weights
));
182 static HRESULT WINAPI
d3dx9_skin_info_GetBoneVertexInfluence(ID3DXSkinInfo
*iface
,
183 DWORD bone_num
, DWORD influence_num
, float *weight
, DWORD
*vertex_num
)
185 FIXME("iface %p, bone_num %u, influence_num %u, weight %p, vertex_num %p stub!\n",
186 iface
, bone_num
, influence_num
, weight
, vertex_num
);
191 static HRESULT WINAPI
d3dx9_skin_info_GetMaxVertexInfluences(ID3DXSkinInfo
*iface
, DWORD
*max_vertex_influences
)
193 FIXME("iface %p, max_vertex_influences %p stub!\n", iface
, max_vertex_influences
);
198 static DWORD WINAPI
d3dx9_skin_info_GetNumBones(ID3DXSkinInfo
*iface
)
200 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
202 TRACE("iface %p.\n", iface
);
204 return skin
->num_bones
;
207 static HRESULT WINAPI
d3dx9_skin_info_FindBoneVertexInfluenceIndex(ID3DXSkinInfo
*iface
,
208 DWORD bone_num
, DWORD vertex_num
, DWORD
*influence_index
)
210 FIXME("iface %p, bone_num %u, vertex_num %u, influence_index %p stub!\n",
211 iface
, bone_num
, vertex_num
, influence_index
);
216 static HRESULT WINAPI
d3dx9_skin_info_GetMaxFaceInfluences(struct ID3DXSkinInfo
*iface
,
217 struct IDirect3DIndexBuffer9
*index_buffer
, DWORD num_faces
, DWORD
*max_face_influences
)
219 FIXME("iface %p, index_buffer %p, num_faces %u, max_face_influences %p stub!\n",
220 iface
, index_buffer
, num_faces
, max_face_influences
);
225 static HRESULT WINAPI
d3dx9_skin_info_SetMinBoneInfluence(ID3DXSkinInfo
*iface
, float min_influence
)
227 FIXME("iface %p, min_influence %.8e stub!\n", iface
, min_influence
);
232 static float WINAPI
d3dx9_skin_info_GetMinBoneInfluence(ID3DXSkinInfo
*iface
)
234 FIXME("iface %p stub!\n", iface
);
239 static HRESULT WINAPI
d3dx9_skin_info_SetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_idx
, const char *name
)
241 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
245 TRACE("iface %p, bone_idx %u, name %s.\n", iface
, bone_idx
, debugstr_a(name
));
247 if (bone_idx
>= skin
->num_bones
|| !name
)
248 return D3DERR_INVALIDCALL
;
250 size
= strlen(name
) + 1;
251 new_name
= HeapAlloc(GetProcessHeap(), 0, size
);
253 return E_OUTOFMEMORY
;
254 memcpy(new_name
, name
, size
);
255 HeapFree(GetProcessHeap(), 0, skin
->bones
[bone_idx
].name
);
256 skin
->bones
[bone_idx
].name
= new_name
;
261 static const char * WINAPI
d3dx9_skin_info_GetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_idx
)
263 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
265 TRACE("iface %p, bone_idx %u.\n", iface
, bone_idx
);
267 if (bone_idx
>= skin
->num_bones
)
270 return skin
->bones
[bone_idx
].name
;
273 static HRESULT WINAPI
d3dx9_skin_info_SetBoneOffsetMatrix(ID3DXSkinInfo
*iface
,
274 DWORD bone_num
, const D3DXMATRIX
*bone_transform
)
276 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
278 TRACE("iface %p, bone_num %u, bone_transform %p.\n", iface
, bone_num
, bone_transform
);
280 if (bone_num
>= skin
->num_bones
|| !bone_transform
)
281 return D3DERR_INVALIDCALL
;
283 skin
->bones
[bone_num
].transform
= *bone_transform
;
287 static D3DXMATRIX
* WINAPI
d3dx9_skin_info_GetBoneOffsetMatrix(ID3DXSkinInfo
*iface
, DWORD bone_num
)
289 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
291 TRACE("iface %p, bone_num %u.\n", iface
, bone_num
);
293 if (bone_num
>= skin
->num_bones
)
296 return &skin
->bones
[bone_num
].transform
;
299 static HRESULT WINAPI
d3dx9_skin_info_Clone(ID3DXSkinInfo
*iface
, ID3DXSkinInfo
**skin_info
)
301 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
305 TRACE("iface %p, skin_info %p.\n", iface
, skin_info
);
307 if (FAILED(hr
= D3DXCreateSkinInfo(skin
->num_vertices
, skin
->vertex_declaration
, skin
->num_bones
, skin_info
)))
310 for (i
= 0; i
< skin
->num_bones
; ++i
)
312 struct bone
*current_bone
= &skin
->bones
[i
];
314 if (current_bone
->name
&& FAILED(hr
= (*skin_info
)->lpVtbl
->SetBoneName(*skin_info
, i
, current_bone
->name
)))
316 if (FAILED(hr
= (*skin_info
)->lpVtbl
->SetBoneOffsetMatrix(*skin_info
, i
, ¤t_bone
->transform
)))
318 if (current_bone
->vertices
&& current_bone
->weights
319 && FAILED(hr
= (*skin_info
)->lpVtbl
->SetBoneInfluence(*skin_info
, i
, current_bone
->num_influences
,
320 current_bone
->vertices
, current_bone
->weights
)))
325 (*skin_info
)->lpVtbl
->Release(*skin_info
);
330 static HRESULT WINAPI
d3dx9_skin_info_Remap(ID3DXSkinInfo
*iface
, DWORD num_vertices
, DWORD
*vertex_remap
)
332 FIXME("iface %p, num_vertices %u, vertex_remap %p stub!\n", iface
, num_vertices
, vertex_remap
);
337 static HRESULT WINAPI
d3dx9_skin_info_SetFVF(ID3DXSkinInfo
*iface
, DWORD fvf
)
340 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
342 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
344 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
345 if (FAILED(hr
)) return hr
;
347 return iface
->lpVtbl
->SetDeclaration(iface
, declaration
);
350 static HRESULT WINAPI
d3dx9_skin_info_SetDeclaration(ID3DXSkinInfo
*iface
, const D3DVERTEXELEMENT9
*declaration
)
352 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
356 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
359 return D3DERR_INVALIDCALL
;
360 for (count
= 0; declaration
[count
].Stream
!= 0xff; count
++) {
361 if (declaration
[count
].Stream
!= 0) {
362 WARN("Invalid vertex element %u; contains non-zero stream %u\n",
363 count
, declaration
[count
].Stream
);
364 return D3DERR_INVALIDCALL
;
369 memcpy(skin
->vertex_declaration
, declaration
, count
* sizeof(*declaration
));
371 if (FAILED(hr
= D3DXFVFFromDeclarator(skin
->vertex_declaration
, &skin
->fvf
)))
377 static DWORD WINAPI
d3dx9_skin_info_GetFVF(ID3DXSkinInfo
*iface
)
379 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
381 TRACE("iface %p.\n", iface
);
386 static HRESULT WINAPI
d3dx9_skin_info_GetDeclaration(ID3DXSkinInfo
*iface
,
387 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
])
389 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
392 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
394 while (skin
->vertex_declaration
[count
++].Stream
!= 0xff);
395 memcpy(declaration
, skin
->vertex_declaration
, count
* sizeof(declaration
[0]));
399 static HRESULT WINAPI
d3dx9_skin_info_UpdateSkinnedMesh(ID3DXSkinInfo
*iface
, const D3DXMATRIX
*bone_transforms
,
400 const D3DXMATRIX
*bone_inv_transpose_transforms
, const void *src_vertices
, void *dst_vertices
)
402 FIXME("iface %p, bone_transforms %p, bone_inv_transpose_transforms %p, src_vertices %p, dst_vertices %p stub!\n",
403 iface
, bone_transforms
, bone_inv_transpose_transforms
, src_vertices
, dst_vertices
);
408 static HRESULT WINAPI
d3dx9_skin_info_ConvertToBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
409 DWORD options
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
410 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
411 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
413 FIXME("iface %p, mesh_in %p, options %#x, adjacency_in %p, adjacency_out %p, face_remap %p, vertex_remap %p, "
414 "max_face_infl %p, num_bone_combinations %p, bone_combination_table %p, mesh_out %p stub!\n",
415 iface
, mesh_in
, options
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
416 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
421 static HRESULT WINAPI
d3dx9_skin_info_ConvertToIndexedBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
422 DWORD options
, DWORD palette_size
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
423 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
424 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
426 FIXME("iface %p, mesh_in %p, options %#x, palette_size %u, adjacency_in %p, adjacency_out %p, face_remap %p, vertex_remap %p, "
427 "max_face_infl %p, num_bone_combinations %p, bone_combination_table %p, mesh_out %p stub!\n",
428 iface
, mesh_in
, options
, palette_size
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
429 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
434 static const struct ID3DXSkinInfoVtbl d3dx9_skin_info_vtbl
=
436 d3dx9_skin_info_QueryInterface
,
437 d3dx9_skin_info_AddRef
,
438 d3dx9_skin_info_Release
,
439 d3dx9_skin_info_SetBoneInfluence
,
440 d3dx9_skin_info_SetBoneVertexInfluence
,
441 d3dx9_skin_info_GetNumBoneInfluences
,
442 d3dx9_skin_info_GetBoneInfluence
,
443 d3dx9_skin_info_GetBoneVertexInfluence
,
444 d3dx9_skin_info_GetMaxVertexInfluences
,
445 d3dx9_skin_info_GetNumBones
,
446 d3dx9_skin_info_FindBoneVertexInfluenceIndex
,
447 d3dx9_skin_info_GetMaxFaceInfluences
,
448 d3dx9_skin_info_SetMinBoneInfluence
,
449 d3dx9_skin_info_GetMinBoneInfluence
,
450 d3dx9_skin_info_SetBoneName
,
451 d3dx9_skin_info_GetBoneName
,
452 d3dx9_skin_info_SetBoneOffsetMatrix
,
453 d3dx9_skin_info_GetBoneOffsetMatrix
,
454 d3dx9_skin_info_Clone
,
455 d3dx9_skin_info_Remap
,
456 d3dx9_skin_info_SetFVF
,
457 d3dx9_skin_info_SetDeclaration
,
458 d3dx9_skin_info_GetFVF
,
459 d3dx9_skin_info_GetDeclaration
,
460 d3dx9_skin_info_UpdateSkinnedMesh
,
461 d3dx9_skin_info_ConvertToBlendedMesh
,
462 d3dx9_skin_info_ConvertToIndexedBlendedMesh
,
465 HRESULT WINAPI
D3DXCreateSkinInfo(DWORD num_vertices
, const D3DVERTEXELEMENT9
*declaration
,
466 DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
469 static const D3DVERTEXELEMENT9 empty_declaration
= D3DDECL_END();
470 struct d3dx9_skin_info
*object
= NULL
;
472 TRACE("num_vertices %u, declaration %p, num_bones %u, skin_info %p.\n",
473 num_vertices
, declaration
, num_bones
, skin_info
);
475 if (!skin_info
|| !declaration
)
476 return D3DERR_INVALIDCALL
;
478 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
480 return E_OUTOFMEMORY
;
482 object
->ID3DXSkinInfo_iface
.lpVtbl
= &d3dx9_skin_info_vtbl
;
484 object
->num_vertices
= num_vertices
;
485 object
->num_bones
= num_bones
;
486 object
->vertex_declaration
[0] = empty_declaration
;
489 object
->bones
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_bones
* sizeof(*object
->bones
));
490 if (!object
->bones
) {
495 if (FAILED(hr
= d3dx9_skin_info_SetDeclaration(&object
->ID3DXSkinInfo_iface
, declaration
)))
498 *skin_info
= &object
->ID3DXSkinInfo_iface
;
502 HeapFree(GetProcessHeap(), 0, object
->bones
);
503 HeapFree(GetProcessHeap(), 0, object
);
507 HRESULT WINAPI
D3DXCreateSkinInfoFVF(DWORD num_vertices
, DWORD fvf
, DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
510 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
512 TRACE("(%u, %x, %u, %p)\n", num_vertices
, fvf
, num_bones
, skin_info
);
514 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
518 return D3DXCreateSkinInfo(num_vertices
, declaration
, num_bones
, skin_info
);