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 mesh_builder
->materials
= NULL
;
360 HeapFree(GetProcessHeap(), 0, mesh_builder
->material_indices
);
361 mesh_builder
->material_indices
= NULL
;
364 static HRESULT WINAPI
d3drm_mesh_builder2_QueryInterface(IDirect3DRMMeshBuilder2
*iface
, REFIID riid
, void **out
)
366 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
368 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
370 if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder2
)
371 || IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder
)
372 || IsEqualGUID(riid
, &IID_IUnknown
))
374 *out
= &mesh_builder
->IDirect3DRMMeshBuilder2_iface
;
376 else if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder3
))
378 *out
= &mesh_builder
->IDirect3DRMMeshBuilder3_iface
;
383 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
384 return E_NOINTERFACE
;
387 IUnknown_AddRef((IUnknown
*)*out
);
391 static ULONG WINAPI
d3drm_mesh_builder2_AddRef(IDirect3DRMMeshBuilder2
*iface
)
393 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
394 ULONG refcount
= InterlockedIncrement(&mesh_builder
->ref
);
396 TRACE("%p increasing refcount to %u.\n", mesh_builder
, refcount
);
401 static ULONG WINAPI
d3drm_mesh_builder2_Release(IDirect3DRMMeshBuilder2
*iface
)
403 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
404 ULONG refcount
= InterlockedDecrement(&mesh_builder
->ref
);
406 TRACE("%p decreasing refcount to %u.\n", mesh_builder
, refcount
);
410 clean_mesh_builder_data(mesh_builder
);
411 if (mesh_builder
->material
)
412 IDirect3DRMMaterial2_Release(mesh_builder
->material
);
413 if (mesh_builder
->texture
)
414 IDirect3DRMTexture3_Release(mesh_builder
->texture
);
415 HeapFree(GetProcessHeap(), 0, mesh_builder
);
421 static HRESULT WINAPI
d3drm_mesh_builder2_Clone(IDirect3DRMMeshBuilder2
*iface
,
422 IUnknown
*outer
, REFIID iid
, void **out
)
424 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
429 static HRESULT WINAPI
d3drm_mesh_builder2_AddDestroyCallback(IDirect3DRMMeshBuilder2
*iface
,
430 D3DRMOBJECTCALLBACK cb
, void *ctx
)
432 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
437 static HRESULT WINAPI
d3drm_mesh_builder2_DeleteDestroyCallback(IDirect3DRMMeshBuilder2
*iface
,
438 D3DRMOBJECTCALLBACK cb
, void *ctx
)
440 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
445 static HRESULT WINAPI
d3drm_mesh_builder2_SetAppData(IDirect3DRMMeshBuilder2
*iface
, DWORD data
)
447 FIXME("iface %p, data %#x stub!\n", iface
, data
);
452 static DWORD WINAPI
d3drm_mesh_builder2_GetAppData(IDirect3DRMMeshBuilder2
*iface
)
454 FIXME("iface %p stub!\n", iface
);
459 static HRESULT WINAPI
d3drm_mesh_builder2_SetName(IDirect3DRMMeshBuilder2
*iface
, const char *name
)
461 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
463 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
465 return IDirect3DRMMeshBuilder3_SetName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, name
);
468 static HRESULT WINAPI
d3drm_mesh_builder2_GetName(IDirect3DRMMeshBuilder2
*iface
, DWORD
*size
, char *name
)
470 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
472 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
474 return IDirect3DRMMeshBuilder3_GetName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, size
, name
);
477 static HRESULT WINAPI
d3drm_mesh_builder2_GetClassName(IDirect3DRMMeshBuilder2
*iface
, DWORD
*size
, char *name
)
479 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
481 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
483 return IDirect3DRMMeshBuilder3_GetClassName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, size
, name
);
486 static HRESULT WINAPI
d3drm_mesh_builder2_Load(IDirect3DRMMeshBuilder2
*iface
, void *filename
,
487 void *name
, D3DRMLOADOPTIONS flags
, D3DRMLOADTEXTURECALLBACK cb
, void *ctx
)
489 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
491 TRACE("iface %p, filename %p, name %p, flags %#x, cb %p, ctx %p.\n",
492 iface
, filename
, name
, flags
, cb
, ctx
);
495 FIXME("Texture callback is not yet supported\n");
497 return IDirect3DRMMeshBuilder3_Load(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
498 filename
, name
, flags
, NULL
, ctx
);
501 static HRESULT WINAPI
d3drm_mesh_builder2_Save(IDirect3DRMMeshBuilder2
*iface
,
502 const char *filename
, D3DRMXOFFORMAT format
, D3DRMSAVEOPTIONS flags
)
504 FIXME("iface %p, filename %s, format %#x, flags %#x stub!\n",
505 iface
, debugstr_a(filename
), format
, flags
);
510 static HRESULT WINAPI
d3drm_mesh_builder2_Scale(IDirect3DRMMeshBuilder2
*iface
,
511 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
513 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
515 TRACE("iface %p, sx %.8e, sy %.8e, sz %.8e.\n", iface
, sx
, sy
, sz
);
517 return IDirect3DRMMeshBuilder3_Scale(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, sx
, sy
, sz
);
520 static HRESULT WINAPI
d3drm_mesh_builder2_Translate(IDirect3DRMMeshBuilder2
*iface
,
521 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
523 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
528 static HRESULT WINAPI
d3drm_mesh_builder2_SetColorSource(IDirect3DRMMeshBuilder2
*iface
, D3DRMCOLORSOURCE source
)
530 FIXME("iface %p, source %#x stub!\n", iface
, source
);
535 static HRESULT WINAPI
d3drm_mesh_builder2_GetBox(IDirect3DRMMeshBuilder2
*iface
, D3DRMBOX
*box
)
537 FIXME("iface %p, box %p stub!\n", iface
, box
);
542 static HRESULT WINAPI
d3drm_mesh_builder2_GenerateNormals(IDirect3DRMMeshBuilder2
*iface
)
544 FIXME("iface %p stub!\n", iface
);
549 static D3DRMCOLORSOURCE WINAPI
d3drm_mesh_builder2_GetColorSource(IDirect3DRMMeshBuilder2
*iface
)
551 FIXME("iface %p stub!\n", iface
);
556 static HRESULT WINAPI
d3drm_mesh_builder2_AddMesh(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMMesh
*mesh
)
558 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
563 static HRESULT WINAPI
d3drm_mesh_builder2_AddMeshBuilder(IDirect3DRMMeshBuilder2
*iface
,
564 IDirect3DRMMeshBuilder
*mesh_builder
)
566 FIXME("iface %p, mesh_builder %p stub!\n", iface
, mesh_builder
);
571 static HRESULT WINAPI
d3drm_mesh_builder2_AddFrame(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFrame
*frame
)
573 FIXME("iface %p, frame %p stub!\n", iface
, frame
);
578 static HRESULT WINAPI
d3drm_mesh_builder2_AddFace(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFace
*face
)
580 FIXME("iface %p, face %p stub!\n", iface
, face
);
585 static HRESULT WINAPI
d3drm_mesh_builder2_AddFaces(IDirect3DRMMeshBuilder2
*iface
,
586 DWORD vertex_count
, D3DVECTOR
*vertices
, DWORD normal_count
, D3DVECTOR
*normals
,
587 DWORD
*face_data
, IDirect3DRMFaceArray
**array
)
589 FIXME("iface %p, vertex_count %u, vertices %p, normal_count %u, normals %p, face_data %p, array %p stub!\n",
590 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data
, array
);
595 static HRESULT WINAPI
d3drm_mesh_builder2_ReserveSpace(IDirect3DRMMeshBuilder2
*iface
,
596 DWORD vertex_count
, DWORD normal_count
, DWORD face_count
)
598 FIXME("iface %p, vertex_count %u, normal_count %u, face_count %u stub!\n",
599 iface
, vertex_count
, normal_count
, face_count
);
604 static HRESULT WINAPI
d3drm_mesh_builder2_SetColorRGB(IDirect3DRMMeshBuilder2
*iface
,
605 D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
607 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
609 TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface
, red
, green
, blue
);
611 return IDirect3DRMMeshBuilder3_SetColorRGB(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, red
, green
, blue
);
614 static HRESULT WINAPI
d3drm_mesh_builder2_SetColor(IDirect3DRMMeshBuilder2
*iface
, D3DCOLOR color
)
616 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
618 TRACE("iface %p, color 0x%08x.\n", iface
, color
);
620 return IDirect3DRMMeshBuilder3_SetColor(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, color
);
623 static HRESULT WINAPI
d3drm_mesh_builder2_SetTexture(IDirect3DRMMeshBuilder2
*iface
,
624 IDirect3DRMTexture
*texture
)
626 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
627 IDirect3DRMTexture3
*texture3
= NULL
;
628 HRESULT hr
= D3DRM_OK
;
630 TRACE("iface %p, texture %p.\n", iface
, texture
);
633 hr
= IDirect3DRMTexture_QueryInterface(texture
, &IID_IDirect3DRMTexture3
, (void **)&texture3
);
635 hr
= IDirect3DRMMeshBuilder3_SetTexture(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, texture3
);
637 IDirect3DRMTexture3_Release(texture3
);
642 static HRESULT WINAPI
d3drm_mesh_builder2_SetMaterial(IDirect3DRMMeshBuilder2
*iface
,
643 IDirect3DRMMaterial
*material
)
645 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
647 TRACE("iface %p, material %p.\n", iface
, material
);
649 return IDirect3DRMMeshBuilder3_SetMaterial(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
650 (IDirect3DRMMaterial2
*)material
);
653 static HRESULT WINAPI
d3drm_mesh_builder2_SetTextureTopology(IDirect3DRMMeshBuilder2
*iface
,
654 BOOL wrap_u
, BOOL wrap_v
)
656 FIXME("iface %p, wrap_u %#x, wrap_v %#x stub!\n", iface
, wrap_u
, wrap_v
);
661 static HRESULT WINAPI
d3drm_mesh_builder2_SetQuality(IDirect3DRMMeshBuilder2
*iface
,
662 D3DRMRENDERQUALITY quality
)
664 FIXME("iface %p, quality %#x stub!\n", iface
, quality
);
669 static HRESULT WINAPI
d3drm_mesh_builder2_SetPerspective(IDirect3DRMMeshBuilder2
*iface
, BOOL enable
)
671 FIXME("iface %p, enable %#x stub!\n", iface
, enable
);
676 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertex(IDirect3DRMMeshBuilder2
*iface
,
677 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
679 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
684 static HRESULT WINAPI
d3drm_mesh_builder2_SetNormal(IDirect3DRMMeshBuilder2
*iface
,
685 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
687 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
692 static HRESULT WINAPI
d3drm_mesh_builder2_SetTextureCoordinates(IDirect3DRMMeshBuilder2
*iface
,
693 DWORD index
, D3DVALUE u
, D3DVALUE v
)
695 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
697 TRACE("iface %p, index %u, u %.8e, v %.8e.\n", iface
, index
, u
, v
);
699 return IDirect3DRMMeshBuilder3_SetTextureCoordinates(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
703 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertexColor(IDirect3DRMMeshBuilder2
*iface
,
704 DWORD index
, D3DCOLOR color
)
706 FIXME("iface %p, index %u, color 0x%08x stub!\n", iface
, index
, color
);
711 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertexColorRGB(IDirect3DRMMeshBuilder2
*iface
,
712 DWORD index
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
714 FIXME("iface %p, index %u, red %.8e, green %.8e, blue %.8e stub!\n",
715 iface
, index
, red
, green
, blue
);
720 static HRESULT WINAPI
d3drm_mesh_builder2_GetFaces(IDirect3DRMMeshBuilder2
*iface
,
721 IDirect3DRMFaceArray
**array
)
723 FIXME("iface %p, array %p stub!\n", iface
, array
);
728 static HRESULT WINAPI
d3drm_mesh_builder2_GetVertices(IDirect3DRMMeshBuilder2
*iface
,
729 DWORD
*vertex_count
, D3DVECTOR
*vertices
, DWORD
*normal_count
, D3DVECTOR
*normals
,
730 DWORD
*face_data_size
, DWORD
*face_data
)
732 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
734 TRACE("iface %p, vertex_count %p, vertices %p, normal_count %p, normals %p, face_data_size %p, face_data %p.\n",
735 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data_size
, face_data
);
737 if (vertices
&& (!vertex_count
|| (*vertex_count
< mesh_builder
->nb_vertices
)))
738 return D3DRMERR_BADVALUE
;
740 *vertex_count
= mesh_builder
->nb_vertices
;
741 if (vertices
&& mesh_builder
->nb_vertices
)
742 memcpy(vertices
, mesh_builder
->pVertices
, mesh_builder
->nb_vertices
* sizeof(*vertices
));
744 if (normals
&& (!normal_count
|| (*normal_count
< mesh_builder
->nb_normals
)))
745 return D3DRMERR_BADVALUE
;
747 *normal_count
= mesh_builder
->nb_normals
;
748 if (normals
&& mesh_builder
->nb_normals
)
749 memcpy(normals
, mesh_builder
->pNormals
, mesh_builder
->nb_normals
* sizeof(*normals
));
751 if (face_data
&& (!face_data_size
|| (*face_data_size
< mesh_builder
->face_data_size
)))
752 return D3DRMERR_BADVALUE
;
754 *face_data_size
= mesh_builder
->face_data_size
;
755 if (face_data
&& mesh_builder
->face_data_size
)
756 memcpy(face_data
, mesh_builder
->pFaceData
, mesh_builder
->face_data_size
* sizeof(*face_data
));
761 static HRESULT WINAPI
d3drm_mesh_builder2_GetTextureCoordinates(IDirect3DRMMeshBuilder2
*iface
,
762 DWORD index
, D3DVALUE
*u
, D3DVALUE
*v
)
764 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
766 TRACE("iface %p, index %u, u %p, v %p.\n", iface
, index
, u
, v
);
768 return IDirect3DRMMeshBuilder3_GetTextureCoordinates(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
772 static int WINAPI
d3drm_mesh_builder2_AddVertex(IDirect3DRMMeshBuilder2
*iface
,
773 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
775 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
780 static int WINAPI
d3drm_mesh_builder2_AddNormal(IDirect3DRMMeshBuilder2
*iface
,
781 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
783 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
788 static HRESULT WINAPI
d3drm_mesh_builder2_CreateFace(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFace
**face
)
790 TRACE("iface %p, face %p.\n", iface
, face
);
792 return Direct3DRMFace_create(&IID_IDirect3DRMFace
, (IUnknown
**)face
);
795 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_builder2_GetQuality(IDirect3DRMMeshBuilder2
*iface
)
797 FIXME("iface %p stub!\n", iface
);
802 static BOOL WINAPI
d3drm_mesh_builder2_GetPerspective(IDirect3DRMMeshBuilder2
*iface
)
804 FIXME("iface %p stub!\n", iface
);
809 static int WINAPI
d3drm_mesh_builder2_GetFaceCount(IDirect3DRMMeshBuilder2
*iface
)
811 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
813 TRACE("iface %p.\n", iface
);
815 return mesh_builder
->nb_faces
;
818 static int WINAPI
d3drm_mesh_builder2_GetVertexCount(IDirect3DRMMeshBuilder2
*iface
)
820 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
822 TRACE("iface %p.\n", iface
);
824 return mesh_builder
->nb_vertices
;
827 static D3DCOLOR WINAPI
d3drm_mesh_builder2_GetVertexColor(IDirect3DRMMeshBuilder2
*iface
, DWORD index
)
829 FIXME("iface %p, index %u stub!\n", iface
, index
);
834 static HRESULT WINAPI
d3drm_mesh_builder2_CreateMesh(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMMesh
**mesh
)
836 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
838 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
840 return IDirect3DRMMeshBuilder3_CreateMesh(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, mesh
);
843 static HRESULT WINAPI
d3drm_mesh_builder2_GenerateNormals2(IDirect3DRMMeshBuilder2
*iface
,
844 D3DVALUE crease
, DWORD flags
)
846 FIXME("iface %p, crease %.8e, flags %#x stub!\n", iface
, crease
, flags
);
851 static HRESULT WINAPI
d3drm_mesh_builder2_GetFace(IDirect3DRMMeshBuilder2
*iface
,
852 DWORD index
, IDirect3DRMFace
**face
)
854 FIXME("iface %p, index %u, face %p stub!\n", iface
, index
, face
);
859 static const struct IDirect3DRMMeshBuilder2Vtbl d3drm_mesh_builder2_vtbl
=
861 d3drm_mesh_builder2_QueryInterface
,
862 d3drm_mesh_builder2_AddRef
,
863 d3drm_mesh_builder2_Release
,
864 d3drm_mesh_builder2_Clone
,
865 d3drm_mesh_builder2_AddDestroyCallback
,
866 d3drm_mesh_builder2_DeleteDestroyCallback
,
867 d3drm_mesh_builder2_SetAppData
,
868 d3drm_mesh_builder2_GetAppData
,
869 d3drm_mesh_builder2_SetName
,
870 d3drm_mesh_builder2_GetName
,
871 d3drm_mesh_builder2_GetClassName
,
872 d3drm_mesh_builder2_Load
,
873 d3drm_mesh_builder2_Save
,
874 d3drm_mesh_builder2_Scale
,
875 d3drm_mesh_builder2_Translate
,
876 d3drm_mesh_builder2_SetColorSource
,
877 d3drm_mesh_builder2_GetBox
,
878 d3drm_mesh_builder2_GenerateNormals
,
879 d3drm_mesh_builder2_GetColorSource
,
880 d3drm_mesh_builder2_AddMesh
,
881 d3drm_mesh_builder2_AddMeshBuilder
,
882 d3drm_mesh_builder2_AddFrame
,
883 d3drm_mesh_builder2_AddFace
,
884 d3drm_mesh_builder2_AddFaces
,
885 d3drm_mesh_builder2_ReserveSpace
,
886 d3drm_mesh_builder2_SetColorRGB
,
887 d3drm_mesh_builder2_SetColor
,
888 d3drm_mesh_builder2_SetTexture
,
889 d3drm_mesh_builder2_SetMaterial
,
890 d3drm_mesh_builder2_SetTextureTopology
,
891 d3drm_mesh_builder2_SetQuality
,
892 d3drm_mesh_builder2_SetPerspective
,
893 d3drm_mesh_builder2_SetVertex
,
894 d3drm_mesh_builder2_SetNormal
,
895 d3drm_mesh_builder2_SetTextureCoordinates
,
896 d3drm_mesh_builder2_SetVertexColor
,
897 d3drm_mesh_builder2_SetVertexColorRGB
,
898 d3drm_mesh_builder2_GetFaces
,
899 d3drm_mesh_builder2_GetVertices
,
900 d3drm_mesh_builder2_GetTextureCoordinates
,
901 d3drm_mesh_builder2_AddVertex
,
902 d3drm_mesh_builder2_AddNormal
,
903 d3drm_mesh_builder2_CreateFace
,
904 d3drm_mesh_builder2_GetQuality
,
905 d3drm_mesh_builder2_GetPerspective
,
906 d3drm_mesh_builder2_GetFaceCount
,
907 d3drm_mesh_builder2_GetVertexCount
,
908 d3drm_mesh_builder2_GetVertexColor
,
909 d3drm_mesh_builder2_CreateMesh
,
910 d3drm_mesh_builder2_GenerateNormals2
,
911 d3drm_mesh_builder2_GetFace
,
914 static HRESULT WINAPI
d3drm_mesh_builder3_QueryInterface(IDirect3DRMMeshBuilder3
*iface
, REFIID riid
, void **out
)
916 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
918 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
920 return d3drm_mesh_builder2_QueryInterface(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
, riid
, out
);
923 static ULONG WINAPI
d3drm_mesh_builder3_AddRef(IDirect3DRMMeshBuilder3
*iface
)
925 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
927 TRACE("iface %p.\n", iface
);
929 return d3drm_mesh_builder2_AddRef(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
);
932 static ULONG WINAPI
d3drm_mesh_builder3_Release(IDirect3DRMMeshBuilder3
*iface
)
934 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
936 TRACE("iface %p.\n", iface
);
938 return d3drm_mesh_builder2_Release(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
);
941 static HRESULT WINAPI
d3drm_mesh_builder3_Clone(IDirect3DRMMeshBuilder3
*iface
,
942 IUnknown
*outer
, REFIID iid
, void **out
)
944 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
949 static HRESULT WINAPI
d3drm_mesh_builder3_AddDestroyCallback(IDirect3DRMMeshBuilder3
*iface
,
950 D3DRMOBJECTCALLBACK cb
, void *ctx
)
952 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
957 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteDestroyCallback(IDirect3DRMMeshBuilder3
*iface
,
958 D3DRMOBJECTCALLBACK cb
, void *ctx
)
960 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
965 static HRESULT WINAPI
d3drm_mesh_builder3_SetAppData(IDirect3DRMMeshBuilder3
*iface
, DWORD data
)
967 FIXME("iface %p, data %#x stub!\n", iface
, data
);
972 static DWORD WINAPI
d3drm_mesh_builder3_GetAppData(IDirect3DRMMeshBuilder3
*iface
)
974 FIXME("iface %p stub!\n", iface
);
979 static HRESULT WINAPI
d3drm_mesh_builder3_SetName(IDirect3DRMMeshBuilder3
*iface
, const char *name
)
981 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
984 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
988 string
= HeapAlloc(GetProcessHeap(), 0, strlen(name
) + 1);
989 if (!string
) return E_OUTOFMEMORY
;
990 strcpy(string
, name
);
992 HeapFree(GetProcessHeap(), 0, mesh_builder
->name
);
993 mesh_builder
->name
= string
;
998 static HRESULT WINAPI
d3drm_mesh_builder3_GetName(IDirect3DRMMeshBuilder3
*iface
,
999 DWORD
*size
, char *name
)
1001 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1003 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
1008 if (!mesh_builder
->name
)
1014 if (*size
< (strlen(mesh_builder
->name
) + 1))
1015 return E_INVALIDARG
;
1017 strcpy(name
, mesh_builder
->name
);
1018 *size
= strlen(mesh_builder
->name
) + 1;
1023 static HRESULT WINAPI
d3drm_mesh_builder3_GetClassName(IDirect3DRMMeshBuilder3
*iface
,
1024 DWORD
*size
, char *name
)
1026 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
1028 if (!size
|| *size
< strlen("Builder") || !name
)
1029 return E_INVALIDARG
;
1031 strcpy(name
, "Builder");
1032 *size
= sizeof("Builder");
1037 HRESULT
load_mesh_data(IDirect3DRMMeshBuilder3
*iface
, IDirectXFileData
*pData
,
1038 D3DRMLOADTEXTURECALLBACK load_texture_proc
, void *arg
)
1040 struct d3drm_mesh_builder
*This
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1041 IDirectXFileData
*pData2
= NULL
;
1046 HRESULT ret
= D3DRMERR_BADOBJECT
;
1047 DWORD
* faces_vertex_idx_data
= NULL
;
1048 DWORD
* faces_vertex_idx_ptr
;
1049 DWORD faces_vertex_idx_size
;
1050 DWORD
* faces_normal_idx_data
= NULL
;
1051 DWORD
* faces_normal_idx_ptr
= NULL
;
1052 DWORD
* faces_data_ptr
;
1053 DWORD faces_data_size
= 0;
1056 TRACE("(%p)->(%p)\n", This
, pData
);
1058 hr
= IDirectXFileData_GetName(pData
, NULL
, &size
);
1059 if (hr
!= DXFILE_OK
)
1063 This
->name
= HeapAlloc(GetProcessHeap(), 0, size
);
1065 return E_OUTOFMEMORY
;
1067 hr
= IDirectXFileData_GetName(pData
, This
->name
, &size
);
1068 if (hr
!= DXFILE_OK
)
1072 TRACE("Mesh name is '%s'\n", This
->name
? This
->name
: "");
1074 This
->nb_normals
= 0;
1076 hr
= IDirectXFileData_GetData(pData
, NULL
, &size
, (void**)&ptr
);
1077 if (hr
!= DXFILE_OK
)
1080 This
->nb_vertices
= *(DWORD
*)ptr
;
1081 This
->nb_faces
= *(DWORD
*)(ptr
+ sizeof(DWORD
) + This
->nb_vertices
* sizeof(D3DVECTOR
));
1082 faces_vertex_idx_size
= size
- sizeof(DWORD
) - This
->nb_vertices
* sizeof(D3DVECTOR
) - sizeof(DWORD
);
1084 TRACE("Mesh: nb_vertices = %d, nb_faces = %d, faces_vertex_idx_size = %d\n", This
->nb_vertices
, This
->nb_faces
, faces_vertex_idx_size
);
1086 This
->pVertices
= HeapAlloc(GetProcessHeap(), 0, This
->nb_vertices
* sizeof(D3DVECTOR
));
1087 memcpy(This
->pVertices
, ptr
+ sizeof(DWORD
), This
->nb_vertices
* sizeof(D3DVECTOR
));
1089 faces_vertex_idx_ptr
= faces_vertex_idx_data
= HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size
);
1090 memcpy(faces_vertex_idx_data
, ptr
+ sizeof(DWORD
) + This
->nb_vertices
* sizeof(D3DVECTOR
) + sizeof(DWORD
), faces_vertex_idx_size
);
1092 /* Each vertex index will have its normal index counterpart so just allocate twice the size */
1093 This
->pFaceData
= HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size
* 2);
1094 faces_data_ptr
= (DWORD
*)This
->pFaceData
;
1098 IDirectXFileObject
*object
;
1100 hr
= IDirectXFileData_GetNextObject(pData
, &object
);
1101 if (hr
== DXFILEERR_NOMOREOBJECTS
)
1103 TRACE("No more object\n");
1106 if (hr
!= DXFILE_OK
)
1109 hr
= IDirectXFileObject_QueryInterface(object
, &IID_IDirectXFileData
, (void**)&pData2
);
1110 IDirectXFileObject_Release(object
);
1111 if (hr
!= DXFILE_OK
)
1114 hr
= IDirectXFileData_GetType(pData2
, &guid
);
1115 if (hr
!= DXFILE_OK
)
1118 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1120 if (IsEqualGUID(guid
, &TID_D3DRMMeshNormals
))
1122 DWORD nb_faces_normals
;
1123 DWORD faces_normal_idx_size
;
1125 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1126 if (hr
!= DXFILE_OK
)
1129 This
->nb_normals
= *(DWORD
*)ptr
;
1130 nb_faces_normals
= *(DWORD
*)(ptr
+ sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
));
1132 TRACE("MeshNormals: nb_normals = %d, nb_faces_normals = %d\n", This
->nb_normals
, nb_faces_normals
);
1133 if (nb_faces_normals
!= This
->nb_faces
)
1134 WARN("nb_face_normals (%d) != nb_faces (%d)\n", nb_faces_normals
, This
->nb_normals
);
1136 This
->pNormals
= HeapAlloc(GetProcessHeap(), 0, This
->nb_normals
* sizeof(D3DVECTOR
));
1137 memcpy(This
->pNormals
, ptr
+ sizeof(DWORD
), This
->nb_normals
* sizeof(D3DVECTOR
));
1139 faces_normal_idx_size
= size
- (2 * sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
));
1140 faces_normal_idx_ptr
= faces_normal_idx_data
= HeapAlloc(GetProcessHeap(), 0, faces_normal_idx_size
);
1141 memcpy(faces_normal_idx_data
, ptr
+ sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
) + sizeof(DWORD
), faces_normal_idx_size
);
1143 else if (IsEqualGUID(guid
, &TID_D3DRMMeshTextureCoords
))
1145 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1146 if (hr
!= DXFILE_OK
)
1149 This
->nb_coords2d
= *(DWORD
*)ptr
;
1151 TRACE("MeshTextureCoords: nb_coords2d = %d\n", This
->nb_coords2d
);
1153 This
->pCoords2d
= HeapAlloc(GetProcessHeap(), 0, This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1154 memcpy(This
->pCoords2d
, ptr
+ sizeof(DWORD
), This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1157 else if (IsEqualGUID(guid
, &TID_D3DRMMeshMaterialList
))
1160 DWORD nb_face_indices
;
1162 IDirectXFileObject
*child
;
1166 TRACE("Process MeshMaterialList\n");
1168 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1169 if (hr
!= DXFILE_OK
)
1172 nb_materials
= *(DWORD
*)ptr
;
1173 nb_face_indices
= *(DWORD
*)(ptr
+ sizeof(DWORD
));
1174 data_size
= 2 * sizeof(DWORD
) + nb_face_indices
* sizeof(DWORD
);
1176 TRACE("nMaterials = %u, nFaceIndexes = %u\n", nb_materials
, nb_face_indices
);
1178 if (size
!= data_size
)
1179 WARN("Returned size %u does not match expected one %u\n", size
, data_size
);
1181 This
->material_indices
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
->material_indices
) * nb_face_indices
);
1182 if (!This
->material_indices
)
1184 memcpy(This
->material_indices
, ptr
+ 2 * sizeof(DWORD
), sizeof(*This
->material_indices
) * nb_face_indices
),
1186 This
->materials
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
->materials
) * nb_materials
);
1187 if (!This
->materials
)
1189 HeapFree(GetProcessHeap(), 0, This
->material_indices
);
1192 This
->nb_materials
= nb_materials
;
1194 while (SUCCEEDED(hr
= IDirectXFileData_GetNextObject(pData2
, &child
)) && (i
< nb_materials
))
1196 IDirectXFileData
*data
;
1197 IDirectXFileDataReference
*reference
;
1198 IDirectXFileObject
*material_child
;
1200 hr
= IDirectXFileObject_QueryInterface(child
, &IID_IDirectXFileData
, (void **)&data
);
1203 hr
= IDirectXFileObject_QueryInterface(child
, &IID_IDirectXFileDataReference
, (void **)&reference
);
1204 IDirectXFileObject_Release(child
);
1208 hr
= IDirectXFileDataReference_Resolve(reference
, &data
);
1209 IDirectXFileDataReference_Release(reference
);
1215 IDirectXFileObject_Release(child
);
1218 hr
= Direct3DRMMaterial_create(&This
->materials
[i
].material
);
1221 IDirectXFileData_Release(data
);
1225 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&ptr
);
1226 if (hr
!= DXFILE_OK
)
1228 IDirectXFileData_Release(data
);
1233 WARN("Material size %u does not match expected one %u\n", size
, 44);
1235 values
= (float*)ptr
;
1237 This
->materials
[i
].color
= RGBA_MAKE((BYTE
)(values
[0] * 255.0f
), (BYTE
)(values
[1] * 255.0f
),
1238 (BYTE
)(values
[2] * 255.0f
), (BYTE
)(values
[3] * 255.0f
));
1240 IDirect3DRMMaterial2_SetAmbient(This
->materials
[i
].material
, values
[0], values
[1], values
[2]); /* Alpha ignored */
1241 IDirect3DRMMaterial2_SetPower(This
->materials
[i
].material
, values
[4]);
1242 IDirect3DRMMaterial2_SetSpecular(This
->materials
[i
].material
, values
[5], values
[6], values
[7]);
1243 IDirect3DRMMaterial2_SetEmissive(This
->materials
[i
].material
, values
[8], values
[9], values
[10]);
1245 This
->materials
[i
].texture
= NULL
;
1247 hr
= IDirectXFileData_GetNextObject(data
, &material_child
);
1250 IDirectXFileData
*data
;
1253 if (FAILED(hr
= IDirectXFileObject_QueryInterface(material_child
,
1254 &IID_IDirectXFileData
, (void **)&data
)))
1256 IDirectXFileDataReference
*reference
;
1258 if (SUCCEEDED(IDirectXFileObject_QueryInterface(material_child
,
1259 &IID_IDirectXFileDataReference
, (void **)&reference
)))
1261 hr
= IDirectXFileDataReference_Resolve(reference
, &data
);
1262 IDirectXFileDataReference_Release(reference
);
1265 IDirectXFileObject_Release(material_child
);
1269 hr
= IDirectXFileData_GetType(data
, &guid
);
1270 if (hr
!= DXFILE_OK
)
1272 if (!IsEqualGUID(guid
, &TID_D3DRMTextureFilename
))
1274 WARN("Not a texture filename\n");
1279 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&filename
);
1282 if (load_texture_proc
)
1284 IDirect3DRMTexture
*texture
;
1286 hr
= load_texture_proc(*filename
, arg
, &texture
);
1289 hr
= IDirect3DTexture_QueryInterface(texture
, &IID_IDirect3DRMTexture3
, (void**)&This
->materials
[i
].texture
);
1290 IDirect3DTexture_Release(texture
);
1297 /* If the texture file is not found, no texture is associated with the material */
1298 file
= CreateFileA(*filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
1299 if (file
!= INVALID_HANDLE_VALUE
)
1303 hr
= Direct3DRMTexture_create(&IID_IDirect3DRMTexture3
, (IUnknown
**)&This
->materials
[i
].texture
);
1306 IDirectXFileData_Release(data
);
1312 IDirectXFileData_Release(data
);
1314 else if (hr
!= DXFILEERR_NOMOREOBJECTS
)
1320 IDirectXFileData_Release(data
);
1325 IDirectXFileObject_Release(child
);
1326 WARN("Found more sub-objects than expected\n");
1328 else if (hr
!= DXFILEERR_NOMOREOBJECTS
)
1336 FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(guid
));
1339 IDirectXFileData_Release(pData2
);
1343 if (!This
->nb_normals
)
1345 /* Allocate normals, one per vertex */
1346 This
->pNormals
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->nb_vertices
* sizeof(D3DVECTOR
));
1347 if (!This
->pNormals
)
1351 for (i
= 0; i
< This
->nb_faces
; i
++)
1354 DWORD nb_face_indexes
;
1355 D3DVECTOR face_normal
;
1357 if (faces_vertex_idx_size
< sizeof(DWORD
))
1358 WARN("Not enough data to read number of indices of face %d\n", i
);
1360 nb_face_indexes
= *(faces_data_ptr
+ faces_data_size
++) = *(faces_vertex_idx_ptr
++);
1361 faces_vertex_idx_size
--;
1362 if (faces_normal_idx_data
&& (*(faces_normal_idx_ptr
++) != nb_face_indexes
))
1363 WARN("Faces indices number mismatch\n");
1365 if (faces_vertex_idx_size
< (nb_face_indexes
* sizeof(DWORD
)))
1366 WARN("Not enough data to read all indices of face %d\n", i
);
1368 if (!This
->nb_normals
)
1370 /* Compute face normal */
1371 if (nb_face_indexes
> 2)
1375 D3DRMVectorSubtract(&a
, &This
->pVertices
[faces_vertex_idx_ptr
[2]], &This
->pVertices
[faces_vertex_idx_ptr
[1]]);
1376 D3DRMVectorSubtract(&b
, &This
->pVertices
[faces_vertex_idx_ptr
[0]], &This
->pVertices
[faces_vertex_idx_ptr
[1]]);
1377 D3DRMVectorCrossProduct(&face_normal
, &a
, &b
);
1378 D3DRMVectorNormalize(&face_normal
);
1382 face_normal
.u1
.x
= 0.0f
;
1383 face_normal
.u2
.y
= 0.0f
;
1384 face_normal
.u3
.z
= 0.0f
;
1388 for (j
= 0; j
< nb_face_indexes
; j
++)
1390 /* Copy vertex index */
1391 *(faces_data_ptr
+ faces_data_size
++) = *faces_vertex_idx_ptr
;
1392 /* Copy normal index */
1393 if (This
->nb_normals
)
1395 /* Read from x file */
1396 *(faces_data_ptr
+ faces_data_size
++) = *(faces_normal_idx_ptr
++);
1400 DWORD vertex_idx
= *faces_vertex_idx_ptr
;
1401 if (vertex_idx
>= This
->nb_vertices
)
1403 WARN("Found vertex index %u but only %u vertices available => use index 0\n", vertex_idx
, This
->nb_vertices
);
1406 *(faces_data_ptr
+ faces_data_size
++) = vertex_idx
;
1407 /* Add face normal to vertex normal */
1408 D3DRMVectorAdd(&This
->pNormals
[vertex_idx
], &This
->pNormals
[vertex_idx
], &face_normal
);
1410 faces_vertex_idx_ptr
++;
1412 faces_vertex_idx_size
-= nb_face_indexes
;
1415 /* Last DWORD must be 0 */
1416 *(faces_data_ptr
+ faces_data_size
++) = 0;
1418 /* Set size (in number of DWORD) of all faces data */
1419 This
->face_data_size
= faces_data_size
;
1421 if (!This
->nb_normals
)
1423 /* Normalize all normals */
1424 for (i
= 0; i
< This
->nb_vertices
; i
++)
1426 D3DRMVectorNormalize(&This
->pNormals
[i
]);
1428 This
->nb_normals
= This
->nb_vertices
;
1431 /* If there is no texture coordinates, generate default texture coordinates (0.0f, 0.0f) for each vertex */
1432 if (!This
->pCoords2d
)
1434 This
->nb_coords2d
= This
->nb_vertices
;
1435 This
->pCoords2d
= HeapAlloc(GetProcessHeap(), 0, This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1436 for (i
= 0; i
< This
->nb_coords2d
; i
++)
1438 This
->pCoords2d
[i
].u
= 0.0f
;
1439 This
->pCoords2d
[i
].v
= 0.0f
;
1443 TRACE("Mesh data loaded successfully\n");
1449 HeapFree(GetProcessHeap(), 0, faces_normal_idx_data
);
1450 HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data
);
1455 static HRESULT WINAPI
d3drm_mesh_builder3_Load(IDirect3DRMMeshBuilder3
*iface
, void *filename
,
1456 void *name
, D3DRMLOADOPTIONS loadflags
, D3DRMLOADTEXTURE3CALLBACK cb
, void *arg
)
1458 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1459 DXFILELOADOPTIONS load_options
;
1460 IDirectXFile
*dxfile
= NULL
;
1461 IDirectXFileEnumObject
*enum_object
= NULL
;
1462 IDirectXFileData
*data
= NULL
;
1465 struct d3drm_file_header
*header
;
1467 HRESULT ret
= D3DRMERR_BADOBJECT
;
1469 TRACE("iface %p, filename %p, name %p, loadflags %#x, cb %p, arg %p.\n",
1470 iface
, filename
, name
, loadflags
, cb
, arg
);
1472 clean_mesh_builder_data(mesh_builder
);
1474 if (loadflags
== D3DRMLOAD_FROMMEMORY
)
1476 load_options
= DXFILELOAD_FROMMEMORY
;
1478 else if (loadflags
== D3DRMLOAD_FROMFILE
)
1480 load_options
= DXFILELOAD_FROMFILE
;
1481 TRACE("Loading from file %s\n", debugstr_a(filename
));
1485 FIXME("Load options %d not supported yet\n", loadflags
);
1489 hr
= DirectXFileCreate(&dxfile
);
1490 if (hr
!= DXFILE_OK
)
1493 hr
= IDirectXFile_RegisterTemplates(dxfile
, templates
, strlen(templates
));
1494 if (hr
!= DXFILE_OK
)
1497 hr
= IDirectXFile_CreateEnumObject(dxfile
, filename
, load_options
, &enum_object
);
1498 if (hr
!= DXFILE_OK
)
1501 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &data
);
1502 if (hr
!= DXFILE_OK
)
1505 hr
= IDirectXFileData_GetType(data
, &guid
);
1506 if (hr
!= DXFILE_OK
)
1509 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1511 if (!IsEqualGUID(guid
, &TID_DXFILEHeader
))
1513 ret
= D3DRMERR_BADFILE
;
1517 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&header
);
1518 if ((hr
!= DXFILE_OK
) || (size
!= sizeof(*header
)))
1521 TRACE("Version is %u.%u, flags %#x.\n", header
->major
, header
->minor
, header
->flags
);
1523 /* Version must be 1.0.x */
1524 if ((header
->major
!= 1) || (header
->minor
!= 0))
1526 ret
= D3DRMERR_BADFILE
;
1530 IDirectXFileData_Release(data
);
1533 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &data
);
1534 if (hr
!= DXFILE_OK
)
1536 ret
= D3DRMERR_NOTFOUND
;
1540 hr
= IDirectXFileData_GetType(data
, &guid
);
1541 if (hr
!= DXFILE_OK
)
1544 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1546 if (!IsEqualGUID(guid
, &TID_D3DRMMesh
))
1548 ret
= D3DRMERR_NOTFOUND
;
1552 /* We don't care about the texture interface version since we rely on QueryInterface */
1553 hr
= load_mesh_data(iface
, data
, (D3DRMLOADTEXTURECALLBACK
)cb
, arg
);
1560 IDirectXFileData_Release(data
);
1562 IDirectXFileEnumObject_Release(enum_object
);
1564 IDirectXFile_Release(dxfile
);
1566 if (ret
!= D3DRM_OK
)
1567 clean_mesh_builder_data(mesh_builder
);
1572 static HRESULT WINAPI
d3drm_mesh_builder3_Save(IDirect3DRMMeshBuilder3
*iface
,
1573 const char *filename
, D3DRMXOFFORMAT format
, D3DRMSAVEOPTIONS flags
)
1575 FIXME("iface %p, filename %s, format %#x, flags %#x stub!\n",
1576 iface
, debugstr_a(filename
), format
, flags
);
1581 static HRESULT WINAPI
d3drm_mesh_builder3_Scale(IDirect3DRMMeshBuilder3
*iface
,
1582 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
1584 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1587 TRACE("iface %p, sx %.8e, sy %.8e, sz %.8e.\n", iface
, sx
, sy
, sz
);
1589 for (i
= 0; i
< mesh_builder
->nb_vertices
; ++i
)
1591 mesh_builder
->pVertices
[i
].u1
.x
*= sx
;
1592 mesh_builder
->pVertices
[i
].u2
.y
*= sy
;
1593 mesh_builder
->pVertices
[i
].u3
.z
*= sz
;
1596 /* Normals are not affected by Scale */
1601 static HRESULT WINAPI
d3drm_mesh_builder3_Translate(IDirect3DRMMeshBuilder3
*iface
,
1602 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
1604 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
1609 static HRESULT WINAPI
d3drm_mesh_builder3_SetColorSource(IDirect3DRMMeshBuilder3
*iface
,
1610 D3DRMCOLORSOURCE source
)
1612 FIXME("iface %p, source %#x stub!\n", iface
, source
);
1617 static HRESULT WINAPI
d3drm_mesh_builder3_GetBox(IDirect3DRMMeshBuilder3
*iface
, D3DRMBOX
*box
)
1619 FIXME("iface %p, box %p stub!\n", iface
, box
);
1624 static HRESULT WINAPI
d3drm_mesh_builder3_GenerateNormals(IDirect3DRMMeshBuilder3
*iface
,
1625 D3DVALUE crease
, DWORD flags
)
1627 FIXME("iface %p, crease %.8e, flags %#x stub!\n", iface
, crease
, flags
);
1632 static D3DRMCOLORSOURCE WINAPI
d3drm_mesh_builder3_GetColorSource(IDirect3DRMMeshBuilder3
*iface
)
1634 FIXME("iface %p stub!\n", iface
);
1639 static HRESULT WINAPI
d3drm_mesh_builder3_AddMesh(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMMesh
*mesh
)
1641 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
1646 static HRESULT WINAPI
d3drm_mesh_builder3_AddMeshBuilder(IDirect3DRMMeshBuilder3
*iface
,
1647 IDirect3DRMMeshBuilder3
*mesh_builder
, DWORD flags
)
1649 FIXME("iface %p, mesh_builder %p, flags %#x stub!\n", iface
, mesh_builder
, flags
);
1654 static HRESULT WINAPI
d3drm_mesh_builder3_AddFrame(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFrame3
*frame
)
1656 FIXME("iface %p, frame %p stub!\n", iface
, frame
);
1661 static HRESULT WINAPI
d3drm_mesh_builder3_AddFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
*face
)
1663 FIXME("iface %p, face %p stub!\n", iface
, face
);
1668 static HRESULT WINAPI
d3drm_mesh_builder3_AddFaces(IDirect3DRMMeshBuilder3
*iface
,
1669 DWORD vertex_count
, D3DVECTOR
*vertices
, DWORD normal_count
, D3DVECTOR
*normals
,
1670 DWORD
*face_data
, IDirect3DRMFaceArray
**array
)
1672 FIXME("iface %p, vertex_count %u, vertices %p, normal_count %u, normals %p, face_data %p array %p stub!\n",
1673 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data
, array
);
1678 static HRESULT WINAPI
d3drm_mesh_builder3_ReserveSpace(IDirect3DRMMeshBuilder3
*iface
,
1679 DWORD vertex_count
, DWORD normal_count
, DWORD face_count
)
1681 FIXME("iface %p, vertex_count %u, normal_count %u, face_count %u stub!\n",
1682 iface
, vertex_count
, normal_count
, face_count
);
1687 static HRESULT WINAPI
d3drm_mesh_builder3_SetColorRGB(IDirect3DRMMeshBuilder3
*iface
,
1688 D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
1690 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1692 TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface
, red
, green
, blue
);
1694 mesh_builder
->color
= RGBA_MAKE((BYTE
)(red
* 255.0f
), (BYTE
)(green
* 255.0f
), (BYTE
)(blue
* 255.0f
), 0xff);
1699 static HRESULT WINAPI
d3drm_mesh_builder3_SetColor(IDirect3DRMMeshBuilder3
*iface
, D3DCOLOR color
)
1701 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1703 TRACE("iface %p, color 0x%08x.\n", iface
, color
);
1705 mesh_builder
->color
= color
;
1710 static HRESULT WINAPI
d3drm_mesh_builder3_SetTexture(IDirect3DRMMeshBuilder3
*iface
,
1711 IDirect3DRMTexture3
*texture
)
1713 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1715 TRACE("iface %p, texture %p.\n", iface
, texture
);
1718 IDirect3DRMTexture3_AddRef(texture
);
1719 if (mesh_builder
->texture
)
1720 IDirect3DRMTexture3_Release(mesh_builder
->texture
);
1721 mesh_builder
->texture
= texture
;
1726 static HRESULT WINAPI
d3drm_mesh_builder3_SetMaterial(IDirect3DRMMeshBuilder3
*iface
,
1727 IDirect3DRMMaterial2
*material
)
1729 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1731 TRACE("iface %p, material %p.\n", iface
, material
);
1734 IDirect3DRMTexture2_AddRef(material
);
1735 if (mesh_builder
->material
)
1736 IDirect3DRMTexture2_Release(mesh_builder
->material
);
1737 mesh_builder
->material
= material
;
1742 static HRESULT WINAPI
d3drm_mesh_builder3_SetTextureTopology(IDirect3DRMMeshBuilder3
*iface
,
1743 BOOL wrap_u
, BOOL wrap_v
)
1745 FIXME("iface %p, wrap_u %#x, wrap_v %#x stub!\n", iface
, wrap_u
, wrap_v
);
1750 static HRESULT WINAPI
d3drm_mesh_builder3_SetQuality(IDirect3DRMMeshBuilder3
*iface
,
1751 D3DRMRENDERQUALITY quality
)
1753 FIXME("iface %p, quality %#x stub!\n", iface
, quality
);
1758 static HRESULT WINAPI
d3drm_mesh_builder3_SetPerspective(IDirect3DRMMeshBuilder3
*iface
,
1761 FIXME("iface %p, enable %#x stub!\n", iface
, enable
);
1766 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertex(IDirect3DRMMeshBuilder3
*iface
,
1767 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1769 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
1774 static HRESULT WINAPI
d3drm_mesh_builder3_SetNormal(IDirect3DRMMeshBuilder3
*iface
,
1775 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1777 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
1782 static HRESULT WINAPI
d3drm_mesh_builder3_SetTextureCoordinates(IDirect3DRMMeshBuilder3
*iface
,
1783 DWORD index
, D3DVALUE u
, D3DVALUE v
)
1785 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1787 TRACE("iface %p, index %u, u %.8e, v %.8e.\n", iface
, index
, u
, v
);
1789 if (index
>= mesh_builder
->nb_coords2d
)
1790 return D3DRMERR_BADVALUE
;
1792 mesh_builder
->pCoords2d
[index
].u
= u
;
1793 mesh_builder
->pCoords2d
[index
].v
= v
;
1798 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertexColor(IDirect3DRMMeshBuilder3
*iface
,
1799 DWORD index
, D3DCOLOR color
)
1801 FIXME("iface %p, index %u, color 0x%08x stub!\n", iface
, index
, color
);
1806 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertexColorRGB(IDirect3DRMMeshBuilder3
*iface
,
1807 DWORD index
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
1809 FIXME("iface %p, index %u, red %.8e, green %.8e, blue %.8e stub!\n",
1810 iface
, index
, red
, green
, blue
);
1815 static HRESULT WINAPI
d3drm_mesh_builder3_GetFaces(IDirect3DRMMeshBuilder3
*iface
,
1816 IDirect3DRMFaceArray
**array
)
1818 FIXME("iface %p, array %p stub!\n", iface
, array
);
1823 static HRESULT WINAPI
d3drm_mesh_builder3_GetGeometry(IDirect3DRMMeshBuilder3
*iface
,
1824 DWORD
*vertex_count
, D3DVECTOR
*vertices
, DWORD
*normal_count
, D3DVECTOR
*normals
,
1825 DWORD
*face_data_size
, DWORD
*face_data
)
1827 FIXME("iface %p, vertex_count %p, vertices %p, normal_count %p, normals %p, "
1828 "face_data_size %p, face_data %p stub!\n",
1829 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data_size
, face_data
);
1834 static HRESULT WINAPI
d3drm_mesh_builder3_GetTextureCoordinates(IDirect3DRMMeshBuilder3
*iface
,
1835 DWORD index
, D3DVALUE
*u
, D3DVALUE
*v
)
1837 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1839 TRACE("iface %p, index %u, u %p, v %p.\n", iface
, index
, u
, v
);
1841 if (index
>= mesh_builder
->nb_coords2d
)
1842 return D3DRMERR_BADVALUE
;
1844 *u
= mesh_builder
->pCoords2d
[index
].u
;
1845 *v
= mesh_builder
->pCoords2d
[index
].v
;
1850 static int WINAPI
d3drm_mesh_builder3_AddVertex(IDirect3DRMMeshBuilder3
*iface
,
1851 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1853 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
1858 static int WINAPI
d3drm_mesh_builder3_AddNormal(IDirect3DRMMeshBuilder3
*iface
,
1859 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1861 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
1866 static HRESULT WINAPI
d3drm_mesh_builder3_CreateFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
**face
)
1868 TRACE("iface %p, face %p.\n", iface
, face
);
1870 return Direct3DRMFace_create(&IID_IDirect3DRMFace2
, (IUnknown
**)face
);
1873 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_builder3_GetQuality(IDirect3DRMMeshBuilder3
*iface
)
1875 FIXME("iface %p stub!\n", iface
);
1880 static BOOL WINAPI
d3drm_mesh_builder3_GetPerspective(IDirect3DRMMeshBuilder3
*iface
)
1882 FIXME("iface %p stub!\n", iface
);
1887 static int WINAPI
d3drm_mesh_builder3_GetFaceCount(IDirect3DRMMeshBuilder3
*iface
)
1889 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1891 TRACE("iface %p.\n", iface
);
1893 return mesh_builder
->nb_faces
;
1896 static int WINAPI
d3drm_mesh_builder3_GetVertexCount(IDirect3DRMMeshBuilder3
*iface
)
1898 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1900 TRACE("iface %p.\n", iface
);
1902 return mesh_builder
->nb_vertices
;
1905 static D3DCOLOR WINAPI
d3drm_mesh_builder3_GetVertexColor(IDirect3DRMMeshBuilder3
*iface
,
1908 FIXME("iface %p, index %u stub!\n", iface
, index
);
1913 static HRESULT WINAPI
d3drm_mesh_builder3_CreateMesh(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMMesh
**mesh
)
1915 struct d3drm_mesh_builder
*This
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1917 D3DRMGROUPINDEX group
;
1919 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
1924 hr
= Direct3DRMMesh_create(mesh
);
1928 /* If there is mesh data, create a group and put data inside */
1929 if (This
->nb_vertices
)
1933 D3DRMVERTEX
* vertices
;
1935 vertices
= HeapAlloc(GetProcessHeap(), 0, This
->nb_vertices
* sizeof(D3DRMVERTEX
));
1938 IDirect3DRMMesh_Release(*mesh
);
1939 return E_OUTOFMEMORY
;
1941 for (i
= 0; i
< This
->nb_vertices
; i
++)
1942 vertices
[i
].position
= This
->pVertices
[i
];
1943 hr
= IDirect3DRMMesh_SetVertices(*mesh
, 0, 0, This
->nb_vertices
, vertices
);
1944 HeapFree(GetProcessHeap(), 0, vertices
);
1946 /* Groups are in reverse order compared to materials list in X file */
1947 for (k
= This
->nb_materials
- 1; k
>= 0; k
--)
1949 unsigned* face_data
;
1951 DWORD
* in_ptr
= This
->pFaceData
;
1952 ULONG vertex_per_face
= 0;
1953 BOOL
* used_vertices
;
1954 unsigned nb_vertices
= 0;
1955 unsigned nb_faces
= 0;
1957 used_vertices
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->face_data_size
* sizeof(*used_vertices
));
1960 IDirect3DRMMesh_Release(*mesh
);
1961 return E_OUTOFMEMORY
;
1964 face_data
= HeapAlloc(GetProcessHeap(), 0, This
->face_data_size
* sizeof(*face_data
));
1967 HeapFree(GetProcessHeap(), 0, used_vertices
);
1968 IDirect3DRMMesh_Release(*mesh
);
1969 return E_OUTOFMEMORY
;
1971 out_ptr
= face_data
;
1973 /* If all faces have the same number of vertex, set vertex_per_face */
1974 for (i
= 0; i
< This
->nb_faces
; i
++)
1976 /* Process only faces belonging to the group */
1977 if (This
->material_indices
[i
] == k
)
1979 if (vertex_per_face
&& (vertex_per_face
!= *in_ptr
))
1981 vertex_per_face
= *in_ptr
;
1983 in_ptr
+= 1 + *in_ptr
* 2;
1985 if (i
!= This
->nb_faces
)
1986 vertex_per_face
= 0;
1988 /* Put only vertex indices */
1989 in_ptr
= This
->pFaceData
;
1990 for (i
= 0; i
< This
->nb_faces
; i
++)
1992 DWORD nb_indices
= *in_ptr
++;
1994 /* Skip faces not belonging to the group */
1995 if (This
->material_indices
[i
] != k
)
1997 in_ptr
+= 2 * nb_indices
;
2001 /* Don't put nb indices when vertex_per_face is set */
2002 if (vertex_per_face
)
2003 *out_ptr
++ = nb_indices
;
2005 for (j
= 0; j
< nb_indices
; j
++)
2007 *out_ptr
= *in_ptr
++;
2008 used_vertices
[*out_ptr
++] = TRUE
;
2009 /* Skip normal index */
2016 for (i
= 0; i
< This
->nb_vertices
; i
++)
2017 if (used_vertices
[i
])
2020 hr
= IDirect3DRMMesh_AddGroup(*mesh
, nb_vertices
, nb_faces
, vertex_per_face
, face_data
, &group
);
2021 HeapFree(GetProcessHeap(), 0, used_vertices
);
2022 HeapFree(GetProcessHeap(), 0, face_data
);
2024 hr
= IDirect3DRMMesh_SetGroupColor(*mesh
, group
, This
->materials
[k
].color
);
2026 hr
= IDirect3DRMMesh_SetGroupMaterial(*mesh
, group
,
2027 (IDirect3DRMMaterial
*)This
->materials
[k
].material
);
2028 if (SUCCEEDED(hr
) && This
->materials
[k
].texture
)
2030 IDirect3DRMTexture
*texture
;
2032 IDirect3DRMTexture3_QueryInterface(This
->materials
[k
].texture
,
2033 &IID_IDirect3DRMTexture
, (void **)&texture
);
2034 hr
= IDirect3DRMMesh_SetGroupTexture(*mesh
, group
, texture
);
2035 IDirect3DRMTexture_Release(texture
);
2039 IDirect3DRMMesh_Release(*mesh
);
2048 static HRESULT WINAPI
d3drm_mesh_builder3_GetFace(IDirect3DRMMeshBuilder3
*iface
,
2049 DWORD index
, IDirect3DRMFace2
**face
)
2051 FIXME("iface %p, index %u, face %p stub!\n", iface
, index
, face
);
2056 static HRESULT WINAPI
d3drm_mesh_builder3_GetVertex(IDirect3DRMMeshBuilder3
*iface
,
2057 DWORD index
, D3DVECTOR
*vector
)
2059 FIXME("iface %p, index %u, vector %p stub!\n", iface
, index
, vector
);
2064 static HRESULT WINAPI
d3drm_mesh_builder3_GetNormal(IDirect3DRMMeshBuilder3
*iface
,
2065 DWORD index
, D3DVECTOR
*vector
)
2067 FIXME("iface %p, index %u, vector %p stub!\n", iface
, index
, vector
);
2072 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteVertices(IDirect3DRMMeshBuilder3
*iface
,
2073 DWORD start_idx
, DWORD count
)
2075 FIXME("iface %p, start_idx %u, count %u stub!\n", iface
, start_idx
, count
);
2080 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteNormals(IDirect3DRMMeshBuilder3
*iface
,
2081 DWORD start_idx
, DWORD count
)
2083 FIXME("iface %p, start_idx %u, count %u stub!\n", iface
, start_idx
, count
);
2088 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
*face
)
2090 FIXME("iface %p, face %p stub!\n", iface
, face
);
2095 static HRESULT WINAPI
d3drm_mesh_builder3_Empty(IDirect3DRMMeshBuilder3
*iface
, DWORD flags
)
2097 FIXME("iface %p, flags %#x stub!\n", iface
, flags
);
2102 static HRESULT WINAPI
d3drm_mesh_builder3_Optimize(IDirect3DRMMeshBuilder3
*iface
, DWORD flags
)
2104 FIXME("iface %p, flags %#x stub!\n", iface
, flags
);
2109 static HRESULT WINAPI
d3drm_mesh_builder3_AddFacesIndexed(IDirect3DRMMeshBuilder3
*iface
,
2110 DWORD flags
, DWORD
*indices
, DWORD
*start_idx
, DWORD
*count
)
2112 FIXME("iface %p, flags %#x, indices %p, start_idx %p, count %p stub!\n",
2113 iface
, flags
, indices
, start_idx
, count
);
2118 static HRESULT WINAPI
d3drm_mesh_builder3_CreateSubMesh(IDirect3DRMMeshBuilder3
*iface
, IUnknown
**mesh
)
2120 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
2125 static HRESULT WINAPI
d3drm_mesh_builder3_GetParentMesh(IDirect3DRMMeshBuilder3
*iface
,
2126 DWORD flags
, IUnknown
**parent
)
2128 FIXME("iface %p, flags %#x, parent %p stub!\n", iface
, flags
, parent
);
2133 static HRESULT WINAPI
d3drm_mesh_builder3_GetSubMeshes(IDirect3DRMMeshBuilder3
*iface
,
2134 DWORD
*count
, IUnknown
**meshes
)
2136 FIXME("iface %p, count %p, meshes %p stub!\n", iface
, count
, meshes
);
2141 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteSubMesh(IDirect3DRMMeshBuilder3
*iface
, IUnknown
*mesh
)
2143 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
2148 static HRESULT WINAPI
d3drm_mesh_builder3_Enable(IDirect3DRMMeshBuilder3
*iface
, DWORD index
)
2150 FIXME("iface %p, index %u stub!\n", iface
, index
);
2155 static HRESULT WINAPI
d3drm_mesh_builder3_GetEnable(IDirect3DRMMeshBuilder3
*iface
, DWORD
*indices
)
2157 FIXME("iface %p, indices %p stub!\n", iface
, indices
);
2162 static HRESULT WINAPI
d3drm_mesh_builder3_AddTriangles(IDirect3DRMMeshBuilder3
*iface
,
2163 DWORD flags
, DWORD format
, DWORD vertex_count
, void *data
)
2165 FIXME("iface %p, flags %#x, format %#x, vertex_count %u, data %p stub!\n",
2166 iface
, flags
, format
, vertex_count
, data
);
2171 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertices(IDirect3DRMMeshBuilder3
*iface
,
2172 DWORD start_idx
, DWORD count
, D3DVECTOR
*vector
)
2174 FIXME("iface %p, start_idx %u, count %u, vector %p stub!\n", iface
, start_idx
, count
, vector
);
2179 static HRESULT WINAPI
d3drm_mesh_builder3_GetVertices(IDirect3DRMMeshBuilder3
*iface
,
2180 DWORD start_idx
, DWORD
*vertex_count
, D3DVECTOR
*vertices
)
2182 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2183 DWORD count
= mesh_builder
->nb_vertices
- start_idx
;
2185 TRACE("iface %p, start_idx %u, vertex_count %p, vertices %p.\n",
2186 iface
, start_idx
, vertex_count
, vertices
);
2189 *vertex_count
= count
;
2190 if (vertices
&& mesh_builder
->nb_vertices
)
2191 memcpy(vertices
, mesh_builder
->pVertices
+ start_idx
, count
* sizeof(*vertices
));
2196 static HRESULT WINAPI
d3drm_mesh_builder3_SetNormals(IDirect3DRMMeshBuilder3
*iface
,
2197 DWORD start_idx
, DWORD count
, D3DVECTOR
*vector
)
2199 FIXME("iface %p, start_idx %u, count %u, vector %p stub!\n",
2200 iface
, start_idx
, count
, vector
);
2205 static HRESULT WINAPI
d3drm_mesh_builder3_GetNormals(IDirect3DRMMeshBuilder3
*iface
,
2206 DWORD start_idx
, DWORD
*normal_count
, D3DVECTOR
*normals
)
2208 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2209 DWORD count
= mesh_builder
->nb_normals
- start_idx
;
2211 TRACE("iface %p, start_idx %u, normal_count %p, normals %p stub!\n",
2212 iface
, start_idx
, normal_count
, normals
);
2215 *normal_count
= count
;
2216 if (normals
&& mesh_builder
->nb_normals
)
2217 memcpy(normals
, mesh_builder
->pNormals
+ start_idx
, count
* sizeof(*normals
));
2222 static int WINAPI
d3drm_mesh_builder3_GetNormalCount(IDirect3DRMMeshBuilder3
*iface
)
2224 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2226 TRACE("iface %p.\n", iface
);
2228 return mesh_builder
->nb_normals
;
2231 static const struct IDirect3DRMMeshBuilder3Vtbl d3drm_mesh_builder3_vtbl
=
2233 d3drm_mesh_builder3_QueryInterface
,
2234 d3drm_mesh_builder3_AddRef
,
2235 d3drm_mesh_builder3_Release
,
2236 d3drm_mesh_builder3_Clone
,
2237 d3drm_mesh_builder3_AddDestroyCallback
,
2238 d3drm_mesh_builder3_DeleteDestroyCallback
,
2239 d3drm_mesh_builder3_SetAppData
,
2240 d3drm_mesh_builder3_GetAppData
,
2241 d3drm_mesh_builder3_SetName
,
2242 d3drm_mesh_builder3_GetName
,
2243 d3drm_mesh_builder3_GetClassName
,
2244 d3drm_mesh_builder3_Load
,
2245 d3drm_mesh_builder3_Save
,
2246 d3drm_mesh_builder3_Scale
,
2247 d3drm_mesh_builder3_Translate
,
2248 d3drm_mesh_builder3_SetColorSource
,
2249 d3drm_mesh_builder3_GetBox
,
2250 d3drm_mesh_builder3_GenerateNormals
,
2251 d3drm_mesh_builder3_GetColorSource
,
2252 d3drm_mesh_builder3_AddMesh
,
2253 d3drm_mesh_builder3_AddMeshBuilder
,
2254 d3drm_mesh_builder3_AddFrame
,
2255 d3drm_mesh_builder3_AddFace
,
2256 d3drm_mesh_builder3_AddFaces
,
2257 d3drm_mesh_builder3_ReserveSpace
,
2258 d3drm_mesh_builder3_SetColorRGB
,
2259 d3drm_mesh_builder3_SetColor
,
2260 d3drm_mesh_builder3_SetTexture
,
2261 d3drm_mesh_builder3_SetMaterial
,
2262 d3drm_mesh_builder3_SetTextureTopology
,
2263 d3drm_mesh_builder3_SetQuality
,
2264 d3drm_mesh_builder3_SetPerspective
,
2265 d3drm_mesh_builder3_SetVertex
,
2266 d3drm_mesh_builder3_SetNormal
,
2267 d3drm_mesh_builder3_SetTextureCoordinates
,
2268 d3drm_mesh_builder3_SetVertexColor
,
2269 d3drm_mesh_builder3_SetVertexColorRGB
,
2270 d3drm_mesh_builder3_GetFaces
,
2271 d3drm_mesh_builder3_GetGeometry
,
2272 d3drm_mesh_builder3_GetTextureCoordinates
,
2273 d3drm_mesh_builder3_AddVertex
,
2274 d3drm_mesh_builder3_AddNormal
,
2275 d3drm_mesh_builder3_CreateFace
,
2276 d3drm_mesh_builder3_GetQuality
,
2277 d3drm_mesh_builder3_GetPerspective
,
2278 d3drm_mesh_builder3_GetFaceCount
,
2279 d3drm_mesh_builder3_GetVertexCount
,
2280 d3drm_mesh_builder3_GetVertexColor
,
2281 d3drm_mesh_builder3_CreateMesh
,
2282 d3drm_mesh_builder3_GetFace
,
2283 d3drm_mesh_builder3_GetVertex
,
2284 d3drm_mesh_builder3_GetNormal
,
2285 d3drm_mesh_builder3_DeleteVertices
,
2286 d3drm_mesh_builder3_DeleteNormals
,
2287 d3drm_mesh_builder3_DeleteFace
,
2288 d3drm_mesh_builder3_Empty
,
2289 d3drm_mesh_builder3_Optimize
,
2290 d3drm_mesh_builder3_AddFacesIndexed
,
2291 d3drm_mesh_builder3_CreateSubMesh
,
2292 d3drm_mesh_builder3_GetParentMesh
,
2293 d3drm_mesh_builder3_GetSubMeshes
,
2294 d3drm_mesh_builder3_DeleteSubMesh
,
2295 d3drm_mesh_builder3_Enable
,
2296 d3drm_mesh_builder3_GetEnable
,
2297 d3drm_mesh_builder3_AddTriangles
,
2298 d3drm_mesh_builder3_SetVertices
,
2299 d3drm_mesh_builder3_GetVertices
,
2300 d3drm_mesh_builder3_SetNormals
,
2301 d3drm_mesh_builder3_GetNormals
,
2302 d3drm_mesh_builder3_GetNormalCount
,
2305 HRESULT
Direct3DRMMeshBuilder_create(REFIID riid
, IUnknown
**out
)
2307 struct d3drm_mesh_builder
*object
;
2309 TRACE("riid %s, out %p.\n", debugstr_guid(riid
), out
);
2311 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2312 return E_OUTOFMEMORY
;
2314 object
->IDirect3DRMMeshBuilder2_iface
.lpVtbl
= &d3drm_mesh_builder2_vtbl
;
2315 object
->IDirect3DRMMeshBuilder3_iface
.lpVtbl
= &d3drm_mesh_builder3_vtbl
;
2318 if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder3
))
2319 *out
= (IUnknown
*)&object
->IDirect3DRMMeshBuilder3_iface
;
2321 *out
= (IUnknown
*)&object
->IDirect3DRMMeshBuilder2_iface
;
2326 static HRESULT WINAPI
d3drm_mesh_QueryInterface(IDirect3DRMMesh
*iface
, REFIID riid
, void **out
)
2328 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
2330 if (IsEqualGUID(riid
, &IID_IDirect3DRMMesh
)
2331 || IsEqualGUID(riid
, &IID_IUnknown
))
2333 IDirect3DRMMesh_AddRef(iface
);
2338 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
2341 return E_NOINTERFACE
;
2344 static ULONG WINAPI
d3drm_mesh_AddRef(IDirect3DRMMesh
*iface
)
2346 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2347 ULONG refcount
= InterlockedIncrement(&mesh
->ref
);
2349 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
2354 static ULONG WINAPI
d3drm_mesh_Release(IDirect3DRMMesh
*iface
)
2356 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2357 ULONG refcount
= InterlockedDecrement(&mesh
->ref
);
2359 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
2365 for (i
= 0; i
< mesh
->nb_groups
; ++i
)
2367 HeapFree(GetProcessHeap(), 0, mesh
->groups
[i
].vertices
);
2368 HeapFree(GetProcessHeap(), 0, mesh
->groups
[i
].face_data
);
2369 if (mesh
->groups
[i
].material
)
2370 IDirect3DRMMaterial2_Release(mesh
->groups
[i
].material
);
2371 if (mesh
->groups
[i
].texture
)
2372 IDirect3DRMTexture3_Release(mesh
->groups
[i
].texture
);
2374 HeapFree(GetProcessHeap(), 0, mesh
->groups
);
2375 HeapFree(GetProcessHeap(), 0, mesh
);
2381 static HRESULT WINAPI
d3drm_mesh_Clone(IDirect3DRMMesh
*iface
,
2382 IUnknown
*outer
, REFIID iid
, void **out
)
2384 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
2389 static HRESULT WINAPI
d3drm_mesh_AddDestroyCallback(IDirect3DRMMesh
*iface
,
2390 D3DRMOBJECTCALLBACK cb
, void *ctx
)
2392 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
2397 static HRESULT WINAPI
d3drm_mesh_DeleteDestroyCallback(IDirect3DRMMesh
*iface
,
2398 D3DRMOBJECTCALLBACK cb
, void *ctx
)
2400 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
2405 static HRESULT WINAPI
d3drm_mesh_SetAppData(IDirect3DRMMesh
*iface
, DWORD data
)
2407 FIXME("iface %p, data %#x stub!\n", iface
, data
);
2412 static DWORD WINAPI
d3drm_mesh_GetAppData(IDirect3DRMMesh
*iface
)
2414 FIXME("iface %p stub!\n", iface
);
2419 static HRESULT WINAPI
d3drm_mesh_SetName(IDirect3DRMMesh
*iface
, const char *name
)
2421 FIXME("iface %p, name %s stub!\n", iface
, debugstr_a(name
));
2426 static HRESULT WINAPI
d3drm_mesh_GetName(IDirect3DRMMesh
*iface
, DWORD
*size
, char *name
)
2428 FIXME("iface %p, size %p, name %p stub!\n", iface
, size
, name
);
2433 static HRESULT WINAPI
d3drm_mesh_GetClassName(IDirect3DRMMesh
*iface
, DWORD
*size
, char *name
)
2435 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
2437 if (!size
|| *size
< strlen("Mesh") || !name
)
2438 return E_INVALIDARG
;
2440 strcpy(name
, "Mesh");
2441 *size
= sizeof("Mesh");
2446 static HRESULT WINAPI
d3drm_mesh_Scale(IDirect3DRMMesh
*iface
,
2447 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
2449 FIXME("iface %p, sx %.8e, sy %.8e, sz %.8e stub!\n", iface
, sx
, sy
, sz
);
2454 static HRESULT WINAPI
d3drm_mesh_Translate(IDirect3DRMMesh
*iface
,
2455 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
2457 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
2462 static HRESULT WINAPI
d3drm_mesh_GetBox(IDirect3DRMMesh
*iface
, D3DRMBOX
*box
)
2464 FIXME("iface %p, box %p stub!\n", iface
, box
);
2469 static HRESULT WINAPI
d3drm_mesh_AddGroup(IDirect3DRMMesh
*iface
, unsigned vertex_count
,
2470 unsigned face_count
, unsigned vertex_per_face
, unsigned *face_data
, D3DRMGROUPINDEX
*id
)
2472 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2473 struct mesh_group
*group
;
2475 TRACE("iface %p, vertex_count %u, face_count %u, vertex_per_face %u, face_data %p, id %p.\n",
2476 iface
, vertex_count
, face_count
, vertex_per_face
, face_data
, id
);
2478 if (!face_data
|| !id
)
2481 if ((mesh
->nb_groups
+ 1) > mesh
->groups_capacity
)
2483 struct mesh_group
*groups
;
2486 if (!mesh
->groups_capacity
)
2489 groups
= HeapAlloc(GetProcessHeap(), 0, new_capacity
* sizeof(*groups
));
2493 new_capacity
= mesh
->groups_capacity
* 2;
2494 groups
= HeapReAlloc(GetProcessHeap(), 0, mesh
->groups
, new_capacity
* sizeof(*groups
));
2498 return E_OUTOFMEMORY
;
2500 mesh
->groups_capacity
= new_capacity
;
2501 mesh
->groups
= groups
;
2504 group
= mesh
->groups
+ mesh
->nb_groups
;
2506 group
->vertices
= HeapAlloc(GetProcessHeap(), 0, vertex_count
* sizeof(D3DRMVERTEX
));
2507 if (!group
->vertices
)
2508 return E_OUTOFMEMORY
;
2509 group
->nb_vertices
= vertex_count
;
2510 group
->nb_faces
= face_count
;
2511 group
->vertex_per_face
= vertex_per_face
;
2513 if (vertex_per_face
)
2515 group
->face_data_size
= face_count
* vertex_per_face
;
2520 unsigned nb_indices
;
2521 unsigned* face_data_ptr
= face_data
;
2522 group
->face_data_size
= 0;
2524 for (i
= 0; i
< face_count
; i
++)
2526 nb_indices
= *face_data_ptr
;
2527 group
->face_data_size
+= nb_indices
+ 1;
2528 face_data_ptr
+= nb_indices
;
2532 group
->face_data
= HeapAlloc(GetProcessHeap(), 0, group
->face_data_size
* sizeof(unsigned));
2533 if (!group
->face_data
)
2535 HeapFree(GetProcessHeap(), 0 , group
->vertices
);
2536 return E_OUTOFMEMORY
;
2539 memcpy(group
->face_data
, face_data
, group
->face_data_size
* sizeof(unsigned));
2541 group
->material
= NULL
;
2542 group
->texture
= NULL
;
2544 *id
= mesh
->nb_groups
++;
2549 static HRESULT WINAPI
d3drm_mesh_SetVertices(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX group_id
,
2550 unsigned int start_idx
, unsigned int count
, D3DRMVERTEX
*values
)
2552 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2554 TRACE("iface %p, group_id %#x, start_idx %u, count %u, values %p.\n",
2555 iface
, group_id
, start_idx
, count
, values
);
2557 if (group_id
>= mesh
->nb_groups
)
2558 return D3DRMERR_BADVALUE
;
2560 if ((start_idx
+ count
- 1) >= mesh
->groups
[group_id
].nb_vertices
)
2561 return D3DRMERR_BADVALUE
;
2566 memcpy(mesh
->groups
[group_id
].vertices
+ start_idx
, values
, count
* sizeof(*values
));
2571 static HRESULT WINAPI
d3drm_mesh_SetGroupColor(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DCOLOR color
)
2573 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2575 TRACE("iface %p, id %#x, color 0x%08x.\n", iface
, id
, color
);
2577 if (id
>= mesh
->nb_groups
)
2578 return D3DRMERR_BADVALUE
;
2580 mesh
->groups
[id
].color
= color
;
2585 static HRESULT WINAPI
d3drm_mesh_SetGroupColorRGB(IDirect3DRMMesh
*iface
,
2586 D3DRMGROUPINDEX id
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
2588 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2590 TRACE("iface %p, id %#x, red %.8e, green %.8e, blue %.8e.\n", iface
, id
, red
, green
, blue
);
2592 if (id
>= mesh
->nb_groups
)
2593 return D3DRMERR_BADVALUE
;
2595 mesh
->groups
[id
].color
= RGBA_MAKE((BYTE
)(red
* 255.0f
), (BYTE
)(green
* 255.0f
), (BYTE
)(blue
* 255.0f
), 0xff);
2600 static HRESULT WINAPI
d3drm_mesh_SetGroupMapping(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DRMMAPPING value
)
2602 FIXME("iface %p, id %#x, value %#x stub!\n", iface
, id
, value
);
2607 static HRESULT WINAPI
d3drm_mesh_SetGroupQuality(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DRMRENDERQUALITY value
)
2609 FIXME("iface %p, id %#x, value %#x stub!\n", iface
, id
, value
);
2614 static HRESULT WINAPI
d3drm_mesh_SetGroupMaterial(IDirect3DRMMesh
*iface
,
2615 D3DRMGROUPINDEX id
, IDirect3DRMMaterial
*material
)
2617 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2619 TRACE("iface %p, id %#x, material %p.\n", iface
, id
, material
);
2621 if (id
>= mesh
->nb_groups
)
2622 return D3DRMERR_BADVALUE
;
2624 if (mesh
->groups
[id
].material
)
2625 IDirect3DRMMaterial2_Release(mesh
->groups
[id
].material
);
2627 mesh
->groups
[id
].material
= (IDirect3DRMMaterial2
*)material
;
2630 IDirect3DRMMaterial2_AddRef(mesh
->groups
[id
].material
);
2635 static HRESULT WINAPI
d3drm_mesh_SetGroupTexture(IDirect3DRMMesh
*iface
,
2636 D3DRMGROUPINDEX id
, IDirect3DRMTexture
*texture
)
2638 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2640 TRACE("iface %p, id %#x, texture %p.\n", iface
, id
, texture
);
2642 if (id
>= mesh
->nb_groups
)
2643 return D3DRMERR_BADVALUE
;
2645 if (mesh
->groups
[id
].texture
)
2646 IDirect3DRMTexture3_Release(mesh
->groups
[id
].texture
);
2650 mesh
->groups
[id
].texture
= NULL
;
2654 return IDirect3DRMTexture3_QueryInterface(texture
, &IID_IDirect3DRMTexture
, (void **)&mesh
->groups
[id
].texture
);
2657 static DWORD WINAPI
d3drm_mesh_GetGroupCount(IDirect3DRMMesh
*iface
)
2659 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2661 TRACE("iface %p.\n", iface
);
2663 return mesh
->nb_groups
;
2666 static HRESULT WINAPI
d3drm_mesh_GetGroup(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, unsigned *vertex_count
,
2667 unsigned *face_count
, unsigned *vertex_per_face
, DWORD
*face_data_size
, unsigned *face_data
)
2669 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2671 TRACE("iface %p, id %#x, vertex_count %p, face_count %p, vertex_per_face %p, face_data_size %p, face_data %p.\n",
2672 iface
, id
, vertex_count
, face_count
, vertex_per_face
, face_data_size
,face_data
);
2674 if (id
>= mesh
->nb_groups
)
2675 return D3DRMERR_BADVALUE
;
2678 *vertex_count
= mesh
->groups
[id
].nb_vertices
;
2680 *face_count
= mesh
->groups
[id
].nb_faces
;
2681 if (vertex_per_face
)
2682 *vertex_per_face
= mesh
->groups
[id
].vertex_per_face
;
2684 *face_data_size
= mesh
->groups
[id
].face_data_size
;
2686 memcpy(face_data
, mesh
->groups
[id
].face_data
, mesh
->groups
[id
].face_data_size
* sizeof(*face_data
));
2691 static HRESULT WINAPI
d3drm_mesh_GetVertices(IDirect3DRMMesh
*iface
,
2692 D3DRMGROUPINDEX group_id
, DWORD start_idx
, DWORD count
, D3DRMVERTEX
*vertices
)
2694 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2696 TRACE("iface %p, group_id %#x, start_idx %u, count %u, vertices %p.\n",
2697 iface
, group_id
, start_idx
, count
, vertices
);
2699 if (group_id
>= mesh
->nb_groups
)
2700 return D3DRMERR_BADVALUE
;
2702 if ((start_idx
+ count
- 1) >= mesh
->groups
[group_id
].nb_vertices
)
2703 return D3DRMERR_BADVALUE
;
2708 memcpy(vertices
, mesh
->groups
[group_id
].vertices
+ start_idx
, count
* sizeof(*vertices
));
2713 static D3DCOLOR WINAPI
d3drm_mesh_GetGroupColor(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2715 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2717 TRACE("iface %p, id %#x.\n", iface
, id
);
2719 return mesh
->groups
[id
].color
;
2722 static D3DRMMAPPING WINAPI
d3drm_mesh_GetGroupMapping(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2724 FIXME("iface %p, id %#x stub!\n", iface
, id
);
2728 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_GetGroupQuality(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2730 FIXME("iface %p, id %#x stub!\n", iface
, id
);
2735 static HRESULT WINAPI
d3drm_mesh_GetGroupMaterial(IDirect3DRMMesh
*iface
,
2736 D3DRMGROUPINDEX id
, IDirect3DRMMaterial
**material
)
2738 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2740 TRACE("iface %p, id %#x, material %p.\n", iface
, id
, material
);
2742 if (id
>= mesh
->nb_groups
)
2743 return D3DRMERR_BADVALUE
;
2748 if (mesh
->groups
[id
].material
)
2749 IDirect3DRMTexture_QueryInterface(mesh
->groups
[id
].material
, &IID_IDirect3DRMMaterial
, (void **)material
);
2756 static HRESULT WINAPI
d3drm_mesh_GetGroupTexture(IDirect3DRMMesh
*iface
,
2757 D3DRMGROUPINDEX id
, IDirect3DRMTexture
**texture
)
2759 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2761 TRACE("iface %p, id %#x, texture %p.\n", iface
, id
, texture
);
2763 if (id
>= mesh
->nb_groups
)
2764 return D3DRMERR_BADVALUE
;
2769 if (mesh
->groups
[id
].texture
)
2770 IDirect3DRMTexture_QueryInterface(mesh
->groups
[id
].texture
, &IID_IDirect3DRMTexture
, (void **)texture
);
2777 static const struct IDirect3DRMMeshVtbl d3drm_mesh_vtbl
=
2779 d3drm_mesh_QueryInterface
,
2783 d3drm_mesh_AddDestroyCallback
,
2784 d3drm_mesh_DeleteDestroyCallback
,
2785 d3drm_mesh_SetAppData
,
2786 d3drm_mesh_GetAppData
,
2789 d3drm_mesh_GetClassName
,
2791 d3drm_mesh_Translate
,
2793 d3drm_mesh_AddGroup
,
2794 d3drm_mesh_SetVertices
,
2795 d3drm_mesh_SetGroupColor
,
2796 d3drm_mesh_SetGroupColorRGB
,
2797 d3drm_mesh_SetGroupMapping
,
2798 d3drm_mesh_SetGroupQuality
,
2799 d3drm_mesh_SetGroupMaterial
,
2800 d3drm_mesh_SetGroupTexture
,
2801 d3drm_mesh_GetGroupCount
,
2802 d3drm_mesh_GetGroup
,
2803 d3drm_mesh_GetVertices
,
2804 d3drm_mesh_GetGroupColor
,
2805 d3drm_mesh_GetGroupMapping
,
2806 d3drm_mesh_GetGroupQuality
,
2807 d3drm_mesh_GetGroupMaterial
,
2808 d3drm_mesh_GetGroupTexture
,
2811 HRESULT
Direct3DRMMesh_create(IDirect3DRMMesh
**mesh
)
2813 struct d3drm_mesh
*object
;
2815 TRACE("mesh %p.\n", mesh
);
2817 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2818 return E_OUTOFMEMORY
;
2820 object
->IDirect3DRMMesh_iface
.lpVtbl
= &d3drm_mesh_vtbl
;
2823 *mesh
= &object
->IDirect3DRMMesh_iface
;