From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d3dx9_36/tests/texture.c | 29 +++++++++++++++++++++++++---- dlls/d3dx9_36/texture.c | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index 0e426b80a9e..5f491b89a72 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -1330,6 +1330,15 @@ static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord value->w = texelsize->x; }
+static void WINAPI fillfunc_cube_coord(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord, + const D3DXVECTOR3 *texelsize, void *data) +{ + value->x = texcoord->x; + value->y = texcoord->y; + value->z = texcoord->z; + value->w = 1.0f; +} + enum cube_coord { XCOORD = 0, @@ -1388,15 +1397,21 @@ static DWORD get_argb_color(D3DFORMAT format, DWORD x, DWORD y, const D3DLOCKED_ } }
+static BYTE get_s8_clipped(float v) +{ + return (BYTE)(v >= 0.0f ? v * 255 + 0.5f : 0.0f); +} + static DWORD get_expected_argb_color(D3DFORMAT format, const D3DXVECTOR4 *v) { switch (format) { case D3DFMT_A8R8G8B8: - return (BYTE)(v->w * 255 + 0.5f) << 24 - | (BYTE)(v->x * 255 + 0.5f) << 16 - | (BYTE)(v->y * 255 + 0.5f) << 8 - | (BYTE)(v->z * 255 + 0.5f); + + return get_s8_clipped(v->w) << 24 + | get_s8_clipped(v->x) << 16 + | get_s8_clipped(v->y) << 8 + | get_s8_clipped(v->z); case D3DFMT_A1R5G5B5:
return (BYTE)(v->w + 0.5f) << 24 @@ -1479,9 +1494,15 @@ static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL); ok(hr == D3D_OK, "Failed to create a cube texture, hr %#x.\n", hr); + hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL); ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); compare_cube_texture(tex, fillfunc_cube, 1); + + hr = D3DXFillCubeTexture(tex, fillfunc_cube_coord, NULL); + ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); + compare_cube_texture(tex, fillfunc_cube_coord, 1); + IDirect3DCubeTexture9_Release(tex);
hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5, diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c index 04df331c79a..def7e41070b 100644 --- a/dlls/d3dx9_36/texture.c +++ b/dlls/d3dx9_36/texture.c @@ -1288,7 +1288,7 @@ static inline void fill_texture(const struct pixel_format_desc *format, BYTE *po else if (format->type == FORMAT_ARGBF) v = *(DWORD *)&comp_value; else if (format->type == FORMAT_ARGB) - v = comp_value * ((1 << format->bits[c]) - 1) + 0.5f; + v = max(comp_value * ((1 << format->bits[c]) - 1) + 0.5f, 0); else FIXME("Unhandled format type %#x\n", format->type);