d3drm: Pass texture of mesh builder to newly created mesh.
[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 pMaterial)
655 {
656     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder2(iface);
657
658     FIXME("(%p)->(%p): stub\n", This, pMaterial);
659
660     return E_NOTIMPL;
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                     vertex_idx = 0;
1371                 *(faces_data_ptr + faces_data_size++) = vertex_idx;
1372                 /* Add face normal to vertex normal */
1373                 D3DRMVectorAdd(&This->pNormals[vertex_idx], &This->pNormals[vertex_idx], &face_normal);
1374             }
1375             faces_vertex_idx_ptr++;
1376         }
1377         faces_vertex_idx_size -= nb_face_indexes;
1378     }
1379
1380     /* Last DWORD must be 0 */
1381     *(faces_data_ptr + faces_data_size++) = 0;
1382
1383     /* Set size (in number of DWORD) of all faces data */
1384     This->face_data_size = faces_data_size;
1385
1386     if (!This->nb_normals)
1387     {
1388         /* Normalize all normals */
1389         for (i = 0; i < This->nb_vertices; i++)
1390         {
1391             D3DRMVectorNormalize(&This->pNormals[i]);
1392         }
1393         This->nb_normals = This->nb_vertices;
1394     }
1395
1396     /* If there is no texture coordinates, generate default texture coordinates (0.0f, 0.0f) for each vertex */
1397     if (!This->pCoords2d)
1398     {
1399         This->nb_coords2d = This->nb_vertices;
1400         This->pCoords2d = HeapAlloc(GetProcessHeap(), 0, This->nb_coords2d * sizeof(Coords2d));
1401         for (i = 0; i < This->nb_coords2d; i++)
1402         {
1403             This->pCoords2d[i].u = 0.0f;
1404             This->pCoords2d[i].v = 0.0f;
1405         }
1406     }
1407
1408     TRACE("Mesh data loaded successfully\n");
1409
1410     ret = D3DRM_OK;
1411
1412 end:
1413
1414     HeapFree(GetProcessHeap(), 0, faces_normal_idx_data);
1415     HeapFree(GetProcessHeap(), 0, faces_vertex_idx_data);
1416
1417     return ret;
1418 }
1419
1420 /*** IDirect3DRMMeshBuilder3 methods ***/
1421 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Load(IDirect3DRMMeshBuilder3* iface,
1422                                                        LPVOID filename, LPVOID name,
1423                                                        D3DRMLOADOPTIONS loadflags,
1424                                                        D3DRMLOADTEXTURE3CALLBACK cb, LPVOID arg)
1425 {
1426     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1427     DXFILELOADOPTIONS load_options;
1428     LPDIRECTXFILE pDXFile = NULL;
1429     LPDIRECTXFILEENUMOBJECT pEnumObject = NULL;
1430     LPDIRECTXFILEDATA pData = NULL;
1431     LPDIRECTXFILEDATA pData2 = NULL;
1432     const GUID* pGuid;
1433     DWORD size;
1434     Header* pHeader;
1435     HRESULT hr;
1436     HRESULT ret = D3DRMERR_BADOBJECT;
1437
1438     TRACE("(%p)->(%p,%p,%x,%p,%p)\n", This, filename, name, loadflags, cb, arg);
1439
1440     /* First free allocated buffers of previous mesh data */
1441     HeapFree(GetProcessHeap(), 0, This->pVertices);
1442     This->pVertices = NULL;
1443     HeapFree(GetProcessHeap(), 0, This->pNormals);
1444     This->pNormals = NULL;
1445     HeapFree(GetProcessHeap(), 0, This->pFaceData);
1446     This->pFaceData = NULL;
1447     HeapFree(GetProcessHeap(), 0, This->pCoords2d);
1448     This->pCoords2d = NULL;
1449
1450     if (loadflags == D3DRMLOAD_FROMMEMORY)
1451     {
1452         load_options = DXFILELOAD_FROMMEMORY;
1453     }
1454     else if (loadflags == D3DRMLOAD_FROMFILE)
1455     {
1456         load_options = DXFILELOAD_FROMFILE;
1457         TRACE("Loading from file %s\n", debugstr_a(filename));
1458     }
1459     else
1460     {
1461         FIXME("Load options %d not supported yet\n", loadflags);
1462         return E_NOTIMPL;
1463     }
1464
1465     hr = DirectXFileCreate(&pDXFile);
1466     if (hr != DXFILE_OK)
1467         goto end;
1468
1469     hr = IDirectXFile_RegisterTemplates(pDXFile, templates, strlen(templates));
1470     if (hr != DXFILE_OK)
1471         goto end;
1472
1473     hr = IDirectXFile_CreateEnumObject(pDXFile, filename, load_options, &pEnumObject);
1474     if (hr != DXFILE_OK)
1475         goto end;
1476
1477     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
1478     if (hr != DXFILE_OK)
1479         goto end;
1480
1481     hr = IDirectXFileData_GetType(pData, &pGuid);
1482     if (hr != DXFILE_OK)
1483         goto end;
1484
1485     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1486
1487     if (!IsEqualGUID(pGuid, &TID_DXFILEHeader))
1488     {
1489         ret = D3DRMERR_BADFILE;
1490         goto end;
1491     }
1492
1493     hr = IDirectXFileData_GetData(pData, NULL, &size, (void**)&pHeader);
1494     if ((hr != DXFILE_OK) || (size != sizeof(Header)))
1495         goto end;
1496
1497     TRACE("Version is %d %d %d\n", pHeader->major, pHeader->minor, pHeader->flags);
1498
1499     /* Version must be 1.0.x */
1500     if ((pHeader->major != 1) || (pHeader->minor != 0))
1501     {
1502         ret = D3DRMERR_BADFILE;
1503         goto end;
1504     }
1505
1506     IDirectXFileData_Release(pData);
1507     pData = NULL;
1508
1509     hr = IDirectXFileEnumObject_GetNextDataObject(pEnumObject, &pData);
1510     if (hr != DXFILE_OK)
1511     {
1512         ret = D3DRMERR_NOTFOUND;
1513         goto end;
1514     }
1515
1516     hr = IDirectXFileData_GetType(pData, &pGuid);
1517     if (hr != DXFILE_OK)
1518         goto end;
1519
1520     TRACE("Found object type whose GUID = %s\n", debugstr_guid(pGuid));
1521
1522     if (!IsEqualGUID(pGuid, &TID_D3DRMMesh))
1523     {
1524         ret = D3DRMERR_NOTFOUND;
1525         goto end;
1526     }
1527
1528     hr = load_mesh_data(iface, pData);
1529     if (hr == S_OK)
1530         ret = D3DRM_OK;
1531
1532 end:
1533
1534     if (pData2)
1535         IDirectXFileData_Release(pData2);
1536     if (pData)
1537         IDirectXFileData_Release(pData);
1538     if (pEnumObject)
1539         IDirectXFileEnumObject_Release(pEnumObject);
1540     if (pDXFile)
1541         IDirectXFile_Release(pDXFile);
1542
1543     if (ret != D3DRM_OK)
1544     {
1545         /* Clean mesh data */
1546         This->nb_vertices = 0;
1547         This->nb_normals = 0;
1548         This->nb_faces = 0;
1549         This->face_data_size = 0;
1550         This->nb_coords2d = 0;
1551         HeapFree(GetProcessHeap(), 0, This->pVertices);
1552         This->pVertices = NULL;
1553         HeapFree(GetProcessHeap(), 0, This->pNormals);
1554         This->pNormals = NULL;
1555         HeapFree(GetProcessHeap(), 0, This->pFaceData);
1556         This->pFaceData = NULL;
1557         HeapFree(GetProcessHeap(), 0, This->pCoords2d);
1558         This->pCoords2d = NULL;
1559     }
1560
1561     return ret;
1562 }
1563
1564 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Save(IDirect3DRMMeshBuilder3* iface,
1565                                                        const char* filename, D3DRMXOFFORMAT format,
1566                                                        D3DRMSAVEOPTIONS save)
1567 {
1568     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1569
1570     FIXME("(%p)->(%s,%d,%d): stub\n", This, filename, format, save);
1571
1572     return E_NOTIMPL;
1573 }
1574
1575 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Scale(IDirect3DRMMeshBuilder3* iface,
1576                                                         D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
1577 {
1578     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1579     int i;
1580
1581     TRACE("(%p)->(%f,%f,%f)\n", This, sx, sy, sz);
1582
1583     for (i = 0; i < This->nb_vertices; i++)
1584     {
1585         This->pVertices[i].u1.x *= sx;
1586         This->pVertices[i].u2.y *= sy;
1587         This->pVertices[i].u3.z *= sz;
1588     }
1589
1590     /* Normals are not affected by Scale */
1591
1592     return D3DRM_OK;
1593 }
1594
1595 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Translate(IDirect3DRMMeshBuilder3* iface,
1596                                                             D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
1597 {
1598     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1599
1600     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty, tz);
1601
1602     return E_NOTIMPL;
1603 }
1604
1605 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorSource(IDirect3DRMMeshBuilder3* iface,
1606                                                                  D3DRMCOLORSOURCE color)
1607 {
1608     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1609
1610     FIXME("(%p)->(%x): stub\n", This, color);
1611
1612     return E_NOTIMPL;
1613 }
1614
1615 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetBox(IDirect3DRMMeshBuilder3* iface,
1616                                                          D3DRMBOX* box)
1617 {
1618     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1619
1620     FIXME("(%p)->(%p): stub\n", This, box);
1621
1622     return E_NOTIMPL;
1623 }
1624
1625 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GenerateNormals(IDirect3DRMMeshBuilder3* iface,
1626                                                                   D3DVALUE crease, DWORD flags)
1627 {
1628     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1629
1630     FIXME("(%p)->(%f,%u): stub\n", This, crease, flags);
1631
1632     return E_NOTIMPL;
1633 }
1634
1635 static D3DRMCOLORSOURCE WINAPI IDirect3DRMMeshBuilder3Impl_GetColorSource(IDirect3DRMMeshBuilder3* iface)
1636 {
1637     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1638
1639     FIXME("(%p)->(): stub\n", This);
1640
1641     return E_NOTIMPL;
1642 }
1643
1644 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMesh(IDirect3DRMMeshBuilder3* iface,
1645                                                           LPDIRECT3DRMMESH Mesh)
1646 {
1647     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1648
1649     FIXME("(%p)->(%p): stub\n", This, Mesh);
1650
1651     return E_NOTIMPL;
1652 }
1653
1654 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddMeshBuilder(IDirect3DRMMeshBuilder3* iface,
1655                                                                  LPDIRECT3DRMMESHBUILDER3 MeshBuilder,
1656                                                                  DWORD flags)
1657 {
1658     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1659
1660     FIXME("(%p)->(%p,%u): stub\n", This, MeshBuilder, flags);
1661
1662     return E_NOTIMPL;
1663 }
1664
1665 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFrame(IDirect3DRMMeshBuilder3* iface,
1666                                                            LPDIRECT3DRMFRAME3 Frame)
1667 {
1668     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1669
1670     FIXME("(%p)->(%p): stub\n", This, Frame);
1671
1672     return E_NOTIMPL;
1673 }
1674
1675 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFace(IDirect3DRMMeshBuilder3* iface,
1676                                                           LPDIRECT3DRMFACE2 Face)
1677 {
1678     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1679
1680     FIXME("(%p)->(%p): stub\n", This, Face);
1681
1682     return E_NOTIMPL;
1683 }
1684
1685 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFaces(IDirect3DRMMeshBuilder3* iface,
1686                                                            DWORD vcount, D3DVECTOR* vertices,
1687                                                            DWORD ncount, D3DVECTOR* normals,
1688                                                            DWORD* data,
1689                                                            LPDIRECT3DRMFACEARRAY* FaceArray)
1690 {
1691     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1692
1693     FIXME("(%p)->(%d,%p,%d,%p,%p,%p): stub\n", This, vcount, vertices, ncount,
1694           normals, data, FaceArray);
1695
1696     return E_NOTIMPL;
1697 }
1698
1699 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_ReserveSpace(IDirect3DRMMeshBuilder3* iface,
1700                                                                DWORD vertex_Count,
1701                                                                DWORD normal_count,
1702                                                                DWORD face_count)
1703 {
1704     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1705
1706     FIXME("(%p)->(%d,%d,%d): stub\n", This, vertex_Count, normal_count, face_count);
1707
1708     return E_NOTIMPL;
1709 }
1710
1711 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColorRGB(IDirect3DRMMeshBuilder3* iface,
1712                                                               D3DVALUE red, D3DVALUE green,
1713                                                               D3DVALUE blue)
1714 {
1715     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1716
1717     TRACE("(%p)->(%f,%f,%f)\n", This, red, green, blue);
1718
1719     This->color = D3DCOLOR_ARGB(0xff, (BYTE)(red   * 255.0f),
1720                                       (BYTE)(green * 255.0f),
1721                                       (BYTE)(blue  * 255.0f));
1722
1723     return D3DRM_OK;
1724 }
1725
1726 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetColor(IDirect3DRMMeshBuilder3* iface,
1727                                                            D3DCOLOR color)
1728 {
1729     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1730
1731     TRACE("(%p)->(%x)\n", This, color);
1732
1733     This->color = color;
1734
1735     return D3DRM_OK;
1736 }
1737
1738 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTexture(IDirect3DRMMeshBuilder3* iface,
1739                                                              LPDIRECT3DRMTEXTURE3 texture)
1740 {
1741     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1742
1743     TRACE("(%p)->(%p)\n", This, texture);
1744
1745     if (texture)
1746         IDirect3DRMTexture3_AddRef(texture);
1747     if (This->texture)
1748         IDirect3DRMTexture3_Release(This->texture);
1749     This->texture = texture;
1750
1751     return D3DRM_OK;
1752 }
1753
1754 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetMaterial(IDirect3DRMMeshBuilder3* iface,
1755                                                               LPDIRECT3DRMMATERIAL2 material)
1756 {
1757     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1758
1759     FIXME("(%p)->(%p): stub\n", This, material);
1760
1761     return E_NOTIMPL;
1762 }
1763
1764 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureTopology(IDirect3DRMMeshBuilder3* iface,
1765                                                                      BOOL wrap_u, BOOL wrap_v)
1766 {
1767     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1768
1769     FIXME("(%p)->(%d,%d): stub\n", This, wrap_u, wrap_v);
1770
1771     return E_NOTIMPL;
1772 }
1773
1774 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetQuality(IDirect3DRMMeshBuilder3* iface,
1775                                                              D3DRMRENDERQUALITY quality)
1776 {
1777     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1778
1779     FIXME("(%p)->(%d): stub\n", This, quality);
1780
1781     return E_NOTIMPL;
1782 }
1783
1784 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetPerspective(IDirect3DRMMeshBuilder3* iface,
1785                                                                  BOOL enable)
1786 {
1787     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1788
1789     FIXME("(%p)->(%d): stub\n", This, enable);
1790
1791     return E_NOTIMPL;
1792 }
1793
1794 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertex(IDirect3DRMMeshBuilder3* iface,
1795                                                             DWORD index,
1796                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
1797 {
1798     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1799
1800     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1801
1802     return E_NOTIMPL;
1803 }
1804
1805 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormal(IDirect3DRMMeshBuilder3* iface,
1806                                                             DWORD index,
1807                                                             D3DVALUE x, D3DVALUE y, D3DVALUE z)
1808 {
1809     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1810
1811     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1812
1813     return E_NOTIMPL;
1814 }
1815
1816 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1817                                                                         DWORD index, D3DVALUE u,
1818                                                                         D3DVALUE v)
1819 {
1820     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1821
1822     TRACE("(%p)->(%u,%f,%f)\n", This, index, u, v);
1823
1824     if (index >= This->nb_coords2d)
1825         return D3DRMERR_BADVALUE;
1826
1827     This->pCoords2d[index].u = u;
1828     This->pCoords2d[index].v = v;
1829
1830     return D3DRM_OK;
1831 }
1832
1833 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColor(IDirect3DRMMeshBuilder3* iface,
1834                                                                  DWORD index, D3DCOLOR color)
1835 {
1836     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1837
1838     FIXME("(%p)->(%d,%x): stub\n", This, index, color);
1839
1840     return E_NOTIMPL;
1841 }
1842
1843 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB(IDirect3DRMMeshBuilder3* iface,
1844                                                                     DWORD index,
1845                                                                     D3DVALUE red, D3DVALUE green,
1846                                                                     D3DVALUE blue)
1847 {
1848     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1849
1850     FIXME("(%p)->(%d,%f,%f,%f): stub\n", This, index, red, green, blue);
1851
1852     return E_NOTIMPL;
1853 }
1854
1855 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFaces(IDirect3DRMMeshBuilder3* iface,
1856                                                            LPDIRECT3DRMFACEARRAY* FaceArray)
1857 {
1858     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1859
1860     FIXME("(%p)->(%p): stub\n", This, FaceArray);
1861
1862     return E_NOTIMPL;
1863 }
1864
1865 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetGeometry(IDirect3DRMMeshBuilder3* iface,
1866                                                               DWORD* vcount, D3DVECTOR* vertices,
1867                                                               DWORD* ncount, D3DVECTOR* normals,
1868                                                               DWORD* face_data_size,
1869                                                               DWORD* face_data)
1870 {
1871     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1872
1873     FIXME("(%p)->(%p,%p,%p,%p,%p,%p): stub\n", This, vcount, vertices, ncount, normals,
1874           face_data_size, face_data);
1875
1876     return E_NOTIMPL;
1877 }
1878
1879 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates(IDirect3DRMMeshBuilder3* iface,
1880                                                                         DWORD index, D3DVALUE* u,
1881                                                                         D3DVALUE* v)
1882 {
1883     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1884
1885     TRACE("(%p)->(%d,%p,%p)\n", This, index, u, v);
1886
1887     if (index >= This->nb_coords2d)
1888         return D3DRMERR_BADVALUE;
1889
1890     *u = This->pCoords2d[index].u;
1891     *v = This->pCoords2d[index].v;
1892
1893     return D3DRM_OK;
1894 }
1895
1896
1897 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddVertex(IDirect3DRMMeshBuilder3* iface,
1898                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
1899 {
1900     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1901
1902     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1903
1904     return 0;
1905 }
1906
1907 static int WINAPI IDirect3DRMMeshBuilder3Impl_AddNormal(IDirect3DRMMeshBuilder3* iface,
1908                                                         D3DVALUE x, D3DVALUE y, D3DVALUE z)
1909 {
1910     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1911
1912     FIXME("(%p)->(%f,%f,%f): stub\n", This, x, y, z);
1913
1914     return 0;
1915 }
1916
1917 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateFace(IDirect3DRMMeshBuilder3* iface,
1918                                                              LPDIRECT3DRMFACE2* Face)
1919 {
1920     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1921
1922     FIXME("(%p)->(%p): stub\n", This, Face);
1923
1924     return E_NOTIMPL;
1925 }
1926
1927 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshBuilder3Impl_GetQuality(IDirect3DRMMeshBuilder3* iface)
1928 {
1929     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1930
1931     FIXME("(%p)->(): stub\n", This);
1932
1933     return 0;
1934 }
1935
1936 static BOOL WINAPI IDirect3DRMMeshBuilder3Impl_GetPerspective(IDirect3DRMMeshBuilder3* iface)
1937 {
1938     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1939
1940     FIXME("(%p)->(): stub\n", This);
1941
1942     return FALSE;
1943 }
1944
1945 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetFaceCount(IDirect3DRMMeshBuilder3* iface)
1946 {
1947     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1948
1949     TRACE("(%p)->()\n", This);
1950
1951     return This->nb_faces;
1952 }
1953
1954 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexCount(IDirect3DRMMeshBuilder3* iface)
1955 {
1956     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1957
1958     TRACE("(%p)->()\n", This);
1959
1960     return This->nb_vertices;
1961 }
1962
1963 static D3DCOLOR WINAPI IDirect3DRMMeshBuilder3Impl_GetVertexColor(IDirect3DRMMeshBuilder3* iface,
1964                                                                   DWORD index)
1965 {
1966     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1967
1968     FIXME("(%p)->(%d): stub\n", This, index);
1969
1970     return 0;
1971 }
1972
1973 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateMesh(IDirect3DRMMeshBuilder3* iface,
1974                                                              LPDIRECT3DRMMESH* mesh)
1975 {
1976     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
1977     HRESULT hr;
1978     D3DRMGROUPINDEX group;
1979
1980     TRACE("(%p)->(%p)\n", This, mesh);
1981
1982     if (!mesh)
1983         return E_POINTER;
1984
1985     hr = Direct3DRMMesh_create(mesh);
1986     if (FAILED(hr))
1987         return hr;
1988
1989     /* If there is mesh data, create a group and put data inside */
1990     if (This->nb_vertices)
1991     {
1992         unsigned* face_data;
1993         unsigned* out_ptr;
1994         DWORD* in_ptr = This->pFaceData;
1995         int i, j;
1996
1997         face_data = HeapAlloc(GetProcessHeap(), 0, This->face_data_size * sizeof(DWORD));
1998         if (!face_data)
1999         {
2000             IDirect3DRMMesh_Release(*mesh);
2001             return E_OUTOFMEMORY;
2002         }
2003         out_ptr = face_data;
2004
2005         /* Put only vertex indices */
2006         for (i = 0; i < This->nb_faces; i++)
2007         {
2008             DWORD nb_indices = *out_ptr++ = *in_ptr++;
2009             for (j = 0; j < nb_indices; j++)
2010             {
2011                 *out_ptr++ = *in_ptr++;
2012                 /* Skip normal index */
2013                 in_ptr++;
2014             }
2015         }
2016
2017         hr = IDirect3DRMMesh_AddGroup(*mesh, This->nb_vertices, This->nb_faces, 0, face_data, &group);
2018         HeapFree(GetProcessHeap(), 0, face_data);
2019         if (SUCCEEDED(hr))
2020         {
2021             D3DRMVERTEX* vertices;
2022
2023             vertices = HeapAlloc(GetProcessHeap(), 0, This->nb_vertices * sizeof(D3DRMVERTEX));
2024             if (vertices)
2025             {
2026                 for (i = 0; i < This->nb_vertices; i++)
2027                 {
2028                     vertices[i].position = This->pVertices[i];
2029                 }
2030                 hr = IDirect3DRMMesh_SetVertices(*mesh, 0, 0, This->nb_vertices, vertices);
2031                 HeapFree(GetProcessHeap(), 0, vertices);
2032             }
2033             else
2034             {
2035                 hr = E_OUTOFMEMORY;
2036             }
2037         }
2038         if (SUCCEEDED(hr))
2039             hr = IDirect3DRMMesh_SetGroupColor(*mesh, 0, This->color);
2040         if (SUCCEEDED(hr))
2041             hr = IDirect3DRMMesh_SetGroupMaterial(*mesh, 0, (LPDIRECT3DRMMATERIAL)This->material);
2042         if (SUCCEEDED(hr) && This->texture)
2043         {
2044              LPDIRECT3DRMTEXTURE texture;
2045
2046              IDirect3DRMTexture3_QueryInterface(This->texture, &IID_IDirect3DRMTexture, (LPVOID*)&texture);
2047              hr = IDirect3DRMMesh_SetGroupTexture(*mesh, 0, texture);
2048              IDirect3DRMTexture_Release(texture);
2049         }
2050         if (FAILED(hr))
2051             IDirect3DRMMesh_Release(*mesh);
2052     }
2053
2054     return hr;
2055 }
2056
2057 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetFace(IDirect3DRMMeshBuilder3* iface,
2058                                                           DWORD index, LPDIRECT3DRMFACE2* Face)
2059 {
2060     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2061
2062     FIXME("(%p)->(%u,%p): stub\n", This, index, Face);
2063
2064     return E_NOTIMPL;
2065 }
2066
2067 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertex(IDirect3DRMMeshBuilder3* iface,
2068                                                             DWORD index, LPD3DVECTOR vector)
2069 {
2070     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2071
2072     FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
2073
2074     return E_NOTIMPL;
2075 }
2076
2077 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormal(IDirect3DRMMeshBuilder3* iface,
2078                                                             DWORD index, LPD3DVECTOR vector)
2079 {
2080     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2081
2082     FIXME("(%p)->(%u,%p): stub\n", This, index, vector);
2083
2084     return E_NOTIMPL;
2085 }
2086
2087 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteVertices(IDirect3DRMMeshBuilder3* iface,
2088                                                                  DWORD IndexFirst, DWORD count)
2089 {
2090     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2091
2092     FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
2093
2094     return E_NOTIMPL;
2095 }
2096
2097 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteNormals(IDirect3DRMMeshBuilder3* iface,
2098                                                                 DWORD IndexFirst, DWORD count)
2099 {
2100     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2101
2102     FIXME("(%p)->(%u,%u): stub\n", This, IndexFirst, count);
2103
2104     return E_NOTIMPL;
2105 }
2106
2107 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteFace(IDirect3DRMMeshBuilder3* iface,
2108                                                              LPDIRECT3DRMFACE2 Face)
2109 {
2110     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2111
2112     FIXME("(%p)->(%p): stub\n", This, Face);
2113
2114     return E_NOTIMPL;
2115 }
2116
2117 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Empty(IDirect3DRMMeshBuilder3* iface, DWORD flags)
2118 {
2119     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2120
2121     FIXME("(%p)->(%u): stub\n", This, flags);
2122
2123     return E_NOTIMPL;
2124 }
2125
2126 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Optimize(IDirect3DRMMeshBuilder3* iface,
2127                                                            DWORD flags)
2128 {
2129     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2130
2131     FIXME("(%p)->(%u): stub\n", This, flags);
2132
2133     return E_NOTIMPL;
2134 }
2135
2136 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddFacesIndexed(IDirect3DRMMeshBuilder3* iface,
2137                                                                   DWORD flags, DWORD* indices,
2138                                                                   DWORD* IndexFirst, DWORD* count)
2139 {
2140     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2141
2142     FIXME("(%p)->(%u,%p,%p,%p): stub\n", This, flags, indices, IndexFirst, count);
2143
2144     return E_NOTIMPL;
2145 }
2146
2147 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_CreateSubMesh(IDirect3DRMMeshBuilder3* iface,
2148                                                                 LPUNKNOWN *unkwn)
2149 {
2150     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2151
2152     FIXME("(%p)->(%p): stub\n", This, unkwn);
2153
2154     return E_NOTIMPL;
2155 }
2156
2157 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetParentMesh(IDirect3DRMMeshBuilder3* iface,
2158                                                                 DWORD flags, LPUNKNOWN *unkwn)
2159 {
2160     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2161
2162     FIXME("(%p)->(%u,%p): stub\n", This, flags, unkwn);
2163
2164     return E_NOTIMPL;
2165 }
2166
2167 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetSubMeshes(IDirect3DRMMeshBuilder3* iface,
2168                                                                LPDWORD count, LPUNKNOWN *unkwn)
2169 {
2170     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2171
2172     FIXME("(%p)->(%p,%p): stub\n", This, count, unkwn);
2173
2174     return E_NOTIMPL;
2175 }
2176
2177 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_DeleteSubMesh(IDirect3DRMMeshBuilder3* iface,
2178                                                                 LPUNKNOWN unkwn)
2179 {
2180     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2181
2182     FIXME("(%p)->(%p): stub\n", This, unkwn);
2183
2184     return E_NOTIMPL;
2185 }
2186
2187 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_Enable(IDirect3DRMMeshBuilder3* iface,
2188                                                          DWORD index)
2189 {
2190     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2191
2192     FIXME("(%p)->(%u): stub\n", This, index);
2193
2194     return E_NOTIMPL;
2195 }
2196
2197 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetEnable(IDirect3DRMMeshBuilder3* iface,
2198                                                             DWORD* indices)
2199 {
2200     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2201
2202     FIXME("(%p)->(%p): stub\n", This, indices);
2203
2204     return E_NOTIMPL;
2205 }
2206
2207 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_AddTriangles(IDirect3DRMMeshBuilder3* iface,
2208                                                                DWORD flags, DWORD format,
2209                                                                DWORD VertexCount, LPVOID data)
2210 {
2211     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2212
2213     FIXME("(%p)->(%u,%u,%u,%p): stub\n", This, flags, format, VertexCount, data);
2214
2215     return E_NOTIMPL;
2216 }
2217
2218 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetVertices(IDirect3DRMMeshBuilder3* iface,
2219                                                               DWORD IndexFirst, DWORD count,
2220                                                               LPD3DVECTOR vector)
2221 {
2222     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2223
2224     FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
2225
2226     return E_NOTIMPL;
2227 }
2228
2229 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetVertices(IDirect3DRMMeshBuilder3* iface,
2230                                                               DWORD IndexFirst, LPDWORD vcount,
2231                                                               LPD3DVECTOR vertices)
2232 {
2233     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2234     DWORD count = This->nb_vertices - IndexFirst;
2235
2236     TRACE("(%p)->(%u,%p,%p)\n", This, IndexFirst, vcount, vertices);
2237
2238     if (vcount)
2239         *vcount = count;
2240     if (vertices && This->nb_vertices)
2241         memcpy(vertices, This->pVertices + IndexFirst, count * sizeof(D3DVECTOR));
2242
2243     return D3DRM_OK;
2244 }
2245
2246 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_SetNormals(IDirect3DRMMeshBuilder3* iface,
2247                                                              DWORD IndexFirst, DWORD count,
2248                                                              LPD3DVECTOR vector)
2249 {
2250     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2251
2252     FIXME("(%p)->(%u,%u,%p): stub\n", This, IndexFirst, count, vector);
2253
2254     return E_NOTIMPL;
2255 }
2256
2257 static HRESULT WINAPI IDirect3DRMMeshBuilder3Impl_GetNormals(IDirect3DRMMeshBuilder3* iface,
2258                                                              DWORD IndexFirst, LPDWORD count,
2259                                                              LPD3DVECTOR vector)
2260 {
2261     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2262
2263     FIXME("(%p)->(%u,%p,%p): stub\n", This, IndexFirst, count, vector);
2264
2265     return E_NOTIMPL;
2266 }
2267
2268 static int WINAPI IDirect3DRMMeshBuilder3Impl_GetNormalCount(IDirect3DRMMeshBuilder3* iface)
2269 {
2270     IDirect3DRMMeshBuilderImpl *This = impl_from_IDirect3DRMMeshBuilder3(iface);
2271
2272     FIXME("(%p)->(): stub\n", This);
2273
2274     return E_NOTIMPL;
2275 }
2276
2277 static const struct IDirect3DRMMeshBuilder3Vtbl Direct3DRMMeshBuilder3_Vtbl =
2278 {
2279     /*** IUnknown methods ***/
2280     IDirect3DRMMeshBuilder3Impl_QueryInterface,
2281     IDirect3DRMMeshBuilder3Impl_AddRef,
2282     IDirect3DRMMeshBuilder3Impl_Release,
2283     /*** IDirect3DRMObject methods ***/
2284     IDirect3DRMMeshBuilder3Impl_Clone,
2285     IDirect3DRMMeshBuilder3Impl_AddDestroyCallback,
2286     IDirect3DRMMeshBuilder3Impl_DeleteDestroyCallback,
2287     IDirect3DRMMeshBuilder3Impl_SetAppData,
2288     IDirect3DRMMeshBuilder3Impl_GetAppData,
2289     IDirect3DRMMeshBuilder3Impl_SetName,
2290     IDirect3DRMMeshBuilder3Impl_GetName,
2291     IDirect3DRMMeshBuilder3Impl_GetClassName,
2292     /*** IDirect3DRMMeshBuilder3 methods ***/
2293     IDirect3DRMMeshBuilder3Impl_Load,
2294     IDirect3DRMMeshBuilder3Impl_Save,
2295     IDirect3DRMMeshBuilder3Impl_Scale,
2296     IDirect3DRMMeshBuilder3Impl_Translate,
2297     IDirect3DRMMeshBuilder3Impl_SetColorSource,
2298     IDirect3DRMMeshBuilder3Impl_GetBox,
2299     IDirect3DRMMeshBuilder3Impl_GenerateNormals,
2300     IDirect3DRMMeshBuilder3Impl_GetColorSource,
2301     IDirect3DRMMeshBuilder3Impl_AddMesh,
2302     IDirect3DRMMeshBuilder3Impl_AddMeshBuilder,
2303     IDirect3DRMMeshBuilder3Impl_AddFrame,
2304     IDirect3DRMMeshBuilder3Impl_AddFace,
2305     IDirect3DRMMeshBuilder3Impl_AddFaces,
2306     IDirect3DRMMeshBuilder3Impl_ReserveSpace,
2307     IDirect3DRMMeshBuilder3Impl_SetColorRGB,
2308     IDirect3DRMMeshBuilder3Impl_SetColor,
2309     IDirect3DRMMeshBuilder3Impl_SetTexture,
2310     IDirect3DRMMeshBuilder3Impl_SetMaterial,
2311     IDirect3DRMMeshBuilder3Impl_SetTextureTopology,
2312     IDirect3DRMMeshBuilder3Impl_SetQuality,
2313     IDirect3DRMMeshBuilder3Impl_SetPerspective,
2314     IDirect3DRMMeshBuilder3Impl_SetVertex,
2315     IDirect3DRMMeshBuilder3Impl_SetNormal,
2316     IDirect3DRMMeshBuilder3Impl_SetTextureCoordinates,
2317     IDirect3DRMMeshBuilder3Impl_SetVertexColor,
2318     IDirect3DRMMeshBuilder3Impl_SetVertexColorRGB,
2319     IDirect3DRMMeshBuilder3Impl_GetFaces,
2320     IDirect3DRMMeshBuilder3Impl_GetGeometry,
2321     IDirect3DRMMeshBuilder3Impl_GetTextureCoordinates,
2322     IDirect3DRMMeshBuilder3Impl_AddVertex,
2323     IDirect3DRMMeshBuilder3Impl_AddNormal,
2324     IDirect3DRMMeshBuilder3Impl_CreateFace,
2325     IDirect3DRMMeshBuilder3Impl_GetQuality,
2326     IDirect3DRMMeshBuilder3Impl_GetPerspective,
2327     IDirect3DRMMeshBuilder3Impl_GetFaceCount,
2328     IDirect3DRMMeshBuilder3Impl_GetVertexCount,
2329     IDirect3DRMMeshBuilder3Impl_GetVertexColor,
2330     IDirect3DRMMeshBuilder3Impl_CreateMesh,
2331     IDirect3DRMMeshBuilder3Impl_GetFace,
2332     IDirect3DRMMeshBuilder3Impl_GetVertex,
2333     IDirect3DRMMeshBuilder3Impl_GetNormal,
2334     IDirect3DRMMeshBuilder3Impl_DeleteVertices,
2335     IDirect3DRMMeshBuilder3Impl_DeleteNormals,
2336     IDirect3DRMMeshBuilder3Impl_DeleteFace,
2337     IDirect3DRMMeshBuilder3Impl_Empty,
2338     IDirect3DRMMeshBuilder3Impl_Optimize,
2339     IDirect3DRMMeshBuilder3Impl_AddFacesIndexed,
2340     IDirect3DRMMeshBuilder3Impl_CreateSubMesh,
2341     IDirect3DRMMeshBuilder3Impl_GetParentMesh,
2342     IDirect3DRMMeshBuilder3Impl_GetSubMeshes,
2343     IDirect3DRMMeshBuilder3Impl_DeleteSubMesh,
2344     IDirect3DRMMeshBuilder3Impl_Enable,
2345     IDirect3DRMMeshBuilder3Impl_GetEnable,
2346     IDirect3DRMMeshBuilder3Impl_AddTriangles,
2347     IDirect3DRMMeshBuilder3Impl_SetVertices,
2348     IDirect3DRMMeshBuilder3Impl_GetVertices,
2349     IDirect3DRMMeshBuilder3Impl_SetNormals,
2350     IDirect3DRMMeshBuilder3Impl_GetNormals,
2351     IDirect3DRMMeshBuilder3Impl_GetNormalCount
2352 };
2353
2354 HRESULT Direct3DRMMeshBuilder_create(REFIID riid, IUnknown** ppObj)
2355 {
2356     IDirect3DRMMeshBuilderImpl* object;
2357
2358     TRACE("(%p)\n", ppObj);
2359
2360     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshBuilderImpl));
2361     if (!object)
2362     {
2363         ERR("Out of memory\n");
2364         return E_OUTOFMEMORY;
2365     }
2366
2367     object->IDirect3DRMMeshBuilder2_iface.lpVtbl = &Direct3DRMMeshBuilder2_Vtbl;
2368     object->IDirect3DRMMeshBuilder3_iface.lpVtbl = &Direct3DRMMeshBuilder3_Vtbl;
2369     object->ref = 1;
2370
2371     if (IsEqualGUID(riid, &IID_IDirect3DRMMeshBuilder3))
2372         *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder3_iface;
2373     else
2374         *ppObj = (IUnknown*)&object->IDirect3DRMMeshBuilder2_iface;
2375
2376     return S_OK;
2377 }
2378
2379 /*** IUnknown methods ***/
2380 static HRESULT WINAPI IDirect3DRMMeshImpl_QueryInterface(IDirect3DRMMesh* iface,
2381                                                          REFIID riid, void** ppvObject)
2382 {
2383     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2384
2385     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
2386
2387     *ppvObject = NULL;
2388
2389     if (IsEqualGUID(riid, &IID_IUnknown) ||
2390         IsEqualGUID(riid, &IID_IDirect3DRMMesh))
2391     {
2392         *ppvObject = &This->IDirect3DRMMesh_iface;
2393     }
2394     else
2395     {
2396         FIXME("interface %s not implemented\n", debugstr_guid(riid));
2397         return E_NOINTERFACE;
2398     }
2399
2400     IDirect3DRMMesh_AddRef(iface);
2401     return S_OK;
2402 }
2403
2404 static ULONG WINAPI IDirect3DRMMeshImpl_AddRef(IDirect3DRMMesh* iface)
2405 {
2406     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2407     ULONG ref = InterlockedIncrement(&This->ref);
2408
2409     TRACE("(%p)->(): new ref = %d\n", This, ref);
2410
2411     return ref;
2412 }
2413
2414 static ULONG WINAPI IDirect3DRMMeshImpl_Release(IDirect3DRMMesh* iface)
2415 {
2416     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2417     ULONG ref = InterlockedDecrement(&This->ref);
2418
2419     TRACE("(%p)->(): new ref = %d\n", This, ref);
2420
2421     if (!ref)
2422     {
2423         int i;
2424
2425         for (i = 0; i < This->nb_groups; i++)
2426             HeapFree(GetProcessHeap(), 0, This->groups[i].vertices);
2427         HeapFree(GetProcessHeap(), 0, This->groups);
2428         HeapFree(GetProcessHeap(), 0, This);
2429     }
2430
2431     return ref;
2432 }
2433
2434 /*** IDirect3DRMObject methods ***/
2435 static HRESULT WINAPI IDirect3DRMMeshImpl_Clone(IDirect3DRMMesh* iface,
2436                                                 LPUNKNOWN pUnkOuter, REFIID riid,
2437                                                 LPVOID *ppvObj)
2438 {
2439     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2440
2441     FIXME("(%p)->(%p,%s,%p): stub\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
2442
2443     return E_NOTIMPL;
2444 }
2445
2446 static HRESULT WINAPI IDirect3DRMMeshImpl_AddDestroyCallback(IDirect3DRMMesh* iface,
2447                                                              D3DRMOBJECTCALLBACK cb,
2448                                                              LPVOID argument)
2449 {
2450     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2451
2452     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2453
2454     return E_NOTIMPL;
2455 }
2456
2457 static HRESULT WINAPI IDirect3DRMMeshImpl_DeleteDestroyCallback(IDirect3DRMMesh* iface,
2458                                                                  D3DRMOBJECTCALLBACK cb,
2459                                                                  LPVOID argument)
2460 {
2461     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2462
2463     FIXME("(%p)->(%p,%p): stub\n", This, cb, argument);
2464
2465     return E_NOTIMPL;
2466 }
2467
2468 static HRESULT WINAPI IDirect3DRMMeshImpl_SetAppData(IDirect3DRMMesh* iface,
2469                                                      DWORD data)
2470 {
2471     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2472
2473     FIXME("(%p)->(%u): stub\n", This, data);
2474
2475     return E_NOTIMPL;
2476 }
2477
2478 static DWORD WINAPI IDirect3DRMMeshImpl_GetAppData(IDirect3DRMMesh* iface)
2479 {
2480     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2481
2482     FIXME("(%p)->(): stub\n", This);
2483
2484     return 0;
2485 }
2486
2487 static HRESULT WINAPI IDirect3DRMMeshImpl_SetName(IDirect3DRMMesh* iface,
2488                                                   LPCSTR pName)
2489 {
2490     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2491
2492     FIXME("(%p)->(%s): stub\n", This, pName);
2493
2494     return E_NOTIMPL;
2495 }
2496
2497 static HRESULT WINAPI IDirect3DRMMeshImpl_GetName(IDirect3DRMMesh* iface,
2498                                                   LPDWORD lpdwSize, LPSTR lpName)
2499 {
2500     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2501
2502     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
2503
2504     return E_NOTIMPL;
2505 }
2506
2507 static HRESULT WINAPI IDirect3DRMMeshImpl_GetClassName(IDirect3DRMMesh* iface,
2508                                                        LPDWORD lpdwSize, LPSTR lpName)
2509 {
2510     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2511
2512     FIXME("(%p)->(%p,%p): stub\n", This, lpdwSize, lpName);
2513
2514     return E_NOTIMPL;
2515 }
2516
2517 /*** IDirect3DRMMesh methods ***/
2518 static HRESULT WINAPI IDirect3DRMMeshImpl_Scale(IDirect3DRMMesh* iface,
2519                                                 D3DVALUE sx, D3DVALUE sy, D3DVALUE sz)
2520 {
2521     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2522
2523     FIXME("(%p)->(%f,%f,%f): stub\n", This, sx, sy,sz);
2524
2525     return E_NOTIMPL;
2526 }
2527
2528 static HRESULT WINAPI IDirect3DRMMeshImpl_Translate(IDirect3DRMMesh* iface,
2529                                                     D3DVALUE tx, D3DVALUE ty, D3DVALUE tz)
2530 {
2531     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2532
2533     FIXME("(%p)->(%f,%f,%f): stub\n", This, tx, ty,tz);
2534
2535     return E_NOTIMPL;
2536 }
2537
2538 static HRESULT WINAPI IDirect3DRMMeshImpl_GetBox(IDirect3DRMMesh* iface,
2539                                                  D3DRMBOX * box)
2540 {
2541     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2542
2543     FIXME("(%p)->(%p): stub\n", This, box);
2544
2545     return E_NOTIMPL;
2546 }
2547
2548 static HRESULT WINAPI IDirect3DRMMeshImpl_AddGroup(IDirect3DRMMesh* iface,
2549                                                    unsigned vertex_count, unsigned face_count, unsigned vertex_per_face,
2550                                                    unsigned *face_data, D3DRMGROUPINDEX *return_id)
2551 {
2552     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2553     mesh_group* group;
2554
2555     TRACE("(%p)->(%u,%u,%u,%p,%p)\n", This, vertex_count, face_count, vertex_per_face, face_data, return_id);
2556
2557     if (!face_data || !return_id)
2558         return E_POINTER;
2559
2560     if ((This->nb_groups + 1) > This->groups_capacity)
2561     {
2562         ULONG new_capacity;
2563         mesh_group* groups;
2564
2565         if (!This->groups_capacity)
2566         {
2567             new_capacity = 16;
2568             groups = HeapAlloc(GetProcessHeap(), 0, new_capacity * sizeof(mesh_group));
2569         }
2570         else
2571         {
2572             new_capacity = This->groups_capacity * 2;
2573             groups = HeapReAlloc(GetProcessHeap(), 0, This->groups, new_capacity * sizeof(mesh_group));
2574         }
2575
2576         if (!groups)
2577             return E_OUTOFMEMORY;
2578
2579         This->groups_capacity = new_capacity;
2580         This->groups = groups;
2581     }
2582
2583     group = This->groups + This->nb_groups;
2584
2585     group->vertices = HeapAlloc(GetProcessHeap(), 0, vertex_count * sizeof(D3DRMVERTEX));
2586     if (!group->vertices)
2587         return E_OUTOFMEMORY;
2588     group->nb_vertices = vertex_count;
2589     group->nb_faces = face_count;
2590     group->vertex_per_face = vertex_per_face;
2591
2592     if (vertex_per_face)
2593     {
2594         group->face_data_size = face_count * vertex_per_face;
2595     }
2596     else
2597     {
2598         int i;
2599         unsigned nb_indices;
2600         unsigned* face_data_ptr = face_data;
2601         group->face_data_size = 0;
2602
2603         for (i = 0; i < face_count; i++)
2604         {
2605             nb_indices = *face_data_ptr;
2606             group->face_data_size += nb_indices + 1;
2607             face_data_ptr += nb_indices;
2608         }
2609     }
2610
2611     group->face_data = HeapAlloc(GetProcessHeap(), 0, group->face_data_size * sizeof(unsigned));
2612     if (!group->face_data)
2613     {
2614         HeapFree(GetProcessHeap(), 0 , group->vertices);
2615         return E_OUTOFMEMORY;
2616     }
2617
2618     memcpy(group->face_data, face_data, group->face_data_size * sizeof(unsigned));
2619
2620     group->material = NULL;
2621     group->texture = NULL;
2622
2623     *return_id = This->nb_groups++;
2624
2625     return D3DRM_OK;
2626 }
2627
2628 static HRESULT WINAPI IDirect3DRMMeshImpl_SetVertices(IDirect3DRMMesh* iface,
2629                                                       D3DRMGROUPINDEX id, unsigned index, unsigned count,
2630                                                       D3DRMVERTEX *values)
2631 {
2632     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2633
2634     TRACE("(%p)->(%u,%u,%u,%p)\n", This, id, index, count, values);
2635
2636     if (id >= This->nb_groups)
2637         return D3DRMERR_BADVALUE;
2638
2639     if ((index + count - 1) >= This->groups[id].nb_vertices)
2640         return D3DRMERR_BADVALUE;
2641
2642     if (!values)
2643         return E_POINTER;
2644
2645     memcpy(This->groups[id].vertices + index, values, count * sizeof(D3DRMVERTEX));
2646
2647     return D3DRM_OK;
2648 }
2649
2650 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColor(IDirect3DRMMesh* iface,
2651                                                         D3DRMGROUPINDEX id, D3DCOLOR color)
2652 {
2653     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2654
2655     TRACE("(%p)->(%u,%x)\n", This, id, color);
2656
2657     if (id >= This->nb_groups)
2658         return D3DRMERR_BADVALUE;
2659
2660     This->groups[id].color = color;
2661
2662     return D3DRM_OK;
2663 }
2664
2665 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupColorRGB(IDirect3DRMMesh* iface,
2666                                                            D3DRMGROUPINDEX id, D3DVALUE red, D3DVALUE green, D3DVALUE blue)
2667 {
2668     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2669
2670     FIXME("(%p)->(%u,%f,%f,%f): stub\n", This, id, red, green, blue);
2671
2672     return E_NOTIMPL;
2673 }
2674
2675 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMapping(IDirect3DRMMesh* iface,
2676                                                           D3DRMGROUPINDEX id, D3DRMMAPPING value)
2677 {
2678     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2679
2680     FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2681
2682     return E_NOTIMPL;
2683 }
2684
2685 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupQuality(IDirect3DRMMesh* iface,
2686                                                           D3DRMGROUPINDEX id, D3DRMRENDERQUALITY value)
2687 {
2688     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2689
2690     FIXME("(%p)->(%u,%u): stub\n", This, id, value);
2691
2692     return E_NOTIMPL;
2693 }
2694
2695 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupMaterial(IDirect3DRMMesh* iface,
2696                                                            D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL material)
2697 {
2698     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2699
2700     TRACE("(%p)->(%u,%p)\n", This, id, material);
2701
2702     if (id >= This->nb_groups)
2703         return D3DRMERR_BADVALUE;
2704
2705     if (This->groups[id].material)
2706         IDirect3DRMMaterial2_Release(This->groups[id].material);
2707
2708     This->groups[id].material = (LPDIRECT3DRMMATERIAL2)material;
2709
2710     if (material)
2711         IDirect3DRMMaterial2_AddRef(This->groups[id].material);
2712
2713     return D3DRM_OK;
2714 }
2715
2716 static HRESULT WINAPI IDirect3DRMMeshImpl_SetGroupTexture(IDirect3DRMMesh* iface,
2717                                                           D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE texture)
2718 {
2719     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2720
2721     TRACE("(%p)->(%u,%p)\n", This, id, texture);
2722
2723     if (id >= This->nb_groups)
2724         return D3DRMERR_BADVALUE;
2725
2726     if (This->groups[id].texture)
2727         IDirect3DRMTexture3_Release(This->groups[id].texture);
2728
2729     if (!texture)
2730     {
2731         This->groups[id].texture = NULL;
2732         return D3DRM_OK;
2733     }
2734
2735     return IDirect3DRMTexture3_QueryInterface(texture, &IID_IDirect3DRMTexture, (LPVOID*)&This->groups[id].texture);
2736 }
2737
2738 static DWORD WINAPI IDirect3DRMMeshImpl_GetGroupCount(IDirect3DRMMesh* iface)
2739 {
2740     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2741
2742     TRACE("(%p)->()\n", This);
2743
2744     return This->nb_groups;
2745 }
2746
2747 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroup(IDirect3DRMMesh* iface,
2748                                                    D3DRMGROUPINDEX id, unsigned *vertex_count, unsigned *face_count, unsigned *vertex_per_face,
2749                                                    DWORD *face_data_size, unsigned *face_data)
2750 {
2751     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2752
2753     TRACE("(%p)->(%u,%p,%p,%p,%p,%p)\n", This, id, vertex_count, face_count, vertex_per_face, face_data_size, face_data);
2754
2755     if (id >= This->nb_groups)
2756         return D3DRMERR_BADVALUE;
2757
2758     if (vertex_count)
2759         *vertex_count = This->groups[id].nb_vertices;
2760     if (face_count)
2761         *face_count = This->groups[id].nb_faces;
2762     if (vertex_per_face)
2763         *vertex_per_face = This->groups[id].vertex_per_face;
2764     if (face_data_size)
2765         *face_data_size = This->groups[id].face_data_size;
2766     if (face_data)
2767         memcpy(face_data, This->groups[id].face_data, This->groups[id].face_data_size);
2768
2769     return D3DRM_OK;
2770 }
2771
2772 static HRESULT WINAPI IDirect3DRMMeshImpl_GetVertices(IDirect3DRMMesh* iface,
2773                                                       D3DRMGROUPINDEX id, DWORD index, DWORD count, D3DRMVERTEX *return_ptr)
2774 {
2775     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2776
2777     TRACE("(%p)->(%u,%u,%u,%p)\n", This, id, index, count, return_ptr);
2778
2779     if (id >= This->nb_groups)
2780         return D3DRMERR_BADVALUE;
2781
2782     if ((index + count - 1) >= This->groups[id].nb_vertices)
2783         return D3DRMERR_BADVALUE;
2784
2785     if (!return_ptr)
2786         return E_POINTER;
2787
2788     memcpy(return_ptr, This->groups[id].vertices + index, count * sizeof(D3DRMVERTEX));
2789
2790     return D3DRM_OK;
2791 }
2792
2793 static D3DCOLOR WINAPI IDirect3DRMMeshImpl_GetGroupColor(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2794 {
2795     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2796
2797     TRACE("(%p)->(%u)\n", This, id);
2798
2799     return This->groups[id].color;
2800 }
2801
2802 static D3DRMMAPPING WINAPI IDirect3DRMMeshImpl_GetGroupMapping(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2803 {
2804     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2805
2806     FIXME("(%p)->(%u): stub\n", This, id);
2807
2808     return 0;
2809 }
2810 static D3DRMRENDERQUALITY WINAPI IDirect3DRMMeshImpl_GetGroupQuality(IDirect3DRMMesh* iface, D3DRMGROUPINDEX id)
2811 {
2812     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2813
2814     FIXME("(%p)->(%u): stub\n", This, id);
2815
2816     return 0;
2817 }
2818
2819 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupMaterial(IDirect3DRMMesh* iface,
2820                                                            D3DRMGROUPINDEX id, LPDIRECT3DRMMATERIAL *material)
2821 {
2822     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2823
2824     TRACE("(%p)->(%u,%p)\n", This, id, material);
2825
2826     if (id >= This->nb_groups)
2827         return D3DRMERR_BADVALUE;
2828
2829     if (!material)
2830         return E_POINTER;
2831
2832     if (This->groups[id].material)
2833         IDirect3DRMTexture_QueryInterface(This->groups[id].material, &IID_IDirect3DRMMaterial, (void**)material);
2834     else
2835         *material = NULL;
2836
2837     return D3DRM_OK;
2838 }
2839
2840 static HRESULT WINAPI IDirect3DRMMeshImpl_GetGroupTexture(IDirect3DRMMesh* iface,
2841                                                           D3DRMGROUPINDEX id, LPDIRECT3DRMTEXTURE *texture)
2842 {
2843     IDirect3DRMMeshImpl *This = impl_from_IDirect3DRMMesh(iface);
2844
2845     TRACE("(%p)->(%u,%p)\n", This, id, texture);
2846
2847     if (id >= This->nb_groups)
2848         return D3DRMERR_BADVALUE;
2849
2850     if (!texture)
2851         return E_POINTER;
2852
2853     if (This->groups[id].texture)
2854         IDirect3DRMTexture_QueryInterface(This->groups[id].texture, &IID_IDirect3DRMTexture, (void**)texture);
2855     else
2856         *texture = NULL;
2857
2858     return D3DRM_OK;
2859 }
2860
2861 static const struct IDirect3DRMMeshVtbl Direct3DRMMesh_Vtbl =
2862 {
2863     /*** IUnknown methods ***/
2864     IDirect3DRMMeshImpl_QueryInterface,
2865     IDirect3DRMMeshImpl_AddRef,
2866     IDirect3DRMMeshImpl_Release,
2867     /*** IDirect3DRMObject methods ***/
2868     IDirect3DRMMeshImpl_Clone,
2869     IDirect3DRMMeshImpl_AddDestroyCallback,
2870     IDirect3DRMMeshImpl_DeleteDestroyCallback,
2871     IDirect3DRMMeshImpl_SetAppData,
2872     IDirect3DRMMeshImpl_GetAppData,
2873     IDirect3DRMMeshImpl_SetName,
2874     IDirect3DRMMeshImpl_GetName,
2875     IDirect3DRMMeshImpl_GetClassName,
2876     /*** IDirect3DRMMesh methods ***/
2877     IDirect3DRMMeshImpl_Scale,
2878     IDirect3DRMMeshImpl_Translate,
2879     IDirect3DRMMeshImpl_GetBox,
2880     IDirect3DRMMeshImpl_AddGroup,
2881     IDirect3DRMMeshImpl_SetVertices,
2882     IDirect3DRMMeshImpl_SetGroupColor,
2883     IDirect3DRMMeshImpl_SetGroupColorRGB,
2884     IDirect3DRMMeshImpl_SetGroupMapping,
2885     IDirect3DRMMeshImpl_SetGroupQuality,
2886     IDirect3DRMMeshImpl_SetGroupMaterial,
2887     IDirect3DRMMeshImpl_SetGroupTexture,
2888     IDirect3DRMMeshImpl_GetGroupCount,
2889     IDirect3DRMMeshImpl_GetGroup,
2890     IDirect3DRMMeshImpl_GetVertices,
2891     IDirect3DRMMeshImpl_GetGroupColor,
2892     IDirect3DRMMeshImpl_GetGroupMapping,
2893     IDirect3DRMMeshImpl_GetGroupQuality,
2894     IDirect3DRMMeshImpl_GetGroupMaterial,
2895     IDirect3DRMMeshImpl_GetGroupTexture
2896 };
2897
2898 static HRESULT Direct3DRMMesh_create(IDirect3DRMMesh** obj)
2899 {
2900     IDirect3DRMMeshImpl* object;
2901
2902     TRACE("(%p)\n", obj);
2903
2904     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMMeshImpl));
2905     if (!object)
2906     {
2907         ERR("Out of memory\n");
2908         return E_OUTOFMEMORY;
2909     }
2910
2911     object->IDirect3DRMMesh_iface.lpVtbl = &Direct3DRMMesh_Vtbl;
2912     object->ref = 1;
2913
2914     *obj = &object->IDirect3DRMMesh_iface;
2915
2916     return S_OK;
2917 }