Module: wine Branch: master Commit: 76d153144fb0b7948d9edb32b6f3b89124730b18 URL: http://source.winehq.org/git/wine.git/?a=commit;h=76d153144fb0b7948d9edb32b6...
Author: Fabian Bieler der.fabe@gmx.net Date: Thu Mar 22 17:44:17 2007 +0100
d3d9/tests: Add test for texbem instruction.
---
dlls/d3d9/tests/visual.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 198 insertions(+), 0 deletions(-)
diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c index 5f62edf..33c4231 100644 --- a/dlls/d3d9/tests/visual.c +++ b/dlls/d3d9/tests/visual.c @@ -923,6 +923,198 @@ static void fog_with_shader_test(IDirect3DDevice9 *device) IDirect3DVertexDeclaration9_Release(vertex_declaration); }
+/* test the behavior of the texbem instruction + * with normal 2D and projective 2D textures + */ +static void texbem_test(IDirect3DDevice9 *device) +{ + HRESULT hr; + DWORD color; + unsigned int i, x, y; + + static const DWORD pixel_shader_code[] = { + 0xffff0101, /* ps_1_1*/ + 0x00000042, 0xb00f0000, /* tex t0*/ + 0x00000043, 0xb00f0001, 0xb0e40000, /* texbem t1, t0*/ + 0x00000001, 0x800f0000, 0xb0e40001, /* mov r0, t1*/ + 0x0000ffff + }; + + static const float quad[][7] = { + {-128.0f/640.0f, -128.0f/480.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f}, + {-128.0f/640.0f, 128.0f/480.0f, 0.1f, 0.0f, 1.0f, 0.0f, 1.0f}, + { 128.0f/640.0f, -128.0f/480.0f, 0.1f, 1.0f, 0.0f, 1.0f, 0.0f}, + { 128.0f/640.0f, 128.0f/480.0f, 0.1f, 1.0f, 1.0f, 1.0f, 1.0f}, + }; + static const float quad_proj[][9] = { + {-128.0f/640.0f, -128.0f/480.0f, 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 128.0f}, + {-128.0f/640.0f, 128.0f/480.0f, 0.1f, 0.0f, 1.0f, 0.0f, 128.0f, 0.0f, 128.0f}, + { 128.0f/640.0f, -128.0f/480.0f, 0.1f, 1.0f, 0.0f, 128.0f, 0.0f, 0.0f, 128.0f}, + { 128.0f/640.0f, 128.0f/480.0f, 0.1f, 1.0f, 1.0f, 128.0f, 128.0f, 0.0f, 128.0f}, + }; + + static const D3DVERTEXELEMENT9 decl_elements[][4] = { { + {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, + {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, + {0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1}, + D3DDECL_END() + },{ + {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, + {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, + {0, 20, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1}, + D3DDECL_END() + } }; + + /* use assymetric matrix to test loading */ + float bumpenvmat[4] = {0.0,0.5,-0.5,0.0}; + + IDirect3DVertexDeclaration9 *vertex_declaration = NULL; + IDirect3DPixelShader9 *pixel_shader = NULL; + IDirect3DTexture9 *texture[2] = {NULL, NULL}; + D3DLOCKED_RECT locked_rect; + + /* Generate the textures */ + for(i=0; i<2; i++) + { + hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, 0, i?D3DFMT_A8R8G8B8:D3DFMT_V8U8, + D3DPOOL_MANAGED, &texture[i], NULL); + ok(SUCCEEDED(hr), "CreateTexture failed (0x%08x)\n", hr); + + hr = IDirect3DTexture9_LockRect(texture[i], 0, &locked_rect, NULL, D3DLOCK_DISCARD); + ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr); + for (y = 0; y < 128; ++y) + { + if(i) + { /* Set up black texture with 2x2 texel white spot in the middle */ + DWORD *ptr = (DWORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch)); + for (x = 0; x < 128; ++x) + { + if(y>62 && y<66 && x>62 && x<66) + *ptr++ = 0xffffffff; + else + *ptr++ = 0xff000000; + } + } + else + { /* Set up a displacement map which points away from the center parallel to the closest axis. + * (if multiplied with bumpenvmat) + */ + WORD *ptr = (WORD *)(((BYTE *)locked_rect.pBits) + (y * locked_rect.Pitch)); + for (x = 0; x < 128; ++x) + { + if(abs(x-64)>abs(y-64)) + { + if(x < 64) + *ptr++ = 0xc000; + else + *ptr++ = 0x4000; + } + else + { + if(y < 64) + *ptr++ = 0x0040; + else + *ptr++ = 0x00c0; + } + } + } + } + hr = IDirect3DTexture9_UnlockRect(texture[i], 0); + ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr); + + hr = IDirect3DDevice9_SetTexture(device, i, (IDirect3DBaseTexture9 *)texture[i]); + ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr); + + /* Disable texture filtering */ + hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MINFILTER, D3DTEXF_POINT); + ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MINFILTER failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_MAGFILTER failed (0x%08x)\n", hr); + + hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSU failed (0x%08x)\n", hr); + hr = IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + ok(SUCCEEDED(hr), "SetSamplerState D3DSAMP_ADDRESSV failed (0x%08x)\n", hr); + } + + IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT00, *(LPDWORD)&bumpenvmat[0]); + IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT01, *(LPDWORD)&bumpenvmat[1]); + IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT10, *(LPDWORD)&bumpenvmat[2]); + hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_BUMPENVMAT11, *(LPDWORD)&bumpenvmat[3]); + ok(SUCCEEDED(hr), "SetTextureStageState failed (%08x)\n", hr); + + hr = IDirect3DDevice9_SetVertexShader(device, NULL); + ok(SUCCEEDED(hr), "SetVertexShader failed (%08x)\n", hr); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff00ff, 0.0, 0); + ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed (%08x)\n", hr); + + for(i=0; i<2; i++) + { + if(i) + { + hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4|D3DTTFF_PROJECTED); + ok(SUCCEEDED(hr), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr); + } + + hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements[i], &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_CreatePixelShader(device, pixel_shader_code, &pixel_shader); + ok(SUCCEEDED(hr), "CreatePixelShader failed (%08x)\n", hr); + hr = IDirect3DDevice9_SetPixelShader(device, pixel_shader); + ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr); + + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr); + + if(!i) + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad[0], sizeof(quad[0])); + else + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, &quad_proj[0], sizeof(quad_proj[0])); + ok(SUCCEEDED(hr), "DrawPrimitiveUP 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); + + color = getPixelColor(device, 320-32, 240); + ok(color == 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color); + color = getPixelColor(device, 320+32, 240); + ok(color == 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color); + color = getPixelColor(device, 320, 240-32); + ok(color == 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color); + color = getPixelColor(device, 320, 240+32); + ok(color == 0x00ffffff, "texbem failed: Got color 0x%08x, expected 0x00ffffff.\n", color); + + hr = IDirect3DDevice9_SetPixelShader(device, NULL); + ok(SUCCEEDED(hr), "SetPixelShader failed (%08x)\n", hr); + IDirect3DPixelShader9_Release(pixel_shader); + + hr = IDirect3DDevice9_SetVertexDeclaration(device, NULL); + ok(SUCCEEDED(hr), "SetVertexDeclaration failed (%08x)\n", hr); + IDirect3DVertexDeclaration9_Release(vertex_declaration); + } + + /* clean up */ + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0, 0.0f, 0); + ok(SUCCEEDED(hr), "Clear failed (0x%08x)\n", hr); + + hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); + ok(SUCCEEDED(hr), "SetTextureStageState D3DTSS_TEXTURETRANSFORMFLAGS failed (0x%08x)\n", hr); + + for(i=0; i<2; i++) + { + hr = IDirect3DDevice9_SetTexture(device, i, NULL); + ok(SUCCEEDED(hr), "SetTexture failed (0x%08x)\n", hr); + IDirect3DCubeTexture9_Release(texture[i]); + } +} + START_TEST(visual) { IDirect3DDevice9 *device_ptr; @@ -991,6 +1183,12 @@ START_TEST(visual) } else skip("No vs_1_1 and ps_1_1 support\n");
+ if (caps.PixelShaderVersion >= D3DVS_VERSION(1, 1)) + { + texbem_test(device_ptr); + } + else skip("No ps_1_1 support\n"); + cleanup: if(device_ptr) IDirect3DDevice9_Release(device_ptr); }