2 * Implementation of IDirect3DRMMeshBuilderX and IDirect3DRMMesh interfaces
4 * Copyright 2010, 2012 Christian Costa
5 * Copyright 2011 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
26 #include "wine/debug.h"
33 #include "d3drm_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(d3drm
);
40 D3DRMVERTEX
* vertices
;
42 unsigned vertex_per_face
;
46 IDirect3DRMMaterial2
* material
;
47 IDirect3DRMTexture3
* texture
;
52 IDirect3DRMMesh IDirect3DRMMesh_iface
;
54 DWORD groups_capacity
;
56 struct mesh_group
*groups
;
68 IDirect3DRMMaterial2
*material
;
69 IDirect3DRMTexture3
*texture
;
72 struct d3drm_mesh_builder
74 IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface
;
75 IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface
;
86 struct coords_2d
*pCoords2d
;
88 IDirect3DRMMaterial2
*material
;
89 IDirect3DRMTexture3
*texture
;
91 struct mesh_material
*materials
;
92 DWORD
*material_indices
;
99 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
106 "<3D82AB5E-62DA-11CF-AB39-0020AF71E433>"
113 "<F6F23F44-7686-11CF-8F52-0040333594A3>"
119 "<F6F23F45-7686-11CF-8F52-0040333594A3>"
120 "array FLOAT matrix[16];"
124 "<35FF44E0-6C7C-11CF-8F52-0040333594A3>"
132 "<D3E16E81-7835-11CF-8F52-0040333594A3>"
137 "template IndexedColor"
139 "<1630B820-7842-11CF-8F52-0040333594A3>"
141 "ColorRGBA indexColor;"
145 "<537DA6A0-CA37-11D0-941C-0080C80CFA7B>"
150 "<4885AE63-78E8-11CF-8F52-0040333594A3>"
154 "template MaterialWrap"
156 "<4885AE60-78E8-11CF-8F52-0040333594A3>"
160 "template TextureFilename"
162 "<A42790E1-7810-11CF-8F52-0040333594A3>"
167 "<3D82AB4D-62DA-11CF-AB39-0020AF71E433>"
168 "ColorRGBA faceColor;"
170 "ColorRGB specularColor;"
171 "ColorRGB emissiveColor;"
176 "<3D82AB5F-62DA-11CF-AB39-0020AF71E433>"
177 "DWORD nFaceVertexIndices;"
178 "array DWORD faceVertexIndices[nFaceVertexIndices];"
180 "template MeshFaceWraps"
182 "<ED1EC5C0-C0A8-11D0-941C-0080C80CFA7B>"
183 "DWORD nFaceWrapValues;"
184 "array Boolean2d faceWrapValues[nFaceWrapValues];"
186 "template MeshTextureCoords"
188 "<F6F23F40-7686-11CF-8F52-0040333594A3>"
189 "DWORD nTextureCoords;"
190 "array Coords2d textureCoords[nTextureCoords];"
192 "template MeshMaterialList"
194 "<F6F23F42-7686-11CF-8F52-0040333594A3>"
196 "DWORD nFaceIndexes;"
197 "array DWORD faceIndexes[nFaceIndexes];"
200 "template MeshNormals"
202 "<F6F23F43-7686-11CF-8F52-0040333594A3>"
204 "array Vector normals[nNormals];"
205 "DWORD nFaceNormals;"
206 "array MeshFace faceNormals[nFaceNormals];"
208 "template MeshVertexColors"
210 "<1630B821-7842-11CF-8F52-0040333594A3>"
211 "DWORD nVertexColors;"
212 "array IndexedColor vertexColors[nVertexColors];"
216 "<3D82AB44-62DA-11CF-AB39-0020AF71E433>"
218 "array Vector vertices[nVertices];"
220 "array MeshFace faces[nFaces];"
223 "template FrameTransformMatrix"
225 "<F6F23F41-7686-11CF-8F52-0040333594A3>"
226 "Matrix4x4 frameMatrix;"
230 "<3D82AB46-62DA-11CF-AB39-0020AF71E433>"
235 "<10DD46A9-775B-11CF-8F52-0040333594A3>"
237 "array FLOAT values[nValues];"
239 "template TimedFloatKeys"
241 "<F406B180-7B3B-11CF-8F52-0040333594A3>"
245 "template AnimationKey"
247 "<10DD46A8-775B-11CF-8F52-0040333594A3>"
250 "array TimedFloatKeys keys[nKeys];"
252 "template AnimationOptions"
254 "<E2BF56C0-840F-11CF-8F52-0040333594A3>"
256 "DWORD positionquality;"
260 "<3D82AB4F-62DA-11CF-AB39-0020AF71E433>"
263 "template AnimationSet"
265 "<3D82AB50-62DA-11CF-AB39-0020AF71E433>"
268 "template InlineData"
270 "<3A23EEA0-94B1-11D0-AB39-0020AF71E433>"
275 "<3A23EEA1-94B1-11D0-AB39-0020AF71E433>"
277 "array STRING urls[nUrls];"
279 "template ProgressiveMesh"
281 "<8A63C360-997D-11D0-941C-0080C80CFA7B>"
286 "<A42790E0-7810-11CF-8F52-0040333594A3>"
290 "array UCHAR data4[8];"
292 "template StringProperty"
294 "<7F0F21E0-BFE1-11D1-82C0-00A0C9697271>"
298 "template PropertyBag"
300 "<7F0F21E1-BFE1-11D1-82C0-00A0C9697271>"
303 "template ExternalVisual"
305 "<98116AA0-BDBA-11D1-82C0-00A0C9697271>"
306 "Guid guidExternalVisual;"
309 "template RightHanded"
311 "<7F5D5EA0-D53A-11D1-82C0-00A0C9697271>"
312 "DWORD bRightHanded;"
316 static inline struct d3drm_mesh
*impl_from_IDirect3DRMMesh(IDirect3DRMMesh
*iface
)
318 return CONTAINING_RECORD(iface
, struct d3drm_mesh
, IDirect3DRMMesh_iface
);
321 static inline struct d3drm_mesh_builder
*impl_from_IDirect3DRMMeshBuilder2(IDirect3DRMMeshBuilder2
*iface
)
323 return CONTAINING_RECORD(iface
, struct d3drm_mesh_builder
, IDirect3DRMMeshBuilder2_iface
);
326 static inline struct d3drm_mesh_builder
*impl_from_IDirect3DRMMeshBuilder3(IDirect3DRMMeshBuilder3
*iface
)
328 return CONTAINING_RECORD(iface
, struct d3drm_mesh_builder
, IDirect3DRMMeshBuilder3_iface
);
331 static void clean_mesh_builder_data(struct d3drm_mesh_builder
*mesh_builder
)
335 HeapFree(GetProcessHeap(), 0, mesh_builder
->name
);
336 mesh_builder
->name
= NULL
;
337 HeapFree(GetProcessHeap(), 0, mesh_builder
->pVertices
);
338 mesh_builder
->pVertices
= NULL
;
339 mesh_builder
->nb_vertices
= 0;
340 HeapFree(GetProcessHeap(), 0, mesh_builder
->pNormals
);
341 mesh_builder
->pNormals
= NULL
;
342 mesh_builder
->nb_normals
= 0;
343 HeapFree(GetProcessHeap(), 0, mesh_builder
->pFaceData
);
344 mesh_builder
->pFaceData
= NULL
;
345 mesh_builder
->face_data_size
= 0;
346 mesh_builder
->nb_faces
= 0;
347 HeapFree(GetProcessHeap(), 0, mesh_builder
->pCoords2d
);
348 mesh_builder
->pCoords2d
= NULL
;
349 mesh_builder
->nb_coords2d
= 0;
350 for (i
= 0; i
< mesh_builder
->nb_materials
; i
++)
352 if (mesh_builder
->materials
[i
].material
)
353 IDirect3DRMMaterial2_Release(mesh_builder
->materials
[i
].material
);
354 if (mesh_builder
->materials
[i
].texture
)
355 IDirect3DRMTexture3_Release(mesh_builder
->materials
[i
].texture
);
357 mesh_builder
->nb_materials
= 0;
358 HeapFree(GetProcessHeap(), 0, mesh_builder
->materials
);
359 HeapFree(GetProcessHeap(), 0, mesh_builder
->material_indices
);
362 static HRESULT WINAPI
d3drm_mesh_builder2_QueryInterface(IDirect3DRMMeshBuilder2
*iface
, REFIID riid
, void **out
)
364 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
366 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
368 if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder2
)
369 || IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder
)
370 || IsEqualGUID(riid
, &IID_IUnknown
))
372 *out
= &mesh_builder
->IDirect3DRMMeshBuilder2_iface
;
374 else if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder3
))
376 *out
= &mesh_builder
->IDirect3DRMMeshBuilder3_iface
;
381 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
382 return E_NOINTERFACE
;
385 IUnknown_AddRef((IUnknown
*)*out
);
389 static ULONG WINAPI
d3drm_mesh_builder2_AddRef(IDirect3DRMMeshBuilder2
*iface
)
391 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
392 ULONG refcount
= InterlockedIncrement(&mesh_builder
->ref
);
394 TRACE("%p increasing refcount to %u.\n", mesh_builder
, refcount
);
399 static ULONG WINAPI
d3drm_mesh_builder2_Release(IDirect3DRMMeshBuilder2
*iface
)
401 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
402 ULONG refcount
= InterlockedDecrement(&mesh_builder
->ref
);
404 TRACE("%p decreasing refcount to %u.\n", mesh_builder
, refcount
);
408 clean_mesh_builder_data(mesh_builder
);
409 if (mesh_builder
->material
)
410 IDirect3DRMMaterial2_Release(mesh_builder
->material
);
411 if (mesh_builder
->texture
)
412 IDirect3DRMTexture3_Release(mesh_builder
->texture
);
413 HeapFree(GetProcessHeap(), 0, mesh_builder
);
419 static HRESULT WINAPI
d3drm_mesh_builder2_Clone(IDirect3DRMMeshBuilder2
*iface
,
420 IUnknown
*outer
, REFIID iid
, void **out
)
422 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
427 static HRESULT WINAPI
d3drm_mesh_builder2_AddDestroyCallback(IDirect3DRMMeshBuilder2
*iface
,
428 D3DRMOBJECTCALLBACK cb
, void *ctx
)
430 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
435 static HRESULT WINAPI
d3drm_mesh_builder2_DeleteDestroyCallback(IDirect3DRMMeshBuilder2
*iface
,
436 D3DRMOBJECTCALLBACK cb
, void *ctx
)
438 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
443 static HRESULT WINAPI
d3drm_mesh_builder2_SetAppData(IDirect3DRMMeshBuilder2
*iface
, DWORD data
)
445 FIXME("iface %p, data %#x stub!\n", iface
, data
);
450 static DWORD WINAPI
d3drm_mesh_builder2_GetAppData(IDirect3DRMMeshBuilder2
*iface
)
452 FIXME("iface %p stub!\n", iface
);
457 static HRESULT WINAPI
d3drm_mesh_builder2_SetName(IDirect3DRMMeshBuilder2
*iface
, const char *name
)
459 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
461 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
463 return IDirect3DRMMeshBuilder3_SetName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, name
);
466 static HRESULT WINAPI
d3drm_mesh_builder2_GetName(IDirect3DRMMeshBuilder2
*iface
, DWORD
*size
, char *name
)
468 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
470 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
472 return IDirect3DRMMeshBuilder3_GetName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, size
, name
);
475 static HRESULT WINAPI
d3drm_mesh_builder2_GetClassName(IDirect3DRMMeshBuilder2
*iface
, DWORD
*size
, char *name
)
477 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
479 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
481 return IDirect3DRMMeshBuilder3_GetClassName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, size
, name
);
484 static HRESULT WINAPI
d3drm_mesh_builder2_Load(IDirect3DRMMeshBuilder2
*iface
, void *filename
,
485 void *name
, D3DRMLOADOPTIONS flags
, D3DRMLOADTEXTURECALLBACK cb
, void *ctx
)
487 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
489 TRACE("iface %p, filename %p, name %p, flags %#x, cb %p, ctx %p.\n",
490 iface
, filename
, name
, flags
, cb
, ctx
);
493 FIXME("Texture callback is not yet supported\n");
495 return IDirect3DRMMeshBuilder3_Load(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
496 filename
, name
, flags
, NULL
, ctx
);
499 static HRESULT WINAPI
d3drm_mesh_builder2_Save(IDirect3DRMMeshBuilder2
*iface
,
500 const char *filename
, D3DRMXOFFORMAT format
, D3DRMSAVEOPTIONS flags
)
502 FIXME("iface %p, filename %s, format %#x, flags %#x stub!\n",
503 iface
, debugstr_a(filename
), format
, flags
);
508 static HRESULT WINAPI
d3drm_mesh_builder2_Scale(IDirect3DRMMeshBuilder2
*iface
,
509 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
511 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
513 TRACE("iface %p, sx %.8e, sy %.8e, sz %.8e.\n", iface
, sx
, sy
, sz
);
515 return IDirect3DRMMeshBuilder3_Scale(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, sx
, sy
, sz
);
518 static HRESULT WINAPI
d3drm_mesh_builder2_Translate(IDirect3DRMMeshBuilder2
*iface
,
519 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
521 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
526 static HRESULT WINAPI
d3drm_mesh_builder2_SetColorSource(IDirect3DRMMeshBuilder2
*iface
, D3DRMCOLORSOURCE source
)
528 FIXME("iface %p, source %#x stub!\n", iface
, source
);
533 static HRESULT WINAPI
d3drm_mesh_builder2_GetBox(IDirect3DRMMeshBuilder2
*iface
, D3DRMBOX
*box
)
535 FIXME("iface %p, box %p stub!\n", iface
, box
);
540 static HRESULT WINAPI
d3drm_mesh_builder2_GenerateNormals(IDirect3DRMMeshBuilder2
*iface
)
542 FIXME("iface %p stub!\n", iface
);
547 static D3DRMCOLORSOURCE WINAPI
d3drm_mesh_builder2_GetColorSource(IDirect3DRMMeshBuilder2
*iface
)
549 FIXME("iface %p stub!\n", iface
);
554 static HRESULT WINAPI
d3drm_mesh_builder2_AddMesh(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMMesh
*mesh
)
556 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
561 static HRESULT WINAPI
d3drm_mesh_builder2_AddMeshBuilder(IDirect3DRMMeshBuilder2
*iface
,
562 IDirect3DRMMeshBuilder
*mesh_builder
)
564 FIXME("iface %p, mesh_builder %p stub!\n", iface
, mesh_builder
);
569 static HRESULT WINAPI
d3drm_mesh_builder2_AddFrame(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFrame
*frame
)
571 FIXME("iface %p, frame %p stub!\n", iface
, frame
);
576 static HRESULT WINAPI
d3drm_mesh_builder2_AddFace(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFace
*face
)
578 FIXME("iface %p, face %p stub!\n", iface
, face
);
583 static HRESULT WINAPI
d3drm_mesh_builder2_AddFaces(IDirect3DRMMeshBuilder2
*iface
,
584 DWORD vertex_count
, D3DVECTOR
*vertices
, DWORD normal_count
, D3DVECTOR
*normals
,
585 DWORD
*face_data
, IDirect3DRMFaceArray
**array
)
587 FIXME("iface %p, vertex_count %u, vertices %p, normal_count %u, normals %p, face_data %p, array %p stub!\n",
588 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data
, array
);
593 static HRESULT WINAPI
d3drm_mesh_builder2_ReserveSpace(IDirect3DRMMeshBuilder2
*iface
,
594 DWORD vertex_count
, DWORD normal_count
, DWORD face_count
)
596 FIXME("iface %p, vertex_count %u, normal_count %u, face_count %u stub!\n",
597 iface
, vertex_count
, normal_count
, face_count
);
602 static HRESULT WINAPI
d3drm_mesh_builder2_SetColorRGB(IDirect3DRMMeshBuilder2
*iface
,
603 D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
605 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
607 TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface
, red
, green
, blue
);
609 return IDirect3DRMMeshBuilder3_SetColorRGB(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, red
, green
, blue
);
612 static HRESULT WINAPI
d3drm_mesh_builder2_SetColor(IDirect3DRMMeshBuilder2
*iface
, D3DCOLOR color
)
614 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
616 TRACE("iface %p, color 0x%08x.\n", iface
, color
);
618 return IDirect3DRMMeshBuilder3_SetColor(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, color
);
621 static HRESULT WINAPI
d3drm_mesh_builder2_SetTexture(IDirect3DRMMeshBuilder2
*iface
,
622 IDirect3DRMTexture
*texture
)
624 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
625 IDirect3DRMTexture3
*texture3
= NULL
;
626 HRESULT hr
= D3DRM_OK
;
628 TRACE("iface %p, texture %p.\n", iface
, texture
);
631 hr
= IDirect3DRMTexture_QueryInterface(texture
, &IID_IDirect3DRMTexture3
, (void **)&texture3
);
633 hr
= IDirect3DRMMeshBuilder3_SetTexture(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, texture3
);
635 IDirect3DRMTexture3_Release(texture3
);
640 static HRESULT WINAPI
d3drm_mesh_builder2_SetMaterial(IDirect3DRMMeshBuilder2
*iface
,
641 IDirect3DRMMaterial
*material
)
643 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
645 TRACE("iface %p, material %p.\n", iface
, material
);
647 return IDirect3DRMMeshBuilder3_SetMaterial(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
648 (IDirect3DRMMaterial2
*)material
);
651 static HRESULT WINAPI
d3drm_mesh_builder2_SetTextureTopology(IDirect3DRMMeshBuilder2
*iface
,
652 BOOL wrap_u
, BOOL wrap_v
)
654 FIXME("iface %p, wrap_u %#x, wrap_v %#x stub!\n", iface
, wrap_u
, wrap_v
);
659 static HRESULT WINAPI
d3drm_mesh_builder2_SetQuality(IDirect3DRMMeshBuilder2
*iface
,
660 D3DRMRENDERQUALITY quality
)
662 FIXME("iface %p, quality %#x stub!\n", iface
, quality
);
667 static HRESULT WINAPI
d3drm_mesh_builder2_SetPerspective(IDirect3DRMMeshBuilder2
*iface
, BOOL enable
)
669 FIXME("iface %p, enable %#x stub!\n", iface
, enable
);
674 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertex(IDirect3DRMMeshBuilder2
*iface
,
675 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
677 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
682 static HRESULT WINAPI
d3drm_mesh_builder2_SetNormal(IDirect3DRMMeshBuilder2
*iface
,
683 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
685 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
690 static HRESULT WINAPI
d3drm_mesh_builder2_SetTextureCoordinates(IDirect3DRMMeshBuilder2
*iface
,
691 DWORD index
, D3DVALUE u
, D3DVALUE v
)
693 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
695 TRACE("iface %p, index %u, u %.8e, v %.8e.\n", iface
, index
, u
, v
);
697 return IDirect3DRMMeshBuilder3_SetTextureCoordinates(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
701 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertexColor(IDirect3DRMMeshBuilder2
*iface
,
702 DWORD index
, D3DCOLOR color
)
704 FIXME("iface %p, index %u, color 0x%08x stub!\n", iface
, index
, color
);
709 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertexColorRGB(IDirect3DRMMeshBuilder2
*iface
,
710 DWORD index
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
712 FIXME("iface %p, index %u, red %.8e, green %.8e, blue %.8e stub!\n",
713 iface
, index
, red
, green
, blue
);
718 static HRESULT WINAPI
d3drm_mesh_builder2_GetFaces(IDirect3DRMMeshBuilder2
*iface
,
719 IDirect3DRMFaceArray
**array
)
721 FIXME("iface %p, array %p stub!\n", iface
, array
);
726 static HRESULT WINAPI
d3drm_mesh_builder2_GetVertices(IDirect3DRMMeshBuilder2
*iface
,
727 DWORD
*vertex_count
, D3DVECTOR
*vertices
, DWORD
*normal_count
, D3DVECTOR
*normals
,
728 DWORD
*face_data_size
, DWORD
*face_data
)
730 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
732 TRACE("iface %p, vertex_count %p, vertices %p, normal_count %p, normals %p, face_data_size %p, face_data %p.\n",
733 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data_size
, face_data
);
735 if (vertices
&& (!vertex_count
|| (*vertex_count
< mesh_builder
->nb_vertices
)))
736 return D3DRMERR_BADVALUE
;
738 *vertex_count
= mesh_builder
->nb_vertices
;
739 if (vertices
&& mesh_builder
->nb_vertices
)
740 memcpy(vertices
, mesh_builder
->pVertices
, mesh_builder
->nb_vertices
* sizeof(*vertices
));
742 if (normals
&& (!normal_count
|| (*normal_count
< mesh_builder
->nb_normals
)))
743 return D3DRMERR_BADVALUE
;
745 *normal_count
= mesh_builder
->nb_normals
;
746 if (normals
&& mesh_builder
->nb_normals
)
747 memcpy(normals
, mesh_builder
->pNormals
, mesh_builder
->nb_normals
* sizeof(*normals
));
749 if (face_data
&& (!face_data_size
|| (*face_data_size
< mesh_builder
->face_data_size
)))
750 return D3DRMERR_BADVALUE
;
752 *face_data_size
= mesh_builder
->face_data_size
;
753 if (face_data
&& mesh_builder
->face_data_size
)
754 memcpy(face_data
, mesh_builder
->pFaceData
, mesh_builder
->face_data_size
* sizeof(*face_data
));
759 static HRESULT WINAPI
d3drm_mesh_builder2_GetTextureCoordinates(IDirect3DRMMeshBuilder2
*iface
,
760 DWORD index
, D3DVALUE
*u
, D3DVALUE
*v
)
762 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
764 TRACE("iface %p, index %u, u %p, v %p.\n", iface
, index
, u
, v
);
766 return IDirect3DRMMeshBuilder3_GetTextureCoordinates(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
770 static int WINAPI
d3drm_mesh_builder2_AddVertex(IDirect3DRMMeshBuilder2
*iface
,
771 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
773 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
778 static int WINAPI
d3drm_mesh_builder2_AddNormal(IDirect3DRMMeshBuilder2
*iface
,
779 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
781 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
786 static HRESULT WINAPI
d3drm_mesh_builder2_CreateFace(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFace
**face
)
788 TRACE("iface %p, face %p.\n", iface
, face
);
790 return Direct3DRMFace_create(&IID_IDirect3DRMFace
, (IUnknown
**)face
);
793 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_builder2_GetQuality(IDirect3DRMMeshBuilder2
*iface
)
795 FIXME("iface %p stub!\n", iface
);
800 static BOOL WINAPI
d3drm_mesh_builder2_GetPerspective(IDirect3DRMMeshBuilder2
*iface
)
802 FIXME("iface %p stub!\n", iface
);
807 static int WINAPI
d3drm_mesh_builder2_GetFaceCount(IDirect3DRMMeshBuilder2
*iface
)
809 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
811 TRACE("iface %p.\n", iface
);
813 return mesh_builder
->nb_faces
;
816 static int WINAPI
d3drm_mesh_builder2_GetVertexCount(IDirect3DRMMeshBuilder2
*iface
)
818 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
820 TRACE("iface %p.\n", iface
);
822 return mesh_builder
->nb_vertices
;
825 static D3DCOLOR WINAPI
d3drm_mesh_builder2_GetVertexColor(IDirect3DRMMeshBuilder2
*iface
, DWORD index
)
827 FIXME("iface %p, index %u stub!\n", iface
, index
);
832 static HRESULT WINAPI
d3drm_mesh_builder2_CreateMesh(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMMesh
**mesh
)
834 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
836 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
838 return IDirect3DRMMeshBuilder3_CreateMesh(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, mesh
);
841 static HRESULT WINAPI
d3drm_mesh_builder2_GenerateNormals2(IDirect3DRMMeshBuilder2
*iface
,
842 D3DVALUE crease
, DWORD flags
)
844 FIXME("iface %p, crease %.8e, flags %#x stub!\n", iface
, crease
, flags
);
849 static HRESULT WINAPI
d3drm_mesh_builder2_GetFace(IDirect3DRMMeshBuilder2
*iface
,
850 DWORD index
, IDirect3DRMFace
**face
)
852 FIXME("iface %p, index %u, face %p stub!\n", iface
, index
, face
);
857 static const struct IDirect3DRMMeshBuilder2Vtbl d3drm_mesh_builder2_vtbl
=
859 d3drm_mesh_builder2_QueryInterface
,
860 d3drm_mesh_builder2_AddRef
,
861 d3drm_mesh_builder2_Release
,
862 d3drm_mesh_builder2_Clone
,
863 d3drm_mesh_builder2_AddDestroyCallback
,
864 d3drm_mesh_builder2_DeleteDestroyCallback
,
865 d3drm_mesh_builder2_SetAppData
,
866 d3drm_mesh_builder2_GetAppData
,
867 d3drm_mesh_builder2_SetName
,
868 d3drm_mesh_builder2_GetName
,
869 d3drm_mesh_builder2_GetClassName
,
870 d3drm_mesh_builder2_Load
,
871 d3drm_mesh_builder2_Save
,
872 d3drm_mesh_builder2_Scale
,
873 d3drm_mesh_builder2_Translate
,
874 d3drm_mesh_builder2_SetColorSource
,
875 d3drm_mesh_builder2_GetBox
,
876 d3drm_mesh_builder2_GenerateNormals
,
877 d3drm_mesh_builder2_GetColorSource
,
878 d3drm_mesh_builder2_AddMesh
,
879 d3drm_mesh_builder2_AddMeshBuilder
,
880 d3drm_mesh_builder2_AddFrame
,
881 d3drm_mesh_builder2_AddFace
,
882 d3drm_mesh_builder2_AddFaces
,
883 d3drm_mesh_builder2_ReserveSpace
,
884 d3drm_mesh_builder2_SetColorRGB
,
885 d3drm_mesh_builder2_SetColor
,
886 d3drm_mesh_builder2_SetTexture
,
887 d3drm_mesh_builder2_SetMaterial
,
888 d3drm_mesh_builder2_SetTextureTopology
,
889 d3drm_mesh_builder2_SetQuality
,
890 d3drm_mesh_builder2_SetPerspective
,
891 d3drm_mesh_builder2_SetVertex
,
892 d3drm_mesh_builder2_SetNormal
,
893 d3drm_mesh_builder2_SetTextureCoordinates
,
894 d3drm_mesh_builder2_SetVertexColor
,
895 d3drm_mesh_builder2_SetVertexColorRGB
,
896 d3drm_mesh_builder2_GetFaces
,
897 d3drm_mesh_builder2_GetVertices
,
898 d3drm_mesh_builder2_GetTextureCoordinates
,
899 d3drm_mesh_builder2_AddVertex
,
900 d3drm_mesh_builder2_AddNormal
,
901 d3drm_mesh_builder2_CreateFace
,
902 d3drm_mesh_builder2_GetQuality
,
903 d3drm_mesh_builder2_GetPerspective
,
904 d3drm_mesh_builder2_GetFaceCount
,
905 d3drm_mesh_builder2_GetVertexCount
,
906 d3drm_mesh_builder2_GetVertexColor
,
907 d3drm_mesh_builder2_CreateMesh
,
908 d3drm_mesh_builder2_GenerateNormals2
,
909 d3drm_mesh_builder2_GetFace
,
912 static HRESULT WINAPI
d3drm_mesh_builder3_QueryInterface(IDirect3DRMMeshBuilder3
*iface
, REFIID riid
, void **out
)
914 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
916 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
918 return d3drm_mesh_builder2_QueryInterface(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
, riid
, out
);
921 static ULONG WINAPI
d3drm_mesh_builder3_AddRef(IDirect3DRMMeshBuilder3
*iface
)
923 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
925 TRACE("iface %p.\n", iface
);
927 return d3drm_mesh_builder2_AddRef(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
);
930 static ULONG WINAPI
d3drm_mesh_builder3_Release(IDirect3DRMMeshBuilder3
*iface
)
932 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
934 TRACE("iface %p.\n", iface
);
936 return d3drm_mesh_builder2_Release(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
);
939 static HRESULT WINAPI
d3drm_mesh_builder3_Clone(IDirect3DRMMeshBuilder3
*iface
,
940 IUnknown
*outer
, REFIID iid
, void **out
)
942 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
947 static HRESULT WINAPI
d3drm_mesh_builder3_AddDestroyCallback(IDirect3DRMMeshBuilder3
*iface
,
948 D3DRMOBJECTCALLBACK cb
, void *ctx
)
950 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
955 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteDestroyCallback(IDirect3DRMMeshBuilder3
*iface
,
956 D3DRMOBJECTCALLBACK cb
, void *ctx
)
958 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
963 static HRESULT WINAPI
d3drm_mesh_builder3_SetAppData(IDirect3DRMMeshBuilder3
*iface
, DWORD data
)
965 FIXME("iface %p, data %#x stub!\n", iface
, data
);
970 static DWORD WINAPI
d3drm_mesh_builder3_GetAppData(IDirect3DRMMeshBuilder3
*iface
)
972 FIXME("iface %p stub!\n", iface
);
977 static HRESULT WINAPI
d3drm_mesh_builder3_SetName(IDirect3DRMMeshBuilder3
*iface
, const char *name
)
979 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
982 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
986 string
= HeapAlloc(GetProcessHeap(), 0, strlen(name
) + 1);
987 if (!string
) return E_OUTOFMEMORY
;
988 strcpy(string
, name
);
990 HeapFree(GetProcessHeap(), 0, mesh_builder
->name
);
991 mesh_builder
->name
= string
;
996 static HRESULT WINAPI
d3drm_mesh_builder3_GetName(IDirect3DRMMeshBuilder3
*iface
,
997 DWORD
*size
, char *name
)
999 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1001 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
1006 if (!mesh_builder
->name
)
1012 if (*size
< (strlen(mesh_builder
->name
) + 1))
1013 return E_INVALIDARG
;
1015 strcpy(name
, mesh_builder
->name
);
1016 *size
= strlen(mesh_builder
->name
) + 1;
1021 static HRESULT WINAPI
d3drm_mesh_builder3_GetClassName(IDirect3DRMMeshBuilder3
*iface
,
1022 DWORD
*size
, char *name
)
1024 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
1026 if (!size
|| *size
< strlen("Builder") || !name
)
1027 return E_INVALIDARG
;
1029 strcpy(name
, "Builder");
1030 *size
= sizeof("Builder");
1035 HRESULT
load_mesh_data(IDirect3DRMMeshBuilder3
*iface
, IDirectXFileData
*pData
,
1036 D3DRMLOADTEXTURECALLBACK load_texture_proc
, void *arg
)
1038 struct d3drm_mesh_builder
*This
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1039 IDirectXFileData
*pData2
= NULL
;
1044 HRESULT ret
= D3DRMERR_BADOBJECT
;
1045 DWORD
* faces_vertex_idx_data
= NULL
;
1046 DWORD
* faces_vertex_idx_ptr
;
1047 DWORD faces_vertex_idx_size
;
1048 DWORD
* faces_normal_idx_data
= NULL
;
1049 DWORD
* faces_normal_idx_ptr
= NULL
;
1050 DWORD
* faces_data_ptr
;
1051 DWORD faces_data_size
= 0;
1054 TRACE("(%p)->(%p)\n", This
, pData
);
1056 hr
= IDirectXFileData_GetName(pData
, NULL
, &size
);
1057 if (hr
!= DXFILE_OK
)
1061 This
->name
= HeapAlloc(GetProcessHeap(), 0, size
);
1063 return E_OUTOFMEMORY
;
1065 hr
= IDirectXFileData_GetName(pData
, This
->name
, &size
);
1066 if (hr
!= DXFILE_OK
)
1070 TRACE("Mesh name is '%s'\n", This
->name
? This
->name
: "");
1072 This
->nb_normals
= 0;
1074 hr
= IDirectXFileData_GetData(pData
, NULL
, &size
, (void**)&ptr
);
1075 if (hr
!= DXFILE_OK
)
1078 This
->nb_vertices
= *(DWORD
*)ptr
;
1079 This
->nb_faces
= *(DWORD
*)(ptr
+ sizeof(DWORD
) + This
->nb_vertices
* sizeof(D3DVECTOR
));
1080 faces_vertex_idx_size
= size
- sizeof(DWORD
) - This
->nb_vertices
* sizeof(D3DVECTOR
) - sizeof(DWORD
);
1082 TRACE("Mesh: nb_vertices = %d, nb_faces = %d, faces_vertex_idx_size = %d\n", This
->nb_vertices
, This
->nb_faces
, faces_vertex_idx_size
);
1084 This
->pVertices
= HeapAlloc(GetProcessHeap(), 0, This
->nb_vertices
* sizeof(D3DVECTOR
));
1085 memcpy(This
->pVertices
, ptr
+ sizeof(DWORD
), This
->nb_vertices
* sizeof(D3DVECTOR
));
1087 faces_vertex_idx_ptr
= faces_vertex_idx_data
= HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size
);
1088 memcpy(faces_vertex_idx_data
, ptr
+ sizeof(DWORD
) + This
->nb_vertices
* sizeof(D3DVECTOR
) + sizeof(DWORD
), faces_vertex_idx_size
);
1090 /* Each vertex index will have its normal index counterpart so just allocate twice the size */
1091 This
->pFaceData
= HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size
* 2);
1092 faces_data_ptr
= (DWORD
*)This
->pFaceData
;
1096 IDirectXFileObject
*object
;
1098 hr
= IDirectXFileData_GetNextObject(pData
, &object
);
1099 if (hr
== DXFILEERR_NOMOREOBJECTS
)
1101 TRACE("No more object\n");
1104 if (hr
!= DXFILE_OK
)
1107 hr
= IDirectXFileObject_QueryInterface(object
, &IID_IDirectXFileData
, (void**)&pData2
);
1108 IDirectXFileObject_Release(object
);
1109 if (hr
!= DXFILE_OK
)
1112 hr
= IDirectXFileData_GetType(pData2
, &guid
);
1113 if (hr
!= DXFILE_OK
)
1116 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1118 if (IsEqualGUID(guid
, &TID_D3DRMMeshNormals
))
1120 DWORD nb_faces_normals
;
1121 DWORD faces_normal_idx_size
;
1123 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1124 if (hr
!= DXFILE_OK
)
1127 This
->nb_normals
= *(DWORD
*)ptr
;
1128 nb_faces_normals
= *(DWORD
*)(ptr
+ sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
));
1130 TRACE("MeshNormals: nb_normals = %d, nb_faces_normals = %d\n", This
->nb_normals
, nb_faces_normals
);
1131 if (nb_faces_normals
!= This
->nb_faces
)
1132 WARN("nb_face_normals (%d) != nb_faces (%d)\n", nb_faces_normals
, This
->nb_normals
);
1134 This
->pNormals
= HeapAlloc(GetProcessHeap(), 0, This
->nb_normals
* sizeof(D3DVECTOR
));
1135 memcpy(This
->pNormals
, ptr
+ sizeof(DWORD
), This
->nb_normals
* sizeof(D3DVECTOR
));
1137 faces_normal_idx_size
= size
- (2 * sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
));
1138 faces_normal_idx_ptr
= faces_normal_idx_data
= HeapAlloc(GetProcessHeap(), 0, faces_normal_idx_size
);
1139 memcpy(faces_normal_idx_data
, ptr
+ sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
) + sizeof(DWORD
), faces_normal_idx_size
);
1141 else if (IsEqualGUID(guid
, &TID_D3DRMMeshTextureCoords
))
1143 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1144 if (hr
!= DXFILE_OK
)
1147 This
->nb_coords2d
= *(DWORD
*)ptr
;
1149 TRACE("MeshTextureCoords: nb_coords2d = %d\n", This
->nb_coords2d
);
1151 This
->pCoords2d
= HeapAlloc(GetProcessHeap(), 0, This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1152 memcpy(This
->pCoords2d
, ptr
+ sizeof(DWORD
), This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1155 else if (IsEqualGUID(guid
, &TID_D3DRMMeshMaterialList
))
1158 DWORD nb_face_indices
;
1160 IDirectXFileObject
*child
;
1164 TRACE("Process MeshMaterialList\n");
1166 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1167 if (hr
!= DXFILE_OK
)
1170 nb_materials
= *(DWORD
*)ptr
;
1171 nb_face_indices
= *(DWORD
*)(ptr
+ sizeof(DWORD
));
1172 data_size
= 2 * sizeof(DWORD
) + nb_face_indices
* sizeof(DWORD
);
1174 TRACE("nMaterials = %u, nFaceIndexes = %u\n", nb_materials
, nb_face_indices
);
1176 if (size
!= data_size
)
1177 WARN("Returned size %u does not match expected one %u\n", size
, data_size
);
1179 This
->material_indices
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
->material_indices
) * nb_face_indices
);
1180 if (!This
->material_indices
)
1182 memcpy(This
->material_indices
, ptr
+ 2 * sizeof(DWORD
), sizeof(*This
->material_indices
) * nb_face_indices
),
1184 This
->materials
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
->materials
) * nb_materials
);
1185 if (!This
->materials
)
1187 HeapFree(GetProcessHeap(), 0, This
->material_indices
);
1190 This
->nb_materials
= nb_materials
;
1192 while (SUCCEEDED(hr
= IDirectXFileData_GetNextObject(pData2
, &child
)) && (i
< nb_materials
))
1194 IDirectXFileData
*data
;
1195 IDirectXFileDataReference
*reference
;
1196 IDirectXFileObject
*material_child
;
1198 hr
= IDirectXFileObject_QueryInterface(child
, &IID_IDirectXFileData
, (void **)&data
);
1201 hr
= IDirectXFileObject_QueryInterface(child
, &IID_IDirectXFileDataReference
, (void **)&reference
);
1202 IDirectXFileObject_Release(child
);
1206 hr
= IDirectXFileDataReference_Resolve(reference
, &data
);
1207 IDirectXFileDataReference_Release(reference
);
1213 IDirectXFileObject_Release(child
);
1216 hr
= Direct3DRMMaterial_create(&This
->materials
[i
].material
);
1219 IDirectXFileData_Release(data
);
1223 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&ptr
);
1224 if (hr
!= DXFILE_OK
)
1226 IDirectXFileData_Release(data
);
1231 WARN("Material size %u does not match expected one %u\n", size
, 44);
1233 values
= (float*)ptr
;
1235 This
->materials
[i
].color
= RGBA_MAKE((BYTE
)(values
[0] * 255.0f
), (BYTE
)(values
[1] * 255.0f
),
1236 (BYTE
)(values
[2] * 255.0f
), (BYTE
)(values
[3] * 255.0f
));
1238 IDirect3DRMMaterial2_SetAmbient(This
->materials
[i
].material
, values
[0], values
[1], values
[2]); /* Alpha ignored */
1239 IDirect3DRMMaterial2_SetPower(This
->materials
[i
].material
, values
[4]);
1240 IDirect3DRMMaterial2_SetSpecular(This
->materials
[i
].material
, values
[5], values
[6], values
[7]);
1241 IDirect3DRMMaterial2_SetEmissive(This
->materials
[i
].material
, values
[8], values
[9], values
[10]);
1243 This
->materials
[i
].texture
= NULL
;
1245 hr
= IDirectXFileData_GetNextObject(data
, &material_child
);
1248 IDirectXFileData
*data
;
1251 hr
= IDirectXFileObject_QueryInterface(material_child
, &IID_IDirectXFileData
, (void **)&data
);
1254 IDirectXFileDataReference
*reference
;
1256 hr
= IDirectXFileObject_QueryInterface(material_child
, &IID_IDirectXFileDataReference
, (void **)&reference
);
1260 hr
= IDirectXFileDataReference_Resolve(reference
, &data
);
1261 IDirectXFileDataReference_Release(reference
);
1266 hr
= IDirectXFileData_GetType(data
, &guid
);
1267 if (hr
!= DXFILE_OK
)
1269 if (!IsEqualGUID(guid
, &TID_D3DRMTextureFilename
))
1271 WARN("Not a texture filename\n");
1276 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&filename
);
1279 if (load_texture_proc
)
1281 IDirect3DRMTexture
*texture
;
1283 hr
= load_texture_proc(*filename
, arg
, &texture
);
1286 hr
= IDirect3DTexture_QueryInterface(texture
, &IID_IDirect3DRMTexture3
, (void**)&This
->materials
[i
].texture
);
1287 IDirect3DTexture_Release(texture
);
1294 /* If the texture file is not found, no texture is associated with the material */
1295 file
= CreateFileA(*filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
1296 if (file
!= INVALID_HANDLE_VALUE
)
1300 hr
= Direct3DRMTexture_create(&IID_IDirect3DRMTexture3
, (IUnknown
**)&This
->materials
[i
].texture
);
1303 IDirectXFileData_Release(data
);
1310 else if (hr
!= DXFILEERR_NOMOREOBJECTS
)
1316 IDirectXFileData_Release(data
);
1321 IDirectXFileObject_Release(child
);
1322 WARN("Found more sub-objects than expected\n");
1324 else if (hr
!= DXFILEERR_NOMOREOBJECTS
)
1332 FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(guid
));
1335 IDirectXFileData_Release(pData2
);
1339 if (!This
->nb_normals
)
1341 /* Allocate normals, one per vertex */
1342 This
->pNormals
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->nb_vertices
* sizeof(D3DVECTOR
));
1343 if (!This
->pNormals
)
1347 for (i
= 0; i
< This
->nb_faces
; i
++)
1350 DWORD nb_face_indexes
;
1351 D3DVECTOR face_normal
;
1353 if (faces_vertex_idx_size
< sizeof(DWORD
))
1354 WARN("Not enough data to read number of indices of face %d\n", i
);
1356 nb_face_indexes
= *(faces_data_ptr
+ faces_data_size
++) = *(faces_vertex_idx_ptr
++);
1357 faces_vertex_idx_size
--;
1358 if (faces_normal_idx_data
&& (*(faces_normal_idx_ptr
++) != nb_face_indexes
))
1359 WARN("Faces indices number mismatch\n");
1361 if (faces_vertex_idx_size
< (nb_face_indexes
* sizeof(DWORD
)))
1362 WARN("Not enough data to read all indices of face %d\n", i
);
1364 if (!This
->nb_normals
)
1366 /* Compute face normal */
1367 if (nb_face_indexes
> 2)
1371 D3DRMVectorSubtract(&a
, &This
->pVertices
[faces_vertex_idx_ptr
[2]], &This
->pVertices
[faces_vertex_idx_ptr
[1]]);
1372 D3DRMVectorSubtract(&b
, &This
->pVertices
[faces_vertex_idx_ptr
[0]], &This
->pVertices
[faces_vertex_idx_ptr
[1]]);
1373 D3DRMVectorCrossProduct(&face_normal
, &a
, &b
);
1374 D3DRMVectorNormalize(&face_normal
);
1378 face_normal
.u1
.x
= 0.0f
;
1379 face_normal
.u2
.y
= 0.0f
;
1380 face_normal
.u3
.z
= 0.0f
;
1384 for (j
= 0; j
< nb_face_indexes
; j
++)
1386 /* Copy vertex index */
1387 *(faces_data_ptr
+ faces_data_size
++) = *faces_vertex_idx_ptr
;
1388 /* Copy normal index */
1389 if (This
->nb_normals
)
1391 /* Read from x file */
1392 *(faces_data_ptr
+ faces_data_size
++) = *(faces_normal_idx_ptr
++);
1396 DWORD vertex_idx
= *faces_vertex_idx_ptr
;
1397 if (vertex_idx
>= This
->nb_vertices
)
1399 WARN("Found vertex index %u but only %u vertices available => use index 0\n", vertex_idx
, This
->nb_vertices
);
1402 *(faces_data_ptr
+ faces_data_size
++) = vertex_idx
;
1403 /* Add face normal to vertex normal */
1404 D3DRMVectorAdd(&This
->pNormals
[vertex_idx
], &This
->pNormals
[vertex_idx
], &face_normal
);
1406 faces_vertex_idx_ptr
++;
1408 faces_vertex_idx_size
-= nb_face_indexes
;
1411 /* Last DWORD must be 0 */
1412 *(faces_data_ptr
+ faces_data_size
++) = 0;
1414 /* Set size (in number of DWORD) of all faces data */
1415 This
->face_data_size
= faces_data_size
;
1417 if (!This
->nb_normals
)
1419 /* Normalize all normals */
1420 for (i
= 0; i
< This
->nb_vertices
; i
++)
1422 D3DRMVectorNormalize(&This
->pNormals
[i
]);
1424 This
->nb_normals
= This
->nb_vertices
;
1427 /* If there is no texture coordinates, generate default texture coordinates (0.0f, 0.0f) for each vertex */
1428 if (!This
->pCoords2d
)
1430 This
->nb_coords2d
= This
->nb_vertices
;
1431 This
->pCoords2d
= HeapAlloc(GetProcessHeap(), 0, This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1432 for (i
= 0; i
< This
->nb_coords2d
; i
++)
1434 This
->pCoords2d
[i
].u
= 0.0f
;
1435 This
->pCoords2d
[i
].v
= 0.0f
;
1439 TRACE("Mesh data loaded successfully\n");
1445 HeapFree(GetProcessHeap(), 0, faces_normal_idx_data
);
1446 HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data
);
1451 static HRESULT WINAPI
d3drm_mesh_builder3_Load(IDirect3DRMMeshBuilder3
*iface
, void *filename
,
1452 void *name
, D3DRMLOADOPTIONS loadflags
, D3DRMLOADTEXTURE3CALLBACK cb
, void *arg
)
1454 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1455 DXFILELOADOPTIONS load_options
;
1456 IDirectXFile
*dxfile
= NULL
;
1457 IDirectXFileEnumObject
*enum_object
= NULL
;
1458 IDirectXFileData
*data
= NULL
;
1461 struct d3drm_file_header
*header
;
1463 HRESULT ret
= D3DRMERR_BADOBJECT
;
1465 TRACE("iface %p, filename %p, name %p, loadflags %#x, cb %p, arg %p.\n",
1466 iface
, filename
, name
, loadflags
, cb
, arg
);
1468 clean_mesh_builder_data(mesh_builder
);
1470 if (loadflags
== D3DRMLOAD_FROMMEMORY
)
1472 load_options
= DXFILELOAD_FROMMEMORY
;
1474 else if (loadflags
== D3DRMLOAD_FROMFILE
)
1476 load_options
= DXFILELOAD_FROMFILE
;
1477 TRACE("Loading from file %s\n", debugstr_a(filename
));
1481 FIXME("Load options %d not supported yet\n", loadflags
);
1485 hr
= DirectXFileCreate(&dxfile
);
1486 if (hr
!= DXFILE_OK
)
1489 hr
= IDirectXFile_RegisterTemplates(dxfile
, templates
, strlen(templates
));
1490 if (hr
!= DXFILE_OK
)
1493 hr
= IDirectXFile_CreateEnumObject(dxfile
, filename
, load_options
, &enum_object
);
1494 if (hr
!= DXFILE_OK
)
1497 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &data
);
1498 if (hr
!= DXFILE_OK
)
1501 hr
= IDirectXFileData_GetType(data
, &guid
);
1502 if (hr
!= DXFILE_OK
)
1505 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1507 if (!IsEqualGUID(guid
, &TID_DXFILEHeader
))
1509 ret
= D3DRMERR_BADFILE
;
1513 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&header
);
1514 if ((hr
!= DXFILE_OK
) || (size
!= sizeof(*header
)))
1517 TRACE("Version is %u.%u, flags %#x.\n", header
->major
, header
->minor
, header
->flags
);
1519 /* Version must be 1.0.x */
1520 if ((header
->major
!= 1) || (header
->minor
!= 0))
1522 ret
= D3DRMERR_BADFILE
;
1526 IDirectXFileData_Release(data
);
1529 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &data
);
1530 if (hr
!= DXFILE_OK
)
1532 ret
= D3DRMERR_NOTFOUND
;
1536 hr
= IDirectXFileData_GetType(data
, &guid
);
1537 if (hr
!= DXFILE_OK
)
1540 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1542 if (!IsEqualGUID(guid
, &TID_D3DRMMesh
))
1544 ret
= D3DRMERR_NOTFOUND
;
1548 /* We don't care about the texture interface version since we rely on QueryInterface */
1549 hr
= load_mesh_data(iface
, data
, (D3DRMLOADTEXTURECALLBACK
)cb
, arg
);
1556 IDirectXFileData_Release(data
);
1558 IDirectXFileEnumObject_Release(enum_object
);
1560 IDirectXFile_Release(dxfile
);
1562 if (ret
!= D3DRM_OK
)
1563 clean_mesh_builder_data(mesh_builder
);
1568 static HRESULT WINAPI
d3drm_mesh_builder3_Save(IDirect3DRMMeshBuilder3
*iface
,
1569 const char *filename
, D3DRMXOFFORMAT format
, D3DRMSAVEOPTIONS flags
)
1571 FIXME("iface %p, filename %s, format %#x, flags %#x stub!\n",
1572 iface
, debugstr_a(filename
), format
, flags
);
1577 static HRESULT WINAPI
d3drm_mesh_builder3_Scale(IDirect3DRMMeshBuilder3
*iface
,
1578 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
1580 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1583 TRACE("iface %p, sx %.8e, sy %.8e, sz %.8e.\n", iface
, sx
, sy
, sz
);
1585 for (i
= 0; i
< mesh_builder
->nb_vertices
; ++i
)
1587 mesh_builder
->pVertices
[i
].u1
.x
*= sx
;
1588 mesh_builder
->pVertices
[i
].u2
.y
*= sy
;
1589 mesh_builder
->pVertices
[i
].u3
.z
*= sz
;
1592 /* Normals are not affected by Scale */
1597 static HRESULT WINAPI
d3drm_mesh_builder3_Translate(IDirect3DRMMeshBuilder3
*iface
,
1598 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
1600 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
1605 static HRESULT WINAPI
d3drm_mesh_builder3_SetColorSource(IDirect3DRMMeshBuilder3
*iface
,
1606 D3DRMCOLORSOURCE source
)
1608 FIXME("iface %p, source %#x stub!\n", iface
, source
);
1613 static HRESULT WINAPI
d3drm_mesh_builder3_GetBox(IDirect3DRMMeshBuilder3
*iface
, D3DRMBOX
*box
)
1615 FIXME("iface %p, box %p stub!\n", iface
, box
);
1620 static HRESULT WINAPI
d3drm_mesh_builder3_GenerateNormals(IDirect3DRMMeshBuilder3
*iface
,
1621 D3DVALUE crease
, DWORD flags
)
1623 FIXME("iface %p, crease %.8e, flags %#x stub!\n", iface
, crease
, flags
);
1628 static D3DRMCOLORSOURCE WINAPI
d3drm_mesh_builder3_GetColorSource(IDirect3DRMMeshBuilder3
*iface
)
1630 FIXME("iface %p stub!\n", iface
);
1635 static HRESULT WINAPI
d3drm_mesh_builder3_AddMesh(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMMesh
*mesh
)
1637 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
1642 static HRESULT WINAPI
d3drm_mesh_builder3_AddMeshBuilder(IDirect3DRMMeshBuilder3
*iface
,
1643 IDirect3DRMMeshBuilder3
*mesh_builder
, DWORD flags
)
1645 FIXME("iface %p, mesh_builder %p, flags %#x stub!\n", iface
, mesh_builder
, flags
);
1650 static HRESULT WINAPI
d3drm_mesh_builder3_AddFrame(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFrame3
*frame
)
1652 FIXME("iface %p, frame %p stub!\n", iface
, frame
);
1657 static HRESULT WINAPI
d3drm_mesh_builder3_AddFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
*face
)
1659 FIXME("iface %p, face %p stub!\n", iface
, face
);
1664 static HRESULT WINAPI
d3drm_mesh_builder3_AddFaces(IDirect3DRMMeshBuilder3
*iface
,
1665 DWORD vertex_count
, D3DVECTOR
*vertices
, DWORD normal_count
, D3DVECTOR
*normals
,
1666 DWORD
*face_data
, IDirect3DRMFaceArray
**array
)
1668 FIXME("iface %p, vertex_count %u, vertices %p, normal_count %u, normals %p, face_data %p array %p stub!\n",
1669 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data
, array
);
1674 static HRESULT WINAPI
d3drm_mesh_builder3_ReserveSpace(IDirect3DRMMeshBuilder3
*iface
,
1675 DWORD vertex_count
, DWORD normal_count
, DWORD face_count
)
1677 FIXME("iface %p, vertex_count %u, normal_count %u, face_count %u stub!\n",
1678 iface
, vertex_count
, normal_count
, face_count
);
1683 static HRESULT WINAPI
d3drm_mesh_builder3_SetColorRGB(IDirect3DRMMeshBuilder3
*iface
,
1684 D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
1686 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1688 TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface
, red
, green
, blue
);
1690 mesh_builder
->color
= RGBA_MAKE((BYTE
)(red
* 255.0f
), (BYTE
)(green
* 255.0f
), (BYTE
)(blue
* 255.0f
), 0xff);
1695 static HRESULT WINAPI
d3drm_mesh_builder3_SetColor(IDirect3DRMMeshBuilder3
*iface
, D3DCOLOR color
)
1697 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1699 TRACE("iface %p, color 0x%08x.\n", iface
, color
);
1701 mesh_builder
->color
= color
;
1706 static HRESULT WINAPI
d3drm_mesh_builder3_SetTexture(IDirect3DRMMeshBuilder3
*iface
,
1707 IDirect3DRMTexture3
*texture
)
1709 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1711 TRACE("iface %p, texture %p.\n", iface
, texture
);
1714 IDirect3DRMTexture3_AddRef(texture
);
1715 if (mesh_builder
->texture
)
1716 IDirect3DRMTexture3_Release(mesh_builder
->texture
);
1717 mesh_builder
->texture
= texture
;
1722 static HRESULT WINAPI
d3drm_mesh_builder3_SetMaterial(IDirect3DRMMeshBuilder3
*iface
,
1723 IDirect3DRMMaterial2
*material
)
1725 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1727 TRACE("iface %p, material %p.\n", iface
, material
);
1730 IDirect3DRMTexture2_AddRef(material
);
1731 if (mesh_builder
->material
)
1732 IDirect3DRMTexture2_Release(mesh_builder
->material
);
1733 mesh_builder
->material
= material
;
1738 static HRESULT WINAPI
d3drm_mesh_builder3_SetTextureTopology(IDirect3DRMMeshBuilder3
*iface
,
1739 BOOL wrap_u
, BOOL wrap_v
)
1741 FIXME("iface %p, wrap_u %#x, wrap_v %#x stub!\n", iface
, wrap_u
, wrap_v
);
1746 static HRESULT WINAPI
d3drm_mesh_builder3_SetQuality(IDirect3DRMMeshBuilder3
*iface
,
1747 D3DRMRENDERQUALITY quality
)
1749 FIXME("iface %p, quality %#x stub!\n", iface
, quality
);
1754 static HRESULT WINAPI
d3drm_mesh_builder3_SetPerspective(IDirect3DRMMeshBuilder3
*iface
,
1757 FIXME("iface %p, enable %#x stub!\n", iface
, enable
);
1762 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertex(IDirect3DRMMeshBuilder3
*iface
,
1763 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1765 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
1770 static HRESULT WINAPI
d3drm_mesh_builder3_SetNormal(IDirect3DRMMeshBuilder3
*iface
,
1771 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1773 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
1778 static HRESULT WINAPI
d3drm_mesh_builder3_SetTextureCoordinates(IDirect3DRMMeshBuilder3
*iface
,
1779 DWORD index
, D3DVALUE u
, D3DVALUE v
)
1781 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1783 TRACE("iface %p, index %u, u %.8e, v %.8e.\n", iface
, index
, u
, v
);
1785 if (index
>= mesh_builder
->nb_coords2d
)
1786 return D3DRMERR_BADVALUE
;
1788 mesh_builder
->pCoords2d
[index
].u
= u
;
1789 mesh_builder
->pCoords2d
[index
].v
= v
;
1794 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertexColor(IDirect3DRMMeshBuilder3
*iface
,
1795 DWORD index
, D3DCOLOR color
)
1797 FIXME("iface %p, index %u, color 0x%08x stub!\n", iface
, index
, color
);
1802 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertexColorRGB(IDirect3DRMMeshBuilder3
*iface
,
1803 DWORD index
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
1805 FIXME("iface %p, index %u, red %.8e, green %.8e, blue %.8e stub!\n",
1806 iface
, index
, red
, green
, blue
);
1811 static HRESULT WINAPI
d3drm_mesh_builder3_GetFaces(IDirect3DRMMeshBuilder3
*iface
,
1812 IDirect3DRMFaceArray
**array
)
1814 FIXME("iface %p, array %p stub!\n", iface
, array
);
1819 static HRESULT WINAPI
d3drm_mesh_builder3_GetGeometry(IDirect3DRMMeshBuilder3
*iface
,
1820 DWORD
*vertex_count
, D3DVECTOR
*vertices
, DWORD
*normal_count
, D3DVECTOR
*normals
,
1821 DWORD
*face_data_size
, DWORD
*face_data
)
1823 FIXME("iface %p, vertex_count %p, vertices %p, normal_count %p, normals %p, "
1824 "face_data_size %p, face_data %p stub!\n",
1825 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data_size
, face_data
);
1830 static HRESULT WINAPI
d3drm_mesh_builder3_GetTextureCoordinates(IDirect3DRMMeshBuilder3
*iface
,
1831 DWORD index
, D3DVALUE
*u
, D3DVALUE
*v
)
1833 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1835 TRACE("iface %p, index %u, u %p, v %p.\n", iface
, index
, u
, v
);
1837 if (index
>= mesh_builder
->nb_coords2d
)
1838 return D3DRMERR_BADVALUE
;
1840 *u
= mesh_builder
->pCoords2d
[index
].u
;
1841 *v
= mesh_builder
->pCoords2d
[index
].v
;
1846 static int WINAPI
d3drm_mesh_builder3_AddVertex(IDirect3DRMMeshBuilder3
*iface
,
1847 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1849 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
1854 static int WINAPI
d3drm_mesh_builder3_AddNormal(IDirect3DRMMeshBuilder3
*iface
,
1855 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1857 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
1862 static HRESULT WINAPI
d3drm_mesh_builder3_CreateFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
**face
)
1864 TRACE("iface %p, face %p.\n", iface
, face
);
1866 return Direct3DRMFace_create(&IID_IDirect3DRMFace2
, (IUnknown
**)face
);
1869 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_builder3_GetQuality(IDirect3DRMMeshBuilder3
*iface
)
1871 FIXME("iface %p stub!\n", iface
);
1876 static BOOL WINAPI
d3drm_mesh_builder3_GetPerspective(IDirect3DRMMeshBuilder3
*iface
)
1878 FIXME("iface %p stub!\n", iface
);
1883 static int WINAPI
d3drm_mesh_builder3_GetFaceCount(IDirect3DRMMeshBuilder3
*iface
)
1885 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1887 TRACE("iface %p.\n", iface
);
1889 return mesh_builder
->nb_faces
;
1892 static int WINAPI
d3drm_mesh_builder3_GetVertexCount(IDirect3DRMMeshBuilder3
*iface
)
1894 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1896 TRACE("iface %p.\n", iface
);
1898 return mesh_builder
->nb_vertices
;
1901 static D3DCOLOR WINAPI
d3drm_mesh_builder3_GetVertexColor(IDirect3DRMMeshBuilder3
*iface
,
1904 FIXME("iface %p, index %u stub!\n", iface
, index
);
1909 static HRESULT WINAPI
d3drm_mesh_builder3_CreateMesh(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMMesh
**mesh
)
1911 struct d3drm_mesh_builder
*This
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1913 D3DRMGROUPINDEX group
;
1915 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
1920 hr
= Direct3DRMMesh_create(mesh
);
1924 /* If there is mesh data, create a group and put data inside */
1925 if (This
->nb_vertices
)
1929 D3DRMVERTEX
* vertices
;
1931 vertices
= HeapAlloc(GetProcessHeap(), 0, This
->nb_vertices
* sizeof(D3DRMVERTEX
));
1934 IDirect3DRMMesh_Release(*mesh
);
1935 return E_OUTOFMEMORY
;
1937 for (i
= 0; i
< This
->nb_vertices
; i
++)
1938 vertices
[i
].position
= This
->pVertices
[i
];
1939 hr
= IDirect3DRMMesh_SetVertices(*mesh
, 0, 0, This
->nb_vertices
, vertices
);
1940 HeapFree(GetProcessHeap(), 0, vertices
);
1942 /* Groups are in reverse order compared to materials list in X file */
1943 for (k
= This
->nb_materials
- 1; k
>= 0; k
--)
1945 unsigned* face_data
;
1947 DWORD
* in_ptr
= This
->pFaceData
;
1948 ULONG vertex_per_face
= 0;
1949 BOOL
* used_vertices
;
1950 unsigned nb_vertices
= 0;
1951 unsigned nb_faces
= 0;
1953 used_vertices
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->face_data_size
* sizeof(*used_vertices
));
1956 IDirect3DRMMesh_Release(*mesh
);
1957 return E_OUTOFMEMORY
;
1960 face_data
= HeapAlloc(GetProcessHeap(), 0, This
->face_data_size
* sizeof(*face_data
));
1963 HeapFree(GetProcessHeap(), 0, used_vertices
);
1964 IDirect3DRMMesh_Release(*mesh
);
1965 return E_OUTOFMEMORY
;
1967 out_ptr
= face_data
;
1969 /* If all faces have the same number of vertex, set vertex_per_face */
1970 for (i
= 0; i
< This
->nb_faces
; i
++)
1972 /* Process only faces belonging to the group */
1973 if (This
->material_indices
[i
] == k
)
1975 if (vertex_per_face
&& (vertex_per_face
!= *in_ptr
))
1977 vertex_per_face
= *in_ptr
;
1979 in_ptr
+= 1 + *in_ptr
* 2;
1981 if (i
!= This
->nb_faces
)
1982 vertex_per_face
= 0;
1984 /* Put only vertex indices */
1985 in_ptr
= This
->pFaceData
;
1986 for (i
= 0; i
< This
->nb_faces
; i
++)
1988 DWORD nb_indices
= *in_ptr
++;
1990 /* Skip faces not belonging to the group */
1991 if (This
->material_indices
[i
] != k
)
1993 in_ptr
+= 2 * nb_indices
;
1997 /* Don't put nb indices when vertex_per_face is set */
1998 if (vertex_per_face
)
1999 *out_ptr
++ = nb_indices
;
2001 for (j
= 0; j
< nb_indices
; j
++)
2003 *out_ptr
= *in_ptr
++;
2004 used_vertices
[*out_ptr
++] = TRUE
;
2005 /* Skip normal index */
2012 for (i
= 0; i
< This
->nb_vertices
; i
++)
2013 if (used_vertices
[i
])
2016 hr
= IDirect3DRMMesh_AddGroup(*mesh
, nb_vertices
, nb_faces
, vertex_per_face
, face_data
, &group
);
2017 HeapFree(GetProcessHeap(), 0, used_vertices
);
2018 HeapFree(GetProcessHeap(), 0, face_data
);
2020 hr
= IDirect3DRMMesh_SetGroupColor(*mesh
, group
, This
->materials
[k
].color
);
2022 hr
= IDirect3DRMMesh_SetGroupMaterial(*mesh
, group
,
2023 (IDirect3DRMMaterial
*)This
->materials
[k
].material
);
2024 if (SUCCEEDED(hr
) && This
->materials
[k
].texture
)
2026 IDirect3DRMTexture
*texture
;
2028 IDirect3DRMTexture3_QueryInterface(This
->materials
[k
].texture
,
2029 &IID_IDirect3DRMTexture
, (void **)&texture
);
2030 hr
= IDirect3DRMMesh_SetGroupTexture(*mesh
, group
, texture
);
2031 IDirect3DRMTexture_Release(texture
);
2035 IDirect3DRMMesh_Release(*mesh
);
2044 static HRESULT WINAPI
d3drm_mesh_builder3_GetFace(IDirect3DRMMeshBuilder3
*iface
,
2045 DWORD index
, IDirect3DRMFace2
**face
)
2047 FIXME("iface %p, index %u, face %p stub!\n", iface
, index
, face
);
2052 static HRESULT WINAPI
d3drm_mesh_builder3_GetVertex(IDirect3DRMMeshBuilder3
*iface
,
2053 DWORD index
, D3DVECTOR
*vector
)
2055 FIXME("iface %p, index %u, vector %p stub!\n", iface
, index
, vector
);
2060 static HRESULT WINAPI
d3drm_mesh_builder3_GetNormal(IDirect3DRMMeshBuilder3
*iface
,
2061 DWORD index
, D3DVECTOR
*vector
)
2063 FIXME("iface %p, index %u, vector %p stub!\n", iface
, index
, vector
);
2068 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteVertices(IDirect3DRMMeshBuilder3
*iface
,
2069 DWORD start_idx
, DWORD count
)
2071 FIXME("iface %p, start_idx %u, count %u stub!\n", iface
, start_idx
, count
);
2076 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteNormals(IDirect3DRMMeshBuilder3
*iface
,
2077 DWORD start_idx
, DWORD count
)
2079 FIXME("iface %p, start_idx %u, count %u stub!\n", iface
, start_idx
, count
);
2084 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
*face
)
2086 FIXME("iface %p, face %p stub!\n", iface
, face
);
2091 static HRESULT WINAPI
d3drm_mesh_builder3_Empty(IDirect3DRMMeshBuilder3
*iface
, DWORD flags
)
2093 FIXME("iface %p, flags %#x stub!\n", iface
, flags
);
2098 static HRESULT WINAPI
d3drm_mesh_builder3_Optimize(IDirect3DRMMeshBuilder3
*iface
, DWORD flags
)
2100 FIXME("iface %p, flags %#x stub!\n", iface
, flags
);
2105 static HRESULT WINAPI
d3drm_mesh_builder3_AddFacesIndexed(IDirect3DRMMeshBuilder3
*iface
,
2106 DWORD flags
, DWORD
*indices
, DWORD
*start_idx
, DWORD
*count
)
2108 FIXME("iface %p, flags %#x, indices %p, start_idx %p, count %p stub!\n",
2109 iface
, flags
, indices
, start_idx
, count
);
2114 static HRESULT WINAPI
d3drm_mesh_builder3_CreateSubMesh(IDirect3DRMMeshBuilder3
*iface
, IUnknown
**mesh
)
2116 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
2121 static HRESULT WINAPI
d3drm_mesh_builder3_GetParentMesh(IDirect3DRMMeshBuilder3
*iface
,
2122 DWORD flags
, IUnknown
**parent
)
2124 FIXME("iface %p, flags %#x, parent %p stub!\n", iface
, flags
, parent
);
2129 static HRESULT WINAPI
d3drm_mesh_builder3_GetSubMeshes(IDirect3DRMMeshBuilder3
*iface
,
2130 DWORD
*count
, IUnknown
**meshes
)
2132 FIXME("iface %p, count %p, meshes %p stub!\n", iface
, count
, meshes
);
2137 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteSubMesh(IDirect3DRMMeshBuilder3
*iface
, IUnknown
*mesh
)
2139 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
2144 static HRESULT WINAPI
d3drm_mesh_builder3_Enable(IDirect3DRMMeshBuilder3
*iface
, DWORD index
)
2146 FIXME("iface %p, index %u stub!\n", iface
, index
);
2151 static HRESULT WINAPI
d3drm_mesh_builder3_GetEnable(IDirect3DRMMeshBuilder3
*iface
, DWORD
*indices
)
2153 FIXME("iface %p, indices %p stub!\n", iface
, indices
);
2158 static HRESULT WINAPI
d3drm_mesh_builder3_AddTriangles(IDirect3DRMMeshBuilder3
*iface
,
2159 DWORD flags
, DWORD format
, DWORD vertex_count
, void *data
)
2161 FIXME("iface %p, flags %#x, format %#x, vertex_count %u, data %p stub!\n",
2162 iface
, flags
, format
, vertex_count
, data
);
2167 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertices(IDirect3DRMMeshBuilder3
*iface
,
2168 DWORD start_idx
, DWORD count
, D3DVECTOR
*vector
)
2170 FIXME("iface %p, start_idx %u, count %u, vector %p stub!\n", iface
, start_idx
, count
, vector
);
2175 static HRESULT WINAPI
d3drm_mesh_builder3_GetVertices(IDirect3DRMMeshBuilder3
*iface
,
2176 DWORD start_idx
, DWORD
*vertex_count
, D3DVECTOR
*vertices
)
2178 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2179 DWORD count
= mesh_builder
->nb_vertices
- start_idx
;
2181 TRACE("iface %p, start_idx %u, vertex_count %p, vertices %p.\n",
2182 iface
, start_idx
, vertex_count
, vertices
);
2185 *vertex_count
= count
;
2186 if (vertices
&& mesh_builder
->nb_vertices
)
2187 memcpy(vertices
, mesh_builder
->pVertices
+ start_idx
, count
* sizeof(*vertices
));
2192 static HRESULT WINAPI
d3drm_mesh_builder3_SetNormals(IDirect3DRMMeshBuilder3
*iface
,
2193 DWORD start_idx
, DWORD count
, D3DVECTOR
*vector
)
2195 FIXME("iface %p, start_idx %u, count %u, vector %p stub!\n",
2196 iface
, start_idx
, count
, vector
);
2201 static HRESULT WINAPI
d3drm_mesh_builder3_GetNormals(IDirect3DRMMeshBuilder3
*iface
,
2202 DWORD start_idx
, DWORD
*normal_count
, D3DVECTOR
*normals
)
2204 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2205 DWORD count
= mesh_builder
->nb_normals
- start_idx
;
2207 TRACE("iface %p, start_idx %u, normal_count %p, normals %p stub!\n",
2208 iface
, start_idx
, normal_count
, normals
);
2211 *normal_count
= count
;
2212 if (normals
&& mesh_builder
->nb_normals
)
2213 memcpy(normals
, mesh_builder
->pNormals
+ start_idx
, count
* sizeof(*normals
));
2218 static int WINAPI
d3drm_mesh_builder3_GetNormalCount(IDirect3DRMMeshBuilder3
*iface
)
2220 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2222 TRACE("iface %p.\n", iface
);
2224 return mesh_builder
->nb_normals
;
2227 static const struct IDirect3DRMMeshBuilder3Vtbl d3drm_mesh_builder3_vtbl
=
2229 d3drm_mesh_builder3_QueryInterface
,
2230 d3drm_mesh_builder3_AddRef
,
2231 d3drm_mesh_builder3_Release
,
2232 d3drm_mesh_builder3_Clone
,
2233 d3drm_mesh_builder3_AddDestroyCallback
,
2234 d3drm_mesh_builder3_DeleteDestroyCallback
,
2235 d3drm_mesh_builder3_SetAppData
,
2236 d3drm_mesh_builder3_GetAppData
,
2237 d3drm_mesh_builder3_SetName
,
2238 d3drm_mesh_builder3_GetName
,
2239 d3drm_mesh_builder3_GetClassName
,
2240 d3drm_mesh_builder3_Load
,
2241 d3drm_mesh_builder3_Save
,
2242 d3drm_mesh_builder3_Scale
,
2243 d3drm_mesh_builder3_Translate
,
2244 d3drm_mesh_builder3_SetColorSource
,
2245 d3drm_mesh_builder3_GetBox
,
2246 d3drm_mesh_builder3_GenerateNormals
,
2247 d3drm_mesh_builder3_GetColorSource
,
2248 d3drm_mesh_builder3_AddMesh
,
2249 d3drm_mesh_builder3_AddMeshBuilder
,
2250 d3drm_mesh_builder3_AddFrame
,
2251 d3drm_mesh_builder3_AddFace
,
2252 d3drm_mesh_builder3_AddFaces
,
2253 d3drm_mesh_builder3_ReserveSpace
,
2254 d3drm_mesh_builder3_SetColorRGB
,
2255 d3drm_mesh_builder3_SetColor
,
2256 d3drm_mesh_builder3_SetTexture
,
2257 d3drm_mesh_builder3_SetMaterial
,
2258 d3drm_mesh_builder3_SetTextureTopology
,
2259 d3drm_mesh_builder3_SetQuality
,
2260 d3drm_mesh_builder3_SetPerspective
,
2261 d3drm_mesh_builder3_SetVertex
,
2262 d3drm_mesh_builder3_SetNormal
,
2263 d3drm_mesh_builder3_SetTextureCoordinates
,
2264 d3drm_mesh_builder3_SetVertexColor
,
2265 d3drm_mesh_builder3_SetVertexColorRGB
,
2266 d3drm_mesh_builder3_GetFaces
,
2267 d3drm_mesh_builder3_GetGeometry
,
2268 d3drm_mesh_builder3_GetTextureCoordinates
,
2269 d3drm_mesh_builder3_AddVertex
,
2270 d3drm_mesh_builder3_AddNormal
,
2271 d3drm_mesh_builder3_CreateFace
,
2272 d3drm_mesh_builder3_GetQuality
,
2273 d3drm_mesh_builder3_GetPerspective
,
2274 d3drm_mesh_builder3_GetFaceCount
,
2275 d3drm_mesh_builder3_GetVertexCount
,
2276 d3drm_mesh_builder3_GetVertexColor
,
2277 d3drm_mesh_builder3_CreateMesh
,
2278 d3drm_mesh_builder3_GetFace
,
2279 d3drm_mesh_builder3_GetVertex
,
2280 d3drm_mesh_builder3_GetNormal
,
2281 d3drm_mesh_builder3_DeleteVertices
,
2282 d3drm_mesh_builder3_DeleteNormals
,
2283 d3drm_mesh_builder3_DeleteFace
,
2284 d3drm_mesh_builder3_Empty
,
2285 d3drm_mesh_builder3_Optimize
,
2286 d3drm_mesh_builder3_AddFacesIndexed
,
2287 d3drm_mesh_builder3_CreateSubMesh
,
2288 d3drm_mesh_builder3_GetParentMesh
,
2289 d3drm_mesh_builder3_GetSubMeshes
,
2290 d3drm_mesh_builder3_DeleteSubMesh
,
2291 d3drm_mesh_builder3_Enable
,
2292 d3drm_mesh_builder3_GetEnable
,
2293 d3drm_mesh_builder3_AddTriangles
,
2294 d3drm_mesh_builder3_SetVertices
,
2295 d3drm_mesh_builder3_GetVertices
,
2296 d3drm_mesh_builder3_SetNormals
,
2297 d3drm_mesh_builder3_GetNormals
,
2298 d3drm_mesh_builder3_GetNormalCount
,
2301 HRESULT
Direct3DRMMeshBuilder_create(REFIID riid
, IUnknown
**out
)
2303 struct d3drm_mesh_builder
*object
;
2305 TRACE("riid %s, out %p.\n", debugstr_guid(riid
), out
);
2307 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2308 return E_OUTOFMEMORY
;
2310 object
->IDirect3DRMMeshBuilder2_iface
.lpVtbl
= &d3drm_mesh_builder2_vtbl
;
2311 object
->IDirect3DRMMeshBuilder3_iface
.lpVtbl
= &d3drm_mesh_builder3_vtbl
;
2314 if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder3
))
2315 *out
= (IUnknown
*)&object
->IDirect3DRMMeshBuilder3_iface
;
2317 *out
= (IUnknown
*)&object
->IDirect3DRMMeshBuilder2_iface
;
2322 static HRESULT WINAPI
d3drm_mesh_QueryInterface(IDirect3DRMMesh
*iface
, REFIID riid
, void **out
)
2324 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
2326 if (IsEqualGUID(riid
, &IID_IDirect3DRMMesh
)
2327 || IsEqualGUID(riid
, &IID_IUnknown
))
2329 IDirect3DRMMesh_AddRef(iface
);
2334 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
2337 return E_NOINTERFACE
;
2340 static ULONG WINAPI
d3drm_mesh_AddRef(IDirect3DRMMesh
*iface
)
2342 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2343 ULONG refcount
= InterlockedIncrement(&mesh
->ref
);
2345 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
2350 static ULONG WINAPI
d3drm_mesh_Release(IDirect3DRMMesh
*iface
)
2352 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2353 ULONG refcount
= InterlockedDecrement(&mesh
->ref
);
2355 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
2361 for (i
= 0; i
< mesh
->nb_groups
; ++i
)
2363 HeapFree(GetProcessHeap(), 0, mesh
->groups
[i
].vertices
);
2364 HeapFree(GetProcessHeap(), 0, mesh
->groups
[i
].face_data
);
2365 if (mesh
->groups
[i
].material
)
2366 IDirect3DRMMaterial2_Release(mesh
->groups
[i
].material
);
2367 if (mesh
->groups
[i
].texture
)
2368 IDirect3DRMTexture3_Release(mesh
->groups
[i
].texture
);
2370 HeapFree(GetProcessHeap(), 0, mesh
->groups
);
2371 HeapFree(GetProcessHeap(), 0, mesh
);
2377 static HRESULT WINAPI
d3drm_mesh_Clone(IDirect3DRMMesh
*iface
,
2378 IUnknown
*outer
, REFIID iid
, void **out
)
2380 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
2385 static HRESULT WINAPI
d3drm_mesh_AddDestroyCallback(IDirect3DRMMesh
*iface
,
2386 D3DRMOBJECTCALLBACK cb
, void *ctx
)
2388 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
2393 static HRESULT WINAPI
d3drm_mesh_DeleteDestroyCallback(IDirect3DRMMesh
*iface
,
2394 D3DRMOBJECTCALLBACK cb
, void *ctx
)
2396 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
2401 static HRESULT WINAPI
d3drm_mesh_SetAppData(IDirect3DRMMesh
*iface
, DWORD data
)
2403 FIXME("iface %p, data %#x stub!\n", iface
, data
);
2408 static DWORD WINAPI
d3drm_mesh_GetAppData(IDirect3DRMMesh
*iface
)
2410 FIXME("iface %p stub!\n", iface
);
2415 static HRESULT WINAPI
d3drm_mesh_SetName(IDirect3DRMMesh
*iface
, const char *name
)
2417 FIXME("iface %p, name %s stub!\n", iface
, debugstr_a(name
));
2422 static HRESULT WINAPI
d3drm_mesh_GetName(IDirect3DRMMesh
*iface
, DWORD
*size
, char *name
)
2424 FIXME("iface %p, size %p, name %p stub!\n", iface
, size
, name
);
2429 static HRESULT WINAPI
d3drm_mesh_GetClassName(IDirect3DRMMesh
*iface
, DWORD
*size
, char *name
)
2431 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
2433 if (!size
|| *size
< strlen("Mesh") || !name
)
2434 return E_INVALIDARG
;
2436 strcpy(name
, "Mesh");
2437 *size
= sizeof("Mesh");
2442 static HRESULT WINAPI
d3drm_mesh_Scale(IDirect3DRMMesh
*iface
,
2443 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
2445 FIXME("iface %p, sx %.8e, sy %.8e, sz %.8e stub!\n", iface
, sx
, sy
, sz
);
2450 static HRESULT WINAPI
d3drm_mesh_Translate(IDirect3DRMMesh
*iface
,
2451 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
2453 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
2458 static HRESULT WINAPI
d3drm_mesh_GetBox(IDirect3DRMMesh
*iface
, D3DRMBOX
*box
)
2460 FIXME("iface %p, box %p stub!\n", iface
, box
);
2465 static HRESULT WINAPI
d3drm_mesh_AddGroup(IDirect3DRMMesh
*iface
, unsigned vertex_count
,
2466 unsigned face_count
, unsigned vertex_per_face
, unsigned *face_data
, D3DRMGROUPINDEX
*id
)
2468 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2469 struct mesh_group
*group
;
2471 TRACE("iface %p, vertex_count %u, face_count %u, vertex_per_face %u, face_data %p, id %p.\n",
2472 iface
, vertex_count
, face_count
, vertex_per_face
, face_data
, id
);
2474 if (!face_data
|| !id
)
2477 if ((mesh
->nb_groups
+ 1) > mesh
->groups_capacity
)
2479 struct mesh_group
*groups
;
2482 if (!mesh
->groups_capacity
)
2485 groups
= HeapAlloc(GetProcessHeap(), 0, new_capacity
* sizeof(*groups
));
2489 new_capacity
= mesh
->groups_capacity
* 2;
2490 groups
= HeapReAlloc(GetProcessHeap(), 0, mesh
->groups
, new_capacity
* sizeof(*groups
));
2494 return E_OUTOFMEMORY
;
2496 mesh
->groups_capacity
= new_capacity
;
2497 mesh
->groups
= groups
;
2500 group
= mesh
->groups
+ mesh
->nb_groups
;
2502 group
->vertices
= HeapAlloc(GetProcessHeap(), 0, vertex_count
* sizeof(D3DRMVERTEX
));
2503 if (!group
->vertices
)
2504 return E_OUTOFMEMORY
;
2505 group
->nb_vertices
= vertex_count
;
2506 group
->nb_faces
= face_count
;
2507 group
->vertex_per_face
= vertex_per_face
;
2509 if (vertex_per_face
)
2511 group
->face_data_size
= face_count
* vertex_per_face
;
2516 unsigned nb_indices
;
2517 unsigned* face_data_ptr
= face_data
;
2518 group
->face_data_size
= 0;
2520 for (i
= 0; i
< face_count
; i
++)
2522 nb_indices
= *face_data_ptr
;
2523 group
->face_data_size
+= nb_indices
+ 1;
2524 face_data_ptr
+= nb_indices
;
2528 group
->face_data
= HeapAlloc(GetProcessHeap(), 0, group
->face_data_size
* sizeof(unsigned));
2529 if (!group
->face_data
)
2531 HeapFree(GetProcessHeap(), 0 , group
->vertices
);
2532 return E_OUTOFMEMORY
;
2535 memcpy(group
->face_data
, face_data
, group
->face_data_size
* sizeof(unsigned));
2537 group
->material
= NULL
;
2538 group
->texture
= NULL
;
2540 *id
= mesh
->nb_groups
++;
2545 static HRESULT WINAPI
d3drm_mesh_SetVertices(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX group_id
,
2546 unsigned int start_idx
, unsigned int count
, D3DRMVERTEX
*values
)
2548 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2550 TRACE("iface %p, group_id %#x, start_idx %u, count %u, values %p.\n",
2551 iface
, group_id
, start_idx
, count
, values
);
2553 if (group_id
>= mesh
->nb_groups
)
2554 return D3DRMERR_BADVALUE
;
2556 if ((start_idx
+ count
- 1) >= mesh
->groups
[group_id
].nb_vertices
)
2557 return D3DRMERR_BADVALUE
;
2562 memcpy(mesh
->groups
[group_id
].vertices
+ start_idx
, values
, count
* sizeof(*values
));
2567 static HRESULT WINAPI
d3drm_mesh_SetGroupColor(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DCOLOR color
)
2569 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2571 TRACE("iface %p, id %#x, color 0x%08x.\n", iface
, id
, color
);
2573 if (id
>= mesh
->nb_groups
)
2574 return D3DRMERR_BADVALUE
;
2576 mesh
->groups
[id
].color
= color
;
2581 static HRESULT WINAPI
d3drm_mesh_SetGroupColorRGB(IDirect3DRMMesh
*iface
,
2582 D3DRMGROUPINDEX id
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
2584 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2586 TRACE("iface %p, id %#x, red %.8e, green %.8e, blue %.8e.\n", iface
, id
, red
, green
, blue
);
2588 if (id
>= mesh
->nb_groups
)
2589 return D3DRMERR_BADVALUE
;
2591 mesh
->groups
[id
].color
= RGBA_MAKE((BYTE
)(red
* 255.0f
), (BYTE
)(green
* 255.0f
), (BYTE
)(blue
* 255.0f
), 0xff);
2596 static HRESULT WINAPI
d3drm_mesh_SetGroupMapping(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DRMMAPPING value
)
2598 FIXME("iface %p, id %#x, value %#x stub!\n", iface
, id
, value
);
2603 static HRESULT WINAPI
d3drm_mesh_SetGroupQuality(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DRMRENDERQUALITY value
)
2605 FIXME("iface %p, id %#x, value %#x stub!\n", iface
, id
, value
);
2610 static HRESULT WINAPI
d3drm_mesh_SetGroupMaterial(IDirect3DRMMesh
*iface
,
2611 D3DRMGROUPINDEX id
, IDirect3DRMMaterial
*material
)
2613 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2615 TRACE("iface %p, id %#x, material %p.\n", iface
, id
, material
);
2617 if (id
>= mesh
->nb_groups
)
2618 return D3DRMERR_BADVALUE
;
2620 if (mesh
->groups
[id
].material
)
2621 IDirect3DRMMaterial2_Release(mesh
->groups
[id
].material
);
2623 mesh
->groups
[id
].material
= (IDirect3DRMMaterial2
*)material
;
2626 IDirect3DRMMaterial2_AddRef(mesh
->groups
[id
].material
);
2631 static HRESULT WINAPI
d3drm_mesh_SetGroupTexture(IDirect3DRMMesh
*iface
,
2632 D3DRMGROUPINDEX id
, IDirect3DRMTexture
*texture
)
2634 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2636 TRACE("iface %p, id %#x, texture %p.\n", iface
, id
, texture
);
2638 if (id
>= mesh
->nb_groups
)
2639 return D3DRMERR_BADVALUE
;
2641 if (mesh
->groups
[id
].texture
)
2642 IDirect3DRMTexture3_Release(mesh
->groups
[id
].texture
);
2646 mesh
->groups
[id
].texture
= NULL
;
2650 return IDirect3DRMTexture3_QueryInterface(texture
, &IID_IDirect3DRMTexture
, (void **)&mesh
->groups
[id
].texture
);
2653 static DWORD WINAPI
d3drm_mesh_GetGroupCount(IDirect3DRMMesh
*iface
)
2655 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2657 TRACE("iface %p.\n", iface
);
2659 return mesh
->nb_groups
;
2662 static HRESULT WINAPI
d3drm_mesh_GetGroup(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, unsigned *vertex_count
,
2663 unsigned *face_count
, unsigned *vertex_per_face
, DWORD
*face_data_size
, unsigned *face_data
)
2665 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2667 TRACE("iface %p, id %#x, vertex_count %p, face_count %p, vertex_per_face %p, face_data_size %p, face_data %p.\n",
2668 iface
, id
, vertex_count
, face_count
, vertex_per_face
, face_data_size
,face_data
);
2670 if (id
>= mesh
->nb_groups
)
2671 return D3DRMERR_BADVALUE
;
2674 *vertex_count
= mesh
->groups
[id
].nb_vertices
;
2676 *face_count
= mesh
->groups
[id
].nb_faces
;
2677 if (vertex_per_face
)
2678 *vertex_per_face
= mesh
->groups
[id
].vertex_per_face
;
2680 *face_data_size
= mesh
->groups
[id
].face_data_size
;
2682 memcpy(face_data
, mesh
->groups
[id
].face_data
, mesh
->groups
[id
].face_data_size
* sizeof(*face_data
));
2687 static HRESULT WINAPI
d3drm_mesh_GetVertices(IDirect3DRMMesh
*iface
,
2688 D3DRMGROUPINDEX group_id
, DWORD start_idx
, DWORD count
, D3DRMVERTEX
*vertices
)
2690 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2692 TRACE("iface %p, group_id %#x, start_idx %u, count %u, vertices %p.\n",
2693 iface
, group_id
, start_idx
, count
, vertices
);
2695 if (group_id
>= mesh
->nb_groups
)
2696 return D3DRMERR_BADVALUE
;
2698 if ((start_idx
+ count
- 1) >= mesh
->groups
[group_id
].nb_vertices
)
2699 return D3DRMERR_BADVALUE
;
2704 memcpy(vertices
, mesh
->groups
[group_id
].vertices
+ start_idx
, count
* sizeof(*vertices
));
2709 static D3DCOLOR WINAPI
d3drm_mesh_GetGroupColor(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2711 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2713 TRACE("iface %p, id %#x.\n", iface
, id
);
2715 return mesh
->groups
[id
].color
;
2718 static D3DRMMAPPING WINAPI
d3drm_mesh_GetGroupMapping(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2720 FIXME("iface %p, id %#x stub!\n", iface
, id
);
2724 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_GetGroupQuality(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2726 FIXME("iface %p, id %#x stub!\n", iface
, id
);
2731 static HRESULT WINAPI
d3drm_mesh_GetGroupMaterial(IDirect3DRMMesh
*iface
,
2732 D3DRMGROUPINDEX id
, IDirect3DRMMaterial
**material
)
2734 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2736 TRACE("iface %p, id %#x, material %p.\n", iface
, id
, material
);
2738 if (id
>= mesh
->nb_groups
)
2739 return D3DRMERR_BADVALUE
;
2744 if (mesh
->groups
[id
].material
)
2745 IDirect3DRMTexture_QueryInterface(mesh
->groups
[id
].material
, &IID_IDirect3DRMMaterial
, (void **)material
);
2752 static HRESULT WINAPI
d3drm_mesh_GetGroupTexture(IDirect3DRMMesh
*iface
,
2753 D3DRMGROUPINDEX id
, IDirect3DRMTexture
**texture
)
2755 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2757 TRACE("iface %p, id %#x, texture %p.\n", iface
, id
, texture
);
2759 if (id
>= mesh
->nb_groups
)
2760 return D3DRMERR_BADVALUE
;
2765 if (mesh
->groups
[id
].texture
)
2766 IDirect3DRMTexture_QueryInterface(mesh
->groups
[id
].texture
, &IID_IDirect3DRMTexture
, (void **)texture
);
2773 static const struct IDirect3DRMMeshVtbl d3drm_mesh_vtbl
=
2775 d3drm_mesh_QueryInterface
,
2779 d3drm_mesh_AddDestroyCallback
,
2780 d3drm_mesh_DeleteDestroyCallback
,
2781 d3drm_mesh_SetAppData
,
2782 d3drm_mesh_GetAppData
,
2785 d3drm_mesh_GetClassName
,
2787 d3drm_mesh_Translate
,
2789 d3drm_mesh_AddGroup
,
2790 d3drm_mesh_SetVertices
,
2791 d3drm_mesh_SetGroupColor
,
2792 d3drm_mesh_SetGroupColorRGB
,
2793 d3drm_mesh_SetGroupMapping
,
2794 d3drm_mesh_SetGroupQuality
,
2795 d3drm_mesh_SetGroupMaterial
,
2796 d3drm_mesh_SetGroupTexture
,
2797 d3drm_mesh_GetGroupCount
,
2798 d3drm_mesh_GetGroup
,
2799 d3drm_mesh_GetVertices
,
2800 d3drm_mesh_GetGroupColor
,
2801 d3drm_mesh_GetGroupMapping
,
2802 d3drm_mesh_GetGroupQuality
,
2803 d3drm_mesh_GetGroupMaterial
,
2804 d3drm_mesh_GetGroupTexture
,
2807 HRESULT
Direct3DRMMesh_create(IDirect3DRMMesh
**mesh
)
2809 struct d3drm_mesh
*object
;
2811 TRACE("mesh %p.\n", mesh
);
2813 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2814 return E_OUTOFMEMORY
;
2816 object
->IDirect3DRMMesh_iface
.lpVtbl
= &d3drm_mesh_vtbl
;
2819 *mesh
= &object
->IDirect3DRMMesh_iface
;