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
23 #include "wine/port.h"
25 #include "d3drm_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3drm
);
32 D3DRMVERTEX
* vertices
;
34 unsigned vertex_per_face
;
38 IDirect3DRMMaterial2
* material
;
39 IDirect3DRMTexture3
* texture
;
44 IDirect3DRMMesh IDirect3DRMMesh_iface
;
46 DWORD groups_capacity
;
48 struct mesh_group
*groups
;
60 IDirect3DRMMaterial2
*material
;
61 IDirect3DRMTexture3
*texture
;
64 struct d3drm_mesh_builder
66 IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface
;
67 IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface
;
78 struct coords_2d
*pCoords2d
;
80 IDirect3DRMMaterial2
*material
;
81 IDirect3DRMTexture3
*texture
;
83 struct mesh_material
*materials
;
84 DWORD
*material_indices
;
91 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
98 "<3D82AB5E-62DA-11CF-AB39-0020AF71E433>"
105 "<F6F23F44-7686-11CF-8F52-0040333594A3>"
111 "<F6F23F45-7686-11CF-8F52-0040333594A3>"
112 "array FLOAT matrix[16];"
116 "<35FF44E0-6C7C-11CF-8F52-0040333594A3>"
124 "<D3E16E81-7835-11CF-8F52-0040333594A3>"
129 "template IndexedColor"
131 "<1630B820-7842-11CF-8F52-0040333594A3>"
133 "ColorRGBA indexColor;"
137 "<537DA6A0-CA37-11D0-941C-0080C80CFA7B>"
142 "<4885AE63-78E8-11CF-8F52-0040333594A3>"
146 "template MaterialWrap"
148 "<4885AE60-78E8-11CF-8F52-0040333594A3>"
152 "template TextureFilename"
154 "<A42790E1-7810-11CF-8F52-0040333594A3>"
159 "<3D82AB4D-62DA-11CF-AB39-0020AF71E433>"
160 "ColorRGBA faceColor;"
162 "ColorRGB specularColor;"
163 "ColorRGB emissiveColor;"
168 "<3D82AB5F-62DA-11CF-AB39-0020AF71E433>"
169 "DWORD nFaceVertexIndices;"
170 "array DWORD faceVertexIndices[nFaceVertexIndices];"
172 "template MeshFaceWraps"
174 "<ED1EC5C0-C0A8-11D0-941C-0080C80CFA7B>"
175 "DWORD nFaceWrapValues;"
176 "array Boolean2d faceWrapValues[nFaceWrapValues];"
178 "template MeshTextureCoords"
180 "<F6F23F40-7686-11CF-8F52-0040333594A3>"
181 "DWORD nTextureCoords;"
182 "array Coords2d textureCoords[nTextureCoords];"
184 "template MeshMaterialList"
186 "<F6F23F42-7686-11CF-8F52-0040333594A3>"
188 "DWORD nFaceIndexes;"
189 "array DWORD faceIndexes[nFaceIndexes];"
192 "template MeshNormals"
194 "<F6F23F43-7686-11CF-8F52-0040333594A3>"
196 "array Vector normals[nNormals];"
197 "DWORD nFaceNormals;"
198 "array MeshFace faceNormals[nFaceNormals];"
200 "template MeshVertexColors"
202 "<1630B821-7842-11CF-8F52-0040333594A3>"
203 "DWORD nVertexColors;"
204 "array IndexedColor vertexColors[nVertexColors];"
208 "<3D82AB44-62DA-11CF-AB39-0020AF71E433>"
210 "array Vector vertices[nVertices];"
212 "array MeshFace faces[nFaces];"
215 "template FrameTransformMatrix"
217 "<F6F23F41-7686-11CF-8F52-0040333594A3>"
218 "Matrix4x4 frameMatrix;"
222 "<3D82AB46-62DA-11CF-AB39-0020AF71E433>"
227 "<10DD46A9-775B-11CF-8F52-0040333594A3>"
229 "array FLOAT values[nValues];"
231 "template TimedFloatKeys"
233 "<F406B180-7B3B-11CF-8F52-0040333594A3>"
237 "template AnimationKey"
239 "<10DD46A8-775B-11CF-8F52-0040333594A3>"
242 "array TimedFloatKeys keys[nKeys];"
244 "template AnimationOptions"
246 "<E2BF56C0-840F-11CF-8F52-0040333594A3>"
248 "DWORD positionquality;"
252 "<3D82AB4F-62DA-11CF-AB39-0020AF71E433>"
255 "template AnimationSet"
257 "<3D82AB50-62DA-11CF-AB39-0020AF71E433>"
260 "template InlineData"
262 "<3A23EEA0-94B1-11D0-AB39-0020AF71E433>"
267 "<3A23EEA1-94B1-11D0-AB39-0020AF71E433>"
269 "array STRING urls[nUrls];"
271 "template ProgressiveMesh"
273 "<8A63C360-997D-11D0-941C-0080C80CFA7B>"
278 "<A42790E0-7810-11CF-8F52-0040333594A3>"
282 "array UCHAR data4[8];"
284 "template StringProperty"
286 "<7F0F21E0-BFE1-11D1-82C0-00A0C9697271>"
290 "template PropertyBag"
292 "<7F0F21E1-BFE1-11D1-82C0-00A0C9697271>"
295 "template ExternalVisual"
297 "<98116AA0-BDBA-11D1-82C0-00A0C9697271>"
298 "Guid guidExternalVisual;"
301 "template RightHanded"
303 "<7F5D5EA0-D53A-11D1-82C0-00A0C9697271>"
304 "DWORD bRightHanded;"
308 static inline struct d3drm_mesh
*impl_from_IDirect3DRMMesh(IDirect3DRMMesh
*iface
)
310 return CONTAINING_RECORD(iface
, struct d3drm_mesh
, IDirect3DRMMesh_iface
);
313 static inline struct d3drm_mesh_builder
*impl_from_IDirect3DRMMeshBuilder2(IDirect3DRMMeshBuilder2
*iface
)
315 return CONTAINING_RECORD(iface
, struct d3drm_mesh_builder
, IDirect3DRMMeshBuilder2_iface
);
318 static inline struct d3drm_mesh_builder
*impl_from_IDirect3DRMMeshBuilder3(IDirect3DRMMeshBuilder3
*iface
)
320 return CONTAINING_RECORD(iface
, struct d3drm_mesh_builder
, IDirect3DRMMeshBuilder3_iface
);
323 static void clean_mesh_builder_data(struct d3drm_mesh_builder
*mesh_builder
)
327 HeapFree(GetProcessHeap(), 0, mesh_builder
->name
);
328 mesh_builder
->name
= NULL
;
329 HeapFree(GetProcessHeap(), 0, mesh_builder
->pVertices
);
330 mesh_builder
->pVertices
= NULL
;
331 mesh_builder
->nb_vertices
= 0;
332 HeapFree(GetProcessHeap(), 0, mesh_builder
->pNormals
);
333 mesh_builder
->pNormals
= NULL
;
334 mesh_builder
->nb_normals
= 0;
335 HeapFree(GetProcessHeap(), 0, mesh_builder
->pFaceData
);
336 mesh_builder
->pFaceData
= NULL
;
337 mesh_builder
->face_data_size
= 0;
338 mesh_builder
->nb_faces
= 0;
339 HeapFree(GetProcessHeap(), 0, mesh_builder
->pCoords2d
);
340 mesh_builder
->pCoords2d
= NULL
;
341 mesh_builder
->nb_coords2d
= 0;
342 for (i
= 0; i
< mesh_builder
->nb_materials
; i
++)
344 if (mesh_builder
->materials
[i
].material
)
345 IDirect3DRMMaterial2_Release(mesh_builder
->materials
[i
].material
);
346 if (mesh_builder
->materials
[i
].texture
)
347 IDirect3DRMTexture3_Release(mesh_builder
->materials
[i
].texture
);
349 mesh_builder
->nb_materials
= 0;
350 HeapFree(GetProcessHeap(), 0, mesh_builder
->materials
);
351 mesh_builder
->materials
= NULL
;
352 HeapFree(GetProcessHeap(), 0, mesh_builder
->material_indices
);
353 mesh_builder
->material_indices
= NULL
;
356 static HRESULT WINAPI
d3drm_mesh_builder2_QueryInterface(IDirect3DRMMeshBuilder2
*iface
, REFIID riid
, void **out
)
358 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
360 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
362 if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder2
)
363 || IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder
)
364 || IsEqualGUID(riid
, &IID_IUnknown
))
366 *out
= &mesh_builder
->IDirect3DRMMeshBuilder2_iface
;
368 else if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder3
))
370 *out
= &mesh_builder
->IDirect3DRMMeshBuilder3_iface
;
375 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
376 return E_NOINTERFACE
;
379 IUnknown_AddRef((IUnknown
*)*out
);
383 static ULONG WINAPI
d3drm_mesh_builder2_AddRef(IDirect3DRMMeshBuilder2
*iface
)
385 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
386 ULONG refcount
= InterlockedIncrement(&mesh_builder
->ref
);
388 TRACE("%p increasing refcount to %u.\n", mesh_builder
, refcount
);
393 static ULONG WINAPI
d3drm_mesh_builder2_Release(IDirect3DRMMeshBuilder2
*iface
)
395 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
396 ULONG refcount
= InterlockedDecrement(&mesh_builder
->ref
);
398 TRACE("%p decreasing refcount to %u.\n", mesh_builder
, refcount
);
402 clean_mesh_builder_data(mesh_builder
);
403 if (mesh_builder
->material
)
404 IDirect3DRMMaterial2_Release(mesh_builder
->material
);
405 if (mesh_builder
->texture
)
406 IDirect3DRMTexture3_Release(mesh_builder
->texture
);
407 HeapFree(GetProcessHeap(), 0, mesh_builder
);
413 static HRESULT WINAPI
d3drm_mesh_builder2_Clone(IDirect3DRMMeshBuilder2
*iface
,
414 IUnknown
*outer
, REFIID iid
, void **out
)
416 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
421 static HRESULT WINAPI
d3drm_mesh_builder2_AddDestroyCallback(IDirect3DRMMeshBuilder2
*iface
,
422 D3DRMOBJECTCALLBACK cb
, void *ctx
)
424 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
429 static HRESULT WINAPI
d3drm_mesh_builder2_DeleteDestroyCallback(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_SetAppData(IDirect3DRMMeshBuilder2
*iface
, DWORD data
)
439 FIXME("iface %p, data %#x stub!\n", iface
, data
);
444 static DWORD WINAPI
d3drm_mesh_builder2_GetAppData(IDirect3DRMMeshBuilder2
*iface
)
446 FIXME("iface %p stub!\n", iface
);
451 static HRESULT WINAPI
d3drm_mesh_builder2_SetName(IDirect3DRMMeshBuilder2
*iface
, const char *name
)
453 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
455 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
457 return IDirect3DRMMeshBuilder3_SetName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, name
);
460 static HRESULT WINAPI
d3drm_mesh_builder2_GetName(IDirect3DRMMeshBuilder2
*iface
, DWORD
*size
, char *name
)
462 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
464 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
466 return IDirect3DRMMeshBuilder3_GetName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, size
, name
);
469 static HRESULT WINAPI
d3drm_mesh_builder2_GetClassName(IDirect3DRMMeshBuilder2
*iface
, DWORD
*size
, char *name
)
471 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
473 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
475 return IDirect3DRMMeshBuilder3_GetClassName(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, size
, name
);
478 static HRESULT WINAPI
d3drm_mesh_builder2_Load(IDirect3DRMMeshBuilder2
*iface
, void *filename
,
479 void *name
, D3DRMLOADOPTIONS flags
, D3DRMLOADTEXTURECALLBACK cb
, void *ctx
)
481 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
483 TRACE("iface %p, filename %p, name %p, flags %#x, cb %p, ctx %p.\n",
484 iface
, filename
, name
, flags
, cb
, ctx
);
487 FIXME("Texture callback is not yet supported\n");
489 return IDirect3DRMMeshBuilder3_Load(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
490 filename
, name
, flags
, NULL
, ctx
);
493 static HRESULT WINAPI
d3drm_mesh_builder2_Save(IDirect3DRMMeshBuilder2
*iface
,
494 const char *filename
, D3DRMXOFFORMAT format
, D3DRMSAVEOPTIONS flags
)
496 FIXME("iface %p, filename %s, format %#x, flags %#x stub!\n",
497 iface
, debugstr_a(filename
), format
, flags
);
502 static HRESULT WINAPI
d3drm_mesh_builder2_Scale(IDirect3DRMMeshBuilder2
*iface
,
503 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
505 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
507 TRACE("iface %p, sx %.8e, sy %.8e, sz %.8e.\n", iface
, sx
, sy
, sz
);
509 return IDirect3DRMMeshBuilder3_Scale(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, sx
, sy
, sz
);
512 static HRESULT WINAPI
d3drm_mesh_builder2_Translate(IDirect3DRMMeshBuilder2
*iface
,
513 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
515 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
520 static HRESULT WINAPI
d3drm_mesh_builder2_SetColorSource(IDirect3DRMMeshBuilder2
*iface
, D3DRMCOLORSOURCE source
)
522 FIXME("iface %p, source %#x stub!\n", iface
, source
);
527 static HRESULT WINAPI
d3drm_mesh_builder2_GetBox(IDirect3DRMMeshBuilder2
*iface
, D3DRMBOX
*box
)
529 FIXME("iface %p, box %p stub!\n", iface
, box
);
534 static HRESULT WINAPI
d3drm_mesh_builder2_GenerateNormals(IDirect3DRMMeshBuilder2
*iface
)
536 FIXME("iface %p stub!\n", iface
);
541 static D3DRMCOLORSOURCE WINAPI
d3drm_mesh_builder2_GetColorSource(IDirect3DRMMeshBuilder2
*iface
)
543 FIXME("iface %p stub!\n", iface
);
548 static HRESULT WINAPI
d3drm_mesh_builder2_AddMesh(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMMesh
*mesh
)
550 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
555 static HRESULT WINAPI
d3drm_mesh_builder2_AddMeshBuilder(IDirect3DRMMeshBuilder2
*iface
,
556 IDirect3DRMMeshBuilder
*mesh_builder
)
558 FIXME("iface %p, mesh_builder %p stub!\n", iface
, mesh_builder
);
563 static HRESULT WINAPI
d3drm_mesh_builder2_AddFrame(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFrame
*frame
)
565 FIXME("iface %p, frame %p stub!\n", iface
, frame
);
570 static HRESULT WINAPI
d3drm_mesh_builder2_AddFace(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFace
*face
)
572 FIXME("iface %p, face %p stub!\n", iface
, face
);
577 static HRESULT WINAPI
d3drm_mesh_builder2_AddFaces(IDirect3DRMMeshBuilder2
*iface
,
578 DWORD vertex_count
, D3DVECTOR
*vertices
, DWORD normal_count
, D3DVECTOR
*normals
,
579 DWORD
*face_data
, IDirect3DRMFaceArray
**array
)
581 FIXME("iface %p, vertex_count %u, vertices %p, normal_count %u, normals %p, face_data %p, array %p stub!\n",
582 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data
, array
);
587 static HRESULT WINAPI
d3drm_mesh_builder2_ReserveSpace(IDirect3DRMMeshBuilder2
*iface
,
588 DWORD vertex_count
, DWORD normal_count
, DWORD face_count
)
590 FIXME("iface %p, vertex_count %u, normal_count %u, face_count %u stub!\n",
591 iface
, vertex_count
, normal_count
, face_count
);
596 static HRESULT WINAPI
d3drm_mesh_builder2_SetColorRGB(IDirect3DRMMeshBuilder2
*iface
,
597 D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
599 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
601 TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface
, red
, green
, blue
);
603 return IDirect3DRMMeshBuilder3_SetColorRGB(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, red
, green
, blue
);
606 static HRESULT WINAPI
d3drm_mesh_builder2_SetColor(IDirect3DRMMeshBuilder2
*iface
, D3DCOLOR color
)
608 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
610 TRACE("iface %p, color 0x%08x.\n", iface
, color
);
612 return IDirect3DRMMeshBuilder3_SetColor(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, color
);
615 static HRESULT WINAPI
d3drm_mesh_builder2_SetTexture(IDirect3DRMMeshBuilder2
*iface
,
616 IDirect3DRMTexture
*texture
)
618 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
619 IDirect3DRMTexture3
*texture3
= NULL
;
620 HRESULT hr
= D3DRM_OK
;
622 TRACE("iface %p, texture %p.\n", iface
, texture
);
625 hr
= IDirect3DRMTexture_QueryInterface(texture
, &IID_IDirect3DRMTexture3
, (void **)&texture3
);
627 hr
= IDirect3DRMMeshBuilder3_SetTexture(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, texture3
);
629 IDirect3DRMTexture3_Release(texture3
);
634 static HRESULT WINAPI
d3drm_mesh_builder2_SetMaterial(IDirect3DRMMeshBuilder2
*iface
,
635 IDirect3DRMMaterial
*material
)
637 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
639 TRACE("iface %p, material %p.\n", iface
, material
);
641 return IDirect3DRMMeshBuilder3_SetMaterial(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
642 (IDirect3DRMMaterial2
*)material
);
645 static HRESULT WINAPI
d3drm_mesh_builder2_SetTextureTopology(IDirect3DRMMeshBuilder2
*iface
,
646 BOOL wrap_u
, BOOL wrap_v
)
648 FIXME("iface %p, wrap_u %#x, wrap_v %#x stub!\n", iface
, wrap_u
, wrap_v
);
653 static HRESULT WINAPI
d3drm_mesh_builder2_SetQuality(IDirect3DRMMeshBuilder2
*iface
,
654 D3DRMRENDERQUALITY quality
)
656 FIXME("iface %p, quality %#x stub!\n", iface
, quality
);
661 static HRESULT WINAPI
d3drm_mesh_builder2_SetPerspective(IDirect3DRMMeshBuilder2
*iface
, BOOL enable
)
663 FIXME("iface %p, enable %#x stub!\n", iface
, enable
);
668 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertex(IDirect3DRMMeshBuilder2
*iface
,
669 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
671 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
676 static HRESULT WINAPI
d3drm_mesh_builder2_SetNormal(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_SetTextureCoordinates(IDirect3DRMMeshBuilder2
*iface
,
685 DWORD index
, D3DVALUE u
, D3DVALUE v
)
687 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
689 TRACE("iface %p, index %u, u %.8e, v %.8e.\n", iface
, index
, u
, v
);
691 return IDirect3DRMMeshBuilder3_SetTextureCoordinates(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
695 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertexColor(IDirect3DRMMeshBuilder2
*iface
,
696 DWORD index
, D3DCOLOR color
)
698 FIXME("iface %p, index %u, color 0x%08x stub!\n", iface
, index
, color
);
703 static HRESULT WINAPI
d3drm_mesh_builder2_SetVertexColorRGB(IDirect3DRMMeshBuilder2
*iface
,
704 DWORD index
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
706 FIXME("iface %p, index %u, red %.8e, green %.8e, blue %.8e stub!\n",
707 iface
, index
, red
, green
, blue
);
712 static HRESULT WINAPI
d3drm_mesh_builder2_GetFaces(IDirect3DRMMeshBuilder2
*iface
,
713 IDirect3DRMFaceArray
**array
)
715 FIXME("iface %p, array %p stub!\n", iface
, array
);
720 static HRESULT WINAPI
d3drm_mesh_builder2_GetVertices(IDirect3DRMMeshBuilder2
*iface
,
721 DWORD
*vertex_count
, D3DVECTOR
*vertices
, DWORD
*normal_count
, D3DVECTOR
*normals
,
722 DWORD
*face_data_size
, DWORD
*face_data
)
724 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
726 TRACE("iface %p, vertex_count %p, vertices %p, normal_count %p, normals %p, face_data_size %p, face_data %p.\n",
727 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data_size
, face_data
);
729 if (vertices
&& (!vertex_count
|| (*vertex_count
< mesh_builder
->nb_vertices
)))
730 return D3DRMERR_BADVALUE
;
732 *vertex_count
= mesh_builder
->nb_vertices
;
733 if (vertices
&& mesh_builder
->nb_vertices
)
734 memcpy(vertices
, mesh_builder
->pVertices
, mesh_builder
->nb_vertices
* sizeof(*vertices
));
736 if (normals
&& (!normal_count
|| (*normal_count
< mesh_builder
->nb_normals
)))
737 return D3DRMERR_BADVALUE
;
739 *normal_count
= mesh_builder
->nb_normals
;
740 if (normals
&& mesh_builder
->nb_normals
)
741 memcpy(normals
, mesh_builder
->pNormals
, mesh_builder
->nb_normals
* sizeof(*normals
));
743 if (face_data
&& (!face_data_size
|| (*face_data_size
< mesh_builder
->face_data_size
)))
744 return D3DRMERR_BADVALUE
;
746 *face_data_size
= mesh_builder
->face_data_size
;
747 if (face_data
&& mesh_builder
->face_data_size
)
748 memcpy(face_data
, mesh_builder
->pFaceData
, mesh_builder
->face_data_size
* sizeof(*face_data
));
753 static HRESULT WINAPI
d3drm_mesh_builder2_GetTextureCoordinates(IDirect3DRMMeshBuilder2
*iface
,
754 DWORD index
, D3DVALUE
*u
, D3DVALUE
*v
)
756 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
758 TRACE("iface %p, index %u, u %p, v %p.\n", iface
, index
, u
, v
);
760 return IDirect3DRMMeshBuilder3_GetTextureCoordinates(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
,
764 static int WINAPI
d3drm_mesh_builder2_AddVertex(IDirect3DRMMeshBuilder2
*iface
,
765 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
767 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
772 static int WINAPI
d3drm_mesh_builder2_AddNormal(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 HRESULT WINAPI
d3drm_mesh_builder2_CreateFace(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMFace
**face
)
782 TRACE("iface %p, face %p.\n", iface
, face
);
784 return Direct3DRMFace_create(&IID_IDirect3DRMFace
, (IUnknown
**)face
);
787 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_builder2_GetQuality(IDirect3DRMMeshBuilder2
*iface
)
789 FIXME("iface %p stub!\n", iface
);
794 static BOOL WINAPI
d3drm_mesh_builder2_GetPerspective(IDirect3DRMMeshBuilder2
*iface
)
796 FIXME("iface %p stub!\n", iface
);
801 static int WINAPI
d3drm_mesh_builder2_GetFaceCount(IDirect3DRMMeshBuilder2
*iface
)
803 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
805 TRACE("iface %p.\n", iface
);
807 return mesh_builder
->nb_faces
;
810 static int WINAPI
d3drm_mesh_builder2_GetVertexCount(IDirect3DRMMeshBuilder2
*iface
)
812 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
814 TRACE("iface %p.\n", iface
);
816 return mesh_builder
->nb_vertices
;
819 static D3DCOLOR WINAPI
d3drm_mesh_builder2_GetVertexColor(IDirect3DRMMeshBuilder2
*iface
, DWORD index
)
821 FIXME("iface %p, index %u stub!\n", iface
, index
);
826 static HRESULT WINAPI
d3drm_mesh_builder2_CreateMesh(IDirect3DRMMeshBuilder2
*iface
, IDirect3DRMMesh
**mesh
)
828 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder2(iface
);
830 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
832 return IDirect3DRMMeshBuilder3_CreateMesh(&mesh_builder
->IDirect3DRMMeshBuilder3_iface
, mesh
);
835 static HRESULT WINAPI
d3drm_mesh_builder2_GenerateNormals2(IDirect3DRMMeshBuilder2
*iface
,
836 D3DVALUE crease
, DWORD flags
)
838 FIXME("iface %p, crease %.8e, flags %#x stub!\n", iface
, crease
, flags
);
843 static HRESULT WINAPI
d3drm_mesh_builder2_GetFace(IDirect3DRMMeshBuilder2
*iface
,
844 DWORD index
, IDirect3DRMFace
**face
)
846 FIXME("iface %p, index %u, face %p stub!\n", iface
, index
, face
);
851 static const struct IDirect3DRMMeshBuilder2Vtbl d3drm_mesh_builder2_vtbl
=
853 d3drm_mesh_builder2_QueryInterface
,
854 d3drm_mesh_builder2_AddRef
,
855 d3drm_mesh_builder2_Release
,
856 d3drm_mesh_builder2_Clone
,
857 d3drm_mesh_builder2_AddDestroyCallback
,
858 d3drm_mesh_builder2_DeleteDestroyCallback
,
859 d3drm_mesh_builder2_SetAppData
,
860 d3drm_mesh_builder2_GetAppData
,
861 d3drm_mesh_builder2_SetName
,
862 d3drm_mesh_builder2_GetName
,
863 d3drm_mesh_builder2_GetClassName
,
864 d3drm_mesh_builder2_Load
,
865 d3drm_mesh_builder2_Save
,
866 d3drm_mesh_builder2_Scale
,
867 d3drm_mesh_builder2_Translate
,
868 d3drm_mesh_builder2_SetColorSource
,
869 d3drm_mesh_builder2_GetBox
,
870 d3drm_mesh_builder2_GenerateNormals
,
871 d3drm_mesh_builder2_GetColorSource
,
872 d3drm_mesh_builder2_AddMesh
,
873 d3drm_mesh_builder2_AddMeshBuilder
,
874 d3drm_mesh_builder2_AddFrame
,
875 d3drm_mesh_builder2_AddFace
,
876 d3drm_mesh_builder2_AddFaces
,
877 d3drm_mesh_builder2_ReserveSpace
,
878 d3drm_mesh_builder2_SetColorRGB
,
879 d3drm_mesh_builder2_SetColor
,
880 d3drm_mesh_builder2_SetTexture
,
881 d3drm_mesh_builder2_SetMaterial
,
882 d3drm_mesh_builder2_SetTextureTopology
,
883 d3drm_mesh_builder2_SetQuality
,
884 d3drm_mesh_builder2_SetPerspective
,
885 d3drm_mesh_builder2_SetVertex
,
886 d3drm_mesh_builder2_SetNormal
,
887 d3drm_mesh_builder2_SetTextureCoordinates
,
888 d3drm_mesh_builder2_SetVertexColor
,
889 d3drm_mesh_builder2_SetVertexColorRGB
,
890 d3drm_mesh_builder2_GetFaces
,
891 d3drm_mesh_builder2_GetVertices
,
892 d3drm_mesh_builder2_GetTextureCoordinates
,
893 d3drm_mesh_builder2_AddVertex
,
894 d3drm_mesh_builder2_AddNormal
,
895 d3drm_mesh_builder2_CreateFace
,
896 d3drm_mesh_builder2_GetQuality
,
897 d3drm_mesh_builder2_GetPerspective
,
898 d3drm_mesh_builder2_GetFaceCount
,
899 d3drm_mesh_builder2_GetVertexCount
,
900 d3drm_mesh_builder2_GetVertexColor
,
901 d3drm_mesh_builder2_CreateMesh
,
902 d3drm_mesh_builder2_GenerateNormals2
,
903 d3drm_mesh_builder2_GetFace
,
906 static HRESULT WINAPI
d3drm_mesh_builder3_QueryInterface(IDirect3DRMMeshBuilder3
*iface
, REFIID riid
, void **out
)
908 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
910 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
912 return d3drm_mesh_builder2_QueryInterface(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
, riid
, out
);
915 static ULONG WINAPI
d3drm_mesh_builder3_AddRef(IDirect3DRMMeshBuilder3
*iface
)
917 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
919 TRACE("iface %p.\n", iface
);
921 return d3drm_mesh_builder2_AddRef(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
);
924 static ULONG WINAPI
d3drm_mesh_builder3_Release(IDirect3DRMMeshBuilder3
*iface
)
926 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
928 TRACE("iface %p.\n", iface
);
930 return d3drm_mesh_builder2_Release(&mesh_builder
->IDirect3DRMMeshBuilder2_iface
);
933 static HRESULT WINAPI
d3drm_mesh_builder3_Clone(IDirect3DRMMeshBuilder3
*iface
,
934 IUnknown
*outer
, REFIID iid
, void **out
)
936 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
941 static HRESULT WINAPI
d3drm_mesh_builder3_AddDestroyCallback(IDirect3DRMMeshBuilder3
*iface
,
942 D3DRMOBJECTCALLBACK cb
, void *ctx
)
944 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
949 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteDestroyCallback(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_SetAppData(IDirect3DRMMeshBuilder3
*iface
, DWORD data
)
959 FIXME("iface %p, data %#x stub!\n", iface
, data
);
964 static DWORD WINAPI
d3drm_mesh_builder3_GetAppData(IDirect3DRMMeshBuilder3
*iface
)
966 FIXME("iface %p stub!\n", iface
);
971 static HRESULT WINAPI
d3drm_mesh_builder3_SetName(IDirect3DRMMeshBuilder3
*iface
, const char *name
)
973 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
976 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
980 string
= HeapAlloc(GetProcessHeap(), 0, strlen(name
) + 1);
981 if (!string
) return E_OUTOFMEMORY
;
982 strcpy(string
, name
);
984 HeapFree(GetProcessHeap(), 0, mesh_builder
->name
);
985 mesh_builder
->name
= string
;
990 static HRESULT WINAPI
d3drm_mesh_builder3_GetName(IDirect3DRMMeshBuilder3
*iface
,
991 DWORD
*size
, char *name
)
993 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
995 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
1000 if (!mesh_builder
->name
)
1006 if (*size
< (strlen(mesh_builder
->name
) + 1))
1007 return E_INVALIDARG
;
1009 strcpy(name
, mesh_builder
->name
);
1010 *size
= strlen(mesh_builder
->name
) + 1;
1015 static HRESULT WINAPI
d3drm_mesh_builder3_GetClassName(IDirect3DRMMeshBuilder3
*iface
,
1016 DWORD
*size
, char *name
)
1018 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
1020 if (!size
|| *size
< strlen("Builder") || !name
)
1021 return E_INVALIDARG
;
1023 strcpy(name
, "Builder");
1024 *size
= sizeof("Builder");
1029 HRESULT
load_mesh_data(IDirect3DRMMeshBuilder3
*iface
, IDirectXFileData
*pData
,
1030 D3DRMLOADTEXTURECALLBACK load_texture_proc
, void *arg
)
1032 struct d3drm_mesh_builder
*This
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1033 IDirectXFileData
*pData2
= NULL
;
1038 HRESULT ret
= D3DRMERR_BADOBJECT
;
1039 DWORD
* faces_vertex_idx_data
= NULL
;
1040 DWORD
* faces_vertex_idx_ptr
;
1041 DWORD faces_vertex_idx_size
;
1042 DWORD
* faces_normal_idx_data
= NULL
;
1043 DWORD
* faces_normal_idx_ptr
= NULL
;
1044 DWORD
* faces_data_ptr
;
1045 DWORD faces_data_size
= 0;
1048 TRACE("(%p)->(%p)\n", This
, pData
);
1050 hr
= IDirectXFileData_GetName(pData
, NULL
, &size
);
1051 if (hr
!= DXFILE_OK
)
1055 This
->name
= HeapAlloc(GetProcessHeap(), 0, size
);
1057 return E_OUTOFMEMORY
;
1059 hr
= IDirectXFileData_GetName(pData
, This
->name
, &size
);
1060 if (hr
!= DXFILE_OK
)
1064 TRACE("Mesh name is %s\n", debugstr_a(This
->name
));
1066 This
->nb_normals
= 0;
1068 hr
= IDirectXFileData_GetData(pData
, NULL
, &size
, (void**)&ptr
);
1069 if (hr
!= DXFILE_OK
)
1072 This
->nb_vertices
= *(DWORD
*)ptr
;
1073 This
->nb_faces
= *(DWORD
*)(ptr
+ sizeof(DWORD
) + This
->nb_vertices
* sizeof(D3DVECTOR
));
1074 faces_vertex_idx_size
= size
- sizeof(DWORD
) - This
->nb_vertices
* sizeof(D3DVECTOR
) - sizeof(DWORD
);
1076 TRACE("Mesh: nb_vertices = %d, nb_faces = %d, faces_vertex_idx_size = %d\n", This
->nb_vertices
, This
->nb_faces
, faces_vertex_idx_size
);
1078 This
->pVertices
= HeapAlloc(GetProcessHeap(), 0, This
->nb_vertices
* sizeof(D3DVECTOR
));
1079 memcpy(This
->pVertices
, ptr
+ sizeof(DWORD
), This
->nb_vertices
* sizeof(D3DVECTOR
));
1081 faces_vertex_idx_ptr
= faces_vertex_idx_data
= HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size
);
1082 memcpy(faces_vertex_idx_data
, ptr
+ sizeof(DWORD
) + This
->nb_vertices
* sizeof(D3DVECTOR
) + sizeof(DWORD
), faces_vertex_idx_size
);
1084 /* Each vertex index will have its normal index counterpart so just allocate twice the size */
1085 This
->pFaceData
= HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size
* 2);
1086 faces_data_ptr
= (DWORD
*)This
->pFaceData
;
1090 IDirectXFileObject
*object
;
1092 hr
= IDirectXFileData_GetNextObject(pData
, &object
);
1093 if (hr
== DXFILEERR_NOMOREOBJECTS
)
1095 TRACE("No more object\n");
1098 if (hr
!= DXFILE_OK
)
1101 hr
= IDirectXFileObject_QueryInterface(object
, &IID_IDirectXFileData
, (void**)&pData2
);
1102 IDirectXFileObject_Release(object
);
1103 if (hr
!= DXFILE_OK
)
1106 hr
= IDirectXFileData_GetType(pData2
, &guid
);
1107 if (hr
!= DXFILE_OK
)
1110 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1112 if (IsEqualGUID(guid
, &TID_D3DRMMeshNormals
))
1114 DWORD nb_faces_normals
;
1115 DWORD faces_normal_idx_size
;
1117 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1118 if (hr
!= DXFILE_OK
)
1121 This
->nb_normals
= *(DWORD
*)ptr
;
1122 nb_faces_normals
= *(DWORD
*)(ptr
+ sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
));
1124 TRACE("MeshNormals: nb_normals = %d, nb_faces_normals = %d\n", This
->nb_normals
, nb_faces_normals
);
1125 if (nb_faces_normals
!= This
->nb_faces
)
1126 WARN("nb_face_normals (%d) != nb_faces (%d)\n", nb_faces_normals
, This
->nb_normals
);
1128 This
->pNormals
= HeapAlloc(GetProcessHeap(), 0, This
->nb_normals
* sizeof(D3DVECTOR
));
1129 memcpy(This
->pNormals
, ptr
+ sizeof(DWORD
), This
->nb_normals
* sizeof(D3DVECTOR
));
1131 faces_normal_idx_size
= size
- (2 * sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
));
1132 faces_normal_idx_ptr
= faces_normal_idx_data
= HeapAlloc(GetProcessHeap(), 0, faces_normal_idx_size
);
1133 memcpy(faces_normal_idx_data
, ptr
+ sizeof(DWORD
) + This
->nb_normals
* sizeof(D3DVECTOR
) + sizeof(DWORD
), faces_normal_idx_size
);
1135 else if (IsEqualGUID(guid
, &TID_D3DRMMeshTextureCoords
))
1137 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1138 if (hr
!= DXFILE_OK
)
1141 This
->nb_coords2d
= *(DWORD
*)ptr
;
1143 TRACE("MeshTextureCoords: nb_coords2d = %d\n", This
->nb_coords2d
);
1145 This
->pCoords2d
= HeapAlloc(GetProcessHeap(), 0, This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1146 memcpy(This
->pCoords2d
, ptr
+ sizeof(DWORD
), This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1149 else if (IsEqualGUID(guid
, &TID_D3DRMMeshMaterialList
))
1152 DWORD nb_face_indices
;
1154 IDirectXFileObject
*child
;
1157 struct d3drm_texture
*texture_object
;
1159 TRACE("Process MeshMaterialList\n");
1161 hr
= IDirectXFileData_GetData(pData2
, NULL
, &size
, (void**)&ptr
);
1162 if (hr
!= DXFILE_OK
)
1165 nb_materials
= *(DWORD
*)ptr
;
1166 nb_face_indices
= *(DWORD
*)(ptr
+ sizeof(DWORD
));
1167 data_size
= 2 * sizeof(DWORD
) + nb_face_indices
* sizeof(DWORD
);
1169 TRACE("nMaterials = %u, nFaceIndexes = %u\n", nb_materials
, nb_face_indices
);
1171 if (size
!= data_size
)
1172 WARN("Returned size %u does not match expected one %u\n", size
, data_size
);
1174 This
->material_indices
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
->material_indices
) * nb_face_indices
);
1175 if (!This
->material_indices
)
1177 memcpy(This
->material_indices
, ptr
+ 2 * sizeof(DWORD
), sizeof(*This
->material_indices
) * nb_face_indices
),
1179 This
->materials
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
->materials
) * nb_materials
);
1180 if (!This
->materials
)
1182 HeapFree(GetProcessHeap(), 0, This
->material_indices
);
1185 This
->nb_materials
= nb_materials
;
1187 while (SUCCEEDED(hr
= IDirectXFileData_GetNextObject(pData2
, &child
)) && (i
< nb_materials
))
1189 IDirectXFileData
*data
;
1190 IDirectXFileDataReference
*reference
;
1191 IDirectXFileObject
*material_child
;
1193 hr
= IDirectXFileObject_QueryInterface(child
, &IID_IDirectXFileData
, (void **)&data
);
1196 hr
= IDirectXFileObject_QueryInterface(child
, &IID_IDirectXFileDataReference
, (void **)&reference
);
1197 IDirectXFileObject_Release(child
);
1201 hr
= IDirectXFileDataReference_Resolve(reference
, &data
);
1202 IDirectXFileDataReference_Release(reference
);
1208 IDirectXFileObject_Release(child
);
1211 hr
= Direct3DRMMaterial_create(&This
->materials
[i
].material
);
1214 IDirectXFileData_Release(data
);
1218 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&ptr
);
1219 if (hr
!= DXFILE_OK
)
1221 IDirectXFileData_Release(data
);
1226 WARN("Material size %u does not match expected one %u\n", size
, 44);
1228 values
= (float*)ptr
;
1230 d3drm_set_color(&This
->materials
[i
].color
, values
[0], values
[1], values
[2], values
[3]);
1232 IDirect3DRMMaterial2_SetAmbient(This
->materials
[i
].material
, values
[0], values
[1], values
[2]); /* Alpha ignored */
1233 IDirect3DRMMaterial2_SetPower(This
->materials
[i
].material
, values
[4]);
1234 IDirect3DRMMaterial2_SetSpecular(This
->materials
[i
].material
, values
[5], values
[6], values
[7]);
1235 IDirect3DRMMaterial2_SetEmissive(This
->materials
[i
].material
, values
[8], values
[9], values
[10]);
1237 This
->materials
[i
].texture
= NULL
;
1239 hr
= IDirectXFileData_GetNextObject(data
, &material_child
);
1242 IDirectXFileData
*data
;
1245 if (FAILED(hr
= IDirectXFileObject_QueryInterface(material_child
,
1246 &IID_IDirectXFileData
, (void **)&data
)))
1248 IDirectXFileDataReference
*reference
;
1250 if (SUCCEEDED(IDirectXFileObject_QueryInterface(material_child
,
1251 &IID_IDirectXFileDataReference
, (void **)&reference
)))
1253 hr
= IDirectXFileDataReference_Resolve(reference
, &data
);
1254 IDirectXFileDataReference_Release(reference
);
1257 IDirectXFileObject_Release(material_child
);
1261 hr
= IDirectXFileData_GetType(data
, &guid
);
1262 if (hr
!= DXFILE_OK
)
1264 if (!IsEqualGUID(guid
, &TID_D3DRMTextureFilename
))
1266 WARN("Not a texture filename\n");
1271 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&filename
);
1274 if (load_texture_proc
)
1276 IDirect3DRMTexture
*texture
;
1278 hr
= load_texture_proc(*filename
, arg
, &texture
);
1281 hr
= IDirect3DTexture_QueryInterface(texture
, &IID_IDirect3DRMTexture3
, (void**)&This
->materials
[i
].texture
);
1282 IDirect3DTexture_Release(texture
);
1289 /* If the texture file is not found, no texture is associated with the material */
1290 file
= CreateFileA(*filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
1291 if (file
!= INVALID_HANDLE_VALUE
)
1294 if (FAILED(hr
= d3drm_texture_create(&texture_object
, NULL
)))
1296 IDirectXFileData_Release(data
);
1299 This
->materials
[i
].texture
= &texture_object
->IDirect3DRMTexture3_iface
;
1303 IDirectXFileData_Release(data
);
1305 else if (hr
!= DXFILEERR_NOMOREOBJECTS
)
1311 IDirectXFileData_Release(data
);
1316 IDirectXFileObject_Release(child
);
1317 WARN("Found more sub-objects than expected\n");
1319 else if (hr
!= DXFILEERR_NOMOREOBJECTS
)
1327 FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(guid
));
1330 IDirectXFileData_Release(pData2
);
1334 if (!This
->nb_normals
)
1336 /* Allocate normals, one per vertex */
1337 This
->pNormals
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->nb_vertices
* sizeof(D3DVECTOR
));
1338 if (!This
->pNormals
)
1342 for (i
= 0; i
< This
->nb_faces
; i
++)
1345 DWORD nb_face_indexes
;
1346 D3DVECTOR face_normal
;
1348 if (faces_vertex_idx_size
< sizeof(DWORD
))
1349 WARN("Not enough data to read number of indices of face %d\n", i
);
1351 nb_face_indexes
= *(faces_data_ptr
+ faces_data_size
++) = *(faces_vertex_idx_ptr
++);
1352 faces_vertex_idx_size
--;
1353 if (faces_normal_idx_data
&& (*(faces_normal_idx_ptr
++) != nb_face_indexes
))
1354 WARN("Faces indices number mismatch\n");
1356 if (faces_vertex_idx_size
< (nb_face_indexes
* sizeof(DWORD
)))
1357 WARN("Not enough data to read all indices of face %d\n", i
);
1359 if (!This
->nb_normals
)
1361 /* Compute face normal */
1362 if (nb_face_indexes
> 2
1363 && faces_vertex_idx_ptr
[0] < This
->nb_vertices
1364 && faces_vertex_idx_ptr
[1] < This
->nb_vertices
1365 && faces_vertex_idx_ptr
[2] < This
->nb_vertices
)
1369 D3DRMVectorSubtract(&a
, &This
->pVertices
[faces_vertex_idx_ptr
[2]], &This
->pVertices
[faces_vertex_idx_ptr
[1]]);
1370 D3DRMVectorSubtract(&b
, &This
->pVertices
[faces_vertex_idx_ptr
[0]], &This
->pVertices
[faces_vertex_idx_ptr
[1]]);
1371 D3DRMVectorCrossProduct(&face_normal
, &a
, &b
);
1372 D3DRMVectorNormalize(&face_normal
);
1376 face_normal
.u1
.x
= 0.0f
;
1377 face_normal
.u2
.y
= 0.0f
;
1378 face_normal
.u3
.z
= 0.0f
;
1382 for (j
= 0; j
< nb_face_indexes
; j
++)
1384 /* Copy vertex index */
1385 *(faces_data_ptr
+ faces_data_size
++) = *faces_vertex_idx_ptr
;
1386 /* Copy normal index */
1387 if (This
->nb_normals
)
1389 /* Read from x file */
1390 *(faces_data_ptr
+ faces_data_size
++) = *(faces_normal_idx_ptr
++);
1394 DWORD vertex_idx
= *faces_vertex_idx_ptr
;
1395 if (vertex_idx
>= This
->nb_vertices
)
1397 WARN("Found vertex index %u but only %u vertices available => use index 0\n", vertex_idx
, This
->nb_vertices
);
1400 *(faces_data_ptr
+ faces_data_size
++) = vertex_idx
;
1401 /* Add face normal to vertex normal */
1402 D3DRMVectorAdd(&This
->pNormals
[vertex_idx
], &This
->pNormals
[vertex_idx
], &face_normal
);
1404 faces_vertex_idx_ptr
++;
1406 faces_vertex_idx_size
-= nb_face_indexes
;
1409 /* Last DWORD must be 0 */
1410 *(faces_data_ptr
+ faces_data_size
++) = 0;
1412 /* Set size (in number of DWORD) of all faces data */
1413 This
->face_data_size
= faces_data_size
;
1415 if (!This
->nb_normals
)
1417 /* Normalize all normals */
1418 for (i
= 0; i
< This
->nb_vertices
; i
++)
1420 D3DRMVectorNormalize(&This
->pNormals
[i
]);
1422 This
->nb_normals
= This
->nb_vertices
;
1425 /* If there is no texture coordinates, generate default texture coordinates (0.0f, 0.0f) for each vertex */
1426 if (!This
->pCoords2d
)
1428 This
->nb_coords2d
= This
->nb_vertices
;
1429 This
->pCoords2d
= HeapAlloc(GetProcessHeap(), 0, This
->nb_coords2d
* sizeof(*This
->pCoords2d
));
1430 for (i
= 0; i
< This
->nb_coords2d
; i
++)
1432 This
->pCoords2d
[i
].u
= 0.0f
;
1433 This
->pCoords2d
[i
].v
= 0.0f
;
1437 TRACE("Mesh data loaded successfully\n");
1443 HeapFree(GetProcessHeap(), 0, faces_normal_idx_data
);
1444 HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data
);
1449 static HRESULT WINAPI
d3drm_mesh_builder3_Load(IDirect3DRMMeshBuilder3
*iface
, void *filename
,
1450 void *name
, D3DRMLOADOPTIONS loadflags
, D3DRMLOADTEXTURE3CALLBACK cb
, void *arg
)
1452 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1453 DXFILELOADOPTIONS load_options
;
1454 IDirectXFile
*dxfile
= NULL
;
1455 IDirectXFileEnumObject
*enum_object
= NULL
;
1456 IDirectXFileData
*data
= NULL
;
1459 struct d3drm_file_header
*header
;
1461 HRESULT ret
= D3DRMERR_BADOBJECT
;
1463 TRACE("iface %p, filename %p, name %p, loadflags %#x, cb %p, arg %p.\n",
1464 iface
, filename
, name
, loadflags
, cb
, arg
);
1466 clean_mesh_builder_data(mesh_builder
);
1468 if (loadflags
== D3DRMLOAD_FROMMEMORY
)
1470 load_options
= DXFILELOAD_FROMMEMORY
;
1472 else if (loadflags
== D3DRMLOAD_FROMFILE
)
1474 load_options
= DXFILELOAD_FROMFILE
;
1475 TRACE("Loading from file %s\n", debugstr_a(filename
));
1479 FIXME("Load options %d not supported yet\n", loadflags
);
1483 hr
= DirectXFileCreate(&dxfile
);
1484 if (hr
!= DXFILE_OK
)
1487 hr
= IDirectXFile_RegisterTemplates(dxfile
, templates
, strlen(templates
));
1488 if (hr
!= DXFILE_OK
)
1491 hr
= IDirectXFile_CreateEnumObject(dxfile
, filename
, load_options
, &enum_object
);
1492 if (hr
!= DXFILE_OK
)
1495 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &data
);
1496 if (hr
!= DXFILE_OK
)
1499 hr
= IDirectXFileData_GetType(data
, &guid
);
1500 if (hr
!= DXFILE_OK
)
1503 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1505 if (!IsEqualGUID(guid
, &TID_DXFILEHeader
))
1507 ret
= D3DRMERR_BADFILE
;
1511 hr
= IDirectXFileData_GetData(data
, NULL
, &size
, (void**)&header
);
1512 if ((hr
!= DXFILE_OK
) || (size
!= sizeof(*header
)))
1515 TRACE("Version is %u.%u, flags %#x.\n", header
->major
, header
->minor
, header
->flags
);
1517 /* Version must be 1.0.x */
1518 if ((header
->major
!= 1) || (header
->minor
!= 0))
1520 ret
= D3DRMERR_BADFILE
;
1524 IDirectXFileData_Release(data
);
1527 hr
= IDirectXFileEnumObject_GetNextDataObject(enum_object
, &data
);
1528 if (hr
!= DXFILE_OK
)
1530 ret
= D3DRMERR_NOTFOUND
;
1534 hr
= IDirectXFileData_GetType(data
, &guid
);
1535 if (hr
!= DXFILE_OK
)
1538 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid
));
1540 if (!IsEqualGUID(guid
, &TID_D3DRMMesh
))
1542 ret
= D3DRMERR_NOTFOUND
;
1546 /* We don't care about the texture interface version since we rely on QueryInterface */
1547 hr
= load_mesh_data(iface
, data
, (D3DRMLOADTEXTURECALLBACK
)cb
, arg
);
1554 IDirectXFileData_Release(data
);
1556 IDirectXFileEnumObject_Release(enum_object
);
1558 IDirectXFile_Release(dxfile
);
1560 if (ret
!= D3DRM_OK
)
1561 clean_mesh_builder_data(mesh_builder
);
1566 static HRESULT WINAPI
d3drm_mesh_builder3_Save(IDirect3DRMMeshBuilder3
*iface
,
1567 const char *filename
, D3DRMXOFFORMAT format
, D3DRMSAVEOPTIONS flags
)
1569 FIXME("iface %p, filename %s, format %#x, flags %#x stub!\n",
1570 iface
, debugstr_a(filename
), format
, flags
);
1575 static HRESULT WINAPI
d3drm_mesh_builder3_Scale(IDirect3DRMMeshBuilder3
*iface
,
1576 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
1578 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1581 TRACE("iface %p, sx %.8e, sy %.8e, sz %.8e.\n", iface
, sx
, sy
, sz
);
1583 for (i
= 0; i
< mesh_builder
->nb_vertices
; ++i
)
1585 mesh_builder
->pVertices
[i
].u1
.x
*= sx
;
1586 mesh_builder
->pVertices
[i
].u2
.y
*= sy
;
1587 mesh_builder
->pVertices
[i
].u3
.z
*= sz
;
1590 /* Normals are not affected by Scale */
1595 static HRESULT WINAPI
d3drm_mesh_builder3_Translate(IDirect3DRMMeshBuilder3
*iface
,
1596 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
1598 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
1603 static HRESULT WINAPI
d3drm_mesh_builder3_SetColorSource(IDirect3DRMMeshBuilder3
*iface
,
1604 D3DRMCOLORSOURCE source
)
1606 FIXME("iface %p, source %#x stub!\n", iface
, source
);
1611 static HRESULT WINAPI
d3drm_mesh_builder3_GetBox(IDirect3DRMMeshBuilder3
*iface
, D3DRMBOX
*box
)
1613 FIXME("iface %p, box %p stub!\n", iface
, box
);
1618 static HRESULT WINAPI
d3drm_mesh_builder3_GenerateNormals(IDirect3DRMMeshBuilder3
*iface
,
1619 D3DVALUE crease
, DWORD flags
)
1621 FIXME("iface %p, crease %.8e, flags %#x stub!\n", iface
, crease
, flags
);
1626 static D3DRMCOLORSOURCE WINAPI
d3drm_mesh_builder3_GetColorSource(IDirect3DRMMeshBuilder3
*iface
)
1628 FIXME("iface %p stub!\n", iface
);
1633 static HRESULT WINAPI
d3drm_mesh_builder3_AddMesh(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMMesh
*mesh
)
1635 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
1640 static HRESULT WINAPI
d3drm_mesh_builder3_AddMeshBuilder(IDirect3DRMMeshBuilder3
*iface
,
1641 IDirect3DRMMeshBuilder3
*mesh_builder
, DWORD flags
)
1643 FIXME("iface %p, mesh_builder %p, flags %#x stub!\n", iface
, mesh_builder
, flags
);
1648 static HRESULT WINAPI
d3drm_mesh_builder3_AddFrame(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFrame3
*frame
)
1650 FIXME("iface %p, frame %p stub!\n", iface
, frame
);
1655 static HRESULT WINAPI
d3drm_mesh_builder3_AddFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
*face
)
1657 FIXME("iface %p, face %p stub!\n", iface
, face
);
1662 static HRESULT WINAPI
d3drm_mesh_builder3_AddFaces(IDirect3DRMMeshBuilder3
*iface
,
1663 DWORD vertex_count
, D3DVECTOR
*vertices
, DWORD normal_count
, D3DVECTOR
*normals
,
1664 DWORD
*face_data
, IDirect3DRMFaceArray
**array
)
1666 FIXME("iface %p, vertex_count %u, vertices %p, normal_count %u, normals %p, face_data %p array %p stub!\n",
1667 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data
, array
);
1672 static HRESULT WINAPI
d3drm_mesh_builder3_ReserveSpace(IDirect3DRMMeshBuilder3
*iface
,
1673 DWORD vertex_count
, DWORD normal_count
, DWORD face_count
)
1675 FIXME("iface %p, vertex_count %u, normal_count %u, face_count %u stub!\n",
1676 iface
, vertex_count
, normal_count
, face_count
);
1681 static HRESULT WINAPI
d3drm_mesh_builder3_SetColorRGB(IDirect3DRMMeshBuilder3
*iface
,
1682 D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
1684 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1686 TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface
, red
, green
, blue
);
1688 d3drm_set_color(&mesh_builder
->color
, red
, green
, blue
, 1.0f
);
1693 static HRESULT WINAPI
d3drm_mesh_builder3_SetColor(IDirect3DRMMeshBuilder3
*iface
, D3DCOLOR color
)
1695 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1697 TRACE("iface %p, color 0x%08x.\n", iface
, color
);
1699 mesh_builder
->color
= color
;
1704 static HRESULT WINAPI
d3drm_mesh_builder3_SetTexture(IDirect3DRMMeshBuilder3
*iface
,
1705 IDirect3DRMTexture3
*texture
)
1707 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1709 TRACE("iface %p, texture %p.\n", iface
, texture
);
1712 IDirect3DRMTexture3_AddRef(texture
);
1713 if (mesh_builder
->texture
)
1714 IDirect3DRMTexture3_Release(mesh_builder
->texture
);
1715 mesh_builder
->texture
= texture
;
1720 static HRESULT WINAPI
d3drm_mesh_builder3_SetMaterial(IDirect3DRMMeshBuilder3
*iface
,
1721 IDirect3DRMMaterial2
*material
)
1723 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1725 TRACE("iface %p, material %p.\n", iface
, material
);
1728 IDirect3DRMTexture2_AddRef(material
);
1729 if (mesh_builder
->material
)
1730 IDirect3DRMTexture2_Release(mesh_builder
->material
);
1731 mesh_builder
->material
= material
;
1736 static HRESULT WINAPI
d3drm_mesh_builder3_SetTextureTopology(IDirect3DRMMeshBuilder3
*iface
,
1737 BOOL wrap_u
, BOOL wrap_v
)
1739 FIXME("iface %p, wrap_u %#x, wrap_v %#x stub!\n", iface
, wrap_u
, wrap_v
);
1744 static HRESULT WINAPI
d3drm_mesh_builder3_SetQuality(IDirect3DRMMeshBuilder3
*iface
,
1745 D3DRMRENDERQUALITY quality
)
1747 FIXME("iface %p, quality %#x stub!\n", iface
, quality
);
1752 static HRESULT WINAPI
d3drm_mesh_builder3_SetPerspective(IDirect3DRMMeshBuilder3
*iface
,
1755 FIXME("iface %p, enable %#x stub!\n", iface
, enable
);
1760 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertex(IDirect3DRMMeshBuilder3
*iface
,
1761 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1763 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
1768 static HRESULT WINAPI
d3drm_mesh_builder3_SetNormal(IDirect3DRMMeshBuilder3
*iface
,
1769 DWORD index
, D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1771 FIXME("iface %p, index %u, x %.8e, y %.8e, z %.8e stub!\n", iface
, index
, x
, y
, z
);
1776 static HRESULT WINAPI
d3drm_mesh_builder3_SetTextureCoordinates(IDirect3DRMMeshBuilder3
*iface
,
1777 DWORD index
, D3DVALUE u
, D3DVALUE v
)
1779 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1781 TRACE("iface %p, index %u, u %.8e, v %.8e.\n", iface
, index
, u
, v
);
1783 if (index
>= mesh_builder
->nb_coords2d
)
1784 return D3DRMERR_BADVALUE
;
1786 mesh_builder
->pCoords2d
[index
].u
= u
;
1787 mesh_builder
->pCoords2d
[index
].v
= v
;
1792 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertexColor(IDirect3DRMMeshBuilder3
*iface
,
1793 DWORD index
, D3DCOLOR color
)
1795 FIXME("iface %p, index %u, color 0x%08x stub!\n", iface
, index
, color
);
1800 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertexColorRGB(IDirect3DRMMeshBuilder3
*iface
,
1801 DWORD index
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
1803 FIXME("iface %p, index %u, red %.8e, green %.8e, blue %.8e stub!\n",
1804 iface
, index
, red
, green
, blue
);
1809 static HRESULT WINAPI
d3drm_mesh_builder3_GetFaces(IDirect3DRMMeshBuilder3
*iface
,
1810 IDirect3DRMFaceArray
**array
)
1812 FIXME("iface %p, array %p stub!\n", iface
, array
);
1817 static HRESULT WINAPI
d3drm_mesh_builder3_GetGeometry(IDirect3DRMMeshBuilder3
*iface
,
1818 DWORD
*vertex_count
, D3DVECTOR
*vertices
, DWORD
*normal_count
, D3DVECTOR
*normals
,
1819 DWORD
*face_data_size
, DWORD
*face_data
)
1821 FIXME("iface %p, vertex_count %p, vertices %p, normal_count %p, normals %p, "
1822 "face_data_size %p, face_data %p stub!\n",
1823 iface
, vertex_count
, vertices
, normal_count
, normals
, face_data_size
, face_data
);
1828 static HRESULT WINAPI
d3drm_mesh_builder3_GetTextureCoordinates(IDirect3DRMMeshBuilder3
*iface
,
1829 DWORD index
, D3DVALUE
*u
, D3DVALUE
*v
)
1831 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1833 TRACE("iface %p, index %u, u %p, v %p.\n", iface
, index
, u
, v
);
1835 if (index
>= mesh_builder
->nb_coords2d
)
1836 return D3DRMERR_BADVALUE
;
1838 *u
= mesh_builder
->pCoords2d
[index
].u
;
1839 *v
= mesh_builder
->pCoords2d
[index
].v
;
1844 static int WINAPI
d3drm_mesh_builder3_AddVertex(IDirect3DRMMeshBuilder3
*iface
,
1845 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1847 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
1852 static int WINAPI
d3drm_mesh_builder3_AddNormal(IDirect3DRMMeshBuilder3
*iface
,
1853 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
)
1855 FIXME("iface %p, x %.8e, y %.8e, z %.8e stub!\n", iface
, x
, y
, z
);
1860 static HRESULT WINAPI
d3drm_mesh_builder3_CreateFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
**face
)
1862 TRACE("iface %p, face %p.\n", iface
, face
);
1864 return Direct3DRMFace_create(&IID_IDirect3DRMFace2
, (IUnknown
**)face
);
1867 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_builder3_GetQuality(IDirect3DRMMeshBuilder3
*iface
)
1869 FIXME("iface %p stub!\n", iface
);
1874 static BOOL WINAPI
d3drm_mesh_builder3_GetPerspective(IDirect3DRMMeshBuilder3
*iface
)
1876 FIXME("iface %p stub!\n", iface
);
1881 static int WINAPI
d3drm_mesh_builder3_GetFaceCount(IDirect3DRMMeshBuilder3
*iface
)
1883 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1885 TRACE("iface %p.\n", iface
);
1887 return mesh_builder
->nb_faces
;
1890 static int WINAPI
d3drm_mesh_builder3_GetVertexCount(IDirect3DRMMeshBuilder3
*iface
)
1892 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1894 TRACE("iface %p.\n", iface
);
1896 return mesh_builder
->nb_vertices
;
1899 static D3DCOLOR WINAPI
d3drm_mesh_builder3_GetVertexColor(IDirect3DRMMeshBuilder3
*iface
,
1902 FIXME("iface %p, index %u stub!\n", iface
, index
);
1907 static HRESULT WINAPI
d3drm_mesh_builder3_CreateMesh(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMMesh
**mesh
)
1909 struct d3drm_mesh_builder
*This
= impl_from_IDirect3DRMMeshBuilder3(iface
);
1911 D3DRMGROUPINDEX group
;
1913 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
1918 hr
= Direct3DRMMesh_create(mesh
);
1922 /* If there is mesh data, create a group and put data inside */
1923 if (This
->nb_vertices
)
1927 D3DRMVERTEX
* vertices
;
1929 vertices
= HeapAlloc(GetProcessHeap(), 0, This
->nb_vertices
* sizeof(D3DRMVERTEX
));
1932 IDirect3DRMMesh_Release(*mesh
);
1933 return E_OUTOFMEMORY
;
1935 for (i
= 0; i
< This
->nb_vertices
; i
++)
1936 vertices
[i
].position
= This
->pVertices
[i
];
1937 hr
= IDirect3DRMMesh_SetVertices(*mesh
, 0, 0, This
->nb_vertices
, vertices
);
1938 HeapFree(GetProcessHeap(), 0, vertices
);
1940 /* Groups are in reverse order compared to materials list in X file */
1941 for (k
= This
->nb_materials
- 1; k
>= 0; k
--)
1943 unsigned* face_data
;
1945 DWORD
* in_ptr
= This
->pFaceData
;
1946 ULONG vertex_per_face
= 0;
1947 BOOL
* used_vertices
;
1948 unsigned nb_vertices
= 0;
1949 unsigned nb_faces
= 0;
1951 used_vertices
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->face_data_size
* sizeof(*used_vertices
));
1954 IDirect3DRMMesh_Release(*mesh
);
1955 return E_OUTOFMEMORY
;
1958 face_data
= HeapAlloc(GetProcessHeap(), 0, This
->face_data_size
* sizeof(*face_data
));
1961 HeapFree(GetProcessHeap(), 0, used_vertices
);
1962 IDirect3DRMMesh_Release(*mesh
);
1963 return E_OUTOFMEMORY
;
1965 out_ptr
= face_data
;
1967 /* If all faces have the same number of vertex, set vertex_per_face */
1968 for (i
= 0; i
< This
->nb_faces
; i
++)
1970 /* Process only faces belonging to the group */
1971 if (This
->material_indices
[i
] == k
)
1973 if (vertex_per_face
&& (vertex_per_face
!= *in_ptr
))
1975 vertex_per_face
= *in_ptr
;
1977 in_ptr
+= 1 + *in_ptr
* 2;
1979 if (i
!= This
->nb_faces
)
1980 vertex_per_face
= 0;
1982 /* Put only vertex indices */
1983 in_ptr
= This
->pFaceData
;
1984 for (i
= 0; i
< This
->nb_faces
; i
++)
1986 DWORD nb_indices
= *in_ptr
++;
1988 /* Skip faces not belonging to the group */
1989 if (This
->material_indices
[i
] != k
)
1991 in_ptr
+= 2 * nb_indices
;
1995 /* Don't put nb indices when vertex_per_face is set */
1996 if (vertex_per_face
)
1997 *out_ptr
++ = nb_indices
;
1999 for (j
= 0; j
< nb_indices
; j
++)
2001 *out_ptr
= *in_ptr
++;
2002 used_vertices
[*out_ptr
++] = TRUE
;
2003 /* Skip normal index */
2010 for (i
= 0; i
< This
->nb_vertices
; i
++)
2011 if (used_vertices
[i
])
2014 hr
= IDirect3DRMMesh_AddGroup(*mesh
, nb_vertices
, nb_faces
, vertex_per_face
, face_data
, &group
);
2015 HeapFree(GetProcessHeap(), 0, used_vertices
);
2016 HeapFree(GetProcessHeap(), 0, face_data
);
2018 hr
= IDirect3DRMMesh_SetGroupColor(*mesh
, group
, This
->materials
[k
].color
);
2020 hr
= IDirect3DRMMesh_SetGroupMaterial(*mesh
, group
,
2021 (IDirect3DRMMaterial
*)This
->materials
[k
].material
);
2022 if (SUCCEEDED(hr
) && This
->materials
[k
].texture
)
2024 IDirect3DRMTexture
*texture
;
2026 IDirect3DRMTexture3_QueryInterface(This
->materials
[k
].texture
,
2027 &IID_IDirect3DRMTexture
, (void **)&texture
);
2028 hr
= IDirect3DRMMesh_SetGroupTexture(*mesh
, group
, texture
);
2029 IDirect3DRMTexture_Release(texture
);
2033 IDirect3DRMMesh_Release(*mesh
);
2042 static HRESULT WINAPI
d3drm_mesh_builder3_GetFace(IDirect3DRMMeshBuilder3
*iface
,
2043 DWORD index
, IDirect3DRMFace2
**face
)
2045 FIXME("iface %p, index %u, face %p stub!\n", iface
, index
, face
);
2050 static HRESULT WINAPI
d3drm_mesh_builder3_GetVertex(IDirect3DRMMeshBuilder3
*iface
,
2051 DWORD index
, D3DVECTOR
*vector
)
2053 FIXME("iface %p, index %u, vector %p stub!\n", iface
, index
, vector
);
2058 static HRESULT WINAPI
d3drm_mesh_builder3_GetNormal(IDirect3DRMMeshBuilder3
*iface
,
2059 DWORD index
, D3DVECTOR
*vector
)
2061 FIXME("iface %p, index %u, vector %p stub!\n", iface
, index
, vector
);
2066 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteVertices(IDirect3DRMMeshBuilder3
*iface
,
2067 DWORD start_idx
, DWORD count
)
2069 FIXME("iface %p, start_idx %u, count %u stub!\n", iface
, start_idx
, count
);
2074 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteNormals(IDirect3DRMMeshBuilder3
*iface
,
2075 DWORD start_idx
, DWORD count
)
2077 FIXME("iface %p, start_idx %u, count %u stub!\n", iface
, start_idx
, count
);
2082 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteFace(IDirect3DRMMeshBuilder3
*iface
, IDirect3DRMFace2
*face
)
2084 FIXME("iface %p, face %p stub!\n", iface
, face
);
2089 static HRESULT WINAPI
d3drm_mesh_builder3_Empty(IDirect3DRMMeshBuilder3
*iface
, DWORD flags
)
2091 FIXME("iface %p, flags %#x stub!\n", iface
, flags
);
2096 static HRESULT WINAPI
d3drm_mesh_builder3_Optimize(IDirect3DRMMeshBuilder3
*iface
, DWORD flags
)
2098 FIXME("iface %p, flags %#x stub!\n", iface
, flags
);
2103 static HRESULT WINAPI
d3drm_mesh_builder3_AddFacesIndexed(IDirect3DRMMeshBuilder3
*iface
,
2104 DWORD flags
, DWORD
*indices
, DWORD
*start_idx
, DWORD
*count
)
2106 FIXME("iface %p, flags %#x, indices %p, start_idx %p, count %p stub!\n",
2107 iface
, flags
, indices
, start_idx
, count
);
2112 static HRESULT WINAPI
d3drm_mesh_builder3_CreateSubMesh(IDirect3DRMMeshBuilder3
*iface
, IUnknown
**mesh
)
2114 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
2119 static HRESULT WINAPI
d3drm_mesh_builder3_GetParentMesh(IDirect3DRMMeshBuilder3
*iface
,
2120 DWORD flags
, IUnknown
**parent
)
2122 FIXME("iface %p, flags %#x, parent %p stub!\n", iface
, flags
, parent
);
2127 static HRESULT WINAPI
d3drm_mesh_builder3_GetSubMeshes(IDirect3DRMMeshBuilder3
*iface
,
2128 DWORD
*count
, IUnknown
**meshes
)
2130 FIXME("iface %p, count %p, meshes %p stub!\n", iface
, count
, meshes
);
2135 static HRESULT WINAPI
d3drm_mesh_builder3_DeleteSubMesh(IDirect3DRMMeshBuilder3
*iface
, IUnknown
*mesh
)
2137 FIXME("iface %p, mesh %p stub!\n", iface
, mesh
);
2142 static HRESULT WINAPI
d3drm_mesh_builder3_Enable(IDirect3DRMMeshBuilder3
*iface
, DWORD index
)
2144 FIXME("iface %p, index %u stub!\n", iface
, index
);
2149 static HRESULT WINAPI
d3drm_mesh_builder3_GetEnable(IDirect3DRMMeshBuilder3
*iface
, DWORD
*indices
)
2151 FIXME("iface %p, indices %p stub!\n", iface
, indices
);
2156 static HRESULT WINAPI
d3drm_mesh_builder3_AddTriangles(IDirect3DRMMeshBuilder3
*iface
,
2157 DWORD flags
, DWORD format
, DWORD vertex_count
, void *data
)
2159 FIXME("iface %p, flags %#x, format %#x, vertex_count %u, data %p stub!\n",
2160 iface
, flags
, format
, vertex_count
, data
);
2165 static HRESULT WINAPI
d3drm_mesh_builder3_SetVertices(IDirect3DRMMeshBuilder3
*iface
,
2166 DWORD start_idx
, DWORD count
, D3DVECTOR
*vector
)
2168 FIXME("iface %p, start_idx %u, count %u, vector %p stub!\n", iface
, start_idx
, count
, vector
);
2173 static HRESULT WINAPI
d3drm_mesh_builder3_GetVertices(IDirect3DRMMeshBuilder3
*iface
,
2174 DWORD start_idx
, DWORD
*vertex_count
, D3DVECTOR
*vertices
)
2176 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2177 DWORD count
= mesh_builder
->nb_vertices
- start_idx
;
2179 TRACE("iface %p, start_idx %u, vertex_count %p, vertices %p.\n",
2180 iface
, start_idx
, vertex_count
, vertices
);
2183 *vertex_count
= count
;
2184 if (vertices
&& mesh_builder
->nb_vertices
)
2185 memcpy(vertices
, mesh_builder
->pVertices
+ start_idx
, count
* sizeof(*vertices
));
2190 static HRESULT WINAPI
d3drm_mesh_builder3_SetNormals(IDirect3DRMMeshBuilder3
*iface
,
2191 DWORD start_idx
, DWORD count
, D3DVECTOR
*vector
)
2193 FIXME("iface %p, start_idx %u, count %u, vector %p stub!\n",
2194 iface
, start_idx
, count
, vector
);
2199 static HRESULT WINAPI
d3drm_mesh_builder3_GetNormals(IDirect3DRMMeshBuilder3
*iface
,
2200 DWORD start_idx
, DWORD
*normal_count
, D3DVECTOR
*normals
)
2202 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2203 DWORD count
= mesh_builder
->nb_normals
- start_idx
;
2205 TRACE("iface %p, start_idx %u, normal_count %p, normals %p.\n",
2206 iface
, start_idx
, normal_count
, normals
);
2209 *normal_count
= count
;
2210 if (normals
&& mesh_builder
->nb_normals
)
2211 memcpy(normals
, mesh_builder
->pNormals
+ start_idx
, count
* sizeof(*normals
));
2216 static int WINAPI
d3drm_mesh_builder3_GetNormalCount(IDirect3DRMMeshBuilder3
*iface
)
2218 struct d3drm_mesh_builder
*mesh_builder
= impl_from_IDirect3DRMMeshBuilder3(iface
);
2220 TRACE("iface %p.\n", iface
);
2222 return mesh_builder
->nb_normals
;
2225 static const struct IDirect3DRMMeshBuilder3Vtbl d3drm_mesh_builder3_vtbl
=
2227 d3drm_mesh_builder3_QueryInterface
,
2228 d3drm_mesh_builder3_AddRef
,
2229 d3drm_mesh_builder3_Release
,
2230 d3drm_mesh_builder3_Clone
,
2231 d3drm_mesh_builder3_AddDestroyCallback
,
2232 d3drm_mesh_builder3_DeleteDestroyCallback
,
2233 d3drm_mesh_builder3_SetAppData
,
2234 d3drm_mesh_builder3_GetAppData
,
2235 d3drm_mesh_builder3_SetName
,
2236 d3drm_mesh_builder3_GetName
,
2237 d3drm_mesh_builder3_GetClassName
,
2238 d3drm_mesh_builder3_Load
,
2239 d3drm_mesh_builder3_Save
,
2240 d3drm_mesh_builder3_Scale
,
2241 d3drm_mesh_builder3_Translate
,
2242 d3drm_mesh_builder3_SetColorSource
,
2243 d3drm_mesh_builder3_GetBox
,
2244 d3drm_mesh_builder3_GenerateNormals
,
2245 d3drm_mesh_builder3_GetColorSource
,
2246 d3drm_mesh_builder3_AddMesh
,
2247 d3drm_mesh_builder3_AddMeshBuilder
,
2248 d3drm_mesh_builder3_AddFrame
,
2249 d3drm_mesh_builder3_AddFace
,
2250 d3drm_mesh_builder3_AddFaces
,
2251 d3drm_mesh_builder3_ReserveSpace
,
2252 d3drm_mesh_builder3_SetColorRGB
,
2253 d3drm_mesh_builder3_SetColor
,
2254 d3drm_mesh_builder3_SetTexture
,
2255 d3drm_mesh_builder3_SetMaterial
,
2256 d3drm_mesh_builder3_SetTextureTopology
,
2257 d3drm_mesh_builder3_SetQuality
,
2258 d3drm_mesh_builder3_SetPerspective
,
2259 d3drm_mesh_builder3_SetVertex
,
2260 d3drm_mesh_builder3_SetNormal
,
2261 d3drm_mesh_builder3_SetTextureCoordinates
,
2262 d3drm_mesh_builder3_SetVertexColor
,
2263 d3drm_mesh_builder3_SetVertexColorRGB
,
2264 d3drm_mesh_builder3_GetFaces
,
2265 d3drm_mesh_builder3_GetGeometry
,
2266 d3drm_mesh_builder3_GetTextureCoordinates
,
2267 d3drm_mesh_builder3_AddVertex
,
2268 d3drm_mesh_builder3_AddNormal
,
2269 d3drm_mesh_builder3_CreateFace
,
2270 d3drm_mesh_builder3_GetQuality
,
2271 d3drm_mesh_builder3_GetPerspective
,
2272 d3drm_mesh_builder3_GetFaceCount
,
2273 d3drm_mesh_builder3_GetVertexCount
,
2274 d3drm_mesh_builder3_GetVertexColor
,
2275 d3drm_mesh_builder3_CreateMesh
,
2276 d3drm_mesh_builder3_GetFace
,
2277 d3drm_mesh_builder3_GetVertex
,
2278 d3drm_mesh_builder3_GetNormal
,
2279 d3drm_mesh_builder3_DeleteVertices
,
2280 d3drm_mesh_builder3_DeleteNormals
,
2281 d3drm_mesh_builder3_DeleteFace
,
2282 d3drm_mesh_builder3_Empty
,
2283 d3drm_mesh_builder3_Optimize
,
2284 d3drm_mesh_builder3_AddFacesIndexed
,
2285 d3drm_mesh_builder3_CreateSubMesh
,
2286 d3drm_mesh_builder3_GetParentMesh
,
2287 d3drm_mesh_builder3_GetSubMeshes
,
2288 d3drm_mesh_builder3_DeleteSubMesh
,
2289 d3drm_mesh_builder3_Enable
,
2290 d3drm_mesh_builder3_GetEnable
,
2291 d3drm_mesh_builder3_AddTriangles
,
2292 d3drm_mesh_builder3_SetVertices
,
2293 d3drm_mesh_builder3_GetVertices
,
2294 d3drm_mesh_builder3_SetNormals
,
2295 d3drm_mesh_builder3_GetNormals
,
2296 d3drm_mesh_builder3_GetNormalCount
,
2299 HRESULT
Direct3DRMMeshBuilder_create(REFIID riid
, IUnknown
**out
)
2301 struct d3drm_mesh_builder
*object
;
2303 TRACE("riid %s, out %p.\n", debugstr_guid(riid
), out
);
2305 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2306 return E_OUTOFMEMORY
;
2308 object
->IDirect3DRMMeshBuilder2_iface
.lpVtbl
= &d3drm_mesh_builder2_vtbl
;
2309 object
->IDirect3DRMMeshBuilder3_iface
.lpVtbl
= &d3drm_mesh_builder3_vtbl
;
2312 if (IsEqualGUID(riid
, &IID_IDirect3DRMMeshBuilder3
))
2313 *out
= (IUnknown
*)&object
->IDirect3DRMMeshBuilder3_iface
;
2315 *out
= (IUnknown
*)&object
->IDirect3DRMMeshBuilder2_iface
;
2320 static HRESULT WINAPI
d3drm_mesh_QueryInterface(IDirect3DRMMesh
*iface
, REFIID riid
, void **out
)
2322 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
2324 if (IsEqualGUID(riid
, &IID_IDirect3DRMMesh
)
2325 || IsEqualGUID(riid
, &IID_IUnknown
))
2327 IDirect3DRMMesh_AddRef(iface
);
2332 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
2335 return E_NOINTERFACE
;
2338 static ULONG WINAPI
d3drm_mesh_AddRef(IDirect3DRMMesh
*iface
)
2340 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2341 ULONG refcount
= InterlockedIncrement(&mesh
->ref
);
2343 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
2348 static ULONG WINAPI
d3drm_mesh_Release(IDirect3DRMMesh
*iface
)
2350 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2351 ULONG refcount
= InterlockedDecrement(&mesh
->ref
);
2353 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
2359 for (i
= 0; i
< mesh
->nb_groups
; ++i
)
2361 HeapFree(GetProcessHeap(), 0, mesh
->groups
[i
].vertices
);
2362 HeapFree(GetProcessHeap(), 0, mesh
->groups
[i
].face_data
);
2363 if (mesh
->groups
[i
].material
)
2364 IDirect3DRMMaterial2_Release(mesh
->groups
[i
].material
);
2365 if (mesh
->groups
[i
].texture
)
2366 IDirect3DRMTexture3_Release(mesh
->groups
[i
].texture
);
2368 HeapFree(GetProcessHeap(), 0, mesh
->groups
);
2369 HeapFree(GetProcessHeap(), 0, mesh
);
2375 static HRESULT WINAPI
d3drm_mesh_Clone(IDirect3DRMMesh
*iface
,
2376 IUnknown
*outer
, REFIID iid
, void **out
)
2378 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
2383 static HRESULT WINAPI
d3drm_mesh_AddDestroyCallback(IDirect3DRMMesh
*iface
,
2384 D3DRMOBJECTCALLBACK cb
, void *ctx
)
2386 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
2391 static HRESULT WINAPI
d3drm_mesh_DeleteDestroyCallback(IDirect3DRMMesh
*iface
,
2392 D3DRMOBJECTCALLBACK cb
, void *ctx
)
2394 FIXME("iface %p, cb %p, ctx %p stub!\n", iface
, cb
, ctx
);
2399 static HRESULT WINAPI
d3drm_mesh_SetAppData(IDirect3DRMMesh
*iface
, DWORD data
)
2401 FIXME("iface %p, data %#x stub!\n", iface
, data
);
2406 static DWORD WINAPI
d3drm_mesh_GetAppData(IDirect3DRMMesh
*iface
)
2408 FIXME("iface %p stub!\n", iface
);
2413 static HRESULT WINAPI
d3drm_mesh_SetName(IDirect3DRMMesh
*iface
, const char *name
)
2415 FIXME("iface %p, name %s stub!\n", iface
, debugstr_a(name
));
2420 static HRESULT WINAPI
d3drm_mesh_GetName(IDirect3DRMMesh
*iface
, DWORD
*size
, char *name
)
2422 FIXME("iface %p, size %p, name %p stub!\n", iface
, size
, name
);
2427 static HRESULT WINAPI
d3drm_mesh_GetClassName(IDirect3DRMMesh
*iface
, DWORD
*size
, char *name
)
2429 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
2431 if (!size
|| *size
< strlen("Mesh") || !name
)
2432 return E_INVALIDARG
;
2434 strcpy(name
, "Mesh");
2435 *size
= sizeof("Mesh");
2440 static HRESULT WINAPI
d3drm_mesh_Scale(IDirect3DRMMesh
*iface
,
2441 D3DVALUE sx
, D3DVALUE sy
, D3DVALUE sz
)
2443 FIXME("iface %p, sx %.8e, sy %.8e, sz %.8e stub!\n", iface
, sx
, sy
, sz
);
2448 static HRESULT WINAPI
d3drm_mesh_Translate(IDirect3DRMMesh
*iface
,
2449 D3DVALUE tx
, D3DVALUE ty
, D3DVALUE tz
)
2451 FIXME("iface %p, tx %.8e, ty %.8e, tz %.8e stub!\n", iface
, tx
, ty
, tz
);
2456 static HRESULT WINAPI
d3drm_mesh_GetBox(IDirect3DRMMesh
*iface
, D3DRMBOX
*box
)
2458 FIXME("iface %p, box %p stub!\n", iface
, box
);
2463 static HRESULT WINAPI
d3drm_mesh_AddGroup(IDirect3DRMMesh
*iface
, unsigned vertex_count
,
2464 unsigned face_count
, unsigned vertex_per_face
, unsigned *face_data
, D3DRMGROUPINDEX
*id
)
2466 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2467 struct mesh_group
*group
;
2469 TRACE("iface %p, vertex_count %u, face_count %u, vertex_per_face %u, face_data %p, id %p.\n",
2470 iface
, vertex_count
, face_count
, vertex_per_face
, face_data
, id
);
2472 if (!face_data
|| !id
)
2475 if ((mesh
->nb_groups
+ 1) > mesh
->groups_capacity
)
2477 struct mesh_group
*groups
;
2480 if (!mesh
->groups_capacity
)
2483 groups
= HeapAlloc(GetProcessHeap(), 0, new_capacity
* sizeof(*groups
));
2487 new_capacity
= mesh
->groups_capacity
* 2;
2488 groups
= HeapReAlloc(GetProcessHeap(), 0, mesh
->groups
, new_capacity
* sizeof(*groups
));
2492 return E_OUTOFMEMORY
;
2494 mesh
->groups_capacity
= new_capacity
;
2495 mesh
->groups
= groups
;
2498 group
= mesh
->groups
+ mesh
->nb_groups
;
2500 group
->vertices
= HeapAlloc(GetProcessHeap(), 0, vertex_count
* sizeof(D3DRMVERTEX
));
2501 if (!group
->vertices
)
2502 return E_OUTOFMEMORY
;
2503 group
->nb_vertices
= vertex_count
;
2504 group
->nb_faces
= face_count
;
2505 group
->vertex_per_face
= vertex_per_face
;
2507 if (vertex_per_face
)
2509 group
->face_data_size
= face_count
* vertex_per_face
;
2514 unsigned nb_indices
;
2515 unsigned* face_data_ptr
= face_data
;
2516 group
->face_data_size
= 0;
2518 for (i
= 0; i
< face_count
; i
++)
2520 nb_indices
= *face_data_ptr
;
2521 group
->face_data_size
+= nb_indices
+ 1;
2522 face_data_ptr
+= nb_indices
;
2526 group
->face_data
= HeapAlloc(GetProcessHeap(), 0, group
->face_data_size
* sizeof(unsigned));
2527 if (!group
->face_data
)
2529 HeapFree(GetProcessHeap(), 0 , group
->vertices
);
2530 return E_OUTOFMEMORY
;
2533 memcpy(group
->face_data
, face_data
, group
->face_data_size
* sizeof(unsigned));
2535 group
->material
= NULL
;
2536 group
->texture
= NULL
;
2538 *id
= mesh
->nb_groups
++;
2543 static HRESULT WINAPI
d3drm_mesh_SetVertices(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX group_id
,
2544 unsigned int start_idx
, unsigned int count
, D3DRMVERTEX
*values
)
2546 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2548 TRACE("iface %p, group_id %#x, start_idx %u, count %u, values %p.\n",
2549 iface
, group_id
, start_idx
, count
, values
);
2551 if (group_id
>= mesh
->nb_groups
)
2552 return D3DRMERR_BADVALUE
;
2554 if ((start_idx
+ count
- 1) >= mesh
->groups
[group_id
].nb_vertices
)
2555 return D3DRMERR_BADVALUE
;
2560 memcpy(mesh
->groups
[group_id
].vertices
+ start_idx
, values
, count
* sizeof(*values
));
2565 static HRESULT WINAPI
d3drm_mesh_SetGroupColor(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DCOLOR color
)
2567 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2569 TRACE("iface %p, id %#x, color 0x%08x.\n", iface
, id
, color
);
2571 if (id
>= mesh
->nb_groups
)
2572 return D3DRMERR_BADVALUE
;
2574 mesh
->groups
[id
].color
= color
;
2579 static HRESULT WINAPI
d3drm_mesh_SetGroupColorRGB(IDirect3DRMMesh
*iface
,
2580 D3DRMGROUPINDEX id
, D3DVALUE red
, D3DVALUE green
, D3DVALUE blue
)
2582 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2584 TRACE("iface %p, id %#x, red %.8e, green %.8e, blue %.8e.\n", iface
, id
, red
, green
, blue
);
2586 if (id
>= mesh
->nb_groups
)
2587 return D3DRMERR_BADVALUE
;
2589 d3drm_set_color(&mesh
->groups
[id
].color
, red
, green
, blue
, 1.0f
);
2594 static HRESULT WINAPI
d3drm_mesh_SetGroupMapping(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DRMMAPPING value
)
2596 FIXME("iface %p, id %#x, value %#x stub!\n", iface
, id
, value
);
2601 static HRESULT WINAPI
d3drm_mesh_SetGroupQuality(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, D3DRMRENDERQUALITY value
)
2603 FIXME("iface %p, id %#x, value %#x stub!\n", iface
, id
, value
);
2608 static HRESULT WINAPI
d3drm_mesh_SetGroupMaterial(IDirect3DRMMesh
*iface
,
2609 D3DRMGROUPINDEX id
, IDirect3DRMMaterial
*material
)
2611 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2613 TRACE("iface %p, id %#x, material %p.\n", iface
, id
, material
);
2615 if (id
>= mesh
->nb_groups
)
2616 return D3DRMERR_BADVALUE
;
2618 if (mesh
->groups
[id
].material
)
2619 IDirect3DRMMaterial2_Release(mesh
->groups
[id
].material
);
2621 mesh
->groups
[id
].material
= (IDirect3DRMMaterial2
*)material
;
2624 IDirect3DRMMaterial2_AddRef(mesh
->groups
[id
].material
);
2629 static HRESULT WINAPI
d3drm_mesh_SetGroupTexture(IDirect3DRMMesh
*iface
,
2630 D3DRMGROUPINDEX id
, IDirect3DRMTexture
*texture
)
2632 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2634 TRACE("iface %p, id %#x, texture %p.\n", iface
, id
, texture
);
2636 if (id
>= mesh
->nb_groups
)
2637 return D3DRMERR_BADVALUE
;
2639 if (mesh
->groups
[id
].texture
)
2640 IDirect3DRMTexture3_Release(mesh
->groups
[id
].texture
);
2644 mesh
->groups
[id
].texture
= NULL
;
2648 return IDirect3DRMTexture3_QueryInterface(texture
, &IID_IDirect3DRMTexture
, (void **)&mesh
->groups
[id
].texture
);
2651 static DWORD WINAPI
d3drm_mesh_GetGroupCount(IDirect3DRMMesh
*iface
)
2653 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2655 TRACE("iface %p.\n", iface
);
2657 return mesh
->nb_groups
;
2660 static HRESULT WINAPI
d3drm_mesh_GetGroup(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
, unsigned *vertex_count
,
2661 unsigned *face_count
, unsigned *vertex_per_face
, DWORD
*face_data_size
, unsigned *face_data
)
2663 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2665 TRACE("iface %p, id %#x, vertex_count %p, face_count %p, vertex_per_face %p, face_data_size %p, face_data %p.\n",
2666 iface
, id
, vertex_count
, face_count
, vertex_per_face
, face_data_size
,face_data
);
2668 if (id
>= mesh
->nb_groups
)
2669 return D3DRMERR_BADVALUE
;
2672 *vertex_count
= mesh
->groups
[id
].nb_vertices
;
2674 *face_count
= mesh
->groups
[id
].nb_faces
;
2675 if (vertex_per_face
)
2676 *vertex_per_face
= mesh
->groups
[id
].vertex_per_face
;
2678 *face_data_size
= mesh
->groups
[id
].face_data_size
;
2680 memcpy(face_data
, mesh
->groups
[id
].face_data
, mesh
->groups
[id
].face_data_size
* sizeof(*face_data
));
2685 static HRESULT WINAPI
d3drm_mesh_GetVertices(IDirect3DRMMesh
*iface
,
2686 D3DRMGROUPINDEX group_id
, DWORD start_idx
, DWORD count
, D3DRMVERTEX
*vertices
)
2688 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2690 TRACE("iface %p, group_id %#x, start_idx %u, count %u, vertices %p.\n",
2691 iface
, group_id
, start_idx
, count
, vertices
);
2693 if (group_id
>= mesh
->nb_groups
)
2694 return D3DRMERR_BADVALUE
;
2696 if ((start_idx
+ count
- 1) >= mesh
->groups
[group_id
].nb_vertices
)
2697 return D3DRMERR_BADVALUE
;
2702 memcpy(vertices
, mesh
->groups
[group_id
].vertices
+ start_idx
, count
* sizeof(*vertices
));
2707 static D3DCOLOR WINAPI
d3drm_mesh_GetGroupColor(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2709 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2711 TRACE("iface %p, id %#x.\n", iface
, id
);
2713 return mesh
->groups
[id
].color
;
2716 static D3DRMMAPPING WINAPI
d3drm_mesh_GetGroupMapping(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2718 FIXME("iface %p, id %#x stub!\n", iface
, id
);
2722 static D3DRMRENDERQUALITY WINAPI
d3drm_mesh_GetGroupQuality(IDirect3DRMMesh
*iface
, D3DRMGROUPINDEX id
)
2724 FIXME("iface %p, id %#x stub!\n", iface
, id
);
2729 static HRESULT WINAPI
d3drm_mesh_GetGroupMaterial(IDirect3DRMMesh
*iface
,
2730 D3DRMGROUPINDEX id
, IDirect3DRMMaterial
**material
)
2732 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2734 TRACE("iface %p, id %#x, material %p.\n", iface
, id
, material
);
2736 if (id
>= mesh
->nb_groups
)
2737 return D3DRMERR_BADVALUE
;
2742 if (mesh
->groups
[id
].material
)
2743 IDirect3DRMTexture_QueryInterface(mesh
->groups
[id
].material
, &IID_IDirect3DRMMaterial
, (void **)material
);
2750 static HRESULT WINAPI
d3drm_mesh_GetGroupTexture(IDirect3DRMMesh
*iface
,
2751 D3DRMGROUPINDEX id
, IDirect3DRMTexture
**texture
)
2753 struct d3drm_mesh
*mesh
= impl_from_IDirect3DRMMesh(iface
);
2755 TRACE("iface %p, id %#x, texture %p.\n", iface
, id
, texture
);
2757 if (id
>= mesh
->nb_groups
)
2758 return D3DRMERR_BADVALUE
;
2763 if (mesh
->groups
[id
].texture
)
2764 IDirect3DRMTexture_QueryInterface(mesh
->groups
[id
].texture
, &IID_IDirect3DRMTexture
, (void **)texture
);
2771 static const struct IDirect3DRMMeshVtbl d3drm_mesh_vtbl
=
2773 d3drm_mesh_QueryInterface
,
2777 d3drm_mesh_AddDestroyCallback
,
2778 d3drm_mesh_DeleteDestroyCallback
,
2779 d3drm_mesh_SetAppData
,
2780 d3drm_mesh_GetAppData
,
2783 d3drm_mesh_GetClassName
,
2785 d3drm_mesh_Translate
,
2787 d3drm_mesh_AddGroup
,
2788 d3drm_mesh_SetVertices
,
2789 d3drm_mesh_SetGroupColor
,
2790 d3drm_mesh_SetGroupColorRGB
,
2791 d3drm_mesh_SetGroupMapping
,
2792 d3drm_mesh_SetGroupQuality
,
2793 d3drm_mesh_SetGroupMaterial
,
2794 d3drm_mesh_SetGroupTexture
,
2795 d3drm_mesh_GetGroupCount
,
2796 d3drm_mesh_GetGroup
,
2797 d3drm_mesh_GetVertices
,
2798 d3drm_mesh_GetGroupColor
,
2799 d3drm_mesh_GetGroupMapping
,
2800 d3drm_mesh_GetGroupQuality
,
2801 d3drm_mesh_GetGroupMaterial
,
2802 d3drm_mesh_GetGroupTexture
,
2805 HRESULT
Direct3DRMMesh_create(IDirect3DRMMesh
**mesh
)
2807 struct d3drm_mesh
*object
;
2809 TRACE("mesh %p.\n", mesh
);
2811 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2812 return E_OUTOFMEMORY
;
2814 object
->IDirect3DRMMesh_iface
.lpVtbl
= &d3drm_mesh_vtbl
;
2817 *mesh
= &object
->IDirect3DRMMesh_iface
;