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
27 #include "wine/test.h"
29 #define CHECK_REFCOUNT(obj,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
[] =
61 static char data_no_mesh
[] =
68 static char data_ok
[] =
87 static char data_full
[] =
89 "Header { 1; 0; 1; }\n"
97 " MeshMaterialList {\n"
100 " 0.0; 1.0; 0.0; 1.0;;\n"
104 " TextureFileName {\n"
105 " \"Texture.bmp\";\n"
117 " MeshTextureCoords {\n"
125 static char data_d3drm_load
[] =
152 " 0.1, 0.2, 0.3, 0.4;;\n"
158 static char data_frame_mesh_materials
[] =
160 "Header { 1; 0; 1; }\n"
176 " MeshMaterialList {\n"
177 " 3; 6; 0, 1, 1, 2, 2, 2;\n"
179 " 1.0; 0.0; 0.0; 0.1;;\n"
181 " 0.11; 0.12; 0.13;;\n"
182 " 0.14; 0.15; 0.16;;\n"
185 " 0.0; 1.0; 0.0; 0.2;;\n"
187 " 0.21; 0.22; 0.23;;\n"
188 " 0.24; 0.25; 0.26;;\n"
191 " 0.0; 0.0; 1.0; 0.3;;\n"
193 " 0.31; 0.32; 0.33;;\n"
194 " 0.34; 0.35; 0.36;;\n"
200 static void test_MeshBuilder(void)
204 IDirect3DRMMeshBuilder
*pMeshBuilder
;
205 IDirect3DRMMesh
*mesh
;
206 D3DRMLOADMEMORY info
;
208 DWORD val1
, val2
, val3
;
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
);
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
);
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
);
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
);
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 */
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
);
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
);
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
);
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
);
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
);
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
);
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
);
426 unsigned nb_vertices
, nb_faces
, nb_face_vertices
;
428 IDirect3DRMMaterial
*material
= (IDirect3DRMMaterial
*)0xdeadbeef;
429 IDirect3DRMTexture
*texture
= (IDirect3DRMTexture
*)0xdeadbeef;
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)
503 IDirect3DRM3
*d3drm3
;
504 IDirect3DRMMeshBuilder3
*pMeshBuilder3
;
505 D3DRMLOADMEMORY info
;
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
);
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
);
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 */
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
);
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
);
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
);
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
);
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
);
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)
614 IDirect3DRMMesh
*mesh
;
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
);
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)
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];
656 CHAR cname
[64] = {0};
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
);
666 skip("Cannot get IDirect3DRMFace interface (hr = %x), skipping tests\n", hr
);
667 IDirect3DRM_Release(d3drm
);
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
);
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
);
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
);
703 hr
= IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2
, &array1
);
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
);
712 ok(icount
== 1, "wrong FaceCount: %i\n", icount
);
715 hr
= IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2
, &array1
);
717 ok(hr
== D3DRM_OK
, "Cannot get FaceArray (hr = %x)\n", hr
);
719 ok(array1
!= NULL
, "pArray = %p\n", 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
);
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
);
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
);
768 ok(icount
== 1, "wrong FaceCount: %i\n", icount
);
771 hr
= IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3
, &array1
);
773 ok(hr
== D3DRM_OK
, "Cannot get FaceArray (hr = %x)\n", hr
);
775 ok(array1
!= NULL
, "pArray = %p\n", 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
);
803 ok(icount
== 4, "Wrong number of faces %d (must be 4)\n", icount
);
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
);
815 hr
= IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3
, &array1
);
817 ok(hr
== D3DRM_OK
, "Cannot get FaceArray (hr = %x)\n", hr
);
819 ok(array1
!= NULL
, "pArray = %p\n", 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)
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
;
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
);
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);
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
);
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);
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
));
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);
1006 hr
= IDirect3DRMFrame_GetChildren(pFrameP2
, &frame_array
);
1007 ok(hr
== D3DRM_OK
, "Cannot get children (hr = %x)\n", hr
);
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
);
1020 hr
= IDirect3DRMFrame_GetChildren(pFrameP1
, &frame_array
);
1021 ok(hr
== D3DRM_OK
, "Cannot get children (hr = %x)\n", hr
);
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);
1046 hr
= IDirect3DRMFrame_GetChildren(pFrameP2
, &frame_array
);
1047 ok(hr
== D3DRM_OK
, "Cannot get children (hr = %x)\n", hr
);
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
);
1060 hr
= IDirect3DRMFrame_DeleteChild(pFrameP2
, pFrameC
);
1061 ok(hr
== D3DRM_OK
, "Cannot delete child frame (hr = %x)\n", hr
);
1062 CHECK_REFCOUNT(pFrameC
, 1);
1065 hr
= IDirect3DRMFrame_GetChildren(pFrameP2
, &frame_array
);
1066 ok(hr
== D3DRM_OK
, "Cannot get children (hr = %x)\n", hr
);
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);
1093 hr
= IDirect3DRMFrame_GetChildren(pFrameP2
, &frame_array
);
1094 ok(hr
== D3DRM_OK
, "Cannot get children (hr = %x)\n", hr
);
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);
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
);
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
);
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);
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);
1170 hr
= IDirect3DRMFrame_GetLights(pFrameP1
, &light_array
);
1171 ok(hr
== D3DRM_OK
, "Cannot get lights (hr = %x)\n", hr
);
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
);
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
);
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
;
1219 IDirect3DRMDevice
*device
;
1220 IDirect3DRMFrame
*frame
;
1221 IDirect3DRMViewport
*viewport
;
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
);
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)
1276 IDirect3DRMLight
*light
;
1277 D3DRMLIGHTTYPE type
;
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
);
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)
1331 IDirect3DRM3
*d3drm3
;
1332 IDirect3DRMMaterial2
*material2
;
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
);
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
);
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)
1411 IDirect3DRMTexture
*texture
;
1412 D3DRMIMAGE initimg
= {
1414 TRUE
, 2 * sizeof(DWORD
), NULL
, NULL
,
1415 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
1417 DWORD pixel
[4] = { 20000, 30000, 10000, 0 };
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
);
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
;
1451 IDirect3DRMDevice
*device
;
1452 IDirect3DRMWinDevice
*win_device
;
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
);
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
);
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
);
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
);
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
);
1511 IDirect3DRMDevice_Release(device
);
1512 IDirectDrawClipper_Release(pClipper
);
1514 IDirect3DRM_Release(d3drm
);
1515 DestroyWindow(window
);
1518 static void test_frame_transform(void)
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
);
1556 static void test_d3drm_load(void)
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
)
1581 IDirect3DRMFrame
*frame
;
1582 IDirect3DRMVisualArray
*array
;
1583 IDirect3DRMVisual
*visual
;
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
);
1615 int vertex_per_face
;
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)
1631 D3DRMLOADMEMORY info
;
1632 const GUID
*req_refiids
[] = { &IID_IDirect3DRMFrame
};
1633 IDirect3DRMMesh
*mesh
;
1635 IDirect3DRMMaterial
*material
;
1636 IDirect3DRMTexture
*texture
;
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
;
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
);
1691 IDirect3DRMMaterial_Release(material
);
1693 IDirect3DRMTexture_Release(texture
);
1696 IDirect3DRMMesh_Release(mesh
);
1697 IDirect3DRMMeshBuilder_Release(mesh_builder
);
1698 IDirect3DRM_Release(d3drm
);
1704 REFIID refcount_iid
;
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
;
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
);
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
);
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
},
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
},
1906 IDirect3DRM
*d3drm1
;
1907 IDirect3DRM2
*d3drm2
;
1908 IDirect3DRM3
*d3drm3
;
1909 IDirect3DRMFrame
*frame1
;
1910 IDirect3DRMFrame2
*frame2
;
1911 IDirect3DRMFrame3
*frame3
;
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
)
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
= NULL
;
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
;
1978 GUID driver
= IID_IDirect3DRGBDevice
;
1980 ULONG ref1
, ref2
, cref1
, cref2
;
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 todo_wine
ok(hr
== D3DRMERR_BADVALUE
, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr
);
1998 IDirect3DRMDevice_Release(device1
);
2000 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2001 hr
= IDirect3DRM_CreateDeviceFromClipper(d3drm1
, NULL
, &driver
, 300, 200, &device1
);
2002 todo_wine
ok(hr
== D3DRMERR_BADVALUE
, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr
);
2004 IDirect3DRMDevice_Release(device1
);
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 todo_wine
ok(ref2
> ref1
, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1
, ref2
);
2010 cref2
= get_refcount((IUnknown
*)clipper
);
2011 todo_wine
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 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr
);
2019 hr
= IDirect3DDevice_QueryInterface(d3ddevice1
, &IID_IDirectDrawSurface
, (void **)&surface
);
2020 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2022 hr
= IDirectDrawSurface_GetClipper(surface
, &d3drm_clipper
);
2023 ok(hr
== DDERR_NOCLIPPERATTACHED
, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr
);
2025 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2026 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **)&surface7
);
2027 ok(hr
== DD_OK
, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr
);
2028 IDirectDrawSurface7_GetDDInterface(surface7
, (void **)&unknown
);
2029 hr
= IUnknown_QueryInterface(unknown
, &IID_IDirectDraw
, (void **)&ddraw
);
2030 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2031 IUnknown_Release(unknown
);
2032 hr
= IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2033 NULL
, &d3drm_primary
, surface_callback
);
2034 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
2035 ok(d3drm_primary
!= NULL
, "No primary surface was enumerated.\n");
2036 hr
= IDirectDrawSurface_GetClipper(d3drm_primary
, &d3drm_clipper
);
2037 ok(hr
== DD_OK
, "Cannot get attached clipper from primary surface (hr = %x).\n", hr
);
2038 ok(d3drm_clipper
== clipper
, "Expected clipper returned == %p, got %p.\n", clipper
, d3drm_clipper
);
2040 IDirectDrawClipper_Release(d3drm_clipper
);
2041 IDirectDrawSurface_Release(d3drm_primary
);
2042 IDirectDrawSurface7_Release(surface7
);
2043 IDirectDraw_Release(ddraw
);
2045 /* Check properties of render target and depth surface */
2046 surface_desc
.dwSize
= sizeof(surface_desc
);
2047 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
2048 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
2050 ok((surface_desc
.dwWidth
== 300) && (surface_desc
.dwHeight
== 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2051 surface_desc
.dwWidth
, surface_desc
.dwHeight
);
2052 ok((surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
)) == (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
),
2053 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
, surface_desc
.ddsCaps
.dwCaps
);
2054 expected_flags
= DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2055 ok(surface_desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, surface_desc
.dwFlags
);
2057 hr
= DirectDrawCreate(NULL
, &ddraw
, NULL
);
2058 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2059 desc
.dwSize
= sizeof(desc
);
2060 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2061 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2062 ok(desc
.ddpfPixelFormat
.dwRGBBitCount
== surface_desc
.ddpfPixelFormat
.dwRGBBitCount
, "Expected %u bpp, got %u bpp.\n",
2063 surface_desc
.ddpfPixelFormat
.dwRGBBitCount
, desc
.ddpfPixelFormat
.dwRGBBitCount
);
2065 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2066 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2068 desc
.dwSize
= sizeof(desc
);
2069 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
2070 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
2072 ok((desc
.dwWidth
== 300) && (desc
.dwHeight
== 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2073 desc
.dwWidth
, desc
.dwHeight
);
2074 ok((desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) == DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
2075 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2076 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
2077 ok(desc
.dwZBufferBitDepth
== 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc
.dwZBufferBitDepth
);
2078 ok(desc
.ddpfPixelFormat
.dwStencilBitMask
== 0, "Expected 0 stencil bits, got %x.\n", desc
.ddpfPixelFormat
.dwStencilBitMask
);
2080 /* Release old objects and check refcount of device and clipper */
2081 IDirectDrawSurface_Release(ds
);
2083 IDirectDrawSurface_Release(surface
);
2085 IDirect3DDevice_Release(d3ddevice1
);
2087 IDirect3DRMDevice_Release(device1
);
2088 ref2
= get_refcount((IUnknown
*)d3drm1
);
2089 ok(ref1
== ref2
, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1
, ref2
);
2090 cref2
= get_refcount((IUnknown
*)clipper
);
2091 todo_wine
ok(cref1
== cref2
, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1
, cref2
);
2093 /* Test if render target format follows the screen format */
2094 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2095 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2096 hr
= IDirectDraw_SetDisplayMode(ddraw
, desc
.dwWidth
, desc
.dwHeight
, 16);
2097 ok(hr
== DD_OK
, "Cannot set display mode to 16bpp (hr = %x).\n", hr
);
2099 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2100 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2101 ok(desc
.ddpfPixelFormat
.dwRGBBitCount
== 16, "Expected 16 bpp, got %u.\n", desc
.ddpfPixelFormat
.dwRGBBitCount
);
2103 hr
= IDirect3DRM_CreateDeviceFromClipper(d3drm1
, clipper
, &driver
, rc
.right
, rc
.bottom
, &device1
);
2104 ok(hr
== D3DRM_OK
, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr
);
2106 hr
= IDirect3DRMDevice_GetDirect3DDevice(device1
, &d3ddevice1
);
2107 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr
);
2111 hr
= IDirect3DDevice_QueryInterface(d3ddevice1
, &IID_IDirectDrawSurface
, (void **)&surface
);
2112 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2114 surface_desc
.dwSize
= sizeof(surface_desc
);
2115 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
2116 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
2117 todo_wine
ok(surface_desc
.ddpfPixelFormat
.dwRGBBitCount
== 16, "Expected 16bpp, got %ubpp.\n",
2118 surface_desc
.ddpfPixelFormat
.dwRGBBitCount
);
2120 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2121 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2125 IDirectDrawSurface_Release(ds
);
2127 IDirectDrawSurface_Release(surface
);
2129 IDirect3DDevice_Release(d3ddevice1
);
2130 IDirect3DRMDevice_Release(device1
);
2132 IDirect3DRM_Release(d3drm1
);
2134 IDirectDrawClipper_Release(clipper
);
2136 IDirectDraw_Release(ddraw
);
2137 DestroyWindow(window
);
2140 static void test_create_device_from_clipper2(void)
2142 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
2143 IDirect3DRM
*d3drm1
= NULL
;
2144 IDirect3DRM2
*d3drm2
= NULL
;
2145 IDirectDraw
*ddraw
= NULL
;
2146 IUnknown
*unknown
= NULL
;
2147 IDirect3DRMDevice2
*device2
= NULL
;
2148 IDirect3DDevice2
*d3ddevice2
= NULL
;
2149 IDirectDrawClipper
*clipper
= NULL
, *d3drm_clipper
= NULL
;
2150 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_primary
= NULL
;
2151 IDirectDrawSurface7
*surface7
= NULL
;
2152 DDSURFACEDESC desc
, surface_desc
;
2153 DWORD expected_flags
;
2155 GUID driver
= IID_IDirect3DRGBDevice
;
2157 ULONG ref1
, ref2
, ref3
, cref1
, cref2
;
2160 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, 0, 0, 500, 400, 0, 0, 0, 0);
2161 GetClientRect(window
, &rc
);
2162 hr
= DirectDrawCreateClipper(0, &clipper
, NULL
);
2163 ok(hr
== DD_OK
, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr
);
2164 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
2165 ok(hr
== DD_OK
, "Cannot set HWnd to Clipper (hr = %x).\n", hr
);
2167 hr
= Direct3DRMCreate(&d3drm1
);
2168 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
2169 ref1
= get_refcount((IUnknown
*)d3drm1
);
2170 cref1
= get_refcount((IUnknown
*)clipper
);
2172 hr
= IDirect3DRM_QueryInterface(d3drm1
, &IID_IDirect3DRM2
, (void **)&d3drm2
);
2173 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr
);
2174 ref2
= get_refcount((IUnknown
*)d3drm2
);
2176 hr
= IDirect3DRM2_CreateDeviceFromClipper(d3drm2
, clipper
, &driver
, 0, 0, &device2
);
2177 todo_wine
ok(hr
== D3DRMERR_BADVALUE
, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr
);
2179 IDirect3DRMDevice2_Release(device2
);
2181 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2182 hr
= IDirect3DRM2_CreateDeviceFromClipper(d3drm2
, NULL
, &driver
, 300, 200, &device2
);
2183 todo_wine
ok(hr
== D3DRMERR_BADVALUE
, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr
);
2185 IDirect3DRMDevice2_Release(device2
);
2187 hr
= IDirect3DRM2_CreateDeviceFromClipper(d3drm2
, clipper
, &driver
, 300, 200, &device2
);
2188 ok(hr
== D3DRM_OK
, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr
);
2189 ref3
= get_refcount((IUnknown
*)d3drm1
);
2190 todo_wine
ok(ref3
> ref1
, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1
, ref3
);
2191 ref3
= get_refcount((IUnknown
*)d3drm2
);
2192 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2193 cref2
= get_refcount((IUnknown
*)clipper
);
2194 todo_wine
ok(cref2
> cref1
, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1
, cref2
);
2196 /* Fetch immediate mode device in order to access render target */
2197 hr
= IDirect3DRMDevice2_GetDirect3DDevice2(device2
, &d3ddevice2
);
2198 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
2202 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &surface
);
2203 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2205 hr
= IDirectDrawSurface_GetClipper(surface
, &d3drm_clipper
);
2206 ok(hr
== DDERR_NOCLIPPERATTACHED
, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr
);
2208 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2209 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **)&surface7
);
2210 ok(hr
== DD_OK
, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr
);
2211 IDirectDrawSurface7_GetDDInterface(surface7
, (void **)&unknown
);
2212 hr
= IUnknown_QueryInterface(unknown
, &IID_IDirectDraw
, (void **)&ddraw
);
2213 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2214 IUnknown_Release(unknown
);
2215 hr
= IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2216 NULL
, &d3drm_primary
, surface_callback
);
2217 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
2218 ok(d3drm_primary
!= NULL
, "No primary surface was enumerated.\n");
2219 hr
= IDirectDrawSurface_GetClipper(d3drm_primary
, &d3drm_clipper
);
2220 ok(hr
== DD_OK
, "Cannot get attached clipper from primary surface (hr = %x).\n", hr
);
2221 ok(d3drm_clipper
== clipper
, "Expected clipper returned == %p, got %p.\n", clipper
, d3drm_clipper
);
2223 IDirectDrawClipper_Release(d3drm_clipper
);
2224 IDirectDrawSurface_Release(d3drm_primary
);
2225 IDirectDrawSurface7_Release(surface7
);
2226 IDirectDraw_Release(ddraw
);
2228 /* Check properties of render target and depth surface */
2229 surface_desc
.dwSize
= sizeof(surface_desc
);
2230 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
2231 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
2233 ok((surface_desc
.dwWidth
== 300) && (surface_desc
.dwHeight
== 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2234 surface_desc
.dwWidth
, surface_desc
.dwHeight
);
2235 ok((surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
)) == (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
),
2236 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
, surface_desc
.ddsCaps
.dwCaps
);
2237 expected_flags
= DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2238 ok(surface_desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, surface_desc
.dwFlags
);
2240 hr
= DirectDrawCreate(NULL
, &ddraw
, NULL
);
2241 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2242 desc
.dwSize
= sizeof(desc
);
2243 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2244 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2245 ok(desc
.ddpfPixelFormat
.dwRGBBitCount
== surface_desc
.ddpfPixelFormat
.dwRGBBitCount
, "Expected %u bpp, got %u bpp.\n",
2246 surface_desc
.ddpfPixelFormat
.dwRGBBitCount
, desc
.ddpfPixelFormat
.dwRGBBitCount
);
2248 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2249 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2251 desc
.dwSize
= sizeof(desc
);
2252 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
2253 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
2255 ok((desc
.dwWidth
== 300) && (desc
.dwHeight
== 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2256 desc
.dwWidth
, desc
.dwHeight
);
2257 ok((desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) == DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
2258 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2259 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
2260 ok(desc
.dwZBufferBitDepth
== 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc
.dwZBufferBitDepth
);
2261 ok(desc
.ddpfPixelFormat
.dwStencilBitMask
== 0, "Expected 0 stencil bits, got %x.\n", desc
.ddpfPixelFormat
.dwStencilBitMask
);
2263 /* Release old objects and check refcount of device and clipper */
2264 IDirectDrawSurface_Release(ds
);
2266 IDirectDrawSurface_Release(surface
);
2268 IDirect3DDevice2_Release(d3ddevice2
);
2270 IDirect3DRMDevice2_Release(device2
);
2271 ref3
= get_refcount((IUnknown
*)d3drm1
);
2272 ok(ref1
== ref3
, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1
, ref3
);
2273 ref3
= get_refcount((IUnknown
*)d3drm2
);
2274 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2275 cref2
= get_refcount((IUnknown
*)clipper
);
2276 todo_wine
ok(cref1
== cref2
, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1
, cref2
);
2278 /* Test if render target format follows the screen format */
2279 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2280 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2281 hr
= IDirectDraw_SetDisplayMode(ddraw
, desc
.dwWidth
, desc
.dwHeight
, 16);
2282 ok(hr
== DD_OK
, "Cannot set display mode to 16bpp (hr = %x).\n", hr
);
2284 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2285 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2286 ok(desc
.ddpfPixelFormat
.dwRGBBitCount
== 16, "Expected 16 bpp, got %u.\n", desc
.ddpfPixelFormat
.dwRGBBitCount
);
2288 hr
= IDirect3DRM2_CreateDeviceFromClipper(d3drm2
, clipper
, &driver
, rc
.right
, rc
.bottom
, &device2
);
2289 ok(hr
== D3DRM_OK
, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr
);
2291 hr
= IDirect3DRMDevice2_GetDirect3DDevice2(device2
, &d3ddevice2
);
2292 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
2296 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &surface
);
2297 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2299 surface_desc
.dwSize
= sizeof(surface_desc
);
2300 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
2301 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
2302 todo_wine
ok(surface_desc
.ddpfPixelFormat
.dwRGBBitCount
== 16, "Expected 16bpp, got %ubpp.\n",
2303 surface_desc
.ddpfPixelFormat
.dwRGBBitCount
);
2305 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2306 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2310 IDirectDrawSurface_Release(ds
);
2312 IDirectDrawSurface_Release(surface
);
2314 IDirect3DDevice2_Release(d3ddevice2
);
2316 IDirect3DRMDevice2_Release(device2
);
2318 IDirect3DRM2_Release(d3drm2
);
2320 IDirect3DRM_Release(d3drm1
);
2322 IDirectDrawClipper_Release(clipper
);
2324 IDirectDraw_Release(ddraw
);
2325 DestroyWindow(window
);
2328 static void test_create_device_from_clipper3(void)
2330 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
2331 IDirect3DRM
*d3drm1
= NULL
;
2332 IDirect3DRM3
*d3drm3
= NULL
;
2333 IDirectDraw
*ddraw
= NULL
;
2334 IUnknown
*unknown
= NULL
;
2335 IDirect3DRMDevice3
*device3
= NULL
;
2336 IDirect3DDevice2
*d3ddevice2
= NULL
;
2337 IDirectDrawClipper
*clipper
= NULL
, *d3drm_clipper
= NULL
;
2338 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_primary
= NULL
;
2339 IDirectDrawSurface7
*surface7
= NULL
;
2340 DDSURFACEDESC desc
, surface_desc
;
2341 DWORD expected_flags
;
2343 GUID driver
= IID_IDirect3DRGBDevice
;
2345 ULONG ref1
, ref2
, ref3
, cref1
, cref2
;
2348 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, 0, 0, 500, 400, 0, 0, 0, 0);
2349 GetClientRect(window
, &rc
);
2350 hr
= DirectDrawCreateClipper(0, &clipper
, NULL
);
2351 ok(hr
== DD_OK
, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr
);
2352 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
2353 ok(hr
== DD_OK
, "Cannot set HWnd to Clipper (hr = %x).\n", hr
);
2355 hr
= Direct3DRMCreate(&d3drm1
);
2356 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
2357 ref1
= get_refcount((IUnknown
*)d3drm1
);
2358 cref1
= get_refcount((IUnknown
*)clipper
);
2360 hr
= IDirect3DRM_QueryInterface(d3drm1
, &IID_IDirect3DRM3
, (void **)&d3drm3
);
2361 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr
);
2362 ref2
= get_refcount((IUnknown
*)d3drm3
);
2364 hr
= IDirect3DRM3_CreateDeviceFromClipper(d3drm3
, clipper
, &driver
, 0, 0, &device3
);
2365 todo_wine
ok(hr
== D3DRMERR_BADVALUE
, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr
);
2367 IDirect3DRMDevice3_Release(device3
);
2369 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2370 hr
= IDirect3DRM3_CreateDeviceFromClipper(d3drm3
, NULL
, &driver
, 300, 200, &device3
);
2371 todo_wine
ok(hr
== D3DRMERR_BADVALUE
, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr
);
2373 IDirect3DRMDevice3_Release(device3
);
2375 hr
= IDirect3DRM3_CreateDeviceFromClipper(d3drm3
, clipper
, &driver
, 300, 200, &device3
);
2376 ok(hr
== D3DRM_OK
, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr
);
2377 ref3
= get_refcount((IUnknown
*)d3drm1
);
2378 todo_wine
ok(ref3
> ref1
, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1
, ref3
);
2379 ref3
= get_refcount((IUnknown
*)d3drm3
);
2380 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2381 cref2
= get_refcount((IUnknown
*)clipper
);
2382 todo_wine
ok(cref2
> cref1
, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1
, cref2
);
2384 /* Fetch immediate mode device in order to access render target */
2385 hr
= IDirect3DRMDevice3_GetDirect3DDevice2(device3
, &d3ddevice2
);
2386 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
2390 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &surface
);
2391 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2393 hr
= IDirectDrawSurface_GetClipper(surface
, &d3drm_clipper
);
2394 ok(hr
== DDERR_NOCLIPPERATTACHED
, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr
);
2396 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2397 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface7
, (void **)&surface7
);
2398 ok(hr
== DD_OK
, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr
);
2399 IDirectDrawSurface7_GetDDInterface(surface7
, (void **)&unknown
);
2400 hr
= IUnknown_QueryInterface(unknown
, &IID_IDirectDraw
, (void **)&ddraw
);
2401 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2402 IUnknown_Release(unknown
);
2403 hr
= IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2404 NULL
, &d3drm_primary
, surface_callback
);
2405 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
2406 ok(d3drm_primary
!= NULL
, "No primary surface was enumerated.\n");
2407 hr
= IDirectDrawSurface_GetClipper(d3drm_primary
, &d3drm_clipper
);
2408 ok(hr
== DD_OK
, "Cannot get attached clipper from primary surface (hr = %x).\n", hr
);
2409 ok(d3drm_clipper
== clipper
, "Expected clipper returned == %p, got %p.\n", clipper
, d3drm_clipper
);
2411 IDirectDrawClipper_Release(d3drm_clipper
);
2412 IDirectDrawSurface_Release(d3drm_primary
);
2413 IDirectDrawSurface7_Release(surface7
);
2414 IDirectDraw_Release(ddraw
);
2416 /* Check properties of render target and depth surface */
2417 surface_desc
.dwSize
= sizeof(surface_desc
);
2418 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
2419 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
2421 ok((surface_desc
.dwWidth
== 300) && (surface_desc
.dwHeight
== 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2422 surface_desc
.dwWidth
, surface_desc
.dwHeight
);
2423 ok((surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
)) == (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
),
2424 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
, surface_desc
.ddsCaps
.dwCaps
);
2425 expected_flags
= DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2426 ok(surface_desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, surface_desc
.dwFlags
);
2428 hr
= DirectDrawCreate(NULL
, &ddraw
, NULL
);
2429 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2430 desc
.dwSize
= sizeof(desc
);
2431 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2432 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2433 ok(desc
.ddpfPixelFormat
.dwRGBBitCount
== surface_desc
.ddpfPixelFormat
.dwRGBBitCount
, "Expected %u bpp, got %u bpp.\n",
2434 surface_desc
.ddpfPixelFormat
.dwRGBBitCount
, desc
.ddpfPixelFormat
.dwRGBBitCount
);
2436 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2437 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2439 desc
.dwSize
= sizeof(desc
);
2440 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
2441 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
2443 ok((desc
.dwWidth
== 300) && (desc
.dwHeight
== 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2444 desc
.dwWidth
, desc
.dwHeight
);
2445 ok((desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) == DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
2446 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2447 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
2448 ok(desc
.dwZBufferBitDepth
== 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc
.dwZBufferBitDepth
);
2449 ok(desc
.ddpfPixelFormat
.dwStencilBitMask
== 0, "Expected 0 stencil bits, got %x.\n", desc
.ddpfPixelFormat
.dwStencilBitMask
);
2451 /* Release old objects and check refcount of device and clipper */
2452 IDirectDrawSurface_Release(ds
);
2454 IDirectDrawSurface_Release(surface
);
2456 IDirect3DDevice2_Release(d3ddevice2
);
2458 IDirect3DRMDevice3_Release(device3
);
2459 ref3
= get_refcount((IUnknown
*)d3drm1
);
2460 ok(ref1
== ref3
, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1
, ref3
);
2461 ref3
= get_refcount((IUnknown
*)d3drm3
);
2462 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2463 cref2
= get_refcount((IUnknown
*)clipper
);
2464 todo_wine
ok(cref1
== cref2
, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1
, cref2
);
2466 /* Test if render target format follows the screen format */
2467 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2468 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2469 hr
= IDirectDraw_SetDisplayMode(ddraw
, desc
.dwWidth
, desc
.dwHeight
, 16);
2470 ok(hr
== DD_OK
, "Cannot set display mode to 16bpp (hr = %x).\n", hr
);
2472 hr
= IDirectDraw_GetDisplayMode(ddraw
, &desc
);
2473 ok(hr
== DD_OK
, "Cannot get IDirectDraw display mode (hr = %x)\n", hr
);
2474 ok(desc
.ddpfPixelFormat
.dwRGBBitCount
== 16, "Expected 16 bpp, got %u.\n", desc
.ddpfPixelFormat
.dwRGBBitCount
);
2476 hr
= IDirect3DRM3_CreateDeviceFromClipper(d3drm3
, clipper
, &driver
, rc
.right
, rc
.bottom
, &device3
);
2477 ok(hr
== D3DRM_OK
, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr
);
2479 hr
= IDirect3DRMDevice3_GetDirect3DDevice2(device3
, &d3ddevice2
);
2480 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
2484 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &surface
);
2485 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2487 surface_desc
.dwSize
= sizeof(surface_desc
);
2488 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
2489 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
2490 todo_wine
ok(surface_desc
.ddpfPixelFormat
.dwRGBBitCount
== 16, "Expected 16bpp, got %ubpp.\n",
2491 surface_desc
.ddpfPixelFormat
.dwRGBBitCount
);
2493 hr
= IDirectDraw2_RestoreDisplayMode(ddraw
);
2494 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2498 IDirectDrawSurface_Release(ds
);
2500 IDirectDrawSurface_Release(surface
);
2502 IDirect3DDevice2_Release(d3ddevice2
);
2504 IDirect3DRMDevice3_Release(device3
);
2506 IDirect3DRM3_Release(d3drm3
);
2508 IDirect3DRM_Release(d3drm1
);
2510 IDirectDrawClipper_Release(clipper
);
2512 IDirectDraw_Release(ddraw
);
2513 DestroyWindow(window
);
2516 static void test_create_device_from_surface1(void)
2518 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
2520 IDirectDraw
*ddraw
= NULL
;
2521 IDirect3DRM
*d3drm1
= NULL
;
2522 IDirect3DRMDevice
*device1
= NULL
;
2523 IDirect3DDevice
*d3ddevice1
= NULL
;
2524 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_surface
= NULL
, *d3drm_ds
= NULL
;
2525 DWORD expected_flags
;
2527 GUID driver
= IID_IDirect3DRGBDevice
;
2528 ULONG ref1
, ref2
, surface_ref1
, surface_ref2
;
2530 BOOL use_sysmem_zbuffer
= FALSE
;
2533 hr
= DirectDrawCreate(NULL
, &ddraw
, NULL
);
2534 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2536 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
, 0, 0, 300, 200, 0, 0, 0, 0);
2537 GetClientRect(window
, &rc
);
2539 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2540 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
2542 hr
= Direct3DRMCreate(&d3drm1
);
2543 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
2544 ref1
= get_refcount((IUnknown
*)d3drm1
);
2546 /* Create a surface and use it to create the retained mode device. */
2547 memset(&desc
, 0, sizeof(desc
));
2548 desc
.dwSize
= sizeof(desc
);
2549 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2550 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2551 desc
.dwWidth
= rc
.right
;
2552 desc
.dwHeight
= rc
.bottom
;
2554 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2555 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2557 hr
= IDirect3DRM_CreateDeviceFromSurface(d3drm1
, &driver
, ddraw
, surface
, &device1
);
2558 todo_wine
ok(hr
== DDERR_INVALIDCAPS
, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr
);
2559 IDirectDrawSurface_Release(surface
);
2561 IDirect3DRMDevice_Release(device1
);
2563 desc
.ddsCaps
.dwCaps
|= DDSCAPS_3DDEVICE
;
2564 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2565 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2566 surface_ref1
= get_refcount((IUnknown
*)surface
);
2567 hr
= IDirect3DRM_CreateDeviceFromSurface(d3drm1
, &driver
, ddraw
, surface
, &device1
);
2568 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr
);
2569 ref2
= get_refcount((IUnknown
*)d3drm1
);
2570 todo_wine
ok(ref2
> ref1
, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1
, ref2
);
2571 surface_ref2
= get_refcount((IUnknown
*)surface
);
2572 todo_wine
ok(surface_ref2
> surface_ref1
, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1
, surface_ref2
);
2574 /* Check if CreateDeviceFromSurface creates a primary surface */
2575 hr
= IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2576 NULL
, &d3drm_surface
, surface_callback
);
2577 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
2578 ok(d3drm_surface
== NULL
, "No primary surface should have enumerated (%p).\n", d3drm_surface
);
2580 hr
= IDirect3DRMDevice_GetDirect3DDevice(device1
, &d3ddevice1
);
2581 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr
);
2585 hr
= IDirect3DDevice_QueryInterface(d3ddevice1
, &IID_IDirectDrawSurface
, (void **)&d3drm_surface
);
2586 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2587 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
2589 /* Check properties of attached depth surface */
2590 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &ds
);
2591 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2593 memset(&desc
, 0, sizeof(desc
));
2594 desc
.dwSize
= sizeof(desc
);
2595 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
2596 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
2598 use_sysmem_zbuffer
= desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
2599 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
2600 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
2601 ok(desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
2602 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2603 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
2605 IDirectDrawSurface_Release(ds
);
2606 IDirect3DDevice_Release(d3ddevice1
);
2607 IDirectDrawSurface_Release(d3drm_surface
);
2609 IDirect3DRMDevice_Release(device1
);
2610 ref2
= get_refcount((IUnknown
*)d3drm1
);
2611 ok(ref1
== ref2
, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1
, ref2
);
2612 surface_ref2
= get_refcount((IUnknown
*)surface
);
2613 ok(surface_ref2
== surface_ref1
, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
2614 surface_ref1
, surface_ref2
);
2615 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2616 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2617 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2618 ref1
= IDirectDrawSurface_Release(ds
);
2619 ok(ref1
== 1, "Expected ref1 == 1, got %u.\n", ref1
);
2621 ref1
= IDirectDrawSurface_Release(surface
);
2622 ok(ref1
== 0, "Expected Render target refcount == 0, got %u.\n", ref1
);
2624 memset(&desc
, 0, sizeof(desc
));
2625 desc
.dwSize
= sizeof(desc
);
2626 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2627 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
2628 desc
.dwWidth
= rc
.right
;
2629 desc
.dwHeight
= rc
.bottom
;
2631 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2632 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2634 memset(&desc
, 0, sizeof(desc
));
2635 desc
.dwSize
= sizeof(desc
);
2636 desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
2637 desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
| (use_sysmem_zbuffer
? DDSCAPS_SYSTEMMEMORY
: 0);
2638 desc
.dwZBufferBitDepth
= 16;
2639 desc
.dwWidth
= rc
.right
;
2640 desc
.dwHeight
= rc
.bottom
;
2641 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &ds
, NULL
);
2642 ok(hr
== DD_OK
, "Cannot create depth surface (hr = %x).\n", hr
);
2643 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
2644 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
2646 hr
= IDirect3DRM_CreateDeviceFromSurface(d3drm1
, &driver
, ddraw
, surface
, &device1
);
2647 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr
);
2649 hr
= IDirect3DRMDevice2_GetDirect3DDevice(device1
, &d3ddevice1
);
2650 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr
);
2654 hr
= IDirect3DDevice_QueryInterface(d3ddevice1
, &IID_IDirectDrawSurface
, (void **)&d3drm_surface
);
2655 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2656 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
2658 /* Check if depth surface matches the one we created */
2659 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &d3drm_ds
);
2660 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2661 ok(ds
== d3drm_ds
, "Expected depth surface (%p) == surface created internally (%p).\n", ds
, d3drm_ds
);
2663 IDirectDrawSurface_Release(d3drm_ds
);
2664 IDirectDrawSurface_Release(d3drm_surface
);
2665 IDirectDrawSurface_Release(ds
);
2669 IDirect3DDevice_Release(d3ddevice1
);
2670 IDirect3DRMDevice_Release(device1
);
2671 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2672 todo_wine
ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2675 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2676 ref1
= IDirectDrawSurface_Release(ds
);
2677 ok(ref1
== 1, "Expected ref1 == 1, got %u.\n", ref1
);
2681 ref1
= IDirectDrawSurface_Release(surface
);
2682 ok(ref1
== 0, "Expected Render target refcount == 0, got %u.\n", ref1
);
2685 IDirect3DRM_Release(d3drm1
);
2687 IDirectDraw_Release(ddraw
);
2688 DestroyWindow(window
);
2691 static void test_create_device_from_surface2(void)
2693 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
2695 IDirectDraw
*ddraw
= NULL
;
2696 IDirect3DRM
*d3drm1
= NULL
;
2697 IDirect3DRM2
*d3drm2
= NULL
;
2698 IDirect3DRMDevice2
*device2
= NULL
;
2699 IDirect3DDevice2
*d3ddevice2
= NULL
;
2700 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_surface
= NULL
, *d3drm_ds
= NULL
;
2701 DWORD expected_flags
;
2703 GUID driver
= IID_IDirect3DRGBDevice
;
2704 ULONG ref1
, ref2
, ref3
, surface_ref1
, surface_ref2
;
2706 BOOL use_sysmem_zbuffer
= FALSE
;
2709 hr
= DirectDrawCreate(NULL
, &ddraw
, NULL
);
2710 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2712 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
, 0, 0, 300, 200, 0, 0, 0, 0);
2713 GetClientRect(window
, &rc
);
2715 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2716 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
2718 hr
= Direct3DRMCreate(&d3drm1
);
2719 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
2720 ref1
= get_refcount((IUnknown
*)d3drm1
);
2722 hr
= IDirect3DRM_QueryInterface(d3drm1
, &IID_IDirect3DRM2
, (void **)&d3drm2
);
2723 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr
);
2724 ref2
= get_refcount((IUnknown
*)d3drm2
);
2726 /* Create a surface and use it to create the retained mode device. */
2727 memset(&desc
, 0, sizeof(desc
));
2728 desc
.dwSize
= sizeof(desc
);
2729 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2730 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2731 desc
.dwWidth
= rc
.right
;
2732 desc
.dwHeight
= rc
.bottom
;
2734 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2735 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2737 hr
= IDirect3DRM2_CreateDeviceFromSurface(d3drm2
, &driver
, ddraw
, surface
, &device2
);
2738 todo_wine
ok(hr
== DDERR_INVALIDCAPS
, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr
);
2739 IDirectDrawSurface_Release(surface
);
2741 IDirect3DRMDevice2_Release(device2
);
2743 desc
.ddsCaps
.dwCaps
|= DDSCAPS_3DDEVICE
;
2744 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2745 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2746 surface_ref1
= get_refcount((IUnknown
*)surface
);
2747 hr
= IDirect3DRM2_CreateDeviceFromSurface(d3drm2
, &driver
, ddraw
, surface
, &device2
);
2748 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr
);
2749 ref3
= get_refcount((IUnknown
*)d3drm1
);
2750 todo_wine
ok(ref3
> ref1
, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1
, ref3
);
2751 ref3
= get_refcount((IUnknown
*)d3drm2
);
2752 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2753 surface_ref2
= get_refcount((IUnknown
*)surface
);
2754 todo_wine
ok(surface_ref2
> surface_ref1
, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1
, surface_ref2
);
2756 /* Check if CreateDeviceFromSurface creates a primary surface */
2757 hr
= IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2758 NULL
, &d3drm_surface
, surface_callback
);
2759 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
2760 ok(d3drm_surface
== NULL
, "No primary surface should have enumerated (%p).\n", d3drm_surface
);
2762 hr
= IDirect3DRMDevice2_GetDirect3DDevice2(device2
, &d3ddevice2
);
2763 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
2767 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &d3drm_surface
);
2768 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2769 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
2771 /* Check properties of attached depth surface */
2772 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &ds
);
2773 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2775 memset(&desc
, 0, sizeof(desc
));
2776 desc
.dwSize
= sizeof(desc
);
2777 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
2778 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
2780 use_sysmem_zbuffer
= desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
2781 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
2782 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
2783 ok(desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
2784 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2785 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
2787 IDirectDrawSurface_Release(ds
);
2788 IDirect3DDevice2_Release(d3ddevice2
);
2789 IDirectDrawSurface_Release(d3drm_surface
);
2791 IDirect3DRMDevice2_Release(device2
);
2792 ref3
= get_refcount((IUnknown
*)d3drm1
);
2793 ok(ref1
== ref3
, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1
, ref3
);
2794 ref3
= get_refcount((IUnknown
*)d3drm2
);
2795 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2796 surface_ref2
= get_refcount((IUnknown
*)surface
);
2797 ok(surface_ref2
== surface_ref1
, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
2798 surface_ref1
, surface_ref2
);
2799 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2800 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2801 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2802 ref1
= IDirectDrawSurface_Release(ds
);
2803 ok(ref1
== 1, "Expected ref1 == 1, got %u.\n", ref1
);
2805 ref1
= IDirectDrawSurface_Release(surface
);
2806 ok(ref1
== 0, "Expected Render target refcount == 0, got %u.\n", ref1
);
2808 memset(&desc
, 0, sizeof(desc
));
2809 desc
.dwSize
= sizeof(desc
);
2810 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2811 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
2812 desc
.dwWidth
= rc
.right
;
2813 desc
.dwHeight
= rc
.bottom
;
2815 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2816 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2818 memset(&desc
, 0, sizeof(desc
));
2819 desc
.dwSize
= sizeof(desc
);
2820 desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
2821 desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
| (use_sysmem_zbuffer
? DDSCAPS_SYSTEMMEMORY
: 0);
2822 desc
.dwZBufferBitDepth
= 16;
2823 desc
.dwWidth
= rc
.right
;
2824 desc
.dwHeight
= rc
.bottom
;
2825 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &ds
, NULL
);
2826 ok(hr
== DD_OK
, "Cannot create depth surface (hr = %x).\n", hr
);
2827 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
2828 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
2830 hr
= IDirect3DRM2_CreateDeviceFromSurface(d3drm2
, &driver
, ddraw
, surface
, &device2
);
2831 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr
);
2833 hr
= IDirect3DRMDevice2_GetDirect3DDevice2(device2
, &d3ddevice2
);
2834 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
2838 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &d3drm_surface
);
2839 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2840 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
2842 /* Check if depth surface matches the one we created */
2843 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &d3drm_ds
);
2844 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2845 ok(ds
== d3drm_ds
, "Expected depth surface (%p) == surface created internally (%p).\n", ds
, d3drm_ds
);
2847 IDirectDrawSurface_Release(d3drm_ds
);
2848 IDirectDrawSurface_Release(d3drm_surface
);
2849 IDirectDrawSurface_Release(ds
);
2853 IDirect3DDevice2_Release(d3ddevice2
);
2854 IDirect3DRMDevice2_Release(device2
);
2855 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2856 todo_wine
ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2859 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
2860 ref1
= IDirectDrawSurface_Release(ds
);
2861 ok(ref1
== 1, "Expected ref1 == 1, got %u.\n", ref1
);
2865 ref1
= IDirectDrawSurface_Release(surface
);
2866 ok(ref1
== 0, "Expected Render target refcount == 0, got %u.\n", ref1
);
2869 IDirect3DRM2_Release(d3drm2
);
2871 IDirect3DRM_Release(d3drm1
);
2873 IDirectDraw_Release(ddraw
);
2874 DestroyWindow(window
);
2877 static void test_create_device_from_surface3(void)
2879 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
2881 IDirectDraw
*ddraw
= NULL
;
2882 IDirect3DRM
*d3drm1
= NULL
;
2883 IDirect3DRM3
*d3drm3
= NULL
;
2884 IDirect3DRMDevice3
*device3
= NULL
;
2885 IDirect3DDevice2
*d3ddevice2
= NULL
;
2886 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_surface
= NULL
, *d3drm_ds
= NULL
;
2887 DWORD expected_flags
;
2889 GUID driver
= IID_IDirect3DRGBDevice
;
2890 ULONG ref1
, ref2
, ref3
, surface_ref1
, surface_ref2
;
2892 BOOL use_sysmem_zbuffer
= FALSE
;
2895 hr
= DirectDrawCreate(NULL
, &ddraw
, NULL
);
2896 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
2898 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
, 0, 0, 300, 200, 0, 0, 0, 0);
2899 GetClientRect(window
, &rc
);
2901 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2902 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
2904 hr
= Direct3DRMCreate(&d3drm1
);
2905 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
2906 ref1
= get_refcount((IUnknown
*)d3drm1
);
2908 hr
= IDirect3DRM_QueryInterface(d3drm1
, &IID_IDirect3DRM3
, (void **)&d3drm3
);
2909 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr
);
2910 ref2
= get_refcount((IUnknown
*)d3drm3
);
2912 /* Create a surface and use it to create the retained mode device. */
2913 memset(&desc
, 0, sizeof(desc
));
2914 desc
.dwSize
= sizeof(desc
);
2915 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2916 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2917 desc
.dwWidth
= rc
.right
;
2918 desc
.dwHeight
= rc
.bottom
;
2920 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2921 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2923 hr
= IDirect3DRM3_CreateDeviceFromSurface(d3drm3
, &driver
, ddraw
, surface
, 0, &device3
);
2924 todo_wine
ok(hr
== DDERR_INVALIDCAPS
, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr
);
2925 IDirectDrawSurface_Release(surface
);
2927 IDirect3DRMDevice3_Release(device3
);
2929 desc
.ddsCaps
.dwCaps
|= DDSCAPS_3DDEVICE
;
2930 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
2931 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
2932 surface_ref1
= get_refcount((IUnknown
*)surface
);
2933 hr
= IDirect3DRM3_CreateDeviceFromSurface(d3drm3
, &driver
, ddraw
, surface
, 0, &device3
);
2934 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr
);
2935 ref3
= get_refcount((IUnknown
*)d3drm1
);
2936 todo_wine
ok(ref3
> ref1
, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1
, ref3
);
2937 ref3
= get_refcount((IUnknown
*)d3drm3
);
2938 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2939 surface_ref2
= get_refcount((IUnknown
*)surface
);
2940 todo_wine
ok(surface_ref2
> surface_ref1
, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1
, surface_ref2
);
2942 /* Check if CreateDeviceFromSurface creates a primary surface */
2943 hr
= IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2944 NULL
, &d3drm_surface
, surface_callback
);
2945 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
2946 ok(d3drm_surface
== NULL
, "No primary surface should have enumerated (%p).\n", d3drm_surface
);
2948 hr
= IDirect3DRMDevice3_GetDirect3DDevice2(device3
, &d3ddevice2
);
2949 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
2953 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &d3drm_surface
);
2954 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
2955 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
2957 /* Check properties of attached depth surface */
2958 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &ds
);
2959 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
2961 memset(&desc
, 0, sizeof(desc
));
2962 desc
.dwSize
= sizeof(desc
);
2963 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
2964 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
2966 use_sysmem_zbuffer
= desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
2967 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
2968 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
2969 ok(desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
2970 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
2971 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
2973 IDirectDrawSurface_Release(ds
);
2974 IDirect3DDevice2_Release(d3ddevice2
);
2975 IDirectDrawSurface_Release(d3drm_surface
);
2977 IDirect3DRMDevice3_Release(device3
);
2978 ref3
= get_refcount((IUnknown
*)d3drm1
);
2979 ok(ref1
== ref3
, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1
, ref3
);
2980 ref3
= get_refcount((IUnknown
*)d3drm3
);
2981 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
2982 surface_ref2
= get_refcount((IUnknown
*)surface
);
2983 ok(surface_ref2
== surface_ref1
, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
2984 surface_ref1
, surface_ref2
);
2985 /* In version 3, d3drm will destroy all references of the depth surface it created internally. */
2986 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
2987 todo_wine
ok(hr
== DDERR_NOTFOUND
, "Expected hr == DDERR_NOTFOUND, got %x.\n", hr
);
2989 IDirectDrawSurface_Release(ds
);
2991 ref1
= IDirectDrawSurface_Release(surface
);
2992 ok(ref1
== 0, "Expected Render target refcount == 0, got %u.\n", ref1
);
2994 memset(&desc
, 0, sizeof(desc
));
2995 desc
.dwSize
= sizeof(desc
);
2996 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
2997 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
2998 desc
.dwWidth
= rc
.right
;
2999 desc
.dwHeight
= rc
.bottom
;
3001 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
3002 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3004 memset(&desc
, 0, sizeof(desc
));
3005 desc
.dwSize
= sizeof(desc
);
3006 desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
3007 desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
| (use_sysmem_zbuffer
? DDSCAPS_SYSTEMMEMORY
: 0);
3008 desc
.dwZBufferBitDepth
= 16;
3009 desc
.dwWidth
= rc
.right
;
3010 desc
.dwHeight
= rc
.bottom
;
3011 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &ds
, NULL
);
3012 ok(hr
== DD_OK
, "Cannot create depth surface (hr = %x).\n", hr
);
3013 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
3014 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
3016 hr
= IDirect3DRM3_CreateDeviceFromSurface(d3drm3
, &driver
, ddraw
, surface
, D3DRMDEVICE_NOZBUFFER
, &device3
);
3017 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr
);
3019 hr
= IDirect3DRMDevice3_GetDirect3DDevice2(device3
, &d3ddevice2
);
3020 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
3024 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &d3drm_surface
);
3025 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
3026 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
3028 /* Check if depth surface matches the one we created */
3029 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &d3drm_ds
);
3030 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
3031 ok(ds
== d3drm_ds
, "Expected depth surface (%p) == surface created internally (%p).\n", ds
, d3drm_ds
);
3033 IDirectDrawSurface_Release(d3drm_ds
);
3034 IDirectDrawSurface_Release(d3drm_surface
);
3035 IDirectDrawSurface_Release(ds
);
3036 IDirect3DDevice2_Release(d3ddevice2
);
3037 IDirect3DRMDevice3_Release(device3
);
3038 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
3039 todo_wine
ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
3042 /* The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3043 ref1
= IDirectDrawSurface_Release(ds
);
3044 ok(ref1
== 1, "Expected ref1 == 1, got %u.\n", ref1
);
3047 /* What happens if we pass no flags and still attach our own depth surface? */
3048 hr
= IDirect3DRM3_CreateDeviceFromSurface(d3drm3
, &driver
, ddraw
, surface
, 0, &device3
);
3049 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr
);
3051 hr
= IDirect3DRMDevice3_GetDirect3DDevice2(device3
, &d3ddevice2
);
3052 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
3056 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &d3drm_surface
);
3057 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
3058 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
3060 /* Check if depth surface matches the one we created */
3061 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &d3drm_ds
);
3062 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
3063 ok(ds
== d3drm_ds
, "Expected depth surface (%p) == surface created internally (%p).\n", ds
, d3drm_ds
);
3065 IDirectDrawSurface_Release(d3drm_ds
);
3066 IDirectDrawSurface_Release(d3drm_surface
);
3067 IDirect3DDevice2_Release(d3ddevice2
);
3068 IDirect3DRMDevice3_Release(device3
);
3069 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &ds
);
3070 todo_wine
ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
3073 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3074 ref1
= IDirectDrawSurface_Release(ds
);
3075 ok(ref1
== 1, "Expected ref1 == 1, got %u.\n", ref1
);
3077 ref1
= IDirectDrawSurface_Release(surface
);
3078 ok(ref1
== 0, "Expected Render target refcount == 0, got %u.\n", ref1
);
3080 memset(&desc
, 0, sizeof(desc
));
3081 desc
.dwSize
= sizeof(desc
);
3082 desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3083 desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
3084 desc
.dwWidth
= rc
.right
;
3085 desc
.dwHeight
= rc
.bottom
;
3087 hr
= IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
);
3088 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3090 /* What happens if we don't pass D3DRMDEVICE_NOZBUFFER and still not attach our own depth surface? */
3091 hr
= IDirect3DRM3_CreateDeviceFromSurface(d3drm3
, &driver
, ddraw
, surface
, D3DRMDEVICE_NOZBUFFER
, &device3
);
3092 ok(SUCCEEDED(hr
), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr
);
3094 hr
= IDirect3DRMDevice3_GetDirect3DDevice2(device3
, &d3ddevice2
);
3095 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
3099 hr
= IDirect3DDevice2_GetRenderTarget(d3ddevice2
, &d3drm_surface
);
3100 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
3101 ok(surface
== d3drm_surface
, "Expected surface returned == %p, got %p.\n", surface
, d3drm_surface
);
3103 /* Check if depth surface matches the one we created */
3104 hr
= IDirectDrawSurface_GetAttachedSurface(d3drm_surface
, &caps
, &d3drm_ds
);
3105 ok(hr
== DDERR_NOTFOUND
, "Expected hr == DDERR_NOTFOUND, got %x).\n", hr
);
3106 IDirectDrawSurface_Release(d3drm_surface
);
3110 IDirect3DDevice2_Release(d3ddevice2
);
3111 IDirect3DRMDevice3_Release(device3
);
3114 ref1
= IDirectDrawSurface_Release(surface
);
3115 ok(ref1
== 0, "Expected Render target refcount == 0, got %u.\n", ref1
);
3118 IDirect3DRM3_Release(d3drm3
);
3120 IDirect3DRM_Release(d3drm1
);
3122 IDirectDraw_Release(ddraw
);
3123 DestroyWindow(window
);
3126 static IDirect3DDevice
*create_device1(IDirectDraw
*ddraw
, HWND window
, IDirectDrawSurface
**ds
)
3128 static const DWORD z_depths
[] = { 32, 24, 16 };
3129 IDirectDrawSurface
*surface
;
3130 IDirect3DDevice
*device
= NULL
;
3131 DDSURFACEDESC surface_desc
;
3136 GetClientRect(window
, &rc
);
3137 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3138 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3140 memset(&surface_desc
, 0, sizeof(surface_desc
));
3141 surface_desc
.dwSize
= sizeof(surface_desc
);
3142 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3143 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
3144 surface_desc
.dwWidth
= rc
.right
;
3145 surface_desc
.dwHeight
= rc
.bottom
;
3147 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
3148 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3150 /* We used to use EnumDevices() for this, but it seems
3151 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
3152 * relationship with reality. */
3153 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
3155 memset(&surface_desc
, 0, sizeof(surface_desc
));
3156 surface_desc
.dwSize
= sizeof(surface_desc
);
3157 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
3158 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
3159 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
3160 surface_desc
.dwWidth
= rc
.right
;
3161 surface_desc
.dwHeight
= rc
.bottom
;
3162 if (FAILED(IDirectDraw_CreateSurface(ddraw
, &surface_desc
, ds
, NULL
)))
3165 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, *ds
);
3166 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
3169 IDirectDrawSurface_Release(*ds
);
3173 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
)))
3176 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, *ds
);
3177 IDirectDrawSurface_Release(*ds
);
3181 IDirectDrawSurface_Release(surface
);
3185 static void test_create_device_from_d3d1(void)
3187 IDirectDraw
*ddraw1
= NULL
;
3188 IDirect3D
*d3d1
= NULL
;
3189 IDirect3DRM
*d3drm1
= NULL
;
3190 IDirect3DRMDevice
*device1
= NULL
;
3191 IDirect3DDevice
*d3ddevice1
= NULL
, *d3drm_d3ddevice1
= NULL
;
3192 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_ds
= NULL
;
3193 DWORD expected_flags
;
3194 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
3198 ULONG ref1
, ref2
, device_ref1
, device_ref2
;
3201 hr
= DirectDrawCreate(NULL
, &ddraw1
, NULL
);
3202 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
3204 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
, 0, 0, 300, 200, 0, 0, 0, 0);
3205 GetClientRect(window
, &rc
);
3207 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirect3D
, (void **)&d3d1
);
3208 ok(hr
== DD_OK
, "Cannot get IDirect3D2 interface (hr = %x).\n", hr
);
3210 /* Create the immediate mode device */
3211 d3ddevice1
= create_device1(ddraw1
, window
, &ds
);
3212 if (d3ddevice1
== NULL
)
3214 win_skip("Cannot create IM device, skipping tests.\n");
3215 IDirect3D_Release(d3d1
);
3216 IDirectDraw_Release(ddraw1
);
3219 device_ref1
= get_refcount((IUnknown
*)d3ddevice1
);
3221 hr
= Direct3DRMCreate(&d3drm1
);
3222 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
3223 ref1
= get_refcount((IUnknown
*)d3drm1
);
3226 hr
= IDirect3DRM_CreateDeviceFromD3D(d3drm1
, d3d1
, d3ddevice1
, &device1
);
3227 ok(hr
== DD_OK
, "Failed to create IDirect3DRMDevice interface (hr = %x)\n", hr
);
3228 ref2
= get_refcount((IUnknown
*)d3drm1
);
3229 todo_wine
ok(ref2
> ref1
, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1
, ref2
);
3230 device_ref2
= get_refcount((IUnknown
*)d3ddevice1
);
3231 todo_wine
ok(device_ref2
> device_ref1
, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1
, device_ref2
);
3233 hr
= IDirectDraw_EnumSurfaces(ddraw1
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
3234 NULL
, &surface
, surface_callback
);
3235 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
3236 ok(surface
== NULL
, "No primary surface should have enumerated (%p).\n", surface
);
3238 hr
= IDirect3DRMDevice_GetDirect3DDevice(device1
, &d3drm_d3ddevice1
);
3239 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr
);
3242 ok(d3ddevice1
== d3drm_d3ddevice1
, "Expected Immediate Mode deivce created == %p, got %p.\n", d3ddevice1
, d3drm_d3ddevice1
);
3244 /* Check properties of render target and depth surfaces */
3245 hr
= IDirect3DDevice_QueryInterface(d3drm_d3ddevice1
, &IID_IDirectDrawSurface
, (void **)&surface
);
3246 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
3248 memset(&desc
, 0, sizeof(desc
));
3249 desc
.dwSize
= sizeof(desc
);
3250 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &desc
);
3251 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
3253 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3254 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
3255 ok((desc
.ddsCaps
.dwCaps
& (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
)) == (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
),
3256 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
, desc
.ddsCaps
.dwCaps
);
3257 expected_flags
= DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
3258 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
3260 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &d3drm_ds
);
3261 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
3262 ok(ds
== d3drm_ds
, "Expected depth surface (%p) == surface created internally (%p).\n", ds
, d3drm_ds
);
3264 desc
.dwSize
= sizeof(desc
);
3265 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
3266 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
3268 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3269 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
3270 ok((desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) == DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
3271 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
3272 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
3274 IDirectDrawSurface_Release(d3drm_ds
);
3275 IDirectDrawSurface_Release(ds
);
3277 IDirectDrawSurface_Release(surface
);
3278 IDirect3DDevice_Release(d3drm_d3ddevice1
);
3281 IDirectDrawSurface_Release(ds
);
3283 IDirect3DRMDevice_Release(device1
);
3284 ref2
= get_refcount((IUnknown
*)d3drm1
);
3285 ok(ref1
== ref2
, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1
, ref2
);
3286 device_ref2
= get_refcount((IUnknown
*)d3ddevice1
);
3287 ok(device_ref2
== device_ref1
, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1
, device_ref2
);
3289 IDirect3DRM_Release(d3drm1
);
3290 IDirect3DDevice_Release(d3ddevice1
);
3291 IDirect3D_Release(d3d1
);
3292 IDirectDraw_Release(ddraw1
);
3293 DestroyWindow(window
);
3296 static IDirect3DDevice2
*create_device2(IDirectDraw2
*ddraw
, HWND window
, IDirectDrawSurface
**ds
)
3298 static const DWORD z_depths
[] = { 32, 24, 16 };
3299 IDirectDrawSurface
*surface
;
3300 IDirect3DDevice2
*device
= NULL
;
3301 DDSURFACEDESC surface_desc
;
3307 GetClientRect(window
, &rc
);
3308 hr
= IDirectDraw2_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3309 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3311 memset(&surface_desc
, 0, sizeof(surface_desc
));
3312 surface_desc
.dwSize
= sizeof(surface_desc
);
3313 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3314 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
3315 surface_desc
.dwWidth
= rc
.right
;
3316 surface_desc
.dwHeight
= rc
.bottom
;
3318 hr
= IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
3319 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3321 hr
= IDirectDraw2_QueryInterface(ddraw
, &IID_IDirect3D2
, (void **)&d3d
);
3324 IDirectDrawSurface_Release(surface
);
3329 /* We used to use EnumDevices() for this, but it seems
3330 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
3331 * relationship with reality. */
3332 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
3334 memset(&surface_desc
, 0, sizeof(surface_desc
));
3335 surface_desc
.dwSize
= sizeof(surface_desc
);
3336 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
3337 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
3338 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
3339 surface_desc
.dwWidth
= rc
.right
;
3340 surface_desc
.dwHeight
= rc
.bottom
;
3341 if (FAILED(IDirectDraw2_CreateSurface(ddraw
, &surface_desc
, ds
, NULL
)))
3344 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, *ds
);
3345 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
3348 IDirectDrawSurface_Release(*ds
);
3352 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, surface
, &device
)))
3355 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, *ds
);
3356 IDirectDrawSurface_Release(*ds
);
3360 IDirect3D2_Release(d3d
);
3361 IDirectDrawSurface_Release(surface
);
3365 static void test_create_device_from_d3d2(void)
3367 IDirectDraw
*ddraw1
= NULL
;
3368 IDirectDraw2
*ddraw2
= NULL
;
3369 IDirect3D2
*d3d2
= NULL
;
3370 IDirect3DRM
*d3drm1
= NULL
;
3371 IDirect3DRM2
*d3drm2
= NULL
;
3372 IDirect3DRMDevice2
*device2
= NULL
;
3373 IDirect3DDevice2
*d3ddevice2
= NULL
, *d3drm_d3ddevice2
= NULL
;
3374 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_ds
= NULL
;
3375 DWORD expected_flags
;
3376 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
3380 ULONG ref1
, ref2
, ref3
, device_ref1
, device_ref2
;
3383 hr
= DirectDrawCreate(NULL
, &ddraw1
, NULL
);
3384 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
3386 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
, 0, 0, 300, 200, 0, 0, 0, 0);
3387 GetClientRect(window
, &rc
);
3389 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirect3D2
, (void **)&d3d2
);
3390 ok(hr
== DD_OK
, "Cannot get IDirect3D2 interface (hr = %x).\n", hr
);
3391 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw2
, (void **)&ddraw2
);
3392 ok(hr
== DD_OK
, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr
);
3394 /* Create the immediate mode device */
3395 d3ddevice2
= create_device2(ddraw2
, window
, &ds
);
3396 if (d3ddevice2
== NULL
)
3398 win_skip("Cannot create IM device, skipping tests.\n");
3399 IDirect3D2_Release(d3d2
);
3400 IDirectDraw2_Release(ddraw2
);
3401 IDirectDraw_Release(ddraw1
);
3404 device_ref1
= get_refcount((IUnknown
*)d3ddevice2
);
3406 hr
= Direct3DRMCreate(&d3drm1
);
3407 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
3408 ref1
= get_refcount((IUnknown
*)d3drm1
);
3410 hr
= IDirect3DRM_QueryInterface(d3drm1
, &IID_IDirect3DRM2
, (void **)&d3drm2
);
3411 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr
);
3412 ref2
= get_refcount((IUnknown
*)d3drm2
);
3414 hr
= IDirect3DRM2_CreateDeviceFromD3D(d3drm2
, d3d2
, d3ddevice2
, &device2
);
3415 ok(hr
== DD_OK
, "Failed to create IDirect3DRMDevice2 interface (hr = %x)\n", hr
);
3416 ref3
= get_refcount((IUnknown
*)d3drm1
);
3417 todo_wine
ok(ref3
> ref1
, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1
, ref3
);
3418 ref3
= get_refcount((IUnknown
*)d3drm2
);
3419 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
3420 device_ref2
= get_refcount((IUnknown
*)d3ddevice2
);
3421 todo_wine
ok(device_ref2
> device_ref1
, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1
, device_ref2
);
3423 hr
= IDirectDraw_EnumSurfaces(ddraw1
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
3424 NULL
, &surface
, surface_callback
);
3425 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
3426 ok(surface
== NULL
, "No primary surface should have enumerated (%p).\n", surface
);
3428 hr
= IDirect3DRMDevice2_GetDirect3DDevice2(device2
, &d3drm_d3ddevice2
);
3429 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
3432 ok(d3ddevice2
== d3drm_d3ddevice2
, "Expected Immediate Mode deivce created == %p, got %p.\n", d3ddevice2
, d3drm_d3ddevice2
);
3434 /* Check properties of render target and depth surfaces */
3435 hr
= IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2
, &surface
);
3436 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
3438 memset(&desc
, 0, sizeof(desc
));
3439 desc
.dwSize
= sizeof(desc
);
3440 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &desc
);
3441 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
3443 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3444 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
3445 ok((desc
.ddsCaps
.dwCaps
& (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
)) == (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
),
3446 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
, desc
.ddsCaps
.dwCaps
);
3447 expected_flags
= DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
3448 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
3450 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &d3drm_ds
);
3451 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
3452 ok(ds
== d3drm_ds
, "Expected depth surface (%p) == surface created internally (%p).\n", ds
, d3drm_ds
);
3454 desc
.dwSize
= sizeof(desc
);
3455 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
3456 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
3458 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3459 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
3460 ok((desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) == DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
3461 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
3462 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
3464 IDirectDrawSurface_Release(d3drm_ds
);
3465 IDirectDrawSurface_Release(ds
);
3467 IDirectDrawSurface_Release(surface
);
3468 IDirect3DDevice2_Release(d3drm_d3ddevice2
);
3471 IDirectDrawSurface_Release(ds
);
3473 IDirect3DRMDevice2_Release(device2
);
3474 ref3
= get_refcount((IUnknown
*)d3drm1
);
3475 ok(ref1
== ref3
, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1
, ref3
);
3476 ref3
= get_refcount((IUnknown
*)d3drm2
);
3477 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
3478 device_ref2
= get_refcount((IUnknown
*)d3ddevice2
);
3479 ok(device_ref2
== device_ref1
, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1
, device_ref2
);
3481 IDirect3DRM2_Release(d3drm2
);
3482 IDirect3DRM_Release(d3drm1
);
3483 IDirect3DDevice2_Release(d3ddevice2
);
3484 IDirect3D2_Release(d3d2
);
3485 IDirectDraw2_Release(ddraw2
);
3486 IDirectDraw_Release(ddraw1
);
3487 DestroyWindow(window
);
3490 static void test_create_device_from_d3d3(void)
3492 IDirectDraw
*ddraw1
= NULL
;
3493 IDirectDraw2
*ddraw2
= NULL
;
3494 IDirect3D2
*d3d2
= NULL
;
3495 IDirect3DRM
*d3drm1
= NULL
;
3496 IDirect3DRM3
*d3drm3
= NULL
;
3497 IDirect3DRMDevice3
*device3
= NULL
;
3498 IDirect3DDevice2
*d3ddevice2
= NULL
, *d3drm_d3ddevice2
= NULL
;
3499 IDirectDrawSurface
*surface
= NULL
, *ds
= NULL
, *d3drm_ds
= NULL
;
3500 DWORD expected_flags
;
3501 DDSCAPS caps
= { DDSCAPS_ZBUFFER
};
3505 ULONG ref1
, ref2
, ref3
, device_ref1
, device_ref2
;
3508 hr
= DirectDrawCreate(NULL
, &ddraw1
, NULL
);
3509 ok(hr
== DD_OK
, "Cannot get IDirectDraw interface (hr = %x).\n", hr
);
3511 window
= CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW
, 0, 0, 300, 200, 0, 0, 0, 0);
3512 GetClientRect(window
, &rc
);
3514 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirect3D2
, (void **)&d3d2
);
3515 ok(hr
== DD_OK
, "Cannot get IDirect3D2 interface (hr = %x).\n", hr
);
3516 hr
= IDirectDraw_QueryInterface(ddraw1
, &IID_IDirectDraw2
, (void **)&ddraw2
);
3517 ok(hr
== DD_OK
, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr
);
3519 /* Create the immediate mode device */
3520 d3ddevice2
= create_device2(ddraw2
, window
, &ds
);
3521 if (d3ddevice2
== NULL
)
3523 win_skip("Cannot create IM device, skipping tests.\n");
3524 IDirect3D2_Release(d3d2
);
3525 IDirectDraw2_Release(ddraw2
);
3526 IDirectDraw_Release(ddraw1
);
3529 device_ref1
= get_refcount((IUnknown
*)d3ddevice2
);
3531 hr
= Direct3DRMCreate(&d3drm1
);
3532 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM interface (hr = %x).\n", hr
);
3533 ref1
= get_refcount((IUnknown
*)d3drm1
);
3535 hr
= IDirect3DRM_QueryInterface(d3drm1
, &IID_IDirect3DRM3
, (void **)&d3drm3
);
3536 ok(hr
== D3DRM_OK
, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr
);
3537 ref2
= get_refcount((IUnknown
*)d3drm3
);
3539 hr
= IDirect3DRM3_CreateDeviceFromD3D(d3drm3
, d3d2
, d3ddevice2
, &device3
);
3540 ok(hr
== DD_OK
, "Failed to create IDirect3DRMDevice3 interface (hr = %x)\n", hr
);
3541 ref3
= get_refcount((IUnknown
*)d3drm1
);
3542 todo_wine
ok(ref3
> ref1
, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1
, ref3
);
3543 ref3
= get_refcount((IUnknown
*)d3drm3
);
3544 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
3545 device_ref2
= get_refcount((IUnknown
*)d3ddevice2
);
3546 todo_wine
ok(device_ref2
> device_ref1
, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1
, device_ref2
);
3548 hr
= IDirectDraw_EnumSurfaces(ddraw1
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
3549 NULL
, &surface
, surface_callback
);
3550 ok(hr
== DD_OK
, "Failed to enumerate surfaces (hr = %x).\n", hr
);
3551 ok(surface
== NULL
, "No primary surface should have enumerated (%p).\n", surface
);
3553 hr
= IDirect3DRMDevice3_GetDirect3DDevice2(device3
, &d3drm_d3ddevice2
);
3554 todo_wine
ok(hr
== D3DRM_OK
, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr
);
3557 ok(d3ddevice2
== d3drm_d3ddevice2
, "Expected Immediate Mode deivce created == %p, got %p.\n", d3ddevice2
, d3drm_d3ddevice2
);
3559 /* Check properties of render target and depth surfaces */
3560 hr
= IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2
, &surface
);
3561 ok(hr
== DD_OK
, "Cannot get surface to the render target (hr = %x).\n", hr
);
3563 memset(&desc
, 0, sizeof(desc
));
3564 desc
.dwSize
= sizeof(desc
);
3565 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &desc
);
3566 ok(hr
== DD_OK
, "Cannot get surface desc structure (hr = %x).\n", hr
);
3568 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3569 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
3570 ok((desc
.ddsCaps
.dwCaps
& (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
)) == (DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
),
3571 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
, desc
.ddsCaps
.dwCaps
);
3572 expected_flags
= DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
3573 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
3575 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &d3drm_ds
);
3576 ok(hr
== DD_OK
, "Cannot get attached depth surface (hr = %x).\n", hr
);
3577 ok(ds
== d3drm_ds
, "Expected depth surface (%p) == surface created internally (%p).\n", ds
, d3drm_ds
);
3579 desc
.dwSize
= sizeof(desc
);
3580 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
3581 ok(hr
== DD_OK
, "Cannot get z surface desc structure (hr = %x).\n", hr
);
3583 ok((desc
.dwWidth
== rc
.right
) && (desc
.dwHeight
== rc
.bottom
), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3584 rc
.right
, rc
.bottom
, desc
.dwWidth
, desc
.dwHeight
);
3585 ok((desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) == DDSCAPS_ZBUFFER
, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER
, desc
.ddsCaps
.dwCaps
);
3586 expected_flags
= DDSD_ZBUFFERBITDEPTH
| DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
;
3587 ok(desc
.dwFlags
== expected_flags
, "Expected %x for flags, got %x.\n", expected_flags
, desc
.dwFlags
);
3589 IDirectDrawSurface_Release(d3drm_ds
);
3590 IDirectDrawSurface_Release(ds
);
3592 IDirectDrawSurface_Release(surface
);
3593 IDirect3DDevice2_Release(d3drm_d3ddevice2
);
3596 IDirectDrawSurface_Release(ds
);
3598 IDirect3DRMDevice3_Release(device3
);
3599 ref3
= get_refcount((IUnknown
*)d3drm1
);
3600 ok(ref1
== ref3
, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1
, ref3
);
3601 ref3
= get_refcount((IUnknown
*)d3drm3
);
3602 ok(ref3
== ref2
, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2
, ref3
);
3603 device_ref2
= get_refcount((IUnknown
*)d3ddevice2
);
3604 ok(device_ref2
== device_ref1
, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1
, device_ref2
);
3606 IDirect3DRM3_Release(d3drm3
);
3607 IDirect3DRM_Release(d3drm1
);
3608 IDirect3DDevice2_Release(d3ddevice2
);
3609 IDirect3D2_Release(d3d2
);
3610 IDirectDraw2_Release(ddraw2
);
3611 IDirectDraw_Release(ddraw1
);
3612 DestroyWindow(window
);
3618 test_MeshBuilder3();
3627 test_frame_transform();
3629 test_frame_mesh_materials();
3632 test_create_device_from_clipper1();
3633 test_create_device_from_clipper2();
3634 test_create_device_from_clipper3();
3635 test_create_device_from_surface1();
3636 test_create_device_from_surface2();
3637 test_create_device_from_surface3();
3638 test_create_device_from_d3d1();
3639 test_create_device_from_d3d2();
3640 test_create_device_from_d3d3();