Module: wine Branch: master Commit: 30d5e375e6f432b184ddc76d8d97c630718bd657 URL: http://source.winehq.org/git/wine.git/?a=commit;h=30d5e375e6f432b184ddc76d8d...
Author: Owen Rudge owen@owenrudge.net Date: Thu Jul 22 20:38:23 2010 +0100
d3dx9: Implement D3DXCreateTexture plus tests.
---
dlls/d3dx9_36/tests/texture.c | 161 +++++++++++++++++++++++++++++++++++++++++ dlls/d3dx9_36/texture.c | 12 +++- 2 files changed, 172 insertions(+), 1 deletions(-)
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index f4c74d7..0eaf649 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -155,6 +155,166 @@ static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device) ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8); }
+static void test_D3DXCreateTexture(IDirect3DDevice9 *device) +{ + IDirect3DTexture9 *texture; + D3DSURFACE_DESC desc; + D3DCAPS9 caps; + UINT mipmaps; + HRESULT hr; + + IDirect3DDevice9_GetDeviceCaps(device, &caps); + + hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT); + ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); + + /* width and height tests */ + + hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); + + ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256); + ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256); + + IDirect3DTexture9_Release(texture); + } + + + hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); + + ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1); + ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1); + + IDirect3DTexture9_Release(texture); + } + + + if (caps.TextureCaps & D3DPTEXTURECAPS_POW2) + skip("Hardware only supports pow2 textures\n"); + else + { + hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture); + ok((hr == D3D_OK) || + /* may not work with conditional NPOT */ + ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)), + "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); + + /* Conditional NPOT may create a texture with different dimensions, so allow those + situations instead of returning a fail */ + + ok(desc.Width == 63 || + (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL), + "Returned width %d, expected %d\n", desc.Width, 63); + + ok(desc.Height == 63 || + (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL), + "Returned height %d, expected %d\n", desc.Height, 63); + + IDirect3DTexture9_Release(texture); + } + } + + /* mipmaps */ + + hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + mipmaps = IDirect3DTexture9_GetLevelCount(texture); + ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7); + + IDirect3DTexture9_Release(texture); + } + + + hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + mipmaps = IDirect3DTexture9_GetLevelCount(texture); + ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9); + + IDirect3DTexture9_Release(texture); + } + + + hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + mipmaps = IDirect3DTexture9_GetLevelCount(texture); + ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1); + + IDirect3DTexture9_Release(texture); + } + + + hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + mipmaps = IDirect3DTexture9_GetLevelCount(texture); + ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1); + + IDirect3DTexture9_Release(texture); + } + + /* usage */ + + hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); + hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); + hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); + hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); + hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n"); + + /* format */ + + hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); + ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8); + + IDirect3DTexture9_Release(texture); + } + + + hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture); + ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK); + + if (texture) + { + hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc); + ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8); + + IDirect3DTexture9_Release(texture); + } +} + START_TEST(texture) { HWND wnd; @@ -187,6 +347,7 @@ START_TEST(texture) }
test_D3DXCheckTextureRequirements(device); + test_D3DXCreateTexture(device);
IDirect3DDevice9_Release(device); IDirect3D9_Release(d3d); diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index ad3a1c2..9d547ce 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -185,9 +185,19 @@ HRESULT WINAPI D3DXCreateTexture(LPDIRECT3DDEVICE9 pDevice, D3DPOOL pool, LPDIRECT3DTEXTURE9 *ppTexture) { - FIXME("(%p, %u, %u, %u, %x, %x, %x, %p): semi-stub\n", pDevice, width, height, miplevels, usage, format, + HRESULT hr; + + TRACE("(%p, %u, %u, %u, %x, %x, %x, %p)\n", pDevice, width, height, miplevels, usage, format, pool, ppTexture);
+ if (!pDevice || !ppTexture) + return D3DERR_INVALIDCALL; + + hr = D3DXCheckTextureRequirements(pDevice, &width, &height, &miplevels, usage, &format, pool); + + if (FAILED(hr)) + return hr; + return IDirect3DDevice9_CreateTexture(pDevice, width, height, miplevels, usage, format, pool, ppTexture, NULL); }