[D3DRM_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / d3drm / d3drm.c
1 /*
2 * Copyright 2010, 2012 Christian Costa
3 * Copyright 2012 André Hentschel
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define COBJMACROS
22 #include <d3d.h>
23 #include <initguid.h>
24 #include <d3drm.h>
25 #include <d3drmwin.h>
26
27 #include "wine/test.h"
28
29 #define CHECK_REFCOUNT(obj,rc) \
30 { \
31 int rc_new = rc; \
32 int count = get_refcount( (IUnknown *)obj ); \
33 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
34 }
35
36 static ULONG get_refcount(IUnknown *object)
37 {
38 IUnknown_AddRef( object );
39 return IUnknown_Release( object );
40 }
41
42 static BOOL match_float(float a, float b)
43 {
44 return (a - b) < 0.000001f;
45 }
46
47 static D3DRMMATRIX4D identity = {
48 { 1.0f, 0.0f, 0.0f, 0.0f },
49 { 0.0f, 1.0f, 0.0f, 0.0f },
50 { 0.0f, 0.0f, 1.0f, 0.0f },
51 { 0.0f, 0.0f, 0.0f, 1.0f }
52 };
53
54 static char data_bad_version[] =
55 "xof 0302txt 0064\n"
56 "Header Object\n"
57 "{\n"
58 "1; 2; 3;\n"
59 "}\n";
60
61 static char data_no_mesh[] =
62 "xof 0302txt 0064\n"
63 "Header Object\n"
64 "{\n"
65 "1; 0; 1;\n"
66 "}\n";
67
68 static char data_ok[] =
69 "xof 0302txt 0064\n"
70 "Header Object\n"
71 "{\n"
72 "1; 0; 1;\n"
73 "}\n"
74 "Mesh Object\n"
75 "{\n"
76 "4;\n"
77 "1.0; 0.0; 0.0;,\n"
78 "0.0; 1.0; 0.0;,\n"
79 "0.0; 0.0; 1.0;,\n"
80 "1.0; 1.0; 1.0;;\n"
81 "3;\n"
82 "3; 0, 1, 2;,\n"
83 "3; 1, 2, 3;,\n"
84 "3; 3, 1, 2;;\n"
85 "}\n";
86
87 static char data_full[] =
88 "xof 0302txt 0064\n"
89 "Header { 1; 0; 1; }\n"
90 "Mesh {\n"
91 " 3;\n"
92 " 0.1; 0.2; 0.3;,\n"
93 " 0.4; 0.5; 0.6;,\n"
94 " 0.7; 0.8; 0.9;;\n"
95 " 1;\n"
96 " 3; 0, 1, 2;;\n"
97 " MeshMaterialList {\n"
98 " 1; 1; 0;\n"
99 " Material {\n"
100 " 0.0; 1.0; 0.0; 1.0;;\n"
101 " 30.0;\n"
102 " 1.0; 0.0; 0.0;;\n"
103 " 0.5; 0.5; 0.5;;\n"
104 " TextureFileName {\n"
105 " \"Texture.bmp\";\n"
106 " }\n"
107 " }\n"
108 " }\n"
109 " MeshNormals {\n"
110 " 3;\n"
111 " 1.1; 1.2; 1.3;,\n"
112 " 1.4; 1.5; 1.6;,\n"
113 " 1.7; 1.8; 1.9;;\n"
114 " 1;"
115 " 3; 0, 1, 2;;\n"
116 " }\n"
117 " MeshTextureCoords {\n"
118 " 3;\n"
119 " 0.13; 0.17;,\n"
120 " 0.23; 0.27;,\n"
121 " 0.33; 0.37;;\n"
122 " }\n"
123 "}\n";
124
125 static char data_d3drm_load[] =
126 "xof 0302txt 0064\n"
127 "Header Object\n"
128 "{\n"
129 "1; 0; 1;\n"
130 "}\n"
131 "Mesh Object1\n"
132 "{\n"
133 " 1;\n"
134 " 0.1; 0.2; 0.3;,\n"
135 " 1;\n"
136 " 3; 0, 1, 2;;\n"
137 "}\n"
138 "Mesh Object2\n"
139 "{\n"
140 " 1;\n"
141 " 0.1; 0.2; 0.3;,\n"
142 " 1;\n"
143 " 3; 0, 1, 2;;\n"
144 "}\n"
145 "Frame Scene\n"
146 "{\n"
147 " {Object1}\n"
148 " {Object2}\n"
149 "}\n"
150 "Material\n"
151 "{\n"
152 " 0.1, 0.2, 0.3, 0.4;;\n"
153 " 0.5;\n"
154 " 0.6, 0.7, 0.8;;\n"
155 " 0.9, 1.0, 1.1;;\n"
156 "}\n";
157
158 static char data_frame_mesh_materials[] =
159 "xof 0302txt 0064\n"
160 "Header { 1; 0; 1; }\n"
161 "Frame {\n"
162 " Mesh mesh1 {\n"
163 " 5;\n"
164 " 0.1; 0.2; 0.3;,\n"
165 " 0.4; 0.5; 0.6;,\n"
166 " 0.7; 0.8; 0.9;,\n"
167 " 1.1; 1.2; 1.3;,\n"
168 " 1.4; 1.5; 1.6;;\n"
169 " 6;\n"
170 " 3; 0, 1, 2;,\n"
171 " 3; 0, 2, 1;,\n"
172 " 3; 1, 2, 3;,\n"
173 " 3; 1, 3, 2;,\n"
174 " 3; 2, 3, 4;,\n"
175 " 3; 2, 4, 3;;\n"
176 " MeshMaterialList {\n"
177 " 3; 6; 0, 1, 1, 2, 2, 2;\n"
178 " Material mat1 {\n"
179 " 1.0; 0.0; 0.0; 0.1;;\n"
180 " 10.0;\n"
181 " 0.11; 0.12; 0.13;;\n"
182 " 0.14; 0.15; 0.16;;\n"
183 " }\n"
184 " Material mat2 {\n"
185 " 0.0; 1.0; 0.0; 0.2;;\n"
186 " 20.0;\n"
187 " 0.21; 0.22; 0.23;;\n"
188 " 0.24; 0.25; 0.26;;\n"
189 " }\n"
190 " Material mat3 {\n"
191 " 0.0; 0.0; 1.0; 0.3;;\n"
192 " 30.0;\n"
193 " 0.31; 0.32; 0.33;;\n"
194 " 0.34; 0.35; 0.36;;\n"
195 " }\n"
196 " }\n"
197 " }\n"
198 "}\n";
199
200 static void test_MeshBuilder(void)
201 {
202 HRESULT hr;
203 IDirect3DRM *d3drm;
204 IDirect3DRMMeshBuilder *pMeshBuilder;
205 IDirect3DRMMesh *mesh;
206 D3DRMLOADMEMORY info;
207 int val;
208 DWORD val1, val2, val3;
209 D3DVALUE valu, valv;
210 D3DVECTOR v[3];
211 D3DVECTOR n[4];
212 DWORD f[8];
213 char name[10];
214 DWORD size;
215 D3DCOLOR color;
216 CHAR cname[64] = {0};
217
218 hr = Direct3DRMCreate(&d3drm);
219 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
220
221 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
222 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
223
224 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, NULL, cname);
225 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
226 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, NULL, NULL);
227 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
228 size = 1;
229 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, &size, cname);
230 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
231 size = sizeof(cname);
232 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, &size, cname);
233 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
234 ok(size == sizeof("Builder"), "wrong size: %u\n", size);
235 ok(!strcmp(cname, "Builder"), "Expected cname to be \"Builder\", but got \"%s\"\n", cname);
236
237 info.lpMemory = data_bad_version;
238 info.dSize = strlen(data_bad_version);
239 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
240 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
241
242 info.lpMemory = data_no_mesh;
243 info.dSize = strlen(data_no_mesh);
244 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
245 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
246
247 info.lpMemory = data_ok;
248 info.dSize = strlen(data_ok);
249 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
250 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
251
252 size = sizeof(name);
253 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
254 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
255 ok(!strcmp(name, "Object"), "Retrieved name '%s' instead of 'Object'\n", name);
256 size = strlen("Object"); /* No space for null character */
257 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
258 ok(hr == E_INVALIDARG, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
259 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, NULL);
260 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
261 size = sizeof(name);
262 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
263 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
264 ok(size == 0, "Size should be 0 instead of %u\n", size);
265 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, "");
266 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
267 size = sizeof(name);
268 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
269 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
270 ok(!strcmp(name, ""), "Retrieved name '%s' instead of ''\n", name);
271
272 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
273 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
274
275 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
276 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
277
278 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, NULL, &val2, NULL, &val3, NULL);
279 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
280 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
281 ok(val2 == 4, "Wrong number of normals %d (must be 4)\n", val2);
282 ok(val3 == 22, "Wrong number of face data bytes %d (must be 22)\n", val3);
283
284 /* Check that Load method generated default normals */
285 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, NULL, &val2, n, NULL, NULL);
286 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
287 ok(match_float(U1(n[0]).x, 0.577350f), "Wrong component n[0].x = %f (expected %f)\n", U1(n[0]).x, 0.577350f);
288 ok(match_float(U2(n[0]).y, 0.577350f), "Wrong component n[0].y = %f (expected %f)\n", U2(n[0]).y, 0.577350f);
289 ok(match_float(U3(n[0]).z, 0.577350f), "Wrong component n[0].z = %f (expected %f)\n", U3(n[0]).z, 0.577350f);
290 ok(match_float(U1(n[1]).x, -0.229416f), "Wrong component n[1].x = %f (expected %f)\n", U1(n[1]).x, -0.229416f);
291 ok(match_float(U2(n[1]).y, 0.688247f), "Wrong component n[1].y = %f (expected %f)\n", U2(n[1]).y, 0.688247f);
292 ok(match_float(U3(n[1]).z, 0.688247f), "Wrong component n[1].z = %f (expected %f)\n", U3(n[1]).z, 0.688247f);
293 ok(match_float(U1(n[2]).x, -0.229416f), "Wrong component n[2].x = %f (expected %f)\n", U1(n[2]).x, -0.229416f);
294 ok(match_float(U2(n[2]).y, 0.688247f), "Wrong component n[2].y = %f (expected %f)\n", U2(n[2]).y, 0.688247f);
295 ok(match_float(U3(n[2]).z, 0.688247f), "Wrong component n[2].z = %f (expected %f)\n", U3(n[2]).z, 0.688247f);
296 ok(match_float(U1(n[3]).x, -0.577350f), "Wrong component n[3].x = %f (expected %f)\n", U1(n[3]).x, -0.577350f);
297 ok(match_float(U2(n[3]).y, 0.577350f), "Wrong component n[3].y = %f (expected %f)\n", U2(n[3]).y, 0.577350f);
298 ok(match_float(U3(n[3]).z, 0.577350f), "Wrong component n[3].z = %f (expected %f)\n", U3(n[3]).z, 0.577350f);
299
300 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
301 valu = 1.23f;
302 valv = 3.21f;
303 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
304 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
305 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
306 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
307 valu = 1.23f;
308 valv = 3.21f;
309 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 1, &valu, &valv);
310 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
311 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
312 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
313 valu = 1.23f;
314 valv = 3.21f;
315 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 2, &valu, &valv);
316 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
317 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
318 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
319 valu = 1.23f;
320 valv = 3.21f;
321 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 3, &valu, &valv);
322 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
323 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
324 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
325 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 4, &valu, &valv);
326 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
327
328 valu = 1.23f;
329 valv = 3.21f;
330 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 0, valu, valv);
331 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
332 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 4, valu, valv);
333 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
334
335 valu = 0.0f;
336 valv = 0.0f;
337 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
338 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
339 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
340 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
341
342 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
343
344 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
345 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
346
347 /* No group in mesh when mesh builder is not loaded */
348 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
349 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
350 if (hr == D3DRM_OK)
351 {
352 DWORD nb_groups;
353
354 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
355 ok(nb_groups == 0, "GetCroupCount returned %u\n", nb_groups);
356
357 IDirect3DRMMesh_Release(mesh);
358 }
359
360 info.lpMemory = data_full;
361 info.dSize = strlen(data_full);
362 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
363 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
364
365 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
366 ok(val == 3, "Wrong number of vertices %d (must be 3)\n", val);
367
368 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
369 ok(val == 1, "Wrong number of faces %d (must be 1)\n", val);
370
371 /* Check no buffer size and too small buffer size errors */
372 val1 = 1; val2 = 3; val3 = 8;
373 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
374 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
375 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, v, &val2, n, &val3, f);
376 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
377 val1 = 3; val2 = 1; val3 = 8;
378 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
379 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
380 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, NULL, n, &val3, f);
381 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
382 val1 = 3; val2 = 3; val3 = 1;
383 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
384 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
385 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, NULL, f);
386 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
387
388 val1 = 3; val2 = 3; val3 = 8;
389 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
390 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
391 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
392 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
393 ok(val3 == 8, "Wrong number of face data bytes %d (must be 8)\n", val3);
394 ok(U1(v[0]).x == 0.1f, "Wrong component v[0].x = %f (expected 0.1)\n", U1(v[0]).x);
395 ok(U2(v[0]).y == 0.2f, "Wrong component v[0].y = %f (expected 0.2)\n", U2(v[0]).y);
396 ok(U3(v[0]).z == 0.3f, "Wrong component v[0].z = %f (expected 0.3)\n", U3(v[0]).z);
397 ok(U1(v[1]).x == 0.4f, "Wrong component v[1].x = %f (expected 0.4)\n", U1(v[1]).x);
398 ok(U2(v[1]).y == 0.5f, "Wrong component v[1].y = %f (expected 0.5)\n", U2(v[1]).y);
399 ok(U3(v[1]).z == 0.6f, "Wrong component v[1].z = %f (expected 0.6)\n", U3(v[1]).z);
400 ok(U1(v[2]).x == 0.7f, "Wrong component v[2].x = %f (expected 0.7)\n", U1(v[2]).x);
401 ok(U2(v[2]).y == 0.8f, "Wrong component v[2].y = %f (expected 0.8)\n", U2(v[2]).y);
402 ok(U3(v[2]).z == 0.9f, "Wrong component v[2].z = %f (expected 0.9)\n", U3(v[2]).z);
403 ok(U1(n[0]).x == 1.1f, "Wrong component n[0].x = %f (expected 1.1)\n", U1(n[0]).x);
404 ok(U2(n[0]).y == 1.2f, "Wrong component n[0].y = %f (expected 1.2)\n", U2(n[0]).y);
405 ok(U3(n[0]).z == 1.3f, "Wrong component n[0].z = %f (expected 1.3)\n", U3(n[0]).z);
406 ok(U1(n[1]).x == 1.4f, "Wrong component n[1].x = %f (expected 1.4)\n", U1(n[1]).x);
407 ok(U2(n[1]).y == 1.5f, "Wrong component n[1].y = %f (expected 1.5)\n", U2(n[1]).y);
408 ok(U3(n[1]).z == 1.6f, "Wrong component n[1].z = %f (expected 1.6)\n", U3(n[1]).z);
409 ok(U1(n[2]).x == 1.7f, "Wrong component n[2].x = %f (expected 1.7)\n", U1(n[2]).x);
410 ok(U2(n[2]).y == 1.8f, "Wrong component n[2].y = %f (expected 1.8)\n", U2(n[2]).y);
411 ok(U3(n[2]).z == 1.9f, "Wrong component n[2].z = %f (expected 1.9)\n", U3(n[2]).z);
412 ok(f[0] == 3 , "Wrong component f[0] = %d (expected 3)\n", f[0]);
413 ok(f[1] == 0 , "Wrong component f[1] = %d (expected 0)\n", f[1]);
414 ok(f[2] == 0 , "Wrong component f[2] = %d (expected 0)\n", f[2]);
415 ok(f[3] == 1 , "Wrong component f[3] = %d (expected 1)\n", f[3]);
416 ok(f[4] == 1 , "Wrong component f[4] = %d (expected 1)\n", f[4]);
417 ok(f[5] == 2 , "Wrong component f[5] = %d (expected 2)\n", f[5]);
418 ok(f[6] == 2 , "Wrong component f[6] = %d (expected 2)\n", f[6]);
419 ok(f[7] == 0 , "Wrong component f[7] = %d (expected 0)\n", f[7]);
420
421 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
422 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
423 if (hr == D3DRM_OK)
424 {
425 DWORD nb_groups;
426 unsigned nb_vertices, nb_faces, nb_face_vertices;
427 DWORD data_size;
428 IDirect3DRMMaterial *material = (IDirect3DRMMaterial *)0xdeadbeef;
429 IDirect3DRMTexture *texture = (IDirect3DRMTexture *)0xdeadbeef;
430 D3DVALUE values[3];
431
432 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
433 ok(nb_groups == 1, "GetCroupCount returned %u\n", nb_groups);
434 hr = IDirect3DRMMesh_GetGroup(mesh, 1, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
435 ok(hr == D3DRMERR_BADVALUE, "GetCroup returned hr = %x\n", hr);
436 hr = IDirect3DRMMesh_GetGroup(mesh, 0, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
437 ok(hr == D3DRM_OK, "GetCroup failed returning hr = %x\n", hr);
438 ok(nb_vertices == 3, "Wrong number of vertices %u (must be 3)\n", nb_vertices);
439 ok(nb_faces == 1, "Wrong number of faces %u (must be 1)\n", nb_faces);
440 ok(nb_face_vertices == 3, "Wrong number of vertices per face %u (must be 3)\n", nb_face_vertices);
441 ok(data_size == 3, "Wrong number of face data bytes %u (must be 3)\n", data_size);
442 color = IDirect3DRMMesh_GetGroupColor(mesh, 0);
443 ok(color == 0xff00ff00, "Wrong color returned %#x instead of %#x\n", color, 0xff00ff00);
444 hr = IDirect3DRMMesh_GetGroupTexture(mesh, 0, &texture);
445 ok(hr == D3DRM_OK, "GetCroupTexture failed returning hr = %x\n", hr);
446 ok(texture == NULL, "No texture should be present\n");
447 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, 0, &material);
448 ok(hr == D3DRM_OK, "GetCroupMaterial failed returning hr = %x\n", hr);
449 ok(material != NULL, "No material present\n");
450 hr = IDirect3DRMMaterial_GetEmissive(material, &values[0], &values[1], &values[2]);
451 ok(hr == D3DRM_OK, "Failed to get emissive color, hr %#x.\n", hr);
452 ok(values[0] == 0.5f, "Got unexpected red component %.8e.\n", values[0]);
453 ok(values[1] == 0.5f, "Got unexpected green component %.8e.\n", values[1]);
454 ok(values[2] == 0.5f, "Got unexpected blue component %.8e.\n", values[2]);
455 hr = IDirect3DRMMaterial_GetSpecular(material, &values[0], &values[1], &values[2]);
456 ok(hr == D3DRM_OK, "Failed to get specular color, hr %#x.\n", hr);
457 ok(values[0] == 1.0f, "Got unexpected red component %.8e.\n", values[0]);
458 ok(values[1] == 0.0f, "Got unexpected green component %.8e.\n", values[1]);
459 ok(values[2] == 0.0f, "Got unexpected blue component %.8e.\n", values[2]);
460 values[0] = IDirect3DRMMaterial_GetPower(material);
461 ok(values[0] == 30.0f, "Got unexpected power value %.8e.\n", values[0]);
462 IDirect3DRMMaterial_Release(material);
463
464 IDirect3DRMMesh_Release(mesh);
465 }
466
467 hr = IDirect3DRMMeshBuilder_Scale(pMeshBuilder, 2, 3 ,4);
468 ok(hr == D3DRM_OK, "Scale failed returning hr = %x\n", hr);
469
470 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
471 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
472 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
473 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
474 ok(U1(v[0]).x == 0.1f*2, "Wrong component v[0].x = %f (expected %f)\n", U1(v[0]).x, 0.1f*2);
475 ok(U2(v[0]).y == 0.2f*3, "Wrong component v[0].y = %f (expected %f)\n", U2(v[0]).y, 0.2f*3);
476 ok(U3(v[0]).z == 0.3f*4, "Wrong component v[0].z = %f (expected %f)\n", U3(v[0]).z, 0.3f*4);
477 ok(U1(v[1]).x == 0.4f*2, "Wrong component v[1].x = %f (expected %f)\n", U1(v[1]).x, 0.4f*2);
478 ok(U2(v[1]).y == 0.5f*3, "Wrong component v[1].y = %f (expected %f)\n", U2(v[1]).y, 0.5f*3);
479 ok(U3(v[1]).z == 0.6f*4, "Wrong component v[1].z = %f (expected %f)\n", U3(v[1]).z, 0.6f*4);
480 ok(U1(v[2]).x == 0.7f*2, "Wrong component v[2].x = %f (expected %f)\n", U1(v[2]).x, 0.7f*2);
481 ok(U2(v[2]).y == 0.8f*3, "Wrong component v[2].y = %f (expected %f)\n", U2(v[2]).y, 0.8f*3);
482 ok(U3(v[2]).z == 0.9f*4, "Wrong component v[2].z = %f (expected %f)\n", U3(v[2]).z, 0.9f*4);
483 /* Normals are not affected by Scale */
484 ok(U1(n[0]).x == 1.1f, "Wrong component n[0].x = %f (expected %f)\n", U1(n[0]).x, 1.1f);
485 ok(U2(n[0]).y == 1.2f, "Wrong component n[0].y = %f (expected %f)\n", U2(n[0]).y, 1.2f);
486 ok(U3(n[0]).z == 1.3f, "Wrong component n[0].z = %f (expected %f)\n", U3(n[0]).z, 1.3f);
487 ok(U1(n[1]).x == 1.4f, "Wrong component n[1].x = %f (expected %f)\n", U1(n[1]).x, 1.4f);
488 ok(U2(n[1]).y == 1.5f, "Wrong component n[1].y = %f (expected %f)\n", U2(n[1]).y, 1.5f);
489 ok(U3(n[1]).z == 1.6f, "Wrong component n[1].z = %f (expected %f)\n", U3(n[1]).z, 1.6f);
490 ok(U1(n[2]).x == 1.7f, "Wrong component n[2].x = %f (expected %f)\n", U1(n[2]).x, 1.7f);
491 ok(U2(n[2]).y == 1.8f, "Wrong component n[2].y = %f (expected %f)\n", U2(n[2]).y, 1.8f);
492 ok(U3(n[2]).z == 1.9f, "Wrong component n[2].z = %f (expected %f)\n", U3(n[2]).z, 1.9f);
493
494 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
495
496 IDirect3DRM_Release(d3drm);
497 }
498
499 static void test_MeshBuilder3(void)
500 {
501 HRESULT hr;
502 IDirect3DRM *d3drm;
503 IDirect3DRM3 *d3drm3;
504 IDirect3DRMMeshBuilder3 *pMeshBuilder3;
505 D3DRMLOADMEMORY info;
506 int val;
507 DWORD val1;
508 D3DVALUE valu, valv;
509 DWORD size;
510 CHAR cname[64] = {0};
511
512 hr = Direct3DRMCreate(&d3drm);
513 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
514
515 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
516 {
517 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
518 IDirect3DRM_Release(d3drm);
519 return;
520 }
521
522 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &pMeshBuilder3);
523 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
524
525 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, NULL, cname);
526 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
527 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, NULL, NULL);
528 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
529 size = 1;
530 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, &size, cname);
531 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
532 size = sizeof(cname);
533 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, &size, cname);
534 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
535 ok(size == sizeof("Builder"), "wrong size: %u\n", size);
536 ok(!strcmp(cname, "Builder"), "Expected cname to be \"Builder\", but got \"%s\"\n", cname);
537
538 info.lpMemory = data_bad_version;
539 info.dSize = strlen(data_bad_version);
540 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
541 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
542
543 info.lpMemory = data_no_mesh;
544 info.dSize = strlen(data_no_mesh);
545 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
546 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
547
548 info.lpMemory = data_ok;
549 info.dSize = strlen(data_ok);
550 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
551 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
552
553 val = IDirect3DRMMeshBuilder3_GetVertexCount(pMeshBuilder3);
554 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
555
556 val = IDirect3DRMMeshBuilder3_GetFaceCount(pMeshBuilder3);
557 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
558
559 hr = IDirect3DRMMeshBuilder3_GetVertices(pMeshBuilder3, 0, &val1, NULL);
560 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
561 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
562
563 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
564 valu = 1.23f;
565 valv = 3.21f;
566 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
567 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
568 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
569 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
570 valu = 1.23f;
571 valv = 3.21f;
572 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 1, &valu, &valv);
573 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
574 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
575 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
576 valu = 1.23f;
577 valv = 3.21f;
578 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 2, &valu, &valv);
579 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
580 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
581 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
582 valu = 1.23f;
583 valv = 3.21f;
584 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 3, &valu, &valv);
585 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
586 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
587 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
588 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 4, &valu, &valv);
589 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
590
591 valu = 1.23f;
592 valv = 3.21f;
593 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 0, valu, valv);
594 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
595 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 4, valu, valv);
596 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
597
598 valu = 0.0f;
599 valv = 0.0f;
600 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
601 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
602 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
603 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
604
605 IDirect3DRMMeshBuilder3_Release(pMeshBuilder3);
606 IDirect3DRM3_Release(d3drm3);
607 IDirect3DRM_Release(d3drm);
608 }
609
610 static void test_Mesh(void)
611 {
612 HRESULT hr;
613 IDirect3DRM *d3drm;
614 IDirect3DRMMesh *mesh;
615 DWORD size;
616 CHAR cname[64] = {0};
617
618 hr = Direct3DRMCreate(&d3drm);
619 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
620
621 hr = IDirect3DRM_CreateMesh(d3drm, &mesh);
622 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMesh interface (hr = %x)\n", hr);
623
624 hr = IDirect3DRMMesh_GetClassName(mesh, NULL, cname);
625 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
626 hr = IDirect3DRMMesh_GetClassName(mesh, NULL, NULL);
627 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
628 size = 1;
629 hr = IDirect3DRMMesh_GetClassName(mesh, &size, cname);
630 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
631 size = sizeof(cname);
632 hr = IDirect3DRMMesh_GetClassName(mesh, &size, cname);
633 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
634 ok(size == sizeof("Mesh"), "wrong size: %u\n", size);
635 ok(!strcmp(cname, "Mesh"), "Expected cname to be \"Mesh\", but got \"%s\"\n", cname);
636
637 IDirect3DRMMesh_Release(mesh);
638
639 IDirect3DRM_Release(d3drm);
640 }
641
642 static void test_Face(void)
643 {
644 HRESULT hr;
645 IDirect3DRM *d3drm;
646 IDirect3DRM2 *d3drm2;
647 IDirect3DRM3 *d3drm3;
648 IDirect3DRMMeshBuilder2 *MeshBuilder2;
649 IDirect3DRMMeshBuilder3 *MeshBuilder3;
650 IDirect3DRMFace *face1;
651 IDirect3DRMFace2 *face2;
652 IDirect3DRMFaceArray *array1;
653 D3DRMLOADMEMORY info;
654 D3DVECTOR v1[4], n1[4], v2[4], n2[4];
655 DWORD count;
656 CHAR cname[64] = {0};
657 int icount;
658
659 hr = Direct3DRMCreate(&d3drm);
660 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
661
662 hr = IDirect3DRM_CreateFace(d3drm, &face1);
663 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
664 if (FAILED(hr))
665 {
666 skip("Cannot get IDirect3DRMFace interface (hr = %x), skipping tests\n", hr);
667 IDirect3DRM_Release(d3drm);
668 return;
669 }
670
671 hr = IDirect3DRMFace_GetClassName(face1, NULL, cname);
672 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
673 hr = IDirect3DRMFace_GetClassName(face1, NULL, NULL);
674 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
675 count = 1;
676 hr = IDirect3DRMFace_GetClassName(face1, &count, cname);
677 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
678 count = sizeof(cname);
679 hr = IDirect3DRMFace_GetClassName(face1, &count, cname);
680 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
681 ok(count == sizeof("Face"), "wrong size: %u\n", count);
682 ok(!strcmp(cname, "Face"), "Expected cname to be \"Face\", but got \"%s\"\n", cname);
683
684 icount = IDirect3DRMFace_GetVertexCount(face1);
685 ok(!icount, "wrong VertexCount: %i\n", icount);
686
687 IDirect3DRMFace_Release(face1);
688
689 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM2, (void **)&d3drm2)))
690 {
691 win_skip("Cannot get IDirect3DRM2 interface (hr = %x), skipping tests\n", hr);
692 IDirect3DRM_Release(d3drm);
693 return;
694 }
695
696 hr = IDirect3DRM2_CreateMeshBuilder(d3drm2, &MeshBuilder2);
697 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder2 interface (hr = %x)\n", hr);
698
699 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
700 ok(!icount, "wrong FaceCount: %i\n", icount);
701
702 array1 = NULL;
703 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
704 todo_wine
705 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
706
707 hr = IDirect3DRMMeshBuilder2_CreateFace(MeshBuilder2, &face1);
708 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
709
710 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
711 todo_wine
712 ok(icount == 1, "wrong FaceCount: %i\n", icount);
713
714 array1 = NULL;
715 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
716 todo_wine
717 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
718 todo_wine
719 ok(array1 != NULL, "pArray = %p\n", array1);
720 if (array1)
721 {
722 IDirect3DRMFace *face;
723 count = IDirect3DRMFaceArray_GetSize(array1);
724 ok(count == 1, "count = %u\n", count);
725 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
726 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
727 IDirect3DRMFace_Release(face);
728 IDirect3DRMFaceArray_Release(array1);
729 }
730
731 icount = IDirect3DRMFace_GetVertexCount(face1);
732 ok(!icount, "wrong VertexCount: %i\n", icount);
733
734 IDirect3DRMFace_Release(face1);
735 IDirect3DRMMeshBuilder2_Release(MeshBuilder2);
736
737 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
738 {
739 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
740 IDirect3DRM_Release(d3drm);
741 return;
742 }
743
744 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &MeshBuilder3);
745 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
746
747 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
748 ok(!icount, "wrong FaceCount: %i\n", icount);
749
750 hr = IDirect3DRMMeshBuilder3_CreateFace(MeshBuilder3, &face2);
751 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace2 interface (hr = %x)\n", hr);
752
753 hr = IDirect3DRMFace2_GetClassName(face2, NULL, cname);
754 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
755 hr = IDirect3DRMFace2_GetClassName(face2, NULL, NULL);
756 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
757 count = 1;
758 hr = IDirect3DRMFace2_GetClassName(face2, &count, cname);
759 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
760 count = sizeof(cname);
761 hr = IDirect3DRMFace2_GetClassName(face2, &count, cname);
762 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
763 ok(count == sizeof("Face"), "wrong size: %u\n", count);
764 ok(!strcmp(cname, "Face"), "Expected cname to be \"Face\", but got \"%s\"\n", cname);
765
766 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
767 todo_wine
768 ok(icount == 1, "wrong FaceCount: %i\n", icount);
769
770 array1 = NULL;
771 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
772 todo_wine
773 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
774 todo_wine
775 ok(array1 != NULL, "pArray = %p\n", array1);
776 if (array1)
777 {
778 IDirect3DRMFace *face;
779 count = IDirect3DRMFaceArray_GetSize(array1);
780 ok(count == 1, "count = %u\n", count);
781 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
782 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
783 IDirect3DRMFace_Release(face);
784 IDirect3DRMFaceArray_Release(array1);
785 }
786
787 icount = IDirect3DRMFace2_GetVertexCount(face2);
788 ok(!icount, "wrong VertexCount: %i\n", icount);
789
790 info.lpMemory = data_ok;
791 info.dSize = strlen(data_ok);
792 hr = IDirect3DRMMeshBuilder3_Load(MeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
793 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
794
795 icount = IDirect3DRMMeshBuilder3_GetVertexCount(MeshBuilder3);
796 ok(icount == 4, "Wrong number of vertices %d (must be 4)\n", icount);
797
798 icount = IDirect3DRMMeshBuilder3_GetNormalCount(MeshBuilder3);
799 ok(icount == 4, "Wrong number of normals %d (must be 4)\n", icount);
800
801 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
802 todo_wine
803 ok(icount == 4, "Wrong number of faces %d (must be 4)\n", icount);
804
805 count = 4;
806 hr = IDirect3DRMMeshBuilder3_GetVertices(MeshBuilder3, 0, &count, v1);
807 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
808 ok(count == 4, "Wrong number of vertices %d (must be 4)\n", count);
809
810 hr = IDirect3DRMMeshBuilder3_GetNormals(MeshBuilder3, 0, &count, n1);
811 ok(hr == D3DRM_OK, "Cannot get normals information (hr = %x)\n", hr);
812 ok(count == 4, "Wrong number of normals %d (must be 4)\n", count);
813
814 array1 = NULL;
815 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
816 todo_wine
817 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
818 todo_wine
819 ok(array1 != NULL, "pArray = %p\n", array1);
820 if (array1)
821 {
822 IDirect3DRMFace *face;
823 count = IDirect3DRMFaceArray_GetSize(array1);
824 ok(count == 4, "count = %u\n", count);
825 hr = IDirect3DRMFaceArray_GetElement(array1, 1, &face);
826 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
827 hr = IDirect3DRMFace_GetVertices(face, &count, v2, n2);
828 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
829 ok(count == 3, "Wrong number of vertices %d (must be 3)\n", count);
830 ok(U1(v2[0]).x == U1(v1[0]).x, "Wrong component v2[0].x = %f (expected %f)\n",
831 U1(v2[0]).x, U1(v1[0]).x);
832 ok(U2(v2[0]).y == U2(v1[0]).y, "Wrong component v2[0].y = %f (expected %f)\n",
833 U2(v2[0]).y, U2(v1[0]).y);
834 ok(U3(v2[0]).z == U3(v1[0]).z, "Wrong component v2[0].z = %f (expected %f)\n",
835 U3(v2[0]).z, U3(v1[0]).z);
836 ok(U1(v2[1]).x == U1(v1[1]).x, "Wrong component v2[1].x = %f (expected %f)\n",
837 U1(v2[1]).x, U1(v1[1]).x);
838 ok(U2(v2[1]).y == U2(v1[1]).y, "Wrong component v2[1].y = %f (expected %f)\n",
839 U2(v2[1]).y, U2(v1[1]).y);
840 ok(U3(v2[1]).z == U3(v1[1]).z, "Wrong component v2[1].z = %f (expected %f)\n",
841 U3(v2[1]).z, U3(v1[1]).z);
842 ok(U1(v2[2]).x == U1(v1[2]).x, "Wrong component v2[2].x = %f (expected %f)\n",
843 U1(v2[2]).x, U1(v1[2]).x);
844 ok(U2(v2[2]).y == U2(v1[2]).y, "Wrong component v2[2].y = %f (expected %f)\n",
845 U2(v2[2]).y, U2(v1[2]).y);
846 ok(U3(v2[2]).z == U3(v1[2]).z, "Wrong component v2[2].z = %f (expected %f)\n",
847 U3(v2[2]).z, U3(v1[2]).z);
848
849 ok(U1(n2[0]).x == U1(n1[0]).x, "Wrong component n2[0].x = %f (expected %f)\n",
850 U1(n2[0]).x, U1(n1[0]).x);
851 ok(U2(n2[0]).y == U2(n1[0]).y, "Wrong component n2[0].y = %f (expected %f)\n",
852 U2(n2[0]).y, U2(n1[0]).y);
853 ok(U3(n2[0]).z == U3(n1[0]).z, "Wrong component n2[0].z = %f (expected %f)\n",
854 U3(n2[0]).z, U3(n1[0]).z);
855 ok(U1(n2[1]).x == U1(n1[1]).x, "Wrong component n2[1].x = %f (expected %f)\n",
856 U1(n2[1]).x, U1(n1[1]).x);
857 ok(U2(n2[1]).y == U2(n1[1]).y, "Wrong component n2[1].y = %f (expected %f)\n",
858 U2(n2[1]).y, U2(n1[1]).y);
859 ok(U3(n2[1]).z == U3(n1[1]).z, "Wrong component n2[1].z = %f (expected %f)\n",
860 U3(n2[1]).z, U3(n1[1]).z);
861 ok(U1(n2[2]).x == U1(n1[2]).x, "Wrong component n2[2].x = %f (expected %f)\n",
862 U1(n2[2]).x, U1(n1[2]).x);
863 ok(U2(n2[2]).y == U2(n1[2]).y, "Wrong component n2[2].y = %f (expected %f)\n",
864 U2(n2[2]).y, U2(n1[2]).y);
865 ok(U3(n2[2]).z == U3(n1[2]).z, "Wrong component n2[2].z = %f (expected %f)\n",
866 U3(n2[2]).z, U3(n1[2]).z);
867
868 IDirect3DRMFace_Release(face);
869 IDirect3DRMFaceArray_Release(array1);
870 }
871
872 IDirect3DRMFace2_Release(face2);
873 IDirect3DRMMeshBuilder3_Release(MeshBuilder3);
874 IDirect3DRM3_Release(d3drm3);
875 IDirect3DRM2_Release(d3drm2);
876 IDirect3DRM_Release(d3drm);
877 }
878
879 static void test_Frame(void)
880 {
881 HRESULT hr;
882 IDirect3DRM *d3drm;
883 IDirect3DRMFrame *pFrameC;
884 IDirect3DRMFrame *pFrameP1;
885 IDirect3DRMFrame *pFrameP2;
886 IDirect3DRMFrame *pFrameTmp;
887 IDirect3DRMFrameArray *frame_array;
888 IDirect3DRMMeshBuilder *mesh_builder;
889 IDirect3DRMVisual *visual1;
890 IDirect3DRMVisual *visual_tmp;
891 IDirect3DRMVisualArray *visual_array;
892 IDirect3DRMLight *light1;
893 IDirect3DRMLight *light_tmp;
894 IDirect3DRMLightArray *light_array;
895 D3DCOLOR color;
896 DWORD count;
897 CHAR cname[64] = {0};
898
899 hr = Direct3DRMCreate(&d3drm);
900 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
901
902 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameC);
903 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
904 CHECK_REFCOUNT(pFrameC, 1);
905
906 hr = IDirect3DRMFrame_GetClassName(pFrameC, NULL, cname);
907 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
908 hr = IDirect3DRMFrame_GetClassName(pFrameC, NULL, NULL);
909 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
910 count = 1;
911 hr = IDirect3DRMFrame_GetClassName(pFrameC, &count, cname);
912 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
913 count = sizeof(cname);
914 hr = IDirect3DRMFrame_GetClassName(pFrameC, &count, cname);
915 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
916 ok(count == sizeof("Frame"), "wrong size: %u\n", count);
917 ok(!strcmp(cname, "Frame"), "Expected cname to be \"Frame\", but got \"%s\"\n", cname);
918
919 hr = IDirect3DRMFrame_GetParent(pFrameC, NULL);
920 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
921 pFrameTmp = (void*)0xdeadbeef;
922 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
923 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
924 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
925 CHECK_REFCOUNT(pFrameC, 1);
926
927 frame_array = NULL;
928 hr = IDirect3DRMFrame_GetChildren(pFrameC, &frame_array);
929 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
930 ok(!!frame_array, "frame_array = %p\n", frame_array);
931 if (frame_array)
932 {
933 count = IDirect3DRMFrameArray_GetSize(frame_array);
934 ok(count == 0, "count = %u\n", count);
935 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
936 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
937 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
938 IDirect3DRMFrameArray_Release(frame_array);
939 }
940
941 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP1);
942 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
943
944 /* GetParent with NULL pointer */
945 hr = IDirect3DRMFrame_GetParent(pFrameP1, NULL);
946 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
947 CHECK_REFCOUNT(pFrameP1, 1);
948
949 /* [Add/Delete]Child with NULL pointer */
950 hr = IDirect3DRMFrame_AddChild(pFrameP1, NULL);
951 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
952 CHECK_REFCOUNT(pFrameP1, 1);
953
954 hr = IDirect3DRMFrame_DeleteChild(pFrameP1, NULL);
955 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
956 CHECK_REFCOUNT(pFrameP1, 1);
957
958 /* Add child to first parent */
959 pFrameTmp = (void*)0xdeadbeef;
960 hr = IDirect3DRMFrame_GetParent(pFrameP1, &pFrameTmp);
961 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
962 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
963
964 hr = IDirect3DRMFrame_AddChild(pFrameP1, pFrameC);
965 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
966 CHECK_REFCOUNT(pFrameP1, 1);
967 CHECK_REFCOUNT(pFrameC, 2);
968
969 frame_array = NULL;
970 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
971 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
972 /* In some older version of d3drm, creating IDirect3DRMFrameArray object with GetChildren does not increment refcount of children frames */
973 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
974 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
975 if (frame_array)
976 {
977 count = IDirect3DRMFrameArray_GetSize(frame_array);
978 ok(count == 1, "count = %u\n", count);
979 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
980 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
981 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
982 ok((get_refcount((IUnknown*)pFrameC) == 4) || broken(get_refcount((IUnknown*)pFrameC) == 3),
983 "Invalid refcount. Expected 4 (or 3) got %d\n", get_refcount((IUnknown*)pFrameC));
984 IDirect3DRMFrame_Release(pFrameTmp);
985 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
986 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
987 IDirect3DRMFrameArray_Release(frame_array);
988 CHECK_REFCOUNT(pFrameC, 2);
989 }
990
991 pFrameTmp = (void*)0xdeadbeef;
992 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
993 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
994 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
995 CHECK_REFCOUNT(pFrameP1, 2);
996
997 /* Add child to second parent */
998 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP2);
999 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1000
1001 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1002 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1003 CHECK_REFCOUNT(pFrameC, 2);
1004
1005 frame_array = NULL;
1006 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1007 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1008 if (frame_array)
1009 {
1010 count = IDirect3DRMFrameArray_GetSize(frame_array);
1011 ok(count == 1, "count = %u\n", count);
1012 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1013 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1014 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1015 IDirect3DRMFrame_Release(pFrameTmp);
1016 IDirect3DRMFrameArray_Release(frame_array);
1017 }
1018
1019 frame_array = NULL;
1020 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
1021 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1022 if (frame_array)
1023 {
1024 count = IDirect3DRMFrameArray_GetSize(frame_array);
1025 ok(count == 0, "count = %u\n", count);
1026 pFrameTmp = (void*)0xdeadbeef;
1027 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1028 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1029 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1030 IDirect3DRMFrameArray_Release(frame_array);
1031 }
1032
1033 pFrameTmp = (void*)0xdeadbeef;
1034 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1035 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1036 ok(pFrameTmp == pFrameP2, "pFrameTmp = %p\n", pFrameTmp);
1037 CHECK_REFCOUNT(pFrameP2, 2);
1038 CHECK_REFCOUNT(pFrameC, 2);
1039
1040 /* Add child again */
1041 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1042 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1043 CHECK_REFCOUNT(pFrameC, 2);
1044
1045 frame_array = NULL;
1046 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1047 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1048 if (frame_array)
1049 {
1050 count = IDirect3DRMFrameArray_GetSize(frame_array);
1051 ok(count == 1, "count = %u\n", count);
1052 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1053 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1054 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1055 IDirect3DRMFrame_Release(pFrameTmp);
1056 IDirect3DRMFrameArray_Release(frame_array);
1057 }
1058
1059 /* Delete child */
1060 hr = IDirect3DRMFrame_DeleteChild(pFrameP2, pFrameC);
1061 ok(hr == D3DRM_OK, "Cannot delete child frame (hr = %x)\n", hr);
1062 CHECK_REFCOUNT(pFrameC, 1);
1063
1064 frame_array = NULL;
1065 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1066 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1067 if (frame_array)
1068 {
1069 count = IDirect3DRMFrameArray_GetSize(frame_array);
1070 ok(count == 0, "count = %u\n", count);
1071 pFrameTmp = (void*)0xdeadbeef;
1072 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1073 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1074 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1075 IDirect3DRMFrameArray_Release(frame_array);
1076 }
1077
1078 pFrameTmp = (void*)0xdeadbeef;
1079 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1080 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1081 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1082
1083 /* Add two children */
1084 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1085 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1086 CHECK_REFCOUNT(pFrameC, 2);
1087
1088 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1);
1089 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1090 CHECK_REFCOUNT(pFrameP1, 3);
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 == 2, "count = %u\n", count);
1099 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1100 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1101 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1102 IDirect3DRMFrame_Release(pFrameTmp);
1103 hr = IDirect3DRMFrameArray_GetElement(frame_array, 1, &pFrameTmp);
1104 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1105 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1106 IDirect3DRMFrame_Release(pFrameTmp);
1107 IDirect3DRMFrameArray_Release(frame_array);
1108 }
1109
1110 /* [Add/Delete]Visual with NULL pointer */
1111 hr = IDirect3DRMFrame_AddVisual(pFrameP1, NULL);
1112 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1113 CHECK_REFCOUNT(pFrameP1, 3);
1114
1115 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, NULL);
1116 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1117 CHECK_REFCOUNT(pFrameP1, 3);
1118
1119 /* Create Visual */
1120 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &mesh_builder);
1121 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
1122 visual1 = (IDirect3DRMVisual *)mesh_builder;
1123
1124 /* Add Visual to first parent */
1125 hr = IDirect3DRMFrame_AddVisual(pFrameP1, visual1);
1126 ok(hr == D3DRM_OK, "Cannot add visual (hr = %x)\n", hr);
1127 CHECK_REFCOUNT(pFrameP1, 3);
1128 CHECK_REFCOUNT(visual1, 2);
1129
1130 visual_array = NULL;
1131 hr = IDirect3DRMFrame_GetVisuals(pFrameP1, &visual_array);
1132 ok(hr == D3DRM_OK, "Cannot get visuals (hr = %x)\n", hr);
1133 if (visual_array)
1134 {
1135 count = IDirect3DRMVisualArray_GetSize(visual_array);
1136 ok(count == 1, "count = %u\n", count);
1137 hr = IDirect3DRMVisualArray_GetElement(visual_array, 0, &visual_tmp);
1138 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1139 ok(visual_tmp == visual1, "visual_tmp = %p\n", visual_tmp);
1140 IDirect3DRMVisual_Release(visual_tmp);
1141 IDirect3DRMVisualArray_Release(visual_array);
1142 }
1143
1144 /* Delete Visual */
1145 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, visual1);
1146 ok(hr == D3DRM_OK, "Cannot delete visual (hr = %x)\n", hr);
1147 CHECK_REFCOUNT(pFrameP1, 3);
1148 IDirect3DRMMeshBuilder_Release(mesh_builder);
1149
1150 /* [Add/Delete]Light with NULL pointer */
1151 hr = IDirect3DRMFrame_AddLight(pFrameP1, NULL);
1152 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1153 CHECK_REFCOUNT(pFrameP1, 3);
1154
1155 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, NULL);
1156 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1157 CHECK_REFCOUNT(pFrameP1, 3);
1158
1159 /* Create Light */
1160 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.1, 0.2, 0.3, &light1);
1161 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1162
1163 /* Add Light to first parent */
1164 hr = IDirect3DRMFrame_AddLight(pFrameP1, light1);
1165 ok(hr == D3DRM_OK, "Cannot add light (hr = %x)\n", hr);
1166 CHECK_REFCOUNT(pFrameP1, 3);
1167 CHECK_REFCOUNT(light1, 2);
1168
1169 light_array = NULL;
1170 hr = IDirect3DRMFrame_GetLights(pFrameP1, &light_array);
1171 ok(hr == D3DRM_OK, "Cannot get lights (hr = %x)\n", hr);
1172 if (light_array)
1173 {
1174 count = IDirect3DRMLightArray_GetSize(light_array);
1175 ok(count == 1, "count = %u\n", count);
1176 hr = IDirect3DRMLightArray_GetElement(light_array, 0, &light_tmp);
1177 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1178 ok(light_tmp == light1, "light_tmp = %p\n", light_tmp);
1179 IDirect3DRMLight_Release(light_tmp);
1180 IDirect3DRMLightArray_Release(light_array);
1181 }
1182
1183 /* Delete Light */
1184 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, light1);
1185 ok(hr == D3DRM_OK, "Cannot delete light (hr = %x)\n", hr);
1186 CHECK_REFCOUNT(pFrameP1, 3);
1187 IDirect3DRMLight_Release(light1);
1188
1189 /* Test SceneBackground on first parent */
1190 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1191 ok(color == 0xff000000, "wrong color (%x)\n", color);
1192
1193 hr = IDirect3DRMFrame_SetSceneBackground(pFrameP1, 0xff180587);
1194 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1195 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1196 ok(color == 0xff180587, "wrong color (%x)\n", color);
1197
1198 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(pFrameP1, 0.5, 0.5, 0.5);
1199 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1200 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1201 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1202
1203 /* Cleanup */
1204 IDirect3DRMFrame_Release(pFrameP2);
1205 CHECK_REFCOUNT(pFrameC, 2);
1206 CHECK_REFCOUNT(pFrameP1, 3);
1207
1208 IDirect3DRMFrame_Release(pFrameC);
1209 IDirect3DRMFrame_Release(pFrameP1);
1210
1211 IDirect3DRM_Release(d3drm);
1212 }
1213
1214 static void test_Viewport(void)
1215 {
1216 IDirectDrawClipper *pClipper;
1217 HRESULT hr;
1218 IDirect3DRM *d3drm;
1219 IDirect3DRMDevice *device;
1220 IDirect3DRMFrame *frame;
1221 IDirect3DRMViewport *viewport;
1222 GUID driver;
1223 HWND window;
1224 RECT rc;
1225 DWORD size;
1226 CHAR cname[64] = {0};
1227
1228 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
1229 GetClientRect(window, &rc);
1230
1231 hr = Direct3DRMCreate(&d3drm);
1232 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1233
1234 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
1235 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1236
1237 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
1238 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1239
1240 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1241 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
1242 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1243
1244 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
1245 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1246
1247 hr = IDirect3DRM_CreateViewport(d3drm, device, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1248 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %x)\n", hr);
1249
1250 hr = IDirect3DRMViewport_GetClassName(viewport, NULL, cname);
1251 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1252 hr = IDirect3DRMViewport_GetClassName(viewport, NULL, NULL);
1253 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1254 size = 1;
1255 hr = IDirect3DRMViewport_GetClassName(viewport, &size, cname);
1256 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1257 size = sizeof(cname);
1258 hr = IDirect3DRMViewport_GetClassName(viewport, &size, cname);
1259 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1260 ok(size == sizeof("Viewport"), "wrong size: %u\n", size);
1261 ok(!strcmp(cname, "Viewport"), "Expected cname to be \"Viewport\", but got \"%s\"\n", cname);
1262
1263 IDirect3DRMViewport_Release(viewport);
1264 IDirect3DRMFrame_Release(frame);
1265 IDirect3DRMDevice_Release(device);
1266 IDirectDrawClipper_Release(pClipper);
1267
1268 IDirect3DRM_Release(d3drm);
1269 DestroyWindow(window);
1270 }
1271
1272 static void test_Light(void)
1273 {
1274 HRESULT hr;
1275 IDirect3DRM *d3drm;
1276 IDirect3DRMLight *light;
1277 D3DRMLIGHTTYPE type;
1278 D3DCOLOR color;
1279 DWORD size;
1280 CHAR cname[64] = {0};
1281
1282 hr = Direct3DRMCreate(&d3drm);
1283 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1284
1285 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.5, 0.5, 0.5, &light);
1286 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1287
1288 hr = IDirect3DRMLight_GetClassName(light, NULL, cname);
1289 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1290 hr = IDirect3DRMLight_GetClassName(light, NULL, NULL);
1291 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1292 size = 1;
1293 hr = IDirect3DRMLight_GetClassName(light, &size, cname);
1294 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1295 size = sizeof(cname);
1296 hr = IDirect3DRMLight_GetClassName(light, &size, cname);
1297 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1298 ok(size == sizeof("Light"), "wrong size: %u\n", size);
1299 ok(!strcmp(cname, "Light"), "Expected cname to be \"Light\", but got \"%s\"\n", cname);
1300
1301 type = IDirect3DRMLight_GetType(light);
1302 ok(type == D3DRMLIGHT_SPOT, "wrong type (%u)\n", type);
1303
1304 color = IDirect3DRMLight_GetColor(light);
1305 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1306
1307 hr = IDirect3DRMLight_SetType(light, D3DRMLIGHT_POINT);
1308 ok(hr == D3DRM_OK, "Cannot set type (hr = %x)\n", hr);
1309 type = IDirect3DRMLight_GetType(light);
1310 ok(type == D3DRMLIGHT_POINT, "wrong type (%u)\n", type);
1311
1312 hr = IDirect3DRMLight_SetColor(light, 0xff180587);
1313 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1314 color = IDirect3DRMLight_GetColor(light);
1315 ok(color == 0xff180587, "wrong color (%x)\n", color);
1316
1317 hr = IDirect3DRMLight_SetColorRGB(light, 0.5, 0.5, 0.5);
1318 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1319 color = IDirect3DRMLight_GetColor(light);
1320 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1321
1322 IDirect3DRMLight_Release(light);
1323
1324 IDirect3DRM_Release(d3drm);
1325 }
1326
1327 static void test_Material2(void)
1328 {
1329 HRESULT hr;
1330 IDirect3DRM *d3drm;
1331 IDirect3DRM3 *d3drm3;
1332 IDirect3DRMMaterial2 *material2;
1333 D3DVALUE r, g, b;
1334 DWORD size;
1335 CHAR cname[64] = {0};
1336
1337 hr = Direct3DRMCreate(&d3drm);
1338 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1339
1340 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
1341 {
1342 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
1343 IDirect3DRM_Release(d3drm);
1344 return;
1345 }
1346
1347 hr = IDirect3DRM3_CreateMaterial(d3drm3, 18.5f, &material2);
1348 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMaterial2 interface (hr = %x)\n", hr);
1349
1350 hr = IDirect3DRMMaterial2_GetClassName(material2, NULL, cname);
1351 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1352 hr = IDirect3DRMMaterial2_GetClassName(material2, NULL, NULL);
1353 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1354 size = 1;
1355 hr = IDirect3DRMMaterial2_GetClassName(material2, &size, cname);
1356 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1357 size = sizeof(cname);
1358 hr = IDirect3DRMMaterial2_GetClassName(material2, &size, cname);
1359 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1360 ok(size == sizeof("Material"), "wrong size: %u\n", size);
1361 ok(!strcmp(cname, "Material"), "Expected cname to be \"Material\", but got \"%s\"\n", cname);
1362
1363 r = IDirect3DRMMaterial2_GetPower(material2);
1364 ok(r == 18.5f, "wrong power (%f)\n", r);
1365
1366 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
1367 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1368 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);
1369
1370 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
1371 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1372 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);
1373
1374 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
1375 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1376 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);
1377
1378 hr = IDirect3DRMMaterial2_SetPower(material2, 5.87f);
1379 ok(hr == D3DRM_OK, "Cannot set power (hr = %x)\n", hr);
1380 r = IDirect3DRMMaterial2_GetPower(material2);
1381 ok(r == 5.87f, "wrong power (%f)\n", r);
1382
1383 hr = IDirect3DRMMaterial2_SetEmissive(material2, 0.5f, 0.5f, 0.5f);
1384 ok(hr == D3DRM_OK, "Cannot set emissive (hr = %x)\n", hr);
1385 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
1386 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1387 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);
1388
1389 hr = IDirect3DRMMaterial2_SetSpecular(material2, 0.6f, 0.6f, 0.6f);
1390 ok(hr == D3DRM_OK, "Cannot set specular (hr = %x)\n", hr);
1391 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
1392 ok(hr == D3DRM_OK, "Cannot get specular (hr = %x)\n", hr);
1393 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);
1394
1395 hr = IDirect3DRMMaterial2_SetAmbient(material2, 0.7f, 0.7f, 0.7f);
1396 ok(hr == D3DRM_OK, "Cannot set ambient (hr = %x)\n", hr);
1397 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
1398 ok(hr == D3DRM_OK, "Cannot get ambient (hr = %x)\n", hr);
1399 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);
1400
1401 IDirect3DRMMaterial2_Release(material2);
1402
1403 IDirect3DRM3_Release(d3drm3);
1404 IDirect3DRM_Release(d3drm);
1405 }
1406
1407 static void test_Texture(void)
1408 {
1409 HRESULT hr;
1410 IDirect3DRM *d3drm;
1411 IDirect3DRMTexture *texture;
1412 D3DRMIMAGE initimg = {
1413 2, 2, 1, 1, 32,
1414 TRUE, 2 * sizeof(DWORD), NULL, NULL,
1415 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
1416 };
1417 DWORD pixel[4] = { 20000, 30000, 10000, 0 };
1418 DWORD size;
1419 CHAR cname[64] = {0};
1420
1421 hr = Direct3DRMCreate(&d3drm);
1422 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1423
1424 initimg.buffer1 = &pixel;
1425 hr = IDirect3DRM_CreateTexture(d3drm, &initimg, &texture);
1426 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMTexture interface (hr = %x)\n", hr);
1427
1428 hr = IDirect3DRMTexture_GetClassName(texture, NULL, cname);
1429 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1430 hr = IDirect3DRMTexture_GetClassName(texture, NULL, NULL);
1431 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1432 size = 1;
1433 hr = IDirect3DRMTexture_GetClassName(texture, &size, cname);
1434 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1435 size = sizeof(cname);
1436 hr = IDirect3DRMTexture_GetClassName(texture, &size, cname);
1437 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1438 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1439 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1440
1441 IDirect3DRMTexture_Release(texture);
1442
1443 IDirect3DRM_Release(d3drm);
1444 }
1445
1446 static void test_Device(void)
1447 {
1448 IDirectDrawClipper *pClipper;
1449 HRESULT hr;
1450 IDirect3DRM *d3drm;
1451 IDirect3DRMDevice *device;
1452 IDirect3DRMWinDevice *win_device;
1453 GUID driver;
1454 HWND window;
1455 RECT rc;
1456 DWORD size;
1457 CHAR cname[64] = {0};
1458
1459 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
1460 GetClientRect(window, &rc);
1461
1462 hr = Direct3DRMCreate(&d3drm);
1463 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1464
1465 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
1466 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1467
1468 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
1469 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1470
1471 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1472 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
1473 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1474
1475 hr = IDirect3DRMDevice_GetClassName(device, NULL, cname);
1476 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1477 hr = IDirect3DRMDevice_GetClassName(device, NULL, NULL);
1478 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1479 size = 1;
1480 hr = IDirect3DRMDevice_GetClassName(device, &size, cname);
1481 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1482 size = sizeof(cname);
1483 hr = IDirect3DRMDevice_GetClassName(device, &size, cname);
1484 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1485 ok(size == sizeof("Device"), "wrong size: %u\n", size);
1486 ok(!strcmp(cname, "Device"), "Expected cname to be \"Device\", but got \"%s\"\n", cname);
1487
1488 /* WinDevice */
1489 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMWinDevice, (void **)&win_device)))
1490 {
1491 win_skip("Cannot get IDirect3DRMWinDevice interface (hr = %x), skipping tests\n", hr);
1492 goto cleanup;
1493 }
1494
1495 hr = IDirect3DRMWinDevice_GetClassName(win_device, NULL, cname);
1496 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1497 hr = IDirect3DRMWinDevice_GetClassName(win_device, NULL, NULL);
1498 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1499 size = 1;
1500 hr = IDirect3DRMWinDevice_GetClassName(win_device, &size, cname);
1501 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1502 size = sizeof(cname);
1503 hr = IDirect3DRMWinDevice_GetClassName(win_device, &size, cname);
1504 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1505 ok(size == sizeof("Device"), "wrong size: %u\n", size);
1506 ok(!strcmp(cname, "Device"), "Expected cname to be \"Device\", but got \"%s\"\n", cname);
1507
1508 IDirect3DRMWinDevice_Release(win_device);
1509
1510 cleanup:
1511 IDirect3DRMDevice_Release(device);
1512 IDirectDrawClipper_Release(pClipper);
1513
1514 IDirect3DRM_Release(d3drm);
1515 DestroyWindow(window);
1516 }
1517
1518 static void test_frame_transform(void)
1519 {
1520 HRESULT hr;
1521 IDirect3DRM *d3drm;
1522 IDirect3DRMFrame *frame;
1523 D3DRMMATRIX4D matrix;
1524
1525 hr = Direct3DRMCreate(&d3drm);
1526 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1527
1528 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
1529 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1530
1531 hr = IDirect3DRMFrame_GetTransform(frame, matrix);
1532 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetTransform returned hr = %x\n", hr);
1533 ok(!memcmp(matrix, identity, sizeof(D3DRMMATRIX4D)), "Returned matrix is not identity\n");
1534
1535 IDirect3DRMFrame_Release(frame);
1536 IDirect3DRM_Release(d3drm);
1537 }
1538
1539 static int nb_objects = 0;
1540 static const GUID* refiids[] =
1541 {
1542 &IID_IDirect3DRMMeshBuilder,
1543 &IID_IDirect3DRMMeshBuilder,
1544 &IID_IDirect3DRMFrame,
1545 &IID_IDirect3DRMMaterial /* Not taken into account and not notified */
1546 };
1547
1548 static void __cdecl object_load_callback(IDirect3DRMObject *object, REFIID objectguid, void *arg)
1549 {
1550 ok(object != NULL, "Arg 1 should not be null\n");
1551 ok(IsEqualGUID(objectguid, refiids[nb_objects]), "Arg 2 is incorrect\n");
1552 ok(arg == (void *)0xdeadbeef, "Arg 3 should be 0xdeadbeef (got %p)\n", arg);
1553 nb_objects++;
1554 }
1555
1556 static void test_d3drm_load(void)
1557 {
1558 HRESULT hr;
1559 IDirect3DRM *d3drm;
1560 D3DRMLOADMEMORY info;
1561 const GUID* req_refiids[] = { &IID_IDirect3DRMMeshBuilder, &IID_IDirect3DRMFrame, &IID_IDirect3DRMMaterial };
1562
1563 hr = Direct3DRMCreate(&d3drm);
1564 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1565
1566 info.lpMemory = data_d3drm_load;
1567 info.dSize = strlen(data_d3drm_load);
1568 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID **)req_refiids, 3, D3DRMLOAD_FROMMEMORY,
1569 object_load_callback, (void *)0xdeadbeef, NULL, NULL, NULL);
1570 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
1571 ok(nb_objects == 3, "Should have loaded 3 objects (got %d)\n", nb_objects);
1572
1573 IDirect3DRM_Release(d3drm);
1574 }
1575
1576 IDirect3DRMMeshBuilder *mesh_builder = NULL;
1577
1578 static void __cdecl object_load_callback_frame(IDirect3DRMObject *object, REFIID object_guid, void *arg)
1579 {
1580 HRESULT hr;
1581 IDirect3DRMFrame *frame;
1582 IDirect3DRMVisualArray *array;
1583 IDirect3DRMVisual *visual;
1584 ULONG size;
1585 char name[128];
1586
1587 hr = IDirect3DRMObject_QueryInterface(object, &IID_IDirect3DRMFrame, (void**)&frame);
1588 ok(hr == D3DRM_OK, "IDirect3DRMObject_QueryInterface returned %x\n", hr);
1589
1590 hr = IDirect3DRMFrame_GetVisuals(frame, &array);
1591 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetVisuals returned %x\n", hr);
1592
1593 size = IDirect3DRMVisualArray_GetSize(array);
1594 ok(size == 1, "Wrong size %u returned, expected 1\n", size);
1595
1596 hr = IDirect3DRMVisualArray_GetElement(array, 0, &visual);
1597 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetElement returned %x\n", hr);
1598
1599 hr = IDirect3DRMVisual_QueryInterface(visual, &IID_IDirect3DRMMeshBuilder, (void**)&mesh_builder);
1600 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetSize returned %x\n", hr);
1601
1602 size = sizeof(name);
1603 hr = IDirect3DRMMeshBuilder_GetName(mesh_builder, &size, name);
1604 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned %x\n", hr);
1605 ok(!strcmp(name, "mesh1"), "Wrong name %s, expected mesh1\n", name);
1606
1607 IDirect3DRMVisual_Release(visual);
1608 IDirect3DRMVisualArray_Release(array);
1609 IDirect3DRMFrame_Release(frame);
1610 }
1611
1612 struct {
1613 int vertex_count;
1614 int face_count;
1615 int vertex_per_face;
1616 int face_data_size;
1617 DWORD color;
1618 float power;
1619 float specular[3];
1620 float emissive[3];
1621 } groups[3] = {
1622 { 4, 3, 3, 9, 0x4c0000ff, 30.0f, { 0.31f, 0.32f, 0.33f }, { 0.34f, 0.35f, 0.36f } },
1623 { 4, 2, 3, 6, 0x3300ff00, 20.0f, { 0.21f, 0.22f, 0.23f }, { 0.24f, 0.25f, 0.26f } },
1624 { 3, 1, 3, 3, 0x19ff0000, 10.0f, { 0.11f, 0.12f, 0.13f }, { 0.14f, 0.15f, 0.16f } }
1625 };
1626
1627 static void test_frame_mesh_materials(void)
1628 {
1629 HRESULT hr;
1630 IDirect3DRM *d3drm;
1631 D3DRMLOADMEMORY info;
1632 const GUID *req_refiids[] = { &IID_IDirect3DRMFrame };
1633 IDirect3DRMMesh *mesh;
1634 ULONG size;
1635 IDirect3DRMMaterial *material;
1636 IDirect3DRMTexture *texture;
1637 int i;
1638
1639 hr = Direct3DRMCreate(&d3drm);
1640 ok(hr == D3DRM_OK, "Direct3DRMCreate returned %x\n", hr);
1641
1642 info.lpMemory = data_frame_mesh_materials;
1643 info.dSize = strlen(data_frame_mesh_materials);
1644 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID**)req_refiids, 1, D3DRMLOAD_FROMMEMORY, object_load_callback_frame, (void*)0xdeadbeef, NULL, NULL, NULL);
1645 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
1646
1647 hr = IDirect3DRMMeshBuilder_CreateMesh(mesh_builder, &mesh);
1648 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_CreateMesh returned %x\n", hr);
1649
1650 size = IDirect3DRMMesh_GetGroupCount(mesh);
1651 ok(size == 3, "Wrong size %u returned, expected 3\n", size);
1652
1653 for (i = 0; i < size; i++)
1654 {
1655 D3DVALUE red, green, blue, power;
1656 D3DCOLOR color;
1657 unsigned vertex_count, face_count, vertex_per_face;
1658 DWORD face_data_size;
1659
1660 hr = IDirect3DRMMesh_GetGroup(mesh, i, &vertex_count, &face_count, &vertex_per_face, &face_data_size, NULL);
1661 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroup returned %x\n", i, hr);
1662 ok(vertex_count == groups[i].vertex_count, "Group %d: Wrong vertex count %d, expected %d\n", i, vertex_count, groups[i].vertex_count);
1663 ok(face_count == groups[i].face_count, "Group %d: Wrong face count %d; expected %d\n", i, face_count, groups[i].face_count);
1664 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);
1665 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);
1666
1667 color = IDirect3DRMMesh_GetGroupColor(mesh, i);
1668 ok(color == groups[i].color, "Group %d: Wrong color %x, expected %x\n", i, color, groups[i].color);
1669
1670 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, i, &material);
1671 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupMaterial returned %x\n", i, hr);
1672 ok(material != NULL, "Group %d: No material\n", i);
1673 power = IDirect3DRMMaterial_GetPower(material);
1674 ok(power == groups[i].power, "Group %d: Wrong power %f, expected %f\n", i, power, groups[i].power);
1675 hr = IDirect3DRMMaterial_GetSpecular(material, &red, &green, &blue);
1676 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetSpecular returned %x\n", i, hr);
1677 ok(red == groups[i].specular[0], "Group %d: Wrong specular red %f, expected %f\n", i, red, groups[i].specular[0]);
1678 ok(green == groups[i].specular[1], "Group %d: Wrong specular green %f, pD3DRMexpected %f\n", i, green, groups[i].specular[1]);
1679 ok(blue == groups[i].specular[2], "Group %d: Wrong specular blue %f, expected %f\n", i, blue, groups[i].specular[2]);
1680 hr = IDirect3DRMMaterial_GetEmissive(material, &red, &green, &blue);
1681 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetEmissive returned %x\n", i, hr);
1682 ok(red == groups[i].emissive[0], "Group %d: Wrong emissive red %f, expected %f\n", i, red, groups[i].emissive[0]);
1683 ok(green == groups[i].emissive[1], "Group %d: Wrong emissive green %f, expected %f\n", i, green, groups[i].emissive[1]);
1684 ok(blue == groups[i].emissive[2], "Group %d: Wrong emissive blue %f, expected %f\n", i, blue, groups[i].emissive[2]);
1685
1686 hr = IDirect3DRMMesh_GetGroupTexture(mesh, i, &texture);
1687 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupTexture returned %x\n", i, hr);
1688 ok(!texture, "Group %d: Unexpected texture\n", i);
1689
1690 if (material)
1691 IDirect3DRMMaterial_Release(material);
1692 if (texture)
1693 IDirect3DRMTexture_Release(texture);
1694 }
1695
1696 IDirect3DRMMesh_Release(mesh);
1697 IDirect3DRMMeshBuilder_Release(mesh_builder);
1698 IDirect3DRM_Release(d3drm);
1699 }
1700
1701 struct qi_test
1702 {
1703 REFIID iid;
1704 REFIID refcount_iid;
1705 HRESULT hr;
1706 };
1707
1708 static void test_qi(const char *test_name, IUnknown *base_iface,
1709 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1710 {
1711 ULONG refcount, expected_refcount;
1712 IUnknown *iface1, *iface2;
1713 HRESULT hr;
1714 UINT i, j;
1715
1716 for (i = 0; i < entry_count; ++i)
1717 {
1718 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1719 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1720 if (SUCCEEDED(hr))
1721 {
1722 for (j = 0; j < entry_count; ++j)
1723 {
1724 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1725 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1726 if (SUCCEEDED(hr))
1727 {
1728 expected_refcount = 0;
1729 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1730 ++expected_refcount;
1731 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1732 ++expected_refcount;
1733 refcount = IUnknown_Release(iface2);
1734 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1735 refcount, test_name, i, j, expected_refcount);
1736 }
1737 }
1738
1739 expected_refcount = 0;
1740 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1741 ++expected_refcount;
1742 refcount = IUnknown_Release(iface1);
1743 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1744 refcount, test_name, i, expected_refcount);
1745 }
1746 }
1747 }
1748
1749 static void test_d3drm_qi(void)
1750 {
1751 static const struct qi_test tests[] =
1752 {
1753 { &IID_IDirect3DRM3, &IID_IDirect3DRM3, S_OK, },
1754 { &IID_IDirect3DRM2, &IID_IDirect3DRM2, S_OK, },
1755 { &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK, },
1756 { &IID_IDirect3DRMDevice, NULL, CLASS_E_CLASSNOTAVAILABLE },
1757 { &IID_IDirect3DRMObject, NULL, CLASS_E_CLASSNOTAVAILABLE },
1758 { &IID_IDirect3DRMObject2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1759 { &IID_IDirect3DRMDevice2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1760 { &IID_IDirect3DRMDevice3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1761 { &IID_IDirect3DRMViewport, NULL, CLASS_E_CLASSNOTAVAILABLE },
1762 { &IID_IDirect3DRMViewport2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1763 { &IID_IDirect3DRMFrame, NULL, CLASS_E_CLASSNOTAVAILABLE },
1764 { &IID_IDirect3DRMFrame2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1765 { &IID_IDirect3DRMFrame3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1766 { &IID_IDirect3DRMVisual, NULL, CLASS_E_CLASSNOTAVAILABLE },
1767 { &IID_IDirect3DRMMesh, NULL, CLASS_E_CLASSNOTAVAILABLE },
1768 { &IID_IDirect3DRMMeshBuilder, NULL, CLASS_E_CLASSNOTAVAILABLE },
1769 { &IID_IDirect3DRMMeshBuilder2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1770 { &IID_IDirect3DRMMeshBuilder3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1771 { &IID_IDirect3DRMFace, NULL, CLASS_E_CLASSNOTAVAILABLE },
1772 { &IID_IDirect3DRMFace2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1773 { &IID_IDirect3DRMLight, NULL, CLASS_E_CLASSNOTAVAILABLE },
1774 { &IID_IDirect3DRMTexture, NULL, CLASS_E_CLASSNOTAVAILABLE },
1775 { &IID_IDirect3DRMTexture2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1776 { &IID_IDirect3DRMTexture3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1777 { &IID_IDirect3DRMWrap, NULL, CLASS_E_CLASSNOTAVAILABLE },
1778 { &IID_IDirect3DRMMaterial, NULL, CLASS_E_CLASSNOTAVAILABLE },
1779 { &IID_IDirect3DRMMaterial2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1780 { &IID_IDirect3DRMAnimation, NULL, CLASS_E_CLASSNOTAVAILABLE },
1781 { &IID_IDirect3DRMAnimation2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1782 { &IID_IDirect3DRMAnimationSet, NULL, CLASS_E_CLASSNOTAVAILABLE },
1783 { &IID_IDirect3DRMAnimationSet2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1784 { &IID_IDirect3DRMObjectArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1785 { &IID_IDirect3DRMDeviceArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1786 { &IID_IDirect3DRMViewportArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1787 { &IID_IDirect3DRMFrameArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1788 { &IID_IDirect3DRMVisualArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1789 { &IID_IDirect3DRMLightArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1790 { &IID_IDirect3DRMPickedArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1791 { &IID_IDirect3DRMFaceArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1792 { &IID_IDirect3DRMAnimationArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1793 { &IID_IDirect3DRMUserVisual, NULL, CLASS_E_CLASSNOTAVAILABLE },
1794 { &IID_IDirect3DRMShadow, NULL, CLASS_E_CLASSNOTAVAILABLE },
1795 { &IID_IDirect3DRMShadow2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1796 { &IID_IDirect3DRMInterpolator, NULL, CLASS_E_CLASSNOTAVAILABLE },
1797 { &IID_IDirect3DRMProgressiveMesh, NULL, CLASS_E_CLASSNOTAVAILABLE },
1798 { &IID_IDirect3DRMPicked2Array, NULL, CLASS_E_CLASSNOTAVAILABLE },
1799 { &IID_IDirect3DRMClippedVisual, NULL, CLASS_E_CLASSNOTAVAILABLE },
1800 { &IID_IDirectDrawClipper, NULL, CLASS_E_CLASSNOTAVAILABLE },
1801 { &IID_IDirectDrawSurface7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1802 { &IID_IDirectDrawSurface4, NULL, CLASS_E_CLASSNOTAVAILABLE },
1803 { &IID_IDirectDrawSurface3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1804 { &IID_IDirectDrawSurface2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1805 { &IID_IDirectDrawSurface, NULL, CLASS_E_CLASSNOTAVAILABLE },
1806 { &IID_IDirect3DDevice7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1807 { &IID_IDirect3DDevice3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1808 { &IID_IDirect3DDevice2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1809 { &IID_IDirect3DDevice, NULL, CLASS_E_CLASSNOTAVAILABLE },
1810 { &IID_IDirect3D7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1811 { &IID_IDirect3D3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1812 { &IID_IDirect3D2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1813 { &IID_IDirect3D, NULL, CLASS_E_CLASSNOTAVAILABLE },
1814 { &IID_IDirectDraw7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1815 { &IID_IDirectDraw4, NULL, CLASS_E_CLASSNOTAVAILABLE },
1816 { &IID_IDirectDraw3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1817 { &IID_IDirectDraw2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1818 { &IID_IDirectDraw, NULL, CLASS_E_CLASSNOTAVAILABLE },
1819 { &IID_IDirect3DLight, NULL, CLASS_E_CLASSNOTAVAILABLE },
1820 { &IID_IUnknown, &IID_IDirect3DRM, S_OK },
1821 };
1822 HRESULT hr;
1823 IDirect3DRM *d3drm;
1824
1825 hr = Direct3DRMCreate(&d3drm);
1826 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1827
1828 test_qi("d3drm_qi", (IUnknown *)d3drm, &IID_IDirect3DRM, tests, sizeof(tests) / sizeof(*tests));
1829
1830 IDirect3DRM_Release(d3drm);
1831 }
1832
1833 static void test_frame_qi(void)
1834 {
1835 static const struct qi_test tests[] =
1836 {
1837 { &IID_IDirect3DRMFrame3, &IID_IUnknown, S_OK },
1838 { &IID_IDirect3DRMFrame2, &IID_IUnknown, S_OK },
1839 { &IID_IDirect3DRMFrame, &IID_IUnknown, S_OK },
1840 { &IID_IDirect3DRM, NULL, CLASS_E_CLASSNOTAVAILABLE },
1841 { &IID_IDirect3DRMDevice, NULL, CLASS_E_CLASSNOTAVAILABLE },
1842 { &IID_IDirect3DRMObject, &IID_IUnknown, S_OK },
1843 { &IID_IDirect3DRMDevice2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1844 { &IID_IDirect3DRMDevice3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1845 { &IID_IDirect3DRMViewport, NULL, CLASS_E_CLASSNOTAVAILABLE },
1846 { &IID_IDirect3DRMViewport2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1847 { &IID_IDirect3DRM3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1848 { &IID_IDirect3DRM2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1849 { &IID_IDirect3DRMVisual, &IID_IUnknown, S_OK },
1850 { &IID_IDirect3DRMMesh, NULL, CLASS_E_CLASSNOTAVAILABLE },
1851 { &IID_IDirect3DRMMeshBuilder, NULL, CLASS_E_CLASSNOTAVAILABLE },
1852 { &IID_IDirect3DRMMeshBuilder2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1853 { &IID_IDirect3DRMMeshBuilder3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1854 { &IID_IDirect3DRMFace, NULL, CLASS_E_CLASSNOTAVAILABLE },
1855 { &IID_IDirect3DRMFace2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1856 { &IID_IDirect3DRMLight, NULL, CLASS_E_CLASSNOTAVAILABLE },
1857 { &IID_IDirect3DRMTexture, NULL, CLASS_E_CLASSNOTAVAILABLE },
1858 { &IID_IDirect3DRMTexture2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1859 { &IID_IDirect3DRMTexture3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1860 { &IID_IDirect3DRMWrap, NULL, CLASS_E_CLASSNOTAVAILABLE },
1861 { &IID_IDirect3DRMMaterial, NULL, CLASS_E_CLASSNOTAVAILABLE },
1862 { &IID_IDirect3DRMMaterial2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1863 { &IID_IDirect3DRMAnimation, NULL, CLASS_E_CLASSNOTAVAILABLE },
1864 { &IID_IDirect3DRMAnimation2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1865 { &IID_IDirect3DRMAnimationSet, NULL, CLASS_E_CLASSNOTAVAILABLE },
1866 { &IID_IDirect3DRMAnimationSet2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1867 { &IID_IDirect3DRMObjectArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1868 { &IID_IDirect3DRMDeviceArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1869 { &IID_IDirect3DRMViewportArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1870 { &IID_IDirect3DRMFrameArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1871 { &IID_IDirect3DRMVisualArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1872 { &IID_IDirect3DRMLightArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1873 { &IID_IDirect3DRMPickedArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1874 { &IID_IDirect3DRMFaceArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1875 { &IID_IDirect3DRMAnimationArray, NULL, CLASS_E_CLASSNOTAVAILABLE },
1876 { &IID_IDirect3DRMUserVisual, NULL, CLASS_E_CLASSNOTAVAILABLE },
1877 { &IID_IDirect3DRMShadow, NULL, CLASS_E_CLASSNOTAVAILABLE },
1878 { &IID_IDirect3DRMShadow2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1879 { &IID_IDirect3DRMInterpolator, NULL, CLASS_E_CLASSNOTAVAILABLE },
1880 { &IID_IDirect3DRMProgressiveMesh, NULL, CLASS_E_CLASSNOTAVAILABLE },
1881 { &IID_IDirect3DRMPicked2Array, NULL, CLASS_E_CLASSNOTAVAILABLE },
1882 { &IID_IDirect3DRMClippedVisual, NULL, CLASS_E_CLASSNOTAVAILABLE },
1883 { &IID_IDirectDrawClipper, NULL, CLASS_E_CLASSNOTAVAILABLE },
1884 { &IID_IDirectDrawSurface7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1885 { &IID_IDirectDrawSurface4, NULL, CLASS_E_CLASSNOTAVAILABLE },
1886 { &IID_IDirectDrawSurface3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1887 { &IID_IDirectDrawSurface2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1888 { &IID_IDirectDrawSurface, NULL, CLASS_E_CLASSNOTAVAILABLE },
1889 { &IID_IDirect3DDevice7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1890 { &IID_IDirect3DDevice3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1891 { &IID_IDirect3DDevice2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1892 { &IID_IDirect3DDevice, NULL, CLASS_E_CLASSNOTAVAILABLE },
1893 { &IID_IDirect3D7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1894 { &IID_IDirect3D3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1895 { &IID_IDirect3D2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1896 { &IID_IDirect3D, NULL, CLASS_E_CLASSNOTAVAILABLE },
1897 { &IID_IDirectDraw7, NULL, CLASS_E_CLASSNOTAVAILABLE },
1898 { &IID_IDirectDraw4, NULL, CLASS_E_CLASSNOTAVAILABLE },
1899 { &IID_IDirectDraw3, NULL, CLASS_E_CLASSNOTAVAILABLE },
1900 { &IID_IDirectDraw2, NULL, CLASS_E_CLASSNOTAVAILABLE },
1901 { &IID_IDirectDraw, NULL, CLASS_E_CLASSNOTAVAILABLE },
1902 { &IID_IDirect3DLight, NULL, CLASS_E_CLASSNOTAVAILABLE },
1903 { &IID_IUnknown, &IID_IUnknown, S_OK },
1904 };
1905 HRESULT hr;
1906 IDirect3DRM *d3drm1;
1907 IDirect3DRM2 *d3drm2;
1908 IDirect3DRM3 *d3drm3;
1909 IDirect3DRMFrame *frame1;
1910 IDirect3DRMFrame2 *frame2;
1911 IDirect3DRMFrame3 *frame3;
1912 IUnknown *unknown;
1913
1914 hr = Direct3DRMCreate(&d3drm1);
1915 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1916
1917 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
1918 ok(hr == D3DRM_OK, "Failed to create frame1 (hr = %x)\n", hr);
1919 IDirect3DRMFrame_QueryInterface(frame1, &IID_IUnknown, (void **)&unknown);
1920 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame1 (hr = %x)\n", hr);
1921 IDirect3DRMFrame_Release(frame1);
1922 test_qi("frame1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
1923 IUnknown_Release(unknown);
1924
1925 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1926 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
1927 hr = IDirect3DRM2_CreateFrame(d3drm2, NULL, &frame2);
1928 ok(hr == D3DRM_OK, "Failed to create frame2 (hr = %x)\n", hr);
1929 IDirect3DRMFrame2_QueryInterface(frame2, &IID_IUnknown, (void **)&unknown);
1930 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame2 (hr = %x)\n", hr);
1931 IDirect3DRMFrame2_Release(frame2);
1932 test_qi("frame2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
1933 IUnknown_Release(unknown);
1934
1935 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1936 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
1937 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
1938 ok(hr == D3DRM_OK, "Failed to create frame3 (hr = %x)\n", hr);
1939 IDirect3DRMFrame3_QueryInterface(frame3, &IID_IUnknown, (void **)&unknown);
1940 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame3 (hr = %x)\n", hr);
1941 IDirect3DRMFrame3_Release(frame3);
1942 test_qi("frame3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
1943 IUnknown_Release(unknown);
1944
1945 IDirect3DRM3_Release(d3drm3);
1946 IDirect3DRM2_Release(d3drm2);
1947 IDirect3DRM_Release(d3drm1);
1948 }
1949
1950 static void test_device_qi(void)
1951 {
1952 static const struct qi_test tests[] =
1953 {
1954 { &IID_IDirect3DRM3, NULL, CLASS_E_CLASSNOTAVAILABLE},
1955 { &IID_IDirect3DRM2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1956 { &IID_IDirect3DRM, NULL, CLASS_E_CLASSNOTAVAILABLE},
1957 { &IID_IDirect3DRMDevice, &IID_IUnknown, S_OK, },
1958 { &IID_IDirect3DRMDevice2, &IID_IUnknown, S_OK, },
1959 { &IID_IDirect3DRMDevice3, &IID_IUnknown, S_OK, },
1960 { &IID_IDirect3DRMWinDevice, &IID_IUnknown, S_OK, },
1961 { &IID_IDirect3DRMObject, &IID_IUnknown, S_OK, },
1962 { &IID_IDirect3DRMViewport, NULL, CLASS_E_CLASSNOTAVAILABLE},
1963 { &IID_IDirect3DRMViewport2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1964 { &IID_IDirect3DRMFrame, NULL, CLASS_E_CLASSNOTAVAILABLE},
1965 { &IID_IDirect3DRMFrame2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1966 { &IID_IDirect3DRMFrame3, NULL, CLASS_E_CLASSNOTAVAILABLE},
1967 { &IID_IDirect3DRMVisual, NULL, CLASS_E_CLASSNOTAVAILABLE},
1968 { &IID_IDirect3DRMMesh, NULL, CLASS_E_CLASSNOTAVAILABLE},
1969 { &IID_IDirect3DRMMeshBuilder, NULL, CLASS_E_CLASSNOTAVAILABLE},
1970 { &IID_IDirect3DRMMeshBuilder2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1971 { &IID_IDirect3DRMMeshBuilder3, NULL, CLASS_E_CLASSNOTAVAILABLE},
1972 { &IID_IDirect3DRMFace, NULL, CLASS_E_CLASSNOTAVAILABLE},
1973 { &IID_IDirect3DRMFace2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1974 { &IID_IDirect3DRMLight, NULL, CLASS_E_CLASSNOTAVAILABLE},
1975 { &IID_IDirect3DRMTexture, NULL, CLASS_E_CLASSNOTAVAILABLE},
1976 { &IID_IDirect3DRMTexture2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1977 { &IID_IDirect3DRMTexture3, NULL, CLASS_E_CLASSNOTAVAILABLE},
1978 { &IID_IDirect3DRMWrap, NULL, CLASS_E_CLASSNOTAVAILABLE},
1979 { &IID_IDirect3DRMMaterial, NULL, CLASS_E_CLASSNOTAVAILABLE},
1980 { &IID_IDirect3DRMMaterial2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1981 { &IID_IDirect3DRMAnimation, NULL, CLASS_E_CLASSNOTAVAILABLE},
1982 { &IID_IDirect3DRMAnimation2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1983 { &IID_IDirect3DRMAnimationSet, NULL, CLASS_E_CLASSNOTAVAILABLE},
1984 { &IID_IDirect3DRMAnimationSet2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1985 { &IID_IDirect3DRMObjectArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1986 { &IID_IDirect3DRMDeviceArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1987 { &IID_IDirect3DRMViewportArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1988 { &IID_IDirect3DRMFrameArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1989 { &IID_IDirect3DRMVisualArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1990 { &IID_IDirect3DRMLightArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1991 { &IID_IDirect3DRMPickedArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1992 { &IID_IDirect3DRMFaceArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1993 { &IID_IDirect3DRMAnimationArray, NULL, CLASS_E_CLASSNOTAVAILABLE},
1994 { &IID_IDirect3DRMUserVisual, NULL, CLASS_E_CLASSNOTAVAILABLE},
1995 { &IID_IDirect3DRMShadow, NULL, CLASS_E_CLASSNOTAVAILABLE},
1996 { &IID_IDirect3DRMShadow2, NULL, CLASS_E_CLASSNOTAVAILABLE},
1997 { &IID_IDirect3DRMInterpolator, NULL, CLASS_E_CLASSNOTAVAILABLE},
1998 { &IID_IDirect3DRMProgressiveMesh, NULL, CLASS_E_CLASSNOTAVAILABLE},
1999 { &IID_IDirect3DRMPicked2Array, NULL, CLASS_E_CLASSNOTAVAILABLE},
2000 { &IID_IDirect3DRMClippedVisual, NULL, CLASS_E_CLASSNOTAVAILABLE},
2001 { &IID_IDirectDrawClipper, NULL, CLASS_E_CLASSNOTAVAILABLE},
2002 { &IID_IDirectDrawSurface7, NULL, CLASS_E_CLASSNOTAVAILABLE},
2003 { &IID_IDirectDrawSurface4, NULL, CLASS_E_CLASSNOTAVAILABLE},
2004 { &IID_IDirectDrawSurface3, NULL, CLASS_E_CLASSNOTAVAILABLE},
2005 { &IID_IDirectDrawSurface2, NULL, CLASS_E_CLASSNOTAVAILABLE},
2006 { &IID_IDirectDrawSurface, NULL, CLASS_E_CLASSNOTAVAILABLE},
2007 { &IID_IDirect3DDevice7, NULL, CLASS_E_CLASSNOTAVAILABLE},
2008 { &IID_IDirect3DDevice3, NULL, CLASS_E_CLASSNOTAVAILABLE},
2009 { &IID_IDirect3DDevice2, NULL, CLASS_E_CLASSNOTAVAILABLE},
2010 { &IID_IDirect3DDevice, NULL, CLASS_E_CLASSNOTAVAILABLE},
2011 { &IID_IDirect3D7, NULL, CLASS_E_CLASSNOTAVAILABLE},
2012 { &IID_IDirect3D3, NULL, CLASS_E_CLASSNOTAVAILABLE},
2013 { &IID_IDirect3D2, NULL, CLASS_E_CLASSNOTAVAILABLE},
2014 { &IID_IDirect3D, NULL, CLASS_E_CLASSNOTAVAILABLE},
2015 { &IID_IDirectDraw7, NULL, CLASS_E_CLASSNOTAVAILABLE},
2016 { &IID_IDirectDraw4, NULL, CLASS_E_CLASSNOTAVAILABLE},
2017 { &IID_IDirectDraw3, NULL, CLASS_E_CLASSNOTAVAILABLE},
2018 { &IID_IDirectDraw2, NULL, CLASS_E_CLASSNOTAVAILABLE},
2019 { &IID_IDirectDraw, NULL, CLASS_E_CLASSNOTAVAILABLE},
2020 { &IID_IDirect3DLight, NULL, CLASS_E_CLASSNOTAVAILABLE},
2021 { &IID_IUnknown, &IID_IUnknown, S_OK, },
2022 };
2023 HRESULT hr;
2024 IDirect3DRM *d3drm1;
2025 IDirect3DRM2 *d3drm2;
2026 IDirect3DRM3 *d3drm3;
2027 IDirectDrawClipper *clipper;
2028 IDirect3DRMDevice *device1;
2029 IDirect3DRMDevice2 *device2;
2030 IDirect3DRMDevice3 *device3;
2031 IUnknown *unknown;
2032 HWND window;
2033 GUID driver;
2034 RECT rc;
2035
2036 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
2037 GetClientRect(window, &rc);
2038 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2039 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
2040 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2041 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
2042
2043 hr = Direct3DRMCreate(&d3drm1);
2044 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2045 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
2046 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
2047 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
2048 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IUnknown, (void **)&unknown);
2049 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice (hr = %x)\n", hr);
2050 IDirect3DRMDevice_Release(device1);
2051 test_qi("device1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2052 IUnknown_Release(unknown);
2053
2054 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2055 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2056 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
2057 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %x)\n", hr);
2058 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IUnknown, (void **)&unknown);
2059 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice2 (hr = %x)\n", hr);
2060 IDirect3DRMDevice2_Release(device2);
2061 test_qi("device2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2062 IUnknown_Release(unknown);
2063
2064 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2065 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2066 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
2067 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
2068 IDirect3DRMDevice3_QueryInterface(device3, &IID_IUnknown, (void **)&unknown);
2069 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice3 (hr = %x)\n", hr);
2070 IDirect3DRMDevice3_Release(device3);
2071 test_qi("device3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2072 IUnknown_Release(unknown);
2073
2074 IDirectDrawClipper_Release(clipper);
2075 IDirect3DRM3_Release(d3drm3);
2076 IDirect3DRM2_Release(d3drm2);
2077 IDirect3DRM_Release(d3drm1);
2078 DestroyWindow(window);
2079 }
2080
2081 static HRESULT CALLBACK surface_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
2082 {
2083 IDirectDrawSurface **primary = context;
2084
2085 if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
2086 {
2087 *primary = surface;
2088 return DDENUMRET_CANCEL;
2089 }
2090 IDirectDrawSurface_Release(surface);
2091
2092 return DDENUMRET_OK;
2093 }
2094
2095 static void test_create_device_from_clipper1(void)
2096 {
2097 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2098 IDirect3DRM *d3drm1 = NULL;
2099 IDirectDraw *ddraw = NULL;
2100 IUnknown *unknown = NULL;
2101 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
2102 IDirect3DDevice *d3ddevice1 = NULL;
2103 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
2104 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
2105 IDirectDrawSurface7 *surface7 = NULL;
2106 DDSURFACEDESC desc, surface_desc;
2107 DWORD expected_flags;
2108 HWND window;
2109 GUID driver = IID_IDirect3DRGBDevice;
2110 HRESULT hr;
2111 ULONG ref1, ref2, cref1, cref2;
2112 RECT rc;
2113
2114 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
2115 GetClientRect(window, &rc);
2116 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2117 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
2118 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2119 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
2120
2121 hr = Direct3DRMCreate(&d3drm1);
2122 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2123 ref1 = get_refcount((IUnknown *)d3drm1);
2124 cref1 = get_refcount((IUnknown *)clipper);
2125
2126 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 0, 0, &device1);
2127 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2128 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
2129
2130 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2131 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, NULL, &driver, 300, 200, &device1);
2132 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2133
2134 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, NULL);
2135 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2136
2137 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, &device1);
2138 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2139 ref2 = get_refcount((IUnknown *)d3drm1);
2140 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2141 cref2 = get_refcount((IUnknown *)clipper);
2142 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
2143
2144 /* Fetch immediate mode device in order to access render target */
2145 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
2146 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2147
2148 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
2149 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2150
2151 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
2152 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
2153
2154 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2155 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
2156 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
2157 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
2158 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
2159 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2160 IUnknown_Release(unknown);
2161 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2162 NULL, &d3drm_primary, surface_callback);
2163 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2164 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
2165 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
2166 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
2167 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
2168
2169 IDirectDrawClipper_Release(d3drm_clipper);
2170 IDirectDrawSurface_Release(d3drm_primary);
2171 IDirectDrawSurface7_Release(surface7);
2172 IDirectDraw_Release(ddraw);
2173
2174 /* Check properties of render target and depth surface */
2175 surface_desc.dwSize = sizeof(surface_desc);
2176 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2177 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2178
2179 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2180 surface_desc.dwWidth, surface_desc.dwHeight);
2181 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
2182 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
2183 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2184 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
2185
2186 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2187 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2188 desc.dwSize = sizeof(desc);
2189 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2190 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2191 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
2192 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
2193
2194 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2195 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2196
2197 desc.dwSize = sizeof(desc);
2198 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2199 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2200
2201 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2202 desc.dwWidth, desc.dwHeight);
2203 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2204 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2205 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2206 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
2207 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
2208
2209 /* Release old objects and check refcount of device and clipper */
2210 IDirectDrawSurface_Release(ds);
2211 ds = NULL;
2212 IDirectDrawSurface_Release(surface);
2213 surface = NULL;
2214 IDirect3DDevice_Release(d3ddevice1);
2215 d3ddevice1 = NULL;
2216 IDirect3DRMDevice_Release(device1);
2217 ref2 = get_refcount((IUnknown *)d3drm1);
2218 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2219 cref2 = get_refcount((IUnknown *)clipper);
2220 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
2221
2222 /* Test if render target format follows the screen format */
2223 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2224 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2225 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
2226 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
2227
2228 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2229 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2230 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
2231
2232 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
2233 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2234
2235 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
2236 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2237
2238 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
2239 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2240
2241 surface_desc.dwSize = sizeof(surface_desc);
2242 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2243 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2244 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
2245 surface_desc.ddpfPixelFormat.dwRGBBitCount);
2246
2247 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
2248 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2249
2250 if (ds)
2251 IDirectDrawSurface_Release(ds);
2252 IDirectDrawSurface_Release(surface);
2253 IDirect3DDevice_Release(d3ddevice1);
2254 IDirect3DRMDevice_Release(device1);
2255 IDirect3DRM_Release(d3drm1);
2256 IDirectDrawClipper_Release(clipper);
2257 IDirectDraw_Release(ddraw);
2258 DestroyWindow(window);
2259 }
2260
2261 static void test_create_device_from_clipper2(void)
2262 {
2263 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2264 IDirect3DRM *d3drm1 = NULL;
2265 IDirect3DRM2 *d3drm2 = NULL;
2266 IDirectDraw *ddraw = NULL;
2267 IUnknown *unknown = NULL;
2268 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
2269 IDirect3DDevice2 *d3ddevice2 = NULL;
2270 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
2271 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
2272 IDirectDrawSurface7 *surface7 = NULL;
2273 DDSURFACEDESC desc, surface_desc;
2274 DWORD expected_flags;
2275 HWND window;
2276 GUID driver = IID_IDirect3DRGBDevice;
2277 HRESULT hr;
2278 ULONG ref1, ref2, ref3, cref1, cref2;
2279 RECT rc;
2280
2281 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
2282 GetClientRect(window, &rc);
2283 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2284 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
2285 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2286 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
2287
2288 hr = Direct3DRMCreate(&d3drm1);
2289 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2290 ref1 = get_refcount((IUnknown *)d3drm1);
2291 cref1 = get_refcount((IUnknown *)clipper);
2292
2293 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2294 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2295 ref2 = get_refcount((IUnknown *)d3drm2);
2296
2297 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 0, 0, &device2);
2298 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2299 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
2300
2301 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2302 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, NULL, &driver, 300, 200, &device2);
2303 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2304
2305 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, NULL);
2306 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2307
2308 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, &device2);
2309 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
2310 ref3 = get_refcount((IUnknown *)d3drm1);
2311 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2312 ref3 = get_refcount((IUnknown *)d3drm2);
2313 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2314 cref2 = get_refcount((IUnknown *)clipper);
2315 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
2316
2317 /* Fetch immediate mode device in order to access render target */
2318 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
2319 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2320
2321 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
2322 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2323
2324 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
2325 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
2326
2327 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2328 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
2329 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
2330 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
2331 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
2332 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2333 IUnknown_Release(unknown);
2334 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2335 NULL, &d3drm_primary, surface_callback);
2336 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2337 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
2338 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
2339 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
2340 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
2341
2342 IDirectDrawClipper_Release(d3drm_clipper);
2343 IDirectDrawSurface_Release(d3drm_primary);
2344 IDirectDrawSurface7_Release(surface7);
2345 IDirectDraw_Release(ddraw);
2346
2347 /* Check properties of render target and depth surface */
2348 surface_desc.dwSize = sizeof(surface_desc);
2349 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2350 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2351
2352 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2353 surface_desc.dwWidth, surface_desc.dwHeight);
2354 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
2355 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
2356 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2357 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
2358
2359 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2360 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2361 desc.dwSize = sizeof(desc);
2362 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2363 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2364 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
2365 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
2366
2367 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2368 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2369
2370 desc.dwSize = sizeof(desc);
2371 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2372 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2373
2374 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2375 desc.dwWidth, desc.dwHeight);
2376 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2377 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2378 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2379 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
2380 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
2381
2382 /* Release old objects and check refcount of device and clipper */
2383 IDirectDrawSurface_Release(ds);
2384 ds = NULL;
2385 IDirectDrawSurface_Release(surface);
2386 surface = NULL;
2387 IDirect3DDevice2_Release(d3ddevice2);
2388 d3ddevice2 = NULL;
2389 IDirect3DRMDevice2_Release(device2);
2390 ref3 = get_refcount((IUnknown *)d3drm1);
2391 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2392 ref3 = get_refcount((IUnknown *)d3drm2);
2393 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2394 cref2 = get_refcount((IUnknown *)clipper);
2395 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
2396
2397 /* Test if render target format follows the screen format */
2398 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2399 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2400 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
2401 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
2402
2403 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2404 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2405 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
2406
2407 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
2408 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
2409
2410 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
2411 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2412
2413 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
2414 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2415
2416 surface_desc.dwSize = sizeof(surface_desc);
2417 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2418 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2419 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
2420 surface_desc.ddpfPixelFormat.dwRGBBitCount);
2421
2422 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
2423 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2424
2425 IDirectDrawSurface_Release(surface);
2426 IDirect3DDevice2_Release(d3ddevice2);
2427 IDirect3DRMDevice2_Release(device2);
2428 IDirect3DRM2_Release(d3drm2);
2429 IDirect3DRM_Release(d3drm1);
2430 IDirectDrawClipper_Release(clipper);
2431 IDirectDraw_Release(ddraw);
2432 DestroyWindow(window);
2433 }
2434
2435 static void test_create_device_from_clipper3(void)
2436 {
2437 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2438 IDirect3DRM *d3drm1 = NULL;
2439 IDirect3DRM3 *d3drm3 = NULL;
2440 IDirectDraw *ddraw = NULL;
2441 IUnknown *unknown = NULL;
2442 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
2443 IDirect3DDevice2 *d3ddevice2 = NULL;
2444 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
2445 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
2446 IDirectDrawSurface7 *surface7 = NULL;
2447 DDSURFACEDESC desc, surface_desc;
2448 DWORD expected_flags;
2449 HWND window;
2450 GUID driver = IID_IDirect3DRGBDevice;
2451 HRESULT hr;
2452 ULONG ref1, ref2, ref3, cref1, cref2;
2453 RECT rc;
2454
2455 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
2456 GetClientRect(window, &rc);
2457 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2458 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
2459 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2460 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
2461
2462 hr = Direct3DRMCreate(&d3drm1);
2463 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2464 ref1 = get_refcount((IUnknown *)d3drm1);
2465 cref1 = get_refcount((IUnknown *)clipper);
2466
2467 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2468 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2469 ref2 = get_refcount((IUnknown *)d3drm3);
2470
2471 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 0, 0, &device3);
2472 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2473 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
2474
2475 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2476 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, NULL, &driver, 300, 200, &device3);
2477 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2478
2479 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, NULL);
2480 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2481
2482 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, &device3);
2483 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
2484 ref3 = get_refcount((IUnknown *)d3drm1);
2485 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2486 ref3 = get_refcount((IUnknown *)d3drm3);
2487 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2