From aecbb3ad580c1b2c0435c68dd302fa6ba02a15ca Mon Sep 17 00:00:00 2001 From: Matteo Bruni Date: Wed, 17 Oct 2018 23:08:27 +0200 Subject: [PATCH] d3d9/tests: Add a test for drawing with D3DPOOL_SYSTEMMEM buffers. Signed-off-by: Matteo Bruni --- dlls/d3d9/tests/visual.c | 166 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c index 4f26b0d23f9..5d0a6a07c99 100644 --- a/dlls/d3d9/tests/visual.c +++ b/dlls/d3d9/tests/visual.c @@ -24197,6 +24197,171 @@ static void test_color_vertex(void) DestroyWindow(window); } +static void test_systemmem_buffer_draw(void) +{ + static const D3DVERTEXELEMENT9 decl_elements[] = + { + {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, + {1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, + D3DDECL_END() + }; + static const struct + { + struct vec3 position; + DWORD diffuse; + } + quad[] = + { + {{-1.0f, -1.0f, 0.0f}, 0xffff0000}, + {{-1.0f, 1.0f, 0.0f}, 0xff00ff00}, + {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff}, + {{ 1.0f, 1.0f, 0.0f}, 0xffffffff}, + }; + static const struct vec3 quad_s0[] = + { + {-1.0f, -1.0f, 0.0f}, + {-1.0f, 1.0f, 0.0f}, + { 1.0f, -1.0f, 0.0f}, + { 1.0f, 1.0f, 0.0f}, + }; + static const DWORD quad_s1[] = + { + 0xffff0000, + 0xff00ff00, + 0xff0000ff, + 0xffffffff, + }; + static const short indices[] = {0, 1, 2, 3}; + IDirect3DVertexDeclaration9 *vertex_declaration; + IDirect3DVertexBuffer9 *vb, *vb_s0, *vb_s1; + IDirect3DIndexBuffer9 *ib; + IDirect3DDevice9 *device; + IDirect3D9 *d3d; + D3DCOLOR colour; + ULONG refcount; + HWND window; + HRESULT hr; + BYTE *data; + + window = create_window(); + ok(!!window, "Failed to create a window.\n"); + + d3d = Direct3DCreate9(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); + if (!(device = create_device(d3d, window, window, TRUE))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + IDirect3D9_Release(d3d); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE); + ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr); + + hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_SYSTEMMEM, &vb, NULL); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + hr = IDirect3DVertexBuffer9_Lock(vb, 0, sizeof(quad), (void **)&data, 0); + ok(SUCCEEDED(hr), "Failed to map vertex buffer, hr %#x.\n", hr); + memcpy(data, quad, sizeof(quad)); + hr = IDirect3DVertexBuffer9_Unlock(vb); + ok(SUCCEEDED(hr), "Failed to unmap vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0); + ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr); + + hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE); + ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetStreamSource(device, 0, vb, 0, sizeof(*quad)); + ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr); + + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour); + + hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0, + D3DFMT_INDEX16, D3DPOOL_SYSTEMMEM, &ib, NULL); + ok(SUCCEEDED(hr), "Failed to create index buffer, hr %#x.\n", hr); + hr = IDirect3DIndexBuffer9_Lock(ib, 0, sizeof(indices), (void **)&data, 0); + ok(SUCCEEDED(hr), "Failed to map index buffer, hr %#x.\n", hr); + memcpy(data, indices, sizeof(indices)); + hr = IDirect3DIndexBuffer9_Unlock(ib); + ok(SUCCEEDED(hr), "Failed to unmap index buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0); + ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr); + + hr = IDirect3DDevice9_SetIndices(device, ib); + ok(SUCCEEDED(hr), "Failed to set index buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 0, 4, 0, 2); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour); + + hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration); + ok(SUCCEEDED(hr), "Failed to create vertex declaration, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration); + ok(SUCCEEDED(hr), "Failed to set vertex declaration, hr %#x.\n", hr); + + hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_s0), 0, 0, D3DPOOL_SYSTEMMEM, &vb_s0, NULL); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + hr = IDirect3DVertexBuffer9_Lock(vb_s0, 0, sizeof(quad_s0), (void **)&data, 0); + ok(SUCCEEDED(hr), "Failed to map vertex buffer, hr %#x.\n", hr); + memcpy(data, quad_s0, sizeof(quad_s0)); + hr = IDirect3DVertexBuffer9_Unlock(vb_s0); + ok(SUCCEEDED(hr), "Failed to unmap vertex buffer, hr %#x.\n", hr); + hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad_s1), 0, 0, D3DPOOL_SYSTEMMEM, &vb_s1, NULL); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + hr = IDirect3DVertexBuffer9_Lock(vb_s1, 0, sizeof(quad_s1), (void **)&data, 0); + ok(SUCCEEDED(hr), "Failed to map vertex buffer, hr %#x.\n", hr); + memcpy(data, quad_s1, sizeof(quad_s1)); + hr = IDirect3DVertexBuffer9_Unlock(vb_s1); + ok(SUCCEEDED(hr), "Failed to unmap vertex buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice9_SetStreamSource(device, 0, vb_s0, 0, sizeof(*quad_s0)); + ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetStreamSource(device, 1, vb_s1, 0, sizeof(*quad_s1)); + ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x77777777, 0.0f, 0); + ok(SUCCEEDED(hr), "Failed to clear depth/stencil, hr %#x.\n", hr); + + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 0, 4, 0, 2); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + colour = getPixelColor(device, 320, 240); + ok(color_match(colour, 0x00007f7f, 1), "Got unexpected colour 0x%08x.\n", colour); + + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); + + IDirect3DVertexBuffer9_Release(vb_s1); + IDirect3DVertexBuffer9_Release(vb_s0); + IDirect3DVertexDeclaration9_Release(vertex_declaration); + IDirect3DIndexBuffer9_Release(ib); + IDirect3DVertexBuffer9_Release(vb); + refcount = IDirect3DDevice9_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + IDirect3D9_Release(d3d); + DestroyWindow(window); +} + START_TEST(visual) { D3DADAPTER_IDENTIFIER9 identifier; @@ -24335,4 +24500,5 @@ START_TEST(visual) test_null_format(); test_map_synchronisation(); test_color_vertex(); + test_systemmem_buffer_draw(); } -- 2.18.1