ddraw/tests: Add a helper function to create a viewport.

This commit is contained in:
Henri Verbeet 2012-03-26 20:28:08 +02:00 committed by Alexandre Julliard
parent a57368243f
commit 02b6e04a76
3 changed files with 161 additions and 320 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011 Henri Verbeet for CodeWeavers
* Copyright 2011-2012 Henri Verbeet for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -297,6 +297,47 @@ static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coo
return device;
}
static IDirect3DViewport *create_viewport(IDirect3DDevice *device, UINT x, UINT y, UINT w, UINT h)
{
IDirect3DViewport *viewport;
D3DVIEWPORT vp;
IDirect3D *d3d;
HRESULT hr;
hr = IDirect3DDevice_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = x;
vp.dwY = y;
vp.dwWidth = w;
vp.dwHeight = h;
vp.dvScaleX = (float)w / 2.0f;
vp.dvScaleY = (float)h / 2.0f;
vp.dvMaxX = 1.0f;
vp.dvMaxY = 1.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport_SetViewport(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
IDirect3D_Release(d3d);
return viewport;
}
static void destroy_viewport(IDirect3DDevice *device, IDirect3DViewport *viewport)
{
HRESULT hr;
hr = IDirect3DDevice_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport_Release(viewport);
}
static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
{
HRESULT hr = IDirectDrawSurface_Restore(surface);
@ -618,7 +659,6 @@ static void test_coop_level_d3d_state(void)
IDirect3DDevice *device;
D3DMATERIAL material;
IDirectDraw *ddraw;
D3DVIEWPORT vp;
IDirect3D *d3d;
D3DCOLOR color;
HWND window;
@ -642,28 +682,11 @@ static void test_coop_level_d3d_state(void)
hr = IDirect3DDevice_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
IDirect3D_Release(d3d);
hr = IDirect3DDevice_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvScaleX = 320.0f;
vp.dvScaleY = 240.0f;
vp.dvMaxX = 1.0f;
vp.dvMaxY = 1.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport_SetViewport(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
memset(&material, 0, sizeof(material));
material.dwSize = sizeof(material);
@ -709,10 +732,8 @@ static void test_coop_level_d3d_state(void)
color = get_surface_color(rt, 320, 240);
ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
destroy_viewport(device, viewport);
IDirect3DMaterial_Release(background);
IDirect3DViewport_Release(viewport);
IDirectDrawSurface_Release(surface);
IDirectDrawSurface_Release(rt);
IDirect3DDevice_Release(device);
@ -735,7 +756,6 @@ static void test_surface_interface_mismatch(void)
HRESULT hr;
D3DCOLOR color;
HWND window;
D3DVIEWPORT vp;
D3DMATERIAL material;
D3DMATERIALHANDLE background_handle;
D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
@ -809,27 +829,10 @@ static void test_surface_interface_mismatch(void)
if (FAILED(hr))
goto cleanup;
hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
hr = IDirect3DDevice_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvScaleX = 320.0f;
vp.dvScaleY = 240.0f;
vp.dvMaxX = 1.0f;
vp.dvMaxY = 1.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport_SetViewport(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
memset(&material, 0, sizeof(material));
material.dwSize = sizeof(material);
@ -851,10 +854,7 @@ static void test_surface_interface_mismatch(void)
cleanup:
if (viewport)
{
IDirect3DDevice_DeleteViewport(device, viewport);
IDirect3DViewport_Release(viewport);
}
destroy_viewport(device, viewport);
if (background) IDirect3DMaterial_Release(background);
if (surface3) IDirectDrawSurface3_Release(surface3);
if (surface) IDirectDrawSurface_Release(surface);
@ -997,7 +997,6 @@ static void test_zenable(void)
D3DMATERIAL material;
IDirectDraw *ddraw;
UINT inst_length;
D3DVIEWPORT vp;
IDirect3D *d3d;
D3DCOLOR color;
HWND window;
@ -1026,25 +1025,8 @@ static void test_zenable(void)
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvScaleX = 320.0f;
vp.dvScaleY = 240.0f;
vp.dvMaxX = 1.0f;
vp.dvMaxY = 1.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport_SetViewport(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
memset(&material, 0, sizeof(material));
material.dwSize = sizeof(material);
@ -1112,9 +1094,9 @@ static void test_zenable(void)
}
IDirectDrawSurface_Release(rt);
destroy_viewport(device, viewport);
IDirect3DExecuteBuffer_Release(execute_buffer);
IDirect3DMaterial_Release(background);
IDirect3DViewport_Release(viewport);
IDirect3D_Release(d3d);
IDirect3DDevice_Release(device);
IDirectDraw_Release(ddraw);
@ -1168,7 +1150,6 @@ static void test_ck_rgba(void)
IDirectDrawSurface *rt;
D3DMATERIAL material;
IDirectDraw *ddraw;
D3DVIEWPORT vp;
IDirect3D *d3d;
D3DCOLOR color;
HWND window;
@ -1194,24 +1175,7 @@ static void test_ck_rgba(void)
hr = IDirect3DDevice_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvScaleX = 320.0f;
vp.dvScaleY = 240.0f;
vp.dvMaxX = 1.0f;
vp.dvMaxY = 1.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport_SetViewport(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
@ -1352,10 +1316,8 @@ static void test_ck_rgba(void)
IDirectDrawSurface_Release(rt);
IDirect3DExecuteBuffer_Release(execute_buffer);
IDirectDrawSurface_Release(surface);
destroy_viewport(device, viewport);
IDirect3DMaterial_Release(background);
hr = IDirect3DDevice_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport_Release(viewport);
IDirect3DDevice_Release(device);
IDirectDraw_Release(ddraw);
DestroyWindow(window);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011 Henri Verbeet for CodeWeavers
* Copyright 2011-2012 Henri Verbeet for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -253,6 +253,47 @@ static IDirect3DDevice2 *create_device(IDirectDraw2 *ddraw, HWND window, DWORD c
return device;
}
static IDirect3DViewport2 *create_viewport(IDirect3DDevice2 *device, UINT x, UINT y, UINT w, UINT h)
{
IDirect3DViewport2 *viewport;
D3DVIEWPORT2 vp;
IDirect3D2 *d3d;
HRESULT hr;
hr = IDirect3DDevice2_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D2_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice2_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = x;
vp.dwY = y;
vp.dwWidth = w;
vp.dwHeight = h;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport2_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
IDirect3D2_Release(d3d);
return viewport;
}
static void destroy_viewport(IDirect3DDevice2 *device, IDirect3DViewport2 *viewport)
{
HRESULT hr;
hr = IDirect3DDevice2_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport2_Release(viewport);
}
static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
{
HRESULT hr = IDirectDrawSurface_Restore(surface);
@ -574,7 +615,6 @@ static void test_coop_level_d3d_state(void)
IDirect3DDevice2 *device;
D3DMATERIAL material;
IDirectDraw2 *ddraw;
D3DVIEWPORT2 vp;
IDirect3D2 *d3d;
D3DCOLOR color;
DWORD value;
@ -599,28 +639,11 @@ static void test_coop_level_d3d_state(void)
hr = IDirect3DDevice2_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D2_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3D2_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
IDirect3D2_Release(d3d);
hr = IDirect3DDevice2_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport2_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
memset(&material, 0, sizeof(material));
material.dwSize = sizeof(material);
@ -680,10 +703,8 @@ static void test_coop_level_d3d_state(void)
color = get_surface_color(rt, 320, 240);
ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice2_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
destroy_viewport(device, viewport);
IDirect3DMaterial2_Release(background);
IDirect3DViewport2_Release(viewport);
IDirectDrawSurface_Release(surface);
IDirectDrawSurface_Release(rt);
IDirect3DDevice2_Release(device);
@ -706,7 +727,6 @@ static void test_surface_interface_mismatch(void)
HRESULT hr;
D3DCOLOR color;
HWND window;
D3DVIEWPORT2 vp;
D3DMATERIAL material;
D3DMATERIALHANDLE background_handle;
D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
@ -780,27 +800,10 @@ static void test_surface_interface_mismatch(void)
if (FAILED(hr))
goto cleanup;
hr = IDirect3D2_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3D2_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
hr = IDirect3DDevice2_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport2_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
memset(&material, 0, sizeof(material));
material.dwSize = sizeof(material);
@ -822,10 +825,7 @@ static void test_surface_interface_mismatch(void)
cleanup:
if (viewport)
{
IDirect3DDevice2_DeleteViewport(device, viewport);
IDirect3DViewport2_Release(viewport);
}
destroy_viewport(device, viewport);
if (background) IDirect3DMaterial2_Release(background);
if (surface3) IDirectDrawSurface3_Release(surface3);
if (surface) IDirectDrawSurface_Release(surface);
@ -883,7 +883,6 @@ static void test_depth_blit(void)
IDirect3DDevice2 *device;
IDirectDrawSurface *ds1, *ds2, *ds3, *rt;
IDirect3DViewport2 *viewport;
D3DVIEWPORT2 vp_data;
RECT src_rect, dst_rect;
unsigned int i, j;
D3DCOLOR color;
@ -915,8 +914,6 @@ static void test_depth_blit(void)
hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
ok(SUCCEEDED(hr), "Failed to get Direct3D2 interface, hr %#x.\n", hr);
hr = IDirect3D2_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create a viewport, hr %#x.\n", hr);
hr = IDirect3D2_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create a material, hr %#x.\n", hr);
@ -937,19 +934,7 @@ static void test_depth_blit(void)
hr = IDirectDraw2_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
hr = IDirect3DDevice2_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
memset(&vp_data, 0, sizeof(vp_data));
vp_data.dwSize = sizeof(vp_data);
vp_data.dwWidth = ddsd_existing.dwWidth;
vp_data.dwHeight = ddsd_existing.dwHeight;
vp_data.dvMaxZ = 1.0;
vp_data.dvClipX = -1.0f;
vp_data.dvClipWidth = 2.0f;
vp_data.dvClipY = 1.0f;
vp_data.dvClipHeight = 2.0f;
hr = IDirect3DViewport2_SetViewport2(viewport, &vp_data);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, ddsd_existing.dwWidth, ddsd_existing.dwHeight);
hr = IDirect3DDevice2_SetCurrentViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
@ -972,7 +957,7 @@ static void test_depth_blit(void)
ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
U1(d3drect).x1 = U2(d3drect).y1 = 0;
U3(d3drect).x2 = vp_data.dwWidth; U4(d3drect).y2 = vp_data.dwHeight;
U3(d3drect).x2 = ddsd_existing.dwWidth; U4(d3drect).y2 = ddsd_existing.dwHeight;
hr = IDirect3DViewport2_Clear(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER);
ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
@ -1069,10 +1054,8 @@ static void test_depth_blit(void)
}
IDirectDrawSurface_Release(rt);
hr = IDirect3DDevice2_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr);
destroy_viewport(device, viewport);
IDirect3DMaterial2_Release(background);
IDirect3DViewport2_Release(viewport);
IDirect3D2_Release(d3d);
IDirect3DDevice2_Release(device);
IDirectDraw2_Release(ddraw);
@ -1283,7 +1266,6 @@ static void test_zenable(void)
IDirectDrawSurface *rt;
D3DMATERIAL material;
IDirectDraw2 *ddraw;
D3DVIEWPORT2 vp;
IDirect3D2 *d3d;
D3DCOLOR color;
HWND window;
@ -1311,25 +1293,8 @@ static void test_zenable(void)
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D2_CreateMaterial(d3d, &background, NULL);
ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
hr = IDirect3D2_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice2_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport2_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
hr = IDirect3DDevice2_SetCurrentViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
@ -1373,10 +1338,8 @@ static void test_zenable(void)
}
IDirectDrawSurface_Release(rt);
destroy_viewport(device, viewport);
IDirect3DMaterial2_Release(background);
hr = IDirect3DDevice2_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport2_Release(viewport);
IDirect3D2_Release(d3d);
IDirect3DDevice2_Release(device);
IDirectDraw2_Release(ddraw);
@ -1428,7 +1391,6 @@ static void test_ck_rgba(void)
IDirectDrawSurface *rt;
D3DMATERIAL material;
IDirectDraw2 *ddraw;
D3DVIEWPORT2 vp;
IDirect3D2 *d3d;
D3DCOLOR color;
HWND window;
@ -1454,24 +1416,7 @@ static void test_ck_rgba(void)
hr = IDirect3DDevice2_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D2_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice2_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport2_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
hr = IDirect3DDevice2_SetCurrentViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
@ -1581,10 +1526,8 @@ static void test_ck_rgba(void)
hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_TEXTUREHANDLE, 0);
ok(SUCCEEDED(hr), "Failed to unset texture, hr %#x.\n", hr);
IDirectDrawSurface_Release(surface);
destroy_viewport(device, viewport);
IDirect3DMaterial2_Release(background);
hr = IDirect3DDevice2_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport2_Release(viewport);
IDirect3DDevice2_Release(device);
IDirectDraw2_Release(ddraw);
DestroyWindow(window);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011 Henri Verbeet for CodeWeavers
* Copyright 2011-2012 Henri Verbeet for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -290,6 +290,47 @@ static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
return device;
}
static IDirect3DViewport3 *create_viewport(IDirect3DDevice3 *device, UINT x, UINT y, UINT w, UINT h)
{
IDirect3DViewport3 *viewport;
D3DVIEWPORT2 vp;
IDirect3D3 *d3d;
HRESULT hr;
hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice3_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = x;
vp.dwY = y;
vp.dwWidth = w;
vp.dwHeight = h;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
IDirect3D3_Release(d3d);
return viewport;
}
static void destroy_viewport(IDirect3DDevice3 *device, IDirect3DViewport3 *viewport)
{
HRESULT hr;
hr = IDirect3DDevice3_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport3_Release(viewport);
}
static void test_process_vertices(void)
{
IDirect3DVertexBuffer *src_vb, *dst_vb;
@ -798,7 +839,6 @@ static void test_coop_level_d3d_state(void)
IDirect3DViewport3 *viewport;
IDirect3DDevice3 *device;
IDirectDraw4 *ddraw;
D3DVIEWPORT2 vp;
IDirect3D3 *d3d;
D3DCOLOR color;
DWORD value;
@ -814,27 +854,7 @@ static void test_coop_level_d3d_state(void)
return;
}
hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice3_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
@ -851,6 +871,8 @@ static void test_coop_level_d3d_state(void)
color = get_surface_color(rt, 320, 240);
ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
IDirect3D3_Release(d3d);
@ -876,9 +898,7 @@ static void test_coop_level_d3d_state(void)
color = get_surface_color(rt, 320, 240);
ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice3_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport3_Release(viewport);
destroy_viewport(device, viewport);
IDirectDrawSurface4_Release(surface);
IDirectDrawSurface4_Release(rt);
IDirect3DDevice3_Release(device);
@ -899,7 +919,6 @@ static void test_surface_interface_mismatch(void)
HRESULT hr;
D3DCOLOR color;
HWND window;
D3DVIEWPORT2 vp;
D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
@ -968,24 +987,7 @@ static void test_surface_interface_mismatch(void)
if (FAILED(hr))
goto cleanup;
hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice3_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
@ -994,10 +996,7 @@ static void test_surface_interface_mismatch(void)
cleanup:
if (viewport)
{
IDirect3DDevice3_DeleteViewport(device, viewport);
IDirect3DViewport3_Release(viewport);
}
destroy_viewport(device, viewport);
if (surface3) IDirectDrawSurface3_Release(surface3);
if (surface) IDirectDrawSurface4_Release(surface);
if (device) IDirect3DDevice3_Release(device);
@ -1052,7 +1051,6 @@ static void test_depth_blit(void)
IDirect3DDevice3 *device;
IDirectDrawSurface4 *ds1, *ds2, *ds3, *rt;
IDirect3DViewport3 *viewport;
D3DVIEWPORT2 vp_data;
RECT src_rect, dst_rect;
unsigned int i, j;
D3DCOLOR color;
@ -1076,8 +1074,6 @@ static void test_depth_blit(void)
ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create a viewport, hr %#x.\n", hr);
IDirect3D3_Release(d3d);
ds1 = get_depth_stencil(device);
@ -1098,19 +1094,7 @@ static void test_depth_blit(void)
ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
IDirectDraw4_Release(ddraw);
hr = IDirect3DDevice3_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
memset(&vp_data, 0, sizeof(vp_data));
vp_data.dwSize = sizeof(vp_data);
vp_data.dwWidth = ddsd_existing.dwWidth;
vp_data.dwHeight = ddsd_existing.dwHeight;
vp_data.dvMaxZ = 1.0;
vp_data.dvClipX = -1.0f;
vp_data.dvClipWidth = 2.0f;
vp_data.dvClipY = 1.0f;
vp_data.dvClipHeight = 2.0f;
hr = IDirect3DViewport3_SetViewport2(viewport, &vp_data);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, ddsd_existing.dwWidth, ddsd_existing.dwHeight);
hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
@ -1122,7 +1106,7 @@ static void test_depth_blit(void)
ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
U1(d3drect).x1 = U2(d3drect).y1 = 0;
U3(d3drect).x2 = vp_data.dwWidth; U4(d3drect).y2 = vp_data.dwHeight;
U3(d3drect).x2 = ddsd_existing.dwWidth; U4(d3drect).y2 = ddsd_existing.dwHeight;
hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
@ -1213,9 +1197,7 @@ static void test_depth_blit(void)
}
IDirectDrawSurface4_Release(rt);
hr = IDirect3DDevice3_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr);
IDirect3DViewport3_Release(viewport);
destroy_viewport(device, viewport);
IDirect3DDevice3_Release(device);
DestroyWindow(window);
}
@ -1419,8 +1401,6 @@ static void test_zenable(void)
IDirect3DViewport3 *viewport;
IDirect3DDevice3 *device;
IDirectDrawSurface4 *rt;
D3DVIEWPORT2 vp;
IDirect3D3 *d3d;
D3DCOLOR color;
HWND window;
HRESULT hr;
@ -1436,27 +1416,7 @@ static void test_zenable(void)
return;
}
hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice3_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
@ -1487,10 +1447,7 @@ static void test_zenable(void)
}
IDirectDrawSurface4_Release(rt);
hr = IDirect3DDevice3_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport3_Release(viewport);
IDirect3D3_Release(d3d);
destroy_viewport(device, viewport);
IDirect3DDevice3_Release(device);
DestroyWindow(window);
}
@ -1541,7 +1498,6 @@ static void test_ck_rgba(void)
IDirect3DDevice3 *device;
IDirectDrawSurface4 *rt;
IDirectDraw4 *ddraw;
D3DVIEWPORT2 vp;
IDirect3D3 *d3d;
D3DCOLOR color;
HWND window;
@ -1558,32 +1514,14 @@ static void test_ck_rgba(void)
return;
}
hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
hr = IDirect3DDevice3_AddViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
memset(&vp, 0, sizeof(vp));
vp.dwSize = sizeof(vp);
vp.dwX = 0;
vp.dwY = 0;
vp.dwWidth = 640;
vp.dwHeight = 480;
vp.dvClipX = -1.0f;
vp.dvClipY = 1.0f;
vp.dvClipWidth = 2.0f;
vp.dvClipHeight = 2.0f;
vp.dvMinZ = 0.0f;
vp.dvMaxZ = 1.0f;
hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
viewport = create_viewport(device, 0, 0, 640, 480);
hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
IDirect3D3_Release(d3d);
memset(&surface_desc, 0, sizeof(surface_desc));
@ -1672,9 +1610,7 @@ static void test_ck_rgba(void)
IDirectDrawSurface4_Release(rt);
IDirect3DTexture2_Release(texture);
IDirectDrawSurface4_Release(surface);
hr = IDirect3DDevice3_DeleteViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
IDirect3DViewport3_Release(viewport);
destroy_viewport(device, viewport);
IDirectDraw4_Release(ddraw);
IDirect3DDevice3_Release(device);
DestroyWindow(window);