d3drm: Implement IDirect3DRM{2-3}::CreateDeviceFromD3D.
[wine.git] / dlls / d3drm / tests / d3drm.c
blob4e5845c6cf7ce78d8fa9a0f52fda5d7e8125bb6f
1 /*
2 * Copyright 2010, 2012 Christian Costa
3 * Copyright 2012 André Hentschel
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
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.
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.
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
21 #define COBJMACROS
22 #include <d3d.h>
23 #include <initguid.h>
24 #include <d3drm.h>
25 #include <d3drmwin.h>
27 #include "wine/test.h"
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); \
36 static ULONG get_refcount(IUnknown *object)
38 IUnknown_AddRef( object );
39 return IUnknown_Release( object );
42 static BOOL match_float(float a, float b)
44 return (a - b) < 0.000001f;
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 }
54 static char data_bad_version[] =
55 "xof 0302txt 0064\n"
56 "Header Object\n"
57 "{\n"
58 "1; 2; 3;\n"
59 "}\n";
61 static char data_no_mesh[] =
62 "xof 0302txt 0064\n"
63 "Header Object\n"
64 "{\n"
65 "1; 0; 1;\n"
66 "}\n";
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";
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";
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";
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";
200 static void test_MeshBuilder(void)
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};
218 hr = Direct3DRMCreate(&d3drm);
219 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
221 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
222 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
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);
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);
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);
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);
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);
272 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
273 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
275 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
276 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
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);
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);
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);
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);
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);
342 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
344 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
345 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
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)
352 DWORD nb_groups;
354 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
355 ok(nb_groups == 0, "GetCroupCount returned %u\n", nb_groups);
357 IDirect3DRMMesh_Release(mesh);
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);
365 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
366 ok(val == 3, "Wrong number of vertices %d (must be 3)\n", val);
368 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
369 ok(val == 1, "Wrong number of faces %d (must be 1)\n", val);
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);
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]);
421 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
422 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
423 if (hr == D3DRM_OK)
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];
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);
464 IDirect3DRMMesh_Release(mesh);
467 hr = IDirect3DRMMeshBuilder_Scale(pMeshBuilder, 2, 3 ,4);
468 ok(hr == D3DRM_OK, "Scale failed returning hr = %x\n", hr);
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);
494 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
496 IDirect3DRM_Release(d3drm);
499 static void test_MeshBuilder3(void)
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};
512 hr = Direct3DRMCreate(&d3drm);
513 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
515 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
517 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
518 IDirect3DRM_Release(d3drm);
519 return;
522 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &pMeshBuilder3);
523 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
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);
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);
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);
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);
553 val = IDirect3DRMMeshBuilder3_GetVertexCount(pMeshBuilder3);
554 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
556 val = IDirect3DRMMeshBuilder3_GetFaceCount(pMeshBuilder3);
557 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
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);
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);
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);
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);
605 IDirect3DRMMeshBuilder3_Release(pMeshBuilder3);
606 IDirect3DRM3_Release(d3drm3);
607 IDirect3DRM_Release(d3drm);
610 static void test_Mesh(void)
612 HRESULT hr;
613 IDirect3DRM *d3drm;
614 IDirect3DRMMesh *mesh;
615 DWORD size;
616 CHAR cname[64] = {0};
618 hr = Direct3DRMCreate(&d3drm);
619 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
621 hr = IDirect3DRM_CreateMesh(d3drm, &mesh);
622 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMesh interface (hr = %x)\n", hr);
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);
637 IDirect3DRMMesh_Release(mesh);
639 IDirect3DRM_Release(d3drm);
642 static void test_Face(void)
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;
659 hr = Direct3DRMCreate(&d3drm);
660 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
662 hr = IDirect3DRM_CreateFace(d3drm, &face1);
663 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
664 if (FAILED(hr))
666 skip("Cannot get IDirect3DRMFace interface (hr = %x), skipping tests\n", hr);
667 IDirect3DRM_Release(d3drm);
668 return;
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);
684 icount = IDirect3DRMFace_GetVertexCount(face1);
685 ok(!icount, "wrong VertexCount: %i\n", icount);
687 IDirect3DRMFace_Release(face1);
689 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM2, (void **)&d3drm2)))
691 win_skip("Cannot get IDirect3DRM2 interface (hr = %x), skipping tests\n", hr);
692 IDirect3DRM_Release(d3drm);
693 return;
696 hr = IDirect3DRM2_CreateMeshBuilder(d3drm2, &MeshBuilder2);
697 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder2 interface (hr = %x)\n", hr);
699 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
700 ok(!icount, "wrong FaceCount: %i\n", icount);
702 array1 = NULL;
703 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
704 todo_wine
705 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
707 hr = IDirect3DRMMeshBuilder2_CreateFace(MeshBuilder2, &face1);
708 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
710 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
711 todo_wine
712 ok(icount == 1, "wrong FaceCount: %i\n", icount);
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)
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);
731 icount = IDirect3DRMFace_GetVertexCount(face1);
732 ok(!icount, "wrong VertexCount: %i\n", icount);
734 IDirect3DRMFace_Release(face1);
735 IDirect3DRMMeshBuilder2_Release(MeshBuilder2);
737 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
739 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
740 IDirect3DRM_Release(d3drm);
741 return;
744 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &MeshBuilder3);
745 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
747 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
748 ok(!icount, "wrong FaceCount: %i\n", icount);
750 hr = IDirect3DRMMeshBuilder3_CreateFace(MeshBuilder3, &face2);
751 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace2 interface (hr = %x)\n", hr);
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);
766 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
767 todo_wine
768 ok(icount == 1, "wrong FaceCount: %i\n", icount);
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)
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);
787 icount = IDirect3DRMFace2_GetVertexCount(face2);
788 ok(!icount, "wrong VertexCount: %i\n", icount);
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);
795 icount = IDirect3DRMMeshBuilder3_GetVertexCount(MeshBuilder3);
796 ok(icount == 4, "Wrong number of vertices %d (must be 4)\n", icount);
798 icount = IDirect3DRMMeshBuilder3_GetNormalCount(MeshBuilder3);
799 ok(icount == 4, "Wrong number of normals %d (must be 4)\n", icount);
801 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
802 todo_wine
803 ok(icount == 4, "Wrong number of faces %d (must be 4)\n", icount);
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);
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);
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)
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);
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);
868 IDirect3DRMFace_Release(face);
869 IDirect3DRMFaceArray_Release(array1);
872 IDirect3DRMFace2_Release(face2);
873 IDirect3DRMMeshBuilder3_Release(MeshBuilder3);
874 IDirect3DRM3_Release(d3drm3);
875 IDirect3DRM2_Release(d3drm2);
876 IDirect3DRM_Release(d3drm);
879 static void test_Frame(void)
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};
899 hr = Direct3DRMCreate(&d3drm);
900 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
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);
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);
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);
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)
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);
941 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP1);
942 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
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);
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);
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);
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);
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);
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)
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);
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);
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);
1001 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1002 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1003 CHECK_REFCOUNT(pFrameC, 2);
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)
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);
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)
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);
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);
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);
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)
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);
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);
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)
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);
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);
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);
1088 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1);
1089 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1090 CHECK_REFCOUNT(pFrameP1, 3);
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)
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);
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);
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);
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;
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);
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)
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);
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);
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);
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);
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);
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);
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)
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);
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);
1189 /* Test SceneBackground on first parent */
1190 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1191 ok(color == 0xff000000, "wrong color (%x)\n", color);
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);
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);
1203 /* Cleanup */
1204 IDirect3DRMFrame_Release(pFrameP2);
1205 CHECK_REFCOUNT(pFrameC, 2);
1206 CHECK_REFCOUNT(pFrameP1, 3);
1208 IDirect3DRMFrame_Release(pFrameC);
1209 IDirect3DRMFrame_Release(pFrameP1);
1211 IDirect3DRM_Release(d3drm);
1214 static void test_Viewport(void)
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};
1228 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
1229 GetClientRect(window, &rc);
1231 hr = Direct3DRMCreate(&d3drm);
1232 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1234 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
1235 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1237 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
1238 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
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);
1244 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
1245 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
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);
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);
1263 IDirect3DRMViewport_Release(viewport);
1264 IDirect3DRMFrame_Release(frame);
1265 IDirect3DRMDevice_Release(device);
1266 IDirectDrawClipper_Release(pClipper);
1268 IDirect3DRM_Release(d3drm);
1269 DestroyWindow(window);
1272 static void test_Light(void)
1274 HRESULT hr;
1275 IDirect3DRM *d3drm;
1276 IDirect3DRMLight *light;
1277 D3DRMLIGHTTYPE type;
1278 D3DCOLOR color;
1279 DWORD size;
1280 CHAR cname[64] = {0};
1282 hr = Direct3DRMCreate(&d3drm);
1283 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
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);
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);
1301 type = IDirect3DRMLight_GetType(light);
1302 ok(type == D3DRMLIGHT_SPOT, "wrong type (%u)\n", type);
1304 color = IDirect3DRMLight_GetColor(light);
1305 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
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);
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);
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);
1322 IDirect3DRMLight_Release(light);
1324 IDirect3DRM_Release(d3drm);
1327 static void test_Material2(void)
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};
1337 hr = Direct3DRMCreate(&d3drm);
1338 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1340 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
1342 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
1343 IDirect3DRM_Release(d3drm);
1344 return;
1347 hr = IDirect3DRM3_CreateMaterial(d3drm3, 18.5f, &material2);
1348 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMaterial2 interface (hr = %x)\n", hr);
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);
1363 r = IDirect3DRMMaterial2_GetPower(material2);
1364 ok(r == 18.5f, "wrong power (%f)\n", r);
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);
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);
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);
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);
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);
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);
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);
1401 IDirect3DRMMaterial2_Release(material2);
1403 IDirect3DRM3_Release(d3drm3);
1404 IDirect3DRM_Release(d3drm);
1407 static void test_Texture(void)
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
1417 DWORD pixel[4] = { 20000, 30000, 10000, 0 };
1418 DWORD size;
1419 CHAR cname[64] = {0};
1421 hr = Direct3DRMCreate(&d3drm);
1422 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1424 initimg.buffer1 = &pixel;
1425 hr = IDirect3DRM_CreateTexture(d3drm, &initimg, &texture);
1426 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMTexture interface (hr = %x)\n", hr);
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);
1441 IDirect3DRMTexture_Release(texture);
1443 IDirect3DRM_Release(d3drm);
1446 static void test_Device(void)
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};
1459 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
1460 GetClientRect(window, &rc);
1462 hr = Direct3DRMCreate(&d3drm);
1463 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1465 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
1466 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1468 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
1469 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
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);
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);
1488 /* WinDevice */
1489 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMWinDevice, (void **)&win_device)))
1491 win_skip("Cannot get IDirect3DRMWinDevice interface (hr = %x), skipping tests\n", hr);
1492 goto cleanup;
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);
1508 IDirect3DRMWinDevice_Release(win_device);
1510 cleanup:
1511 IDirect3DRMDevice_Release(device);
1512 IDirectDrawClipper_Release(pClipper);
1514 IDirect3DRM_Release(d3drm);
1515 DestroyWindow(window);
1518 static void test_frame_transform(void)
1520 HRESULT hr;
1521 IDirect3DRM *d3drm;
1522 IDirect3DRMFrame *frame;
1523 D3DRMMATRIX4D matrix;
1525 hr = Direct3DRMCreate(&d3drm);
1526 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1528 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
1529 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
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");
1535 IDirect3DRMFrame_Release(frame);
1536 IDirect3DRM_Release(d3drm);
1539 static int nb_objects = 0;
1540 static const GUID* refiids[] =
1542 &IID_IDirect3DRMMeshBuilder,
1543 &IID_IDirect3DRMMeshBuilder,
1544 &IID_IDirect3DRMFrame,
1545 &IID_IDirect3DRMMaterial /* Not taken into account and not notified */
1548 static void __cdecl object_load_callback(IDirect3DRMObject *object, REFIID objectguid, void *arg)
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++;
1556 static void test_d3drm_load(void)
1558 HRESULT hr;
1559 IDirect3DRM *d3drm;
1560 D3DRMLOADMEMORY info;
1561 const GUID* req_refiids[] = { &IID_IDirect3DRMMeshBuilder, &IID_IDirect3DRMFrame, &IID_IDirect3DRMMaterial };
1563 hr = Direct3DRMCreate(&d3drm);
1564 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
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);
1573 IDirect3DRM_Release(d3drm);
1576 IDirect3DRMMeshBuilder *mesh_builder = NULL;
1578 static void __cdecl object_load_callback_frame(IDirect3DRMObject *object, REFIID object_guid, void *arg)
1580 HRESULT hr;
1581 IDirect3DRMFrame *frame;
1582 IDirect3DRMVisualArray *array;
1583 IDirect3DRMVisual *visual;
1584 ULONG size;
1585 char name[128];
1587 hr = IDirect3DRMObject_QueryInterface(object, &IID_IDirect3DRMFrame, (void**)&frame);
1588 ok(hr == D3DRM_OK, "IDirect3DRMObject_QueryInterface returned %x\n", hr);
1590 hr = IDirect3DRMFrame_GetVisuals(frame, &array);
1591 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetVisuals returned %x\n", hr);
1593 size = IDirect3DRMVisualArray_GetSize(array);
1594 ok(size == 1, "Wrong size %u returned, expected 1\n", size);
1596 hr = IDirect3DRMVisualArray_GetElement(array, 0, &visual);
1597 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetElement returned %x\n", hr);
1599 hr = IDirect3DRMVisual_QueryInterface(visual, &IID_IDirect3DRMMeshBuilder, (void**)&mesh_builder);
1600 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetSize returned %x\n", hr);
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);
1607 IDirect3DRMVisual_Release(visual);
1608 IDirect3DRMVisualArray_Release(array);
1609 IDirect3DRMFrame_Release(frame);
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 } }
1627 static void test_frame_mesh_materials(void)
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;
1639 hr = Direct3DRMCreate(&d3drm);
1640 ok(hr == D3DRM_OK, "Direct3DRMCreate returned %x\n", hr);
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);
1647 hr = IDirect3DRMMeshBuilder_CreateMesh(mesh_builder, &mesh);
1648 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_CreateMesh returned %x\n", hr);
1650 size = IDirect3DRMMesh_GetGroupCount(mesh);
1651 ok(size == 3, "Wrong size %u returned, expected 3\n", size);
1653 for (i = 0; i < size; i++)
1655 D3DVALUE red, green, blue, power;
1656 D3DCOLOR color;
1657 unsigned vertex_count, face_count, vertex_per_face;
1658 DWORD face_data_size;
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);
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);
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]);
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);
1690 if (material)
1691 IDirect3DRMMaterial_Release(material);
1692 if (texture)
1693 IDirect3DRMTexture_Release(texture);
1696 IDirect3DRMMesh_Release(mesh);
1697 IDirect3DRMMeshBuilder_Release(mesh_builder);
1698 IDirect3DRM_Release(d3drm);
1701 struct qi_test
1703 REFIID iid;
1704 REFIID refcount_iid;
1705 HRESULT hr;
1708 static void test_qi(const char *test_name, IUnknown *base_iface,
1709 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1711 ULONG refcount, expected_refcount;
1712 IUnknown *iface1, *iface2;
1713 HRESULT hr;
1714 UINT i, j;
1716 for (i = 0; i < entry_count; ++i)
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))
1722 for (j = 0; j < entry_count; ++j)
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))
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);
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);
1749 static void test_d3drm_qi(void)
1751 static const struct qi_test tests[] =
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 },
1822 HRESULT hr;
1823 IDirect3DRM *d3drm;
1825 hr = Direct3DRMCreate(&d3drm);
1826 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1828 test_qi("d3drm_qi", (IUnknown *)d3drm, &IID_IDirect3DRM, tests, sizeof(tests) / sizeof(*tests));
1830 IDirect3DRM_Release(d3drm);
1833 static void test_frame_qi(void)
1835 static const struct qi_test tests[] =
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 },
1905 HRESULT hr;
1906 IDirect3DRM *d3drm1;
1907 IDirect3DRM2 *d3drm2;
1908 IDirect3DRM3 *d3drm3;
1909 IDirect3DRMFrame *frame1;
1910 IDirect3DRMFrame2 *frame2;
1911 IDirect3DRMFrame3 *frame3;
1912 IUnknown *unknown;
1914 hr = Direct3DRMCreate(&d3drm1);
1915 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
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);
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);
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);
1945 IDirect3DRM3_Release(d3drm3);
1946 IDirect3DRM2_Release(d3drm2);
1947 IDirect3DRM_Release(d3drm1);
1950 static HRESULT CALLBACK surface_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
1952 IDirectDrawSurface **primary = context;
1954 if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
1956 *primary = surface;
1957 return DDENUMRET_CANCEL;
1959 IDirectDrawSurface_Release(surface);
1961 return DDENUMRET_OK;
1964 static void test_create_device_from_clipper1(void)
1966 DDSCAPS caps = { DDSCAPS_ZBUFFER };
1967 IDirect3DRM *d3drm1 = NULL;
1968 IDirectDraw *ddraw = NULL;
1969 IUnknown *unknown = NULL;
1970 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
1971 IDirect3DDevice *d3ddevice1 = NULL;
1972 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
1973 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
1974 IDirectDrawSurface7 *surface7 = NULL;
1975 DDSURFACEDESC desc, surface_desc;
1976 DWORD expected_flags;
1977 HWND window;
1978 GUID driver = IID_IDirect3DRGBDevice;
1979 HRESULT hr;
1980 ULONG ref1, ref2, cref1, cref2;
1981 RECT rc;
1983 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
1984 GetClientRect(window, &rc);
1985 hr = DirectDrawCreateClipper(0, &clipper, NULL);
1986 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
1987 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
1988 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
1990 hr = Direct3DRMCreate(&d3drm1);
1991 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
1992 ref1 = get_refcount((IUnknown *)d3drm1);
1993 cref1 = get_refcount((IUnknown *)clipper);
1995 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 0, 0, &device1);
1996 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
1997 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
1999 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2000 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, NULL, &driver, 300, 200, &device1);
2001 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2003 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, NULL);
2004 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2006 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, &device1);
2007 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2008 ref2 = get_refcount((IUnknown *)d3drm1);
2009 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2010 cref2 = get_refcount((IUnknown *)clipper);
2011 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
2013 /* Fetch immediate mode device in order to access render target */
2014 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
2015 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2017 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
2018 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2020 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
2021 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
2023 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2024 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
2025 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
2026 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
2027 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
2028 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2029 IUnknown_Release(unknown);
2030 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2031 NULL, &d3drm_primary, surface_callback);
2032 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2033 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
2034 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
2035 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
2036 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
2038 IDirectDrawClipper_Release(d3drm_clipper);
2039 IDirectDrawSurface_Release(d3drm_primary);
2040 IDirectDrawSurface7_Release(surface7);
2041 IDirectDraw_Release(ddraw);
2043 /* Check properties of render target and depth surface */
2044 surface_desc.dwSize = sizeof(surface_desc);
2045 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2046 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2048 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2049 surface_desc.dwWidth, surface_desc.dwHeight);
2050 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
2051 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
2052 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2053 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
2055 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2056 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2057 desc.dwSize = sizeof(desc);
2058 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2059 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2060 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
2061 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
2063 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2064 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2066 desc.dwSize = sizeof(desc);
2067 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2068 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2070 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2071 desc.dwWidth, desc.dwHeight);
2072 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2073 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2074 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2075 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
2076 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
2078 /* Release old objects and check refcount of device and clipper */
2079 IDirectDrawSurface_Release(ds);
2080 ds = NULL;
2081 IDirectDrawSurface_Release(surface);
2082 surface = NULL;
2083 IDirect3DDevice_Release(d3ddevice1);
2084 d3ddevice1 = NULL;
2085 IDirect3DRMDevice_Release(device1);
2086 ref2 = get_refcount((IUnknown *)d3drm1);
2087 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2088 cref2 = get_refcount((IUnknown *)clipper);
2089 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
2091 /* Test if render target format follows the screen format */
2092 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2093 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2094 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
2095 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
2097 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2098 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2099 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
2101 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
2102 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2104 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
2105 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2107 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
2108 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2110 surface_desc.dwSize = sizeof(surface_desc);
2111 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2112 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2113 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
2114 surface_desc.ddpfPixelFormat.dwRGBBitCount);
2116 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
2117 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2119 if (ds)
2120 IDirectDrawSurface_Release(ds);
2121 IDirectDrawSurface_Release(surface);
2122 IDirect3DDevice_Release(d3ddevice1);
2123 IDirect3DRMDevice_Release(device1);
2124 IDirect3DRM_Release(d3drm1);
2125 IDirectDrawClipper_Release(clipper);
2126 IDirectDraw_Release(ddraw);
2127 DestroyWindow(window);
2130 static void test_create_device_from_clipper2(void)
2132 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2133 IDirect3DRM *d3drm1 = NULL;
2134 IDirect3DRM2 *d3drm2 = NULL;
2135 IDirectDraw *ddraw = NULL;
2136 IUnknown *unknown = NULL;
2137 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
2138 IDirect3DDevice2 *d3ddevice2 = NULL;
2139 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
2140 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
2141 IDirectDrawSurface7 *surface7 = NULL;
2142 DDSURFACEDESC desc, surface_desc;
2143 DWORD expected_flags;
2144 HWND window;
2145 GUID driver = IID_IDirect3DRGBDevice;
2146 HRESULT hr;
2147 ULONG ref1, ref2, ref3, cref1, cref2;
2148 RECT rc;
2150 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
2151 GetClientRect(window, &rc);
2152 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2153 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
2154 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2155 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
2157 hr = Direct3DRMCreate(&d3drm1);
2158 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2159 ref1 = get_refcount((IUnknown *)d3drm1);
2160 cref1 = get_refcount((IUnknown *)clipper);
2162 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2163 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2164 ref2 = get_refcount((IUnknown *)d3drm2);
2166 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 0, 0, &device2);
2167 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2168 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
2170 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2171 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, NULL, &driver, 300, 200, &device2);
2172 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2174 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, NULL);
2175 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2177 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, &device2);
2178 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
2179 ref3 = get_refcount((IUnknown *)d3drm1);
2180 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2181 ref3 = get_refcount((IUnknown *)d3drm2);
2182 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2183 cref2 = get_refcount((IUnknown *)clipper);
2184 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
2186 /* Fetch immediate mode device in order to access render target */
2187 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
2188 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2190 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
2191 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2193 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
2194 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
2196 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2197 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
2198 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
2199 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
2200 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
2201 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2202 IUnknown_Release(unknown);
2203 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2204 NULL, &d3drm_primary, surface_callback);
2205 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2206 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
2207 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
2208 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
2209 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
2211 IDirectDrawClipper_Release(d3drm_clipper);
2212 IDirectDrawSurface_Release(d3drm_primary);
2213 IDirectDrawSurface7_Release(surface7);
2214 IDirectDraw_Release(ddraw);
2216 /* Check properties of render target and depth surface */
2217 surface_desc.dwSize = sizeof(surface_desc);
2218 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2219 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2221 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2222 surface_desc.dwWidth, surface_desc.dwHeight);
2223 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
2224 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
2225 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2226 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
2228 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2229 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2230 desc.dwSize = sizeof(desc);
2231 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2232 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2233 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
2234 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
2236 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2237 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2239 desc.dwSize = sizeof(desc);
2240 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2241 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2243 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2244 desc.dwWidth, desc.dwHeight);
2245 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2246 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2247 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2248 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
2249 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
2251 /* Release old objects and check refcount of device and clipper */
2252 IDirectDrawSurface_Release(ds);
2253 ds = NULL;
2254 IDirectDrawSurface_Release(surface);
2255 surface = NULL;
2256 IDirect3DDevice2_Release(d3ddevice2);
2257 d3ddevice2 = NULL;
2258 IDirect3DRMDevice2_Release(device2);
2259 ref3 = get_refcount((IUnknown *)d3drm1);
2260 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2261 ref3 = get_refcount((IUnknown *)d3drm2);
2262 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2263 cref2 = get_refcount((IUnknown *)clipper);
2264 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
2266 /* Test if render target format follows the screen format */
2267 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2268 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2269 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
2270 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
2272 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2273 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2274 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
2276 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
2277 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
2279 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
2280 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2282 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
2283 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2285 surface_desc.dwSize = sizeof(surface_desc);
2286 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2287 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2288 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
2289 surface_desc.ddpfPixelFormat.dwRGBBitCount);
2291 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
2292 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2294 IDirectDrawSurface_Release(surface);
2295 IDirect3DDevice2_Release(d3ddevice2);
2296 IDirect3DRMDevice2_Release(device2);
2297 IDirect3DRM2_Release(d3drm2);
2298 IDirect3DRM_Release(d3drm1);
2299 IDirectDrawClipper_Release(clipper);
2300 IDirectDraw_Release(ddraw);
2301 DestroyWindow(window);
2304 static void test_create_device_from_clipper3(void)
2306 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2307 IDirect3DRM *d3drm1 = NULL;
2308 IDirect3DRM3 *d3drm3 = NULL;
2309 IDirectDraw *ddraw = NULL;
2310 IUnknown *unknown = NULL;
2311 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
2312 IDirect3DDevice2 *d3ddevice2 = NULL;
2313 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
2314 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
2315 IDirectDrawSurface7 *surface7 = NULL;
2316 DDSURFACEDESC desc, surface_desc;
2317 DWORD expected_flags;
2318 HWND window;
2319 GUID driver = IID_IDirect3DRGBDevice;
2320 HRESULT hr;
2321 ULONG ref1, ref2, ref3, cref1, cref2;
2322 RECT rc;
2324 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
2325 GetClientRect(window, &rc);
2326 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2327 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
2328 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2329 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
2331 hr = Direct3DRMCreate(&d3drm1);
2332 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2333 ref1 = get_refcount((IUnknown *)d3drm1);
2334 cref1 = get_refcount((IUnknown *)clipper);
2336 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2337 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2338 ref2 = get_refcount((IUnknown *)d3drm3);
2340 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 0, 0, &device3);
2341 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2342 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
2344 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2345 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, NULL, &driver, 300, 200, &device3);
2346 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2348 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, NULL);
2349 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2351 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, &device3);
2352 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
2353 ref3 = get_refcount((IUnknown *)d3drm1);
2354 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2355 ref3 = get_refcount((IUnknown *)d3drm3);
2356 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2357 cref2 = get_refcount((IUnknown *)clipper);
2358 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
2360 /* Fetch immediate mode device in order to access render target */
2361 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
2362 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2364 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
2365 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2367 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
2368 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
2370 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2371 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
2372 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
2373 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
2374 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
2375 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2376 IUnknown_Release(unknown);
2377 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2378 NULL, &d3drm_primary, surface_callback);
2379 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2380 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
2381 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
2382 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
2383 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
2385 IDirectDrawClipper_Release(d3drm_clipper);
2386 IDirectDrawSurface_Release(d3drm_primary);
2387 IDirectDrawSurface7_Release(surface7);
2388 IDirectDraw_Release(ddraw);
2390 /* Check properties of render target and depth surface */
2391 surface_desc.dwSize = sizeof(surface_desc);
2392 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2393 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2395 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2396 surface_desc.dwWidth, surface_desc.dwHeight);
2397 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
2398 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
2399 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2400 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
2402 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2403 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2404 desc.dwSize = sizeof(desc);
2405 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2406 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2407 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
2408 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
2410 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2411 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2413 desc.dwSize = sizeof(desc);
2414 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2415 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2417 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2418 desc.dwWidth, desc.dwHeight);
2419 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2420 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2421 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2422 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
2423 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
2425 /* Release old objects and check refcount of device and clipper */
2426 IDirectDrawSurface_Release(ds);
2427 ds = NULL;
2428 IDirectDrawSurface_Release(surface);
2429 surface = NULL;
2430 IDirect3DDevice2_Release(d3ddevice2);
2431 d3ddevice2 = NULL;
2432 IDirect3DRMDevice3_Release(device3);
2433 ref3 = get_refcount((IUnknown *)d3drm1);
2434 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2435 ref3 = get_refcount((IUnknown *)d3drm3);
2436 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2437 cref2 = get_refcount((IUnknown *)clipper);
2438 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
2440 /* Test if render target format follows the screen format */
2441 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2442 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2443 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
2444 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
2446 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2447 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2448 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
2450 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
2451 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
2453 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
2454 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2456 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
2457 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2459 surface_desc.dwSize = sizeof(surface_desc);
2460 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2461 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2462 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
2463 surface_desc.ddpfPixelFormat.dwRGBBitCount);
2465 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
2466 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2468 IDirectDrawSurface_Release(surface);
2469 IDirect3DDevice2_Release(d3ddevice2);
2470 IDirect3DRMDevice3_Release(device3);
2471 IDirect3DRM3_Release(d3drm3);
2472 IDirect3DRM_Release(d3drm1);
2473 IDirectDrawClipper_Release(clipper);
2474 IDirectDraw_Release(ddraw);
2475 DestroyWindow(window);
2478 static void test_create_device_from_surface1(void)
2480 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2481 DDSURFACEDESC desc;
2482 IDirectDraw *ddraw = NULL;
2483 IDirect3DRM *d3drm1 = NULL;
2484 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
2485 IDirect3DDevice *d3ddevice1 = NULL;
2486 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
2487 DWORD expected_flags;
2488 HWND window;
2489 GUID driver = IID_IDirect3DRGBDevice;
2490 ULONG ref1, ref2, surface_ref1, surface_ref2;
2491 RECT rc;
2492 BOOL use_sysmem_zbuffer = FALSE;
2493 HRESULT hr;
2495 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2496 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2498 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
2499 GetClientRect(window, &rc);
2501 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2502 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
2504 hr = Direct3DRMCreate(&d3drm1);
2505 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2506 ref1 = get_refcount((IUnknown *)d3drm1);
2508 /* Create a surface and use it to create the retained mode device. */
2509 memset(&desc, 0, sizeof(desc));
2510 desc.dwSize = sizeof(desc);
2511 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2512 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2513 desc.dwWidth = rc.right;
2514 desc.dwHeight = rc.bottom;
2516 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2517 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2519 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
2520 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
2521 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
2522 IDirectDrawSurface_Release(surface);
2524 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
2525 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2526 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2527 surface_ref1 = get_refcount((IUnknown *)surface);
2529 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, NULL);
2530 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
2531 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, NULL, &device1);
2532 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
2533 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, NULL, surface, &device1);
2534 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
2536 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
2537 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2538 ref2 = get_refcount((IUnknown *)d3drm1);
2539 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2540 surface_ref2 = get_refcount((IUnknown *)surface);
2541 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
2543 /* Check if CreateDeviceFromSurface creates a primary surface */
2544 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2545 NULL, &d3drm_surface, surface_callback);
2546 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2547 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
2549 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
2550 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2552 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
2553 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2554 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
2556 /* Check properties of attached depth surface */
2557 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
2558 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2560 memset(&desc, 0, sizeof(desc));
2561 desc.dwSize = sizeof(desc);
2562 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2563 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2565 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
2566 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
2567 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
2568 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2569 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2570 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2572 IDirectDrawSurface_Release(ds);
2573 IDirect3DDevice_Release(d3ddevice1);
2574 IDirectDrawSurface_Release(d3drm_surface);
2576 IDirect3DRMDevice_Release(device1);
2577 ref2 = get_refcount((IUnknown *)d3drm1);
2578 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2579 surface_ref2 = get_refcount((IUnknown *)surface);
2580 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
2581 surface_ref1, surface_ref2);
2582 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2583 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2584 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2585 ref1 = IDirectDrawSurface_Release(ds);
2586 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
2587 ref1 = IDirectDrawSurface_Release(surface);
2588 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
2590 memset(&desc, 0, sizeof(desc));
2591 desc.dwSize = sizeof(desc);
2592 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2593 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
2594 desc.dwWidth = rc.right;
2595 desc.dwHeight = rc.bottom;
2597 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2598 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2600 memset(&desc, 0, sizeof(desc));
2601 desc.dwSize = sizeof(desc);
2602 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
2603 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
2604 desc.dwZBufferBitDepth = 16;
2605 desc.dwWidth = rc.right;
2606 desc.dwHeight = rc.bottom;
2607 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
2608 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
2609 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
2610 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
2612 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
2613 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2615 hr = IDirect3DRMDevice2_GetDirect3DDevice(device1, &d3ddevice1);
2616 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2618 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
2619 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2620 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
2622 /* Check if depth surface matches the one we created */
2623 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
2624 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2625 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
2627 IDirectDrawSurface_Release(d3drm_ds);
2628 IDirectDrawSurface_Release(d3drm_surface);
2629 IDirectDrawSurface_Release(ds);
2631 IDirect3DDevice_Release(d3ddevice1);
2632 IDirect3DRMDevice_Release(device1);
2633 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2634 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2635 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2636 ref1 = IDirectDrawSurface_Release(ds);
2637 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
2638 ref1 = IDirectDrawSurface_Release(surface);
2639 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
2640 IDirect3DRM_Release(d3drm1);
2641 IDirectDraw_Release(ddraw);
2642 DestroyWindow(window);
2645 static void test_create_device_from_surface2(void)
2647 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2648 DDSURFACEDESC desc;
2649 IDirectDraw *ddraw = NULL;
2650 IDirect3DRM *d3drm1 = NULL;
2651 IDirect3DRM2 *d3drm2 = NULL;
2652 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
2653 IDirect3DDevice2 *d3ddevice2 = NULL;
2654 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
2655 DWORD expected_flags;
2656 HWND window;
2657 GUID driver = IID_IDirect3DRGBDevice;
2658 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
2659 RECT rc;
2660 BOOL use_sysmem_zbuffer = FALSE;
2661 HRESULT hr;
2663 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2664 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2666 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
2667 GetClientRect(window, &rc);
2669 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2670 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
2672 hr = Direct3DRMCreate(&d3drm1);
2673 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2674 ref1 = get_refcount((IUnknown *)d3drm1);
2676 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2677 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2678 ref2 = get_refcount((IUnknown *)d3drm2);
2680 /* Create a surface and use it to create the retained mode device. */
2681 memset(&desc, 0, sizeof(desc));
2682 desc.dwSize = sizeof(desc);
2683 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2684 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2685 desc.dwWidth = rc.right;
2686 desc.dwHeight = rc.bottom;
2688 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2689 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2691 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
2692 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
2693 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
2694 IDirectDrawSurface_Release(surface);
2696 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
2697 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2698 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2699 surface_ref1 = get_refcount((IUnknown *)surface);
2701 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, NULL);
2702 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
2703 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, NULL, &device2);
2704 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
2705 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, NULL, surface, &device2);
2706 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
2708 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
2709 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
2710 ref3 = get_refcount((IUnknown *)d3drm1);
2711 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2712 ref3 = get_refcount((IUnknown *)d3drm2);
2713 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2714 surface_ref2 = get_refcount((IUnknown *)surface);
2715 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
2717 /* Check if CreateDeviceFromSurface creates a primary surface */
2718 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2719 NULL, &d3drm_surface, surface_callback);
2720 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2721 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
2723 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
2724 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2726 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
2727 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2728 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
2730 /* Check properties of attached depth surface */
2731 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
2732 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2734 memset(&desc, 0, sizeof(desc));
2735 desc.dwSize = sizeof(desc);
2736 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2737 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2739 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
2740 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
2741 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
2742 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2743 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2744 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2746 IDirectDrawSurface_Release(ds);
2747 IDirect3DDevice2_Release(d3ddevice2);
2748 IDirectDrawSurface_Release(d3drm_surface);
2750 IDirect3DRMDevice2_Release(device2);
2751 ref3 = get_refcount((IUnknown *)d3drm1);
2752 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2753 ref3 = get_refcount((IUnknown *)d3drm2);
2754 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2755 surface_ref2 = get_refcount((IUnknown *)surface);
2756 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
2757 surface_ref1, surface_ref2);
2758 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2759 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2760 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2761 ref1 = IDirectDrawSurface_Release(ds);
2762 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
2764 ref1 = IDirectDrawSurface_Release(surface);
2765 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
2767 memset(&desc, 0, sizeof(desc));
2768 desc.dwSize = sizeof(desc);
2769 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2770 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
2771 desc.dwWidth = rc.right;
2772 desc.dwHeight = rc.bottom;
2774 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2775 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2777 memset(&desc, 0, sizeof(desc));
2778 desc.dwSize = sizeof(desc);
2779 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
2780 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
2781 desc.dwZBufferBitDepth = 16;
2782 desc.dwWidth = rc.right;
2783 desc.dwHeight = rc.bottom;
2784 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
2785 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
2786 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
2787 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
2789 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
2790 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
2792 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
2793 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2795 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
2796 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2797 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
2799 /* Check if depth surface matches the one we created */
2800 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
2801 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2802 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
2804 IDirectDrawSurface_Release(d3drm_ds);
2805 IDirectDrawSurface_Release(d3drm_surface);
2806 IDirectDrawSurface_Release(ds);
2808 IDirect3DDevice2_Release(d3ddevice2);
2809 IDirect3DRMDevice2_Release(device2);
2810 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2811 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2812 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2813 ref1 = IDirectDrawSurface_Release(ds);
2814 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
2815 ref1 = IDirectDrawSurface_Release(surface);
2816 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
2817 IDirect3DRM2_Release(d3drm2);
2818 IDirect3DRM_Release(d3drm1);
2819 IDirectDraw_Release(ddraw);
2820 DestroyWindow(window);
2823 static void test_create_device_from_surface3(void)
2825 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2826 DDSURFACEDESC desc;
2827 IDirectDraw *ddraw = NULL;
2828 IDirect3DRM *d3drm1 = NULL;
2829 IDirect3DRM3 *d3drm3 = NULL;
2830 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
2831 IDirect3DDevice2 *d3ddevice2 = NULL;
2832 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
2833 DWORD expected_flags;
2834 HWND window;
2835 GUID driver = IID_IDirect3DRGBDevice;
2836 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
2837 RECT rc;
2838 BOOL use_sysmem_zbuffer = FALSE;
2839 HRESULT hr;
2841 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2842 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2844 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
2845 GetClientRect(window, &rc);
2847 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2848 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
2850 hr = Direct3DRMCreate(&d3drm1);
2851 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2852 ref1 = get_refcount((IUnknown *)d3drm1);
2854 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2855 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2856 ref2 = get_refcount((IUnknown *)d3drm3);
2858 /* Create a surface and use it to create the retained mode device. */
2859 memset(&desc, 0, sizeof(desc));
2860 desc.dwSize = sizeof(desc);
2861 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2862 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2863 desc.dwWidth = rc.right;
2864 desc.dwHeight = rc.bottom;
2866 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2867 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2869 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
2870 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
2871 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
2872 IDirectDrawSurface_Release(surface);
2874 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
2875 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2876 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2877 surface_ref1 = get_refcount((IUnknown *)surface);
2879 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, NULL);
2880 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
2881 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, NULL, 0, &device3);
2882 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
2883 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, NULL, surface, 0, &device3);
2884 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
2886 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
2887 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
2888 ref3 = get_refcount((IUnknown *)d3drm1);
2889 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2890 ref3 = get_refcount((IUnknown *)d3drm3);
2891 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2892 surface_ref2 = get_refcount((IUnknown *)surface);
2893 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
2895 /* Check if CreateDeviceFromSurface creates a primary surface */
2896 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2897 NULL, &d3drm_surface, surface_callback);
2898 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2899 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
2901 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
2902 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2904 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
2905 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2906 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
2908 /* Check properties of attached depth surface */
2909 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
2910 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2912 memset(&desc, 0, sizeof(desc));
2913 desc.dwSize = sizeof(desc);
2914 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2915 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2917 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
2918 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
2919 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
2920 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2921 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2922 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2924 IDirectDrawSurface_Release(ds);
2925 IDirect3DDevice2_Release(d3ddevice2);
2926 IDirectDrawSurface_Release(d3drm_surface);
2927 IDirect3DRMDevice3_Release(device3);
2929 ref3 = get_refcount((IUnknown *)d3drm1);
2930 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2931 ref3 = get_refcount((IUnknown *)d3drm3);
2932 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2933 surface_ref2 = get_refcount((IUnknown *)surface);
2934 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
2935 surface_ref1, surface_ref2);
2936 /* In version 3, d3drm will destroy all references of the depth surface it created internally. */
2937 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2938 todo_wine ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x.\n", hr);
2939 if (SUCCEEDED(hr))
2940 IDirectDrawSurface_Release(ds);
2941 ref1 = IDirectDrawSurface_Release(surface);
2942 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
2944 memset(&desc, 0, sizeof(desc));
2945 desc.dwSize = sizeof(desc);
2946 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2947 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
2948 desc.dwWidth = rc.right;
2949 desc.dwHeight = rc.bottom;
2951 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
2952 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2954 memset(&desc, 0, sizeof(desc));
2955 desc.dwSize = sizeof(desc);
2956 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
2957 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
2958 desc.dwZBufferBitDepth = 16;
2959 desc.dwWidth = rc.right;
2960 desc.dwHeight = rc.bottom;
2961 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
2962 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
2963 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
2964 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
2966 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
2967 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
2969 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
2970 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2972 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
2973 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2974 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
2976 /* Check if depth surface matches the one we created */
2977 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
2978 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2979 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
2981 IDirectDrawSurface_Release(d3drm_ds);
2982 IDirectDrawSurface_Release(d3drm_surface);
2983 IDirectDrawSurface_Release(ds);
2984 IDirect3DDevice2_Release(d3ddevice2);
2985 IDirect3DRMDevice3_Release(device3);
2986 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2987 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2988 /* The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2989 ref1 = IDirectDrawSurface_Release(ds);
2990 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
2992 /* What happens if we pass no flags and still attach our own depth surface? */
2993 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
2994 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
2996 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
2997 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2999 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3000 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3001 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3003 /* Check if depth surface matches the one we created */
3004 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3005 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3006 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3008 IDirectDrawSurface_Release(d3drm_ds);
3009 IDirectDrawSurface_Release(d3drm_surface);
3010 IDirect3DDevice2_Release(d3ddevice2);
3011 IDirect3DRMDevice3_Release(device3);
3012 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3013 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3014 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3015 ref1 = IDirectDrawSurface_Release(ds);
3016 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3017 ref1 = IDirectDrawSurface_Release(surface);
3018 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3020 memset(&desc, 0, sizeof(desc));
3021 desc.dwSize = sizeof(desc);
3022 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3023 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3024 desc.dwWidth = rc.right;
3025 desc.dwHeight = rc.bottom;
3027 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3028 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3030 /* What happens if we don't pass D3DRMDEVICE_NOZBUFFER and still not attach our own depth surface? */
3031 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
3032 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3034 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3035 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3037 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3038 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3039 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3041 /* Check if depth surface matches the one we created */
3042 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3043 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x).\n", hr);
3044 IDirectDrawSurface_Release(d3drm_surface);
3046 IDirect3DDevice2_Release(d3ddevice2);
3047 IDirect3DRMDevice3_Release(device3);
3048 ref1 = IDirectDrawSurface_Release(surface);
3049 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3050 IDirect3DRM3_Release(d3drm3);
3051 IDirect3DRM_Release(d3drm1);
3052 IDirectDraw_Release(ddraw);
3053 DestroyWindow(window);
3056 static IDirect3DDevice *create_device1(IDirectDraw *ddraw, HWND window, IDirectDrawSurface **ds)
3058 static const DWORD z_depths[] = { 32, 24, 16 };
3059 IDirectDrawSurface *surface;
3060 IDirect3DDevice *device = NULL;
3061 DDSURFACEDESC surface_desc;
3062 unsigned int i;
3063 HRESULT hr;
3064 RECT rc;
3066 GetClientRect(window, &rc);
3067 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3068 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3070 memset(&surface_desc, 0, sizeof(surface_desc));
3071 surface_desc.dwSize = sizeof(surface_desc);
3072 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3073 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3074 surface_desc.dwWidth = rc.right;
3075 surface_desc.dwHeight = rc.bottom;
3077 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
3078 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3080 /* We used to use EnumDevices() for this, but it seems
3081 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
3082 * relationship with reality. */
3083 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
3085 memset(&surface_desc, 0, sizeof(surface_desc));
3086 surface_desc.dwSize = sizeof(surface_desc);
3087 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3088 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
3089 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
3090 surface_desc.dwWidth = rc.right;
3091 surface_desc.dwHeight = rc.bottom;
3092 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, ds, NULL)))
3093 continue;
3095 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
3096 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3097 if (FAILED(hr))
3099 IDirectDrawSurface_Release(*ds);
3100 continue;
3103 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device)))
3104 break;
3106 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
3107 IDirectDrawSurface_Release(*ds);
3108 *ds = NULL;
3111 IDirectDrawSurface_Release(surface);
3112 return device;
3115 static void test_create_device_from_d3d1(void)
3117 IDirectDraw *ddraw1 = NULL;
3118 IDirect3D *d3d1 = NULL;
3119 IDirect3DRM *d3drm1 = NULL;
3120 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3121 IDirect3DDevice *d3ddevice1 = NULL, *d3drm_d3ddevice1 = NULL;
3122 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
3123 DWORD expected_flags;
3124 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3125 DDSURFACEDESC desc;
3126 RECT rc;
3127 HWND window;
3128 ULONG ref1, ref2, device_ref1, device_ref2;
3129 HRESULT hr;
3131 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
3132 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3134 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
3135 GetClientRect(window, &rc);
3137 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
3138 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
3140 /* Create the immediate mode device */
3141 d3ddevice1 = create_device1(ddraw1, window, &ds);
3142 if (d3ddevice1 == NULL)
3144 win_skip("Cannot create IM device, skipping tests.\n");
3145 IDirect3D_Release(d3d1);
3146 IDirectDraw_Release(ddraw1);
3147 return;
3149 device_ref1 = get_refcount((IUnknown *)d3ddevice1);
3151 hr = Direct3DRMCreate(&d3drm1);
3152 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3153 ref1 = get_refcount((IUnknown *)d3drm1);
3155 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, NULL, d3ddevice1, &device1);
3156 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3157 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3158 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, NULL, &device1);
3159 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3160 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, NULL);
3161 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3163 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, &device1);
3164 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice interface (hr = %x)\n", hr);
3165 ref2 = get_refcount((IUnknown *)d3drm1);
3166 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3167 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
3168 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
3170 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3171 NULL, &surface, surface_callback);
3172 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3173 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
3175 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
3176 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3177 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode deivce created == %p, got %p.\n", d3ddevice1, d3drm_d3ddevice1);
3179 /* Check properties of render target and depth surfaces */
3180 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3181 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3183 memset(&desc, 0, sizeof(desc));
3184 desc.dwSize = sizeof(desc);
3185 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
3186 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3188 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3189 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3190 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3191 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
3192 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3193 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3195 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
3196 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3197 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3199 desc.dwSize = sizeof(desc);
3200 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3201 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3203 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3204 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3205 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3206 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3207 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3209 IDirectDrawSurface_Release(d3drm_ds);
3210 IDirectDrawSurface_Release(ds);
3211 IDirectDrawSurface_Release(surface);
3212 IDirect3DDevice_Release(d3drm_d3ddevice1);
3213 IDirect3DRMDevice_Release(device1);
3214 ref2 = get_refcount((IUnknown *)d3drm1);
3215 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3216 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
3217 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
3219 IDirect3DRM_Release(d3drm1);
3220 IDirect3DDevice_Release(d3ddevice1);
3221 IDirect3D_Release(d3d1);
3222 IDirectDraw_Release(ddraw1);
3223 DestroyWindow(window);
3226 static IDirect3DDevice2 *create_device2(IDirectDraw2 *ddraw, HWND window, IDirectDrawSurface **ds)
3228 static const DWORD z_depths[] = { 32, 24, 16 };
3229 IDirectDrawSurface *surface;
3230 IDirect3DDevice2 *device = NULL;
3231 DDSURFACEDESC surface_desc;
3232 IDirect3D2 *d3d;
3233 unsigned int i;
3234 HRESULT hr;
3235 RECT rc;
3237 GetClientRect(window, &rc);
3238 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3239 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3241 memset(&surface_desc, 0, sizeof(surface_desc));
3242 surface_desc.dwSize = sizeof(surface_desc);
3243 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3244 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3245 surface_desc.dwWidth = rc.right;
3246 surface_desc.dwHeight = rc.bottom;
3248 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
3249 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3251 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
3252 if (FAILED(hr))
3254 IDirectDrawSurface_Release(surface);
3255 *ds = NULL;
3256 return NULL;
3259 /* We used to use EnumDevices() for this, but it seems
3260 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
3261 * relationship with reality. */
3262 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
3264 memset(&surface_desc, 0, sizeof(surface_desc));
3265 surface_desc.dwSize = sizeof(surface_desc);
3266 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3267 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
3268 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
3269 surface_desc.dwWidth = rc.right;
3270 surface_desc.dwHeight = rc.bottom;
3271 if (FAILED(IDirectDraw2_CreateSurface(ddraw, &surface_desc, ds, NULL)))
3272 continue;
3274 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
3275 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3276 if (FAILED(hr))
3278 IDirectDrawSurface_Release(*ds);
3279 continue;
3282 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device)))
3283 break;
3285 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
3286 IDirectDrawSurface_Release(*ds);
3287 *ds = NULL;
3290 IDirect3D2_Release(d3d);
3291 IDirectDrawSurface_Release(surface);
3292 return device;
3295 static void test_create_device_from_d3d2(void)
3297 IDirectDraw *ddraw1 = NULL;
3298 IDirectDraw2 *ddraw2 = NULL;
3299 IDirect3D2 *d3d2 = NULL;
3300 IDirect3DRM *d3drm1 = NULL;
3301 IDirect3DRM2 *d3drm2 = NULL;
3302 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
3303 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL;
3304 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
3305 DWORD expected_flags;
3306 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3307 DDSURFACEDESC desc;
3308 RECT rc;
3309 HWND window;
3310 ULONG ref1, ref2, ref3, device_ref1, device_ref2;
3311 HRESULT hr;
3313 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
3314 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3316 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
3317 GetClientRect(window, &rc);
3319 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
3320 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
3321 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
3322 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
3324 /* Create the immediate mode device */
3325 d3ddevice2 = create_device2(ddraw2, window, &ds);
3326 if (d3ddevice2 == NULL)
3328 win_skip("Cannot create IM device, skipping tests.\n");
3329 IDirect3D2_Release(d3d2);
3330 IDirectDraw2_Release(ddraw2);
3331 IDirectDraw_Release(ddraw1);
3332 return;
3334 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
3336 hr = Direct3DRMCreate(&d3drm1);
3337 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3338 ref1 = get_refcount((IUnknown *)d3drm1);
3340 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3341 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3342 ref2 = get_refcount((IUnknown *)d3drm2);
3344 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, NULL, d3ddevice2, &device2);
3345 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3346 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
3347 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, NULL, &device2);
3348 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3349 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, NULL);
3350 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3352 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, &device2);
3353 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice2 interface (hr = %x)\n", hr);
3354 ref3 = get_refcount((IUnknown *)d3drm1);
3355 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3356 ref3 = get_refcount((IUnknown *)d3drm2);
3357 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3358 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
3359 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
3361 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3362 NULL, &surface, surface_callback);
3363 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3364 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
3366 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
3367 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3368 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode deivce created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
3370 /* Check properties of render target and depth surfaces */
3371 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
3372 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3374 memset(&desc, 0, sizeof(desc));
3375 desc.dwSize = sizeof(desc);
3376 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
3377 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3379 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3380 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3381 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3382 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
3383 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3384 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3386 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
3387 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3388 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3390 desc.dwSize = sizeof(desc);
3391 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3392 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3394 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3395 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3396 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3397 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3398 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3400 IDirectDrawSurface_Release(d3drm_ds);
3401 IDirectDrawSurface_Release(ds);
3402 IDirectDrawSurface_Release(surface);
3403 IDirect3DDevice2_Release(d3drm_d3ddevice2);
3404 IDirect3DRMDevice2_Release(device2);
3405 ref3 = get_refcount((IUnknown *)d3drm1);
3406 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3407 ref3 = get_refcount((IUnknown *)d3drm2);
3408 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3409 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
3410 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
3412 IDirect3DRM2_Release(d3drm2);
3413 IDirect3DRM_Release(d3drm1);
3414 IDirect3DDevice2_Release(d3ddevice2);
3415 IDirect3D2_Release(d3d2);
3416 IDirectDraw2_Release(ddraw2);
3417 IDirectDraw_Release(ddraw1);
3418 DestroyWindow(window);
3421 static void test_create_device_from_d3d3(void)
3423 IDirectDraw *ddraw1 = NULL;
3424 IDirectDraw2 *ddraw2 = NULL;
3425 IDirect3D2 *d3d2 = NULL;
3426 IDirect3DRM *d3drm1 = NULL;
3427 IDirect3DRM3 *d3drm3 = NULL;
3428 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
3429 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL;
3430 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
3431 DWORD expected_flags;
3432 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3433 DDSURFACEDESC desc;
3434 RECT rc;
3435 HWND window;
3436 ULONG ref1, ref2, ref3, device_ref1, device_ref2;
3437 HRESULT hr;
3439 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
3440 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3442 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
3443 GetClientRect(window, &rc);
3445 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
3446 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
3447 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
3448 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
3450 /* Create the immediate mode device */
3451 d3ddevice2 = create_device2(ddraw2, window, &ds);
3452 if (d3ddevice2 == NULL)
3454 win_skip("Cannot create IM device, skipping tests.\n");
3455 IDirect3D2_Release(d3d2);
3456 IDirectDraw2_Release(ddraw2);
3457 IDirectDraw_Release(ddraw1);
3458 return;
3460 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
3462 hr = Direct3DRMCreate(&d3drm1);
3463 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3464 ref1 = get_refcount((IUnknown *)d3drm1);
3466 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3467 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3468 ref2 = get_refcount((IUnknown *)d3drm3);
3470 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, NULL, d3ddevice2, &device3);
3471 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3472 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
3473 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, NULL, &device3);
3474 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3475 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, NULL);
3476 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3478 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, &device3);
3479 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice3 interface (hr = %x)\n", hr);
3480 ref3 = get_refcount((IUnknown *)d3drm1);
3481 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3482 ref3 = get_refcount((IUnknown *)d3drm3);
3483 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3484 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
3485 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
3487 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3488 NULL, &surface, surface_callback);
3489 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3490 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
3492 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
3493 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3494 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode deivce created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
3496 /* Check properties of render target and depth surfaces */
3497 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
3498 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3500 memset(&desc, 0, sizeof(desc));
3501 desc.dwSize = sizeof(desc);
3502 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
3503 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3505 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3506 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3507 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3508 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
3509 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3510 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3512 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
3513 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3514 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3516 desc.dwSize = sizeof(desc);
3517 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3518 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3520 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3521 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3522 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3523 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3524 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3526 IDirectDrawSurface_Release(d3drm_ds);
3527 IDirectDrawSurface_Release(ds);
3528 IDirectDrawSurface_Release(surface);
3529 IDirect3DDevice2_Release(d3drm_d3ddevice2);
3530 IDirect3DRMDevice3_Release(device3);
3531 ref3 = get_refcount((IUnknown *)d3drm1);
3532 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3533 ref3 = get_refcount((IUnknown *)d3drm3);
3534 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3535 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
3536 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
3538 IDirect3DRM3_Release(d3drm3);
3539 IDirect3DRM_Release(d3drm1);
3540 IDirect3DDevice2_Release(d3ddevice2);
3541 IDirect3D2_Release(d3d2);
3542 IDirectDraw2_Release(ddraw2);
3543 IDirectDraw_Release(ddraw1);
3544 DestroyWindow(window);
3547 START_TEST(d3drm)
3549 test_MeshBuilder();
3550 test_MeshBuilder3();
3551 test_Mesh();
3552 test_Face();
3553 test_Frame();
3554 test_Device();
3555 test_Viewport();
3556 test_Light();
3557 test_Material2();
3558 test_Texture();
3559 test_frame_transform();
3560 test_d3drm_load();
3561 test_frame_mesh_materials();
3562 test_d3drm_qi();
3563 test_frame_qi();
3564 test_create_device_from_clipper1();
3565 test_create_device_from_clipper2();
3566 test_create_device_from_clipper3();
3567 test_create_device_from_surface1();
3568 test_create_device_from_surface2();
3569 test_create_device_from_surface3();
3570 test_create_device_from_d3d1();
3571 test_create_device_from_d3d2();
3572 test_create_device_from_d3d3();