From 8a66bf259499a7194aa200a70112dc3a498631e9 Mon Sep 17 00:00:00 2001 From: viciious Date: Sat, 19 Oct 2024 20:02:31 +0300 Subject: [PATCH] Support repeated base layer in decaled textures --- r_data.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/r_data.c b/r_data.c index be9f6016c..5e78f531b 100644 --- a/r_data.c +++ b/r_data.c @@ -102,7 +102,7 @@ void R_InitTextures (void) mtexture = (maptexture_t*)((byte*)maptex + offset); patchcount = LITTLESHORT(mtexture->patchcount); if (patchcount > 1) - numdecals += patchcount - 1; + numdecals += patchcount; } decals = Z_Malloc (numdecals * sizeof(*decals), PU_STATIC); @@ -161,14 +161,14 @@ void R_InitTextures (void) texture->lumpnum = textures[texnum].lumpnum; - if (patchcount > 1) + if (patchcount > 0) { int j; texture_t *texture2; int firstdecal = decal - decals; int numdecals = 0; - for (j = 1; j < patchcount; j++) { + for (j = 0; j < patchcount; j++) { mappatch_t *mp = &mtexture->patches[j]; texnum = LITTLESHORT(mp->patch); @@ -884,6 +884,7 @@ boolean R_CompositeColumn(int colnum, int numdecals, texdecal_t *decals, inpixel i = 0; do { + int j; int count; texdecal_t *decal = &decals[i]; texture_t *decaltex = &textures[decal->texturenum]; @@ -891,18 +892,11 @@ boolean R_CompositeColumn(int colnum, int numdecals, texdecal_t *decals, inpixel if (colnum < decal->mincol || colnum > decal->maxcol) continue; - if (!decaled) - { - decaled = true; - D_memcpy(dst, src, sizeof(inpixel_t) * height); - } - src = (inpixel_t *)decaltex->data[0]; count = (colnum - decal->mincol) * decaltex->height; #if MIPLEVEL > 1 // FIXME - int j; for (j = 0; j < miplevel; j++) count >>= 1; src = (inpixel_t *)decaltex->data[miplevel]; @@ -911,10 +905,29 @@ boolean R_CompositeColumn(int colnum, int numdecals, texdecal_t *decals, inpixel count = decal->maxrow - decal->minrow + 1; #ifdef MARS - dst = (void *)((intptr_t)dst | 0x20000); // overwrite area of VRAM + if (decaled) + dst = (void *)((intptr_t)dst | 0x20000); // overwrite area of VRAM #endif - D_memcpy(dst + decal->minrow, src, sizeof(inpixel_t) * count); - src = dst; + + if (!decaled) + { + decaled = true; + count = height; + for (j = 0; j < height; ) + { + int p = count; + if (j + p > height) + p = height - j; + if (p > decaltex->height) + p = decaltex->height; + D_memcpy(dst + j, src, sizeof(inpixel_t) * p); + j += p; + } + } + else + { + D_memcpy(dst + decal->minrow, src, sizeof(inpixel_t) * count); + } } while (++i < numdecals); return decaled;