[PATCH 5/6] d3d9/tests: Add a test for GenerateMipSubLevels().
Matteo Bruni
mbruni at codeweavers.com
Thu Feb 15 17:47:54 CST 2018
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
It turns out it does nothing on non-D3DUSAGE_AUTOGENMIPMAP textures.
dlls/d3d9/tests/visual.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+)
diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index 47961af7889..8ff5c058faa 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -5864,6 +5864,136 @@ done:
DestroyWindow(window);
}
+static void test_generate_mipmap(void)
+{
+ static const RECT r1 = {256, 256, 512, 512};
+ static const RECT r2 = {512, 256, 768, 512};
+ static const RECT r3 = {256, 512, 512, 768};
+ static const RECT r4 = {512, 512, 768, 768};
+ static const float quad[] =
+ {
+ -0.5f, -0.5f, 0.1f, 0.0f, 0.0f,
+ -0.5f, 0.5f, 0.1f, 0.0f, 1.0f,
+ 0.5f, -0.5f, 0.1f, 1.0f, 0.0f,
+ 0.5f, 0.5f, 0.1f, 1.0f, 1.0f,
+ };
+ IDirect3DTexture9 *texture, *texture2;
+ IDirect3DSurface9 *surface, *surface2;
+ IDirect3DDevice9 *device;
+ unsigned int x, y;
+ D3DLOCKED_RECT lr;
+ IDirect3D9 *d3d;
+ D3DCOLOR color;
+ ULONG refcount;
+ HWND window;
+ HRESULT hr;
+
+ window = create_window();
+ 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");
+ goto done;
+ }
+
+ hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffff00, 1.0f, 0);
+ ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+
+ /* Make the texture big enough that a mipmap level > 0 is used. */
+ hr = IDirect3DDevice9_CreateTexture(device, 1024, 1024, 0, D3DUSAGE_RENDERTARGET,
+ D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture, 0);
+ ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_CreateTexture(device, 1024, 1024, 0, 0,
+ D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture2, 0);
+ ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+
+ hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
+ ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
+ hr = IDirect3DTexture9_GetSurfaceLevel(texture2, 0, &surface2);
+ ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
+ hr = IDirect3DSurface9_LockRect(surface2, &lr, NULL, 0);
+ ok(SUCCEEDED(hr), "Failed to map surface, hr %#x.\n", hr);
+ for (y = 0; y < 1024; ++y)
+ {
+ for(x = 0; x < 1024; ++x)
+ {
+ DWORD *dst = (DWORD *)((BYTE *)lr.pBits + y * lr.Pitch + x * 4);
+ POINT pt;
+
+ pt.x = x;
+ pt.y = y;
+ if (PtInRect(&r1, pt))
+ *dst = 0xffff0000;
+ else if (PtInRect(&r2, pt))
+ *dst = 0xff00ff00;
+ else if (PtInRect(&r3, pt))
+ *dst = 0xff0000ff;
+ else if (PtInRect(&r4, pt))
+ *dst = 0xff000000;
+ else
+ *dst = 0xffffffff;
+ }
+ }
+ hr = IDirect3DSurface9_UnlockRect(surface2);
+ ok(SUCCEEDED(hr), "Failed to unmap surface, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_UpdateSurface(device, surface2, NULL, surface, NULL);
+ ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
+
+ IDirect3DSurface9_Release(surface2);
+ IDirect3DSurface9_Release(surface);
+ IDirect3DTexture9_Release(texture2);
+
+ hr = IDirect3DTexture9_SetAutoGenFilterType(texture, D3DTEXF_LINEAR);
+ ok(SUCCEEDED(hr), "Failed to set mipmap autogen filter type, hr %#x.\n", hr);
+
+ IDirect3DTexture9_GenerateMipSubLevels(texture);
+
+ hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
+ ok(SUCCEEDED(hr), "Failed to set texture, hr %x.\n", hr);
+ hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
+ ok(SUCCEEDED(hr), "Failed to set mipmap filtering, hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+ ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice9_BeginScene(device);
+ ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
+ hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
+ ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
+ hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, 5 * sizeof(float));
+ 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);
+ IDirect3DTexture9_Release(texture);
+
+ color = getPixelColor(device, 200, 200);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ color = getPixelColor(device, 280, 200);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ color = getPixelColor(device, 360, 200);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ color = getPixelColor(device, 440, 200);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ color = getPixelColor(device, 200, 270);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ color = getPixelColor(device, 280, 270);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ color = getPixelColor(device, 360, 270);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ color = getPixelColor(device, 440, 270);
+ ok(!color, "Unexpected color 0x%08x.\n", color);
+ hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+ ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
+
+ refcount = IDirect3DDevice9_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+done:
+ IDirect3D9_Release(d3d);
+ DestroyWindow(window);
+}
+
static void test_mipmap_autogen(void)
{
IDirect3DSurface9 *surface, *surface2, *surface3, *backbuffer;
@@ -23596,6 +23726,7 @@ START_TEST(visual)
g16r16_texture_test();
pixelshader_blending_test();
texture_transform_flags_test();
+ test_generate_mipmap();
test_mipmap_autogen();
fixed_function_decl_test();
conditional_np2_repeat_test();
--
2.13.6
More information about the wine-devel
mailing list