From f461b76bb0ed9fc96f0e4cb17fd5b990ba5694f4 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Sat, 7 Sep 2019 16:54:26 -0300 Subject: [PATCH] fix translucency --- src/doomdef.h | 4 ++- src/hardware/hw_cache.c | 14 +++++++++-- src/r_data.c | 54 ++++++++--------------------------------- src/r_plane.c | 2 -- 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 952bea318..4a0174369 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -616,6 +616,8 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// SRB2CB itself ported this from PrBoom+ #define NEWCLIP -//#define NO_PNG_LUMPS +#ifndef HAVE_PNG +#define NO_PNG_LUMPS +#endif #endif // __DOOMDEF__ diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 2b458c9d9..c9a75a4f3 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -892,8 +892,10 @@ lumpnum_t gr_patchflat; static void HWR_LoadPatchFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) { + UINT8 *flat; patch_t *patch = (patch_t *)W_CacheLumpNum(flatlumpnum, PU_STATIC); size_t lumplength = W_LumpLength(flatlumpnum); + #ifndef NO_PNG_LUMPS if (R_IsLumpPNG((UINT8 *)patch, lumplength)) patch = R_PNGToPatch((UINT8 *)patch, lumplength); @@ -902,7 +904,10 @@ static void HWR_LoadPatchFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) grMipmap->width = (UINT16)SHORT(patch->width); grMipmap->height = (UINT16)SHORT(patch->height); - R_PatchToFlat(patch, Z_Malloc(grMipmap->width * grMipmap->height, PU_HWRCACHE, &grMipmap->grInfo.data)); + flat = Z_Malloc(grMipmap->width * grMipmap->height, PU_HWRCACHE, &grMipmap->grInfo.data); + memset(flat, TRANSPARENTPIXEL, grMipmap->width * grMipmap->height); + + R_PatchToFlat(patch, flat); } static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) @@ -980,6 +985,8 @@ void HWR_GetFlat(lumpnum_t flatlumpnum) static void HWR_LoadTextureFlat(GLMipmap_t *grMipmap, INT32 texturenum) { + UINT8 *flat; + // setup the texture info #ifdef GLIDE_API_COMPATIBILITY grMipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_64; @@ -992,7 +999,10 @@ static void HWR_LoadTextureFlat(GLMipmap_t *grMipmap, INT32 texturenum) grMipmap->width = (UINT16)textures[texturenum]->width; grMipmap->height = (UINT16)textures[texturenum]->height; - R_TextureToFlat(texturenum, Z_Malloc(grMipmap->width * grMipmap->height, PU_HWRCACHE, &grMipmap->grInfo.data)); + flat = Z_Malloc(grMipmap->width * grMipmap->height, PU_HWRCACHE, &grMipmap->grInfo.data); + memset(flat, TRANSPARENTPIXEL, grMipmap->width * grMipmap->height); + + R_TextureToFlat(texturenum, flat); } void HWR_GetTextureFlat(INT32 texturenum) diff --git a/src/r_data.c b/src/r_data.c index 8c6b4926a..fb30005bf 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -376,9 +376,13 @@ static UINT8 *R_GenerateTexture(size_t texnum) lumpnum = patch->lump; lumplength = W_LumpLengthPwad(wadnum, lumpnum); realpatch = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); + #ifndef NO_PNG_LUMPS if (R_IsLumpPNG((UINT8 *)realpatch, lumplength)) + { realpatch = R_PNGToPatch((UINT8 *)realpatch, lumplength); + goto multipatch; + } #endif // Check the patch for holes. @@ -436,6 +440,9 @@ static UINT8 *R_GenerateTexture(size_t texnum) } // multi-patch textures (or 'composite') +#ifndef NO_PNG_LUMPS + multipatch: +#endif texture->holes = false; texture->flip = 0; blocksize = (texture->width * 4) + (texture->width * texture->height); @@ -2441,7 +2448,6 @@ boolean R_CheckIfPatch(lumpnum_t lump) { result = false; break; - } } } @@ -2475,8 +2481,7 @@ void R_PatchToFlat(patch_t *patch, UINT8 *flat) source = (UINT8 *)(column) + 3; for (ofs = 0; dest < deststop && ofs < column->length; ofs++) { - if (source[ofs] != TRANSPARENTPIXEL) - *dest = source[ofs]; + *dest = source[ofs]; dest += SHORT(patch->width); } column = (column_t *)((UINT8 *)column + column->length + 4); @@ -2637,7 +2642,8 @@ static UINT8 *PNG_RawConvert(UINT8 *png, UINT16 *w, UINT16 *h, size_t size) for (x = 0; x < width; x++) { png_bytep px = &(row[x * 4]); - flat[((y * width) + x)] = NearestColor((UINT8)px[0], (UINT8)px[1], (UINT8)px[2]); + if ((UINT8)px[3]) + flat[((y * width) + x)] = NearestColor((UINT8)px[0], (UINT8)px[1], (UINT8)px[2]); } } free(row_pointers); @@ -2645,34 +2651,6 @@ static UINT8 *PNG_RawConvert(UINT8 *png, UINT16 *w, UINT16 *h, size_t size) return flat; } -// Get the alpha mask of the image. -static UINT8 *PNG_GetAlphaMask(UINT8 *png, size_t size) -{ - UINT8 *mask; - png_uint_32 x, y; - UINT16 width, height; - png_bytep *row_pointers = PNG_Read(png, &width, &height, size); - - if (!row_pointers) - return NULL; - - // Convert the image to 8bpp - mask = Z_Malloc(width * height, PU_LEVEL, NULL); - memset(mask, 0, width * height); - for (y = 0; y < height; y++) - { - png_bytep row = row_pointers[y]; - for (x = 0; x < width; x++) - { - png_bytep px = &(row[x * 4]); - mask[((y * width) + x)] = (UINT8)px[3]; - } - } - free(row_pointers); - - return mask; -} - // Convert a PNG to a flat. UINT8 *R_PNGToFlat(levelflat_t *levelflat, UINT8 *png, size_t size) { @@ -2680,13 +2658,11 @@ UINT8 *R_PNGToFlat(levelflat_t *levelflat, UINT8 *png, size_t size) } // Convert a PNG to a patch. -// This is adapted from the "kartmaker" utility static unsigned char imgbuf[1<<26]; patch_t *R_PNGToPatch(UINT8 *png, size_t size) { UINT16 width, height; UINT8 *raw = PNG_RawConvert(png, &width, &height, size); - UINT8 *alphamask = PNG_GetAlphaMask(png, size); UINT32 x, y; UINT8 *img; @@ -2726,16 +2702,6 @@ patch_t *R_PNGToPatch(UINT8 *png, size_t size) for (y = 0; y < height; y++) { UINT8 paletteIndex = raw[((y * width) + x)]; - UINT8 opaque = alphamask[((y * width) + x)]; // If 1, we have a pixel - - // End span if we have a transparent pixel - if (!opaque) - { - if (startofspan) - WRITE8(imgptr, 0); - startofspan = NULL; - continue; - } // Start new column if we need to if (!startofspan || spanSize == 255) diff --git a/src/r_plane.c b/src/r_plane.c index 92b3fe770..c28405726 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -754,7 +754,6 @@ static UINT8 *R_GetPatchFlat(levelflat_t *levelflat, boolean leveltexture, boole { patch = (patch_t *)ds_source; #ifndef NO_PNG_LUMPS -#ifdef HAVE_PNG if (ispng) { levelflat->flatpatch = R_PNGToFlat(levelflat, ds_source, W_LumpLength(levelflat->lumpnum)); @@ -773,7 +772,6 @@ static UINT8 *R_GetPatchFlat(levelflat_t *levelflat, boolean leveltexture, boole } } else -#endif #endif { levelflat->width = ds_flatwidth = SHORT(patch->width);