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