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 "wine/port.h"
24 #include "d3dx9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
37 struct d3dx9_skin_info
39 ID3DXSkinInfo ID3DXSkinInfo_iface
;
43 D3DVERTEXELEMENT9 vertex_declaration
[MAX_FVF_DECL_SIZE
];
49 static inline struct d3dx9_skin_info
*impl_from_ID3DXSkinInfo(ID3DXSkinInfo
*iface
)
51 return CONTAINING_RECORD(iface
, struct d3dx9_skin_info
, ID3DXSkinInfo_iface
);
54 static HRESULT WINAPI
d3dx9_skin_info_QueryInterface(ID3DXSkinInfo
*iface
, REFIID riid
, void **out
)
56 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
58 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ID3DXSkinInfo
))
60 IUnknown_AddRef(iface
);
65 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
70 static ULONG WINAPI
d3dx9_skin_info_AddRef(ID3DXSkinInfo
*iface
)
72 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
73 ULONG refcount
= InterlockedIncrement(&skin
->ref
);
75 TRACE("%p increasing refcount to %u.\n", skin
, refcount
);
80 static ULONG WINAPI
d3dx9_skin_info_Release(ID3DXSkinInfo
*iface
)
82 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
83 ULONG refcount
= InterlockedDecrement(&skin
->ref
);
85 TRACE("%p decreasing refcount to %u.\n", skin
, refcount
);
91 for (i
= 0; i
< skin
->num_bones
; ++i
)
93 HeapFree(GetProcessHeap(), 0, skin
->bones
[i
].name
);
94 HeapFree(GetProcessHeap(), 0, skin
->bones
[i
].vertices
);
95 HeapFree(GetProcessHeap(), 0, skin
->bones
[i
].weights
);
97 HeapFree(GetProcessHeap(), 0, skin
->bones
);
98 HeapFree(GetProcessHeap(), 0, skin
);
104 static HRESULT WINAPI
d3dx9_skin_info_SetBoneInfluence(ID3DXSkinInfo
*iface
,
105 DWORD bone_num
, DWORD num_influences
, const DWORD
*vertices
, const float *weights
)
107 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
109 DWORD
*new_vertices
= NULL
;
110 FLOAT
*new_weights
= NULL
;
112 TRACE("iface %p, bone_num %u, num_influences %u, vertices %p, weights %p.\n",
113 iface
, bone_num
, num_influences
, vertices
, weights
);
115 if (bone_num
>= skin
->num_bones
|| !vertices
|| !weights
)
116 return D3DERR_INVALIDCALL
;
118 if (num_influences
) {
119 new_vertices
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*vertices
));
121 return E_OUTOFMEMORY
;
122 new_weights
= HeapAlloc(GetProcessHeap(), 0, num_influences
* sizeof(*weights
));
124 HeapFree(GetProcessHeap(), 0, new_vertices
);
125 return E_OUTOFMEMORY
;
127 memcpy(new_vertices
, vertices
, num_influences
* sizeof(*vertices
));
128 memcpy(new_weights
, weights
, num_influences
* sizeof(*weights
));
130 bone
= &skin
->bones
[bone_num
];
131 bone
->num_influences
= num_influences
;
132 HeapFree(GetProcessHeap(), 0, bone
->vertices
);
133 HeapFree(GetProcessHeap(), 0, bone
->weights
);
134 bone
->vertices
= new_vertices
;
135 bone
->weights
= new_weights
;
140 static HRESULT WINAPI
d3dx9_skin_info_SetBoneVertexInfluence(ID3DXSkinInfo
*iface
,
141 DWORD bone_num
, DWORD influence_num
, float weight
)
143 FIXME("iface %p, bone_num %u, influence_num %u, weight %.8e stub!\n",
144 iface
, bone_num
, influence_num
, weight
);
149 static DWORD WINAPI
d3dx9_skin_info_GetNumBoneInfluences(ID3DXSkinInfo
*iface
, DWORD bone_num
)
151 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
153 TRACE("iface %p, bone_num %u.\n", iface
, bone_num
);
155 if (bone_num
>= skin
->num_bones
)
158 return skin
->bones
[bone_num
].num_influences
;
161 static HRESULT WINAPI
d3dx9_skin_info_GetBoneInfluence(ID3DXSkinInfo
*iface
,
162 DWORD bone_num
, DWORD
*vertices
, float *weights
)
164 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
167 TRACE("iface %p, bone_num %u, vertices %p, weights %p.\n",
168 iface
, bone_num
, vertices
, weights
);
170 if (bone_num
>= skin
->num_bones
|| !vertices
)
171 return D3DERR_INVALIDCALL
;
173 bone
= &skin
->bones
[bone_num
];
174 if (!bone
->num_influences
)
177 memcpy(vertices
, bone
->vertices
, bone
->num_influences
* sizeof(*vertices
));
179 memcpy(weights
, bone
->weights
, bone
->num_influences
* sizeof(*weights
));
184 static HRESULT WINAPI
d3dx9_skin_info_GetBoneVertexInfluence(ID3DXSkinInfo
*iface
,
185 DWORD bone_num
, DWORD influence_num
, float *weight
, DWORD
*vertex_num
)
187 FIXME("iface %p, bone_num %u, influence_num %u, weight %p, vertex_num %p stub!\n",
188 iface
, bone_num
, influence_num
, weight
, vertex_num
);
193 static HRESULT WINAPI
d3dx9_skin_info_GetMaxVertexInfluences(ID3DXSkinInfo
*iface
, DWORD
*max_vertex_influences
)
195 FIXME("iface %p, max_vertex_influences %p stub!\n", iface
, max_vertex_influences
);
200 static DWORD WINAPI
d3dx9_skin_info_GetNumBones(ID3DXSkinInfo
*iface
)
202 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
204 TRACE("iface %p.\n", iface
);
206 return skin
->num_bones
;
209 static HRESULT WINAPI
d3dx9_skin_info_FindBoneVertexInfluenceIndex(ID3DXSkinInfo
*iface
,
210 DWORD bone_num
, DWORD vertex_num
, DWORD
*influence_index
)
212 FIXME("iface %p, bone_num %u, vertex_num %u, influence_index %p stub!\n",
213 iface
, bone_num
, vertex_num
, influence_index
);
218 static HRESULT WINAPI
d3dx9_skin_info_GetMaxFaceInfluences(struct ID3DXSkinInfo
*iface
,
219 struct IDirect3DIndexBuffer9
*index_buffer
, DWORD num_faces
, DWORD
*max_face_influences
)
221 FIXME("iface %p, index_buffer %p, num_faces %u, max_face_influences %p stub!\n",
222 iface
, index_buffer
, num_faces
, max_face_influences
);
227 static HRESULT WINAPI
d3dx9_skin_info_SetMinBoneInfluence(ID3DXSkinInfo
*iface
, float min_influence
)
229 FIXME("iface %p, min_influence %.8e stub!\n", iface
, min_influence
);
234 static float WINAPI
d3dx9_skin_info_GetMinBoneInfluence(ID3DXSkinInfo
*iface
)
236 FIXME("iface %p stub!\n", iface
);
241 static HRESULT WINAPI
d3dx9_skin_info_SetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_idx
, const char *name
)
243 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
247 TRACE("iface %p, bone_idx %u, name %s.\n", iface
, bone_idx
, debugstr_a(name
));
249 if (bone_idx
>= skin
->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, skin
->bones
[bone_idx
].name
);
258 skin
->bones
[bone_idx
].name
= new_name
;
263 static const char * WINAPI
d3dx9_skin_info_GetBoneName(ID3DXSkinInfo
*iface
, DWORD bone_idx
)
265 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
267 TRACE("iface %p, bone_idx %u.\n", iface
, bone_idx
);
269 if (bone_idx
>= skin
->num_bones
)
272 return skin
->bones
[bone_idx
].name
;
275 static HRESULT WINAPI
d3dx9_skin_info_SetBoneOffsetMatrix(ID3DXSkinInfo
*iface
,
276 DWORD bone_num
, const D3DXMATRIX
*bone_transform
)
278 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
280 TRACE("iface %p, bone_num %u, bone_transform %p.\n", iface
, bone_num
, bone_transform
);
282 if (bone_num
>= skin
->num_bones
|| !bone_transform
)
283 return D3DERR_INVALIDCALL
;
285 skin
->bones
[bone_num
].transform
= *bone_transform
;
289 static D3DXMATRIX
* WINAPI
d3dx9_skin_info_GetBoneOffsetMatrix(ID3DXSkinInfo
*iface
, DWORD bone_num
)
291 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
293 TRACE("iface %p, bone_num %u.\n", iface
, bone_num
);
295 if (bone_num
>= skin
->num_bones
)
298 return &skin
->bones
[bone_num
].transform
;
301 static HRESULT WINAPI
d3dx9_skin_info_Clone(ID3DXSkinInfo
*iface
, ID3DXSkinInfo
**skin_info
)
303 FIXME("iface %p, skin_info %p stub!\n", iface
, skin_info
);
308 static HRESULT WINAPI
d3dx9_skin_info_Remap(ID3DXSkinInfo
*iface
, DWORD num_vertices
, DWORD
*vertex_remap
)
310 FIXME("iface %p, num_vertices %u, vertex_remap %p stub!\n", iface
, num_vertices
, vertex_remap
);
315 static HRESULT WINAPI
d3dx9_skin_info_SetFVF(ID3DXSkinInfo
*iface
, DWORD fvf
)
318 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
320 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
322 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
323 if (FAILED(hr
)) return hr
;
325 return iface
->lpVtbl
->SetDeclaration(iface
, declaration
);
328 static HRESULT WINAPI
d3dx9_skin_info_SetDeclaration(ID3DXSkinInfo
*iface
, const D3DVERTEXELEMENT9
*declaration
)
330 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
334 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
337 return D3DERR_INVALIDCALL
;
338 for (count
= 0; declaration
[count
].Stream
!= 0xff; count
++) {
339 if (declaration
[count
].Stream
!= 0) {
340 WARN("Invalid vertex element %u; contains non-zero stream %u\n",
341 count
, declaration
[count
].Stream
);
342 return D3DERR_INVALIDCALL
;
347 memcpy(skin
->vertex_declaration
, declaration
, count
* sizeof(*declaration
));
349 if (FAILED(hr
= D3DXFVFFromDeclarator(skin
->vertex_declaration
, &skin
->fvf
)))
355 static DWORD WINAPI
d3dx9_skin_info_GetFVF(ID3DXSkinInfo
*iface
)
357 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
359 TRACE("iface %p.\n", iface
);
364 static HRESULT WINAPI
d3dx9_skin_info_GetDeclaration(ID3DXSkinInfo
*iface
,
365 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
])
367 struct d3dx9_skin_info
*skin
= impl_from_ID3DXSkinInfo(iface
);
370 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
372 while (skin
->vertex_declaration
[count
++].Stream
!= 0xff);
373 memcpy(declaration
, skin
->vertex_declaration
, count
* sizeof(declaration
[0]));
377 static HRESULT WINAPI
d3dx9_skin_info_UpdateSkinnedMesh(ID3DXSkinInfo
*iface
, const D3DXMATRIX
*bone_transforms
,
378 const D3DXMATRIX
*bone_inv_transpose_transforms
, const void *src_vertices
, void *dst_vertices
)
380 FIXME("iface %p, bone_transforms %p, bone_inv_transpose_transforms %p, src_vertices %p, dst_vertices %p stub!\n",
381 iface
, bone_transforms
, bone_inv_transpose_transforms
, src_vertices
, dst_vertices
);
386 static HRESULT WINAPI
d3dx9_skin_info_ConvertToBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
387 DWORD options
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
388 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
389 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
391 FIXME("iface %p, mesh_in %p, options %#x, adjacency_in %p, adjacency_out %p, face_remap %p, vertex_remap %p, "
392 "max_face_infl %p, num_bone_combinations %p, bone_combination_table %p, mesh_out %p stub!\n",
393 iface
, mesh_in
, options
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
394 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
399 static HRESULT WINAPI
d3dx9_skin_info_ConvertToIndexedBlendedMesh(ID3DXSkinInfo
*iface
, ID3DXMesh
*mesh_in
,
400 DWORD options
, DWORD palette_size
, const DWORD
*adjacency_in
, DWORD
*adjacency_out
, DWORD
*face_remap
,
401 ID3DXBuffer
**vertex_remap
, DWORD
*max_face_infl
, DWORD
*num_bone_combinations
,
402 ID3DXBuffer
**bone_combination_table
, ID3DXMesh
**mesh_out
)
404 FIXME("iface %p, mesh_in %p, options %#x, palette_size %u, adjacency_in %p, adjacency_out %p, face_remap %p, vertex_remap %p, "
405 "max_face_infl %p, num_bone_combinations %p, bone_combination_table %p, mesh_out %p stub!\n",
406 iface
, mesh_in
, options
, palette_size
, adjacency_in
, adjacency_out
, face_remap
, vertex_remap
,
407 max_face_infl
, num_bone_combinations
, bone_combination_table
, mesh_out
);
412 static const struct ID3DXSkinInfoVtbl d3dx9_skin_info_vtbl
=
414 d3dx9_skin_info_QueryInterface
,
415 d3dx9_skin_info_AddRef
,
416 d3dx9_skin_info_Release
,
417 d3dx9_skin_info_SetBoneInfluence
,
418 d3dx9_skin_info_SetBoneVertexInfluence
,
419 d3dx9_skin_info_GetNumBoneInfluences
,
420 d3dx9_skin_info_GetBoneInfluence
,
421 d3dx9_skin_info_GetBoneVertexInfluence
,
422 d3dx9_skin_info_GetMaxVertexInfluences
,
423 d3dx9_skin_info_GetNumBones
,
424 d3dx9_skin_info_FindBoneVertexInfluenceIndex
,
425 d3dx9_skin_info_GetMaxFaceInfluences
,
426 d3dx9_skin_info_SetMinBoneInfluence
,
427 d3dx9_skin_info_GetMinBoneInfluence
,
428 d3dx9_skin_info_SetBoneName
,
429 d3dx9_skin_info_GetBoneName
,
430 d3dx9_skin_info_SetBoneOffsetMatrix
,
431 d3dx9_skin_info_GetBoneOffsetMatrix
,
432 d3dx9_skin_info_Clone
,
433 d3dx9_skin_info_Remap
,
434 d3dx9_skin_info_SetFVF
,
435 d3dx9_skin_info_SetDeclaration
,
436 d3dx9_skin_info_GetFVF
,
437 d3dx9_skin_info_GetDeclaration
,
438 d3dx9_skin_info_UpdateSkinnedMesh
,
439 d3dx9_skin_info_ConvertToBlendedMesh
,
440 d3dx9_skin_info_ConvertToIndexedBlendedMesh
,
443 HRESULT WINAPI
D3DXCreateSkinInfo(DWORD num_vertices
, const D3DVERTEXELEMENT9
*declaration
,
444 DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
447 static const D3DVERTEXELEMENT9 empty_declaration
= D3DDECL_END();
448 struct d3dx9_skin_info
*object
= NULL
;
450 TRACE("num_vertices %u, declaration %p, num_bones %u, skin_info %p.\n",
451 num_vertices
, declaration
, num_bones
, skin_info
);
453 if (!skin_info
|| !declaration
)
454 return D3DERR_INVALIDCALL
;
456 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
458 return E_OUTOFMEMORY
;
460 object
->ID3DXSkinInfo_iface
.lpVtbl
= &d3dx9_skin_info_vtbl
;
462 object
->num_vertices
= num_vertices
;
463 object
->num_bones
= num_bones
;
464 object
->vertex_declaration
[0] = empty_declaration
;
467 object
->bones
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_bones
* sizeof(*object
->bones
));
468 if (!object
->bones
) {
473 if (FAILED(hr
= d3dx9_skin_info_SetDeclaration(&object
->ID3DXSkinInfo_iface
, declaration
)))
476 *skin_info
= &object
->ID3DXSkinInfo_iface
;
480 HeapFree(GetProcessHeap(), 0, object
->bones
);
481 HeapFree(GetProcessHeap(), 0, object
);
485 HRESULT WINAPI
D3DXCreateSkinInfoFVF(DWORD num_vertices
, DWORD fvf
, DWORD num_bones
, ID3DXSkinInfo
**skin_info
)
488 D3DVERTEXELEMENT9 declaration
[MAX_FVF_DECL_SIZE
];
490 TRACE("(%u, %x, %u, %p)\n", num_vertices
, fvf
, num_bones
, skin_info
);
492 hr
= D3DXDeclaratorFromFVF(fvf
, declaration
);
496 return D3DXCreateSkinInfo(num_vertices
, declaration
, num_bones
, skin_info
);