wined3d/d3d9: Pitch for DXTn textures can not be 0. With tests.

This commit is contained in:
Vitaliy Margolen 2006-12-02 20:27:36 -07:00 committed by Alexandre Julliard
parent 429c8ac948
commit 81c7c00bb2
2 changed files with 32 additions and 2 deletions

View File

@ -17,6 +17,7 @@
*/
#define COBJMACROS
#include <d3d9.h>
#include <dxerr9.h>
#include "wine/test.h"
static HWND create_window(void)
@ -117,6 +118,7 @@ static void test_surface_alignment(IDirect3DDevice9 *device_ptr)
{
IDirect3DSurface9 *surface_ptr = 0;
HRESULT hr;
int i;
/* Test a sysmem surface as those aren't affected by the hardware's np2 restrictions */
hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device_ptr, 5, 5, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface_ptr, 0);
@ -137,6 +139,34 @@ static void test_surface_alignment(IDirect3DDevice9 *device_ptr)
hr = IDirect3DSurface9_UnlockRect(surface_ptr);
IDirect3DSurface9_Release(surface_ptr);
}
for (i = 0; i < 5; i++)
{
IDirect3DTexture9 *pTexture;
int j, pitch;
hr = IDirect3DDevice9_CreateTexture(device_ptr, 64, 64, 0, 0, MAKEFOURCC('D', 'X', 'T', '1'+i),
D3DPOOL_MANAGED, &pTexture, NULL);
ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture: %s\n", DXGetErrorString9(hr));
if (FAILED(hr)) continue;
for (j = IDirect3DBaseTexture9_GetLevelCount(pTexture) - 1; j >= 0; j--)
{
D3DLOCKED_RECT rc;
D3DSURFACE_DESC descr;
IDirect3DTexture9_GetLevelDesc(pTexture, j, &descr);
hr = IDirect3DTexture9_LockRect(pTexture, j, &rc, NULL, 0);
ok(SUCCEEDED(hr), "IDirect3DTexture9_LockRect: %s\n", DXGetErrorString9(hr));
IDirect3DTexture9_UnlockRect(pTexture, j);
pitch = ((descr.Width + 3) >> 2) << 3;
if (i > 0) pitch <<= 1;
ok(rc.Pitch == pitch, "Wrong pitch for DXT%d lvl[%d (%dx%d)]: expected %d got %d\n",
i + 1, j, descr.Width, descr.Height, pitch, rc.Pitch);
}
IUnknown_Release( pTexture );
}
}
START_TEST(surface)

View File

@ -3023,10 +3023,10 @@ DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface) {
where each block is 4x4 pixels, 8 bytes (dxt1) and 16 bytes (dxt2/3/4/5)
ie pitch = (width/4) * bytes per block */
if (This->resource.format == WINED3DFMT_DXT1) /* DXT1 is 8 bytes per block */
ret = (This->currentDesc.Width >> 2) << 3;
ret = ((This->currentDesc.Width + 3) >> 2) << 3;
else if (This->resource.format == WINED3DFMT_DXT2 || This->resource.format == WINED3DFMT_DXT3 ||
This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */
ret = (This->currentDesc.Width >> 2) << 4;
ret = ((This->currentDesc.Width + 3) >> 2) << 4;
else {
if (NP2_REPACK == wined3d_settings.nonpower2_mode || This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
/* Front and back buffers are always lockes/unlocked on currentDesc.Width */