From 646fd15b02e498b1701440176399e1e6f68764ae Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Wed, 28 Oct 2020 15:16:05 -0400 Subject: [PATCH 1/3] Remove these 2 calls to HWR_UnlockCachedPatch From what I can tell, this is not in SRB2 master or next. I'm uncertain about this, but Jeck has had zero crashes with this. --- src/hardware/hw_md2.c | 2 -- src/z_zone.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index fe0d1fc99..3d00252e7 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -419,7 +419,6 @@ static void md2_loadTexture(md2_t *model) } HWD.pfnSetTexture(grpatch->mipmap); - HWR_UnlockCachedPatch(grpatch); } // -----------------+ @@ -470,7 +469,6 @@ static void md2_loadBlendTexture(md2_t *model) } HWD.pfnSetTexture(grpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary - HWR_UnlockCachedPatch(grpatch); Z_Free(filename); } diff --git a/src/z_zone.h b/src/z_zone.h index 5cbcc6655..dfb2f6c71 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -62,7 +62,7 @@ enum PU_CACHE_UNLOCKED = 101, // Note: unused PU_HWRCACHE_UNLOCKED = 102, // 'unlocked' PU_HWRCACHE memory: // 'second-level' cache for graphics - // stored in hardware format and downloaded as needed + // stored in hardware format and downloaded as needed PU_HWRPATCHINFO_UNLOCKED = 103, // 'unlocked' PU_HWRPATCHINFO memory PU_HWRMODELTEXTURE_UNLOCKED = 104, // 'unlocked' PU_HWRMODELTEXTURE memory }; From a253a6cedd71270bc930b22d1c3dd95df2433f0e Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Wed, 28 Oct 2020 15:41:32 -0400 Subject: [PATCH 2/3] Remove rogue line making this function do nothing --- src/hardware/hw_md2.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 3d00252e7..c5958de78 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -607,9 +607,6 @@ void HWR_AddPlayerModel(int skin) // For skins that were added after startup } } - // Check for any MD2s that match the names of sprite names! - while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) - // length of the player model prefix prefixlen = strlen(PLAYERMODELPREFIX); From 01d5c9a95b4d7c37e7c8dbf99ff2edad9d11c282 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Wed, 28 Oct 2020 16:20:11 -0400 Subject: [PATCH 3/3] Put back in the improvements to HWR_CreateBlendedTexture Fixes colors being darker, and creates blend textures faster --- src/hardware/hw_md2.c | 109 +++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index c5958de78..9896eb458 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -698,10 +698,12 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, UINT16 w = gpatch->width, h = gpatch->height; UINT32 size = w*h; RGBA_t *image, *blendimage, *cur, blendcolor; - UINT16 translation[16]; // First the color index + UINT8 translation[16]; // First the color index UINT8 cutoff[16]; // Brightness cutoff before using the next color UINT8 translen = 0; UINT8 i; + UINT8 colorbrightnesses[16]; + UINT8 color_match_lookup[256]; // optimization attempt blendcolor = V_GetColor(0); // initialize memset(translation, 0, sizeof(translation)); @@ -737,6 +739,7 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, if (color != SKINCOLOR_NONE && color < numskincolors) { UINT8 numdupes = 1; + UINT8 prevdupes = numdupes; translation[translen] = skincolors[color].ramp[0]; cutoff[translen] = 255; @@ -751,18 +754,56 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, if (translen > 0) { - cutoff[translen] = cutoff[translen-1] - (256 / (16 / numdupes)); + INT16 newcutoff = cutoff[translen-1] - (255 / (16 / prevdupes)); + + if (newcutoff < 0) + newcutoff = 0; + + cutoff[translen] = (UINT8)newcutoff; } + prevdupes = numdupes; numdupes = 1; translen++; - translation[translen] = (UINT16)skincolors[color].ramp[i]; + translation[translen] = (UINT8)skincolors[color].ramp[i]; } translen++; } + if (skinnum == TC_RAINBOW && translen > 0) + { + UINT16 b; + INT32 compare; + + for (i = 0; i < translen; i++) // moved from inside the loop to here + { + RGBA_t tempc = V_GetColor(translation[i]); + colorbrightnesses[i] = K_ColorRelativeLuminance(tempc.s.red, tempc.s.green, tempc.s.blue); // store brightnesses for comparison + } + // generate lookup table for color brightness matching + for (b = 0; b < 256; b++) + { + UINT16 brightdif = 256; + + color_match_lookup[i] = 0; + for (i = 0; i < translen; i++) + { + if (b > colorbrightnesses[i]) // don't allow greater matches (because calculating a makeshift gradient for this is already a huge mess as is) + continue; + + compare = abs((INT16)(colorbrightnesses[i]) - (INT16)(b)); + + if (compare < brightdif) + { + brightdif = (UINT16)compare; + color_match_lookup[b] = i; // best matching color that's equal brightness or darker + } + } + } + } + while (size--) { if (skinnum == TC_BOSS) @@ -834,7 +875,7 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, else { // All settings that use skincolors! - UINT8 brightness; + UINT16 brightness; if (translen <= 0) { @@ -852,8 +893,11 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, } else { - UINT8 imagebright = K_ColorRelativeLuminance(image->s.red, image->s.green, image->s.blue); - UINT8 blendbright = K_ColorRelativeLuminance(blendimage->s.red, blendimage->s.green, blendimage->s.blue); + UINT16 imagebright, blendbright; + + imagebright = K_ColorRelativeLuminance(image->s.red, image->s.green, image->s.blue); + blendbright = K_ColorRelativeLuminance(blendimage->s.red, blendimage->s.green, blendimage->s.blue); + // slightly dumb average between the blend image color and base image colour, usually one or the other will be fully opaque anyway brightness = (imagebright*(255-blendimage->s.alpha))/255 + (blendbright*blendimage->s.alpha)/255; } @@ -882,9 +926,8 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, // Ensue horrible mess. if (skinnum == TC_RAINBOW) { - UINT16 brightdif = 256; - UINT8 colorbrightnesses[16]; - INT32 compare, m, d; + //UINT16 brightdif = 256; + INT32 /*compare,*/ m, d; // Ignore pure white & pitch black if (brightness > 253 || brightness < 2) @@ -898,13 +941,7 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, mul = 0; mulmax = 1; - for (i = 0; i < translen; i++) - { - RGBA_t tempc = V_GetColor(translation[i]); - colorbrightnesses[i] = K_ColorRelativeLuminance(tempc.s.red, tempc.s.green, tempc.s.blue); // store brightnesses for comparison - } - - for (i = 0; i < translen; i++) + /*for (i = 0; i < translen; i++) { if (brightness > colorbrightnesses[i]) // don't allow greater matches (because calculating a makeshift gradient for this is already a huge mess as is) continue; @@ -916,19 +953,13 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, brightdif = (UINT16)compare; firsti = i; // best matching color that's equal brightness or darker } - } + }*/ + firsti = color_match_lookup[brightness]; secondi = firsti+1; // next color in line - if (secondi >= translen) - { - m = (INT16)brightness; // - 0; - d = (INT16)colorbrightnesses[firsti]; // - 0; - } - else - { - m = (INT16)brightness - (INT16)colorbrightnesses[secondi]; - d = (INT16)colorbrightnesses[firsti] - (INT16)colorbrightnesses[secondi]; - } + + m = (INT16)brightness - (INT16)colorbrightnesses[secondi]; + d = (INT16)colorbrightnesses[firsti] - (INT16)colorbrightnesses[secondi]; if (m >= d) m = d-1; @@ -955,29 +986,15 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, secondi = firsti+1; - mulmax = cutoff[firsti]; - if (secondi < translen) - mulmax -= cutoff[secondi]; - + mulmax = cutoff[firsti] - cutoff[secondi]; mul = cutoff[firsti] - brightness; } blendcolor = V_GetColor(translation[firsti]); - if (secondi >= translen) - mul = 0; - if (mul > 0) // If it's 0, then we only need the first color. { -#if 0 - if (secondi >= translen) - { - // blend to black - nextcolor = V_GetColor(31); - } - else -#endif - nextcolor = V_GetColor(translation[secondi]); + nextcolor = V_GetColor(translation[secondi]); // Find difference between points r = (INT32)(nextcolor.s.red - blendcolor.s.red); @@ -999,10 +1016,14 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, if (skinnum == TC_RAINBOW) { UINT32 tempcolor; - UINT8 colorbright = K_ColorRelativeLuminance(blendcolor.s.red, blendcolor.s.green, blendcolor.s.blue); + UINT16 colorbright; + + colorbright = K_ColorRelativeLuminance(blendcolor.s.red, blendcolor.s.green, blendcolor.s.blue); if (colorbright == 0) + { colorbright = 1; // no dividing by 0 please + } tempcolor = (brightness * blendcolor.s.red) / colorbright; tempcolor = min(255, tempcolor);