d3drm: Release the child object after we're done with it in load_mesh_data() (Valgrind).
[wine.git] / dlls / d3drm / meshbuilder.c
blobc24d9dc41959aef4ff24fdb36733955fd60e84d7
1 /*
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
24 #define COBJMACROS
26 #include "wine/debug.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "dxfile.h"
31 #include "rmxfguid.h"
33 #include "d3drm_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
37 struct mesh_group
39 unsigned nb_vertices;
40 D3DRMVERTEX* vertices;
41 unsigned nb_faces;
42 unsigned vertex_per_face;
43 DWORD face_data_size;
44 unsigned* face_data;
45 D3DCOLOR color;
46 IDirect3DRMMaterial2* material;
47 IDirect3DRMTexture3* texture;
50 struct d3drm_mesh
52 IDirect3DRMMesh IDirect3DRMMesh_iface;
53 LONG ref;
54 DWORD groups_capacity;
55 DWORD nb_groups;
56 struct mesh_group *groups;
59 struct coords_2d
61 D3DVALUE u;
62 D3DVALUE v;
65 struct mesh_material
67 D3DCOLOR color;
68 IDirect3DRMMaterial2 *material;
69 IDirect3DRMTexture3 *texture;
72 struct d3drm_mesh_builder
74 IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface;
75 IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface;
76 LONG ref;
77 char* name;
78 DWORD nb_vertices;
79 D3DVECTOR* pVertices;
80 DWORD nb_normals;
81 D3DVECTOR* pNormals;
82 DWORD nb_faces;
83 DWORD face_data_size;
84 void *pFaceData;
85 DWORD nb_coords2d;
86 struct coords_2d *pCoords2d;
87 D3DCOLOR color;
88 IDirect3DRMMaterial2 *material;
89 IDirect3DRMTexture3 *texture;
90 DWORD nb_materials;
91 struct mesh_material *materials;
92 DWORD *material_indices;
95 char templates[] = {
96 "xof 0302txt 0064"
97 "template Header"
98 "{"
99 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
100 "WORD major;"
101 "WORD minor;"
102 "DWORD flags;"
104 "template Vector"
106 "<3D82AB5E-62DA-11CF-AB39-0020AF71E433>"
107 "FLOAT x;"
108 "FLOAT y;"
109 "FLOAT z;"
111 "template Coords2d"
113 "<F6F23F44-7686-11CF-8F52-0040333594A3>"
114 "FLOAT u;"
115 "FLOAT v;"
117 "template Matrix4x4"
119 "<F6F23F45-7686-11CF-8F52-0040333594A3>"
120 "array FLOAT matrix[16];"
122 "template ColorRGBA"
124 "<35FF44E0-6C7C-11CF-8F52-0040333594A3>"
125 "FLOAT red;"
126 "FLOAT green;"
127 "FLOAT blue;"
128 "FLOAT alpha;"
130 "template ColorRGB"
132 "<D3E16E81-7835-11CF-8F52-0040333594A3>"
133 "FLOAT red;"
134 "FLOAT green;"
135 "FLOAT blue;"
137 "template IndexedColor"
139 "<1630B820-7842-11CF-8F52-0040333594A3>"
140 "DWORD index;"
141 "ColorRGBA indexColor;"
143 "template Boolean"
145 "<537DA6A0-CA37-11D0-941C-0080C80CFA7B>"
146 "DWORD truefalse;"
148 "template Boolean2d"
150 "<4885AE63-78E8-11CF-8F52-0040333594A3>"
151 "Boolean u;"
152 "Boolean v;"
154 "template MaterialWrap"
156 "<4885AE60-78E8-11CF-8F52-0040333594A3>"
157 "Boolean u;"
158 "Boolean v;"
160 "template TextureFilename"
162 "<A42790E1-7810-11CF-8F52-0040333594A3>"
163 "STRING filename;"
165 "template Material"
167 "<3D82AB4D-62DA-11CF-AB39-0020AF71E433>"
168 "ColorRGBA faceColor;"
169 "FLOAT power;"
170 "ColorRGB specularColor;"
171 "ColorRGB emissiveColor;"
172 "[...]"
174 "template MeshFace"
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>"
195 "DWORD nMaterials;"
196 "DWORD nFaceIndexes;"
197 "array DWORD faceIndexes[nFaceIndexes];"
198 "[Material]"
200 "template MeshNormals"
202 "<F6F23F43-7686-11CF-8F52-0040333594A3>"
203 "DWORD nNormals;"
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];"
214 "template Mesh"
216 "<3D82AB44-62DA-11CF-AB39-0020AF71E433>"
217 "DWORD nVertices;"
218 "array Vector vertices[nVertices];"
219 "DWORD nFaces;"
220 "array MeshFace faces[nFaces];"
221 "[...]"
223 "template FrameTransformMatrix"
225 "<F6F23F41-7686-11CF-8F52-0040333594A3>"
226 "Matrix4x4 frameMatrix;"
228 "template Frame"
230 "<3D82AB46-62DA-11CF-AB39-0020AF71E433>"
231 "[...]"
233 "template FloatKeys"
235 "<10DD46A9-775B-11CF-8F52-0040333594A3>"
236 "DWORD nValues;"
237 "array FLOAT values[nValues];"
239 "template TimedFloatKeys"
241 "<F406B180-7B3B-11CF-8F52-0040333594A3>"
242 "DWORD time;"
243 "FloatKeys tfkeys;"
245 "template AnimationKey"
247 "<10DD46A8-775B-11CF-8F52-0040333594A3>"
248 "DWORD keyType;"
249 "DWORD nKeys;"
250 "array TimedFloatKeys keys[nKeys];"
252 "template AnimationOptions"
254 "<E2BF56C0-840F-11CF-8F52-0040333594A3>"
255 "DWORD openclosed;"
256 "DWORD positionquality;"
258 "template Animation"
260 "<3D82AB4F-62DA-11CF-AB39-0020AF71E433>"
261 "[...]"
263 "template AnimationSet"
265 "<3D82AB50-62DA-11CF-AB39-0020AF71E433>"
266 "[Animation]"
268 "template InlineData"
270 "<3A23EEA0-94B1-11D0-AB39-0020AF71E433>"
271 "[BINARY]"
273 "template Url"
275 "<3A23EEA1-94B1-11D0-AB39-0020AF71E433>"
276 "DWORD nUrls;"
277 "array STRING urls[nUrls];"
279 "template ProgressiveMesh"
281 "<8A63C360-997D-11D0-941C-0080C80CFA7B>"
282 "[Url,InlineData]"
284 "template Guid"
286 "<A42790E0-7810-11CF-8F52-0040333594A3>"
287 "DWORD data1;"
288 "WORD data2;"
289 "WORD data3;"
290 "array UCHAR data4[8];"
292 "template StringProperty"
294 "<7F0F21E0-BFE1-11D1-82C0-00A0C9697271>"
295 "STRING key;"
296 "STRING value;"
298 "template PropertyBag"
300 "<7F0F21E1-BFE1-11D1-82C0-00A0C9697271>"
301 "[StringProperty]"
303 "template ExternalVisual"
305 "<98116AA0-BDBA-11D1-82C0-00A0C9697271>"
306 "Guid guidExternalVisual;"
307 "[...]"
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)
333 DWORD i;
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;
380 else
382 *out = NULL;
383 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
384 return E_NOINTERFACE;
387 IUnknown_AddRef((IUnknown *)*out);
388 return S_OK;
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);
398 return 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);
408 if (!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);
418 return refcount;
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);
426 return E_NOTIMPL;
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);
434 return E_NOTIMPL;
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);
442 return E_NOTIMPL;
445 static HRESULT WINAPI d3drm_mesh_builder2_SetAppData(IDirect3DRMMeshBuilder2 *iface, DWORD data)
447 FIXME("iface %p, data %#x stub!\n", iface, data);
449 return E_NOTIMPL;
452 static DWORD WINAPI d3drm_mesh_builder2_GetAppData(IDirect3DRMMeshBuilder2 *iface)
454 FIXME("iface %p stub!\n", iface);
456 return 0;
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);
494 if (cb)
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);
507 return E_NOTIMPL;
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);
525 return E_NOTIMPL;
528 static HRESULT WINAPI d3drm_mesh_builder2_SetColorSource(IDirect3DRMMeshBuilder2 *iface, D3DRMCOLORSOURCE source)
530 FIXME("iface %p, source %#x stub!\n", iface, source);
532 return E_NOTIMPL;
535 static HRESULT WINAPI d3drm_mesh_builder2_GetBox(IDirect3DRMMeshBuilder2 *iface, D3DRMBOX *box)
537 FIXME("iface %p, box %p stub!\n", iface, box);
539 return E_NOTIMPL;
542 static HRESULT WINAPI d3drm_mesh_builder2_GenerateNormals(IDirect3DRMMeshBuilder2 *iface)
544 FIXME("iface %p stub!\n", iface);
546 return E_NOTIMPL;
549 static D3DRMCOLORSOURCE WINAPI d3drm_mesh_builder2_GetColorSource(IDirect3DRMMeshBuilder2 *iface)
551 FIXME("iface %p stub!\n", iface);
553 return E_NOTIMPL;
556 static HRESULT WINAPI d3drm_mesh_builder2_AddMesh(IDirect3DRMMeshBuilder2 *iface, IDirect3DRMMesh *mesh)
558 FIXME("iface %p, mesh %p stub!\n", iface, mesh);
560 return E_NOTIMPL;
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);
568 return E_NOTIMPL;
571 static HRESULT WINAPI d3drm_mesh_builder2_AddFrame(IDirect3DRMMeshBuilder2 *iface, IDirect3DRMFrame *frame)
573 FIXME("iface %p, frame %p stub!\n", iface, frame);
575 return E_NOTIMPL;
578 static HRESULT WINAPI d3drm_mesh_builder2_AddFace(IDirect3DRMMeshBuilder2 *iface, IDirect3DRMFace *face)
580 FIXME("iface %p, face %p stub!\n", iface, face);
582 return E_NOTIMPL;
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);
592 return E_NOTIMPL;
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);
601 return E_NOTIMPL;
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);
632 if (texture)
633 hr = IDirect3DRMTexture_QueryInterface(texture, &IID_IDirect3DRMTexture3, (void **)&texture3);
634 if (SUCCEEDED(hr))
635 hr = IDirect3DRMMeshBuilder3_SetTexture(&mesh_builder->IDirect3DRMMeshBuilder3_iface, texture3);
636 if (texture3)
637 IDirect3DRMTexture3_Release(texture3);
639 return hr;
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);
658 return E_NOTIMPL;
661 static HRESULT WINAPI d3drm_mesh_builder2_SetQuality(IDirect3DRMMeshBuilder2 *iface,
662 D3DRMRENDERQUALITY quality)
664 FIXME("iface %p, quality %#x stub!\n", iface, quality);
666 return E_NOTIMPL;
669 static HRESULT WINAPI d3drm_mesh_builder2_SetPerspective(IDirect3DRMMeshBuilder2 *iface, BOOL enable)
671 FIXME("iface %p, enable %#x stub!\n", iface, enable);
673 return E_NOTIMPL;
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);
681 return E_NOTIMPL;
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);
689 return E_NOTIMPL;
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,
700 index, u, v);
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);
708 return E_NOTIMPL;
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);
717 return E_NOTIMPL;
720 static HRESULT WINAPI d3drm_mesh_builder2_GetFaces(IDirect3DRMMeshBuilder2 *iface,
721 IDirect3DRMFaceArray **array)
723 FIXME("iface %p, array %p stub!\n", iface, array);
725 return E_NOTIMPL;
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;
739 if (vertex_count)
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;
746 if (normal_count)
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;
753 if (face_data_size)
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));
758 return D3DRM_OK;
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,
769 index, u, v);
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);
777 return 0;
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);
785 return 0;
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);
799 return 0;
802 static BOOL WINAPI d3drm_mesh_builder2_GetPerspective(IDirect3DRMMeshBuilder2 *iface)
804 FIXME("iface %p stub!\n", iface);
806 return FALSE;
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);
831 return 0;
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);
848 return E_NOTIMPL;
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);
856 return E_NOTIMPL;
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);
946 return E_NOTIMPL;
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);
954 return E_NOTIMPL;
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);
962 return E_NOTIMPL;
965 static HRESULT WINAPI d3drm_mesh_builder3_SetAppData(IDirect3DRMMeshBuilder3 *iface, DWORD data)
967 FIXME("iface %p, data %#x stub!\n", iface, data);
969 return E_NOTIMPL;
972 static DWORD WINAPI d3drm_mesh_builder3_GetAppData(IDirect3DRMMeshBuilder3 *iface)
974 FIXME("iface %p stub!\n", iface);
976 return 0;
979 static HRESULT WINAPI d3drm_mesh_builder3_SetName(IDirect3DRMMeshBuilder3 *iface, const char *name)
981 struct d3drm_mesh_builder *mesh_builder = impl_from_IDirect3DRMMeshBuilder3(iface);
982 char *string = NULL;
984 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
986 if (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;
995 return D3DRM_OK;
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);
1005 if (!size)
1006 return E_POINTER;
1008 if (!mesh_builder->name)
1010 *size = 0;
1011 return D3DRM_OK;
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;
1020 return D3DRM_OK;
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");
1034 return D3DRM_OK;
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;
1042 const GUID* guid;
1043 DWORD size;
1044 BYTE *ptr;
1045 HRESULT hr;
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;
1054 DWORD i;
1056 TRACE("(%p)->(%p)\n", This, pData);
1058 hr = IDirectXFileData_GetName(pData, NULL, &size);
1059 if (hr != DXFILE_OK)
1060 return hr;
1061 if (size)
1063 This->name = HeapAlloc(GetProcessHeap(), 0, size);
1064 if (!This->name)
1065 return E_OUTOFMEMORY;
1067 hr = IDirectXFileData_GetName(pData, This->name, &size);
1068 if (hr != DXFILE_OK)
1069 return hr;
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)
1078 goto end;
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;
1096 while (1)
1098 IDirectXFileObject *object;
1100 hr = IDirectXFileData_GetNextObject(pData, &object);
1101 if (hr == DXFILEERR_NOMOREOBJECTS)
1103 TRACE("No more object\n");
1104 break;
1106 if (hr != DXFILE_OK)
1107 goto end;
1109 hr = IDirectXFileObject_QueryInterface(object, &IID_IDirectXFileData, (void**)&pData2);
1110 IDirectXFileObject_Release(object);
1111 if (hr != DXFILE_OK)
1112 goto end;
1114 hr = IDirectXFileData_GetType(pData2, &guid);
1115 if (hr != DXFILE_OK)
1116 goto end;
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)
1127 goto end;
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)
1147 goto end;
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))
1159 DWORD nb_materials;
1160 DWORD nb_face_indices;
1161 DWORD data_size;
1162 IDirectXFileObject *child;
1163 DWORD i = 0;
1164 float* values;
1166 TRACE("Process MeshMaterialList\n");
1168 hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1169 if (hr != DXFILE_OK)
1170 goto end;
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)
1183 goto end;
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);
1190 goto end;
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);
1201 if (FAILED(hr))
1203 hr = IDirectXFileObject_QueryInterface(child, &IID_IDirectXFileDataReference, (void **)&reference);
1204 IDirectXFileObject_Release(child);
1205 if (FAILED(hr))
1206 goto end;
1208 hr = IDirectXFileDataReference_Resolve(reference, &data);
1209 IDirectXFileDataReference_Release(reference);
1210 if (FAILED(hr))
1211 goto end;
1213 else
1215 IDirectXFileObject_Release(child);
1218 hr = Direct3DRMMaterial_create(&This->materials[i].material);
1219 if (FAILED(hr))
1221 IDirectXFileData_Release(data);
1222 goto end;
1225 hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&ptr);
1226 if (hr != DXFILE_OK)
1228 IDirectXFileData_Release(data);
1229 goto end;
1232 if (size != 44)
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);
1248 if (hr == S_OK)
1250 IDirectXFileData *data;
1251 char **filename;
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);
1266 if (FAILED(hr))
1267 goto end;
1269 hr = IDirectXFileData_GetType(data, &guid);
1270 if (hr != DXFILE_OK)
1271 goto end;
1272 if (!IsEqualGUID(guid, &TID_D3DRMTextureFilename))
1274 WARN("Not a texture filename\n");
1275 goto end;
1278 size = 4;
1279 hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&filename);
1280 if (SUCCEEDED(hr))
1282 if (load_texture_proc)
1284 IDirect3DRMTexture *texture;
1286 hr = load_texture_proc(*filename, arg, &texture);
1287 if (SUCCEEDED(hr))
1289 hr = IDirect3DTexture_QueryInterface(texture, &IID_IDirect3DRMTexture3, (void**)&This->materials[i].texture);
1290 IDirect3DTexture_Release(texture);
1293 else
1295 HANDLE file;
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)
1301 CloseHandle(file);
1303 hr = Direct3DRMTexture_create(&IID_IDirect3DRMTexture3, (IUnknown**)&This->materials[i].texture);
1304 if (FAILED(hr))
1306 IDirectXFileData_Release(data);
1307 goto end;
1312 IDirectXFileData_Release(data);
1314 else if (hr != DXFILEERR_NOMOREOBJECTS)
1316 goto end;
1318 hr = S_OK;
1320 IDirectXFileData_Release(data);
1321 i++;
1323 if (hr == S_OK)
1325 IDirectXFileObject_Release(child);
1326 WARN("Found more sub-objects than expected\n");
1328 else if (hr != DXFILEERR_NOMOREOBJECTS)
1330 goto end;
1332 hr = S_OK;
1334 else
1336 FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(guid));
1339 IDirectXFileData_Release(pData2);
1340 pData2 = NULL;
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)
1348 goto end;
1351 for (i = 0; i < This->nb_faces; i++)
1353 DWORD j;
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)
1373 D3DVECTOR a, b;
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);
1380 else
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++);
1398 else
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);
1404 vertex_idx = 0;
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");
1445 ret = D3DRM_OK;
1447 end:
1449 HeapFree(GetProcessHeap(), 0, faces_normal_idx_data);
1450 HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data);
1452 return ret;
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;
1463 const GUID* guid;
1464 DWORD size;
1465 struct d3drm_file_header *header;
1466 HRESULT hr;
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));
1483 else
1485 FIXME("Load options %d not supported yet\n", loadflags);
1486 return E_NOTIMPL;
1489 hr = DirectXFileCreate(&dxfile);
1490 if (hr != DXFILE_OK)
1491 goto end;
1493 hr = IDirectXFile_RegisterTemplates(dxfile, templates, strlen(templates));
1494 if (hr != DXFILE_OK)
1495 goto end;
1497 hr = IDirectXFile_CreateEnumObject(dxfile, filename, load_options, &enum_object);
1498 if (hr != DXFILE_OK)
1499 goto end;
1501 hr = IDirectXFileEnumObject_GetNextDataObject(enum_object, &data);
1502 if (hr != DXFILE_OK)
1503 goto end;
1505 hr = IDirectXFileData_GetType(data, &guid);
1506 if (hr != DXFILE_OK)
1507 goto end;
1509 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid));
1511 if (!IsEqualGUID(guid, &TID_DXFILEHeader))
1513 ret = D3DRMERR_BADFILE;
1514 goto end;
1517 hr = IDirectXFileData_GetData(data, NULL, &size, (void**)&header);
1518 if ((hr != DXFILE_OK) || (size != sizeof(*header)))
1519 goto end;
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;
1527 goto end;
1530 IDirectXFileData_Release(data);
1531 data = NULL;
1533 hr = IDirectXFileEnumObject_GetNextDataObject(enum_object, &data);
1534 if (hr != DXFILE_OK)
1536 ret = D3DRMERR_NOTFOUND;
1537 goto end;
1540 hr = IDirectXFileData_GetType(data, &guid);
1541 if (hr != DXFILE_OK)
1542 goto end;
1544 TRACE("Found object type whose GUID = %s\n", debugstr_guid(guid));
1546 if (!IsEqualGUID(guid, &TID_D3DRMMesh))
1548 ret = D3DRMERR_NOTFOUND;
1549 goto end;
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);
1554 if (hr == S_OK)
1555 ret = D3DRM_OK;
1557 end:
1559 if (data)
1560 IDirectXFileData_Release(data);
1561 if (enum_object)
1562 IDirectXFileEnumObject_Release(enum_object);
1563 if (dxfile)
1564 IDirectXFile_Release(dxfile);
1566 if (ret != D3DRM_OK)
1567 clean_mesh_builder_data(mesh_builder);
1569 return ret;
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);
1578 return E_NOTIMPL;
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);
1585 DWORD i;
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 */
1598 return D3DRM_OK;
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);
1606 return E_NOTIMPL;
1609 static HRESULT WINAPI d3drm_mesh_builder3_SetColorSource(IDirect3DRMMeshBuilder3 *iface,
1610 D3DRMCOLORSOURCE source)
1612 FIXME("iface %p, source %#x stub!\n", iface, source);
1614 return E_NOTIMPL;
1617 static HRESULT WINAPI d3drm_mesh_builder3_GetBox(IDirect3DRMMeshBuilder3 *iface, D3DRMBOX *box)
1619 FIXME("iface %p, box %p stub!\n", iface, box);
1621 return E_NOTIMPL;
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);
1629 return E_NOTIMPL;
1632 static D3DRMCOLORSOURCE WINAPI d3drm_mesh_builder3_GetColorSource(IDirect3DRMMeshBuilder3 *iface)
1634 FIXME("iface %p stub!\n", iface);
1636 return E_NOTIMPL;
1639 static HRESULT WINAPI d3drm_mesh_builder3_AddMesh(IDirect3DRMMeshBuilder3 *iface, IDirect3DRMMesh *mesh)
1641 FIXME("iface %p, mesh %p stub!\n", iface, mesh);
1643 return E_NOTIMPL;
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);
1651 return E_NOTIMPL;
1654 static HRESULT WINAPI d3drm_mesh_builder3_AddFrame(IDirect3DRMMeshBuilder3 *iface, IDirect3DRMFrame3 *frame)
1656 FIXME("iface %p, frame %p stub!\n", iface, frame);
1658 return E_NOTIMPL;
1661 static HRESULT WINAPI d3drm_mesh_builder3_AddFace(IDirect3DRMMeshBuilder3 *iface, IDirect3DRMFace2 *face)
1663 FIXME("iface %p, face %p stub!\n", iface, face);
1665 return E_NOTIMPL;
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);
1675 return E_NOTIMPL;
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);
1684 return E_NOTIMPL;
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);
1696 return D3DRM_OK;
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;
1707 return D3DRM_OK;
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);
1717 if (texture)
1718 IDirect3DRMTexture3_AddRef(texture);
1719 if (mesh_builder->texture)
1720 IDirect3DRMTexture3_Release(mesh_builder->texture);
1721 mesh_builder->texture = texture;
1723 return D3DRM_OK;
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);
1733 if (material)
1734 IDirect3DRMTexture2_AddRef(material);
1735 if (mesh_builder->material)
1736 IDirect3DRMTexture2_Release(mesh_builder->material);
1737 mesh_builder->material = material;
1739 return D3DRM_OK;
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);
1747 return E_NOTIMPL;
1750 static HRESULT WINAPI d3drm_mesh_builder3_SetQuality(IDirect3DRMMeshBuilder3 *iface,
1751 D3DRMRENDERQUALITY quality)
1753 FIXME("iface %p, quality %#x stub!\n", iface, quality);
1755 return E_NOTIMPL;
1758 static HRESULT WINAPI d3drm_mesh_builder3_SetPerspective(IDirect3DRMMeshBuilder3 *iface,
1759 BOOL enable)
1761 FIXME("iface %p, enable %#x stub!\n", iface, enable);
1763 return E_NOTIMPL;
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);
1771 return E_NOTIMPL;
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);
1779 return E_NOTIMPL;
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;
1795 return D3DRM_OK;
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);
1803 return E_NOTIMPL;
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);
1812 return E_NOTIMPL;
1815 static HRESULT WINAPI d3drm_mesh_builder3_GetFaces(IDirect3DRMMeshBuilder3 *iface,
1816 IDirect3DRMFaceArray **array)
1818 FIXME("iface %p, array %p stub!\n", iface, array);
1820 return E_NOTIMPL;
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);
1831 return E_NOTIMPL;
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;
1847 return D3DRM_OK;
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);
1855 return 0;
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);
1863 return 0;
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);
1877 return 0;
1880 static BOOL WINAPI d3drm_mesh_builder3_GetPerspective(IDirect3DRMMeshBuilder3 *iface)
1882 FIXME("iface %p stub!\n", iface);
1884 return FALSE;
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,
1906 DWORD index)
1908 FIXME("iface %p, index %u stub!\n", iface, index);
1910 return 0;
1913 static HRESULT WINAPI d3drm_mesh_builder3_CreateMesh(IDirect3DRMMeshBuilder3 *iface, IDirect3DRMMesh **mesh)
1915 struct d3drm_mesh_builder *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1916 HRESULT hr;
1917 D3DRMGROUPINDEX group;
1919 TRACE("iface %p, mesh %p.\n", iface, mesh);
1921 if (!mesh)
1922 return E_POINTER;
1924 hr = Direct3DRMMesh_create(mesh);
1925 if (FAILED(hr))
1926 return hr;
1928 /* If there is mesh data, create a group and put data inside */
1929 if (This->nb_vertices)
1931 DWORD i, j;
1932 int k;
1933 D3DRMVERTEX* vertices;
1935 vertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DRMVERTEX));
1936 if (!vertices)
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;
1950 unsigned* out_ptr;
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));
1958 if (!used_vertices)
1960 IDirect3DRMMesh_Release(*mesh);
1961 return E_OUTOFMEMORY;
1964 face_data = HeapAlloc(GetProcessHeap(), 0, This->face_data_size * sizeof(*face_data));
1965 if (!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))
1980 break;
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;
1998 continue;
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 */
2010 in_ptr++;
2013 nb_faces++;
2016 for (i = 0; i < This->nb_vertices; i++)
2017 if (used_vertices[i])
2018 nb_vertices++;
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);
2023 if (SUCCEEDED(hr))
2024 hr = IDirect3DRMMesh_SetGroupColor(*mesh, group, This->materials[k].color);
2025 if (SUCCEEDED(hr))
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);
2037 if (FAILED(hr))
2039 IDirect3DRMMesh_Release(*mesh);
2040 return hr;
2045 return D3DRM_OK;
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);
2053 return E_NOTIMPL;
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);
2061 return E_NOTIMPL;
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);
2069 return E_NOTIMPL;
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);
2077 return E_NOTIMPL;
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);
2085 return E_NOTIMPL;
2088 static HRESULT WINAPI d3drm_mesh_builder3_DeleteFace(IDirect3DRMMeshBuilder3 *iface, IDirect3DRMFace2 *face)
2090 FIXME("iface %p, face %p stub!\n", iface, face);
2092 return E_NOTIMPL;
2095 static HRESULT WINAPI d3drm_mesh_builder3_Empty(IDirect3DRMMeshBuilder3 *iface, DWORD flags)
2097 FIXME("iface %p, flags %#x stub!\n", iface, flags);
2099 return E_NOTIMPL;
2102 static HRESULT WINAPI d3drm_mesh_builder3_Optimize(IDirect3DRMMeshBuilder3 *iface, DWORD flags)
2104 FIXME("iface %p, flags %#x stub!\n", iface, flags);
2106 return E_NOTIMPL;
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);
2115 return E_NOTIMPL;
2118 static HRESULT WINAPI d3drm_mesh_builder3_CreateSubMesh(IDirect3DRMMeshBuilder3 *iface, IUnknown **mesh)
2120 FIXME("iface %p, mesh %p stub!\n", iface, mesh);
2122 return E_NOTIMPL;
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);
2130 return E_NOTIMPL;
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);
2138 return E_NOTIMPL;
2141 static HRESULT WINAPI d3drm_mesh_builder3_DeleteSubMesh(IDirect3DRMMeshBuilder3 *iface, IUnknown *mesh)
2143 FIXME("iface %p, mesh %p stub!\n", iface, mesh);
2145 return E_NOTIMPL;
2148 static HRESULT WINAPI d3drm_mesh_builder3_Enable(IDirect3DRMMeshBuilder3 *iface, DWORD index)
2150 FIXME("iface %p, index %u stub!\n", iface, index);
2152 return E_NOTIMPL;
2155 static HRESULT WINAPI d3drm_mesh_builder3_GetEnable(IDirect3DRMMeshBuilder3 *iface, DWORD *indices)
2157 FIXME("iface %p, indices %p stub!\n", iface, indices);
2159 return E_NOTIMPL;
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);
2168 return E_NOTIMPL;
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);
2176 return E_NOTIMPL;
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);
2188 if (vertex_count)
2189 *vertex_count = count;
2190 if (vertices && mesh_builder->nb_vertices)
2191 memcpy(vertices, mesh_builder->pVertices + start_idx, count * sizeof(*vertices));
2193 return D3DRM_OK;
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);
2202 return E_NOTIMPL;
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);
2214 if (normal_count)
2215 *normal_count = count;
2216 if (normals && mesh_builder->nb_normals)
2217 memcpy(normals, mesh_builder->pNormals + start_idx, count * sizeof(*normals));
2219 return D3DRM_OK;
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;
2316 object->ref = 1;
2318 if (IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
2319 *out = (IUnknown *)&object->IDirect3DRMMeshBuilder3_iface;
2320 else
2321 *out = (IUnknown *)&object->IDirect3DRMMeshBuilder2_iface;
2323 return S_OK;
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);
2334 *out = iface;
2335 return S_OK;
2338 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
2340 *out = NULL;
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);
2351 return 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);
2361 if (!refcount)
2363 DWORD i;
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);
2378 return refcount;
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);
2386 return E_NOTIMPL;
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);
2394 return E_NOTIMPL;
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);
2402 return E_NOTIMPL;
2405 static HRESULT WINAPI d3drm_mesh_SetAppData(IDirect3DRMMesh *iface, DWORD data)
2407 FIXME("iface %p, data %#x stub!\n", iface, data);
2409 return E_NOTIMPL;
2412 static DWORD WINAPI d3drm_mesh_GetAppData(IDirect3DRMMesh *iface)
2414 FIXME("iface %p stub!\n", iface);
2416 return 0;
2419 static HRESULT WINAPI d3drm_mesh_SetName(IDirect3DRMMesh *iface, const char *name)
2421 FIXME("iface %p, name %s stub!\n", iface, debugstr_a(name));
2423 return E_NOTIMPL;
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);
2430 return E_NOTIMPL;
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");
2443 return D3DRM_OK;
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);
2451 return E_NOTIMPL;
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);
2459 return E_NOTIMPL;
2462 static HRESULT WINAPI d3drm_mesh_GetBox(IDirect3DRMMesh *iface, D3DRMBOX *box)
2464 FIXME("iface %p, box %p stub!\n", iface, box);
2466 return E_NOTIMPL;
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)
2479 return E_POINTER;
2481 if ((mesh->nb_groups + 1) > mesh->groups_capacity)
2483 struct mesh_group *groups;
2484 ULONG new_capacity;
2486 if (!mesh->groups_capacity)
2488 new_capacity = 16;
2489 groups = HeapAlloc(GetProcessHeap(), 0, new_capacity * sizeof(*groups));
2491 else
2493 new_capacity = mesh->groups_capacity * 2;
2494 groups = HeapReAlloc(GetProcessHeap(), 0, mesh->groups, new_capacity * sizeof(*groups));
2497 if (!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;
2517 else
2519 unsigned i;
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++;
2546 return D3DRM_OK;
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;
2563 if (!values)
2564 return E_POINTER;
2566 memcpy(mesh->groups[group_id].vertices + start_idx, values, count * sizeof(*values));
2568 return D3DRM_OK;
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;
2582 return D3DRM_OK;
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);
2597 return D3DRM_OK;
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);
2604 return E_NOTIMPL;
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);
2611 return E_NOTIMPL;
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;
2629 if (material)
2630 IDirect3DRMMaterial2_AddRef(mesh->groups[id].material);
2632 return D3DRM_OK;
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);
2648 if (!texture)
2650 mesh->groups[id].texture = NULL;
2651 return D3DRM_OK;
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;
2677 if (vertex_count)
2678 *vertex_count = mesh->groups[id].nb_vertices;
2679 if (face_count)
2680 *face_count = mesh->groups[id].nb_faces;
2681 if (vertex_per_face)
2682 *vertex_per_face = mesh->groups[id].vertex_per_face;
2683 if (face_data_size)
2684 *face_data_size = mesh->groups[id].face_data_size;
2685 if (face_data)
2686 memcpy(face_data, mesh->groups[id].face_data, mesh->groups[id].face_data_size * sizeof(*face_data));
2688 return D3DRM_OK;
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;
2705 if (!vertices)
2706 return E_POINTER;
2708 memcpy(vertices, mesh->groups[group_id].vertices + start_idx, count * sizeof(*vertices));
2710 return D3DRM_OK;
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);
2726 return 0;
2728 static D3DRMRENDERQUALITY WINAPI d3drm_mesh_GetGroupQuality(IDirect3DRMMesh *iface, D3DRMGROUPINDEX id)
2730 FIXME("iface %p, id %#x stub!\n", iface, id);
2732 return 0;
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;
2745 if (!material)
2746 return E_POINTER;
2748 if (mesh->groups[id].material)
2749 IDirect3DRMTexture_QueryInterface(mesh->groups[id].material, &IID_IDirect3DRMMaterial, (void **)material);
2750 else
2751 *material = NULL;
2753 return D3DRM_OK;
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;
2766 if (!texture)
2767 return E_POINTER;
2769 if (mesh->groups[id].texture)
2770 IDirect3DRMTexture_QueryInterface(mesh->groups[id].texture, &IID_IDirect3DRMTexture, (void **)texture);
2771 else
2772 *texture = NULL;
2774 return D3DRM_OK;
2777 static const struct IDirect3DRMMeshVtbl d3drm_mesh_vtbl =
2779 d3drm_mesh_QueryInterface,
2780 d3drm_mesh_AddRef,
2781 d3drm_mesh_Release,
2782 d3drm_mesh_Clone,
2783 d3drm_mesh_AddDestroyCallback,
2784 d3drm_mesh_DeleteDestroyCallback,
2785 d3drm_mesh_SetAppData,
2786 d3drm_mesh_GetAppData,
2787 d3drm_mesh_SetName,
2788 d3drm_mesh_GetName,
2789 d3drm_mesh_GetClassName,
2790 d3drm_mesh_Scale,
2791 d3drm_mesh_Translate,
2792 d3drm_mesh_GetBox,
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;
2821 object->ref = 1;
2823 *mesh = &object->IDirect3DRMMesh_iface;
2825 return S_OK;