Matteo Bruni : d3dx9: Implement D3DXFilterTexture for cube textures.
Alexandre Julliard
julliard at winehq.org
Thu Nov 4 12:52:52 CDT 2010
Module: wine
Branch: master
Commit: a875f3830108c773ec73abf134ef12d54fe2870f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=a875f3830108c773ec73abf134ef12d54fe2870f
Author: Matteo Bruni <mbruni at codeweavers.com>
Date: Wed Oct 13 01:30:34 2010 +0200
d3dx9: Implement D3DXFilterTexture for cube textures.
---
dlls/d3dx9_36/tests/texture.c | 22 +++++++++++++-
dlls/d3dx9_36/texture.c | 65 +++++++++++++++++++++++++++++++---------
2 files changed, 71 insertions(+), 16 deletions(-)
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c
index 6f6c43d..9856800 100644
--- a/dlls/d3dx9_36/tests/texture.c
+++ b/dlls/d3dx9_36/tests/texture.c
@@ -3,6 +3,7 @@
*
* Copyright 2009 Tony Wasserka
* Copyright 2010 Owen Rudge for CodeWeavers
+ * Copyright 2010 Matteo Bruni for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -398,6 +399,7 @@ static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
{
IDirect3DTexture9 *tex;
+ IDirect3DCubeTexture9 *cubetex;
HRESULT hr;
hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
@@ -433,7 +435,6 @@ static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
else
skip("Failed to create texture\n");
-
hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
if (SUCCEEDED(hr))
@@ -444,6 +445,25 @@ static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
}
else
skip("Failed to create texture\n");
+
+ /* Cube texture test */
+ hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
+
+ if (SUCCEEDED(hr))
+ {
+ hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
+ ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
+
+ hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
+ ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
+
+ hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
+ ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
+ }
+ else
+ skip("Failed to create texture\n");
+
+ IDirect3DCubeTexture9_Release(cubetex);
}
START_TEST(texture)
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c
index 2ae818f..5afceb4 100644
--- a/dlls/d3dx9_36/texture.c
+++ b/dlls/d3dx9_36/texture.c
@@ -2,6 +2,7 @@
* Copyright 2009 Tony Wasserka
* Copyright 2010 Christian Costa
* Copyright 2010 Owen Rudge for CodeWeavers
+ * Copyright 2010 Matteo Bruni for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -45,6 +46,21 @@ static UINT make_pow2(UINT num)
return result;
}
+static HRESULT get_surface(D3DRESOURCETYPE type, LPDIRECT3DBASETEXTURE9 tex,
+ int face, UINT level, LPDIRECT3DSURFACE9 *surf)
+{
+ switch (type)
+ {
+ case D3DRTYPE_TEXTURE:
+ return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level, surf);
+ case D3DRTYPE_CUBETEXTURE:
+ return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex, face, level, surf);
+ default:
+ ERR("Unexpected texture type\n");
+ return E_NOTIMPL;
+ }
+}
+
HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture,
CONST PALETTEENTRY *palette,
UINT srclevel,
@@ -52,6 +68,7 @@ HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture,
{
UINT level = srclevel + 1;
HRESULT hr;
+ D3DRESOURCETYPE type;
TRACE("(%p, %p, %d, %d)\n", texture, palette, srclevel, filter);
@@ -64,46 +81,64 @@ HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture,
if (srclevel >= IDirect3DBaseTexture9_GetLevelCount(texture))
return D3DERR_INVALIDCALL;
- switch (IDirect3DBaseTexture9_GetType(texture))
+ switch (type = IDirect3DBaseTexture9_GetType(texture))
{
case D3DRTYPE_TEXTURE:
+ case D3DRTYPE_CUBETEXTURE:
{
IDirect3DSurface9 *topsurf, *mipsurf;
D3DSURFACE_DESC desc;
+ int i, numfaces;
- if (filter == D3DX_DEFAULT)
+ if (type == D3DRTYPE_TEXTURE)
{
+ numfaces = 1;
IDirect3DTexture9_GetLevelDesc((IDirect3DTexture9*) texture, srclevel, &desc);
+ }
+ else
+ {
+ numfaces = 6;
+ IDirect3DCubeTexture9_GetLevelDesc((IDirect3DTexture9*) texture, srclevel, &desc);
+ }
+ if (filter == D3DX_DEFAULT)
+ {
if (is_pow2(desc.Width) && is_pow2(desc.Height))
filter = D3DX_FILTER_BOX;
else
filter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER;
}
- hr = IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) texture, srclevel, &topsurf);
-
- if (FAILED(hr))
- return D3DERR_INVALIDCALL;
-
- while (IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) texture, level, &mipsurf) == D3D_OK)
+ for (i = 0; i < numfaces; i++)
{
- hr = D3DXLoadSurfaceFromSurface(mipsurf, palette, NULL, topsurf, palette, NULL, filter, 0);
- IDirect3DSurface9_Release(mipsurf);
+ level = srclevel + 1;
+ hr = get_surface(type, texture, i, srclevel, &topsurf);
if (FAILED(hr))
- break;
+ return D3DERR_INVALIDCALL;
- level++;
- }
+ while (get_surface(type, texture, i, level, &mipsurf) == D3D_OK)
+ {
+ hr = D3DXLoadSurfaceFromSurface(mipsurf, palette, NULL, topsurf, palette, NULL, filter, 0);
+ IDirect3DSurface9_Release(topsurf);
+ topsurf = mipsurf;
+
+ if (FAILED(hr))
+ break;
+
+ level++;
+ }
- IDirect3DSurface9_Release(topsurf);
+ IDirect3DSurface9_Release(topsurf);
+ if (FAILED(hr))
+ return hr;
+ }
return D3D_OK;
}
default:
- FIXME("Implement volume and cube texture filtering\n");
+ FIXME("Implement volume texture filtering\n");
return E_NOTIMPL;
}
}
More information about the wine-cvs
mailing list