diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index b9198ea77..710749eb3 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1055,7 +1055,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) Patch_CreateGL(patch); grPatch = patch->hardware; - if (colormap == colormaps || colormap == NULL) + if (colormap == colormaps || colormap == NULL || patch->format == PATCH_FORMAT_RGBA) { // Load the default (green) color in hardware cache HWR_GetPatch(patch); diff --git a/src/r_data.c b/src/r_data.c index d69a5bef5..2372f3691 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -59,37 +59,27 @@ INT16 *hicolormaps; // test a 32k colormap remaps high -> high UINT32 ASTBlendPixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alpha) { RGBA_t output; - INT16 fullalpha = (alpha - (0xFF - foreground.s.alpha)); + #define clamp(c) max(min((c), 0xFF), 0x00) + + INT16 fullalpha = clamp(((INT16)foreground.s.alpha) - (0xFF - alpha)); + if (style == AST_TRANSLUCENT) { - if (fullalpha <= 0) - output.rgba = background.rgba; - else - { - if (fullalpha >= 0xFF) - fullalpha = 0xFF; - - alpha = (UINT8)fullalpha; - - UINT8 beta = 0xFF - alpha; - output.s.red = ((background.s.red * beta) + (foreground.s.red * alpha)) / 0xFF; - output.s.green = ((background.s.green * beta) + (foreground.s.green * alpha)) / 0xFF; - output.s.blue = ((background.s.blue * beta) + (foreground.s.blue * alpha)) / 0xFF; - output.s.alpha = clamp(((INT16)background.s.alpha) + fullalpha); - } + UINT8 beta = 0xFF - fullalpha; + output.s.red = ((background.s.red * beta) + (foreground.s.red * fullalpha)) / 0xFF; + output.s.green = ((background.s.green * beta) + (foreground.s.green * fullalpha)) / 0xFF; + output.s.blue = ((background.s.blue * beta) + (foreground.s.blue * fullalpha)) / 0xFF; + output.s.alpha = clamp(((INT16)background.s.alpha) + fullalpha); } else { - float falpha = ((float)alpha / 255.0f); + float falpha = ((float)fullalpha / 255.0f); float fr = ((float)foreground.s.red * falpha); float fg = ((float)foreground.s.green * falpha); float fb = ((float)foreground.s.blue * falpha); - if (background.s.alpha == 0x00) - output.s.alpha = clamp(fullalpha); - else - output.s.alpha = 0xFF; + output.s.alpha = clamp(((INT16)background.s.alpha) + fullalpha); if (style == AST_ADD) { @@ -119,8 +109,17 @@ UINT32 ASTBlendPixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alph output.s.blue = clamp((int)(background.s.blue * fb)); } // just copy the pixel - else if (style == AST_COPY) - output.rgba = foreground.rgba; + else + { + if (foreground.s.alpha == 0x00) + output.rgba = background.rgba; + else + { + if (foreground.s.alpha != 0x00) + foreground.s.alpha = 0xFF; + output.rgba = foreground.rgba; + } + } } #undef clamp return output.rgba; diff --git a/src/r_patch.c b/src/r_patch.c index 9ed7c5c51..fb7f5d579 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -890,11 +890,11 @@ void Patch_FreeTags(INT32 lowtag, INT32 hightag) void Patch_GenerateFlat(patch_t *patch, pictureflags_t flags) { - UINT8 flip = (flags & (PICFLAGS_XFLIP | PICFLAGS_YFLIP)); + UINT8 flip = flags & (PICFLAGS_XFLIP | PICFLAGS_YFLIP); if (patch->flats[flip] == NULL) { if (patch->format == PATCH_FORMAT_RGBA) - patch->flats[flip] = Picture_Convert(PICFMT_PATCH32, patch->pixels, PICFMT_FLAT32, 0, NULL, 0, 0, 0, 0, flags); + patch->flats[flip] = Picture_Convert(PICFMT_PATCH32, patch, PICFMT_FLAT32, 0, NULL, 0, 0, 0, 0, flags); else patch->flats[flip] = Picture_Convert(PICFMT_PATCH, patch, PICFMT_FLAT16, 0, NULL, 0, 0, 0, 0, flags); } diff --git a/src/v_video.c b/src/v_video.c index 607af034b..a68472330 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -552,6 +552,18 @@ static void transmappedpdraw_i8o32(void *dest, void *source) *d = ASTBlendPixel(*(RGBA_t *)d, v_palette[*(v_colormap + *s)], v_blendmode, v_opacity); } +static UINT32 DoTransparentAlphaBlend(RGBA_t background, RGBA_t foreground) +{ + UINT8 alpha = foreground.s.alpha; + UINT8 beta = 0xFF - alpha; + RGBA_t output; + output.s.red = ((background.s.red * beta) + (foreground.s.red * alpha)) / 0xFF; + output.s.green = ((background.s.green * beta) + (foreground.s.green * alpha)) / 0xFF; + output.s.blue = ((background.s.blue * beta) + (foreground.s.blue * alpha)) / 0xFF; + output.s.alpha = 0xFF; + return output.rgba; +} + // input 32bpp output 8bpp static void standardpdraw_i32o8(void *dest, void *source) { @@ -564,7 +576,7 @@ static void standardpdraw_ia32o8(void *dest, void *source) { RGBA_t src = *(RGBA_t *)source; UINT8 *d = (UINT8 *)dest; - src.rgba = ASTBlendPixel(pMasterPalette[*d], src, AST_TRANSLUCENT, 255); + src.rgba = DoTransparentAlphaBlend(pMasterPalette[*d], src); *d = GetColorLUT(&r_colorlookup, src.s.red, src.s.green, src.s.blue); } static void translucentpdraw_i32o8(void *dest, void *source) @@ -588,7 +600,7 @@ static void standardpdraw_ia32o32(void *dest, void *source) { RGBA_t *s = (RGBA_t *)source; UINT32 *d = (UINT32 *)dest; - *d = ASTBlendPixel(*(RGBA_t *)d, *s, AST_TRANSLUCENT, 255); + *d = DoTransparentAlphaBlend(*(RGBA_t *)d, *s); } static void translucentpdraw_i32o32(void *dest, void *source) {