From 5fbf895da683c21a89ad6a5e1433279c241b564f Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 11 Jun 2009 10:24:30 +0200 Subject: [PATCH] wined3d: Use the format info to calculate compressed surface pitch in IWineD3DBaseSurfaceImpl_GetPitch(). --- dlls/wined3d/surface_base.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dlls/wined3d/surface_base.c b/dlls/wined3d/surface_base.c index f0acb87cfa..2120d19e64 100644 --- a/dlls/wined3d/surface_base.c +++ b/dlls/wined3d/surface_base.c @@ -332,19 +332,19 @@ HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface) { IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface; - WINED3DFORMAT format = This->resource.format_desc->format; + const struct GlPixelFormatDesc *format_desc = This->resource.format_desc; DWORD ret; TRACE("(%p)\n", This); - /* DXTn formats don't have exact pitches as they are to the new row of blocks, - where each block is 4x4 pixels, 8 bytes (dxt1) and 16 bytes (dxt2/3/4/5) - ie pitch = (width/4) * bytes per block */ - if (format == WINED3DFMT_DXT1) /* DXT1 is 8 bytes per block */ - ret = ((This->currentDesc.Width + 3) >> 2) << 3; - else if (format == WINED3DFMT_DXT2 || format == WINED3DFMT_DXT3 || - format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */ - ret = ((This->currentDesc.Width + 3) >> 2) << 4; - else { + if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED) + { + /* Since compressed formats are block based, pitch means the amount of + * bytes to the next row of block rather than the next row of pixels. */ + UINT row_block_count = (This->currentDesc.Width + format_desc->block_width - 1) / format_desc->block_width; + ret = row_block_count * format_desc->block_byte_count; + } + else + { unsigned char alignment = This->resource.wineD3DDevice->surface_alignment; ret = This->resource.format_desc->byte_count * This->currentDesc.Width; /* Bytes / row */ ret = (ret + alignment - 1) & ~(alignment - 1);