[5/5] d3d9: Add a render target test
H. Verbeet
hverbeet at gmail.com
Tue Dec 19 12:25:48 CST 2006
Test if the stuff I just sent works.
Changelog:
- Add a render target test
-------------- next part --------------
---
dlls/d3d9/tests/Makefile.in | 1
dlls/d3d9/tests/rendertarget.c | 156 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 157 insertions(+), 0 deletions(-)
diff --git a/dlls/d3d9/tests/Makefile.in b/dlls/d3d9/tests/Makefile.in
index cab2eee..805c159 100644
--- a/dlls/d3d9/tests/Makefile.in
+++ b/dlls/d3d9/tests/Makefile.in
@@ -8,6 +8,7 @@ EXTRALIBS = -ldxerr9 -luuid -ldxguid
CTESTS = \
device.c \
+ rendertarget.c \
shader.c \
stateblock.c \
surface.c \
diff --git a/dlls/d3d9/tests/rendertarget.c b/dlls/d3d9/tests/rendertarget.c
new file mode 100644
index 0000000..f10dcb6
--- /dev/null
+++ b/dlls/d3d9/tests/rendertarget.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2006 Henri Verbeet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#define COBJMACROS
+#include <d3d9.h>
+#include "wine/test.h"
+
+static HWND create_window(void)
+{
+ WNDCLASS wc = {0};
+ wc.lpfnWndProc = &DefWindowProc;
+ wc.lpszClassName = "d3d9_test_wc";
+ RegisterClass(&wc);
+
+ return CreateWindow("d3d9_test_wc", "d3d9_test",
+ 0, 0, 0, 10, 10, 0, 0, 0, 0);
+}
+
+static IDirect3DDevice9 *init_d3d9(HMODULE d3d9_handle)
+{
+ IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
+ IDirect3D9 *d3d9_ptr = 0;
+ IDirect3DDevice9 *device_ptr = 0;
+ D3DPRESENT_PARAMETERS present_parameters;
+ HRESULT hr;
+
+ d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
+ ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
+ if (!d3d9_create) return NULL;
+
+ d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
+ ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
+ if (!d3d9_ptr) return NULL;
+
+ ZeroMemory(&present_parameters, sizeof(present_parameters));
+ present_parameters.Windowed = TRUE;
+ present_parameters.hDeviceWindow = create_window();
+ present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
+
+ hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
+ NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
+ ok(SUCCEEDED(hr), "IDirect3D_CreateDevice returned %#x\n", hr);
+
+ return device_ptr;
+}
+
+static void test_rendertarget(IDirect3DDevice9 *device_ptr, DWORD mrt_count)
+{
+ DWORD idx;
+ HRESULT hr;
+ ULONG refcount;
+ IDirect3DSurface9 *back_buffer = NULL;
+ IDirect3DSurface9 *render_target = NULL;
+ IDirect3DSurface9 *tmp = NULL;
+
+ /* Get the backbuffer */
+ hr = IDirect3DDevice9_GetRenderTarget(device_ptr, 0, &back_buffer);
+ ok(hr == D3D_OK && back_buffer != NULL, "GetRenderTarget 0 returned: hr %#x, back_buffer %p."
+ " Expected hr %#x, back_buffer != %p\n", hr, back_buffer, D3D_OK, NULL);
+
+ hr = IDirect3DDevice9_CreateRenderTarget(device_ptr, 10, 10, D3DFMT_A8R8G8B8,
+ D3DMULTISAMPLE_NONE, 0, FALSE, &render_target, NULL);
+ ok(SUCCEEDED(hr), "Failed to create render target (%#x)\n", hr);
+ ok(render_target != NULL, "CreateRenderTarget returned a NULL render target\n");
+
+ for (idx = 0; idx < mrt_count; ++idx)
+ {
+ /* Set */
+ hr = IDirect3DDevice9_SetRenderTarget(device_ptr, idx, render_target);
+ ok(hr == D3D_OK, "SetRenderTarget %d returned: hr %#x."
+ " Expected hr %#x\n", idx, hr, D3D_OK);
+
+ /* Get */
+ tmp = NULL;
+ IDirect3DDevice9_GetRenderTarget(device_ptr, idx, &tmp);
+ ok(hr == D3D_OK && tmp == render_target, "GetRenderTarget %d returned: hr %#x, tmp %p."
+ " Expected hr %#x, tmp %p\n", idx, hr, tmp, D3D_OK, render_target);
+ refcount = IDirect3DSurface9_Release(tmp);
+ ok(refcount == 1, "Release %d returned %u. Expected 1\n", idx, refcount);
+
+ /* Unset */
+ hr = IDirect3DDevice9_SetRenderTarget(device_ptr, idx, NULL);
+ if (idx)
+ {
+ ok(hr == D3D_OK, "SetRenderTarget %d returned: hr %#x."
+ " Expected hr %#x\n", idx, hr, D3D_OK);
+
+ /* Get again */
+ tmp = (IDirect3DSurface9 *)0x1337c0d3;
+ IDirect3DDevice9_GetRenderTarget(device_ptr, idx, &tmp);
+ ok(hr == D3D_OK && tmp == NULL, "GetRenderTarget %d returned: hr %#x, tmp %p."
+ " Expected hr %#x, tmp %p\n", idx, hr, tmp, D3DERR_INVALIDCALL, NULL);
+ } else {
+ /* Setting the first render target to NULL should return D3DERR_INVALIDCALL */
+ ok(hr == D3DERR_INVALIDCALL, "SetRenderTarget 0 returned: hr %#x."
+ " Expected hr %#x\n", hr, D3DERR_INVALIDCALL);
+
+ /* Set the original backbuffer */
+ hr = IDirect3DDevice9_SetRenderTarget(device_ptr, idx, back_buffer);
+ ok(hr == D3D_OK, "SetRenderTarget 0 returned: hr %#x."
+ " Expected hr %#x\n", hr, D3D_OK);
+ }
+ }
+
+ /* Setting an invalid render target index should return D3DERR_INVALIDCALL */
+ hr = IDirect3DDevice9_SetRenderTarget(device_ptr, mrt_count, render_target);
+ ok(hr == D3DERR_INVALIDCALL, "SetRenderTarget returned: hr %#x."
+ " Expected hr %#x\n", hr, D3DERR_INVALIDCALL);
+
+ /* Getting an invalid render target index should return D3DERR_INVALIDCALL */
+ tmp = (IDirect3DSurface9 *)0x1337c0d3;
+ IDirect3DDevice9_GetRenderTarget(device_ptr, mrt_count, &tmp);
+ ok(hr == D3DERR_INVALIDCALL && tmp == NULL, "GetRenderTarget returned: hr %#x, tmp %p."
+ " Expected hr %#x, tmp %p\n", hr, tmp, D3DERR_INVALIDCALL, NULL);
+
+ refcount = IDirect3DSurface9_Release(back_buffer);
+ ok(!refcount, "Release returned %u. Expected 0\n", refcount);
+
+ refcount = IDirect3DSurface9_Release(render_target);
+ ok(!refcount, "Release returned %u. Expected 0\n", refcount);
+}
+
+START_TEST(rendertarget)
+{
+ D3DCAPS9 caps;
+ HMODULE d3d9_handle;
+ IDirect3DDevice9 *device_ptr;
+
+ d3d9_handle = LoadLibraryA("d3d9.dll");
+ if (!d3d9_handle)
+ {
+ trace("Could not load d3d9.dll, skipping tests\n");
+ return;
+ }
+
+ device_ptr = init_d3d9(d3d9_handle);
+ if (!device_ptr) return;
+
+ IDirect3DDevice9_GetDeviceCaps(device_ptr, &caps);
+
+ test_rendertarget(device_ptr, caps.NumSimultaneousRTs);
+}
More information about the wine-patches
mailing list