From 314a016e29d99f15703d8e6ed0ff37bf76f259ba Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 7 Mar 2014 11:17:12 +0100 Subject: [PATCH] d3d8/tests: Use create_device() in more tests. --- dlls/d3d8/tests/device.c | 837 ++++++++++++++++----------------------- 1 file changed, 334 insertions(+), 503 deletions(-) diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c index 324160bea65..fa370b022a6 100644 --- a/dlls/d3d8/tests/device.c +++ b/dlls/d3d8/tests/device.c @@ -180,94 +180,75 @@ static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT heigh static void test_mipmap_levels(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; + IDirect3DDevice8 *device; IDirect3D8 *d3d; - HWND hwnd; + ULONG refcount; + HWND window; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferFormat = d3ddm.Format; - if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } - check_mipmap_levels(pDevice, 32, 32, 6); - check_mipmap_levels(pDevice, 256, 1, 9); - check_mipmap_levels(pDevice, 1, 256, 9); - check_mipmap_levels(pDevice, 1, 1, 1); + check_mipmap_levels(device, 32, 32, 6); + check_mipmap_levels(device, 256, 1, 9); + check_mipmap_levels(device, 1, 256, 9); + check_mipmap_levels(device, 1, 1, 1); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if (pDevice) - { - UINT refcount = IDirect3DDevice8_Release( pDevice ); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_swapchain(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; - IDirect3DSwapChain8 *swapchain1 = NULL; - IDirect3DSwapChain8 *swapchain2 = NULL; - IDirect3DSwapChain8 *swapchain3 = NULL; - IDirect3DSurface8 *backbuffer = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; + IDirect3DSwapChain8 *swapchain1; + IDirect3DSwapChain8 *swapchain2; + IDirect3DSwapChain8 *swapchain3; + IDirect3DSurface8 *backbuffer; + D3DPRESENT_PARAMETERS d3dpp; + IDirect3DDevice8 *device; IDirect3D8 *d3d; - HWND hwnd; + ULONG refcount; + HWND window; + HRESULT hr; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.BackBufferCount = 0; - - if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } - /* Check if the back buffer count was modified */ - ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount); + memset(&d3dpp, 0, sizeof(d3dpp)); + d3dpp.Windowed = TRUE; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; /* Create a bunch of swapchains */ d3dpp.BackBufferCount = 0; - hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain1); + hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1); ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr); ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount); d3dpp.BackBufferCount = 1; - hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2); + hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain2); ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr); d3dpp.BackBufferCount = 2; - hr = IDirect3DDevice8_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3); + hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain3); ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr); if(SUCCEEDED(hr)) { /* Swapchain 3, created with backbuffercount 2 */ @@ -328,23 +309,18 @@ static void test_swapchain(void) ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer); if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer); + IDirect3DSwapChain8_Release(swapchain3); + IDirect3DSwapChain8_Release(swapchain2); + IDirect3DSwapChain8_Release(swapchain1); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if(swapchain1) IDirect3DSwapChain8_Release(swapchain1); - if(swapchain2) IDirect3DSwapChain8_Release(swapchain2); - if(swapchain3) IDirect3DSwapChain8_Release(swapchain3); - if (pDevice) - { - UINT refcount = IDirect3DDevice8_Release(pDevice); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_refcount(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; IDirect3DVertexBuffer8 *pVertexBuffer = NULL; IDirect3DIndexBuffer8 *pIndexBuffer = NULL; DWORD dVertexShader = -1; @@ -364,10 +340,11 @@ static void test_refcount(void) IDirect3DSwapChain8 *pSwapChain = NULL; D3DCAPS8 caps; D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; - int refcount = 0, tmp; + IDirect3DDevice8 *device = NULL; + ULONG refcount = 0, tmp; IDirect3D8 *d3d, *d3d2; - HWND hwnd; + HWND window; + HRESULT hr; DWORD decl[] = { @@ -377,37 +354,29 @@ static void test_refcount(void) D3DVSD_END() }; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); CHECK_REFCOUNT(d3d, 1); - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - - if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } - IDirect3DDevice8_GetDeviceCaps(pDevice, &caps); - refcount = get_refcount( (IUnknown *)pDevice ); + IDirect3DDevice8_GetDeviceCaps(device, &caps); + + refcount = get_refcount((IUnknown *)device); ok(refcount == 1, "Invalid device RefCount %d\n", refcount); CHECK_REFCOUNT(d3d, 2); - hr = IDirect3DDevice8_GetDirect3D(pDevice, &d3d2); - CHECK_CALL( hr, "GetDirect3D", pDevice, refcount ); + hr = IDirect3DDevice8_GetDirect3D(device, &d3d2); + CHECK_CALL(hr, "GetDirect3D", device, refcount); ok(d3d2 == d3d, "Expected IDirect3D8 pointers to be equal.\n"); CHECK_REFCOUNT(d3d, 3); @@ -421,35 +390,35 @@ static void test_refcount(void) * - they are not freed if refcount reaches 0. * - the refcount is not forwarded to the container. */ - hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget); - CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount); + hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget); + CHECK_CALL(hr, "GetRenderTarget", device, ++refcount); if(pRenderTarget) { - CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DDevice8, pDevice); + CHECK_SURFACE_CONTAINER(pRenderTarget, IID_IDirect3DDevice8, device); CHECK_REFCOUNT( pRenderTarget, 1); CHECK_ADDREF_REFCOUNT(pRenderTarget, 2); - CHECK_REFCOUNT(pDevice, refcount); + CHECK_REFCOUNT(device, refcount); CHECK_RELEASE_REFCOUNT(pRenderTarget, 1); - CHECK_REFCOUNT(pDevice, refcount); + CHECK_REFCOUNT(device, refcount); - hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget); - CHECK_CALL( hr, "GetRenderTarget", pDevice, refcount); + hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget); + CHECK_CALL(hr, "GetRenderTarget", device, refcount); CHECK_REFCOUNT( pRenderTarget, 2); CHECK_RELEASE_REFCOUNT( pRenderTarget, 1); CHECK_RELEASE_REFCOUNT( pRenderTarget, 0); - CHECK_REFCOUNT( pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); /* The render target is released with the device, so AddRef with refcount=0 is fine here. */ CHECK_ADDREF_REFCOUNT(pRenderTarget, 1); - CHECK_REFCOUNT(pDevice, ++refcount); + CHECK_REFCOUNT(device, ++refcount); CHECK_RELEASE_REFCOUNT(pRenderTarget, 0); - CHECK_REFCOUNT(pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); } /* Render target and back buffer are identical. */ - hr = IDirect3DDevice8_GetBackBuffer(pDevice, 0, 0, &pBackBuffer); - CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount); + hr = IDirect3DDevice8_GetBackBuffer(device, 0, 0, &pBackBuffer); + CHECK_CALL(hr, "GetBackBuffer", device, ++refcount); if(pBackBuffer) { CHECK_RELEASE_REFCOUNT(pBackBuffer, 0); @@ -457,46 +426,46 @@ static void test_refcount(void) pRenderTarget, pBackBuffer); pBackBuffer = NULL; } - CHECK_REFCOUNT( pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); - hr = IDirect3DDevice8_GetDepthStencilSurface(pDevice, &pStencilSurface); - CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount); + hr = IDirect3DDevice8_GetDepthStencilSurface(device, &pStencilSurface); + CHECK_CALL(hr, "GetDepthStencilSurface", device, ++refcount); if(pStencilSurface) { - CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice8, pDevice); + CHECK_SURFACE_CONTAINER(pStencilSurface, IID_IDirect3DDevice8, device); CHECK_REFCOUNT( pStencilSurface, 1); CHECK_ADDREF_REFCOUNT(pStencilSurface, 2); - CHECK_REFCOUNT(pDevice, refcount); + CHECK_REFCOUNT(device, refcount); CHECK_RELEASE_REFCOUNT(pStencilSurface, 1); - CHECK_REFCOUNT(pDevice, refcount); + CHECK_REFCOUNT(device, refcount); CHECK_RELEASE_REFCOUNT( pStencilSurface, 0); - CHECK_REFCOUNT( pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */ CHECK_ADDREF_REFCOUNT(pStencilSurface, 1); - CHECK_REFCOUNT(pDevice, ++refcount); + CHECK_REFCOUNT(device, ++refcount); CHECK_RELEASE_REFCOUNT(pStencilSurface, 0); - CHECK_REFCOUNT(pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); pStencilSurface = NULL; } /* Buffers */ - hr = IDirect3DDevice8_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer ); - CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateIndexBuffer(device, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer); + CHECK_CALL(hr, "CreateIndexBuffer", device, ++refcount); if(pIndexBuffer) { tmp = get_refcount( (IUnknown *)pIndexBuffer ); - hr = IDirect3DDevice8_SetIndices(pDevice, pIndexBuffer, 0); + hr = IDirect3DDevice8_SetIndices(device, pIndexBuffer, 0); CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp); - hr = IDirect3DDevice8_SetIndices(pDevice, NULL, 0); + hr = IDirect3DDevice8_SetIndices(device, NULL, 0); CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp); } - hr = IDirect3DDevice8_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer ); - CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateVertexBuffer(device, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer); + CHECK_CALL(hr, "CreateVertexBuffer", device, ++refcount); if(pVertexBuffer) { IDirect3DVertexBuffer8 *pVBuf = (void*)~0; @@ -504,41 +473,41 @@ static void test_refcount(void) tmp = get_refcount( (IUnknown *)pVertexBuffer ); - hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, pVertexBuffer, 3 * sizeof(float)); + hr = IDirect3DDevice8_SetStreamSource(device, 0, pVertexBuffer, 3 * sizeof(float)); CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp); - hr = IDirect3DDevice8_SetStreamSource(pDevice, 0, NULL, 0); + hr = IDirect3DDevice8_SetStreamSource(device, 0, NULL, 0); CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp); - hr = IDirect3DDevice8_GetStreamSource(pDevice, 0, &pVBuf, &stride); + hr = IDirect3DDevice8_GetStreamSource(device, 0, &pVBuf, &stride); ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n"); ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf); ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride); } /* Shaders */ - hr = IDirect3DDevice8_CreateVertexShader( pDevice, decl, simple_vs, &dVertexShader, 0 ); - CHECK_CALL( hr, "CreateVertexShader", pDevice, refcount ); + hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_vs, &dVertexShader, 0); + CHECK_CALL(hr, "CreateVertexShader", device, refcount); if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0)) { - hr = IDirect3DDevice8_CreatePixelShader( pDevice, simple_ps, &dPixelShader ); - CHECK_CALL( hr, "CreatePixelShader", pDevice, refcount ); + hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &dPixelShader); + CHECK_CALL(hr, "CreatePixelShader", device, refcount); } /* Textures */ - hr = IDirect3DDevice8_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture ); - CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateTexture(device, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture); + CHECK_CALL(hr, "CreateTexture", device, ++refcount); if (pTexture) { tmp = get_refcount( (IUnknown *)pTexture ); /* SetTexture should not increase refcounts */ - hr = IDirect3DDevice8_SetTexture(pDevice, 0, (IDirect3DBaseTexture8 *) pTexture); + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) pTexture); CHECK_CALL( hr, "SetTexture", pTexture, tmp); - hr = IDirect3DDevice8_SetTexture(pDevice, 0, NULL); + hr = IDirect3DDevice8_SetTexture(device, 0, NULL); CHECK_CALL( hr, "SetTexture", pTexture, tmp); /* This should not increment device refcount */ hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel ); - CHECK_CALL( hr, "GetSurfaceLevel", pDevice, refcount ); + CHECK_CALL(hr, "GetSurfaceLevel", device, refcount); /* But should increment texture's refcount */ CHECK_REFCOUNT( pTexture, tmp+1 ); /* Because the texture and surface refcount are identical */ @@ -555,8 +524,8 @@ static void test_refcount(void) } if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) { - hr = IDirect3DDevice8_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture ); - CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateCubeTexture(device, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture); + CHECK_CALL(hr, "CreateCubeTexture", device, ++refcount); } else { @@ -564,8 +533,9 @@ static void test_refcount(void) } if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) { - hr = IDirect3DDevice8_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture ); - CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateVolumeTexture(device, 32, 32, 2, 0, 0, + D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture); + CHECK_CALL(hr, "CreateVolumeTexture", device, ++refcount); } else { @@ -578,7 +548,7 @@ static void test_refcount(void) /* This should not increment device refcount */ hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel); - CHECK_CALL( hr, "GetVolumeLevel", pDevice, refcount ); + CHECK_CALL(hr, "GetVolumeLevel", device, refcount); /* But should increment volume texture's refcount */ CHECK_REFCOUNT( pVolumeTexture, tmp+1 ); /* Because the volume texture and volume refcount are identical */ @@ -594,38 +564,48 @@ static void test_refcount(void) } } /* Surfaces */ - hr = IDirect3DDevice8_CreateDepthStencilSurface( pDevice, 32, 32, D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface ); - CHECK_CALL( hr, "CreateDepthStencilSurface", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32, + D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface); + CHECK_CALL(hr, "CreateDepthStencilSurface", device, ++refcount); CHECK_REFCOUNT( pStencilSurface, 1); - hr = IDirect3DDevice8_CreateImageSurface( pDevice, 32, 32, D3DFMT_X8R8G8B8, &pImageSurface ); - CHECK_CALL( hr, "CreateImageSurface", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, + D3DFMT_X8R8G8B8, &pImageSurface); + CHECK_CALL(hr, "CreateImageSurface", device, ++refcount); CHECK_REFCOUNT( pImageSurface, 1); - hr = IDirect3DDevice8_CreateRenderTarget( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3 ); - CHECK_CALL( hr, "CreateRenderTarget", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateRenderTarget(device, 32, 32, + D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3); + CHECK_CALL(hr, "CreateRenderTarget", device, ++refcount); CHECK_REFCOUNT( pRenderTarget3, 1); /* Misc */ - hr = IDirect3DDevice8_CreateStateBlock( pDevice, D3DSBT_ALL, &dStateBlock ); - CHECK_CALL( hr, "CreateStateBlock", pDevice, refcount ); - hr = IDirect3DDevice8_CreateAdditionalSwapChain( pDevice, &d3dpp, &pSwapChain ); - CHECK_CALL( hr, "CreateAdditionalSwapChain", pDevice, ++refcount ); + hr = IDirect3DDevice8_CreateStateBlock(device, D3DSBT_ALL, &dStateBlock); + CHECK_CALL(hr, "CreateStateBlock", device, refcount); + + memset(&d3dpp, 0, sizeof(d3dpp)); + d3dpp.Windowed = TRUE; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; + d3dpp.EnableAutoDepthStencil = TRUE; + d3dpp.AutoDepthStencilFormat = D3DFMT_D16; + hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &pSwapChain); + CHECK_CALL(hr, "CreateAdditionalSwapChain", device, ++refcount); if(pSwapChain) { /* check implicit back buffer */ hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer); - CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount); + CHECK_CALL(hr, "GetBackBuffer", device, ++refcount); CHECK_REFCOUNT( pSwapChain, 1); if(pBackBuffer) { - CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DDevice8, pDevice); + CHECK_SURFACE_CONTAINER(pBackBuffer, IID_IDirect3DDevice8, device); CHECK_REFCOUNT( pBackBuffer, 1); CHECK_RELEASE_REFCOUNT( pBackBuffer, 0); - CHECK_REFCOUNT( pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */ CHECK_ADDREF_REFCOUNT(pBackBuffer, 1); - CHECK_REFCOUNT(pDevice, ++refcount); + CHECK_REFCOUNT(device, ++refcount); CHECK_RELEASE_REFCOUNT(pBackBuffer, 0); - CHECK_REFCOUNT(pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); pBackBuffer = NULL; } CHECK_REFCOUNT( pSwapChain, 1); @@ -647,55 +627,58 @@ static void test_refcount(void) /* The implicit render target is not freed if refcount reaches 0. * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/ - hr = IDirect3DDevice8_GetRenderTarget(pDevice, &pRenderTarget2); - CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount); + hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget2); + CHECK_CALL(hr, "GetRenderTarget", device, ++refcount); if(pRenderTarget2) { CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0); ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n", pRenderTarget, pRenderTarget2); - CHECK_REFCOUNT( pDevice, --refcount); + CHECK_REFCOUNT(device, --refcount); pRenderTarget2 = NULL; } pRenderTarget = NULL; cleanup: - CHECK_RELEASE(pDevice, pDevice, --refcount); + CHECK_RELEASE(device, device, --refcount); /* Buffers */ - CHECK_RELEASE(pVertexBuffer, pDevice, --refcount); - CHECK_RELEASE(pIndexBuffer, pDevice, --refcount); + CHECK_RELEASE(pVertexBuffer, device, --refcount); + CHECK_RELEASE(pIndexBuffer, device, --refcount); /* Shaders */ - if (dVertexShader != ~0U) IDirect3DDevice8_DeleteVertexShader( pDevice, dVertexShader ); - if (dPixelShader != ~0U) IDirect3DDevice8_DeletePixelShader( pDevice, dPixelShader ); + if (dVertexShader != ~0u) + IDirect3DDevice8_DeleteVertexShader(device, dVertexShader); + if (dPixelShader != ~0u) + IDirect3DDevice8_DeletePixelShader(device, dPixelShader); /* Textures */ - CHECK_RELEASE(pTexture, pDevice, --refcount); - CHECK_RELEASE(pCubeTexture, pDevice, --refcount); - CHECK_RELEASE(pVolumeTexture, pDevice, --refcount); + CHECK_RELEASE(pTexture, device, --refcount); + CHECK_RELEASE(pCubeTexture, device, --refcount); + CHECK_RELEASE(pVolumeTexture, device, --refcount); /* Surfaces */ - CHECK_RELEASE(pStencilSurface, pDevice, --refcount); - CHECK_RELEASE(pImageSurface, pDevice, --refcount); - CHECK_RELEASE(pRenderTarget3, pDevice, --refcount); + CHECK_RELEASE(pStencilSurface, device, --refcount); + CHECK_RELEASE(pImageSurface, device, --refcount); + CHECK_RELEASE(pRenderTarget3, device, --refcount); /* Misc */ - if (dStateBlock != ~0U) IDirect3DDevice8_DeleteStateBlock( pDevice, dStateBlock ); + if (dStateBlock != ~0u) + IDirect3DDevice8_DeleteStateBlock(device, dStateBlock); /* This will destroy device - cannot check the refcount here */ - if (pSwapChain) CHECK_RELEASE_REFCOUNT( pSwapChain, 0); + if (pSwapChain) + CHECK_RELEASE_REFCOUNT(pSwapChain, 0); CHECK_RELEASE_REFCOUNT(d3d, 0); - DestroyWindow( hwnd ); + DestroyWindow(window); } static void test_cursor(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; - CURSORINFO info; - IDirect3DSurface8 *cursor = NULL; - HCURSOR cur; HMODULE user32_handle = GetModuleHandleA("user32.dll"); + IDirect3DSurface8 *cursor = NULL; + IDirect3DDevice8 *device; + CURSORINFO info; IDirect3D8 *d3d; - HWND hwnd; + ULONG refcount; + HCURSOR cur; + HWND window; + HRESULT hr; pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo"); if (!pGetCursorInfo) @@ -709,41 +692,33 @@ static void test_cursor(void) ok(pGetCursorInfo(&info), "GetCursorInfo failed\n"); cur = info.hCursor; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferFormat = d3ddm.Format; - - if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } - IDirect3DDevice8_CreateImageSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, &cursor); - ok(cursor != NULL, "IDirect3DDevice8_CreateOffscreenPlainSurface failed with %#08x\n", hr); + hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor); + ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr); /* Initially hidden */ - hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE); + hr = IDirect3DDevice8_ShowCursor(device, TRUE); ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr); /* Not enabled without a surface*/ - hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE); + hr = IDirect3DDevice8_ShowCursor(device, TRUE); ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr); /* Fails */ - hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, NULL); + hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, NULL); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr); - hr = IDirect3DDevice8_SetCursorProperties(pDevice, 0, 0, cursor); + hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor); ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr); IDirect3DSurface8_Release(cursor); @@ -755,11 +730,11 @@ static void test_cursor(void) ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */ /* Still hidden */ - hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE); + hr = IDirect3DDevice8_ShowCursor(device, TRUE); ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr); /* Enabled now*/ - hr = IDirect3DDevice8_ShowCursor(pDevice, TRUE); + hr = IDirect3DDevice8_ShowCursor(device, TRUE); ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr); /* GDI cursor unchanged */ @@ -769,14 +744,11 @@ static void test_cursor(void) ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags); ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */ + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if (pDevice) - { - UINT refcount = IDirect3DDevice8_Release(pDevice); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static const POINT *expect_pos; @@ -897,47 +869,33 @@ done: static void test_states(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; + IDirect3DDevice8 *device; IDirect3D8 *d3d; - HWND hwnd; + ULONG refcount; + HWND window; + HRESULT hr; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = screen_width; - d3dpp.BackBufferHeight = screen_height; - d3dpp.BackBufferFormat = d3ddm.Format; - - if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } - hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, TRUE); + hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, TRUE); ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr); - hr = IDirect3DDevice8_SetRenderState(pDevice, D3DRS_ZVISIBLE, FALSE); + hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, FALSE); ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if (pDevice) - { - UINT refcount = IDirect3DDevice8_Release(pDevice); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_shader_versions(void) @@ -1565,90 +1523,70 @@ cleanup: static void test_scene(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; + IDirect3DDevice8 *device; IDirect3D8 *d3d; - HWND hwnd; + ULONG refcount; + HWND window; + HRESULT hr; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = 800; - d3dpp.BackBufferHeight = 600; - d3dpp.BackBufferFormat = d3ddm.Format; - - hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice); - ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr); - if(!pDevice) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } /* Test an EndScene without BeginScene. Should return an error */ - hr = IDirect3DDevice8_EndScene(pDevice); + hr = IDirect3DDevice8_EndScene(device); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr); /* Test a normal BeginScene / EndScene pair, this should work */ - hr = IDirect3DDevice8_BeginScene(pDevice); + hr = IDirect3DDevice8_BeginScene(device); ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr); - if(SUCCEEDED(hr)) - { - hr = IDirect3DDevice8_EndScene(pDevice); - ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr); - } + hr = IDirect3DDevice8_EndScene(device); + ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr); /* Test another EndScene without having begun a new scene. Should return an error */ - hr = IDirect3DDevice8_EndScene(pDevice); + hr = IDirect3DDevice8_EndScene(device); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr); /* Two nested BeginScene and EndScene calls */ - hr = IDirect3DDevice8_BeginScene(pDevice); + hr = IDirect3DDevice8_BeginScene(device); ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr); - hr = IDirect3DDevice8_BeginScene(pDevice); + hr = IDirect3DDevice8_BeginScene(device); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr); - hr = IDirect3DDevice8_EndScene(pDevice); + hr = IDirect3DDevice8_EndScene(device); ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr); - hr = IDirect3DDevice8_EndScene(pDevice); + hr = IDirect3DDevice8_EndScene(device); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr); /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */ + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if (pDevice) - { - UINT refcount = IDirect3DDevice8_Release(pDevice); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_shader(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; DWORD hPixelShader = 0, hVertexShader = 0; DWORD hPixelShader2 = 0, hVertexShader2 = 0; DWORD hTempHandle; D3DCAPS8 caps; DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE; + IDirect3DDevice8 *device; IDirect3D8 *d3d; DWORD data_size; + ULONG refcount; + HWND window; + HRESULT hr; void *data; - HWND hwnd; static DWORD dwVertexDecl[] = { @@ -1681,169 +1619,154 @@ static void test_shader(void) const DWORD simple_vs_size = sizeof(simple_vs); const DWORD simple_ps_size = sizeof(simple_ps); - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = 800; - d3dpp.BackBufferHeight = 600; - d3dpp.BackBufferFormat = d3ddm.Format; - - - hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice ); - ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr); - if(!pDevice) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } - IDirect3DDevice8_GetDeviceCaps(pDevice, &caps); + + IDirect3DDevice8_GetDeviceCaps(device, &caps); /* Test setting and retrieving a FVF */ - hr = IDirect3DDevice8_SetVertexShader(pDevice, fvf); + hr = IDirect3DDevice8_SetVertexShader(device, fvf); ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle); ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr); ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf); /* First create a vertex shader */ - hr = IDirect3DDevice8_SetVertexShader(pDevice, 0); + hr = IDirect3DDevice8_SetVertexShader(device, 0); ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, simple_vs, &hVertexShader, 0); + hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, simple_vs, &hVertexShader, 0); ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr); /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */ - hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr); ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0); /* Assign the shader, then verify that GetVertexShader works */ - hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader); + hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader); ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr); ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader); /* Verify that we can retrieve the declaration */ - hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, NULL, &data_size); + hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, NULL, &data_size); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr); ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size); data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size); data_size = 1; - hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size); + hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), " "expected D3DERR_INVALIDCALL\n", hr); ok(data_size == 1, "Got data_size %u, expected 1\n", data_size); data_size = vertex_decl_size; - hr = IDirect3DDevice8_GetVertexShaderDeclaration(pDevice, hVertexShader, data, &data_size); + hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr); ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size); ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n"); HeapFree(GetProcessHeap(), 0, data); /* Verify that we can retrieve the shader function */ - hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, NULL, &data_size); + hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, NULL, &data_size); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr); ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size); data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size); data_size = 1; - hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size); + hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), " "expected D3DERR_INVALIDCALL\n", hr); ok(data_size == 1, "Got data_size %u, expected 1\n", data_size); data_size = simple_vs_size; - hr = IDirect3DDevice8_GetVertexShaderFunction(pDevice, hVertexShader, data, &data_size); + hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr); ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size); ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n"); HeapFree(GetProcessHeap(), 0, data); /* Delete the assigned shader. This is supposed to work */ - hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader); + hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader); ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr); /* The shader should be unset now */ - hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr); ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0); /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components * First try the fixed function shader function, then a custom one */ - hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, 0, &hVertexShader, 0); + hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, 0, &hVertexShader, 0); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr); - if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader); - hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float4, 0, &hVertexShader, 0); + hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float4, 0, &hVertexShader, 0); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr); - if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader); - hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_d3dcolor, 0, &hVertexShader, 0); + hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_d3dcolor, 0, &hVertexShader, 0); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr); - if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader); - hr = IDirect3DDevice8_CreateVertexShader(pDevice, decl_normal_float2, simple_vs, &hVertexShader, 0); + hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, simple_vs, &hVertexShader, 0); ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr); - if(SUCCEEDED(hr)) IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader); + IDirect3DDevice8_DeleteVertexShader(device, hVertexShader); if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0)) { /* The same with a pixel shader */ - hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader); + hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader); ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr); /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */ - hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr); ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0); /* Assign the shader, then verify that GetPixelShader works */ - hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader); + hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader); ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr); - hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr); ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader); /* Verify that we can retrieve the shader function */ - hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, NULL, &data_size); + hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, NULL, &data_size); ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr); ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size); data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size); data_size = 1; - hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size); + hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), " "expected D3DERR_INVALIDCALL\n", hr); ok(data_size == 1, "Got data_size %u, expected 1\n", data_size); data_size = simple_ps_size; - hr = IDirect3DDevice8_GetPixelShaderFunction(pDevice, hPixelShader, data, &data_size); + hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size); ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr); ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size); ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n"); HeapFree(GetProcessHeap(), 0, data); /* Delete the assigned shader. This is supposed to work */ - hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader); + hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader); ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr); /* The shader should be unset now */ - hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr); ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0); /* What happens if a non-bound shader is deleted? */ - hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader); + hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader); ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr); - hr = IDirect3DDevice8_CreatePixelShader(pDevice, simple_ps, &hPixelShader2); + hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader2); ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr); - hr = IDirect3DDevice8_SetPixelShader(pDevice, hPixelShader); + hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader); ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr); - hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2); + hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2); ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr); - hr = IDirect3DDevice8_GetPixelShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr); ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader); - hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader); + hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader); ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr); /* Check for double delete. */ - hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader2); + hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2); ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr); - hr = IDirect3DDevice8_DeletePixelShader(pDevice, hPixelShader); + hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader); ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr); } else @@ -1852,138 +1775,100 @@ static void test_shader(void) } /* What happens if a non-bound shader is deleted? */ - hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader, 0); + hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader, 0); ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_CreateVertexShader(pDevice, dwVertexDecl, NULL, &hVertexShader2, 0); + hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader2, 0); ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_SetVertexShader(pDevice, hVertexShader); + hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader); ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2); + hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2); ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_GetVertexShader(pDevice, &hTempHandle); + hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle); ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr); ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader); - hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader); + hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader); ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr); /* Check for double delete. */ - hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader2); + hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr); - hr = IDirect3DDevice8_DeleteVertexShader(pDevice, hVertexShader); + hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if (pDevice) - { - UINT refcount = IDirect3DDevice8_Release(pDevice); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_limits(void) { - HRESULT hr; - IDirect3DDevice8 *pDevice = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; - IDirect3DTexture8 *pTexture = NULL; + IDirect3DTexture8 *texture; + IDirect3DDevice8 *device; IDirect3D8 *d3d; - HWND hwnd; - int i; + unsigned int i; + ULONG refcount; + HWND window; + HRESULT hr; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = 800; - d3dpp.BackBufferHeight = 600; - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - - hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, - hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice); - ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr); - if(!pDevice) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } - hr = IDirect3DDevice8_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture); + hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture); ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr); - if(!pTexture) goto cleanup; /* There are 8 texture stages. We should be able to access all of them */ - for(i = 0; i < 8; i++) { - hr = IDirect3DDevice8_SetTexture(pDevice, i, (IDirect3DBaseTexture8 *) pTexture); + for (i = 0; i < 8; ++i) + { + hr = IDirect3DDevice8_SetTexture(device, i, (IDirect3DBaseTexture8 *)texture); ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr); - hr = IDirect3DDevice8_SetTexture(pDevice, i, NULL); + hr = IDirect3DDevice8_SetTexture(device, i, NULL); ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr); - hr = IDirect3DDevice8_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD); + hr = IDirect3DDevice8_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_ADD); ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr); } - /* Investigations show that accessing higher textures stage states does not return an error either. Writing - * to too high texture stages(approximately texture 40) causes memory corruption in windows, so there is no - * bounds checking but how do I test that? - */ - + /* Investigations show that accessing higher textures stage states does + * not return an error either. Writing to too high texture stages + * (approximately texture 40) causes memory corruption in windows, so + * there is no bounds checking. */ + IDirect3DTexture8_Release(texture); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if(pTexture) IDirect3DTexture8_Release(pTexture); - if (pDevice) - { - UINT refcount = IDirect3DDevice8_Release(pDevice); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_lights(void) { - D3DPRESENT_PARAMETERS d3dpp; - IDirect3DDevice8 *device = NULL; + IDirect3DDevice8 *device; IDirect3D8 *d3d8; - HWND hwnd; + ULONG refcount; + HWND window; HRESULT hr; unsigned int i; BOOL enabled; D3DCAPS8 caps; - D3DDISPLAYMODE d3ddm; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d8 = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d8, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm ); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = 800; - d3dpp.BackBufferHeight = 600; - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - - hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd, - D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &device ); - ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL, - "IDirect3D8_CreateDevice failed with %08x\n", hr); - if(!device) + if (!(device = create_device(d3d8, window, window, TRUE))) { - skip("Failed to create a d3d device\n"); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } @@ -2014,24 +1899,20 @@ static void test_lights(void) ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr); } + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if (device) - { - UINT refcount = IDirect3DDevice8_Release(device); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d8); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_render_zero_triangles(void) { - D3DPRESENT_PARAMETERS d3dpp; - IDirect3DDevice8 *device = NULL; + IDirect3DDevice8 *device; IDirect3D8 *d3d8; - HWND hwnd; + ULONG refcount; + HWND window; HRESULT hr; - D3DDISPLAYMODE d3ddm; struct nvertex { @@ -2046,29 +1927,14 @@ static void test_render_zero_triangles(void) { 1.0f, -1.0f, 0.1f, 1.0f, 1.0f, 1.0f, 0xff0000ff}, }; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d8 = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d8, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm ); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = 800; - d3dpp.BackBufferHeight = 600; - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - - hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd, - D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &device ); - ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL, - "IDirect3D8_CreateDevice failed with %08x\n", hr); - if(!device) + if (!(device = create_device(d3d8, window, window, TRUE))) { - skip("Failed to create a d3d device\n"); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } @@ -2089,14 +1955,11 @@ static void test_render_zero_triangles(void) IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); cleanup: - if (device) - { - UINT refcount = IDirect3DDevice8_Release(device); - ok(!refcount, "Device has %u references left.\n", refcount); - } IDirect3D8_Release(d3d8); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_depth_stencil_reset(void) @@ -2752,37 +2615,20 @@ done: static void test_ApplyStateBlock(void) { - D3DPRESENT_PARAMETERS d3dpp; - IDirect3DDevice8 *device = NULL; + IDirect3DDevice8 *device; IDirect3D8 *d3d8; - HWND hwnd; + HWND window; HRESULT hr; - D3DDISPLAYMODE d3ddm; DWORD received, token; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d8 = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d8, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &d3ddm ); - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = 800; - d3dpp.BackBufferHeight = 600; - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - - hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, - D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &device ); - ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL, - "IDirect3D8_CreateDevice failed with %#x\n", hr); - if(!device) + if (!(device = create_device(d3d8, window, window, TRUE))) { - skip("Failed to create a d3d device\n"); + skip("Failed to create a 3D device, skipping test.\n"); goto cleanup; } @@ -2812,7 +2658,7 @@ static void test_ApplyStateBlock(void) IDirect3DDevice8_Release(device); cleanup: IDirect3D8_Release(d3d8); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_depth_stencil_size(void) @@ -2971,13 +2817,12 @@ done: static void test_wrong_shader(void) { - HRESULT hr; - IDirect3DDevice8 *device = NULL; - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE d3ddm; + IDirect3DDevice8 *device; IDirect3D8 *d3d; + ULONG refcount; DWORD vs, ps; - HWND hwnd; + HWND window; + HRESULT hr; static const DWORD vs_2_0[] = { @@ -3004,27 +2849,17 @@ static void test_wrong_shader(void) D3DVSD_END() }; - hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, - 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(!!hwnd, "Failed to create a window.\n"); + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); d3d = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); - - IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); - ZeroMemory(&d3dpp, sizeof(d3dpp)); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferWidth = 800; - d3dpp.BackBufferHeight = 600; - d3dpp.BackBufferFormat = d3ddm.Format; - - hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device); - ok(hr == D3D_OK || hr == D3DERR_INVALIDCALL || broken(hr == D3DERR_NOTAVAILABLE), "IDirect3D8_CreateDevice failed with %#08x\n", hr); - if (!device) + if (!(device = create_device(d3d, window, window, TRUE))) { - skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); - goto cleanup; + skip("Failed to create a D3D device, skipping tests.\n"); + IDirect3D8_Release(d3d); + DestroyWindow(window); + return; } hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_ps, &vs, 0); @@ -3039,14 +2874,10 @@ static void test_wrong_shader(void) hr = IDirect3DDevice8_CreatePixelShader(device, ps_2_0, &ps); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr); -cleanup: - if (device) - { - UINT refcount = IDirect3DDevice8_Release(device); - ok(!refcount, "Device has %u references left.\n", refcount); - } + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); IDirect3D8_Release(d3d); - DestroyWindow(hwnd); + DestroyWindow(window); } static void test_mode_change(void)