From bef8c9ae76e2726e90cda9e0ed817e0ca91161a5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 17 Oct 2019 20:29:58 +0200 Subject: [PATCH] - hictinting cleanup. This needs to be moved into the backend, and partially into the shader. So far this only removes the code from the main rendering logic, the final implementation is not done yet. It had to go because it required the main rendering code to look deep into the texture data which would be a major blocker for refactoring. --- source/CMakeLists.txt | 52 ++----------------- source/build/include/hightile.h | 34 ------------- source/build/include/palette.h | 5 +- source/build/include/polymost.h | 6 +-- source/build/src/mdsprite.cpp | 25 +++------ source/build/src/polymost.cpp | 56 +++++++++----------- source/build/src/texcache.cpp | 23 ++++++--- source/build/src/voxmodel.cpp | 4 +- source/common/textures/buildtiles.cpp | 7 +-- source/common/textures/texture.cpp | 15 ++---- source/common/textures/textures.h | 5 +- source/duke3d/src/screens.cpp | 21 -------- source/glbackend/glbackend.cpp | 73 +++++++++++++++++---------- source/glbackend/glbackend.h | 12 ++++- 14 files changed, 122 insertions(+), 216 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index d4a5a7230..07e4740d0 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -36,9 +36,10 @@ if( APPLE ) option( OSX_COCOA_BACKEND "Use native Cocoa backend instead of SDL" ON ) endif() -if( ${DEMOLITION_TARGET_ARCH} MATCHES "x86_64" ) +# Right now only 64 bit is supported. +#if( ${DEMOLITION_TARGET_ARCH} MATCHES "x86_64" ) set( X64 64 ) -endif() +#endif() if( X64 OR ${DEMOLITION_TARGET_ARCH} MATCHES "i386" ) add_definitions( -DARCH_IA32 ) @@ -60,52 +61,7 @@ if( WIN32 ) add_definitions( -D_WIN32 ) - if( ( MSVC14 AND NOT CMAKE_GENERATOR_TOOLSET STREQUAL "v140_xp" ) OR # For VS 2015. - ( MSVC15 AND NOT CMAKE_GENERATOR_TOOLSET STREQUAL "v141_xp" ) ) # For VS 2017. - # for modern Windows SDKs the DirectX headers should be available by default. - set( DX_dinput8_LIBRARY dinput8 ) - else() - - find_path( XINPUT_INCLUDE_DIR xinput.h - PATHS ENV DXSDK_DIR - PATH_SUFFIXES Include ) - if( NOT XINPUT_INCLUDE_DIR ) - # Modern versions of the Windows SDK include xinput.h. Unfortunately, - # CMake cannot find this file via find_path, so we check for it using - # CHECK_INCLUDE_FILES. windows.h must be included before xinput.h. - CHECK_INCLUDE_FILES( "windows.h;xinput.h" XINPUT_H_FOUND ) - if( NOT XINPUT_H_FOUND ) - message( WARNING "Could not find xinput.h. XInput will be disabled." ) - add_definitions( -DNO_XINPUT ) - endif() - else() - include_directories( ${XINPUT_INCLUDE_DIR} ) - endif() - - find_library( DX_dinput8_LIBRARY dinput8 - PATHS ENV DXSDK_DIR - PATH_SUFFIXES Lib Lib/${XBITS} ) - if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) - find_library( DX_dxguid_LIBRARY dxguid - PATHS ENV DXSDK_DIR - PATH_SUFFIXES Lib Lib/${XBITS} ) - endif() - - # Modern versions of the Windows SDK include dinput8. Unfortunately, - # CMake cannot find these libraries via find_library. - if( NOT DX_dinput8_LIBRARY ) - # If we got this far, assume dinput8 is in the system library path. - set( DX_dinput8_LIBRARY dinput8 ) - endif() - - if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) - # Modern versions of the Windows SDK do NOT include dxguid. Its contents - # were moved to dinput8. - if( NOT DX_dxguid_LIBRARY ) - message( STATUS "Could not find dxguid. Build may fail on old Windows SDKs.") - endif() - endif() - endif() + set( DX_dinput8_LIBRARY dinput8 ) if( X64 ) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../platform/Windows/lib/64) diff --git a/source/build/include/hightile.h b/source/build/include/hightile.h index 37d1f5a84..8168cd669 100644 --- a/source/build/include/hightile.h +++ b/source/build/include/hightile.h @@ -9,30 +9,6 @@ typedef struct { extern polytint_t hictinting[MAXPALOOKUPS]; -static inline int have_basepal_tint(void) -{ - polytint_t const & tint = hictinting[MAXPALOOKUPS-1]; - return (tint.r != 255 || - tint.g != 255 || - tint.b != 255); -} - -static inline void hictinting_apply(float *color, int32_t palnum) -{ - polytint_t const & tint = hictinting[palnum]; - color[0] *= (float)tint.r * (1.f/255.f); - color[1] *= (float)tint.g * (1.f/255.f); - color[2] *= (float)tint.b * (1.f/255.f); -} - -static inline void hictinting_apply_ub(uint8_t *color, int32_t palnum) -{ - polytint_t const & tint = hictinting[palnum]; - color[0] = (uint8_t)(color[0] * (float)tint.r * (1.f/255.f)); - color[1] = (uint8_t)(color[1] * (float)tint.g * (1.f/255.f)); - color[2] = (uint8_t)(color[2] * (float)tint.b * (1.f/255.f)); -} - static inline void globaltinting_apply(float *color) { color[0] *= (float)globalr * (1.f/255.f); @@ -40,13 +16,6 @@ static inline void globaltinting_apply(float *color) color[2] *= (float)globalb * (1.f/255.f); } -static inline void globaltinting_apply_ub(uint8_t *color) -{ - color[0] = (uint8_t)(color[0] * (float)globalr * (1.f/255.f)); - color[1] = (uint8_t)(color[1] * (float)globalg * (1.f/255.f)); - color[2] = (uint8_t)(color[2] * (float)globalb * (1.f/255.f)); -} - // replacement flags enum @@ -71,9 +40,6 @@ enum HICTINT_BLENDMASK = 64|128, - HICTINT_ALWAYSUSEART = 256, - HICTINT_NOFOGSHADE = 512, - HICTINT_PRECOMPUTED = HICTINT_COLORIZE | HICTINT_BLENDMASK, HICTINT_IN_MEMORY = HICTINT_PRECOMPUTED | HICTINT_GRAYSCALE | HICTINT_INVERT, diff --git a/source/build/include/palette.h b/source/build/include/palette.h index 26c2926ac..9a249f3bd 100644 --- a/source/build/include/palette.h +++ b/source/build/include/palette.h @@ -23,14 +23,11 @@ #define GLOWPAL (MAXPALOOKUPS - 2) #define SPECULARPAL (MAXPALOOKUPS - 3) #define NORMALPAL (MAXPALOOKUPS - 4) +#define BRIGHTPAL (MAXPALOOKUPS) extern uint8_t curbasepal; -#ifdef LUNATIC -extern const char *(paletteGetBlendTable) (int32_t blend); -#else #define paletteGetBlendTable(blend) (blendtable[blend]) -#endif extern uint32_t PaletteIndexFullbrights[8]; diff --git a/source/build/include/polymost.h b/source/build/include/polymost.h index 8e1c619ec..dbbcfa320 100644 --- a/source/build/include/polymost.h +++ b/source/build/include/polymost.h @@ -88,8 +88,7 @@ static FORCE_INLINE int32_t get_ceiling_fogpal(usectorptr_t const sec) } static FORCE_INLINE int32_t fogshade(int32_t const shade, int32_t const pal) { - polytintflags_t const tintflags = hictinting[pal].f; - return (globalflags & GLOBAL_NO_GL_FOGSHADE || tintflags & HICTINT_NOFOGSHADE) ? 0 : shade; + return (globalflags & GLOBAL_NO_GL_FOGSHADE) ? 0 : shade; } static FORCE_INLINE int check_nonpow2(int32_t const x) @@ -178,7 +177,4 @@ extern hitdata_t polymost_hitdata; #include "texcache.h" -extern void polymost_setupglowtexture(int32_t texunits, FHardwareTexture *tex); -extern void polymost_setupdetailtexture(int32_t texunits, FHardwareTexture* tex); - #endif diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index f04bef11b..6d77facc2 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1780,19 +1780,8 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) // tinting pc[0] = pc[1] = pc[2] = ((float)numshades - min(max((globalshade * shadescale) + m->shadeoff, 0.f), (float)numshades)) / (float)numshades; - auto& h = hictinting[globalpal]; - polytintflags_t const tintflags = h.f; - if (!(tintflags & HICTINT_PRECOMPUTED)) - { - if (!(m->flags&1)) - hictinting_apply(pc, globalpal); - else globalnoeffect=1; - } - GLInterface.SetTinting(tintflags, PalEntry(h.sr, h.sg, h.sb)); - - // global tinting - if (have_basepal_tint()) - hictinting_apply(pc, MAXPALOOKUPS-1); + auto h = hictinting[globalpal]; + GLInterface.SetTinting(h.f, PalEntry(h.sr, h.sg, h.sb), PalEntry(h.r, h.g, h.b)); pc[3] = (tspr->cstat&2) ? glblend[tspr->blend].def[!!(tspr->cstat&512)].alpha : 1.0f; pc[3] *= 1.0f - sext->alpha; @@ -1914,7 +1903,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) if (!(tspr->extra&TSPR_EXTRA_MDHACK)) { //POGOTODO: if we add support for palette indexing on model skins, the texture for the palswap could be setup here - +#if 0 // FIXME: This shouls use the HightileReplacement structure inside the texture so that it can use the same code as world textures. tex = r_detailmapping ? mdloadskin((md2model_t *) m, tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum, DETAILPAL, surfi) : nullptr; if (tex) @@ -1922,7 +1911,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) mdskinmap_t *sk; GLInterface.UseDetailMapping(true); - polymost_setupdetailtexture(3, tex); + //polymost_setupdetailtexture(3, tex); for (sk = m->skinmap; sk; sk = sk->next) if ((int32_t) sk->palette == DETAILPAL && sk->skinnum == tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum && sk->surfnum == surfi) @@ -1939,13 +1928,13 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) if (i) { GLInterface.UseGlowMapping(true); - polymost_setupglowtexture(4, tex); + //polymost_setupglowtexture(4, tex); texmat.loadIdentity(); texmat.translate(xpanning, ypanning, 1.0f); GLInterface.SetMatrix(Matrix_Glow, &texmat); } - +#endif indexhandle = m->vindexes; //PLAG: delayed polygon-level sorted rendering @@ -2009,7 +1998,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) VSMatrix identity(0); GLInterface.SetMatrix(Matrix_ModelView, &identity); - GLInterface.SetTinting(0, 0); + GLInterface.SetTinting(0, 0, PalEntry(255, 255, 255)); GLInterface.SetClamp(prevClamp); GLInterface.SetPolymostShader(); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index c10e74949..8b9ddbe5d 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -479,20 +479,6 @@ void uploadpalswaps(int count, int32_t* swaps) } - -#ifdef USE_GLEXT -void polymost_setupdetailtexture(const int32_t texunits, FHardwareTexture *tex) -{ - GLInterface.BindTexture(texunits, tex, SamplerRepeat); -} - -void polymost_setupglowtexture(const int32_t texunits, FHardwareTexture* tex) -{ - GLInterface.BindTexture(texunits, tex, SamplerRepeat); -} -#endif - - //(dpx,dpy) specifies an n-sided polygon. The polygon must be a convex clockwise loop. // n must be <= 8 (assume clipping can double number of vertices) //method: 0:solid, 1:masked(255 is transparent), 2:transluscent #1, 3:transluscent #2 @@ -516,6 +502,7 @@ int32_t polymost_maskWallHasTranslucency(uwalltype const * const wall) auto tex = TileFiles.tiles[wall->picnum]; auto si = tex->FindReplacement(wall->pal); if (si && usehightile) tex = si->faces[0]; + if (tex->Get8BitPixels()) return false; return tex && tex->GetTranslucency(); } @@ -526,8 +513,9 @@ int32_t polymost_spriteHasTranslucency(uspritetype const * const tspr) return true; auto tex = TileFiles.tiles[tspr->picnum]; - auto si = tex->FindReplacement(tspr->shade, hictinting[tspr->shade].f & HICTINT_ALWAYSUSEART); + auto si = tex->FindReplacement(tspr->shade, 0); if (si && usehightile) tex = si->faces[0]; + if (tex->Get8BitPixels()) return false; return tex && tex->GetTranslucency(); } @@ -755,8 +743,12 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 { // Fixme: Alpha test on shaders must be done differently. // Also: Consider a texture's alpha threshold. +#ifdef HICR float const al = alphahackarray[globalpicnum] != 0 ? alphahackarray[globalpicnum] * (1.f/255.f) : (pth->hicr && pth->hicr->alphacut >= 0.f ? pth->hicr->alphacut : 0.f); +#else + float al = 0; +#endif GLInterface.SetAlphaThreshold(al); handle_blend((method & DAMETH_MASKPROPS) > DAMETH_MASK, drawpoly_blend, (method & DAMETH_MASKPROPS) == DAMETH_TRANS2); @@ -774,22 +766,8 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 // tinting auto& h = hictinting[globalpal]; - polytintflags_t const tintflags = h.f; - if (!(tintflags & HICTINT_PRECOMPUTED)) - { - if (pth->flags & PTH_HIGHTILE) - { - if (pth->palnum != globalpal || (pth->effects & HICTINT_IN_MEMORY) || (tintflags & HICTINT_APPLYOVERALTPAL)) - hictinting_apply(pc, globalpal); - } - else if (tintflags & (HICTINT_USEONART|HICTINT_ALWAYSUSEART)) - hictinting_apply(pc, globalpal); - } - GLInterface.SetTinting(tintflags, PalEntry(h.sr, h.sg, h.sb)); - // global tinting - if ((pth->flags & PTH_HIGHTILE) && have_basepal_tint()) - hictinting_apply(pc, MAXPALOOKUPS-1); + GLInterface.SetTinting(h.f, PalEntry(h.sr, h.sg, h.sb), PalEntry(h.r, h.g, h.b)); globaltinting_apply(pc); @@ -819,7 +797,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 } GLInterface.Draw(DT_TRIANGLE_FAN, data.first, npoints); - GLInterface.SetTinting(0,0); + GLInterface.SetTinting(0, 0, PalEntry(255, 255, 255)); GLInterface.UseDetailMapping(false); GLInterface.UseGlowMapping(false); GLInterface.SetNpotEmulation(false, 1.f, 0.f); @@ -2486,7 +2464,7 @@ static void polymost_drawalls(int32_t const bunch) skyzbufferhack = 1; - if (!usehightile || !hicfindskybox(globalpicnum, globalpal)) + //if (!usehightile || !hicfindskybox(globalpicnum, globalpal)) { float const ghorizbak = ghoriz; pow2xsplit = 0; @@ -2498,6 +2476,7 @@ static void polymost_drawalls(int32_t const bunch) flatskyrender = 0; ghoriz = ghorizbak; } +#if 0 else //NOTE: code copied from ceiling code... lots of duplicated stuff :/ { //Skybox code for parallax floor! @@ -2676,6 +2655,7 @@ static void polymost_drawalls(int32_t const bunch) skyclamphack = 0; drawingskybox = 0; } +#endif skyclamphack = 0; skyzbufferhack = 0; @@ -2746,7 +2726,7 @@ static void polymost_drawalls(int32_t const bunch) skyzbufferhack = 1; - if (!usehightile || !hicfindskybox(globalpicnum, globalpal)) + //if (!usehightile || !hicfindskybox(globalpicnum, globalpal)) { float const ghorizbak = ghoriz; pow2xsplit = 0; @@ -2758,6 +2738,7 @@ static void polymost_drawalls(int32_t const bunch) flatskyrender = 0; ghoriz = ghorizbak; } +#if 0 else { //Skybox code for parallax ceiling! @@ -2936,6 +2917,7 @@ static void polymost_drawalls(int32_t const bunch) skyclamphack = 0; drawingskybox = 0; } +#endif skyclamphack = 0; skyzbufferhack = 0; @@ -3440,6 +3422,12 @@ void polymost_drawrooms() { if (videoGetRenderMode() == REND_CLASSIC) return; + // This is a global setting for the entire scene, so let's do it here, right at the start. + auto& hh = hictinting[MAXPALOOKUPS - 1]; + // This sets a tinting color for global palettes, e.g. water or slime - only used for hires replacements (also an option for low-resource hardware where duplicating the textures may be problematic.) + GLInterface.SetBasepalTint(PalEntry(hh.sr, hh.sg, hh.sb)); + + polymost_outputGLDebugMessage(3, "polymost_drawrooms()"); videoBeginDrawing(); @@ -5703,4 +5691,6 @@ void PrecacheHardwareTextures(int nTile) if (r_glowmapping) polymost_precache(nTile, GLOWPAL, 1); + polymost_precache(nTile, BRIGHTPAL, 1); + } diff --git a/source/build/src/texcache.cpp b/source/build/src/texcache.cpp index bfa0a420c..843e9c99b 100644 --- a/source/build/src/texcache.cpp +++ b/source/build/src/texcache.cpp @@ -33,6 +33,7 @@ void gltexinvalidate(int32_t dapicnum, int32_t dapalnum, int32_t dameth) //Use this for palette effects ... but not ones that change every frame! void gltexinvalidatetype(int32_t type) { +#if 0 for (bssize_t j = 0; j <= GLTEXCACHEADSIZ - 1; j++) { for (pthtyp* pth = texcache.list[j]; pth; pth = pth->next) @@ -48,6 +49,7 @@ void gltexinvalidatetype(int32_t type) } } } +#endif clearskins(type); @@ -147,11 +149,12 @@ void gloadtile_art(int32_t dapic, int32_t dameth, pthtyp* pth, int32_t doalloc) pth->shade = 0; pth->effects = 0; pth->flags = PTH_HASALPHA | PTH_ONEBITALPHA | PTH_INDEXED; - pth->hicr = NULL; + //pth->hicr = NULL; pth->siz = ssiz; } +#if 0 int32_t gloadtile_hi(int32_t dapic, int32_t dapalnum, int32_t facen, hicreplctyp* hicr, int32_t dameth, pthtyp* pth, int32_t doalloc, polytintflags_t effect) { @@ -213,11 +216,12 @@ int32_t gloadtile_hi(int32_t dapic, int32_t dapalnum, int32_t facen, hicreplctyp (hasalpha ? PTH_HASALPHA : 0) | ((hicr->flags & HICR_FORCEFILTER) ? PTH_FORCEFILTER : 0); pth->skyface = facen; - pth->hicr = hicr; + //pth->hicr = hicr; if (facen > 0) pth->siz = { 64, 64 }; else pth->siz = { tilesiz[dapic].x, tilesiz[dapic].y }; return 0; } +#endif #define TEXCACHE_FREEBUFS() { Xfree(pic), Xfree(packbuf), Xfree(midbuf); } @@ -231,7 +235,7 @@ static pthtyp *texcache_tryart(int32_t const dapicnum, int32_t const dapalnum, i int32_t searchpalnum = dapalnum; polytintflags_t const tintflags = hictinting[dapalnum].f; - if (tintflags & (HICTINT_USEONART|HICTINT_ALWAYSUSEART)) + if (tintflags & (HICTINT_USEONART)) { tintpalnum = dapalnum; if (!(tintflags & HICTINT_APPLYOVERPALSWAP)) @@ -263,6 +267,7 @@ static pthtyp *texcache_tryart(int32_t const dapicnum, int32_t const dapalnum, i return pth; } +#if 0 pthtyp *texcache_fetchmulti(pthtyp *pth, hicreplctyp *si, int32_t dapicnum, int32_t dameth) { const int32_t j = dapicnum&(GLTEXCACHEADSIZ-1); @@ -290,15 +295,16 @@ pthtyp *texcache_fetchmulti(pthtyp *pth, hicreplctyp *si, int32_t dapicnum, int3 } } } - return NULL; } +#endif // : ignored if not in Polymost+r_usetileshades pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth) { +#if 0 const int32_t j = dapicnum & (GLTEXCACHEADSIZ - 1); - hicreplctyp *si = usehightile ? hicfindsubst(dapicnum, dapalnum, hictinting[dapalnum].f & HICTINT_ALWAYSUSEART) : NULL; + hicreplctyp *si = usehightile ? hicfindsubst(dapicnum, dapalnum) : NULL; if (drawingskybox && usehightile) { @@ -308,11 +314,12 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3 } if (!si) - { +#endif + { return (dapalnum >= (MAXPALOOKUPS - RESERVEDPALS) || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); } - +#if 0 /* if palette > 0 && replacement found * no effects are applied to the texture * else if palette > 0 && no replacement found @@ -366,6 +373,8 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3 Xfree(pth); return (drawingskybox || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); +#endif + } diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 55a91db72..f60536cc2 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1088,7 +1088,9 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) float pc[4]; pc[0] = pc[1] = pc[2] = ((float)numshades - min(max((globalshade * shadescale) + m->shadeoff, 0.f), (float)numshades)) / (float)numshades; - hictinting_apply(pc, globalpal); + + auto& h = hictinting[globalpal]; + GLInterface.SetTinting(h.f, PalEntry(h.sr, h.sg, h.sb), PalEntry(h.r, h.g, h.b)); if (!shadowHack) { diff --git a/source/common/textures/buildtiles.cpp b/source/common/textures/buildtiles.cpp index 5a09c22a4..4d0898977 100644 --- a/source/common/textures/buildtiles.cpp +++ b/source/common/textures/buildtiles.cpp @@ -549,7 +549,7 @@ void tileDelete(int tile) void tileRemoveReplacement(int tile) { - if ((unsigned)tileNum >= MAXTILES) return false; + if ((unsigned)tile >= MAXTILES) return; FTexture *tex = TileFiles.tiles[tile]; tex->DeleteReplacements(); } @@ -715,7 +715,7 @@ int tileSetHightileReplacement(int picnum, int palnum, const char *filename, flo replace.specpower = specpower; // currently unused replace.specfactor = specfactor; // currently unused replace.flags = flags; - replace.palnum = (uint8_t)palnum; + replace.palnum = (uint16_t)palnum; tex->AddReplacement(replace); return 0; } @@ -732,6 +732,7 @@ int tileSetSkybox(int picnum, int palnum, const char **facenames, int flags ) if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1; if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1; + auto tex = TileFiles.tiles[picnum]; if (tex->GetWidth() <= 0 || tex->GetHeight() <= 0) { initprintf("Warning: defined skybox replacement for empty tile %d.", picnum); @@ -749,7 +750,7 @@ int tileSetSkybox(int picnum, int palnum, const char **facenames, int flags ) } } replace.flags = flags; - replace.palnum = (uint8_t)palnum; + replace.palnum = (uint16_t)palnum; tex->AddReplacement(replace); return 0; } diff --git a/source/common/textures/texture.cpp b/source/common/textures/texture.cpp index 94ce33bba..96caf7b27 100644 --- a/source/common/textures/texture.cpp +++ b/source/common/textures/texture.cpp @@ -433,17 +433,12 @@ void FTexture::DeleteReplacement(int palnum) // //=========================================================================== -HightileReplacement *FTexture::FindReplacement(int palnum, int nozero, bool skybox) +HightileReplacement *FTexture::FindReplacement(int palnum, bool skybox) { - for(;;) - { - for (auto &rep : Hightiles) - { - if (rep.palnum == palnum && (rep.faces[1] != nullptr) == skybox) return &rep; - } - if (!palnum || nozero) break; - palnum = 0; - } + for (auto &rep : Hightiles) + { + if (rep.palnum == palnum && (rep.faces[1] != nullptr) == skybox) return &rep; + } return nullptr; // no replacement found } diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index 8fedb3746..057527e89 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -42,6 +42,7 @@ #include "palentry.h" class FImageSource; +class FTexture; // picanm[].sf: // |bit(1<<7) @@ -105,7 +106,7 @@ struct HightileReplacement FTexture *faces[6]; // only one gets used by a texture, the other 5 are for skyboxes only vec2f_t scale; float alphacut, specpower, specfactor; - uint8_t palnum, flags; + uint16_t palnum, flags; }; class FBitmap; @@ -248,7 +249,7 @@ public: Hightiles.Clear(); } - HightileReplacement * FindReplacement(int palnum, int nozero = 0, bool skybox = false); + HightileReplacement * FindReplacement(int palnum, bool skybox = false); int alphaThreshold = 128; picanm_t PicAnim = {}; diff --git a/source/duke3d/src/screens.cpp b/source/duke3d/src/screens.cpp index 7dedd9792..5cb770ba0 100644 --- a/source/duke3d/src/screens.cpp +++ b/source/duke3d/src/screens.cpp @@ -920,20 +920,11 @@ void G_DisplayRest(int32_t smoothratio) } } #endif // USE_OPENGL - palaccum_add(&tint, &pp->pals, pp->pals.f); -#ifdef SPLITSCREEN_MOD_HACKS - if (pp2) - palaccum_add(&tint, &pp2->pals, pp2->pals.f); -#endif { static const palette_t loogiepal = { 0, 63, 0, 0 }; palaccum_add(&tint, &loogiepal, pp->loogcnt>>1); -#ifdef SPLITSCREEN_MOD_HACKS - if (pp2) - palaccum_add(&tint, &loogiepal, pp2->loogcnt>>1); -#endif } if (g_restorePalette) @@ -944,21 +935,9 @@ void G_DisplayRest(int32_t smoothratio) if (g_restorePalette < 2 || omovethingscnt+1 == g_moveThingsCount) { int32_t pal = pp->palette; -#ifdef SPLITSCREEN_MOD_HACKS - const int32_t opal = pal; - - if (pp2) // splitscreen HACK: BASEPAL trumps all, then it's arbitrary. - pal = min(pal, pp2->palette); -#endif // g_restorePalette < 0: reset tinting, too (e.g. when loading new game) P_SetGamePalette(pp, pal, 2 + (g_restorePalette>0)*16); - -#ifdef SPLITSCREEN_MOD_HACKS - if (pp2) // keep first player's pal as its member! - pp->palette = opal; -#endif - g_restorePalette = 0; } else diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index c563c790d..6af0df8c4 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -37,6 +37,8 @@ #include "glbackend.h" #include "gl_samplers.h" #include "gl_shader.h" +#include "textures.h" +#include "palette.h" #include "baselayer.h" #include "resourcefile.h" @@ -201,56 +203,71 @@ std::pair GLInstance::AllocVertices(size_t num) return std::make_pair((size_t)0, Buffer.data()); } -void GLInstance::ApplyTextureProps() +extern int r_detailmapping, r_glowmapping, usehightile; + +bool GLInstance::ApplyTextureProps() { - + int pal = palmanager.ActivePalswap(); + if (currentTexture == nullptr) return false; + auto rep = currentTexture->FindReplacement(pal); VSMatrix texmat; - // texture scale by parkar request - if (pth->hicr && !drawingskybox && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) + bool changed = false; + + // texture scale + if (rep && ((rep->scale.x != 1.0f) || (rep->scale.y != 1.0f))) { texmat.loadIdentity(); - texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); + texmat.scale(rep->scale.x, rep->scale.y, 1.0f); GLInterface.SetMatrix(Matrix_Texture, &texmat); } - // detail texture if (r_detailmapping) { - pthtyp *detailpth = NULL; - - if (usehightile && !drawingskybox && hicfindsubst(globalpicnum, DETAILPAL, 1) && - (detailpth = texcache_fetch(globalpicnum, DETAILPAL, 0, method & ~DAMETH_MASKPROPS)) && - detailpth->hicr && detailpth->hicr->palnum == DETAILPAL) + auto detailrep = currentTexture->FindReplacement(DETAILPAL); + if (detailrep) { - GLInterface.UseDetailMapping(true); - polymost_setupdetailtexture(3, detailpth->glpic); + UseDetailMapping(true); + //BindTexture(3, detailrep->faces[0], SamplerRepeat); texmat.loadIdentity(); + bool scaled = false; - if (pth->hicr && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) - texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); + if (rep && ((rep->scale.x != 1.0f) || (rep->scale.y != 1.0f))) + { + texmat.scale(rep->scale.x, rep->scale.y, 1.0f); + scaled = true; + } - if ((detailpth->hicr->scale.x != 1.0f) || (detailpth->hicr->scale.y != 1.0f)) - texmat.scale(detailpth->hicr->scale.x, detailpth->hicr->scale.y, 1.0f); + if ((detailrep->scale.x != 1.0f) || (detailrep->scale.y != 1.0f)) + { + texmat.scale(detailrep->scale.x, detailrep->scale.y, 1.0f); + scaled = true; + } - GLInterface.SetMatrix(Matrix_Detail, &texmat); + if (scaled) GLInterface.SetMatrix(Matrix_Detail, &texmat); + changed |= scaled; } } // glow texture if (r_glowmapping) { - pthtyp *glowpth = NULL; - - if (usehightile && !drawingskybox && hicfindsubst(globalpicnum, GLOWPAL, 1) && - (glowpth = texcache_fetch(globalpicnum, GLOWPAL, 0, (method & ~DAMETH_MASKPROPS) | DAMETH_MASK)) && - glowpth->hicr && (glowpth->hicr->palnum == GLOWPAL)) - { - GLInterface.UseGlowMapping(true); - polymost_setupglowtexture(4, glowpth->glpic); - } + auto glowrep = currentTexture->FindReplacement(GLOWPAL); + if (glowrep) + { + UseGlowMapping(true); + //BindTexture(4, glowrep->faces[0], SamplerRepeat); + } } - return true; // true if the matrices were changed, false otherwise + + auto brightrep = currentTexture->FindReplacement(BRIGHTPAL); + if (brightrep) + { + //UseGlowMapping(true); + //BindTexture(5, glowrep->faces[0], SamplerRepeat); + } + + return false; // true if the matrices were changed, false otherwise } void GLInstance::RestoreTextureProps() diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 3aec7987e..d827f02c1 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -80,6 +80,7 @@ public: void BindPalette(int index); void BindPalswap(int index); + int ActivePalswap() const { return lastsindex; } }; @@ -200,6 +201,7 @@ class GLInstance PaletteManager palmanager; int lastPalswapIndex = -1; FHardwareTexture* texv; + FTexture* currentTexture = nullptr; VSMatrix matrices[NUMMATRICES]; @@ -277,7 +279,8 @@ public: void SetSurfaceShader(); void SetVPXShader(); void SetPalette(int palette); - void ApplyTextureProps(); + bool ApplyTextureProps(); + void RestoreTextureProps(); void ReadPixels(int w, int h, uint8_t* buffer); @@ -352,10 +355,15 @@ public: renderState.Brightness = 8.f / (brightness + 8.f); } - void SetTinting(int flags, PalEntry color) + void SetTinting(int flags, PalEntry color, PalEntry modulateColor) { // not yet implemented. } + + void SetBasepalTint(PalEntry color) + { + // not yet implemented - only relevant for hires replacements. + } FTexture *GetTexture(const char *filename); };