From 01199072dd91dfb0d3003a5d7c9c53bf852db164 Mon Sep 17 00:00:00 2001 From: Erich Hoover Date: Mon, 12 Mar 2007 17:07:12 -0600 Subject: [PATCH] wined3d: Fix LockRect memory location calculation for WINED3DFMT_DXT*. --- dlls/d3d9/tests/surface.c | 2 +- dlls/wined3d/surface.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dlls/d3d9/tests/surface.c b/dlls/d3d9/tests/surface.c index 7063a2aa891..189ebf61ed7 100644 --- a/dlls/d3d9/tests/surface.c +++ b/dlls/d3d9/tests/surface.c @@ -218,7 +218,7 @@ static void test_lockrect_offset(IDirect3DDevice9 *device) offset = (BYTE *)locked_rect.pBits - base; expected_offset = (rect.top / dxt_formats[i].block_height) * locked_rect.Pitch + (rect.left / dxt_formats[i].block_width) * dxt_formats[i].block_size; - todo_wine ok(offset == expected_offset, "Got offset %u, expected offset %u for format %s\n", offset, expected_offset, dxt_formats[i].name); + ok(offset == expected_offset, "Got offset %u, expected offset %u for format %s\n", offset, expected_offset, dxt_formats[i].name); hr = IDirect3DSurface9_UnlockRect(surface); ok(SUCCEEDED(hr), "UnlockRect failed (%08x)\n", hr); diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index a295bc7100a..1f4ddb616c4 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -623,8 +623,18 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED return WINED3DERR_INVALIDCALL; } - if (This->resource.format == WINED3DFMT_DXT1) { /* DXT1 is half byte per pixel */ - pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + ((pRect->left * This->bytesPerPixel / 2)); + /* DXTn textures are based on compressed blocks of 4x4 pixels, each + * 16 bytes large (8 bytes in case of DXT1). Because of that Pitch has + * slightly different meaning compared to regular textures. For DXTn + * textures Pitch is the size of a row of blocks, 4 high and "width" + * long. The x offset is calculated differently as well, since moving 4 + * pixels to the right actually moves an entire 4x4 block to right, ie + * 16 bytes (8 in case of DXT1). */ + if (This->resource.format == WINED3DFMT_DXT1) { + pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top / 4) + (pRect->left * 2); + } else if (This->resource.format == WINED3DFMT_DXT2 || This->resource.format == WINED3DFMT_DXT3 + || This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) { + pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top / 4) + (pRect->left * 4); } else { pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel); }