[D3DRM_WINETEST]
[reactos.git] / rostests / winetests / d3drm / d3drm.c
1 /*
2 * Copyright 2010, 2012 Christian Costa
3 * Copyright 2012 André Hentschel
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #define COBJMACROS
21 #include <d3d.h>
22 #include <initguid.h>
23 #include <d3drm.h>
24 #include <d3drmwin.h>
25
26 #include "wine/test.h"
27
28 static HMODULE d3drm_handle = 0;
29
30 static HRESULT (WINAPI * pDirect3DRMCreate)(IDirect3DRM **d3drm);
31
32 #define CHECK_REFCOUNT(obj,rc) \
33 { \
34 int rc_new = rc; \
35 int count = get_refcount( (IUnknown *)obj ); \
36 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
37 }
38
39 #define D3DRM_GET_PROC(func) \
40 p ## func = (void*)GetProcAddress(d3drm_handle, #func); \
41 if(!p ## func) { \
42 trace("GetProcAddress(%s) failed\n", #func); \
43 FreeLibrary(d3drm_handle); \
44 return FALSE; \
45 }
46
47 static BOOL InitFunctionPtrs(void)
48 {
49 d3drm_handle = LoadLibraryA("d3drm.dll");
50
51 if(!d3drm_handle)
52 {
53 skip("Could not load d3drm.dll\n");
54 return FALSE;
55 }
56
57 D3DRM_GET_PROC(Direct3DRMCreate)
58
59 return TRUE;
60 }
61
62 static int get_refcount(IUnknown *object)
63 {
64 IUnknown_AddRef( object );
65 return IUnknown_Release( object );
66 }
67
68 static BOOL match_float(float a, float b)
69 {
70 return (a - b) < 0.000001f;
71 }
72
73 static D3DRMMATRIX4D identity = {
74 { 1.0f, 0.0f, 0.0f, 0.0f },
75 { 0.0f, 1.0f, 0.0f, 0.0f },
76 { 0.0f, 0.0f, 1.0f, 0.0f },
77 { 0.0f, 0.0f, 0.0f, 1.0f }
78 };
79
80 static char data_bad_version[] =
81 "xof 0302txt 0064\n"
82 "Header Object\n"
83 "{\n"
84 "1; 2; 3;\n"
85 "}\n";
86
87 static char data_no_mesh[] =
88 "xof 0302txt 0064\n"
89 "Header Object\n"
90 "{\n"
91 "1; 0; 1;\n"
92 "}\n";
93
94 static char data_ok[] =
95 "xof 0302txt 0064\n"
96 "Header Object\n"
97 "{\n"
98 "1; 0; 1;\n"
99 "}\n"
100 "Mesh Object\n"
101 "{\n"
102 "4;\n"
103 "1.0; 0.0; 0.0;,\n"
104 "0.0; 1.0; 0.0;,\n"
105 "0.0; 0.0; 1.0;,\n"
106 "1.0; 1.0; 1.0;;\n"
107 "3;\n"
108 "3; 0, 1, 2;,\n"
109 "3; 1, 2, 3;,\n"
110 "3; 3, 1, 2;;\n"
111 "}\n";
112
113 static char data_full[] =
114 "xof 0302txt 0064\n"
115 "Header { 1; 0; 1; }\n"
116 "Mesh {\n"
117 " 3;\n"
118 " 0.1; 0.2; 0.3;,\n"
119 " 0.4; 0.5; 0.6;,\n"
120 " 0.7; 0.8; 0.9;;\n"
121 " 1;\n"
122 " 3; 0, 1, 2;;\n"
123 " MeshMaterialList {\n"
124 " 1; 1; 0;\n"
125 " Material {\n"
126 " 0.0; 1.0; 0.0; 1.0;;\n"
127 " 30.0;\n"
128 " 1.0; 0.0; 0.0;;\n"
129 " 0.5; 0.5; 0.5;;\n"
130 " TextureFileName {\n"
131 " \"Texture.bmp\";\n"
132 " }\n"
133 " }\n"
134 " }\n"
135 " MeshNormals {\n"
136 " 3;\n"
137 " 1.1; 1.2; 1.3;,\n"
138 " 1.4; 1.5; 1.6;,\n"
139 " 1.7; 1.8; 1.9;;\n"
140 " 1;"
141 " 3; 0, 1, 2;;\n"
142 " }\n"
143 " MeshTextureCoords {\n"
144 " 3;\n"
145 " 0.13; 0.17;,\n"
146 " 0.23; 0.27;,\n"
147 " 0.33; 0.37;;\n"
148 " }\n"
149 "}\n";
150
151 static char data_d3drm_load[] =
152 "xof 0302txt 0064\n"
153 "Header Object\n"
154 "{\n"
155 "1; 0; 1;\n"
156 "}\n"
157 "Mesh Object1\n"
158 "{\n"
159 " 1;\n"
160 " 0.1; 0.2; 0.3;,\n"
161 " 1;\n"
162 " 3; 0, 1, 2;;\n"
163 "}\n"
164 "Mesh Object2\n"
165 "{\n"
166 " 1;\n"
167 " 0.1; 0.2; 0.3;,\n"
168 " 1;\n"
169 " 3; 0, 1, 2;;\n"
170 "}\n"
171 "Frame Scene\n"
172 "{\n"
173 " {Object1}\n"
174 " {Object2}\n"
175 "}\n"
176 "Material\n"
177 "{\n"
178 " 0.1, 0.2, 0.3, 0.4;;\n"
179 " 0.5;\n"
180 " 0.6, 0.7, 0.8;;\n"
181 " 0.9, 1.0, 1.1;;\n"
182 "}\n";
183
184 static char data_frame_mesh_materials[] =
185 "xof 0302txt 0064\n"
186 "Header { 1; 0; 1; }\n"
187 "Frame {\n"
188 " Mesh mesh1 {\n"
189 " 5;\n"
190 " 0.1; 0.2; 0.3;,\n"
191 " 0.4; 0.5; 0.6;,\n"
192 " 0.7; 0.8; 0.9;,\n"
193 " 1.1; 1.2; 1.3;,\n"
194 " 1.4; 1.5; 1.6;;\n"
195 " 6;\n"
196 " 3; 0, 1, 2;,\n"
197 " 3; 0, 2, 1;,\n"
198 " 3; 1, 2, 3;,\n"
199 " 3; 1, 3, 2;,\n"
200 " 3; 2, 3, 4;,\n"
201 " 3; 2, 4, 3;;\n"
202 " MeshMaterialList {\n"
203 " 3; 6; 0, 1, 1, 2, 2, 2;\n"
204 " Material mat1 {\n"
205 " 1.0; 0.0; 0.0; 0.1;;\n"
206 " 10.0;\n"
207 " 0.11; 0.12; 0.13;;\n"
208 " 0.14; 0.15; 0.16;;\n"
209 " }\n"
210 " Material mat2 {\n"
211 " 0.0; 1.0; 0.0; 0.2;;\n"
212 " 20.0;\n"
213 " 0.21; 0.22; 0.23;;\n"
214 " 0.24; 0.25; 0.26;;\n"
215 " }\n"
216 " Material mat3 {\n"
217 " 0.0; 0.0; 1.0; 0.3;;\n"
218 " 30.0;\n"
219 " 0.31; 0.32; 0.33;;\n"
220 " 0.34; 0.35; 0.36;;\n"
221 " }\n"
222 " }\n"
223 " }\n"
224 "}\n";
225
226 static void test_MeshBuilder(void)
227 {
228 HRESULT hr;
229 IDirect3DRM *d3drm;
230 IDirect3DRMMeshBuilder *pMeshBuilder;
231 IDirect3DRMMesh *mesh;
232 D3DRMLOADMEMORY info;
233 int val;
234 DWORD val1, val2, val3;
235 D3DVALUE valu, valv;
236 D3DVECTOR v[3];
237 D3DVECTOR n[4];
238 DWORD f[8];
239 char name[10];
240 DWORD size;
241 D3DCOLOR color;
242 CHAR cname[64] = {0};
243
244 hr = pDirect3DRMCreate(&d3drm);
245 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
246
247 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
248 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
249
250 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, NULL, cname);
251 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
252 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, NULL, NULL);
253 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
254 size = 1;
255 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, &size, cname);
256 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
257 size = sizeof(cname);
258 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, &size, cname);
259 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
260 ok(size == sizeof("Builder"), "wrong size: %u\n", size);
261 ok(!strcmp(cname, "Builder"), "Expected cname to be \"Builder\", but got \"%s\"\n", cname);
262
263 info.lpMemory = data_bad_version;
264 info.dSize = strlen(data_bad_version);
265 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
266 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
267
268 info.lpMemory = data_no_mesh;
269 info.dSize = strlen(data_no_mesh);
270 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
271 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
272
273 info.lpMemory = data_ok;
274 info.dSize = strlen(data_ok);
275 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
276 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
277
278 size = sizeof(name);
279 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
280 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
281 ok(!strcmp(name, "Object"), "Retrieved name '%s' instead of 'Object'\n", name);
282 size = strlen("Object"); /* No space for null character */
283 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
284 ok(hr == E_INVALIDARG, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
285 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, NULL);
286 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
287 size = sizeof(name);
288 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
289 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
290 ok(size == 0, "Size should be 0 instead of %u\n", size);
291 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, "");
292 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
293 size = sizeof(name);
294 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
295 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
296 ok(!strcmp(name, ""), "Retrieved name '%s' instead of ''\n", name);
297
298 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
299 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
300
301 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
302 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
303
304 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, NULL, &val2, NULL, &val3, NULL);
305 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
306 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
307 ok(val2 == 4, "Wrong number of normals %d (must be 4)\n", val2);
308 ok(val3 == 22, "Wrong number of face data bytes %d (must be 22)\n", val3);
309
310 /* Check that Load method generated default normals */
311 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, NULL, &val2, n, NULL, NULL);
312 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
313 ok(match_float(U1(n[0]).x, 0.577350f), "Wrong component n[0].x = %f (expected %f)\n", U1(n[0]).x, 0.577350f);
314 ok(match_float(U2(n[0]).y, 0.577350f), "Wrong component n[0].y = %f (expected %f)\n", U2(n[0]).y, 0.577350f);
315 ok(match_float(U3(n[0]).z, 0.577350f), "Wrong component n[0].z = %f (expected %f)\n", U3(n[0]).z, 0.577350f);
316 ok(match_float(U1(n[1]).x, -0.229416f), "Wrong component n[1].x = %f (expected %f)\n", U1(n[1]).x, -0.229416f);
317 ok(match_float(U2(n[1]).y, 0.688247f), "Wrong component n[1].y = %f (expected %f)\n", U2(n[1]).y, 0.688247f);
318 ok(match_float(U3(n[1]).z, 0.688247f), "Wrong component n[1].z = %f (expected %f)\n", U3(n[1]).z, 0.688247f);
319 ok(match_float(U1(n[2]).x, -0.229416f), "Wrong component n[2].x = %f (expected %f)\n", U1(n[2]).x, -0.229416f);
320 ok(match_float(U2(n[2]).y, 0.688247f), "Wrong component n[2].y = %f (expected %f)\n", U2(n[2]).y, 0.688247f);
321 ok(match_float(U3(n[2]).z, 0.688247f), "Wrong component n[2].z = %f (expected %f)\n", U3(n[2]).z, 0.688247f);
322 ok(match_float(U1(n[3]).x, -0.577350f), "Wrong component n[3].x = %f (expected %f)\n", U1(n[3]).x, -0.577350f);
323 ok(match_float(U2(n[3]).y, 0.577350f), "Wrong component n[3].y = %f (expected %f)\n", U2(n[3]).y, 0.577350f);
324 ok(match_float(U3(n[3]).z, 0.577350f), "Wrong component n[3].z = %f (expected %f)\n", U3(n[3]).z, 0.577350f);
325
326 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
327 valu = 1.23f;
328 valv = 3.21f;
329 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
330 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
331 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
332 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
333 valu = 1.23f;
334 valv = 3.21f;
335 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 1, &valu, &valv);
336 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
337 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
338 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
339 valu = 1.23f;
340 valv = 3.21f;
341 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 2, &valu, &valv);
342 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
343 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
344 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
345 valu = 1.23f;
346 valv = 3.21f;
347 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 3, &valu, &valv);
348 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
349 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
350 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
351 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 4, &valu, &valv);
352 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
353
354 valu = 1.23f;
355 valv = 3.21f;
356 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 0, valu, valv);
357 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
358 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 4, valu, valv);
359 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
360
361 valu = 0.0f;
362 valv = 0.0f;
363 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
364 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
365 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
366 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
367
368 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
369
370 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
371 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
372
373 /* No group in mesh when mesh builder is not loaded */
374 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
375 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
376 if (hr == D3DRM_OK)
377 {
378 DWORD nb_groups;
379
380 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
381 ok(nb_groups == 0, "GetCroupCount returned %u\n", nb_groups);
382
383 IDirect3DRMMesh_Release(mesh);
384 }
385
386 info.lpMemory = data_full;
387 info.dSize = strlen(data_full);
388 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
389 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
390
391 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
392 ok(val == 3, "Wrong number of vertices %d (must be 3)\n", val);
393
394 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
395 ok(val == 1, "Wrong number of faces %d (must be 1)\n", val);
396
397 /* Check no buffer size and too small buffer size errors */
398 val1 = 1; val2 = 3; val3 = 8;
399 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
400 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
401 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, v, &val2, n, &val3, f);
402 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
403 val1 = 3; val2 = 1; val3 = 8;
404 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
405 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
406 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, NULL, n, &val3, f);
407 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
408 val1 = 3; val2 = 3; val3 = 1;
409 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
410 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
411 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, NULL, f);
412 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
413
414 val1 = 3; val2 = 3; val3 = 8;
415 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
416 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
417 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
418 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
419 ok(val3 == 8, "Wrong number of face data bytes %d (must be 8)\n", val3);
420 ok(U1(v[0]).x == 0.1f, "Wrong component v[0].x = %f (expected 0.1)\n", U1(v[0]).x);
421 ok(U2(v[0]).y == 0.2f, "Wrong component v[0].y = %f (expected 0.2)\n", U2(v[0]).y);
422 ok(U3(v[0]).z == 0.3f, "Wrong component v[0].z = %f (expected 0.3)\n", U3(v[0]).z);
423 ok(U1(v[1]).x == 0.4f, "Wrong component v[1].x = %f (expected 0.4)\n", U1(v[1]).x);
424 ok(U2(v[1]).y == 0.5f, "Wrong component v[1].y = %f (expected 0.5)\n", U2(v[1]).y);
425 ok(U3(v[1]).z == 0.6f, "Wrong component v[1].z = %f (expected 0.6)\n", U3(v[1]).z);
426 ok(U1(v[2]).x == 0.7f, "Wrong component v[2].x = %f (expected 0.7)\n", U1(v[2]).x);
427 ok(U2(v[2]).y == 0.8f, "Wrong component v[2].y = %f (expected 0.8)\n", U2(v[2]).y);
428 ok(U3(v[2]).z == 0.9f, "Wrong component v[2].z = %f (expected 0.9)\n", U3(v[2]).z);
429 ok(U1(n[0]).x == 1.1f, "Wrong component n[0].x = %f (expected 1.1)\n", U1(n[0]).x);
430 ok(U2(n[0]).y == 1.2f, "Wrong component n[0].y = %f (expected 1.2)\n", U2(n[0]).y);
431 ok(U3(n[0]).z == 1.3f, "Wrong component n[0].z = %f (expected 1.3)\n", U3(n[0]).z);
432 ok(U1(n[1]).x == 1.4f, "Wrong component n[1].x = %f (expected 1.4)\n", U1(n[1]).x);
433 ok(U2(n[1]).y == 1.5f, "Wrong component n[1].y = %f (expected 1.5)\n", U2(n[1]).y);
434 ok(U3(n[1]).z == 1.6f, "Wrong component n[1].z = %f (expected 1.6)\n", U3(n[1]).z);
435 ok(U1(n[2]).x == 1.7f, "Wrong component n[2].x = %f (expected 1.7)\n", U1(n[2]).x);
436 ok(U2(n[2]).y == 1.8f, "Wrong component n[2].y = %f (expected 1.8)\n", U2(n[2]).y);
437 ok(U3(n[2]).z == 1.9f, "Wrong component n[2].z = %f (expected 1.9)\n", U3(n[2]).z);
438 ok(f[0] == 3 , "Wrong component f[0] = %d (expected 3)\n", f[0]);
439 ok(f[1] == 0 , "Wrong component f[1] = %d (expected 0)\n", f[1]);
440 ok(f[2] == 0 , "Wrong component f[2] = %d (expected 0)\n", f[2]);
441 ok(f[3] == 1 , "Wrong component f[3] = %d (expected 1)\n", f[3]);
442 ok(f[4] == 1 , "Wrong component f[4] = %d (expected 1)\n", f[4]);
443 ok(f[5] == 2 , "Wrong component f[5] = %d (expected 2)\n", f[5]);
444 ok(f[6] == 2 , "Wrong component f[6] = %d (expected 2)\n", f[6]);
445 ok(f[7] == 0 , "Wrong component f[7] = %d (expected 0)\n", f[7]);
446
447 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
448 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
449 if (hr == D3DRM_OK)
450 {
451 DWORD nb_groups;
452 unsigned nb_vertices, nb_faces, nb_face_vertices;
453 DWORD data_size;
454 IDirect3DRMMaterial *material = (IDirect3DRMMaterial *)0xdeadbeef;
455 IDirect3DRMTexture *texture = (IDirect3DRMTexture *)0xdeadbeef;
456 D3DVALUE values[3];
457
458 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
459 ok(nb_groups == 1, "GetCroupCount returned %u\n", nb_groups);
460 hr = IDirect3DRMMesh_GetGroup(mesh, 1, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
461 ok(hr == D3DRMERR_BADVALUE, "GetCroup returned hr = %x\n", hr);
462 hr = IDirect3DRMMesh_GetGroup(mesh, 0, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
463 ok(hr == D3DRM_OK, "GetCroup failed returning hr = %x\n", hr);
464 ok(nb_vertices == 3, "Wrong number of vertices %u (must be 3)\n", nb_vertices);
465 ok(nb_faces == 1, "Wrong number of faces %u (must be 1)\n", nb_faces);
466 ok(nb_face_vertices == 3, "Wrong number of vertices per face %u (must be 3)\n", nb_face_vertices);
467 ok(data_size == 3, "Wrong number of face data bytes %u (must be 3)\n", data_size);
468 color = IDirect3DRMMesh_GetGroupColor(mesh, 0);
469 ok(color == 0xff00ff00, "Wrong color returned %#x instead of %#x\n", color, 0xff00ff00);
470 hr = IDirect3DRMMesh_GetGroupTexture(mesh, 0, &texture);
471 ok(hr == D3DRM_OK, "GetCroupTexture failed returning hr = %x\n", hr);
472 ok(texture == NULL, "No texture should be present\n");
473 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, 0, &material);
474 ok(hr == D3DRM_OK, "GetCroupMaterial failed returning hr = %x\n", hr);
475 ok(material != NULL, "No material present\n");
476 if ((hr == D3DRM_OK) && material)
477 {
478 hr = IDirect3DRMMaterial_GetEmissive(material, &values[0], &values[1], &values[2]);
479 ok(hr == D3DRM_OK, "GetMaterialEmissive failed returning hr = %x\n", hr);
480 ok(values[0] == 0.5f, "Emissive red component should be %f instead of %f\n", 0.5f, values[0]);
481 ok(values[1] == 0.5f, "Emissive green component should be %f instead of %f\n", 0.5f, values[1]);
482 ok(values[2] == 0.5f, "Emissive blue component should be %f instead of %f\n", 0.5f, values[2]);
483 hr = IDirect3DRMMaterial_GetSpecular(material, &values[0], &values[1], &values[2]);
484 ok(hr == D3DRM_OK, "GetMaterialEmissive failed returning hr = %x\n", hr);
485 ok(values[0] == 1.0f, "Specular red component should be %f instead of %f\n", 1.0f, values[0]);
486 ok(values[1] == 0.0f, "Specular green component should be %f instead of %f\n", 0.0f, values[1]);
487 ok(values[2] == 0.0f, "Specular blue component should be %f instead of %f\n", 0.0f, values[2]);
488 values[0] = IDirect3DRMMaterial_GetPower(material);
489 ok(values[0] == 30.0f, "Power value should be %f instead of %f\n", 30.0f, values[0]);
490 }
491
492 IDirect3DRMMesh_Release(mesh);
493 }
494
495 hr = IDirect3DRMMeshBuilder_Scale(pMeshBuilder, 2, 3 ,4);
496 ok(hr == D3DRM_OK, "Scale failed returning hr = %x\n", hr);
497
498 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
499 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
500 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
501 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
502 ok(U1(v[0]).x == 0.1f*2, "Wrong component v[0].x = %f (expected %f)\n", U1(v[0]).x, 0.1f*2);
503 ok(U2(v[0]).y == 0.2f*3, "Wrong component v[0].y = %f (expected %f)\n", U2(v[0]).y, 0.2f*3);
504 ok(U3(v[0]).z == 0.3f*4, "Wrong component v[0].z = %f (expected %f)\n", U3(v[0]).z, 0.3f*4);
505 ok(U1(v[1]).x == 0.4f*2, "Wrong component v[1].x = %f (expected %f)\n", U1(v[1]).x, 0.4f*2);
506 ok(U2(v[1]).y == 0.5f*3, "Wrong component v[1].y = %f (expected %f)\n", U2(v[1]).y, 0.5f*3);
507 ok(U3(v[1]).z == 0.6f*4, "Wrong component v[1].z = %f (expected %f)\n", U3(v[1]).z, 0.6f*4);
508 ok(U1(v[2]).x == 0.7f*2, "Wrong component v[2].x = %f (expected %f)\n", U1(v[2]).x, 0.7f*2);
509 ok(U2(v[2]).y == 0.8f*3, "Wrong component v[2].y = %f (expected %f)\n", U2(v[2]).y, 0.8f*3);
510 ok(U3(v[2]).z == 0.9f*4, "Wrong component v[2].z = %f (expected %f)\n", U3(v[2]).z, 0.9f*4);
511 /* Normals are not affected by Scale */
512 ok(U1(n[0]).x == 1.1f, "Wrong component n[0].x = %f (expected %f)\n", U1(n[0]).x, 1.1f);
513 ok(U2(n[0]).y == 1.2f, "Wrong component n[0].y = %f (expected %f)\n", U2(n[0]).y, 1.2f);
514 ok(U3(n[0]).z == 1.3f, "Wrong component n[0].z = %f (expected %f)\n", U3(n[0]).z, 1.3f);
515 ok(U1(n[1]).x == 1.4f, "Wrong component n[1].x = %f (expected %f)\n", U1(n[1]).x, 1.4f);
516 ok(U2(n[1]).y == 1.5f, "Wrong component n[1].y = %f (expected %f)\n", U2(n[1]).y, 1.5f);
517 ok(U3(n[1]).z == 1.6f, "Wrong component n[1].z = %f (expected %f)\n", U3(n[1]).z, 1.6f);
518 ok(U1(n[2]).x == 1.7f, "Wrong component n[2].x = %f (expected %f)\n", U1(n[2]).x, 1.7f);
519 ok(U2(n[2]).y == 1.8f, "Wrong component n[2].y = %f (expected %f)\n", U2(n[2]).y, 1.8f);
520 ok(U3(n[2]).z == 1.9f, "Wrong component n[2].z = %f (expected %f)\n", U3(n[2]).z, 1.9f);
521
522 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
523
524 IDirect3DRM_Release(d3drm);
525 }
526
527 static void test_MeshBuilder3(void)
528 {
529 HRESULT hr;
530 IDirect3DRM *d3drm;
531 IDirect3DRM3 *d3drm3;
532 IDirect3DRMMeshBuilder3 *pMeshBuilder3;
533 D3DRMLOADMEMORY info;
534 int val;
535 DWORD val1;
536 D3DVALUE valu, valv;
537 DWORD size;
538 CHAR cname[64] = {0};
539
540 hr = pDirect3DRMCreate(&d3drm);
541 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
542
543 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
544 {
545 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
546 IDirect3DRM_Release(d3drm);
547 return;
548 }
549
550 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &pMeshBuilder3);
551 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
552
553 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, NULL, cname);
554 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
555 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, NULL, NULL);
556 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
557 size = 1;
558 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, &size, cname);
559 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
560 size = sizeof(cname);
561 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, &size, cname);
562 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
563 ok(size == sizeof("Builder"), "wrong size: %u\n", size);
564 ok(!strcmp(cname, "Builder"), "Expected cname to be \"Builder\", but got \"%s\"\n", cname);
565
566 info.lpMemory = data_bad_version;
567 info.dSize = strlen(data_bad_version);
568 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
569 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
570
571 info.lpMemory = data_no_mesh;
572 info.dSize = strlen(data_no_mesh);
573 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
574 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
575
576 info.lpMemory = data_ok;
577 info.dSize = strlen(data_ok);
578 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
579 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
580
581 val = IDirect3DRMMeshBuilder3_GetVertexCount(pMeshBuilder3);
582 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
583
584 val = IDirect3DRMMeshBuilder3_GetFaceCount(pMeshBuilder3);
585 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
586
587 hr = IDirect3DRMMeshBuilder3_GetVertices(pMeshBuilder3, 0, &val1, NULL);
588 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
589 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
590
591 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
592 valu = 1.23f;
593 valv = 3.21f;
594 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
595 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
596 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
597 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
598 valu = 1.23f;
599 valv = 3.21f;
600 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 1, &valu, &valv);
601 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
602 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
603 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
604 valu = 1.23f;
605 valv = 3.21f;
606 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 2, &valu, &valv);
607 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
608 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
609 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
610 valu = 1.23f;
611 valv = 3.21f;
612 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 3, &valu, &valv);
613 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
614 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
615 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
616 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 4, &valu, &valv);
617 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
618
619 valu = 1.23f;
620 valv = 3.21f;
621 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 0, valu, valv);
622 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
623 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 4, valu, valv);
624 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
625
626 valu = 0.0f;
627 valv = 0.0f;
628 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
629 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
630 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
631 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
632
633 IDirect3DRMMeshBuilder3_Release(pMeshBuilder3);
634 IDirect3DRM3_Release(d3drm3);
635 IDirect3DRM_Release(d3drm);
636 }
637
638 static void test_Mesh(void)
639 {
640 HRESULT hr;
641 IDirect3DRM *d3drm;
642 IDirect3DRMMesh *mesh;
643 DWORD size;
644 CHAR cname[64] = {0};
645
646 hr = pDirect3DRMCreate(&d3drm);
647 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
648
649 hr = IDirect3DRM_CreateMesh(d3drm, &mesh);
650 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMesh interface (hr = %x)\n", hr);
651
652 hr = IDirect3DRMMesh_GetClassName(mesh, NULL, cname);
653 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
654 hr = IDirect3DRMMesh_GetClassName(mesh, NULL, NULL);
655 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
656 size = 1;
657 hr = IDirect3DRMMesh_GetClassName(mesh, &size, cname);
658 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
659 size = sizeof(cname);
660 hr = IDirect3DRMMesh_GetClassName(mesh, &size, cname);
661 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
662 ok(size == sizeof("Mesh"), "wrong size: %u\n", size);
663 ok(!strcmp(cname, "Mesh"), "Expected cname to be \"Mesh\", but got \"%s\"\n", cname);
664
665 IDirect3DRMMesh_Release(mesh);
666
667 IDirect3DRM_Release(d3drm);
668 }
669
670 static void test_Face(void)
671 {
672 HRESULT hr;
673 IDirect3DRM *d3drm;
674 IDirect3DRM2 *d3drm2;
675 IDirect3DRM3 *d3drm3;
676 IDirect3DRMMeshBuilder2 *MeshBuilder2;
677 IDirect3DRMMeshBuilder3 *MeshBuilder3;
678 IDirect3DRMFace *face1;
679 IDirect3DRMFace2 *face2;
680 IDirect3DRMFaceArray *array1;
681 D3DRMLOADMEMORY info;
682 D3DVECTOR v1[4], n1[4], v2[4], n2[4];
683 DWORD count;
684 CHAR cname[64] = {0};
685 int icount;
686
687 hr = pDirect3DRMCreate(&d3drm);
688 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
689
690 hr = IDirect3DRM_CreateFace(d3drm, &face1);
691 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
692 if (FAILED(hr))
693 {
694 skip("Cannot get IDirect3DRMFace interface (hr = %x), skipping tests\n", hr);
695 IDirect3DRM_Release(d3drm);
696 return;
697 }
698
699 hr = IDirect3DRMFace_GetClassName(face1, NULL, cname);
700 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
701 hr = IDirect3DRMFace_GetClassName(face1, NULL, NULL);
702 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
703 count = 1;
704 hr = IDirect3DRMFace_GetClassName(face1, &count, cname);
705 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
706 count = sizeof(cname);
707 hr = IDirect3DRMFace_GetClassName(face1, &count, cname);
708 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
709 ok(count == sizeof("Face"), "wrong size: %u\n", count);
710 ok(!strcmp(cname, "Face"), "Expected cname to be \"Face\", but got \"%s\"\n", cname);
711
712 icount = IDirect3DRMFace_GetVertexCount(face1);
713 ok(!icount, "wrong VertexCount: %i\n", icount);
714
715 IDirect3DRMFace_Release(face1);
716
717 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM2, (void **)&d3drm2)))
718 {
719 win_skip("Cannot get IDirect3DRM2 interface (hr = %x), skipping tests\n", hr);
720 IDirect3DRM_Release(d3drm);
721 return;
722 }
723
724 hr = IDirect3DRM2_CreateMeshBuilder(d3drm2, &MeshBuilder2);
725 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder2 interface (hr = %x)\n", hr);
726
727 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
728 ok(!icount, "wrong FaceCount: %i\n", icount);
729
730 array1 = NULL;
731 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
732 todo_wine
733 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
734
735 hr = IDirect3DRMMeshBuilder2_CreateFace(MeshBuilder2, &face1);
736 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
737
738 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
739 todo_wine
740 ok(icount == 1, "wrong FaceCount: %i\n", icount);
741
742 array1 = NULL;
743 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
744 todo_wine
745 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
746 todo_wine
747 ok(array1 != NULL, "pArray = %p\n", array1);
748 if (array1)
749 {
750 IDirect3DRMFace *face;
751 count = IDirect3DRMFaceArray_GetSize(array1);
752 ok(count == 1, "count = %u\n", count);
753 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
754 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
755 IDirect3DRMFace_Release(face);
756 IDirect3DRMFaceArray_Release(array1);
757 }
758
759 icount = IDirect3DRMFace_GetVertexCount(face1);
760 ok(!icount, "wrong VertexCount: %i\n", icount);
761
762 IDirect3DRMFace_Release(face1);
763 IDirect3DRMMeshBuilder2_Release(MeshBuilder2);
764
765 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
766 {
767 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
768 IDirect3DRM_Release(d3drm);
769 return;
770 }
771
772 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &MeshBuilder3);
773 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
774
775 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
776 ok(!icount, "wrong FaceCount: %i\n", icount);
777
778 hr = IDirect3DRMMeshBuilder3_CreateFace(MeshBuilder3, &face2);
779 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace2 interface (hr = %x)\n", hr);
780
781 hr = IDirect3DRMFace2_GetClassName(face2, NULL, cname);
782 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
783 hr = IDirect3DRMFace2_GetClassName(face2, NULL, NULL);
784 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
785 count = 1;
786 hr = IDirect3DRMFace2_GetClassName(face2, &count, cname);
787 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
788 count = sizeof(cname);
789 hr = IDirect3DRMFace2_GetClassName(face2, &count, cname);
790 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
791 ok(count == sizeof("Face"), "wrong size: %u\n", count);
792 ok(!strcmp(cname, "Face"), "Expected cname to be \"Face\", but got \"%s\"\n", cname);
793
794 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
795 todo_wine
796 ok(icount == 1, "wrong FaceCount: %i\n", icount);
797
798 array1 = NULL;
799 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
800 todo_wine
801 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
802 todo_wine
803 ok(array1 != NULL, "pArray = %p\n", array1);
804 if (array1)
805 {
806 IDirect3DRMFace *face;
807 count = IDirect3DRMFaceArray_GetSize(array1);
808 ok(count == 1, "count = %u\n", count);
809 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
810 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
811 IDirect3DRMFace_Release(face);
812 IDirect3DRMFaceArray_Release(array1);
813 }
814
815 icount = IDirect3DRMFace2_GetVertexCount(face2);
816 ok(!icount, "wrong VertexCount: %i\n", icount);
817
818 info.lpMemory = data_ok;
819 info.dSize = strlen(data_ok);
820 hr = IDirect3DRMMeshBuilder3_Load(MeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
821 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
822
823 icount = IDirect3DRMMeshBuilder3_GetVertexCount(MeshBuilder3);
824 ok(icount == 4, "Wrong number of vertices %d (must be 4)\n", icount);
825
826 icount = IDirect3DRMMeshBuilder3_GetNormalCount(MeshBuilder3);
827 ok(icount == 4, "Wrong number of normals %d (must be 4)\n", icount);
828
829 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
830 todo_wine
831 ok(icount == 4, "Wrong number of faces %d (must be 4)\n", icount);
832
833 count = 4;
834 hr = IDirect3DRMMeshBuilder3_GetVertices(MeshBuilder3, 0, &count, v1);
835 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
836 ok(count == 4, "Wrong number of vertices %d (must be 4)\n", count);
837
838 hr = IDirect3DRMMeshBuilder3_GetNormals(MeshBuilder3, 0, &count, n1);
839 ok(hr == D3DRM_OK, "Cannot get normals information (hr = %x)\n", hr);
840 ok(count == 4, "Wrong number of normals %d (must be 4)\n", count);
841
842 array1 = NULL;
843 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
844 todo_wine
845 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
846 todo_wine
847 ok(array1 != NULL, "pArray = %p\n", array1);
848 if (array1)
849 {
850 IDirect3DRMFace *face;
851 count = IDirect3DRMFaceArray_GetSize(array1);
852 ok(count == 4, "count = %u\n", count);
853 hr = IDirect3DRMFaceArray_GetElement(array1, 1, &face);
854 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
855 IDirect3DRMFace_GetVertices(face, &count, v2, n2);
856 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
857 ok(count == 3, "Wrong number of vertices %d (must be 3)\n", count);
858 ok(U1(v2[0]).x == U1(v1[0]).x, "Wrong component v2[0].x = %f (expected %f)\n",
859 U1(v2[0]).x, U1(v1[0]).x);
860 ok(U2(v2[0]).y == U2(v1[0]).y, "Wrong component v2[0].y = %f (expected %f)\n",
861 U2(v2[0]).y, U2(v1[0]).y);
862 ok(U3(v2[0]).z == U3(v1[0]).z, "Wrong component v2[0].z = %f (expected %f)\n",
863 U3(v2[0]).z, U3(v1[0]).z);
864 ok(U1(v2[1]).x == U1(v1[1]).x, "Wrong component v2[1].x = %f (expected %f)\n",
865 U1(v2[1]).x, U1(v1[1]).x);
866 ok(U2(v2[1]).y == U2(v1[1]).y, "Wrong component v2[1].y = %f (expected %f)\n",
867 U2(v2[1]).y, U2(v1[1]).y);
868 ok(U3(v2[1]).z == U3(v1[1]).z, "Wrong component v2[1].z = %f (expected %f)\n",
869 U3(v2[1]).z, U3(v1[1]).z);
870 ok(U1(v2[2]).x == U1(v1[2]).x, "Wrong component v2[2].x = %f (expected %f)\n",
871 U1(v2[2]).x, U1(v1[2]).x);
872 ok(U2(v2[2]).y == U2(v1[2]).y, "Wrong component v2[2].y = %f (expected %f)\n",
873 U2(v2[2]).y, U2(v1[2]).y);
874 ok(U3(v2[2]).z == U3(v1[2]).z, "Wrong component v2[2].z = %f (expected %f)\n",
875 U3(v2[2]).z, U3(v1[2]).z);
876
877 ok(U1(n2[0]).x == U1(n1[0]).x, "Wrong component n2[0].x = %f (expected %f)\n",
878 U1(n2[0]).x, U1(n1[0]).x);
879 ok(U2(n2[0]).y == U2(n1[0]).y, "Wrong component n2[0].y = %f (expected %f)\n",
880 U2(n2[0]).y, U2(n1[0]).y);
881 ok(U3(n2[0]).z == U3(n1[0]).z, "Wrong component n2[0].z = %f (expected %f)\n",
882 U3(n2[0]).z, U3(n1[0]).z);
883 ok(U1(n2[1]).x == U1(n1[1]).x, "Wrong component n2[1].x = %f (expected %f)\n",
884 U1(n2[1]).x, U1(n1[1]).x);
885 ok(U2(n2[1]).y == U2(n1[1]).y, "Wrong component n2[1].y = %f (expected %f)\n",
886 U2(n2[1]).y, U2(n1[1]).y);
887 ok(U3(n2[1]).z == U3(n1[1]).z, "Wrong component n2[1].z = %f (expected %f)\n",
888 U3(n2[1]).z, U3(n1[1]).z);
889 ok(U1(n2[2]).x == U1(n1[2]).x, "Wrong component n2[2].x = %f (expected %f)\n",
890 U1(n2[2]).x, U1(n1[2]).x);
891 ok(U2(n2[2]).y == U2(n1[2]).y, "Wrong component n2[2].y = %f (expected %f)\n",
892 U2(n2[2]).y, U2(n1[2]).y);
893 ok(U3(n2[2]).z == U3(n1[2]).z, "Wrong component n2[2].z = %f (expected %f)\n",
894 U3(n2[2]).z, U3(n1[2]).z);
895
896 IDirect3DRMFace_Release(face);
897 IDirect3DRMFaceArray_Release(array1);
898 }
899
900 IDirect3DRMFace2_Release(face2);
901 IDirect3DRMMeshBuilder3_Release(MeshBuilder3);
902 IDirect3DRM3_Release(d3drm3);
903 IDirect3DRM2_Release(d3drm2);
904 IDirect3DRM_Release(d3drm);
905 }
906
907 static void test_Frame(void)
908 {
909 HRESULT hr;
910 IDirect3DRM *d3drm;
911 IDirect3DRMFrame *pFrameC;
912 IDirect3DRMFrame *pFrameP1;
913 IDirect3DRMFrame *pFrameP2;
914 IDirect3DRMFrame *pFrameTmp;
915 IDirect3DRMFrameArray *frame_array;
916 IDirect3DRMMeshBuilder *mesh_builder;
917 IDirect3DRMVisual *visual1;
918 IDirect3DRMVisual *visual_tmp;
919 IDirect3DRMVisualArray *visual_array;
920 IDirect3DRMLight *light1;
921 IDirect3DRMLight *light_tmp;
922 IDirect3DRMLightArray *light_array;
923 D3DCOLOR color;
924 DWORD count;
925 CHAR cname[64] = {0};
926
927 hr = pDirect3DRMCreate(&d3drm);
928 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
929
930 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameC);
931 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
932 CHECK_REFCOUNT(pFrameC, 1);
933
934 hr = IDirect3DRMFrame_GetClassName(pFrameC, NULL, cname);
935 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
936 hr = IDirect3DRMFrame_GetClassName(pFrameC, NULL, NULL);
937 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
938 count = 1;
939 hr = IDirect3DRMFrame_GetClassName(pFrameC, &count, cname);
940 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
941 count = sizeof(cname);
942 hr = IDirect3DRMFrame_GetClassName(pFrameC, &count, cname);
943 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
944 ok(count == sizeof("Frame"), "wrong size: %u\n", count);
945 ok(!strcmp(cname, "Frame"), "Expected cname to be \"Frame\", but got \"%s\"\n", cname);
946
947 hr = IDirect3DRMFrame_GetParent(pFrameC, NULL);
948 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
949 pFrameTmp = (void*)0xdeadbeef;
950 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
951 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
952 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
953 CHECK_REFCOUNT(pFrameC, 1);
954
955 frame_array = NULL;
956 hr = IDirect3DRMFrame_GetChildren(pFrameC, &frame_array);
957 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
958 ok(!!frame_array, "frame_array = %p\n", frame_array);
959 if (frame_array)
960 {
961 count = IDirect3DRMFrameArray_GetSize(frame_array);
962 ok(count == 0, "count = %u\n", count);
963 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
964 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
965 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
966 IDirect3DRMFrameArray_Release(frame_array);
967 }
968
969 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP1);
970 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
971
972 /* GetParent with NULL pointer */
973 hr = IDirect3DRMFrame_GetParent(pFrameP1, NULL);
974 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
975 CHECK_REFCOUNT(pFrameP1, 1);
976
977 /* [Add/Delete]Child with NULL pointer */
978 hr = IDirect3DRMFrame_AddChild(pFrameP1, NULL);
979 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
980 CHECK_REFCOUNT(pFrameP1, 1);
981
982 hr = IDirect3DRMFrame_DeleteChild(pFrameP1, NULL);
983 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
984 CHECK_REFCOUNT(pFrameP1, 1);
985
986 /* Add child to first parent */
987 pFrameTmp = (void*)0xdeadbeef;
988 hr = IDirect3DRMFrame_GetParent(pFrameP1, &pFrameTmp);
989 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
990 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
991
992 hr = IDirect3DRMFrame_AddChild(pFrameP1, pFrameC);
993 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
994 CHECK_REFCOUNT(pFrameP1, 1);
995 CHECK_REFCOUNT(pFrameC, 2);
996
997 frame_array = NULL;
998 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
999 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1000 /* In some older version of d3drm, creating IDirect3DRMFrameArray object with GetChildren does not increment refcount of children frames */
1001 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
1002 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
1003 if (frame_array)
1004 {
1005 count = IDirect3DRMFrameArray_GetSize(frame_array);
1006 ok(count == 1, "count = %u\n", count);
1007 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1008 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1009 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1010 ok((get_refcount((IUnknown*)pFrameC) == 4) || broken(get_refcount((IUnknown*)pFrameC) == 3),
1011 "Invalid refcount. Expected 4 (or 3) got %d\n", get_refcount((IUnknown*)pFrameC));
1012 IDirect3DRMFrame_Release(pFrameTmp);
1013 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
1014 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
1015 IDirect3DRMFrameArray_Release(frame_array);
1016 CHECK_REFCOUNT(pFrameC, 2);
1017 }
1018
1019 pFrameTmp = (void*)0xdeadbeef;
1020 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1021 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1022 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1023 CHECK_REFCOUNT(pFrameP1, 2);
1024
1025 /* Add child to second parent */
1026 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP2);
1027 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1028
1029 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1030 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1031 CHECK_REFCOUNT(pFrameC, 2);
1032
1033 frame_array = NULL;
1034 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1035 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1036 if (frame_array)
1037 {
1038 count = IDirect3DRMFrameArray_GetSize(frame_array);
1039 ok(count == 1, "count = %u\n", count);
1040 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1041 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1042 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1043 IDirect3DRMFrame_Release(pFrameTmp);
1044 IDirect3DRMFrameArray_Release(frame_array);
1045 }
1046
1047 frame_array = NULL;
1048 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
1049 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1050 if (frame_array)
1051 {
1052 count = IDirect3DRMFrameArray_GetSize(frame_array);
1053 ok(count == 0, "count = %u\n", count);
1054 pFrameTmp = (void*)0xdeadbeef;
1055 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1056 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1057 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1058 IDirect3DRMFrameArray_Release(frame_array);
1059 }
1060
1061 pFrameTmp = (void*)0xdeadbeef;
1062 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1063 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1064 ok(pFrameTmp == pFrameP2, "pFrameTmp = %p\n", pFrameTmp);
1065 CHECK_REFCOUNT(pFrameP2, 2);
1066 CHECK_REFCOUNT(pFrameC, 2);
1067
1068 /* Add child again */
1069 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1070 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1071 CHECK_REFCOUNT(pFrameC, 2);
1072
1073 frame_array = NULL;
1074 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1075 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1076 if (frame_array)
1077 {
1078 count = IDirect3DRMFrameArray_GetSize(frame_array);
1079 ok(count == 1, "count = %u\n", count);
1080 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1081 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1082 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1083 IDirect3DRMFrame_Release(pFrameTmp);
1084 IDirect3DRMFrameArray_Release(frame_array);
1085 }
1086
1087 /* Delete child */
1088 hr = IDirect3DRMFrame_DeleteChild(pFrameP2, pFrameC);
1089 ok(hr == D3DRM_OK, "Cannot delete child frame (hr = %x)\n", hr);
1090 CHECK_REFCOUNT(pFrameC, 1);
1091
1092 frame_array = NULL;
1093 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1094 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1095 if (frame_array)
1096 {
1097 count = IDirect3DRMFrameArray_GetSize(frame_array);
1098 ok(count == 0, "count = %u\n", count);
1099 pFrameTmp = (void*)0xdeadbeef;
1100 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1101 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1102 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1103 IDirect3DRMFrameArray_Release(frame_array);
1104 }
1105
1106 pFrameTmp = (void*)0xdeadbeef;
1107 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1108 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1109 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1110
1111 /* Add two children */
1112 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1113 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1114 CHECK_REFCOUNT(pFrameC, 2);
1115
1116 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1);
1117 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1118 CHECK_REFCOUNT(pFrameP1, 3);
1119
1120 frame_array = NULL;
1121 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1122 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1123 if (frame_array)
1124 {
1125 count = IDirect3DRMFrameArray_GetSize(frame_array);
1126 ok(count == 2, "count = %u\n", count);
1127 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1128 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1129 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1130 IDirect3DRMFrame_Release(pFrameTmp);
1131 hr = IDirect3DRMFrameArray_GetElement(frame_array, 1, &pFrameTmp);
1132 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1133 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1134 IDirect3DRMFrame_Release(pFrameTmp);
1135 IDirect3DRMFrameArray_Release(frame_array);
1136 }
1137
1138 /* [Add/Delete]Visual with NULL pointer */
1139 hr = IDirect3DRMFrame_AddVisual(pFrameP1, NULL);
1140 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1141 CHECK_REFCOUNT(pFrameP1, 3);
1142
1143 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, NULL);
1144 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1145 CHECK_REFCOUNT(pFrameP1, 3);
1146
1147 /* Create Visual */
1148 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &mesh_builder);
1149 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
1150 visual1 = (IDirect3DRMVisual *)mesh_builder;
1151
1152 /* Add Visual to first parent */
1153 hr = IDirect3DRMFrame_AddVisual(pFrameP1, visual1);
1154 ok(hr == D3DRM_OK, "Cannot add visual (hr = %x)\n", hr);
1155 CHECK_REFCOUNT(pFrameP1, 3);
1156 CHECK_REFCOUNT(visual1, 2);
1157
1158 visual_array = NULL;
1159 hr = IDirect3DRMFrame_GetVisuals(pFrameP1, &visual_array);
1160 ok(hr == D3DRM_OK, "Cannot get visuals (hr = %x)\n", hr);
1161 if (visual_array)
1162 {
1163 count = IDirect3DRMVisualArray_GetSize(visual_array);
1164 ok(count == 1, "count = %u\n", count);
1165 hr = IDirect3DRMVisualArray_GetElement(visual_array, 0, &visual_tmp);
1166 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1167 ok(visual_tmp == visual1, "visual_tmp = %p\n", visual_tmp);
1168 IDirect3DRMVisual_Release(visual_tmp);
1169 IDirect3DRMVisualArray_Release(visual_array);
1170 }
1171
1172 /* Delete Visual */
1173 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, visual1);
1174 ok(hr == D3DRM_OK, "Cannot delete visual (hr = %x)\n", hr);
1175 CHECK_REFCOUNT(pFrameP1, 3);
1176 IDirect3DRMMeshBuilder_Release(mesh_builder);
1177
1178 /* [Add/Delete]Light with NULL pointer */
1179 hr = IDirect3DRMFrame_AddLight(pFrameP1, NULL);
1180 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1181 CHECK_REFCOUNT(pFrameP1, 3);
1182
1183 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, NULL);
1184 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1185 CHECK_REFCOUNT(pFrameP1, 3);
1186
1187 /* Create Light */
1188 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.1, 0.2, 0.3, &light1);
1189 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1190
1191 /* Add Light to first parent */
1192 hr = IDirect3DRMFrame_AddLight(pFrameP1, light1);
1193 ok(hr == D3DRM_OK, "Cannot add light (hr = %x)\n", hr);
1194 CHECK_REFCOUNT(pFrameP1, 3);
1195 CHECK_REFCOUNT(light1, 2);
1196
1197 light_array = NULL;
1198 hr = IDirect3DRMFrame_GetLights(pFrameP1, &light_array);
1199 ok(hr == D3DRM_OK, "Cannot get lights (hr = %x)\n", hr);
1200 if (light_array)
1201 {
1202 count = IDirect3DRMLightArray_GetSize(light_array);
1203 ok(count == 1, "count = %u\n", count);
1204 hr = IDirect3DRMLightArray_GetElement(light_array, 0, &light_tmp);
1205 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1206 ok(light_tmp == light1, "light_tmp = %p\n", light_tmp);
1207 IDirect3DRMLight_Release(light_tmp);
1208 IDirect3DRMLightArray_Release(light_array);
1209 }
1210
1211 /* Delete Light */
1212 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, light1);
1213 ok(hr == D3DRM_OK, "Cannot delete light (hr = %x)\n", hr);
1214 CHECK_REFCOUNT(pFrameP1, 3);
1215 IDirect3DRMLight_Release(light1);
1216
1217 /* Test SceneBackground on first parent */
1218 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1219 ok(color == 0xff000000, "wrong color (%x)\n", color);
1220
1221 hr = IDirect3DRMFrame_SetSceneBackground(pFrameP1, 0xff180587);
1222 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1223 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1224 ok(color == 0xff180587, "wrong color (%x)\n", color);
1225
1226 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(pFrameP1, 0.5, 0.5, 0.5);
1227 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1228 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1229 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1230
1231 /* Cleanup */
1232 IDirect3DRMFrame_Release(pFrameP2);
1233 CHECK_REFCOUNT(pFrameC, 2);
1234 CHECK_REFCOUNT(pFrameP1, 3);
1235
1236 IDirect3DRMFrame_Release(pFrameC);
1237 IDirect3DRMFrame_Release(pFrameP1);
1238
1239 IDirect3DRM_Release(d3drm);
1240 }
1241
1242 static void test_Viewport(void)
1243 {
1244 IDirectDrawClipper *pClipper;
1245 HRESULT hr;
1246 IDirect3DRM *d3drm;
1247 IDirect3DRMDevice *device;
1248 IDirect3DRMFrame *frame;
1249 IDirect3DRMViewport *viewport;
1250 GUID driver;
1251 HWND window;
1252 RECT rc;
1253 DWORD size;
1254 CHAR cname[64] = {0};
1255
1256 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
1257 GetClientRect(window, &rc);
1258
1259 hr = pDirect3DRMCreate(&d3drm);
1260 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1261
1262 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
1263 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1264
1265 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
1266 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1267
1268 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1269 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
1270 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1271
1272 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
1273 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1274
1275 hr = IDirect3DRM_CreateViewport(d3drm, device, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1276 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %x)\n", hr);
1277
1278 hr = IDirect3DRMViewport_GetClassName(viewport, NULL, cname);
1279 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1280 hr = IDirect3DRMViewport_GetClassName(viewport, NULL, NULL);
1281 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1282 size = 1;
1283 hr = IDirect3DRMViewport_GetClassName(viewport, &size, cname);
1284 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1285 size = sizeof(cname);
1286 hr = IDirect3DRMViewport_GetClassName(viewport, &size, cname);
1287 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1288 ok(size == sizeof("Viewport"), "wrong size: %u\n", size);
1289 ok(!strcmp(cname, "Viewport"), "Expected cname to be \"Viewport\", but got \"%s\"\n", cname);
1290
1291 IDirect3DRMViewport_Release(viewport);
1292 IDirect3DRMFrame_Release(frame);
1293 IDirect3DRMDevice_Release(device);
1294 IDirectDrawClipper_Release(pClipper);
1295
1296 IDirect3DRM_Release(d3drm);
1297 DestroyWindow(window);
1298 }
1299
1300 static void test_Light(void)
1301 {
1302 HRESULT hr;
1303 IDirect3DRM *d3drm;
1304 IDirect3DRMLight *light;
1305 D3DRMLIGHTTYPE type;
1306 D3DCOLOR color;
1307 DWORD size;
1308 CHAR cname[64] = {0};
1309
1310 hr = pDirect3DRMCreate(&d3drm);
1311 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1312
1313 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.5, 0.5, 0.5, &light);
1314 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1315
1316 hr = IDirect3DRMLight_GetClassName(light, NULL, cname);
1317 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1318 hr = IDirect3DRMLight_GetClassName(light, NULL, NULL);
1319 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1320 size = 1;
1321 hr = IDirect3DRMLight_GetClassName(light, &size, cname);
1322 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1323 size = sizeof(cname);
1324 hr = IDirect3DRMLight_GetClassName(light, &size, cname);
1325 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1326 ok(size == sizeof("Light"), "wrong size: %u\n", size);
1327 ok(!strcmp(cname, "Light"), "Expected cname to be \"Light\", but got \"%s\"\n", cname);
1328
1329 type = IDirect3DRMLight_GetType(light);
1330 ok(type == D3DRMLIGHT_SPOT, "wrong type (%u)\n", type);
1331
1332 color = IDirect3DRMLight_GetColor(light);
1333 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1334
1335 hr = IDirect3DRMLight_SetType(light, D3DRMLIGHT_POINT);
1336 ok(hr == D3DRM_OK, "Cannot set type (hr = %x)\n", hr);
1337 type = IDirect3DRMLight_GetType(light);
1338 ok(type == D3DRMLIGHT_POINT, "wrong type (%u)\n", type);
1339
1340 hr = IDirect3DRMLight_SetColor(light, 0xff180587);
1341 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1342 color = IDirect3DRMLight_GetColor(light);
1343 ok(color == 0xff180587, "wrong color (%x)\n", color);
1344
1345 hr = IDirect3DRMLight_SetColorRGB(light, 0.5, 0.5, 0.5);
1346 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1347 color = IDirect3DRMLight_GetColor(light);
1348 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1349
1350 IDirect3DRMLight_Release(light);
1351
1352 IDirect3DRM_Release(d3drm);
1353 }
1354
1355 static void test_Material2(void)
1356 {
1357 HRESULT hr;
1358 IDirect3DRM *d3drm;
1359 IDirect3DRM3 *d3drm3;
1360 IDirect3DRMMaterial2 *material2;
1361 D3DVALUE r, g, b;
1362 DWORD size;
1363 CHAR cname[64] = {0};
1364
1365 hr = pDirect3DRMCreate(&d3drm);
1366 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1367
1368 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
1369 {
1370 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
1371 IDirect3DRM_Release(d3drm);
1372 return;
1373 }
1374
1375 hr = IDirect3DRM3_CreateMaterial(d3drm3, 18.5f, &material2);
1376 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMaterial2 interface (hr = %x)\n", hr);
1377
1378 hr = IDirect3DRMMaterial2_GetClassName(material2, NULL, cname);
1379 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1380 hr = IDirect3DRMMaterial2_GetClassName(material2, NULL, NULL);
1381 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1382 size = 1;
1383 hr = IDirect3DRMMaterial2_GetClassName(material2, &size, cname);
1384 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1385 size = sizeof(cname);
1386 hr = IDirect3DRMMaterial2_GetClassName(material2, &size, cname);
1387 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1388 ok(size == sizeof("Material"), "wrong size: %u\n", size);
1389 ok(!strcmp(cname, "Material"), "Expected cname to be \"Material\", but got \"%s\"\n", cname);
1390
1391 r = IDirect3DRMMaterial2_GetPower(material2);
1392 ok(r == 18.5f, "wrong power (%f)\n", r);
1393
1394 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
1395 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1396 ok(r == 0.0f && g == 0.0f && b == 0.0f, "wrong emissive r=%f g=%f b=%f, expected r=0.0 g=0.0 b=0.0\n", r, g, b);
1397
1398 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
1399 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1400 ok(r == 1.0f && g == 1.0f && b == 1.0f, "wrong specular r=%f g=%f b=%f, expected r=1.0 g=1.0 b=1.0\n", r, g, b);
1401
1402 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
1403 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1404 ok(r == 0.0f && g == 0.0f && b == 0.0f, "wrong ambient r=%f g=%f b=%f, expected r=0.0 g=0.0 b=0.0\n", r, g, b);
1405
1406 hr = IDirect3DRMMaterial2_SetPower(material2, 5.87f);
1407 ok(hr == D3DRM_OK, "Cannot set power (hr = %x)\n", hr);
1408 r = IDirect3DRMMaterial2_GetPower(material2);
1409 ok(r == 5.87f, "wrong power (%f)\n", r);
1410
1411 hr = IDirect3DRMMaterial2_SetEmissive(material2, 0.5f, 0.5f, 0.5f);
1412 ok(hr == D3DRM_OK, "Cannot set emissive (hr = %x)\n", hr);
1413 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
1414 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1415 ok(r == 0.5f && g == 0.5f && b == 0.5f, "wrong emissive r=%f g=%f b=%f, expected r=0.5 g=0.5 b=0.5\n", r, g, b);
1416
1417 hr = IDirect3DRMMaterial2_SetSpecular(material2, 0.6f, 0.6f, 0.6f);
1418 ok(hr == D3DRM_OK, "Cannot set specular (hr = %x)\n", hr);
1419 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
1420 ok(hr == D3DRM_OK, "Cannot get specular (hr = %x)\n", hr);
1421 ok(r == 0.6f && g == 0.6f && b == 0.6f, "wrong specular r=%f g=%f b=%f, expected r=0.6 g=0.6 b=0.6\n", r, g, b);
1422
1423 hr = IDirect3DRMMaterial2_SetAmbient(material2, 0.7f, 0.7f, 0.7f);
1424 ok(hr == D3DRM_OK, "Cannot set ambient (hr = %x)\n", hr);
1425 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
1426 ok(hr == D3DRM_OK, "Cannot get ambient (hr = %x)\n", hr);
1427 ok(r == 0.7f && g == 0.7f && b == 0.7f, "wrong ambient r=%f g=%f b=%f, expected r=0.7 g=0.7 b=0.7\n", r, g, b);
1428
1429 IDirect3DRMMaterial2_Release(material2);
1430
1431 IDirect3DRM3_Release(d3drm3);
1432 IDirect3DRM_Release(d3drm);
1433 }
1434
1435 static void test_Texture(void)
1436 {
1437 HRESULT hr;
1438 IDirect3DRM *d3drm;
1439 IDirect3DRMTexture *texture;
1440 D3DRMIMAGE initimg = {
1441 2, 2, 1, 1, 32,
1442 TRUE, 2 * sizeof(DWORD), NULL, NULL,
1443 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
1444 };
1445 DWORD pixel[4] = { 20000, 30000, 10000, 0 };
1446 DWORD size;
1447 CHAR cname[64] = {0};
1448
1449 hr = pDirect3DRMCreate(&d3drm);
1450 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1451
1452 initimg.buffer1 = &pixel;
1453 hr = IDirect3DRM_CreateTexture(d3drm, &initimg, &texture);
1454 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMTexture interface (hr = %x)\n", hr);
1455
1456 hr = IDirect3DRMTexture_GetClassName(texture, NULL, cname);
1457 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1458 hr = IDirect3DRMTexture_GetClassName(texture, NULL, NULL);
1459 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1460 size = 1;
1461 hr = IDirect3DRMTexture_GetClassName(texture, &size, cname);
1462 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1463 size = sizeof(cname);
1464 hr = IDirect3DRMTexture_GetClassName(texture, &size, cname);
1465 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1466 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1467 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1468
1469 IDirect3DRMTexture_Release(texture);
1470
1471 IDirect3DRM_Release(d3drm);
1472 }
1473
1474 static void test_Device(void)
1475 {
1476 IDirectDrawClipper *pClipper;
1477 HRESULT hr;
1478 IDirect3DRM *d3drm;
1479 IDirect3DRMDevice *device;
1480 IDirect3DRMWinDevice *win_device;
1481 GUID driver;
1482 HWND window;
1483 RECT rc;
1484 DWORD size;
1485 CHAR cname[64] = {0};
1486
1487 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
1488 GetClientRect(window, &rc);
1489
1490 hr = pDirect3DRMCreate(&d3drm);
1491 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1492
1493 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
1494 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1495
1496 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
1497 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1498
1499 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1500 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
1501 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1502
1503 hr = IDirect3DRMDevice_GetClassName(device, NULL, cname);
1504 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1505 hr = IDirect3DRMDevice_GetClassName(device, NULL, NULL);
1506 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1507 size = 1;
1508 hr = IDirect3DRMDevice_GetClassName(device, &size, cname);
1509 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1510 size = sizeof(cname);
1511 hr = IDirect3DRMDevice_GetClassName(device, &size, cname);
1512 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1513 ok(size == sizeof("Device"), "wrong size: %u\n", size);
1514 ok(!strcmp(cname, "Device"), "Expected cname to be \"Device\", but got \"%s\"\n", cname);
1515
1516 /* WinDevice */
1517 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMWinDevice, (void **)&win_device)))
1518 {
1519 win_skip("Cannot get IDirect3DRMWinDevice interface (hr = %x), skipping tests\n", hr);
1520 goto cleanup;
1521 }
1522
1523 hr = IDirect3DRMWinDevice_GetClassName(win_device, NULL, cname);
1524 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1525 hr = IDirect3DRMWinDevice_GetClassName(win_device, NULL, NULL);
1526 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1527 size = 1;
1528 hr = IDirect3DRMWinDevice_GetClassName(win_device, &size, cname);
1529 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1530 size = sizeof(cname);
1531 hr = IDirect3DRMWinDevice_GetClassName(win_device, &size, cname);
1532 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1533 ok(size == sizeof("Device"), "wrong size: %u\n", size);
1534 ok(!strcmp(cname, "Device"), "Expected cname to be \"Device\", but got \"%s\"\n", cname);
1535
1536 IDirect3DRMWinDevice_Release(win_device);
1537
1538 cleanup:
1539 IDirect3DRMDevice_Release(device);
1540 IDirectDrawClipper_Release(pClipper);
1541
1542 IDirect3DRM_Release(d3drm);
1543 DestroyWindow(window);
1544 }
1545
1546 static void test_frame_transform(void)
1547 {
1548 HRESULT hr;
1549 IDirect3DRM *d3drm;
1550 IDirect3DRMFrame *frame;
1551 D3DRMMATRIX4D matrix;
1552
1553 hr = pDirect3DRMCreate(&d3drm);
1554 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1555
1556 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
1557 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1558
1559 hr = IDirect3DRMFrame_GetTransform(frame, matrix);
1560 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetTransform returned hr = %x\n", hr);
1561 ok(!memcmp(matrix, identity, sizeof(D3DRMMATRIX4D)), "Returned matrix is not identity\n");
1562
1563 IDirect3DRMFrame_Release(frame);
1564 IDirect3DRM_Release(d3drm);
1565 }
1566
1567 static int nb_objects = 0;
1568 static const GUID* refiids[] =
1569 {
1570 &IID_IDirect3DRMMeshBuilder,
1571 &IID_IDirect3DRMMeshBuilder,
1572 &IID_IDirect3DRMFrame,
1573 &IID_IDirect3DRMMaterial /* Not taken into account and not notified */
1574 };
1575
1576 static void __cdecl object_load_callback(IDirect3DRMObject *object, REFIID objectguid, void *arg)
1577 {
1578 ok(object != NULL, "Arg 1 should not be null\n");
1579 ok(IsEqualGUID(objectguid, refiids[nb_objects]), "Arg 2 is incorrect\n");
1580 ok(arg == (void *)0xdeadbeef, "Arg 3 should be 0xdeadbeef (got %p)\n", arg);
1581 nb_objects++;
1582 }
1583
1584 static void test_d3drm_load(void)
1585 {
1586 HRESULT hr;
1587 IDirect3DRM *d3drm;
1588 D3DRMLOADMEMORY info;
1589 const GUID* req_refiids[] = { &IID_IDirect3DRMMeshBuilder, &IID_IDirect3DRMFrame, &IID_IDirect3DRMMaterial };
1590
1591 hr = pDirect3DRMCreate(&d3drm);
1592 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1593
1594 info.lpMemory = data_d3drm_load;
1595 info.dSize = strlen(data_d3drm_load);
1596 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID **)req_refiids, 3, D3DRMLOAD_FROMMEMORY,
1597 object_load_callback, (void *)0xdeadbeef, NULL, NULL, NULL);
1598 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
1599 ok(nb_objects == 3, "Should have loaded 3 objects (got %d)\n", nb_objects);
1600
1601 IDirect3DRM_Release(d3drm);
1602 }
1603
1604 IDirect3DRMMeshBuilder *mesh_builder = NULL;
1605
1606 static void __cdecl object_load_callback_frame(IDirect3DRMObject *object, REFIID object_guid, void *arg)
1607 {
1608 HRESULT hr;
1609 IDirect3DRMFrame *frame;
1610 IDirect3DRMVisualArray *array;
1611 IDirect3DRMVisual *visual;
1612 ULONG size;
1613 char name[128];
1614
1615 hr = IDirect3DRMObject_QueryInterface(object, &IID_IDirect3DRMFrame, (void**)&frame);
1616 ok(hr == D3DRM_OK, "IDirect3DRMObject_QueryInterface returned %x\n", hr);
1617
1618 hr = IDirect3DRMFrame_GetVisuals(frame, &array);
1619 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetVisuals returned %x\n", hr);
1620
1621 size = IDirect3DRMVisualArray_GetSize(array);
1622 ok(size == 1, "Wrong size %u returned, expected 1\n", size);
1623
1624 hr = IDirect3DRMVisualArray_GetElement(array, 0, &visual);
1625 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetElement returned %x\n", hr);
1626
1627 hr = IDirect3DRMVisual_QueryInterface(visual, &IID_IDirect3DRMMeshBuilder, (void**)&mesh_builder);
1628 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetSize returned %x\n", hr);
1629
1630 size = sizeof(name);
1631 hr = IDirect3DRMMeshBuilder_GetName(mesh_builder, &size, name);
1632 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned %x\n", hr);
1633 ok(!strcmp(name, "mesh1"), "Wrong name %s, expected mesh1\n", name);
1634
1635 IDirect3DRMVisual_Release(visual);
1636 IDirect3DRMVisualArray_Release(array);
1637 IDirect3DRMFrame_Release(frame);
1638 }
1639
1640 struct {
1641 int vertex_count;
1642 int face_count;
1643 int vertex_per_face;
1644 int face_data_size;
1645 DWORD color;
1646 float power;
1647 float specular[3];
1648 float emissive[3];
1649 } groups[3] = {
1650 { 4, 3, 3, 9, 0x4c0000ff, 30.0f, { 0.31f, 0.32f, 0.33f }, { 0.34f, 0.35f, 0.36f } },
1651 { 4, 2, 3, 6, 0x3300ff00, 20.0f, { 0.21f, 0.22f, 0.23f }, { 0.24f, 0.25f, 0.26f } },
1652 { 3, 1, 3, 3, 0x19ff0000, 10.0f, { 0.11f, 0.12f, 0.13f }, { 0.14f, 0.15f, 0.16f } }
1653 };
1654
1655 static void test_frame_mesh_materials(void)
1656 {
1657 HRESULT hr;
1658 IDirect3DRM *d3drm;
1659 D3DRMLOADMEMORY info;
1660 const GUID *req_refiids[] = { &IID_IDirect3DRMFrame };
1661 IDirect3DRMMesh *mesh;
1662 ULONG size;
1663 IDirect3DRMMaterial *material;
1664 IDirect3DRMTexture *texture;
1665 int i;
1666
1667 hr = pDirect3DRMCreate(&d3drm);
1668 ok(hr == D3DRM_OK, "Direct3DRMCreate returned %x\n", hr);
1669
1670 info.lpMemory = data_frame_mesh_materials;
1671 info.dSize = strlen(data_frame_mesh_materials);
1672 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID**)req_refiids, 1, D3DRMLOAD_FROMMEMORY, object_load_callback_frame, (void*)0xdeadbeef, NULL, NULL, NULL);
1673 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
1674
1675 hr = IDirect3DRMMeshBuilder_CreateMesh(mesh_builder, &mesh);
1676 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_CreateMesh returned %x\n", hr);
1677
1678 size = IDirect3DRMMesh_GetGroupCount(mesh);
1679 ok(size == 3, "Wrong size %u returned, expected 3\n", size);
1680
1681 for (i = 0; i < size; i++)
1682 {
1683 D3DVALUE red, green, blue, power;
1684 D3DCOLOR color;
1685 unsigned vertex_count, face_count, vertex_per_face;
1686 DWORD face_data_size;
1687
1688 hr = IDirect3DRMMesh_GetGroup(mesh, i, &vertex_count, &face_count, &vertex_per_face, &face_data_size, NULL);
1689 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroup returned %x\n", i, hr);
1690 ok(vertex_count == groups[i].vertex_count, "Group %d: Wrong vertex count %d, expected %d\n", i, vertex_count, groups[i].vertex_count);
1691 ok(face_count == groups[i].face_count, "Group %d: Wrong face count %d; expected %d\n", i, face_count, groups[i].face_count);
1692 ok(vertex_per_face == groups[i].vertex_per_face, "Group %d: Wrong vertex per face %d, expected %d\n", i, vertex_per_face, groups[i].vertex_per_face);
1693 ok(face_data_size == groups[i].face_data_size, "Group %d: Wrong face data size %d, expected %d\n", i, face_data_size, groups[i].face_data_size);
1694
1695 color = IDirect3DRMMesh_GetGroupColor(mesh, i);
1696 ok(color == groups[i].color, "Group %d: Wrong color %x, expected %x\n", i, color, groups[i].color);
1697
1698 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, i, &material);
1699 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupMaterial returned %x\n", i, hr);
1700 ok(material != NULL, "Group %d: No material\n", i);
1701 power = IDirect3DRMMaterial_GetPower(material);
1702 ok(power == groups[i].power, "Group %d: Wrong power %f, expected %f\n", i, power, groups[i].power);
1703 hr = IDirect3DRMMaterial_GetSpecular(material, &red, &green, &blue);
1704 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetSpecular returned %x\n", i, hr);
1705 ok(red == groups[i].specular[0], "Group %d: Wrong specular red %f, expected %f\n", i, red, groups[i].specular[0]);
1706 ok(green == groups[i].specular[1], "Group %d: Wrong specular green %f, pD3DRMexpected %f\n", i, green, groups[i].specular[1]);
1707 ok(blue == groups[i].specular[2], "Group %d: Wrong specular blue %f, expected %f\n", i, blue, groups[i].specular[2]);
1708 hr = IDirect3DRMMaterial_GetEmissive(material, &red, &green, &blue);
1709 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetEmissive returned %x\n", i, hr);
1710 ok(red == groups[i].emissive[0], "Group %d: Wrong emissive red %f, expected %f\n", i, red, groups[i].emissive[0]);
1711 ok(green == groups[i].emissive[1], "Group %d: Wrong emissive green %f, expected %f\n", i, green, groups[i].emissive[1]);
1712 ok(blue == groups[i].emissive[2], "Group %d: Wrong emissive blue %f, expected %f\n", i, blue, groups[i].emissive[2]);
1713
1714 hr = IDirect3DRMMesh_GetGroupTexture(mesh, i, &texture);
1715 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupTexture returned %x\n", i, hr);
1716 ok(!texture, "Group %d: Unexpected texture\n", i);
1717
1718 if (material)
1719 IDirect3DRMMaterial_Release(material);
1720 if (texture)
1721 IDirect3DRMTexture_Release(texture);
1722 }
1723
1724 IDirect3DRMMesh_Release(mesh);
1725 IDirect3DRMMeshBuilder_Release(mesh_builder);
1726 IDirect3DRM_Release(d3drm);
1727 }
1728
1729 START_TEST(d3drm)
1730 {
1731 if (!InitFunctionPtrs())
1732 return;
1733
1734 test_MeshBuilder();
1735 test_MeshBuilder3();
1736 test_Mesh();
1737 test_Face();
1738 test_Frame();
1739 test_Device();
1740 test_Viewport();
1741 test_Light();
1742 test_Material2();
1743 test_Texture();
1744 test_frame_transform();
1745 test_d3drm_load();
1746 test_frame_mesh_materials();
1747
1748 FreeLibrary(d3drm_handle);
1749 }