From b70bc73196fc1d54082966a1773c40544b28231f Mon Sep 17 00:00:00 2001 From: "H. Verbeet" Date: Sat, 2 Jun 2007 15:54:55 +0200 Subject: [PATCH] d3d9: Add a test for calling DrawIndexedPrimitive with a NULL index buffer. --- dlls/d3d9/tests/device.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 365b783e923..710ec46f06d 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -2,6 +2,7 @@ * Copyright (C) 2006 Vitaliy Margolen * Copyright (C) 2006 Chris Robinson * Copyright (C) 2006-2007 Stefan Dösinger(For CodeWeavers) + * Copyright 2007 Henri Verbeet * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1238,6 +1239,122 @@ cleanup: if(hwnd) DestroyWindow(hwnd); } +/* Test what happens when IDirect3DDevice9_DrawIndexedPrimitive is called without a valid index buffer set. */ +static void test_draw_indexed(void) +{ + static const struct { + float position[3]; + DWORD color; + } quad[] = { + {{-1.0f, -1.0f, 0.0f}, 0xffff0000}, + {{-1.0f, 1.0f, 0.0f}, 0xffff0000}, + {{ 1.0f, 1.0f, 0.0f}, 0xffff0000}, + {{ 1.0f, -1.0f, 0.0f}, 0xffff0000}, + }; + WORD indices[] = {0, 1, 2, 3, 0, 2}; + + static const D3DVERTEXELEMENT9 decl_elements[] = { + {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, + {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, + D3DDECL_END() + }; + + IDirect3DVertexDeclaration9 *vertex_declaration = NULL; + IDirect3DVertexBuffer9 *vertex_buffer = NULL; + IDirect3DIndexBuffer9 *index_buffer = NULL; + D3DPRESENT_PARAMETERS present_parameters; + IDirect3DDevice9 *device; + IDirect3D9 *d3d9; + HRESULT hr; + HWND hwnd; + void *ptr; + + hwnd = CreateWindow("static", "d3d9_test", + 0, 0, 0, 10, 10, 0, 0, 0, 0); + if (!hwnd) + { + skip("Failed to create window\n"); + return; + } + + d3d9 = pDirect3DCreate9(D3D_SDK_VERSION); + if (!d3d9) + { + skip("Failed to create IDirect3D9 object\n"); + goto cleanup; + } + + ZeroMemory(&present_parameters, sizeof(present_parameters)); + present_parameters.Windowed = TRUE; + present_parameters.hDeviceWindow = hwnd; + present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD; + + hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device); + if (FAILED(hr) || !device) + { + skip("Failed to create device\n"); + goto cleanup; + } + + hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration); + ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration); + ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr); + + hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_DEFAULT, &vertex_buffer, NULL); + ok(SUCCEEDED(hr), "CreateVertexBuffer failed (0x%08x)\n", hr); + hr = IDirect3DVertexBuffer9_Lock(vertex_buffer, 0, 0, &ptr, D3DLOCK_DISCARD); + ok(SUCCEEDED(hr), "Lock failed (0x%08x)\n", hr); + memcpy(ptr, quad, sizeof(quad)); + hr = IDirect3DVertexBuffer9_Unlock(vertex_buffer); + ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_SetStreamSource(device, 0, vertex_buffer, 0, sizeof(*quad)); + ok(SUCCEEDED(hr), "SetStreamSource failed (0x%08x)\n", hr); + + hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &index_buffer, NULL); + ok(SUCCEEDED(hr), "CreateIndexBuffer failed (0x%08x)\n", hr); + hr = IDirect3DIndexBuffer9_Lock(index_buffer, 0, 0, &ptr, D3DLOCK_DISCARD); + ok(SUCCEEDED(hr), "Lock failed (0x%08x)\n", hr); + memcpy(ptr, indices, sizeof(indices)); + hr = IDirect3DIndexBuffer9_Unlock(index_buffer); + ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE); + ok(SUCCEEDED(hr), "SetRenderState D3DRS_LIGHTING failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr); + + /* NULL index buffer. Should fail */ + hr = IDirect3DDevice9_SetIndices(device, NULL); + ok(SUCCEEDED(hr), "SetIndices failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0 /* BaseVertexIndex */, 0 /* MinIndex */, + 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */); + ok(hr == D3DERR_INVALIDCALL, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n", + hr, D3DERR_INVALIDCALL); + + /* Valid index buffer. Should succeed */ + hr = IDirect3DDevice9_SetIndices(device, index_buffer); + ok(SUCCEEDED(hr), "SetIndices failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0 /* BaseVertexIndex */, 0 /* MinIndex */, + 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */); + ok(SUCCEEDED(hr), "DrawIndexedPrimitive failed (0x%08x)\n", hr); + + hr = IDirect3DDevice9_EndScene(device); + ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr); + + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr); + + IDirect3DVertexBuffer9_Release(vertex_buffer); + IDirect3DIndexBuffer9_Release(index_buffer); + IDirect3DVertexDeclaration9_Release(vertex_declaration); + +cleanup: + if (d3d9) IDirect3D9_Release(d3d9); + if (device) IDirect3DDevice9_Release(device); + if (hwnd) DestroyWindow(hwnd); +} + START_TEST(device) { HMODULE d3d9_handle = LoadLibraryA( "d3d9.dll" ); @@ -1260,5 +1377,6 @@ START_TEST(device) test_scene(); test_limits(); test_depthstenciltest(); + test_draw_indexed(); } } -- 2.11.4.GIT