From d6ba069d9e07590d2086dcd9489812b2cd598ef0 Mon Sep 17 00:00:00 2001 From: Alexander Dorofeyev Date: Thu, 3 Apr 2008 00:12:16 +0300 Subject: [PATCH] wined3d: Improve detection of device palette change. --- dlls/d3d8/tests/visual.c | 56 +++++++++++++++++++----------------------- dlls/wined3d/cubetexture.c | 13 ++++++++++ dlls/wined3d/device.c | 18 +++++++++++++- dlls/wined3d/surface.c | 18 ++++++++------ dlls/wined3d/texture.c | 11 +++++++++ dlls/wined3d/wined3d_private.h | 2 ++ 6 files changed, 78 insertions(+), 40 deletions(-) diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c index 013e818942c..4a9100f7c94 100644 --- a/dlls/d3d8/tests/visual.c +++ b/dlls/d3d8/tests/visual.c @@ -1041,14 +1041,12 @@ static void p8_texture_test(IDirect3DDevice8 *device) ok(red == 0xff && blue == 0 && green == 0, "got color %08x, expected 0x00ff0000\n", color); - todo_wine { - color = getPixelColor(device, 32, 320); - red = (color & 0x00ff0000) >> 16; - green = (color & 0x0000ff00) >> 8; - blue = (color & 0x000000ff) >> 0; - ok(red == 0 && blue == 0xff && green == 0, - "got color %08x, expected 0x000000ff\n", color); - } + color = getPixelColor(device, 32, 320); + red = (color & 0x00ff0000) >> 16; + green = (color & 0x0000ff00) >> 8; + blue = (color & 0x000000ff) >> 0; + ok(red == 0 && blue == 0xff && green == 0, + "got color %08x, expected 0x000000ff\n", color); hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 0.0, 0); ok(hr == D3D_OK, "IDirect3DDevice8_Clear failed, hr = %08x\n", hr); @@ -1069,14 +1067,12 @@ static void p8_texture_test(IDirect3DDevice8 *device) hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr); - todo_wine { - color = getPixelColor(device, 32, 32); - red = (color & 0x00ff0000) >> 16; - green = (color & 0x0000ff00) >> 8; - blue = (color & 0x000000ff) >> 0; - ok(red == 0 && blue == 0xff && green == 0, - "got color %08x, expected 0x000000ff\n", color); - } + color = getPixelColor(device, 32, 32); + red = (color & 0x00ff0000) >> 16; + green = (color & 0x0000ff00) >> 8; + blue = (color & 0x000000ff) >> 0; + ok(red == 0 && blue == 0xff && green == 0, + "got color %08x, expected 0x000000ff\n", color); /* Test palettes with alpha */ IDirect3DDevice8_GetDeviceCaps(device, &caps); @@ -1134,21 +1130,19 @@ static void p8_texture_test(IDirect3DDevice8 *device) hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); ok(hr == D3D_OK, "IDirect3DDevice8_Present failed, hr = %08x\n", hr); - todo_wine { - color = getPixelColor(device, 32, 32); - red = (color & 0x00ff0000) >> 16; - green = (color & 0x0000ff00) >> 8; - blue = (color & 0x000000ff) >> 0; - ok(red >= 0x7e && red <= 0x81 && blue == 0 && green == 0, - "got color %08x, expected 0x00800000 or near\n", color); - - color = getPixelColor(device, 32, 320); - red = (color & 0x00ff0000) >> 16; - green = (color & 0x0000ff00) >> 8; - blue = (color & 0x000000ff) >> 0; - ok(red == 0 && blue >= 0x7e && blue <= 0x81 && green == 0, - "got color %08x, expected 0x00000080 or near\n", color); - } + color = getPixelColor(device, 32, 32); + red = (color & 0x00ff0000) >> 16; + green = (color & 0x0000ff00) >> 8; + blue = (color & 0x000000ff) >> 0; + ok(red >= 0x7e && red <= 0x81 && blue == 0 && green == 0, + "got color %08x, expected 0x00800000 or near\n", color); + + color = getPixelColor(device, 32, 320); + red = (color & 0x00ff0000) >> 16; + green = (color & 0x0000ff00) >> 8; + blue = (color & 0x000000ff) >> 0; + ok(red == 0 && blue >= 0x7e && blue <= 0x81 && green == 0, + "got color %08x, expected 0x00000080 or near\n", color); } hr = IDirect3DDevice8_SetTexture(device, 0, NULL); diff --git a/dlls/wined3d/cubetexture.c b/dlls/wined3d/cubetexture.c index c44b3f9b91f..175a2cd4130 100644 --- a/dlls/wined3d/cubetexture.c +++ b/dlls/wined3d/cubetexture.c @@ -125,6 +125,19 @@ static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) { } IWineD3DCubeTexture_BindTexture(iface); + if (This->resource.format == WINED3DFMT_P8 || This->resource.format == WINED3DFMT_A8P8) { + for (i = 0; i < This->baseTexture.levels; i++) { + for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) { + if(palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[j][i])) { + TRACE("Reloading surface because the d3d8/9 palette was changed\n"); + /* TODO: This is not necessarily needed with hw palettized texture support */ + IWineD3DSurface_LoadLocation(This->surfaces[j][i], SFLAG_INSYSMEM, NULL); + /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */ + IWineD3DSurface_ModifyLocation(This->surfaces[j][i], SFLAG_INTEXTURE, FALSE); + } + } + } + } /* If the texture is marked dirty or the srgb sampler setting has changed since the last load then reload the surfaces */ if (This->baseTexture.dirty) { for (i = 0; i < This->baseTexture.levels; i++) { diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index dd0461c018f..76ab604a0d7 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -5490,6 +5490,18 @@ static HRESULT WINAPI IWineD3DDeviceImpl_ValidateDevice(IWineD3DDevice *iface, return WINED3D_OK; } +static void dirtify_p8_texture_samplers(IWineD3DDeviceImpl *device) +{ + int i; + + for (i = 0; i < MAX_COMBINED_SAMPLERS; i++) { + IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl*)device->stateBlock->textures[i]; + if (texture && (texture->resource.format == WINED3DFMT_P8 || texture->resource.format == WINED3DFMT_A8P8)) { + IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(i)); + } + } +} + static HRESULT WINAPI IWineD3DDeviceImpl_SetPaletteEntries(IWineD3DDevice *iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; int j; @@ -5531,6 +5543,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPaletteEntries(IWineD3DDevice *ifa This->palettes[PaletteNumber][j].peBlue = pEntries[j].peBlue; This->palettes[PaletteNumber][j].peFlags = pEntries[j].peFlags; } + if (PaletteNumber == This->currentPalette) dirtify_p8_texture_samplers(This); TRACE("(%p) : returning\n", This); return WINED3D_OK; } @@ -5565,7 +5578,10 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetCurrentTexturePalette(IWineD3DDevi return WINED3DERR_INVALIDCALL; } /*TODO: stateblocks */ - This->currentPalette = PaletteNumber; + if (This->currentPalette != PaletteNumber) { + This->currentPalette = PaletteNumber; + dirtify_p8_texture_samplers(This); + } TRACE("(%p) : returning\n", This); return WINED3D_OK; } diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 91bc419eb88..641c2490ed0 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -499,6 +499,15 @@ void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface) { ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD); } + if (This->resource.format == WINED3DFMT_P8 || This->resource.format == WINED3DFMT_A8P8) { + if(palette9_changed(This)) { + TRACE("Reloading surface because the d3d8/9 palette was changed\n"); + /* TODO: This is not necessarily needed with hw palettized texture support */ + IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL); + /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */ + IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE); + } + } ENTER_GL(); glEnable(This->glDescription.target);/* make sure texture support is enabled in this context */ if (!This->glDescription.level) { @@ -2149,7 +2158,7 @@ static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface, CONVERT_TYPES conve } } -static BOOL palette9_changed(IWineD3DSurfaceImpl *This) { +BOOL palette9_changed(IWineD3DSurfaceImpl *This) { IWineD3DDeviceImpl *device = This->resource.wineD3DDevice; if(This->palette || (This->resource.format != WINED3DFMT_P8 && This->resource.format != WINED3DFMT_A8P8)) { @@ -2227,13 +2236,6 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BO /* Make sure the texture is reloaded because of the color key change, this kills performance though :( */ /* TODO: This is not necessarily needed with hw palettized texture support */ This->Flags &= ~SFLAG_INTEXTURE; - } else if(palette9_changed(This)) { - TRACE("Reloading surface because the d3d8/9 palette was changed\n"); - /* TODO: This is not necessarily needed with hw palettized texture support */ - IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL); - - /* Make sure the texture is reloaded because of the color key change, this kills performance though :( */ - This->Flags &= ~SFLAG_INTEXTURE; } else { TRACE("surface is already in texture\n"); return WINED3D_OK; diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index a6919ef2f1c..9c50da6459b 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -116,6 +116,17 @@ static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) { IWineD3DTexture_BindTexture(iface); + if (This->resource.format == WINED3DFMT_P8 || This->resource.format == WINED3DFMT_A8P8) { + for (i = 0; i < This->baseTexture.levels; i++) { + if(palette9_changed((IWineD3DSurfaceImpl *)This->surfaces[i])) { + TRACE("Reloading surface because the d3d8/9 palette was changed\n"); + /* TODO: This is not necessarily needed with hw palettized texture support */ + IWineD3DSurface_LoadLocation(This->surfaces[i], SFLAG_INSYSMEM, NULL); + /* Make sure the texture is reloaded because of the palette change, this kills performance though :( */ + IWineD3DSurface_ModifyLocation(This->surfaces[i], SFLAG_INTEXTURE, FALSE); + } + } + } /* If the texture is marked dirty or the srgb sampler setting has changed since the last load then reload the surfaces */ if (This->baseTexture.dirty) { for (i = 0; i < This->baseTexture.levels; i++) { diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index fac54331fb8..652d86df40e 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1409,6 +1409,8 @@ typedef enum { HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode); +BOOL palette9_changed(IWineD3DSurfaceImpl *This); + /***************************************************************************** * IWineD3DVertexDeclaration implementation structure */ -- 2.11.4.GIT