Commit a875f383 authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

d3dx9: Implement D3DXFilterTexture for cube textures.

parent a3c21e71
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* *
* Copyright 2009 Tony Wasserka * Copyright 2009 Tony Wasserka
* Copyright 2010 Owen Rudge for CodeWeavers * Copyright 2010 Owen Rudge for CodeWeavers
* Copyright 2010 Matteo Bruni for CodeWeavers
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -398,6 +399,7 @@ static void test_D3DXCreateTexture(IDirect3DDevice9 *device) ...@@ -398,6 +399,7 @@ static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
static void test_D3DXFilterTexture(IDirect3DDevice9 *device) static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
{ {
IDirect3DTexture9 *tex; IDirect3DTexture9 *tex;
IDirect3DCubeTexture9 *cubetex;
HRESULT hr; HRESULT hr;
hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL); hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
...@@ -433,7 +435,6 @@ static void test_D3DXFilterTexture(IDirect3DDevice9 *device) ...@@ -433,7 +435,6 @@ static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
else else
skip("Failed to create texture\n"); skip("Failed to create texture\n");
hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL); hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
...@@ -444,6 +445,25 @@ static void test_D3DXFilterTexture(IDirect3DDevice9 *device) ...@@ -444,6 +445,25 @@ static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
} }
else else
skip("Failed to create texture\n"); 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) START_TEST(texture)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright 2009 Tony Wasserka * Copyright 2009 Tony Wasserka
* Copyright 2010 Christian Costa * Copyright 2010 Christian Costa
* Copyright 2010 Owen Rudge for CodeWeavers * Copyright 2010 Owen Rudge for CodeWeavers
* Copyright 2010 Matteo Bruni for CodeWeavers
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -45,6 +46,21 @@ static UINT make_pow2(UINT num) ...@@ -45,6 +46,21 @@ static UINT make_pow2(UINT num)
return result; 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, HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture,
CONST PALETTEENTRY *palette, CONST PALETTEENTRY *palette,
UINT srclevel, UINT srclevel,
...@@ -52,6 +68,7 @@ HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture, ...@@ -52,6 +68,7 @@ HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture,
{ {
UINT level = srclevel + 1; UINT level = srclevel + 1;
HRESULT hr; HRESULT hr;
D3DRESOURCETYPE type;
TRACE("(%p, %p, %d, %d)\n", texture, palette, srclevel, filter); TRACE("(%p, %p, %d, %d)\n", texture, palette, srclevel, filter);
...@@ -64,46 +81,64 @@ HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture, ...@@ -64,46 +81,64 @@ HRESULT WINAPI D3DXFilterTexture(LPDIRECT3DBASETEXTURE9 texture,
if (srclevel >= IDirect3DBaseTexture9_GetLevelCount(texture)) if (srclevel >= IDirect3DBaseTexture9_GetLevelCount(texture))
return D3DERR_INVALIDCALL; return D3DERR_INVALIDCALL;
switch (IDirect3DBaseTexture9_GetType(texture)) switch (type = IDirect3DBaseTexture9_GetType(texture))
{ {
case D3DRTYPE_TEXTURE: case D3DRTYPE_TEXTURE:
case D3DRTYPE_CUBETEXTURE:
{ {
IDirect3DSurface9 *topsurf, *mipsurf; IDirect3DSurface9 *topsurf, *mipsurf;
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
int i, numfaces;
if (filter == D3DX_DEFAULT) if (type == D3DRTYPE_TEXTURE)
{ {
numfaces = 1;
IDirect3DTexture9_GetLevelDesc((IDirect3DTexture9*) texture, srclevel, &desc); 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)) if (is_pow2(desc.Width) && is_pow2(desc.Height))
filter = D3DX_FILTER_BOX; filter = D3DX_FILTER_BOX;
else else
filter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER; filter = D3DX_FILTER_BOX | D3DX_FILTER_DITHER;
} }
hr = IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) texture, srclevel, &topsurf); for (i = 0; i < numfaces; i++)
if (FAILED(hr))
return D3DERR_INVALIDCALL;
while (IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) texture, level, &mipsurf) == D3D_OK)
{ {
hr = D3DXLoadSurfaceFromSurface(mipsurf, palette, NULL, topsurf, palette, NULL, filter, 0); level = srclevel + 1;
IDirect3DSurface9_Release(mipsurf); hr = get_surface(type, texture, i, srclevel, &topsurf);
if (FAILED(hr)) 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; return D3D_OK;
} }
default: default:
FIXME("Implement volume and cube texture filtering\n"); FIXME("Implement volume texture filtering\n");
return E_NOTIMPL; return E_NOTIMPL;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment