From 9c2575865625360b12b74360a0652199b299934f Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 28 Feb 2012 19:48:40 +0100 Subject: [PATCH] wined3d: Support color keyed WINED3DFMT_B8G8R8A8_UNORM surfaces. Color keying and alpha channels aren't mutually exclusive. --- dlls/wined3d/state.c | 7 +------ dlls/wined3d/surface.c | 28 ++++++++++++++++++++++++++++ dlls/wined3d/wined3d_private.h | 1 + 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 697432176ef..a5d748a8f56 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -538,12 +538,7 @@ static void state_alpha(struct wined3d_context *context, const struct wined3d_st struct wined3d_surface *surf = surface_from_resource(texture->sub_resources[0]); if (surf->CKeyFlags & WINEDDSD_CKSRCBLT) - { - /* The surface conversion does not do color keying conversion for surfaces that have an alpha - * channel on their own. Likewise, the alpha test shouldn't be set up for color keying if the - * surface has alpha bits */ - if (!surf->resource.format->alpha_mask) enable_ckey = TRUE; - } + enable_ckey = TRUE; } } diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index d2939402b25..9ec3db38615 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -4554,6 +4554,14 @@ HRESULT d3dfmt_get_conv(const struct wined3d_surface *surface, BOOL need_alpha_c } break; + case WINED3DFMT_B8G8R8A8_UNORM: + if (colorkey_active) + { + *conversion_type = WINED3D_CT_CK_ARGB32; + format->conv_byte_count = 4; + } + break; + default: break; } @@ -4765,6 +4773,26 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI } break; + case WINED3D_CT_CK_ARGB32: + { + unsigned int x, y; + for (y = 0; y < height; ++y) + { + source = src + pitch * y; + dest = dst + outpitch * y; + for (x = 0; x < width; ++x) + { + DWORD color = *(const DWORD *)source; + if (color_in_range(&surface->src_blt_color_key, color)) + color &= ~0xff000000; + *(DWORD*)dest = color; + source += 4; + dest += 4; + } + } + } + break; + default: ERR("Unsupported conversion type %#x.\n", conversion_type); } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index df817af825e..cd9690c6bc5 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2192,6 +2192,7 @@ enum wined3d_conversion_type WINED3D_CT_CK_5551, WINED3D_CT_CK_RGB24, WINED3D_CT_RGB32_888, + WINED3D_CT_CK_ARGB32, }; HRESULT d3dfmt_get_conv(const struct wined3d_surface *surface, BOOL need_alpha_ck, BOOL use_texturing,