Signed-off-by: Paul Gofman <gofmanp(a)gmail.com>
---
v2:
- use 'struct vec3' instead of float array.
dlls/d3d9/tests/device.c | 102 +++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 0f7bc75393..7d70f9758d 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -13174,6 +13174,107 @@ static void test_multiply_transform(void)
DestroyWindow(window);
}
+static void test_vertex_buffer_read_write(void)
+{
+ IDirect3DVertexBuffer9 *buffer;
+ IDirect3DDevice9 *device;
+ IDirect3D9 *d3d;
+ ULONG refcount;
+ unsigned int i;
+ float *data;
+ HWND window;
+ HRESULT hr;
+
+ static const struct vec3 tri[] =
+ {
+ {-1.0f, -1.0f, 0.0f},
+ {-1.0f, 1.0f, 0.0f},
+ { 1.0f, 1.0f, 0.0f},
+ };
+
+ window = create_window();
+ d3d = Direct3DCreate9(D3D_SDK_VERSION);
+ ok(!!d3d, "Failed to create a D3D object.\n");
+ if (!(device = create_device(d3d, window, NULL)))
+ {
+ skip("Failed to create a D3D device, skipping tests.\n");
+ IDirect3D9_Release(d3d);
+ DestroyWindow(window);
+ return;
+ }
+ hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(tri),
+ D3DUSAGE_DYNAMIC, D3DFVF_XYZ, D3DPOOL_DEFAULT, &buffer, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(tri), (void **)&data, D3DLOCK_DISCARD);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ memcpy(data, tri, sizeof(tri));
+ hr = IDirect3DVertexBuffer9_Unlock(buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ /* Draw using the buffer to make wined3d create BO. */
+ hr = IDirect3DDevice9_SetStreamSource(device, 0, buffer, 0, sizeof(*tri));
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_BeginScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 1);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_EndScene(device);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(tri), (void **)&data, D3DLOCK_NOOVERWRITE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ for (i = 0; i < 3; ++i)
+ data[i] = 3.0f;
+ hr = IDirect3DVertexBuffer9_Unlock(buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(tri), (void **)&data, D3DLOCK_NOOVERWRITE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ for (i = 0; i < 3; ++i)
+ ok(data[i] == 3.0f, "Got unexpected value %.8e, i %u.\n", data[i], i);
+ hr = IDirect3DVertexBuffer9_Unlock(buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(tri), (void **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ for (i = 0; i < 3; ++i)
+ todo_wine ok(data[i] == 3.0f, "Got unexpected value %.8e, i %u.\n", data[i], i);
+ hr = IDirect3DVertexBuffer9_Unlock(buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(tri), (void **)&data, D3DLOCK_NOOVERWRITE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ for (i = 0; i < 3; ++i)
+ todo_wine ok(data[i] == 3.0f, "Got unexpected value %.8e, i %u.\n", data[i], i);
+ hr = IDirect3DVertexBuffer9_Unlock(buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(tri), (void **)&data, 0);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ for (i = 0; i < 3; ++i)
+ data[i] = 4.0f;
+ hr = IDirect3DVertexBuffer9_Unlock(buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ hr = IDirect3DVertexBuffer9_Lock(buffer, 0, sizeof(tri), (void **)&data, D3DLOCK_NOOVERWRITE);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ for (i = 0; i < 3; ++i)
+ ok(data[i] == 4.0f, "Got unexpected value %.8e, i %u.\n", data[i], i);
+ hr = IDirect3DVertexBuffer9_Unlock(buffer);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+ IDirect3DVertexBuffer9_Release(buffer);
+ refcount = IDirect3DDevice9_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ IDirect3D9_Release(d3d);
+ DestroyWindow(window);
+}
+
START_TEST(device)
{
WNDCLASSA wc = {0};
@@ -13299,6 +13400,7 @@ START_TEST(device)
test_device_caps();
test_resource_access();
test_multiply_transform();
+ test_vertex_buffer_read_write();
UnregisterClassA("d3d9_test_wc", GetModuleHandleA(NULL));
}
--
2.20.1