diff --git a/src/r_data.c b/src/r_data.c index 507696925..bd56f5674 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -504,6 +504,45 @@ UINT8 *R_GetColumn(fixed_t tex, INT32 col) return texturecache[tex] + LONG(texturecolumnofs[tex][wrap_column(tex, col)]); } +static UINT8 ***holecols; + +// used for R_DrawWallColumn +// convert "holey" columns into contigous columns +// filled with cyan in place of holes +UINT8 *R_GetHoleColumn(INT32 tex, INT32 col) +{ + col = wrap_column(tex, col); + + if (!holecols[tex][col]) + { + UINT8 *src = texturecache[tex] + LONG(texturecolumnofs[tex][col]); + column_t *coldata = (column_t *)(src - 3); + + INT32 texheight = textureheight[tex] >> FRACBITS; + + UINT8 *holecole = Z_Malloc(texheight, PU_STATIC, NULL); + // fill in everything with cyan so we can skip it + memset(holecole, TRANSPARENTPIXEL, texheight); + + // shamelessly copy pasted from R_GenerateTexture + INT32 topdelta, prevdelta = -1; + while (coldata->topdelta != 0xff) + { + topdelta = coldata->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + + memcpy(holecole + topdelta, (UINT8*)coldata + 4, coldata->length); + coldata = (column_t *)((UINT8*)coldata + coldata->length + 4); + } + + holecols[tex][col] = holecole; + } + + return holecols[tex][col]; +} + // convert flats to hicolor as they are requested // UINT8 *R_GetFlat(lumpnum_t flatlumpnum) @@ -679,6 +718,30 @@ static INT32 R_CountTextures(UINT16 wadnum) return count; } +static void R_AllocHoleColes(INT32 add) +{ + // only needed for software + if (rendermode != render_soft) + return; + + const INT32 newtextures = (numtextures + add); + + Z_Realloc(holecols, newtextures * sizeof(UINT8**), PU_STATIC, &holecols); + + for (INT32 tex = numtextures; tex < newtextures; tex++) + { + // FIXME: kinda wasteful but idk how to make shit not die skipping textures without holes.... + INT32 width = texturewidth[tex]; + + holecols[tex] = Z_Malloc(width * sizeof(UINT8*), PU_STATIC, NULL); + + for (INT32 col = 0; col < width; col++) + { + holecols[tex][col] = NULL; + } + } +} + static void R_AllocateTextures(INT32 add) { const INT32 newtextures = (numtextures + add); @@ -723,6 +786,7 @@ static INT32 R_DefineTextures(INT32 i, UINT16 w) static void R_FinishLoadingTextures(INT32 add) { + R_AllocHoleColes(add); numtextures += add; #ifdef HWRENDER diff --git a/src/r_data.h b/src/r_data.h index 168f72bf0..ff455427d 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -81,6 +81,7 @@ void R_CheckTextureCache(INT32 tex); // Retrieve column data for span blitting. UINT8 *R_GetColumn(fixed_t tex, INT32 col); +UINT8 *R_GetHoleColumn(INT32 tex, INT32 col); UINT8 *R_GetFlat(lumpnum_t flatnum); diff --git a/src/r_draw.h b/src/r_draw.h index b399ff0c8..a1d451fb4 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -123,6 +123,8 @@ enum COLDRAWFUNC_TRANSTRANS, COLDRAWFUNC_TWOSMULTIPATCH, COLDRAWFUNC_TWOSMULTIPATCHTRANS, + COLDRAWFUNC_TWOSMULTIPATCH_DIRECT, + COLDRAWFUNC_TWOSMULTIPATCHTRANS_DIRECT, COLDRAWFUNC_FOG, COLDRAWFUNC_MAX diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 0b9388df1..db959b68b 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1168,7 +1168,6 @@ static inline void R_ExpandPlaneY(visplane_t *pl, INT32 x, INT16 top, INT16 bott static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t mid, fixed_t texturecolumn, INT32 texture, boolean remap) { - UINT8 *holecol = NULL; const INT32 itexturecolumn = texturecolumn >> FRACBITS; dc->yl = yl; dc->yh = yh; @@ -1180,42 +1179,18 @@ static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t m R_SetColumnFunc(colfunctype); coldrawfunc_t* colfunccopy = colfunc; - // ok so this thing cannot handle "holey" textures - // since it just reads the data as pixels directly - // but the holey ones dont have any data there or smth - // plug missing "data" with cyan so multipatch drawer can cut them - // fixes reading oob garbo and the "melty" effect on maps like spelunky or hyakaykuykiukikykooekyk streets - // caveat: this is mostly done on single sided walls which may cause some other issues, but mostly seems to work fineish - // this is probably inefficient as hell but oh well if (textures[texture]->holes) { - holecol = static_cast(malloc(dc->texheight)); - column_t *col = (column_t *)(dc->source - 3); - // fill in everything with cyan so we can skip it - memset(holecol, TRANSPARENTPIXEL, dc->texheight); + dc->source = R_GetHoleColumn(texture, itexturecolumn); - // shamelessly copy pasted from R_GenerateTexture - INT32 topdelta, prevdelta = -1; - while (col->topdelta != 0xff) - { - topdelta = col->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - memcpy(holecol + topdelta, (UINT8*)col + 4, col->length); - col = (column_t *)((UINT8*)col + col->length + 4); - } - - dc->source = holecol; - - // so it can cut the "holes" + // need to use multipatch drawers to cut cyan pixels if (R_CheckColumnFunc(COLDRAWFUNC_FUZZY) == true) { - colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS]; + colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS_DIRECT]; } else { - colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCH]; + colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCH_DIRECT]; } } @@ -1227,8 +1202,6 @@ static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t m } colfunccopy(const_cast(&dc_copy)); - - free(holecol); } static boolean didsolidcol; // True if at least one column was marked solid diff --git a/src/screen.c b/src/screen.c index 55a9b5648..8ebd663e1 100644 --- a/src/screen.c +++ b/src/screen.c @@ -106,6 +106,8 @@ static void SCR_SetDrawFuncs(enum columncontext_e _columncontext) colfuncs[COLDRAWFUNC_TRANS] = R_DrawTranslatedColumn_Flush; colfuncs[COLDRAWFUNC_SHADOWED] = R_DrawColumnShadowed_Flush; colfuncs[COLDRAWFUNC_TRANSTRANS] = R_DrawTranslatedTranslucentColumn_Flush; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCH] = R_Draw2sMultiPatchColumn_Flush; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS] = R_Draw2sMultiPatchTranslucentColumn_Flush; } else { @@ -114,10 +116,13 @@ static void SCR_SetDrawFuncs(enum columncontext_e _columncontext) colfuncs[COLDRAWFUNC_TRANS] = R_DrawTranslatedColumn; colfuncs[COLDRAWFUNC_SHADOWED] = R_DrawColumnShadowed; colfuncs[COLDRAWFUNC_TRANSTRANS] = R_DrawTranslatedTranslucentColumn; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCH] = R_Draw2sMultiPatchColumn; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS] = R_Draw2sMultiPatchTranslucentColumn; } - colfuncs[COLDRAWFUNC_TWOSMULTIPATCH] = R_Draw2sMultiPatchColumn; - colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS] = R_Draw2sMultiPatchTranslucentColumn; + // gotta keep a copy of those for R_DrawWallColumn..... + colfuncs[COLDRAWFUNC_TWOSMULTIPATCH_DIRECT] = R_Draw2sMultiPatchColumn; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS_DIRECT] = R_Draw2sMultiPatchTranslucentColumn; colfuncs[COLDRAWFUNC_FOG] = R_DrawFogColumn;