kernel32: Fix buffer overflows in K32GetModuleFileNameExA/W.
[wine] / dlls / d3drm / meshbuilder.c
1 /*
2  * Implementation of IDirect3DRMMeshBuilder2 Interface
3  *
4  * Copyright 2010, 2012 Christian Costa
5  * Copyright 2011 AndrĂ© Hentschel
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "wine/debug.h"
23
24 #define COBJMACROS
25
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "dxfile.h"
29 #include "rmxfguid.h"
30
31 #include "d3drm_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
34
35 static HRESULT Direct3DRMMesh_create(IDirect3DRMMesh** obj);
36
37 typedef struct {
38     IDirect3DRMMesh IDirect3DRMMesh_iface;
39     LONG ref;
40 } IDirect3DRMMeshImpl;
41
42 typedef struct {
43     D3DVALUE u;
44     D3DVALUE v;
45 } Coords2d;
46
47 typedef struct {
48     IDirect3DRMMeshBuilder2 IDirect3DRMMeshBuilder2_iface;
49     IDirect3DRMMeshBuilder3 IDirect3DRMMeshBuilder3_iface;
50     LONG ref;
51     DWORD nb_vertices;
52     D3DVECTOR* pVertices;
53     DWORD nb_normals;
54     D3DVECTOR* pNormals;
55     DWORD nb_faces;
56     DWORD face_data_size;
57     LPVOID pFaceData;
58     DWORD nb_coords2d;
59     Coords2d* pCoords2d;
60 } IDirect3DRMMeshBuilderImpl;
61
62 char templates[] = {
63 "xof 0302txt 0064"
64 "template Header"
65 "{"
66 "<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
67 "WORD major;"
68 "WORD minor;"
69 "DWORD flags;"
70 "}"
71 "template Vector"
72 "{"
73 "<3D82AB5E-62DA-11CF-AB39-0020AF71E433>"
74 "FLOAT x;"
75 "FLOAT y;"
76 "FLOAT z;"
77 "}"
78 "template Coords2d"
79 "{"
80 "<F6F23F44-7686-11CF-8F52-0040333594A3>"
81 "FLOAT u;"
82 "FLOAT v;"
83 "}"
84 "template Matrix4x4"
85 "{"
86 "<F6F23F45-7686-11CF-8F52-0040333594A3>"
87 "array FLOAT matrix[16];"
88 "}"
89 "template ColorRGBA"
90 "{"
91 "<35FF44E0-6C7C-11CF-8F52-0040333594A3>"
92 "FLOAT red;"
93 "FLOAT green;"
94 "FLOAT blue;"
95 "FLOAT alpha;"
96 "}"
97 "template ColorRGB"
98 "{"
99 "<D3E16E81-7835-11CF-8F52-0040333594A3>"
100 "FLOAT red;"
101 "FLOAT green;"
102 "FLOAT blue;"
103 "}"
104 "template IndexedColor"
105 "{"
106 "<1630B820-7842-11CF-8F52-0040333594A3>"
107 "DWORD index;"
108 "ColorRGBA indexColor;"
109 "}"
110 "template Boolean"
111 "{"
112 "<537DA6A0-CA37-11D0-941C-0080C80CFA7B>"
113 "DWORD truefalse;"
114 "}"
115 "template Boolean2d"
116 "{"
117 "<4885AE63-78E8-11CF-8F52-0040333594A3>"
118 "Boolean u;"
119 "Boolean v;"
120 "}"
121 "template MaterialWrap"
122 "{"
123 "<4885AE60-78E8-11CF-8F52-0040333594A3>"
124 "Boolean u;"
125 "Boolean v;"
126 "}"
127 "template TextureFilename"
128 "{"
129 "<A42790E1-7810-11CF-8F52-0040333594A3>"
130 "STRING filename;"
131 "}"
132 "template Material"
133 "{"
134 "<3D82AB4D-62DA-11CF-AB39-0020AF71E433>"
135 "ColorRGBA faceColor;"
136 "FLOAT power;"
137 "ColorRGB specularColor;"
138 "ColorRGB emissiveColor;"
139 "[...]"
140 "}"
141 "template MeshFace"
142 "{"
143 "<3D82AB5F-62DA-11CF-AB39-0020AF71E433>"
144 "DWORD nFaceVertexIndices;"
145 "array DWORD faceVertexIndices[nFaceVertexIndices];"
146 "}"
147 "template MeshFaceWraps"
148 "{"
149 "<ED1EC5C0-C0A8-11D0-941C-0080C80CFA7B>"
150 "DWORD nFaceWrapValues;"
151 "array Boolean2d faceWrapValues[nFaceWrapValues];"
152 "}"
153 "template MeshTextureCoords"
154 "{"
155 "<F6F23F40-7686-11CF-8F52-0040333594A3>"
156 "DWORD nTextureCoords;"
157 "array Coords2d textureCoords[nTextureCoords];"
158 "}"
159 "template MeshMaterialList"
160 "{"
161 "<F6F23F42-7686-11CF-8F52-0040333594A3>"
162 "DWORD nMaterials;"
163 "DWORD nFaceIndexes;"
164 "array DWORD faceIndexes[nFaceIndexes];"
165 "[Material]"
166 "}"
167 "template MeshNormals"
168 "{"
169 "<F6F23F43-7686-11CF-8F52-0040333594A3>"
170 "DWORD nNormals;"
171 "array Vector normals[nNormals];"
172 "DWORD nFaceNormals;"
173 "array MeshFace faceNormals[nFaceNormals];"
174 "}"
175 "template MeshVertexColors"
176 "{"
177 "<1630B821-7842-11CF-8F52-0040333594A3>"
178 "DWORD nVertexColors;"
179 "array IndexedColor vertexColors[nVertexColors];"
180 "}"
181 "template Mesh"
182 "{"
183 "<3D82AB44-62DA-11CF-AB39-0020AF71E433>"
184 "DWORD nVertices;"
185 "array Vector vertices[nVertices];"
186 "DWORD nFaces;"
187 "array MeshFace faces[nFaces];"
188 "[...]"
189 "}"
190 "template FrameTransformMatrix"
191 "{"
192 "<F6F23F41-7686-11CF-8F52-0040333594A3>"
193 "Matrix4x4 frameMatrix;"
194 "}"
195 "template Frame"
196 "{"
197 "<3D82AB46-62DA-11CF-AB39-0020AF71E433>"
198 "[...]"
199 "}"
200 "template FloatKeys"
201 "{"
202 "<10DD46A9-775B-11CF-8F52-0040333594A3>"
203 "DWORD nValues;"
204 "array FLOAT values[nValues];"
205 "}"
206 "template TimedFloatKeys"
207 "{"
208 "<F406B180-7B3B-11CF-8F52-0040333594A3>"
209 "DWORD time;"
210 "FloatKeys tfkeys;"
211 "}"
212 "template AnimationKey"
213 "{"
214 "<10DD46A8-775B-11CF-8F52-0040333594A3>"
215 "DWORD keyType;"
216 "DWORD nKeys;"
217 "array TimedFloatKeys keys[nKeys];"
218 "}"
219 "template AnimationOptions"
220 "{"
221 "<E2BF56C0-840F-11CF-8F52-0040333594A3>"
222 "DWORD openclosed;"
223 "DWORD positionquality;"
224 "}"
225 "template Animation"
226 "{"
227 "<3D82AB4F-62DA-11CF-AB39-0020AF71E433>"
228 "[...]"
229 "}"
230 "template AnimationSet"
231 "{"
232 "<3D82AB50-62DA-11CF-AB39-0020AF71E433>"
233 "[Animation]"
234 "}"
235 "template InlineData"
236 "{"
237 "<3A23EEA0-94B1-11D0-AB39-0020AF71E433>"
238 "[BINARY]"
239 "}"
240 "template Url"
241 "{"
242 "<3A23EEA1-94B1-11D0-AB39-0020AF71E433>"
243 "DWORD nUrls;"
244 "array STRING urls[nUrls];"
245 "}"
246 "template ProgressiveMesh"
247 "{"
248 "<8A63C360-997D-11D0-941C-0080C80CFA7B>"
249 "[Url,InlineData]"
250 "}"
251 "template Guid"
252 "{"
253 "<A42790E0-7810-11CF-8F52-0040333594A3>"
254 "DWORD data1;"
255 "WORD data2;"
256 "WORD data3;"
257 "array UCHAR data4[8];"
258 "}"
259 "template StringProperty"
260 "{"
261 "<7F0F21E0-BFE1-11D1-82C0-00A0C9697271>"
262 "STRING key;"
263 "STRING value;"
264 "}"
265 "template PropertyBag"
266 "{"
267 "<7F0F21E1-BFE1-11D1-82C0-00A0C9697271>"
268 "[StringProperty]"
269 "}"
270 "template ExternalVisual"
271 "{"
272 "<98116AA0-BDBA-11D1-82C0-00A0C9697271>"
273 "Guid guidExternalVisual;"
274 "[...]"
275 "}"
276 "template RightHanded"
277 "{"
278 "<7F5D5EA0-D53A-11D1-82C0-00A0C9697271>"
279 "DWORD bRightHanded;"
280 "}"
281 };
282
283 static inline IDirect3DRMMeshImpl *impl_from_IDirect3DRMMesh(IDirect3DRMMesh *iface)
284 {
285     return CONTAINING_RECORD(iface, IDirect3DRMMeshImpl, IDirect3DRMMesh_iface);
286 }
287
288 static inline IDirect3DRMMeshBuilderImpl *impl_from_IDirect3DRMMeshBuilder2(IDirect3DRMMeshBuilder2 *iface)
289 {
290     return CONTAINING_RECORD(iface, IDirect3DRMMeshBuilderImpl, IDirect3DRMMeshBuilder2_iface);
291 }
292
293 static inline IDirect3DRMMeshBuilderImpl *impl_from_IDirect3DRMMeshBuilder3(IDirect3DRMMeshBuilder3 *iface)
294 {
295     return CONTAINING_RECORD(iface, IDirect3DRMMeshBuilderImpl, IDirect3DRMMeshBuilder3_iface);
296 }
297
298 /*** IUnknown methods ***/
299 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_QueryInterface(IDirect3DRMMeshBuilder2* iface,
300                                                                  REFIID riid, void** ppvObject)
301 {
302     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
303
304     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
305
306     *ppvObject = NULL;
307
308     if(IsEqualGUID(riid, &IID_IUnknown) ||
309        IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder) ||
310        IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder2))
311     {
312         *ppvObject = &This->IDirect3DRMMeshBuilder2_iface;
313     }
314     else if(IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
315     {
316         *ppvObject = &This->IDirect3DRMMeshBuilder3_iface;
317     }
318     else
319     {
320         FIXME("interface %s not implemented\n", debugstr_guid(riid));
321         return E_NOINTERFACE;
322     }
323
324     IDirect3DRMMeshBuilder_AddRef(iface);
325     return S_OK;
326 }
327
328 static ULONG WINAPI IDirect3DRMMeshBuilder2Impl_AddRef(IDirect3DRMMeshBuilder2* iface)
329 {
330     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
331     ULONG ref = InterlockedIncrement(&This->ref);
332
333     TRACE("(%p)->(): new ref = %d\n", This, ref);
334
335     return ref;
336 }
337
338 static ULONG WINAPI IDirect3DRMMeshBuilder2Impl_Release(IDirect3DRMMeshBuilder2* iface)
339 {
340     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
341     ULONG ref = InterlockedDecrement(&This->ref);
342
343     TRACE("(%p)->(): new ref = %d\n", This, ref);
344
345     if (!ref)
346     {
347         HeapFree(GetProcessHeap(), 0, This->pVertices);
348         HeapFree(GetProcessHeap(), 0, This->pNormals);
349         HeapFree(GetProcessHeap(), 0, This->pFaceData);
350         HeapFree(GetProcessHeap(), 0, This->pCoords2d);
351         HeapFree(GetProcessHeap(), 0, This);
352     }
353
354     return ref;
355 }
356
357 /*** IDirect3DRMObject methods ***/
358 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Clone(IDirect3DRMMeshBuilder2* iface,
359                                                         LPUNKNOWN pUnkOuter, REFIID riid,
360                                                         LPVOID *ppvObj)
361 {
362     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
363
364     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
365
366     return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddDestroyCallback(IDirect3DRMMeshBuilder2* iface,
370                                                                      D3DRMOBJECTCALLBACK cb,
371                                                                      LPVOID argument)
372 {
373     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
374
375     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
376
377     return E_NOTIMPL;
378 }
379
380 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_DeleteDestroyCallback(IDirect3DRMMeshBuilder2* iface,
381                                                                         D3DRMOBJECTCALLBACK cb,
382                                                                         LPVOID argument)
383 {
384     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
385
386     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
387
388     return E_NOTIMPL;
389 }
390
391 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetAppData(IDirect3DRMMeshBuilder2* iface,
392                                                              DWORD data)
393 {
394     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
395
396     FIXME("(%p)->(%u): stub\n", This, data);
397
398     return E_NOTIMPL;
399 }
400
401 static DWORD WINAPI IDirect3DRMMeshBuilder2Impl_GetAppData(IDirect3DRMMeshBuilder2* iface)
402 {
403     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
404
405     FIXME("(%p)->(): stub\n", This);
406
407     return 0;
408 }
409
410 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetName(IDirect3DRMMeshBuilder2* iface,
411                                                           LPCSTR pName)
412 {
413     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
414
415     FIXME("(%p)->(%s): stub\n", This, pName);
416
417     return E_NOTIMPL;
418 }
419
420 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetName(IDirect3DRMMeshBuilder2* iface,
421                                                           LPDWORD lpdwSize, LPSTR lpName)
422 {
423     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
424
425     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
426
427     return E_NOTIMPL;
428 }
429
430 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetClassName(IDirect3DRMMeshBuilder2* iface,
431                                                                LPDWORD lpdwSize, LPSTR lpName)
432 {
433     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
434
435     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
436
437     return E_NOTIMPL;
438 }
439
440 /*** IDirect3DRMMeshBuilder2 methods ***/
441 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Load(IDirect3DRMMeshBuilder2* iface,
442                                                        LPVOID filename, LPVOID name,
443                                                        D3DRMLOADOPTIONS loadflags,
444                                                        D3DRMLOADTEXTURECALLBACK cb, LPVOID arg)
445 {
446     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
447
448     TRACE("(%p)->(%p,%p,%x,%p,%p)\n", This, filename, name, loadflags, cb, arg);
449
450     if (cb)
451         FIXME("Texture callback is not yet supported\n");
452
453     return IDirect3DRMMeshBuilder3_Load(&This->IDirect3DRMMeshBuilder3_iface, filename, name,
454                                         loadflags, NULL, arg);
455 }
456
457 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Save(IDirect3DRMMeshBuilder2* iface,
458                                                        const char *filename, D3DRMXOFFORMAT format,
459                                                        D3DRMSAVEOPTIONS save)
460 {
461     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
462
463     FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
464
465     return E_NOTIMPL;
466 }
467
468 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Scale(IDirect3DRMMeshBuilder2* iface,
469                                                         D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
470 {
471     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
472
473     FIXME("(%p)->(%f,%f,%f): stub\n", This, sx, sy, sz);
474
475     return D3DRM_OK;
476 }
477
478 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_Translate(IDirect3DRMMeshBuilder2* iface,
479                                                             D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
480 {
481     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
482
483     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
484
485     return E_NOTIMPL;
486 }
487
488 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColorSource(IDirect3DRMMeshBuilder2* iface,
489                                                                  D3DRMCOLORSOURCE color)
490 {
491     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
492
493     FIXME("(%p)->(%x): stub\n", This, color);
494
495     return E_NOTIMPL;
496 }
497
498 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetBox(IDirect3DRMMeshBuilder2* iface,
499                                                          D3DRMBOX *pBox)
500 {
501     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
502
503     FIXME("(%p)->(%p): stub\n", This, pBox);
504
505     return E_NOTIMPL;
506 }
507
508 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GenerateNormals(IDirect3DRMMeshBuilder2* iface)
509 {
510     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
511
512     FIXME("(%p)->(): stub\n", This);
513
514     return E_NOTIMPL;
515 }
516
517 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilder2Impl_GetColorSource(IDirect3DRMMeshBuilder2* iface)
518 {
519     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
520
521     FIXME("(%p)->(): stub\n", This);
522
523     return E_NOTIMPL;
524 }
525
526 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddMesh(IDirect3DRMMeshBuilder2* iface,
527                                                           LPDIRECT3DRMMESH pMesh)
528 {
529     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
530
531     FIXME("(%p)->(%p): stub\n", This, pMesh);
532
533     return E_NOTIMPL;
534 }
535
536 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddMeshBuilder(IDirect3DRMMeshBuilder2* iface,
537                                                                  LPDIRECT3DRMMESHBUILDER pMeshBuilder)
538 {
539     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
540
541     FIXME("(%p)->(%p): stub\n", This, pMeshBuilder);
542
543     return E_NOTIMPL;
544 }
545
546 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFrame(IDirect3DRMMeshBuilder2* iface,
547                                                            LPDIRECT3DRMFRAME pFrame)
548 {
549     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
550
551     FIXME("(%p)->(%p): stub\n", This, pFrame);
552
553     return E_NOTIMPL;
554 }
555
556 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFace(IDirect3DRMMeshBuilder2* iface,
557                                                           LPDIRECT3DRMFACE pFace)
558 {
559     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
560
561     FIXME("(%p)->(%p): stub\n", This, pFace);
562
563     return E_NOTIMPL;
564 }
565
566 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_AddFaces(IDirect3DRMMeshBuilder2* iface,
567                                                            DWORD vcount, D3DVECTOR *vertices,
568                                                            DWORD ncount, D3DVECTOR *normals,
569                                                            DWORD *data,
570                                                            LPDIRECT3DRMFACEARRAY* pFaceArray)
571 {
572     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
573
574     FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals, data, pFaceArray);
575
576     return E_NOTIMPL;
577 }
578
579 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_ReserveSpace(IDirect3DRMMeshBuilder2* iface,
580                                                                DWORD vertex_Count,
581                                                                DWORD normal_count,
582                                                                DWORD face_count)
583 {
584     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
585
586     FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
587
588     return E_NOTIMPL;
589 }
590
591 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColorRGB(IDirect3DRMMeshBuilder2* iface,
592                                                               D3DVALUE red, D3DVALUE green,
593                                                               D3DVALUE blue)
594 {
595     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
596
597     FIXME("(%p)->(%f,%f,%f): stub\n", This, red, green, blue);
598
599     return E_NOTIMPL;
600 }
601
602 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetColor(IDirect3DRMMeshBuilder2* iface,
603                                                            D3DCOLOR color)
604 {
605     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
606
607     FIXME("(%p)->(%x): stub\n", This, color);
608
609     return E_NOTIMPL;
610 }
611
612 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTexture(IDirect3DRMMeshBuilder2* iface,
613                                                              LPDIRECT3DRMTEXTURE pTexture)
614 {
615     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
616
617     FIXME("(%p)->(%p): stub\n", This, pTexture);
618
619     return E_NOTIMPL;
620 }
621
622 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetMaterial(IDirect3DRMMeshBuilder2* iface,
623                                                               LPDIRECT3DRMMATERIAL pMaterial)
624 {
625     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
626
627     FIXME("(%p)->(%p): stub\n", This, pMaterial);
628
629     return E_NOTIMPL;
630 }
631
632 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTextureTopology(IDirect3DRMMeshBuilder2* iface,
633                                                                      BOOL wrap_u, BOOL wrap_v)
634 {
635     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
636
637     FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
638
639     return E_NOTIMPL;
640 }
641
642 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetQuality(IDirect3DRMMeshBuilder2* iface,
643                                                              D3DRMRENDERQUALITY quality)
644 {
645     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
646
647     FIXME("(%p)->(%d): stub\n", This, quality);
648
649     return E_NOTIMPL;
650 }
651
652 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetPerspective(IDirect3DRMMeshBuilder2* iface,
653                                                                  BOOL enable)
654 {
655     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
656
657     FIXME("(%p)->(%d): stub\n", This, enable);
658
659     return E_NOTIMPL;
660 }
661
662 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertex(IDirect3DRMMeshBuilder2* iface,
663                                                             DWORD index,
664                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
665 {
666     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
667
668     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
669
670     return E_NOTIMPL;
671 }
672
673 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetNormal(IDirect3DRMMeshBuilder2* iface,
674                                                             DWORD index,
675                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
676 {
677     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
678
679     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
680
681     return E_NOTIMPL;
682 }
683
684 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetTextureCoordinates(IDirect3DRMMeshBuilder2* iface,
685                                                                         DWORD index,
686                                                                         D3DVALUE u, D3DVALUE v)
687 {
688     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
689
690     TRACE("(%p)->(%u,%f,%f)\n", This, index, u, v);
691
692     return IDirect3DRMMeshBuilder3_SetTextureCoordinates(&This->IDirect3DRMMeshBuilder3_iface,
693                                                          index, u, v);
694 }
695
696 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertexColor(IDirect3DRMMeshBuilder2* iface,
697                                                                  DWORD index, D3DCOLOR color)
698 {
699     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
700
701     FIXME("(%p)->(%d,%x): stub\n", This, index, color);
702
703     return E_NOTIMPL;
704 }
705
706 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_SetVertexColorRGB(IDirect3DRMMeshBuilder2* iface,
707                                                                     DWORD index, D3DVALUE red,
708                                                                     D3DVALUE green, D3DVALUE blue)
709 {
710     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
711
712     FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
713
714     return E_NOTIMPL;
715 }
716
717 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetFaces(IDirect3DRMMeshBuilder2* iface,
718                                                            LPDIRECT3DRMFACEARRAY* pFaceArray)
719 {
720     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
721
722     FIXME("(%p)->(%p): stub\n", This, pFaceArray);
723
724     return E_NOTIMPL;
725 }
726
727 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetVertices(IDirect3DRMMeshBuilder2* iface,
728                                                               DWORD *vcount, D3DVECTOR *vertices,
729                                                               DWORD *ncount, D3DVECTOR *normals,
730                                                               DWORD *face_data_size,
731                                                               DWORD *face_data)
732 {
733     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
734
735     TRACE("(%p)->(%p,%p,%p,%p,%p,%p)\n", This, vcount, vertices, ncount, normals, face_data_size, face_data);
736
737     if (vcount)
738         *vcount = This->nb_vertices;
739     if (vertices && This->nb_vertices)
740         memcpy(vertices, This->pVertices, This->nb_vertices * sizeof(D3DVECTOR));
741     if (ncount)
742         *ncount = This->nb_normals;
743     if (normals && This->nb_normals)
744         memcpy(normals, This->pNormals, This->nb_normals * sizeof(D3DVECTOR));
745     if (face_data_size)
746         *face_data_size = This->face_data_size;
747     if (face_data && This->face_data_size)
748         memcpy(face_data, This->pFaceData, This->face_data_size * sizeof(DWORD));
749
750     return D3DRM_OK;
751 }
752
753 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetTextureCoordinates(IDirect3DRMMeshBuilder2* iface,
754                                                                         DWORD index,
755                                                                         D3DVALUE *u, D3DVALUE *v)
756 {
757     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
758
759     TRACE("(%p)->(%u,%p,%p)\n", This, index, u, v);
760
761     return IDirect3DRMMeshBuilder3_GetTextureCoordinates(&This->IDirect3DRMMeshBuilder3_iface,
762                                                          index, u, v);
763 }
764
765 static int WINAPI IDirect3DRMMeshBuilder2Impl_AddVertex(IDirect3DRMMeshBuilder2* iface,
766                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
767 {
768     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
769
770     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
771
772     return 0;
773 }
774
775 static int WINAPI IDirect3DRMMeshBuilder2Impl_AddNormal(IDirect3DRMMeshBuilder2* iface,
776                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
777 {
778     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
779
780     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
781
782     return 0;
783 }
784
785 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_CreateFace(IDirect3DRMMeshBuilder2* iface,
786                                                              LPDIRECT3DRMFACE* ppFace)
787 {
788     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
789
790     FIXME("(%p)->(%p): stub\n", This, ppFace);
791
792     return E_NOTIMPL;
793 }
794
795 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilder2Impl_GetQuality(IDirect3DRMMeshBuilder2* iface)
796 {
797     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
798
799     FIXME("(%p)->(): stub\n", This);
800
801     return 0;
802 }
803
804 static BOOL WINAPI IDirect3DRMMeshBuilder2Impl_GetPerspective(IDirect3DRMMeshBuilder2* iface)
805 {
806     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
807
808     FIXME("(%p)->(): stub\n", This);
809
810     return FALSE;
811 }
812
813 static int WINAPI IDirect3DRMMeshBuilder2Impl_GetFaceCount(IDirect3DRMMeshBuilder2* iface)
814 {
815     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
816
817     TRACE("(%p)->()\n", This);
818
819     return This->nb_faces;
820 }
821
822 static int WINAPI IDirect3DRMMeshBuilder2Impl_GetVertexCount(IDirect3DRMMeshBuilder2* iface)
823 {
824     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
825
826     TRACE("(%p)->()\n", This);
827
828     return This->nb_vertices;
829 }
830
831 static D3DCOLOR WINAPI IDirect3DRMMeshBuilder2Impl_GetVertexColor(IDirect3DRMMeshBuilder2* iface,
832                                                                   DWORD index)
833 {
834     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
835
836     FIXME("(%p)->(%d): stub\n", This, index);
837
838     return 0;
839 }
840
841 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_CreateMesh(IDirect3DRMMeshBuilder2* iface,
842                                                              LPDIRECT3DRMMESH* ppMesh)
843 {
844     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
845
846     TRACE("(%p)->(%p)\n", This, ppMesh);
847
848     return Direct3DRMMesh_create(ppMesh);
849 }
850
851 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GenerateNormals2(IDirect3DRMMeshBuilder2* iface,
852                                                                    D3DVALUE crease, DWORD dwFlags)
853 {
854     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
855
856     FIXME("(%p)->(%f,%u): stub\n", This, crease, dwFlags);
857
858     return E_NOTIMPL;
859 }
860
861 static HRESULT WINAPI IDirect3DRMMeshBuilder2Impl_GetFace(IDirect3DRMMeshBuilder2* iface,
862                                                           DWORD index, LPDIRECT3DRMFACE* ppFace)
863 {
864     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
865
866     FIXME("(%p)->(%u,%p): stub\n", This, index, ppFace);
867
868     return E_NOTIMPL;
869 }
870
871 static const struct IDirect3DRMMeshBuilder2Vtbl Direct3DRMMeshBuilder2_Vtbl =
872 {
873     /*** IUnknown methods ***/
874     IDirect3DRMMeshBuilder2Impl_QueryInterface,
875     IDirect3DRMMeshBuilder2Impl_AddRef,
876     IDirect3DRMMeshBuilder2Impl_Release,
877     /*** IDirect3DRMObject methods ***/
878     IDirect3DRMMeshBuilder2Impl_Clone,
879     IDirect3DRMMeshBuilder2Impl_AddDestroyCallback,
880     IDirect3DRMMeshBuilder2Impl_DeleteDestroyCallback,
881     IDirect3DRMMeshBuilder2Impl_SetAppData,
882     IDirect3DRMMeshBuilder2Impl_GetAppData,
883     IDirect3DRMMeshBuilder2Impl_SetName,
884     IDirect3DRMMeshBuilder2Impl_GetName,
885     IDirect3DRMMeshBuilder2Impl_GetClassName,
886     /*** IDirect3DRMMeshBuilder methods ***/
887     IDirect3DRMMeshBuilder2Impl_Load,
888     IDirect3DRMMeshBuilder2Impl_Save,
889     IDirect3DRMMeshBuilder2Impl_Scale,
890     IDirect3DRMMeshBuilder2Impl_Translate,
891     IDirect3DRMMeshBuilder2Impl_SetColorSource,
892     IDirect3DRMMeshBuilder2Impl_GetBox,
893     IDirect3DRMMeshBuilder2Impl_GenerateNormals,
894     IDirect3DRMMeshBuilder2Impl_GetColorSource,
895     IDirect3DRMMeshBuilder2Impl_AddMesh,
896     IDirect3DRMMeshBuilder2Impl_AddMeshBuilder,
897     IDirect3DRMMeshBuilder2Impl_AddFrame,
898     IDirect3DRMMeshBuilder2Impl_AddFace,
899     IDirect3DRMMeshBuilder2Impl_AddFaces,
900     IDirect3DRMMeshBuilder2Impl_ReserveSpace,
901     IDirect3DRMMeshBuilder2Impl_SetColorRGB,
902     IDirect3DRMMeshBuilder2Impl_SetColor,
903     IDirect3DRMMeshBuilder2Impl_SetTexture,
904     IDirect3DRMMeshBuilder2Impl_SetMaterial,
905     IDirect3DRMMeshBuilder2Impl_SetTextureTopology,
906     IDirect3DRMMeshBuilder2Impl_SetQuality,
907     IDirect3DRMMeshBuilder2Impl_SetPerspective,
908     IDirect3DRMMeshBuilder2Impl_SetVertex,
909     IDirect3DRMMeshBuilder2Impl_SetNormal,
910     IDirect3DRMMeshBuilder2Impl_SetTextureCoordinates,
911     IDirect3DRMMeshBuilder2Impl_SetVertexColor,
912     IDirect3DRMMeshBuilder2Impl_SetVertexColorRGB,
913     IDirect3DRMMeshBuilder2Impl_GetFaces,
914     IDirect3DRMMeshBuilder2Impl_GetVertices,
915     IDirect3DRMMeshBuilder2Impl_GetTextureCoordinates,
916     IDirect3DRMMeshBuilder2Impl_AddVertex,
917     IDirect3DRMMeshBuilder2Impl_AddNormal,
918     IDirect3DRMMeshBuilder2Impl_CreateFace,
919     IDirect3DRMMeshBuilder2Impl_GetQuality,
920     IDirect3DRMMeshBuilder2Impl_GetPerspective,
921     IDirect3DRMMeshBuilder2Impl_GetFaceCount,
922     IDirect3DRMMeshBuilder2Impl_GetVertexCount,
923     IDirect3DRMMeshBuilder2Impl_GetVertexColor,
924     IDirect3DRMMeshBuilder2Impl_CreateMesh,
925     /*** IDirect3DRMMeshBuilder2 methods ***/
926     IDirect3DRMMeshBuilder2Impl_GenerateNormals2,
927     IDirect3DRMMeshBuilder2Impl_GetFace
928 };
929
930
931 /*** IUnknown methods ***/
932 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_QueryInterface(IDirect3DRMMeshBuilder3* iface,
933                                                                  REFIID riid, void** ppvObject)
934 {
935     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
936     return IDirect3DRMMeshBuilder2_QueryInterface(&This->IDirect3DRMMeshBuilder2_iface, riid, ppvObject);
937 }
938
939 static ULONG WINAPI IDirect3DRMMeshBuilder3Impl_AddRef(IDirect3DRMMeshBuilder3* iface)
940 {
941     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
942     return IDirect3DRMMeshBuilder2_AddRef(&This->IDirect3DRMMeshBuilder2_iface);
943 }
944
945 static ULONG WINAPI IDirect3DRMMeshBuilder3Impl_Release(IDirect3DRMMeshBuilder3* iface)
946 {
947     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
948     return IDirect3DRMMeshBuilder2_Release(&This->IDirect3DRMMeshBuilder2_iface);
949 }
950
951 /*** IDirect3DRMObject methods ***/
952 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Clone(IDirect3DRMMeshBuilder3* iface,
953                                                         LPUNKNOWN pUnkOuter, REFIID riid,
954                                                         LPVOID *ppvObj)
955 {
956     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
957
958     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
959
960     return E_NOTIMPL;
961 }
962
963 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddDestroyCallback(IDirect3DRMMeshBuilder3* iface,
964                                                                      D3DRMOBJECTCALLBACK cb,
965                                                                      LPVOID argument)
966 {
967     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
968
969     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
970
971     return E_NOTIMPL;
972 }
973
974 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteDestroyCallback(IDirect3DRMMeshBuilder3* iface,
975                                                                         D3DRMOBJECTCALLBACK cb,
976                                                                         LPVOID argument)
977 {
978     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
979
980     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
981
982     return E_NOTIMPL;
983 }
984
985 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetAppData(IDirect3DRMMeshBuilder3* iface,
986                                                              DWORD data)
987 {
988     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
989
990     FIXME("(%p)->(%u): stub\n", This, data);
991
992     return E_NOTIMPL;
993 }
994
995 static DWORD WINAPI IDirect3DRMMeshBuilder3Impl_GetAppData(IDirect3DRMMeshBuilder3* iface)
996 {
997     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
998
999     FIXME("(%p)->(): stub\n", This);
1000
1001     return 0;
1002 }
1003
1004 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetName(IDirect3DRMMeshBuilder3* iface,
1005                                                           LPCSTR pName)
1006 {
1007     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1008
1009     FIXME("(%p)->(%s): stub\n", This, pName);
1010
1011     return E_NOTIMPL;
1012 }
1013
1014 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetName(IDirect3DRMMeshBuilder3* iface,
1015                                                           LPDWORD lpdwSize, LPSTR lpName)
1016 {
1017     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1018
1019     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
1020
1021     return E_NOTIMPL;
1022 }
1023
1024 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetClassName(IDirect3DRMMeshBuilder3* iface,
1025                                                                LPDWORD lpdwSize, LPSTR lpName)
1026 {
1027     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1028
1029     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
1030
1031     return E_NOTIMPL;
1032 }
1033
1034 HRESULT load_mesh_data(IDirect3DRMMeshBuilder3* iface, LPDIRECTXFILEDATA pData)
1035 {
1036     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1037     LPDIRECTXFILEOBJECT pObject = NULL;
1038     LPDIRECTXFILEDATA pData2 = NULL;
1039     const GUID* pGuid;
1040     DWORD size;
1041     LPBYTE ptr;
1042     HRESULT hr;
1043     HRESULT ret = D3DRMERR_BADOBJECT;
1044     DWORD* faces_vertex_idx_data = NULL;
1045     DWORD* faces_vertex_idx_ptr;
1046     DWORD faces_vertex_idx_size;
1047     DWORD* faces_normal_idx_data = NULL;
1048     DWORD* faces_normal_idx_ptr = NULL;
1049     DWORD* faces_data_ptr;
1050     DWORD faces_data_size = 0;
1051     DWORD i;
1052
1053     TRACE("(%p)->(%p)\n", This, pData);
1054
1055     hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&ptr);
1056     if (hr != DXFILE_OK)
1057         goto end;
1058
1059     This->nb_vertices = *(DWORD*)ptr;
1060     This->nb_faces = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR));
1061     faces_vertex_idx_size = size - sizeof(DWORD) - This->nb_vertices * sizeof(D3DVECTOR) - sizeof(DWORD);
1062     faces_vertex_idx_ptr = (DWORD*)(ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR) + sizeof(DWORD));
1063
1064     TRACE("Mesh: nb_vertices = %d, nb_faces = %d, faces_vertex_idx_size = %d\n", This->nb_vertices, This->nb_faces, faces_vertex_idx_size);
1065
1066     This->pVertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DVECTOR));
1067     memcpy(This->pVertices, ptr + sizeof(DWORD), This->nb_vertices * sizeof(D3DVECTOR));
1068
1069     faces_vertex_idx_ptr = faces_vertex_idx_data = HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size);
1070     memcpy(faces_vertex_idx_data, ptr + sizeof(DWORD) + This->nb_vertices * sizeof(D3DVECTOR) + sizeof(DWORD), faces_vertex_idx_size);
1071
1072     /* Each vertex index will have its normal index counterpart so just allocate twice the size */
1073     This->pFaceData = HeapAlloc(GetProcessHeap(), 0, faces_vertex_idx_size*2);
1074     faces_data_ptr = (DWORD*)This->pFaceData;
1075
1076     while (1)
1077     {
1078         hr =  IDirectXFileData_GetNextObject(pData, &pObject);
1079         if (hr == DXFILEERR_NOMOREOBJECTS)
1080         {
1081             TRACE("No more object\n");
1082             break;
1083         }
1084         if (hr != DXFILE_OK)
1085            goto end;
1086
1087         hr = IDirectXFileObject_QueryInterface(pObject, &IID_IDirectXFileData, (void**)&pData2);
1088         IDirectXFileObject_Release(pObject);
1089         if (hr != DXFILE_OK)
1090             goto end;
1091
1092         hr = IDirectXFileData_GetType(pData2, &pGuid);
1093         if (hr != DXFILE_OK)
1094             goto end;
1095
1096         TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1097
1098         if (IsEqualGUID(pGuid, &TID_D3DRMMeshNormals))
1099         {
1100             DWORD nb_faces_normals;
1101             DWORD faces_normal_idx_size;
1102
1103             hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1104             if (hr != DXFILE_OK)
1105                 goto end;
1106
1107             This->nb_normals = *(DWORD*)ptr;
1108             nb_faces_normals = *(DWORD*)(ptr + sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR));
1109
1110             TRACE("MeshNormals: nb_normals = %d, nb_faces_normals = %d\n", This->nb_normals, nb_faces_normals);
1111             if (nb_faces_normals != This->nb_faces)
1112                 WARN("nb_face_normals (%d) != nb_faces (%d)\n", nb_faces_normals, This->nb_normals);
1113
1114             This->pNormals = HeapAlloc(GetProcessHeap(), 0, This->nb_normals * sizeof(D3DVECTOR));
1115             memcpy(This->pNormals, ptr + sizeof(DWORD), This->nb_normals * sizeof(D3DVECTOR));
1116
1117             faces_normal_idx_size = size - (2*sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR));
1118             faces_normal_idx_ptr = faces_normal_idx_data = HeapAlloc(GetProcessHeap(), 0, faces_normal_idx_size);
1119             memcpy(faces_normal_idx_data, ptr + sizeof(DWORD) + This->nb_normals * sizeof(D3DVECTOR) + sizeof(DWORD), faces_normal_idx_size);
1120         }
1121         else if (IsEqualGUID(pGuid, &TID_D3DRMMeshTextureCoords))
1122         {
1123             hr = IDirectXFileData_GetData(pData2, NULL, &size, (void**)&ptr);
1124             if (hr != DXFILE_OK)
1125                 goto end;
1126
1127             This->nb_coords2d = *(DWORD*)ptr;
1128
1129             TRACE("MeshTextureCoords: nb_coords2d = %d\n", This->nb_coords2d);
1130
1131             This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
1132             memcpy(This->pCoords2d, ptr + sizeof(DWORD), This->nb_coords2d * sizeof(Coords2d));
1133
1134         }
1135         else if (IsEqualGUID(pGuid, &TID_D3DRMMeshMaterialList))
1136         {
1137             FIXME("MeshMaterialList not supported yet, ignoring...\n");
1138         }
1139         else
1140         {
1141             FIXME("Unknown GUID %s, ignoring...\n", debugstr_guid(pGuid));
1142         }
1143
1144         IDirectXFileData_Release(pData2);
1145         pData2 = NULL;
1146     }
1147
1148     for (i = 0; i < This->nb_faces; i++)
1149     {
1150         DWORD j;
1151         DWORD nb_face_indexes;
1152
1153         if (faces_vertex_idx_size < sizeof(DWORD))
1154             WARN("Not enough data to read number of indices of face %d\n", i);
1155
1156         nb_face_indexes  = *(faces_data_ptr + faces_data_size++) = *(faces_vertex_idx_ptr++);
1157         faces_vertex_idx_size--;
1158         if (faces_normal_idx_data && (*(faces_normal_idx_ptr++) != nb_face_indexes))
1159             WARN("Faces indices number mismatch\n");
1160
1161         if (faces_vertex_idx_size < (nb_face_indexes * sizeof(DWORD)))
1162             WARN("Not enough data to read all indices of face %d\n", i);
1163
1164         for (j = 0; j < nb_face_indexes; j++)
1165         {
1166             /* Copy vertex index */
1167             *(faces_data_ptr + faces_data_size++) = *(faces_vertex_idx_ptr++);
1168             /* Copy normal index */
1169             if (faces_normal_idx_data)
1170             {
1171                 /* Read from x file */
1172                 *(faces_data_ptr + faces_data_size++) = *(faces_normal_idx_ptr++);
1173             }
1174             else
1175             {
1176                 FIXME("No normal available, generate a fake normal index\n");
1177                 /* Must be generated, put 0 for now */
1178                 *(faces_data_ptr + faces_data_size++) = 0;
1179             }
1180         }
1181         faces_vertex_idx_size -= nb_face_indexes;
1182     }
1183
1184     /* Last DWORD must be 0 */
1185     *(faces_data_ptr + faces_data_size++) = 0;
1186
1187     /* Set size (in number of DWORD) of all faces data */
1188     This->face_data_size = faces_data_size;
1189
1190     /* If there is no texture coordinates, generate default texture coordinates (0.0f, 0.0f) for each vertex */
1191     if (!This->pCoords2d)
1192     {
1193         This->nb_coords2d = This->nb_vertices;
1194         This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
1195         for (i = 0; i < This->nb_coords2d; i++)
1196         {
1197             This->pCoords2d[i].u = 0.0f;
1198             This->pCoords2d[i].v = 0.0f;
1199         }
1200     }
1201
1202     TRACE("Mesh data loaded successfully\n");
1203
1204     ret = D3DRM_OK;
1205
1206 end:
1207
1208     HeapFree(GetProcessHeap(), 0, faces_normal_idx_data);
1209     HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data);
1210
1211     return ret;
1212 }
1213
1214 /*** IDirect3DRMMeshBuilder3 methods ***/
1215 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Load(IDirect3DRMMeshBuilder3* iface,
1216                                                        LPVOID filename, LPVOID name,
1217                                                        D3DRMLOADOPTIONS loadflags,
1218                                                        D3DRMLOADTEXTURE3CALLBACK cb, LPVOID arg)
1219 {
1220     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1221     DXFILELOADOPTIONS load_options;
1222     LPDIRECTXFILE pDXFile = NULL;
1223     LPDIRECTXFILEENUMOBJECT pEnumObject = NULL;
1224     LPDIRECTXFILEDATA pData = NULL;
1225     LPDIRECTXFILEDATA pData2 = NULL;
1226     const GUID* pGuid;
1227     DWORD size;
1228     Header* pHeader;
1229     HRESULT hr;
1230     HRESULT ret = D3DRMERR_BADOBJECT;
1231
1232     TRACE("(%p)->(%p,%p,%x,%p,%p)\n", This, filename, name, loadflags, cb, arg);
1233
1234     /* First free allocated buffers of previous mesh data */
1235     HeapFree(GetProcessHeap(), 0, This->pVertices);
1236     This->pVertices = NULL;
1237     HeapFree(GetProcessHeap(), 0, This->pNormals);
1238     This->pNormals = NULL;
1239     HeapFree(GetProcessHeap(), 0, This->pFaceData);
1240     This->pFaceData = NULL;
1241     HeapFree(GetProcessHeap(), 0, This->pCoords2d);
1242     This->pCoords2d = NULL;
1243
1244     if (loadflags == D3DRMLOAD_FROMMEMORY)
1245     {
1246         load_options = DXFILELOAD_FROMMEMORY;
1247     }
1248     else
1249     {
1250         FIXME("Load options %d not supported yet\n", loadflags);
1251         return E_NOTIMPL;
1252     }
1253
1254     hr = DirectXFileCreate(&pDXFile);
1255     if (hr != DXFILE_OK)
1256         goto end;
1257
1258     hr = IDirectXFile_RegisterTemplates(pDXFile, templates, strlen(templates));
1259     if (hr != DXFILE_OK)
1260         goto end;
1261
1262     hr = IDirectXFile_CreateEnumObject(pDXFile, filename, load_options, &pEnumObject);
1263     if (hr != DXFILE_OK)
1264         goto end;
1265
1266     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
1267     if (hr != DXFILE_OK)
1268         goto end;
1269
1270     hr = IDirectXFileData_GetType(pData, &pGuid);
1271     if (hr != DXFILE_OK)
1272         goto end;
1273
1274     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1275
1276     if (!IsEqualGUID(pGuid, &TID_DXFILEHeader))
1277     {
1278         ret = D3DRMERR_BADFILE;
1279         goto end;
1280     }
1281
1282     hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&pHeader);
1283     if ((hr != DXFILE_OK) || (size != sizeof(Header)))
1284         goto end;
1285
1286     TRACE("Version is %d %d %d\n", pHeader->major, pHeader->minor, pHeader->flags);
1287
1288     /* Version must be 1.0.x */
1289     if ((pHeader->major != 1) || (pHeader->minor != 0))
1290     {
1291         ret = D3DRMERR_BADFILE;
1292         goto end;
1293     }
1294
1295     IDirectXFileData_Release(pData);
1296     pData = NULL;
1297
1298     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
1299     if (hr != DXFILE_OK)
1300     {
1301         ret = D3DRMERR_NOTFOUND;
1302         goto end;
1303     }
1304
1305     hr = IDirectXFileData_GetType(pData, &pGuid);
1306     if (hr != DXFILE_OK)
1307         goto end;
1308
1309     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1310
1311     if (!IsEqualGUID(pGuid, &TID_D3DRMMesh))
1312     {
1313         ret = D3DRMERR_NOTFOUND;
1314         goto end;
1315     }
1316
1317     hr = load_mesh_data(iface, pData);
1318     if (hr == S_OK)
1319         ret = D3DRM_OK;
1320
1321 end:
1322
1323     if (pData2)
1324         IDirectXFileData_Release(pData2);
1325     if (pData)
1326         IDirectXFileData_Release(pData);
1327     if (pEnumObject)
1328         IDirectXFileEnumObject_Release(pEnumObject);
1329     if (pDXFile)
1330         IDirectXFile_Release(pDXFile);
1331
1332     if (ret != D3DRM_OK)
1333     {
1334         /* Clean mesh data */
1335         This->nb_vertices = 0;
1336         This->nb_normals = 0;
1337         This->nb_faces = 0;
1338         This->face_data_size = 0;
1339         This->nb_coords2d = 0;
1340         HeapFree(GetProcessHeap(), 0, This->pVertices);
1341         This->pVertices = NULL;
1342         HeapFree(GetProcessHeap(), 0, This->pNormals);
1343         This->pNormals = NULL;
1344         HeapFree(GetProcessHeap(), 0, This->pFaceData);
1345         This->pFaceData = NULL;
1346         HeapFree(GetProcessHeap(), 0, This->pCoords2d);
1347         This->pCoords2d = NULL;
1348     }
1349
1350     return ret;
1351 }
1352
1353 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Save(IDirect3DRMMeshBuilder3* iface,
1354                                                        const char* filename, D3DRMXOFFORMAT format,
1355                                                        D3DRMSAVEOPTIONS save)
1356 {
1357     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1358
1359     FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
1360
1361     return E_NOTIMPL;
1362 }
1363
1364 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Scale(IDirect3DRMMeshBuilder3* iface,
1365                                                         D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
1366 {
1367     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1368
1369     FIXME("(%p)->(%f,%f,%f): stub\n", This, sx, sy, sz);
1370
1371     return E_NOTIMPL;
1372 }
1373
1374 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Translate(IDirect3DRMMeshBuilder3* iface,
1375                                                             D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
1376 {
1377     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1378
1379     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
1380
1381     return E_NOTIMPL;
1382 }
1383
1384 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorSource(IDirect3DRMMeshBuilder3* iface,
1385                                                                  D3DRMCOLORSOURCE color)
1386 {
1387     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1388
1389     FIXME("(%p)->(%x): stub\n", This, color);
1390
1391     return E_NOTIMPL;
1392 }
1393
1394 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetBox(IDirect3DRMMeshBuilder3* iface,
1395                                                          D3DRMBOX* box)
1396 {
1397     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1398
1399     FIXME("(%p)->(%p): stub\n", This, box);
1400
1401     return E_NOTIMPL;
1402 }
1403
1404 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GenerateNormals(IDirect3DRMMeshBuilder3* iface,
1405                                                                   D3DVALUE crease, DWORD flags)
1406 {
1407     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1408
1409     FIXME("(%p)->(%f,%u): stub\n", This, crease, flags);
1410
1411     return E_NOTIMPL;
1412 }
1413
1414 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilder3Impl_GetColorSource(IDirect3DRMMeshBuilder3* iface)
1415 {
1416     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1417
1418     FIXME("(%p)->(): stub\n", This);
1419
1420     return E_NOTIMPL;
1421 }
1422
1423 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMesh(IDirect3DRMMeshBuilder3* iface,
1424                                                           LPDIRECT3DRMMESH Mesh)
1425 {
1426     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1427
1428     FIXME("(%p)->(%p): stub\n", This, Mesh);
1429
1430     return E_NOTIMPL;
1431 }
1432
1433 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMeshBuilder(IDirect3DRMMeshBuilder3* iface,
1434                                                                  LPDIRECT3DRMMESHBUILDER3 MeshBuilder,
1435                                                                  DWORD flags)
1436 {
1437     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1438
1439     FIXME("(%p)->(%p,%u): stub\n", This, MeshBuilder, flags);
1440
1441     return E_NOTIMPL;
1442 }
1443
1444 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFrame(IDirect3DRMMeshBuilder3* iface,
1445                                                            LPDIRECT3DRMFRAME3 Frame)
1446 {
1447     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1448
1449     FIXME("(%p)->(%p): stub\n", This, Frame);
1450
1451     return E_NOTIMPL;
1452 }
1453
1454 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFace(IDirect3DRMMeshBuilder3* iface,
1455                                                           LPDIRECT3DRMFACE2 Face)
1456 {
1457     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1458
1459     FIXME("(%p)->(%p): stub\n", This, Face);
1460
1461     return E_NOTIMPL;
1462 }
1463
1464 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFaces(IDirect3DRMMeshBuilder3* iface,
1465                                                            DWORD vcount, D3DVECTOR* vertices,
1466                                                            DWORD ncount, D3DVECTOR* normals,
1467                                                            DWORD* data,
1468                                                            LPDIRECT3DRMFACEARRAY* FaceArray)
1469 {
1470     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1471
1472     FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount,
1473           normals, data, FaceArray);
1474
1475     return E_NOTIMPL;
1476 }
1477
1478 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_ReserveSpace(IDirect3DRMMeshBuilder3* iface,
1479                                                                DWORD vertex_Count,
1480                                                                DWORD normal_count,
1481                                                                DWORD face_count)
1482 {
1483     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1484
1485     FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
1486
1487     return E_NOTIMPL;
1488 }
1489
1490 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorRGB(IDirect3DRMMeshBuilder3* iface,
1491                                                               D3DVALUE red, D3DVALUE green,
1492                                                               D3DVALUE blue)
1493 {
1494     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1495
1496     FIXME("(%p)->(%f,%f,%f): stub\n", This, red, green, blue);
1497
1498     return E_NOTIMPL;
1499 }
1500
1501 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColor(IDirect3DRMMeshBuilder3* iface,
1502                                                            D3DCOLOR color)
1503 {
1504     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1505
1506     FIXME("(%p)->(%x): stub\n", This, color);
1507
1508     return E_NOTIMPL;
1509 }
1510
1511 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTexture(IDirect3DRMMeshBuilder3* iface,
1512                                                              LPDIRECT3DRMTEXTURE3 texture)
1513 {
1514     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1515
1516     FIXME("(%p)->(%p): stub\n", This, texture);
1517
1518     return E_NOTIMPL;
1519 }
1520
1521 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetMaterial(IDirect3DRMMeshBuilder3* iface,
1522                                                               LPDIRECT3DRMMATERIAL2 material)
1523 {
1524     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1525
1526     FIXME("(%p)->(%p): stub\n", This, material);
1527
1528     return E_NOTIMPL;
1529 }
1530
1531 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureTopology(IDirect3DRMMeshBuilder3* iface,
1532                                                                      BOOL wrap_u, BOOL wrap_v)
1533 {
1534     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1535
1536     FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
1537
1538     return E_NOTIMPL;
1539 }
1540
1541 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetQuality(IDirect3DRMMeshBuilder3* iface,
1542                                                              D3DRMRENDERQUALITY quality)
1543 {
1544     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1545
1546     FIXME("(%p)->(%d): stub\n", This, quality);
1547
1548     return E_NOTIMPL;
1549 }
1550
1551 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetPerspective(IDirect3DRMMeshBuilder3* iface,
1552                                                                  BOOL enable)
1553 {
1554     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1555
1556     FIXME("(%p)->(%d): stub\n", This, enable);
1557
1558     return E_NOTIMPL;
1559 }
1560
1561 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertex(IDirect3DRMMeshBuilder3* iface,
1562                                                             DWORD index,
1563                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
1564 {
1565     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1566
1567     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1568
1569     return E_NOTIMPL;
1570 }
1571
1572 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormal(IDirect3DRMMeshBuilder3* iface,
1573                                                             DWORD index,
1574                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
1575 {
1576     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1577
1578     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1579
1580     return E_NOTIMPL;
1581 }
1582
1583 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1584                                                                         DWORD index, D3DVALUE u,
1585                                                                         D3DVALUE v)
1586 {
1587     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1588
1589     TRACE("(%p)->(%u,%f,%f)\n", This, index, u, v);
1590
1591     if (index >= This->nb_coords2d)
1592         return D3DRMERR_BADVALUE;
1593
1594     This->pCoords2d[index].u = u;
1595     This->pCoords2d[index].v = v;
1596
1597     return D3DRM_OK;
1598 }
1599
1600 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColor(IDirect3DRMMeshBuilder3* iface,
1601                                                                  DWORD index, D3DCOLOR color)
1602 {
1603     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1604
1605     FIXME("(%p)->(%d,%x): stub\n", This, index, color);
1606
1607     return E_NOTIMPL;
1608 }
1609
1610 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB(IDirect3DRMMeshBuilder3* iface,
1611                                                                     DWORD index,
1612                                                                     D3DVALUE red, D3DVALUE green,
1613                                                                     D3DVALUE blue)
1614 {
1615     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1616
1617     FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
1618
1619     return E_NOTIMPL;
1620 }
1621
1622 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFaces(IDirect3DRMMeshBuilder3* iface,
1623                                                            LPDIRECT3DRMFACEARRAY* FaceArray)
1624 {
1625     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1626
1627     FIXME("(%p)->(%p): stub\n", This, FaceArray);
1628
1629     return E_NOTIMPL;
1630 }
1631
1632 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetGeometry(IDirect3DRMMeshBuilder3* iface,
1633                                                               DWORD* vcount, D3DVECTOR* vertices,
1634                                                               DWORD* ncount, D3DVECTOR* normals,
1635                                                               DWORD* face_data_size,
1636                                                               DWORD* face_data)
1637 {
1638     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1639
1640     FIXME("(%p)->(%p,%p,%p,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals,
1641           face_data_size, face_data);
1642
1643     return E_NOTIMPL;
1644 }
1645
1646 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1647                                                                         DWORD index, D3DVALUE* u,
1648                                                                         D3DVALUE* v)
1649 {
1650     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1651
1652     TRACE("(%p)->(%d,%p,%p)\n", This, index, u, v);
1653
1654     if (index >= This->nb_coords2d)
1655         return D3DRMERR_BADVALUE;
1656
1657     *u = This->pCoords2d[index].u;
1658     *v = This->pCoords2d[index].v;
1659
1660     return D3DRM_OK;
1661 }
1662
1663
1664 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddVertex(IDirect3DRMMeshBuilder3* iface,
1665                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
1666 {
1667     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1668
1669     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1670
1671     return 0;
1672 }
1673
1674 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddNormal(IDirect3DRMMeshBuilder3* iface,
1675                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
1676 {
1677     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1678
1679     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1680
1681     return 0;
1682 }
1683
1684 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateFace(IDirect3DRMMeshBuilder3* iface,
1685                                                              LPDIRECT3DRMFACE2* Face)
1686 {
1687     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1688
1689     FIXME("(%p)->(%p): stub\n", This, Face);
1690
1691     return E_NOTIMPL;
1692 }
1693
1694 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilder3Impl_GetQuality(IDirect3DRMMeshBuilder3* iface)
1695 {
1696     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1697
1698     FIXME("(%p)->(): stub\n", This);
1699
1700     return 0;
1701 }
1702
1703 static BOOL WINAPI IDirect3DRMMeshBuilder3Impl_GetPerspective(IDirect3DRMMeshBuilder3* iface)
1704 {
1705     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1706
1707     FIXME("(%p)->(): stub\n", This);
1708
1709     return FALSE;
1710 }
1711
1712 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetFaceCount(IDirect3DRMMeshBuilder3* iface)
1713 {
1714     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1715
1716     TRACE("(%p)->()\n", This);
1717
1718     return This->nb_faces;
1719 }
1720
1721 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexCount(IDirect3DRMMeshBuilder3* iface)
1722 {
1723     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1724
1725     TRACE("(%p)->()\n", This);
1726
1727     return This->nb_vertices;
1728 }
1729
1730 static D3DCOLOR WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexColor(IDirect3DRMMeshBuilder3* iface,
1731                                                                   DWORD index)
1732 {
1733     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1734
1735     FIXME("(%p)->(%d): stub\n", This, index);
1736
1737     return 0;
1738 }
1739
1740 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateMesh(IDirect3DRMMeshBuilder3* iface,
1741                                                              LPDIRECT3DRMMESH* Mesh)
1742 {
1743     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1744
1745     TRACE("(%p)->(%p)\n", This, Mesh);
1746
1747     return Direct3DRMMesh_create(Mesh);
1748 }
1749
1750 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFace(IDirect3DRMMeshBuilder3* iface,
1751                                                           DWORD index, LPDIRECT3DRMFACE2* Face)
1752 {
1753     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1754
1755     FIXME("(%p)->(%u,%p): stub\n", This, index, Face);
1756
1757     return E_NOTIMPL;
1758 }
1759
1760 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertex(IDirect3DRMMeshBuilder3* iface,
1761                                                             DWORD index, LPD3DVECTOR vector)
1762 {
1763     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1764
1765     FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
1766
1767     return E_NOTIMPL;
1768 }
1769
1770 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormal(IDirect3DRMMeshBuilder3* iface,
1771                                                             DWORD index, LPD3DVECTOR vector)
1772 {
1773     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1774
1775     FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
1776
1777     return E_NOTIMPL;
1778 }
1779
1780 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteVertices(IDirect3DRMMeshBuilder3* iface,
1781                                                                  DWORD IndexFirst, DWORD count)
1782 {
1783     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1784
1785     FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
1786
1787     return E_NOTIMPL;
1788 }
1789
1790 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteNormals(IDirect3DRMMeshBuilder3* iface,
1791                                                                 DWORD IndexFirst, DWORD count)
1792 {
1793     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1794
1795     FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
1796
1797     return E_NOTIMPL;
1798 }
1799
1800 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteFace(IDirect3DRMMeshBuilder3* iface,
1801                                                              LPDIRECT3DRMFACE2 Face)
1802 {
1803     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1804
1805     FIXME("(%p)->(%p): stub\n", This, Face);
1806
1807     return E_NOTIMPL;
1808 }
1809
1810 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Empty(IDirect3DRMMeshBuilder3* iface, DWORD flags)
1811 {
1812     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1813
1814     FIXME("(%p)->(%u): stub\n", This, flags);
1815
1816     return E_NOTIMPL;
1817 }
1818
1819 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Optimize(IDirect3DRMMeshBuilder3* iface,
1820                                                            DWORD flags)
1821 {
1822     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1823
1824     FIXME("(%p)->(%u): stub\n", This, flags);
1825
1826     return E_NOTIMPL;
1827 }
1828
1829 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFacesIndexed(IDirect3DRMMeshBuilder3* iface,
1830                                                                   DWORD flags, DWORD* indices,
1831                                                                   DWORD* IndexFirst, DWORD* count)
1832 {
1833     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1834
1835     FIXME("(%p)->(%u,%p,%p,%p): stub\n", This, flags, indices, IndexFirst, count);
1836
1837     return E_NOTIMPL;
1838 }
1839
1840 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateSubMesh(IDirect3DRMMeshBuilder3* iface,
1841                                                                 LPUNKNOWN *unkwn)
1842 {
1843     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1844
1845     FIXME("(%p)->(%p): stub\n", This, unkwn);
1846
1847     return E_NOTIMPL;
1848 }
1849
1850 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetParentMesh(IDirect3DRMMeshBuilder3* iface,
1851                                                                 DWORD flags, LPUNKNOWN *unkwn)
1852 {
1853     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1854
1855     FIXME("(%p)->(%u,%p): stub\n", This, flags, unkwn);
1856
1857     return E_NOTIMPL;
1858 }
1859
1860 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetSubMeshes(IDirect3DRMMeshBuilder3* iface,
1861                                                                LPDWORD count, LPUNKNOWN *unkwn)
1862 {
1863     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1864
1865     FIXME("(%p)->(%p,%p): stub\n", This, count, unkwn);
1866
1867     return E_NOTIMPL;
1868 }
1869
1870 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteSubMesh(IDirect3DRMMeshBuilder3* iface,
1871                                                                 LPUNKNOWN unkwn)
1872 {
1873     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1874
1875     FIXME("(%p)->(%p): stub\n", This, unkwn);
1876
1877     return E_NOTIMPL;
1878 }
1879
1880 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Enable(IDirect3DRMMeshBuilder3* iface,
1881                                                          DWORD index)
1882 {
1883     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1884
1885     FIXME("(%p)->(%u): stub\n", This, index);
1886
1887     return E_NOTIMPL;
1888 }
1889
1890 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetEnable(IDirect3DRMMeshBuilder3* iface,
1891                                                             DWORD* indices)
1892 {
1893     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1894
1895     FIXME("(%p)->(%p): stub\n", This, indices);
1896
1897     return E_NOTIMPL;
1898 }
1899
1900 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddTriangles(IDirect3DRMMeshBuilder3* iface,
1901                                                                DWORD flags, DWORD format,
1902                                                                DWORD VertexCount, LPVOID data)
1903 {
1904     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1905
1906     FIXME("(%p)->(%u,%u,%u,%p): stub\n", This, flags, format, VertexCount, data);
1907
1908     return E_NOTIMPL;
1909 }
1910
1911 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertices(IDirect3DRMMeshBuilder3* iface,
1912                                                               DWORD IndexFirst, DWORD count,
1913                                                               LPD3DVECTOR vector)
1914 {
1915     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1916
1917     FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
1918
1919     return E_NOTIMPL;
1920 }
1921
1922 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertices(IDirect3DRMMeshBuilder3* iface,
1923                                                               DWORD IndexFirst, LPDWORD vcount,
1924                                                               LPD3DVECTOR vertices)
1925 {
1926     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1927     DWORD count = This->nb_vertices - IndexFirst;
1928
1929     TRACE("(%p)->(%u,%p,%p)\n", This, IndexFirst, vcount, vertices);
1930
1931     if (vcount)
1932         *vcount = count;
1933     if (vertices && This->nb_vertices)
1934         memcpy(vertices, This->pVertices + IndexFirst, count * sizeof(D3DVECTOR));
1935
1936     return D3DRM_OK;
1937 }
1938
1939 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormals(IDirect3DRMMeshBuilder3* iface,
1940                                                              DWORD IndexFirst, DWORD count,
1941                                                              LPD3DVECTOR vector)
1942 {
1943     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1944
1945     FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
1946
1947     return E_NOTIMPL;
1948 }
1949
1950 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormals(IDirect3DRMMeshBuilder3* iface,
1951                                                              DWORD IndexFirst, LPDWORD count,
1952                                                              LPD3DVECTOR vector)
1953 {
1954     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1955
1956     FIXME("(%p)->(%u,%p,%p): stub\n", This, IndexFirst, count, vector);
1957
1958     return E_NOTIMPL;
1959 }
1960
1961 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetNormalCount(IDirect3DRMMeshBuilder3* iface)
1962 {
1963     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1964
1965     FIXME("(%p)->(): stub\n", This);
1966
1967     return E_NOTIMPL;
1968 }
1969
1970 static const struct IDirect3DRMMeshBuilder3Vtbl Direct3DRMMeshBuilder3_Vtbl =
1971 {
1972     /*** IUnknown methods ***/
1973     IDirect3DRMMeshBuilder3Impl_QueryInterface,
1974     IDirect3DRMMeshBuilder3Impl_AddRef,
1975     IDirect3DRMMeshBuilder3Impl_Release,
1976     /*** IDirect3DRMObject methods ***/
1977     IDirect3DRMMeshBuilder3Impl_Clone,
1978     IDirect3DRMMeshBuilder3Impl_AddDestroyCallback,
1979     IDirect3DRMMeshBuilder3Impl_DeleteDestroyCallback,
1980     IDirect3DRMMeshBuilder3Impl_SetAppData,
1981     IDirect3DRMMeshBuilder3Impl_GetAppData,
1982     IDirect3DRMMeshBuilder3Impl_SetName,
1983     IDirect3DRMMeshBuilder3Impl_GetName,
1984     IDirect3DRMMeshBuilder3Impl_GetClassName,
1985     /*** IDirect3DRMMeshBuilder3 methods ***/
1986     IDirect3DRMMeshBuilder3Impl_Load,
1987     IDirect3DRMMeshBuilder3Impl_Save,
1988     IDirect3DRMMeshBuilder3Impl_Scale,
1989     IDirect3DRMMeshBuilder3Impl_Translate,
1990     IDirect3DRMMeshBuilder3Impl_SetColorSource,
1991     IDirect3DRMMeshBuilder3Impl_GetBox,
1992     IDirect3DRMMeshBuilder3Impl_GenerateNormals,
1993     IDirect3DRMMeshBuilder3Impl_GetColorSource,
1994     IDirect3DRMMeshBuilder3Impl_AddMesh,
1995     IDirect3DRMMeshBuilder3Impl_AddMeshBuilder,
1996     IDirect3DRMMeshBuilder3Impl_AddFrame,
1997     IDirect3DRMMeshBuilder3Impl_AddFace,
1998     IDirect3DRMMeshBuilder3Impl_AddFaces,
1999     IDirect3DRMMeshBuilder3Impl_ReserveSpace,
2000     IDirect3DRMMeshBuilder3Impl_SetColorRGB,
2001     IDirect3DRMMeshBuilder3Impl_SetColor,
2002     IDirect3DRMMeshBuilder3Impl_SetTexture,
2003     IDirect3DRMMeshBuilder3Impl_SetMaterial,
2004     IDirect3DRMMeshBuilder3Impl_SetTextureTopology,
2005     IDirect3DRMMeshBuilder3Impl_SetQuality,
2006     IDirect3DRMMeshBuilder3Impl_SetPerspective,
2007     IDirect3DRMMeshBuilder3Impl_SetVertex,
2008     IDirect3DRMMeshBuilder3Impl_SetNormal,
2009     IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates,
2010     IDirect3DRMMeshBuilder3Impl_SetVertexColor,
2011     IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB,
2012     IDirect3DRMMeshBuilder3Impl_GetFaces,
2013     IDirect3DRMMeshBuilder3Impl_GetGeometry,
2014     IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates,
2015     IDirect3DRMMeshBuilder3Impl_AddVertex,
2016     IDirect3DRMMeshBuilder3Impl_AddNormal,
2017     IDirect3DRMMeshBuilder3Impl_CreateFace,
2018     IDirect3DRMMeshBuilder3Impl_GetQuality,
2019     IDirect3DRMMeshBuilder3Impl_GetPerspective,
2020     IDirect3DRMMeshBuilder3Impl_GetFaceCount,
2021     IDirect3DRMMeshBuilder3Impl_GetVertexCount,
2022     IDirect3DRMMeshBuilder3Impl_GetVertexColor,
2023     IDirect3DRMMeshBuilder3Impl_CreateMesh,
2024     IDirect3DRMMeshBuilder3Impl_GetFace,
2025     IDirect3DRMMeshBuilder3Impl_GetVertex,
2026     IDirect3DRMMeshBuilder3Impl_GetNormal,
2027     IDirect3DRMMeshBuilder3Impl_DeleteVertices,
2028     IDirect3DRMMeshBuilder3Impl_DeleteNormals,
2029     IDirect3DRMMeshBuilder3Impl_DeleteFace,
2030     IDirect3DRMMeshBuilder3Impl_Empty,
2031     IDirect3DRMMeshBuilder3Impl_Optimize,
2032     IDirect3DRMMeshBuilder3Impl_AddFacesIndexed,
2033     IDirect3DRMMeshBuilder3Impl_CreateSubMesh,
2034     IDirect3DRMMeshBuilder3Impl_GetParentMesh,
2035     IDirect3DRMMeshBuilder3Impl_GetSubMeshes,
2036     IDirect3DRMMeshBuilder3Impl_DeleteSubMesh,
2037     IDirect3DRMMeshBuilder3Impl_Enable,
2038     IDirect3DRMMeshBuilder3Impl_GetEnable,
2039     IDirect3DRMMeshBuilder3Impl_AddTriangles,
2040     IDirect3DRMMeshBuilder3Impl_SetVertices,
2041     IDirect3DRMMeshBuilder3Impl_GetVertices,
2042     IDirect3DRMMeshBuilder3Impl_SetNormals,
2043     IDirect3DRMMeshBuilder3Impl_GetNormals,
2044     IDirect3DRMMeshBuilder3Impl_GetNormalCount
2045 };
2046
2047 HRESULT Direct3DRMMeshBuilder_create(REFIID riid, IUnknown** ppObj)
2048 {
2049     IDirect3DRMMeshBuilderImpl* object;
2050
2051     TRACE("(%p)\n", ppObj);
2052
2053     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshBuilderImpl));
2054     if (!object)
2055     {
2056         ERR("Out of memory\n");
2057         return E_OUTOFMEMORY;
2058     }
2059
2060     object->IDirect3DRMMeshBuilder2_iface.lpVtbl = &Direct3DRMMeshBuilder2_Vtbl;
2061     object->IDirect3DRMMeshBuilder3_iface.lpVtbl = &Direct3DRMMeshBuilder3_Vtbl;
2062     object->ref = 1;
2063
2064     if (IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
2065         *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder3_iface;
2066     else
2067         *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder2_iface;
2068
2069     return S_OK;
2070 }
2071
2072 /*** IUnknown methods ***/
2073 static HRESULT WINAPI IDirect3DRMMeshImpl_QueryInterface(IDirect3DRMMesh* iface,
2074                                                          REFIID riid, void** ppvObject)
2075 {
2076     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2077
2078     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
2079
2080     *ppvObject = NULL;
2081
2082     if (IsEqualGUID(riid, &IID_IUnknown) ||
2083         IsEqualGUID(riid, &IID_IDirect3DRMMesh))
2084     {
2085         *ppvObject = &This->IDirect3DRMMesh_iface;
2086     }
2087     else
2088     {
2089         FIXME("interface %s not implemented\n", debugstr_guid(riid));
2090         return E_NOINTERFACE;
2091     }
2092
2093     IDirect3DRMMesh_AddRef(iface);
2094     return S_OK;
2095 }
2096
2097 static ULONG WINAPI IDirect3DRMMeshImpl_AddRef(IDirect3DRMMesh* iface)
2098 {
2099     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2100     ULONG ref = InterlockedIncrement(&This->ref);
2101
2102     TRACE("(%p): AddRef from %d\n", This, ref - 1);
2103
2104     return ref;
2105 }
2106
2107 static ULONG WINAPI IDirect3DRMMeshImpl_Release(IDirect3DRMMesh* iface)
2108 {
2109     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2110     ULONG ref = InterlockedDecrement(&This->ref);
2111
2112     TRACE("(%p): ReleaseRef to %d\n", This, ref);
2113
2114     if (!ref)
2115         HeapFree(GetProcessHeap(), 0, This);
2116
2117     return ref;
2118 }
2119
2120 /*** IDirect3DRMObject methods ***/
2121 static HRESULT WINAPI IDirect3DRMMeshImpl_Clone(IDirect3DRMMesh* iface,
2122                                                 LPUNKNOWN pUnkOuter, REFIID riid,
2123                                                 LPVOID *ppvObj)
2124 {
2125     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2126
2127     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
2128
2129     return E_NOTIMPL;
2130 }
2131
2132 static HRESULT WINAPI IDirect3DRMMeshImpl_AddDestroyCallback(IDirect3DRMMesh* iface,
2133                                                              D3DRMOBJECTCALLBACK cb,
2134                                                              LPVOID argument)
2135 {
2136     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2137
2138     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2139
2140     return E_NOTIMPL;
2141 }
2142
2143 static HRESULT WINAPI IDirect3DRMMeshImpl_DeleteDestroyCallback(IDirect3DRMMesh* iface,
2144                                                                  D3DRMOBJECTCALLBACK cb,
2145                                                                  LPVOID argument)
2146 {
2147     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2148
2149     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2150
2151     return E_NOTIMPL;
2152 }
2153
2154 static HRESULT WINAPI IDirect3DRMMeshImpl_SetAppData(IDirect3DRMMesh* iface,
2155                                                      DWORD data)
2156 {
2157     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2158
2159     FIXME("(%p)->(%u): stub\n", This, data);
2160
2161     return E_NOTIMPL;
2162 }
2163
2164 static DWORD WINAPI IDirect3DRMMeshImpl_GetAppData(IDirect3DRMMesh* iface)
2165 {
2166     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2167
2168     FIXME("(%p)->(): stub\n", This);
2169
2170     return 0;
2171 }
2172
2173 static HRESULT WINAPI IDirect3DRMMeshImpl_SetName(IDirect3DRMMesh* iface,
2174                                                   LPCSTR pName)
2175 {
2176     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2177
2178     FIXME("(%p)->(%s): stub\n", This, pName);
2179
2180     return E_NOTIMPL;
2181 }
2182
2183 static HRESULT WINAPI IDirect3DRMMeshImpl_GetName(IDirect3DRMMesh* iface,
2184                                                   LPDWORD lpdwSize, LPSTR lpName)
2185 {
2186     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2187
2188     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
2189
2190     return E_NOTIMPL;
2191 }
2192
2193 static HRESULT WINAPI IDirect3DRMMeshImpl_GetClassName(IDirect3DRMMesh* iface,
2194                                                        LPDWORD lpdwSize, LPSTR lpName)
2195 {
2196     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2197
2198     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
2199
2200     return E_NOTIMPL;
2201 }
2202
2203 /*** IDirect3DRMMesh methods ***/
2204 static HRESULT WINAPI IDirect3DRMMeshImpl_Scale(IDirect3DRMMesh* iface,
2205                                                 D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
2206 {
2207     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2208
2209     FIXME("(%p)->(%f,%f,%f): stub\n", This, sx, sy,sz);
2210
2211     return E_NOTIMPL;
2212 }
2213
2214 static HRESULT WINAPI IDirect3DRMMeshImpl_Translate(IDirect3DRMMesh* iface,
2215                                                     D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
2216 {
2217     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2218
2219     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty,tz);
2220
2221     return E_NOTIMPL;
2222 }
2223
2224 static HRESULT WINAPI IDirect3DRMMeshImpl_GetBox(IDirect3DRMMesh* iface,
2225                                                  D3DRMBOX * box)
2226 {
2227     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2228
2229     FIXME("(%p)->(%p): stub\n", This, box);
2230
2231     return E_NOTIMPL;
2232 }
2233
2234 static HRESULT WINAPI IDirect3DRMMeshImpl_AddGroup(IDirect3DRMMesh* iface,
2235                                                    unsigned vCount, unsigned fCount, unsigned vPerFace,
2236                                                    unsigned *fData, D3DRMGROUPINDEX *returnId)
2237 {
2238     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2239
2240     FIXME("(%p)->(%u,%u,%u,%p,%p): stub\n", This, vCount, fCount, vPerFace, fData, returnId);
2241
2242     return E_NOTIMPL;
2243 }
2244
2245 static HRESULT WINAPI IDirect3DRMMeshImpl_SetVertices(IDirect3DRMMesh* iface,
2246                                                       D3DRMGROUPINDEX id, unsigned index, unsigned count,
2247                                                       D3DRMVERTEX *values)
2248 {
2249     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2250
2251     FIXME("(%p)->(%u,%u,%u,%p): stub\n", This, id, index, count, values);
2252
2253     return E_NOTIMPL;
2254 }
2255
2256 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColor(IDirect3DRMMesh* iface,
2257                                                         D3DRMGROUPINDEX id, D3DCOLOR value)
2258 {
2259     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2260
2261     FIXME("(%p)->(%u,%x): stub\n", This, id, value);
2262
2263     return E_NOTIMPL;
2264 }
2265
2266 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColorRGB(IDirect3DRMMesh* iface,
2267                                                            D3DRMGROUPINDEX id, D3DVALUE red, D3DVALUE green, D3DVALUE blue)
2268 {
2269     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2270
2271     FIXME("(%p)->(%u,%f,%f,%f): stub\n", This, id, red, green, blue);
2272
2273     return E_NOTIMPL;
2274 }
2275
2276 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMapping(IDirect3DRMMesh* iface,
2277                                                           D3DRMGROUPINDEX id, D3DRMMAPPING value)
2278 {
2279     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2280
2281     FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2282
2283     return E_NOTIMPL;
2284 }
2285
2286 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupQuality(IDirect3DRMMesh* iface,
2287                                                           D3DRMGROUPINDEX id, D3DRMRENDERQUALITY value)
2288 {
2289     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2290
2291     FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2292
2293     return E_NOTIMPL;
2294 }
2295
2296 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMaterial(IDirect3DRMMesh* iface,
2297                                                            D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL value)
2298 {
2299     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2300
2301     FIXME("(%p)->(%u,%p): stub\n", This, id, value);
2302
2303     return E_NOTIMPL;
2304 }
2305
2306 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupTexture(IDirect3DRMMesh* iface,
2307                                                           D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE value)
2308 {
2309     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2310
2311     FIXME("(%p)->(%u,%p): stub\n", This, id, value);
2312
2313     return E_NOTIMPL;
2314 }
2315
2316 static DWORD WINAPI IDirect3DRMMeshImpl_GetGroupCount(IDirect3DRMMesh* iface)
2317 {
2318     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2319
2320     FIXME("(%p)->(): stub\n", This);
2321
2322     return 0;
2323 }
2324
2325 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroup(IDirect3DRMMesh* iface,
2326                                                    D3DRMGROUPINDEX id, unsigned *vCount, unsigned *fCount, unsigned *vPerFace,
2327                                                    DWORD *fDataSize, unsigned *fData)
2328 {
2329     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2330
2331     FIXME("(%p)->(%u,%p,%p,%p,%p,%p): stub\n", This, id, vCount, fCount, vPerFace, fDataSize, fData);
2332
2333     return E_NOTIMPL;
2334 }
2335
2336 static HRESULT WINAPI IDirect3DRMMeshImpl_GetVertices(IDirect3DRMMesh* iface,
2337                                                       D3DRMGROUPINDEX id, DWORD index, DWORD count, D3DRMVERTEX *returnPtr)
2338 {
2339     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2340
2341     FIXME("(%p)->(%u,%u,%u,%p): stub\n", This, id, index, count, returnPtr);
2342
2343     return E_NOTIMPL;
2344 }
2345
2346 static D3DCOLOR WINAPI IDirect3DRMMeshImpl_GetGroupColor(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2347 {
2348     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2349
2350     FIXME("(%p)->(%u): stub\n", This, id);
2351
2352     return 0;
2353 }
2354
2355 static D3DRMMAPPING WINAPI IDirect3DRMMeshImpl_GetGroupMapping(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2356 {
2357     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2358
2359     FIXME("(%p)->(%u): stub\n", This, id);
2360
2361     return 0;
2362 }
2363 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshImpl_GetGroupQuality(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2364 {
2365     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2366
2367     FIXME("(%p)->(%u): stub\n", This, id);
2368
2369     return 0;
2370 }
2371
2372 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupMaterial(IDirect3DRMMesh* iface,
2373                                                            D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL *returnPtr)
2374 {
2375     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2376
2377     FIXME("(%p)->(%u,%p): stub\n", This, id, returnPtr);
2378
2379     return E_NOTIMPL;
2380 }
2381
2382 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupTexture(IDirect3DRMMesh* iface,
2383                                                           D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE *returnPtr)
2384 {
2385     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2386
2387     FIXME("(%p)->(%u,%p): stub\n", This, id, returnPtr);
2388
2389     return E_NOTIMPL;
2390 }
2391
2392 static const struct IDirect3DRMMeshVtbl Direct3DRMMesh_Vtbl =
2393 {
2394     /*** IUnknown methods ***/
2395     IDirect3DRMMeshImpl_QueryInterface,
2396     IDirect3DRMMeshImpl_AddRef,
2397     IDirect3DRMMeshImpl_Release,
2398     /*** IDirect3DRMObject methods ***/
2399     IDirect3DRMMeshImpl_Clone,
2400     IDirect3DRMMeshImpl_AddDestroyCallback,
2401     IDirect3DRMMeshImpl_DeleteDestroyCallback,
2402     IDirect3DRMMeshImpl_SetAppData,
2403     IDirect3DRMMeshImpl_GetAppData,
2404     IDirect3DRMMeshImpl_SetName,
2405     IDirect3DRMMeshImpl_GetName,
2406     IDirect3DRMMeshImpl_GetClassName,
2407     /*** IDirect3DRMMesh methods ***/
2408     IDirect3DRMMeshImpl_Scale,
2409     IDirect3DRMMeshImpl_Translate,
2410     IDirect3DRMMeshImpl_GetBox,
2411     IDirect3DRMMeshImpl_AddGroup,
2412     IDirect3DRMMeshImpl_SetVertices,
2413     IDirect3DRMMeshImpl_SetGroupColor,
2414     IDirect3DRMMeshImpl_SetGroupColorRGB,
2415     IDirect3DRMMeshImpl_SetGroupMapping,
2416     IDirect3DRMMeshImpl_SetGroupQuality,
2417     IDirect3DRMMeshImpl_SetGroupMaterial,
2418     IDirect3DRMMeshImpl_SetGroupTexture,
2419     IDirect3DRMMeshImpl_GetGroupCount,
2420     IDirect3DRMMeshImpl_GetGroup,
2421     IDirect3DRMMeshImpl_GetVertices,
2422     IDirect3DRMMeshImpl_GetGroupColor,
2423     IDirect3DRMMeshImpl_GetGroupMapping,
2424     IDirect3DRMMeshImpl_GetGroupQuality,
2425     IDirect3DRMMeshImpl_GetGroupMaterial,
2426     IDirect3DRMMeshImpl_GetGroupTexture
2427 };
2428
2429 static HRESULT Direct3DRMMesh_create(IDirect3DRMMesh** obj)
2430 {
2431     IDirect3DRMMeshImpl* object;
2432
2433     TRACE("(%p)\n", obj);
2434
2435     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshImpl));
2436     if (!object)
2437     {
2438         ERR("Out of memory\n");
2439         return E_OUTOFMEMORY;
2440     }
2441
2442     object->IDirect3DRMMesh_iface.lpVtbl = &Direct3DRMMesh_Vtbl;
2443     object->ref = 1;
2444
2445     *obj = &object->IDirect3DRMMesh_iface;
2446
2447     return S_OK;
2448 }