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);
33 typedef struct ID3DXSkinInfoImpl
35 ID3DXSkinInfo ID3DXSkinInfo_iface;
39 D3DVERTEXELEMENT9 vertex_declaration[MAX_FVF_DECL_SIZE];
45 static inline struct ID3DXSkinInfoImpl *impl_from_ID3DXSkinInfo(ID3DXSkinInfo *iface)
47 return CONTAINING_RECORD(iface, struct ID3DXSkinInfoImpl, ID3DXSkinInfo_iface);
50 static HRESULT WINAPI ID3DXSkinInfoImpl_QueryInterface(ID3DXSkinInfo *iface, REFIID riid, void **ppobj)
52 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), ppobj);
54 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ID3DXSkinInfo))
56 IUnknown_AddRef(iface);
61 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
66 static ULONG WINAPI ID3DXSkinInfoImpl_AddRef(ID3DXSkinInfo *iface)
68 struct ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
69 ULONG ref = InterlockedIncrement(&This->ref);
71 TRACE("%p increasing refcount to %u\n", This, ref);
76 static ULONG WINAPI ID3DXSkinInfoImpl_Release(ID3DXSkinInfo *iface)
78 struct ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
79 ULONG ref = InterlockedDecrement(&This->ref);
81 TRACE("%p decreasing refcount to %u\n", This, ref);
85 for (i = 0; i < This->num_bones; i++) {
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(ID3DXSkinInfo *iface, LPDIRECT3DINDEXBUFFER9 index_buffer, DWORD num_faces, DWORD *max_face_influences)
212 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
214 FIXME("(%p, %p, %u, %p): stub\n", This, index_buffer, num_faces, max_face_influences);
219 static HRESULT WINAPI ID3DXSkinInfoImpl_SetMinBoneInfluence(ID3DXSkinInfo *iface, FLOAT min_influence)
221 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
223 FIXME("(%p, %g): stub\n", This, min_influence);
228 static FLOAT WINAPI ID3DXSkinInfoImpl_GetMinBoneInfluence(ID3DXSkinInfo *iface)
230 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
232 FIXME("(%p): stub\n", This);
237 static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneName(ID3DXSkinInfo *iface, DWORD bone_num, LPCSTR name)
239 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
241 FIXME("(%p, %u, %s): stub\n", This, bone_num, debugstr_a(name));
246 static LPCSTR WINAPI ID3DXSkinInfoImpl_GetBoneName(ID3DXSkinInfo *iface, DWORD bone_num)
248 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
250 FIXME("(%p, %u): stub\n", This, bone_num);
255 static HRESULT WINAPI ID3DXSkinInfoImpl_SetBoneOffsetMatrix(ID3DXSkinInfo *iface, DWORD bone_num, CONST D3DXMATRIX *bone_transform)
257 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
259 FIXME("(%p, %u, %p): stub\n", This, bone_num, bone_transform);
264 static LPD3DXMATRIX WINAPI ID3DXSkinInfoImpl_GetBoneOffsetMatrix(ID3DXSkinInfo *iface, DWORD bone_num)
266 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
268 FIXME("(%p, %u): stub\n", This, bone_num);
273 static HRESULT WINAPI ID3DXSkinInfoImpl_Clone(ID3DXSkinInfo *iface, LPD3DXSKININFO *skin_info)
275 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
277 FIXME("(%p, %p): stub\n", This, skin_info);
282 static HRESULT WINAPI ID3DXSkinInfoImpl_Remap(ID3DXSkinInfo *iface, DWORD num_vertices, DWORD *vertex_remap)
284 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
286 FIXME("(%p, %u, %p): stub\n", This, num_vertices, vertex_remap);
291 static HRESULT WINAPI ID3DXSkinInfoImpl_SetFVF(ID3DXSkinInfo *iface, DWORD fvf)
293 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
295 D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE];
297 TRACE("(%p, %x)\n", This, fvf);
299 hr = D3DXDeclaratorFromFVF(fvf, declaration);
300 if (FAILED(hr)) return hr;
302 return iface->lpVtbl->SetDeclaration(iface, declaration);
305 static HRESULT WINAPI ID3DXSkinInfoImpl_SetDeclaration(ID3DXSkinInfo *iface, CONST D3DVERTEXELEMENT9 *declaration)
307 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
311 TRACE("(%p, %p)\n", This, declaration);
314 return D3DERR_INVALIDCALL;
315 for (count = 0; declaration[count].Stream != 0xff; count++) {
316 if (declaration[count].Stream != 0) {
317 WARN("Invalid vertex element %u; contains non-zero stream %u\n",
318 count, declaration[count].Stream);
319 return D3DERR_INVALIDCALL;
324 memcpy(This->vertex_declaration, declaration, count * sizeof(*declaration));
326 hr = D3DXFVFFromDeclarator(This->vertex_declaration, &This->fvf);
333 static DWORD WINAPI ID3DXSkinInfoImpl_GetFVF(ID3DXSkinInfo *iface)
335 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
337 TRACE("(%p)\n", This);
342 static HRESULT WINAPI ID3DXSkinInfoImpl_GetDeclaration(ID3DXSkinInfo *iface, D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE])
344 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
347 TRACE("(%p)\n", This);
349 while (This->vertex_declaration[count++].Stream != 0xff);
350 memcpy(declaration, This->vertex_declaration, count * sizeof(declaration[0]));
354 static HRESULT WINAPI ID3DXSkinInfoImpl_UpdateSkinnedMesh(ID3DXSkinInfo *iface, CONST D3DXMATRIX *bone_transforms,
355 CONST D3DXMATRIX *bone_inv_transpose_transforms, LPCVOID vertices_src, PVOID vertices_dest)
357 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
359 FIXME("(%p, %p, %p, %p, %p): stub\n", This, bone_transforms, bone_inv_transpose_transforms, vertices_src, vertices_dest);
364 static HRESULT WINAPI ID3DXSkinInfoImpl_ConvertToBlendedMesh(ID3DXSkinInfo *iface, LPD3DXMESH mesh_in,
365 DWORD options, CONST DWORD *adjacency_in, LPDWORD adjacency_out, DWORD *face_remap,
366 LPD3DXBUFFER *vertex_remap, DWORD *max_face_infl, DWORD *num_bone_combinations,
367 LPD3DXBUFFER *bone_combination_table, LPD3DXMESH *mesh_out)
369 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
371 FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
372 This, mesh_in, options, adjacency_in, adjacency_out, face_remap, vertex_remap,
373 max_face_infl, num_bone_combinations, bone_combination_table, mesh_out);
378 static HRESULT WINAPI ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh(ID3DXSkinInfo *iface, LPD3DXMESH mesh_in,
379 DWORD options, CONST DWORD *adjacency_in, LPDWORD adjacency_out, DWORD *face_remap,
380 LPD3DXBUFFER *vertex_remap, DWORD *max_face_infl, DWORD *num_bone_combinations,
381 LPD3DXBUFFER *bone_combination_table, LPD3DXMESH *mesh_out)
383 ID3DXSkinInfoImpl *This = impl_from_ID3DXSkinInfo(iface);
385 FIXME("(%p, %p, %x, %p, %p, %p, %p, %p, %p, %p, %p): stub\n",
386 This, mesh_in, options, adjacency_in, adjacency_out, face_remap, vertex_remap,
387 max_face_infl, num_bone_combinations, bone_combination_table, mesh_out);
392 static const struct ID3DXSkinInfoVtbl ID3DXSkinInfoImpl_Vtbl =
394 /* IUnknown methods */
395 ID3DXSkinInfoImpl_QueryInterface,
396 ID3DXSkinInfoImpl_AddRef,
397 ID3DXSkinInfoImpl_Release,
399 ID3DXSkinInfoImpl_SetBoneInfluence,
400 ID3DXSkinInfoImpl_SetBoneVertexInfluence,
401 ID3DXSkinInfoImpl_GetNumBoneInfluences,
402 ID3DXSkinInfoImpl_GetBoneInfluence,
403 ID3DXSkinInfoImpl_GetBoneVertexInfluence,
404 ID3DXSkinInfoImpl_GetMaxVertexInfluences,
405 ID3DXSkinInfoImpl_GetNumBones,
406 ID3DXSkinInfoImpl_FindBoneVertexInfluenceIndex,
407 ID3DXSkinInfoImpl_GetMaxFaceInfluences,
408 ID3DXSkinInfoImpl_SetMinBoneInfluence,
409 ID3DXSkinInfoImpl_GetMinBoneInfluence,
410 ID3DXSkinInfoImpl_SetBoneName,
411 ID3DXSkinInfoImpl_GetBoneName,
412 ID3DXSkinInfoImpl_SetBoneOffsetMatrix,
413 ID3DXSkinInfoImpl_GetBoneOffsetMatrix,
414 ID3DXSkinInfoImpl_Clone,
415 ID3DXSkinInfoImpl_Remap,
416 ID3DXSkinInfoImpl_SetFVF,
417 ID3DXSkinInfoImpl_SetDeclaration,
418 ID3DXSkinInfoImpl_GetFVF,
419 ID3DXSkinInfoImpl_GetDeclaration,
420 ID3DXSkinInfoImpl_UpdateSkinnedMesh,
421 ID3DXSkinInfoImpl_ConvertToBlendedMesh,
422 ID3DXSkinInfoImpl_ConvertToIndexedBlendedMesh
425 HRESULT WINAPI D3DXCreateSkinInfo(DWORD num_vertices, CONST D3DVERTEXELEMENT9 *declaration,
426 DWORD num_bones, LPD3DXSKININFO *skin_info)
429 ID3DXSkinInfoImpl *object = NULL;
430 static const D3DVERTEXELEMENT9 empty_declaration = D3DDECL_END();
432 TRACE("(%u, %p, %u, %p)\n", num_vertices, declaration, num_bones, skin_info);
434 if (!skin_info || !declaration)
435 return D3DERR_INVALIDCALL;
437 object = HeapAlloc(GetProcessHeap(), 0, sizeof(*object));
439 return E_OUTOFMEMORY;
441 object->ID3DXSkinInfo_iface.lpVtbl = &ID3DXSkinInfoImpl_Vtbl;
443 object->num_vertices = num_vertices;
444 object->num_bones = num_bones;
445 object->vertex_declaration[0] = empty_declaration;
448 object->bones = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num_bones * sizeof(*object->bones));
449 if (!object->bones) {
454 hr = ID3DXSkinInfoImpl_SetDeclaration(&object->ID3DXSkinInfo_iface, declaration);
455 if (FAILED(hr)) goto error;
457 *skin_info = &object->ID3DXSkinInfo_iface;
461 HeapFree(GetProcessHeap(), 0, object->bones);
462 HeapFree(GetProcessHeap(), 0, object);
466 HRESULT WINAPI D3DXCreateSkinInfoFVF(DWORD num_vertices, DWORD fvf, DWORD num_bones, LPD3DXSKININFO *skin_info)
469 D3DVERTEXELEMENT9 declaration[MAX_FVF_DECL_SIZE];
471 TRACE("(%u, %x, %u, %p)\n", num_vertices, fvf, num_bones, skin_info);
473 hr = D3DXDeclaratorFromFVF(fvf, declaration);
477 return D3DXCreateSkinInfo(num_vertices, declaration, num_bones, skin_info);