From f8e9cb8fbc3de1322acae05552039a56f6bc1fdf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 19:00:07 +0200 Subject: [PATCH] - major dependency reduction of the texture system. --- src/am_map.cpp | 1 + src/common/utility/palutil.h | 1 + src/console/c_cmds.cpp | 1 + src/console/c_console.cpp | 1 + src/d_main.cpp | 121 ++++++- src/g_dumpinfo.cpp | 1 + src/g_level.cpp | 1 + src/g_statusbar/sbar_mugshot.cpp | 1 + src/g_statusbar/sbarinfo.cpp | 1 + src/g_statusbar/shared_sbar.cpp | 1 + src/gamedata/decallib.cpp | 1 + src/gamedata/fonts/font.cpp | 2 + src/gamedata/fonts/hexfont.cpp | 2 + src/gamedata/fonts/singlelumpfont.cpp | 1 + src/gamedata/fonts/singlepicfont.cpp | 1 + src/gamedata/fonts/specialfont.cpp | 1 + src/gamedata/fonts/v_font.cpp | 1 + src/gamedata/info.cpp | 1 + src/gamedata/p_terrain.cpp | 1 + src/gamedata/r_defs.h | 1 + src/gamedata/textures/anim_switches.cpp | 1 + src/gamedata/textures/animations.cpp | 1 + .../textures/formats/buildtexture.cpp | 2 + .../textures/formats/emptytexture.cpp | 1 - src/gamedata/textures/formats/flattexture.cpp | 1 - .../textures/formats/multipatchtexture.h | 7 +- src/gamedata/textures/formats/pngtexture.cpp | 3 +- .../textures/formats/rawpagetexture.cpp | 1 - .../textures/formats/shadertexture.cpp | 3 +- src/gamedata/textures/hires/hqresize.cpp | 5 +- src/gamedata/textures/image.cpp | 8 +- src/gamedata/textures/image.h | 6 +- src/gamedata/textures/imagetexture.cpp | 5 +- .../textures/multipatchtexturebuilder.cpp | 81 +---- src/gamedata/textures/skyboxtexture.cpp | 1 + src/gamedata/textures/texmanip.h | 75 +++++ src/gamedata/textures/texture.cpp | 57 +--- src/gamedata/textures/texturemanager.cpp | 296 +----------------- src/gamedata/textures/texturemanager.h | 186 +++++++++++ src/gamedata/textures/textures.h | 231 ++------------ src/hu_scores.cpp | 1 + src/intermission/intermission.cpp | 1 + src/maploader/maploader.cpp | 1 + src/maploader/udmf.cpp | 1 + src/menu/menu.cpp | 5 +- src/menu/menudef.cpp | 40 ++- src/p_setup.cpp | 1 + src/playsim/a_decals.cpp | 1 + src/playsim/fragglescript/t_func.cpp | 1 + src/playsim/fragglescript/t_load.cpp | 1 + src/playsim/mapthinkers/a_doors.cpp | 1 + src/playsim/p_3dmidtex.cpp | 1 + src/playsim/p_acs.cpp | 1 + src/playsim/p_sectors.cpp | 1 + src/r_data/colormaps.cpp | 1 + src/r_data/gldefs.cpp | 1 + src/r_data/models/models.cpp | 1 + src/r_data/models/models_md2.cpp | 1 + src/r_data/models/models_md3.cpp | 1 + src/r_data/models/models_obj.cpp | 1 + src/r_data/models/models_ue1.cpp | 1 + src/r_data/models/models_voxel.cpp | 1 + src/r_data/r_canvastexture.cpp | 1 + src/r_data/r_translate.h | 71 ----- src/r_data/sprites.cpp | 1 + src/rendering/2d/v_draw.cpp | 1 + src/rendering/gl/renderer/gl_renderer.cpp | 1 + .../postprocessing/hw_postprocess.cpp | 1 + src/rendering/hwrenderer/scene/hw_bsp.cpp | 1 + src/rendering/hwrenderer/scene/hw_decal.cpp | 1 + .../hwrenderer/scene/hw_fakeflat.cpp | 1 + .../hwrenderer/scene/hw_renderhacks.cpp | 1 + src/rendering/hwrenderer/scene/hw_sky.cpp | 1 + src/rendering/hwrenderer/scene/hw_sprites.cpp | 1 + src/rendering/hwrenderer/scene/hw_walls.cpp | 1 + src/rendering/hwrenderer/scene/hw_weapon.cpp | 1 + .../hwrenderer/textures/hw_material.cpp | 52 +++ .../hwrenderer/textures/hw_material.h | 2 - .../hwrenderer/textures/hw_precache.cpp | 6 +- .../hwrenderer/textures/hw_texcontainer.h | 1 + src/rendering/hwrenderer/utility/hw_cvars.cpp | 1 + src/rendering/r_sky.cpp | 1 + src/rendering/swrenderer/line/r_line.cpp | 1 + .../swrenderer/line/r_renderdrawsegment.cpp | 1 + src/rendering/swrenderer/plane/r_skyplane.cpp | 1 + .../swrenderer/plane/r_visibleplane.cpp | 1 + src/rendering/swrenderer/r_swrenderer.cpp | 3 +- src/rendering/swrenderer/r_swscene.cpp | 1 + .../swrenderer/scene/r_opaque_pass.cpp | 1 + .../swrenderer/textures/r_swtexture.cpp | 5 + .../swrenderer/textures/warpbuffer.h | 3 +- src/rendering/swrenderer/things/r_decal.cpp | 1 + src/rendering/swrenderer/things/r_model.cpp | 1 + .../swrenderer/things/r_playersprite.cpp | 1 + src/scripting/backend/codegen.cpp | 1 + src/scripting/backend/codegen.h | 1 + src/scripting/thingdef_properties.cpp | 1 + src/scripting/vm/jit_move.cpp | 1 + src/scripting/vm/vmexec.cpp | 1 + src/scripting/vmthunks.cpp | 179 ++++++++++- src/serializer.cpp | 1 + src/utility/v_collection.cpp | 1 + src/wi_stuff.cpp | 1 + 103 files changed, 820 insertions(+), 712 deletions(-) create mode 100644 src/gamedata/textures/texmanip.h create mode 100644 src/gamedata/textures/texturemanager.h diff --git a/src/am_map.cpp b/src/am_map.cpp index 77cf0d5ad..9d2ac227d 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -67,6 +67,7 @@ #include "earcut.hpp" #include "c_buttons.h" #include "d_buttons.h" +#include "texturemanager.h" //============================================================================= diff --git a/src/common/utility/palutil.h b/src/common/utility/palutil.h index 7e6e966cf..077c4c036 100644 --- a/src/common/utility/palutil.h +++ b/src/common/utility/palutil.h @@ -1,6 +1,7 @@ #pragma once #include +#include "zstring.h" #include "palentry.h" struct FScriptPosition; diff --git a/src/console/c_cmds.cpp b/src/console/c_cmds.cpp index 6deec16b6..ef7115709 100644 --- a/src/console/c_cmds.cpp +++ b/src/console/c_cmds.cpp @@ -67,6 +67,7 @@ #include "findfile.h" #include "i_music.h" #include "s_music.h" +#include "texturemanager.h" extern FILE *Logfile; extern bool insave; diff --git a/src/console/c_console.cpp b/src/console/c_console.cpp index b28eeb525..3d28ff715 100644 --- a/src/console/c_console.cpp +++ b/src/console/c_console.cpp @@ -66,6 +66,7 @@ #include "utf8.h" #include "s_music.h" #include "i_time.h" +#include "texturemanager.h" #include "gi.h" diff --git a/src/d_main.cpp b/src/d_main.cpp index c14fcdc72..b74c731d8 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -108,6 +108,8 @@ #include "d_buttons.h" #include "i_interface.h" #include "animations.h" +#include "texturemanager.h" +#include "formats/multipatchtexture.h" EXTERN_CVAR(Bool, hud_althud) EXTERN_CVAR(Int, vr_mode) @@ -2626,6 +2628,121 @@ static bool System_CaptureModeInGame() } +static void PatchTextures() +{ + // The Hexen scripts use BLANK as a blank texture, even though it's really not. + // I guess the Doom renderer must have clipped away the line at the bottom of + // the texture so it wasn't visible. Change its use type to a blank null texture to really make it blank. + if (gameinfo.gametype == GAME_Hexen) + { + FTextureID tex = TexMan.CheckForTexture("BLANK", ETextureType::Wall, false); + if (tex.Exists()) + { + auto texture = TexMan.GetTexture(tex, false); + texture->SetUseType(ETextureType::Null); + } + } + + // Hexen parallax skies use color 0 to indicate transparency on the front + // layer, so we must not remap color 0 on these textures. Unfortunately, + // the only way to identify these textures is to check the MAPINFO. + for (unsigned int i = 0; i < wadlevelinfos.Size(); ++i) + { + if (wadlevelinfos[i].flags & LEVEL_DOUBLESKY) + { + FTextureID picnum = TexMan.CheckForTexture(wadlevelinfos[i].SkyPic1, ETextureType::Wall, false); + if (picnum.isValid()) + { + TexMan.GetTexture(picnum)->SetFrontSkyLayer(); + } + } + } + +} + +//========================================================================== +// +// this gets called during texture creation to fix known problems +// +//========================================================================== + +static void CheckForHacks(BuildInfo& buildinfo) +{ + if (buildinfo.Parts.Size() == 0) + { + return; + } + + // Heretic sky textures are marked as only 128 pixels tall, + // even though they are really 200 pixels tall. + if (gameinfo.gametype == GAME_Heretic && + buildinfo.Name.Len() == 4 && + buildinfo.Name[0] == 'S' && + buildinfo.Name[1] == 'K' && + buildinfo.Name[2] == 'Y' && + buildinfo.Name[3] >= '1' && + buildinfo.Name[3] <= '3' && + buildinfo.Height == 128) + { + buildinfo.Height = 200; + buildinfo.tex->SetSize(buildinfo.tex->GetTexelWidth(), 200); + return; + } + + // The Doom E1 sky has its patch's y offset at -8 instead of 0. + if (gameinfo.gametype == GAME_Doom && + !(gameinfo.flags & GI_MAPxx) && + buildinfo.Name.Len() == 4 && + buildinfo.Parts.Size() == 1 && + buildinfo.Height == 128 && + buildinfo.Parts[0].OriginY == -8 && + buildinfo.Name[0] == 'S' && + buildinfo.Name[1] == 'K' && + buildinfo.Name[2] == 'Y' && + buildinfo.Name[3] == '1') + { + buildinfo.Parts[0].OriginY = 0; + return; + } + + // BIGDOOR7 in Doom also has patches at y offset -4 instead of 0. + if (gameinfo.gametype == GAME_Doom && + !(gameinfo.flags & GI_MAPxx) && + buildinfo.Name.CompareNoCase("BIGDOOR7") == 0 && + buildinfo.Parts.Size() == 2 && + buildinfo.Height == 128 && + buildinfo.Parts[0].OriginY == -4 && + buildinfo.Parts[1].OriginY == -4) + { + buildinfo.Parts[0].OriginY = 0; + buildinfo.Parts[1].OriginY = 0; + return; + } +} + +CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + // This is in case the sky texture has been substituted. + R_InitSkyMap(); +} + +//========================================================================== +// +// FTextureManager :: PalCheck taken out of the texture manager because it ties it to other subsystems +// todo: move elsewhere +// +//========================================================================== + +int PalCheck(int tex) +{ + // In any true color mode this shouldn't do anything. + if (vid_nopalsubstitutions || V_IsTrueColor()) return tex; + FTexture *ftex = TexMan.ByIndex(tex); + if (ftex != nullptr && ftex->GetPalVersion() != nullptr) return ftex->GetPalVersion()->GetID().GetIndex(); + return tex; +} + + //========================================================================== // // D_DoomMain @@ -2945,7 +3062,9 @@ static int D_DoomMain_Internal (void) S_ParseMusInfo(); if (!batchrun) Printf ("Texman.Init: Init texture manager.\n"); - TexMan.Init(); + SpriteFrames.Clear(); + TexMan.Init([]() { StartScreen->Progress(); }, CheckForHacks); + PatchTextures(); TexAnim.Init(); C_InitConback(); diff --git a/src/g_dumpinfo.cpp b/src/g_dumpinfo.cpp index 33376d4ae..01f19b46b 100644 --- a/src/g_dumpinfo.cpp +++ b/src/g_dumpinfo.cpp @@ -43,6 +43,7 @@ #include "v_text.h" #include "c_functions.h" #include "gstrings.h" +#include "texturemanager.h" //========================================================================== // diff --git a/src/g_level.cpp b/src/g_level.cpp index b1ba92501..6b62bdbf5 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -91,6 +91,7 @@ #include "i_time.h" #include "p_maputl.h" #include "s_music.h" +#include "texturemanager.h" void STAT_StartNewGame(const char *lev); void STAT_ChangeLevel(const char *newl, FLevelLocals *Level); diff --git a/src/g_statusbar/sbar_mugshot.cpp b/src/g_statusbar/sbar_mugshot.cpp index 9fb6f4e76..09e483ef8 100644 --- a/src/g_statusbar/sbar_mugshot.cpp +++ b/src/g_statusbar/sbar_mugshot.cpp @@ -39,6 +39,7 @@ #include "sbar.h" #include "r_utility.h" #include "actorinlines.h" +#include "texturemanager.h" #define ST_RAMPAGEDELAY (2*TICRATE) #define ST_MUCHPAIN 20 diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 3f2de463f..f1bdf3ff4 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -49,6 +49,7 @@ #include "vm.h" #include "i_system.h" #include "utf8.h" +#include "texturemanager.h" #define ARTIFLASH_OFFSET (statusBar->invBarOffset+6) enum diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index cc20fe026..e294c716a 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -59,6 +59,7 @@ #include "events.h" #include "g_game.h" #include "utf8.h" +#include "texturemanager.h" #include "../version.h" diff --git a/src/gamedata/decallib.cpp b/src/gamedata/decallib.cpp index 3c5bb9f0d..4c2223250 100644 --- a/src/gamedata/decallib.cpp +++ b/src/gamedata/decallib.cpp @@ -47,6 +47,7 @@ #include "serializer.h" #include "g_levellocals.h" #include "a_decalfx.h" +#include "texturemanager.h" FDecalLib DecalLibrary; diff --git a/src/gamedata/fonts/font.cpp b/src/gamedata/fonts/font.cpp index ee856befa..e437bae15 100644 --- a/src/gamedata/fonts/font.cpp +++ b/src/gamedata/fonts/font.cpp @@ -58,6 +58,8 @@ #include "myiswalpha.h" #include "textures/formats/fontchars.h" #include "textures/formats/multipatchtexture.h" +#include "texturemanager.h" +#include "r_translate.h" #include "fontinternals.h" diff --git a/src/gamedata/fonts/hexfont.cpp b/src/gamedata/fonts/hexfont.cpp index 9e15a69ec..a6a6d088f 100644 --- a/src/gamedata/fonts/hexfont.cpp +++ b/src/gamedata/fonts/hexfont.cpp @@ -39,6 +39,8 @@ #include "filesystem.h" #include "utf8.h" #include "sc_man.h" +#include "texturemanager.h" +#include "r_translate.h" #include "fontinternals.h" diff --git a/src/gamedata/fonts/singlelumpfont.cpp b/src/gamedata/fonts/singlelumpfont.cpp index f1aafd10d..393f9e783 100644 --- a/src/gamedata/fonts/singlelumpfont.cpp +++ b/src/gamedata/fonts/singlelumpfont.cpp @@ -40,6 +40,7 @@ #include "filesystem.h" #include "utf8.h" #include "textures/formats/fontchars.h" +#include "texturemanager.h" #include "fontinternals.h" diff --git a/src/gamedata/fonts/singlepicfont.cpp b/src/gamedata/fonts/singlepicfont.cpp index a42aafe79..8d289944d 100644 --- a/src/gamedata/fonts/singlepicfont.cpp +++ b/src/gamedata/fonts/singlepicfont.cpp @@ -37,6 +37,7 @@ #include "textures.h" #include "v_font.h" #include "filesystem.h" +#include "texturemanager.h" class FSinglePicFont : public FFont { diff --git a/src/gamedata/fonts/specialfont.cpp b/src/gamedata/fonts/specialfont.cpp index 6231db07e..f2ce0ece8 100644 --- a/src/gamedata/fonts/specialfont.cpp +++ b/src/gamedata/fonts/specialfont.cpp @@ -37,6 +37,7 @@ #include "textures.h" #include "image.h" #include "textures/formats/fontchars.h" +#include "texturemanager.h" #include "fontinternals.h" diff --git a/src/gamedata/fonts/v_font.cpp b/src/gamedata/fonts/v_font.cpp index f16a11e79..d00a7b0f9 100644 --- a/src/gamedata/fonts/v_font.cpp +++ b/src/gamedata/fonts/v_font.cpp @@ -55,6 +55,7 @@ #include "image.h" #include "utf8.h" #include "textures/formats/fontchars.h" +#include "texturemanager.h" #include "fontinternals.h" diff --git a/src/gamedata/info.cpp b/src/gamedata/info.cpp index 3c98f8191..b7cc3531c 100644 --- a/src/gamedata/info.cpp +++ b/src/gamedata/info.cpp @@ -52,6 +52,7 @@ #include "types.h" #include "filesystem.h" #include "g_levellocals.h" +#include "texturemanager.h" extern void LoadActors (); extern void InitBotStuff(); diff --git a/src/gamedata/p_terrain.cpp b/src/gamedata/p_terrain.cpp index 3b71db0f2..6371502c5 100644 --- a/src/gamedata/p_terrain.cpp +++ b/src/gamedata/p_terrain.cpp @@ -46,6 +46,7 @@ #include "p_local.h" #include "actor.h" #include "vm.h" +#include "texturemanager.h" // MACROS ------------------------------------------------------------------ diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index 1ea203f2d..3e68a8e3e 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -35,6 +35,7 @@ #include "m_bbox.h" #include "dobjgc.h" #include "r_data/r_translate.h" +#include "texmanip.h" // Some more or less basic data types // we depend on. diff --git a/src/gamedata/textures/anim_switches.cpp b/src/gamedata/textures/anim_switches.cpp index 1212efd2b..f6acd67b0 100644 --- a/src/gamedata/textures/anim_switches.cpp +++ b/src/gamedata/textures/anim_switches.cpp @@ -41,6 +41,7 @@ #include "sc_man.h" #include "gi.h" #include "animations.h" +#include "texturemanager.h" static int SortSwitchDefs (const void *a, const void *b) diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index c759da4c3..99dc2aaf6 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -42,6 +42,7 @@ #include "filesystem.h" #include "serializer.h" #include "animations.h" +#include "texturemanager.h" // MACROS ------------------------------------------------------------------ diff --git a/src/gamedata/textures/formats/buildtexture.cpp b/src/gamedata/textures/formats/buildtexture.cpp index 5cbcc0e31..dff76d757 100644 --- a/src/gamedata/textures/formats/buildtexture.cpp +++ b/src/gamedata/textures/formats/buildtexture.cpp @@ -44,6 +44,8 @@ #include "resourcefile.h" #include "image.h" #include "animations.h" +#include "texturemanager.h" +#include "r_translate.h" //========================================================================== diff --git a/src/gamedata/textures/formats/emptytexture.cpp b/src/gamedata/textures/formats/emptytexture.cpp index 108c248e6..ab4703e4e 100644 --- a/src/gamedata/textures/formats/emptytexture.cpp +++ b/src/gamedata/textures/formats/emptytexture.cpp @@ -37,7 +37,6 @@ #include "files.h" #include "filesystem.h" -#include "textures/textures.h" #include "image.h" //========================================================================== diff --git a/src/gamedata/textures/formats/flattexture.cpp b/src/gamedata/textures/formats/flattexture.cpp index ca26d0548..20c5d052a 100644 --- a/src/gamedata/textures/formats/flattexture.cpp +++ b/src/gamedata/textures/formats/flattexture.cpp @@ -35,7 +35,6 @@ #include "files.h" #include "filesystem.h" -#include "textures/textures.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/multipatchtexture.h b/src/gamedata/textures/formats/multipatchtexture.h index d5c3be0ef..f9f5913e1 100644 --- a/src/gamedata/textures/formats/multipatchtexture.h +++ b/src/gamedata/textures/formats/multipatchtexture.h @@ -3,6 +3,8 @@ #include "palettecontainer.h" #include "textureid.h" #include "vectors.h" +#include "bitmap.h" +#include "image.h" class FImageTexture; //========================================================================== @@ -121,6 +123,8 @@ class FMultipatchTextureBuilder { FTextureManager &TexMan; TArray BuiltTextures; + void(*progressFunc)(); + void(*checkForHacks)(BuildInfo&); void MakeTexture(BuildInfo &buildinfo, ETextureType usetype); @@ -128,11 +132,10 @@ class FMultipatchTextureBuilder void AddTexturesLump(const void *lumpdata, int lumpsize, int deflumpnum, int patcheslump, int firstdup, bool texture1); void ParsePatch(FScanner &sc, BuildInfo &info, TexPart &part, TexInit &init); - void CheckForHacks(BuildInfo &buildinfo); void ResolvePatches(BuildInfo &buildinfo); public: - FMultipatchTextureBuilder(FTextureManager &texMan) : TexMan(texMan) + FMultipatchTextureBuilder(FTextureManager &texMan, void(*progressFunc_)(), void(*checkForHacks_)(BuildInfo &)) : TexMan(texMan), progressFunc(progressFunc_), checkForHacks(checkForHacks_) { } diff --git a/src/gamedata/textures/formats/pngtexture.cpp b/src/gamedata/textures/formats/pngtexture.cpp index c6f7f0cf4..58c2b25d4 100644 --- a/src/gamedata/textures/formats/pngtexture.cpp +++ b/src/gamedata/textures/formats/pngtexture.cpp @@ -40,7 +40,7 @@ #include "bitmap.h" #include "imagehelpers.h" #include "image.h" -#include "textures.h" +#include "printf.h" //========================================================================== // @@ -557,6 +557,7 @@ int FPNGTexture::CopyPixels(FBitmap *bmp, int conversion) } +#include "textures.h" //========================================================================== // diff --git a/src/gamedata/textures/formats/rawpagetexture.cpp b/src/gamedata/textures/formats/rawpagetexture.cpp index be979e285..38fca7a67 100644 --- a/src/gamedata/textures/formats/rawpagetexture.cpp +++ b/src/gamedata/textures/formats/rawpagetexture.cpp @@ -36,7 +36,6 @@ #include "files.h" #include "filesystem.h" #include "bitmap.h" -#include "textures/textures.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/shadertexture.cpp b/src/gamedata/textures/formats/shadertexture.cpp index 9a8f2842e..d07f30706 100644 --- a/src/gamedata/textures/formats/shadertexture.cpp +++ b/src/gamedata/textures/formats/shadertexture.cpp @@ -34,7 +34,6 @@ ** */ -#include "menu/menu.h" #include "filesystem.h" #include "bitmap.h" #include "imagehelpers.h" @@ -132,6 +131,6 @@ private: FTexture *CreateShaderTexture(bool vertical, bool reverse) { FStringf name("BarShader%c%c", vertical ? 'v' : 'h', reverse ? 'r' : 'f'); - return new FImageTexture(new FBarShader(vertical, reverse), name.GetChars()); + return CreateImageTexture(new FBarShader(vertical, reverse), name.GetChars()); } diff --git a/src/gamedata/textures/hires/hqresize.cpp b/src/gamedata/textures/hires/hqresize.cpp index 8a63dd06f..e04be8262 100644 --- a/src/gamedata/textures/hires/hqresize.cpp +++ b/src/gamedata/textures/hires/hqresize.cpp @@ -35,7 +35,6 @@ */ #include "c_cvars.h" -#include "v_video.h" #include "hqnx/hqx.h" #ifdef HAVE_MMX #include "hqnx_asm/hqnx_asm.h" @@ -43,7 +42,9 @@ #include "xbr/xbrz.h" #include "xbr/xbrz_old.h" #include "parallel_for.h" -#include "hwrenderer/textures/hw_material.h" +#include "textures.h" +#include "texturemanager.h" +#include "printf.h" EXTERN_CVAR(Int, gl_texture_hqresizemult) CUSTOM_CVAR(Int, gl_texture_hqresizemode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) diff --git a/src/gamedata/textures/image.cpp b/src/gamedata/textures/image.cpp index a27319322..9a8f7028e 100644 --- a/src/gamedata/textures/image.cpp +++ b/src/gamedata/textures/image.cpp @@ -34,12 +34,12 @@ ** */ -#include "v_video.h" #include "bitmap.h" #include "image.h" #include "filesystem.h" #include "files.h" #include "cmdlib.h" +#include "palettecontainer.h" FMemArena FImageSource::ImageArena(32768); TArrayFImageSource::ImageForLump; @@ -283,7 +283,7 @@ FBitmap FImageSource::GetCachedBitmap(PalEntry *remap, int conversion, int *ptra void FImageSource::CollectForPrecache(PrecacheInfo &info, bool requiretruecolor) { auto val = info.CheckKey(ImageID); - bool tc = requiretruecolor || V_IsTrueColor(); + bool tc = requiretruecolor; if (val) { val->first += tc; @@ -307,9 +307,9 @@ void FImageSource::EndPrecaching() precacheDataRgba.Clear(); } -void FImageSource::RegisterForPrecache(FImageSource *img) +void FImageSource::RegisterForPrecache(FImageSource *img, bool requiretruecolor) { - img->CollectForPrecache(precacheInfo); + img->CollectForPrecache(precacheInfo, requiretruecolor); } //========================================================================== diff --git a/src/gamedata/textures/image.h b/src/gamedata/textures/image.h index afaa96205..f05d7c5bd 100644 --- a/src/gamedata/textures/image.h +++ b/src/gamedata/textures/image.h @@ -140,12 +140,12 @@ public: return bUseGamePalette; } - virtual void CollectForPrecache(PrecacheInfo &info, bool requiretruecolor = false); + virtual void CollectForPrecache(PrecacheInfo &info, bool requiretruecolor); static void BeginPrecaching(); static void EndPrecaching(); - static void RegisterForPrecache(FImageSource *img); + static void RegisterForPrecache(FImageSource *img, bool requiretruecolor); }; class FTexture; -FTexture* CreateImageTexture(FImageSource* img) noexcept; +FTexture* CreateImageTexture(FImageSource* img, const char *name = nullptr) noexcept; diff --git a/src/gamedata/textures/imagetexture.cpp b/src/gamedata/textures/imagetexture.cpp index 1405ac4f7..4fe578003 100644 --- a/src/gamedata/textures/imagetexture.cpp +++ b/src/gamedata/textures/imagetexture.cpp @@ -38,7 +38,6 @@ #include "filesystem.h" #include "templates.h" #include "bitmap.h" -#include "v_video.h" #include "image.h" #include "textures.h" @@ -91,8 +90,8 @@ TArray FImageTexture::Get8BitPixels(bool alpha) } -FTexture* CreateImageTexture(FImageSource* img) noexcept +FTexture* CreateImageTexture(FImageSource* img, const char *name) noexcept { - return new FImageTexture(img); + return new FImageTexture(img, name); } diff --git a/src/gamedata/textures/multipatchtexturebuilder.cpp b/src/gamedata/textures/multipatchtexturebuilder.cpp index 33017eb59..a048e7a86 100644 --- a/src/gamedata/textures/multipatchtexturebuilder.cpp +++ b/src/gamedata/textures/multipatchtexturebuilder.cpp @@ -38,22 +38,13 @@ #include "doomtype.h" #include "files.h" #include "filesystem.h" - -#include "gi.h" -#include "st_start.h" -#include "sc_man.h" -#include "templates.h" -#include "r_data/r_translate.h" +#include "engineerrors.h" #include "bitmap.h" -#include "colormatcher.h" -#include "v_palette.h" -#include "v_video.h" -#include "v_text.h" -#include "cmdlib.h" -#include "imagehelpers.h" +#include "textures.h" #include "image.h" #include "formats/multipatchtexture.h" -#include "engineerrors.h" +#include "texturemanager.h" + // On the Alpha, accessing the shorts directly if they aren't aligned on a // 4-byte boundary causes unaligned access warnings. Why it does this at @@ -388,7 +379,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi if (j + 1 == firstdup) { BuildTexture((const uint8_t *)maptex + offset, patchlookup.Data(), numpatches, isStrife, deflumpnum, (i == 1 && texture1) ? ETextureType::FirstDefined : ETextureType::Wall); - StartScreen->Progress(); + progressFunc(); } } } @@ -772,66 +763,6 @@ void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType) -//========================================================================== -// -// FMultiPatchTexture :: CheckForHacks -// -//========================================================================== - -void FMultipatchTextureBuilder::CheckForHacks(BuildInfo &buildinfo) -{ - if (buildinfo.Parts.Size() == 0) - { - return; - } - - // Heretic sky textures are marked as only 128 pixels tall, - // even though they are really 200 pixels tall. - if (gameinfo.gametype == GAME_Heretic && - buildinfo.Name.Len() == 4 && - buildinfo.Name[0] == 'S' && - buildinfo.Name[1] == 'K' && - buildinfo.Name[2] == 'Y' && - buildinfo.Name[3] >= '1' && - buildinfo.Name[3] <= '3' && - buildinfo.Height == 128) - { - buildinfo.Height = 200; - buildinfo.tex->SetSize(buildinfo.tex->Width, 200); - return; - } - - // The Doom E1 sky has its patch's y offset at -8 instead of 0. - if (gameinfo.gametype == GAME_Doom && - !(gameinfo.flags & GI_MAPxx) && - buildinfo.Name.Len() == 4 && - buildinfo.Parts.Size() == 1 && - buildinfo.Height == 128 && - buildinfo.Parts[0].OriginY == -8 && - buildinfo.Name[0] == 'S' && - buildinfo.Name[1] == 'K' && - buildinfo.Name[2] == 'Y' && - buildinfo.Name[3] == '1') - { - buildinfo.Parts[0].OriginY = 0; - return; - } - - // BIGDOOR7 in Doom also has patches at y offset -4 instead of 0. - if (gameinfo.gametype == GAME_Doom && - !(gameinfo.flags & GI_MAPxx) && - buildinfo.Name.CompareNoCase("BIGDOOR7") == 0 && - buildinfo.Parts.Size() == 2 && - buildinfo.Height == 128 && - buildinfo.Parts[0].OriginY == -4 && - buildinfo.Parts[1].OriginY == -4) - { - buildinfo.Parts[0].OriginY = 0; - buildinfo.Parts[1].OriginY = 0; - return; - } -} - //========================================================================== // // @@ -911,7 +842,7 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) } } - CheckForHacks(buildinfo); + checkForHacks(buildinfo); } void FMultipatchTextureBuilder::ResolveAllPatches() diff --git a/src/gamedata/textures/skyboxtexture.cpp b/src/gamedata/textures/skyboxtexture.cpp index 9312c2303..ea3b406da 100644 --- a/src/gamedata/textures/skyboxtexture.cpp +++ b/src/gamedata/textures/skyboxtexture.cpp @@ -25,6 +25,7 @@ #include "textures.h" #include "skyboxtexture.h" #include "bitmap.h" +#include "texturemanager.h" diff --git a/src/gamedata/textures/texmanip.h b/src/gamedata/textures/texmanip.h new file mode 100644 index 000000000..c5e3a368a --- /dev/null +++ b/src/gamedata/textures/texmanip.h @@ -0,0 +1,75 @@ +#pragma once + +#include "palentry.h" + +struct TextureManipulation +{ + enum + { + BlendNone = 0, + BlendAlpha = 1, + BlendScreen = 2, + BlendOverlay = 3, + BlendHardLight = 4, + BlendMask = 7, + InvertBit = 8, + ActiveBit = 16, // Must be set for the shader to do something + }; + PalEntry AddColor; // Alpha contains the blend flags + PalEntry ModulateColor; // Alpha may contain a multiplier to get higher values than 1.0 without promoting this to 4 full floats. + PalEntry BlendColor; + float DesaturationFactor; + + bool CheckIfEnabled() // check if this manipulation is doing something. NoOps do not need to be preserved, unless they override older setttings. + { + if (AddColor != 0 || // this includes a check for the blend mode without which BlendColor is not active + ModulateColor != 0x01ffffff || // 1 in alpha must be the default for a no-op. + DesaturationFactor != 0) + { + AddColor.a |= ActiveBit; // mark as active for the shader's benefit. + return true; + } + return false; + } + + void SetTextureModulateColor(int slot, PalEntry rgb) + { + rgb.a = ModulateColor.a; + ModulateColor = rgb; + } + + void SetTextureModulateScaleFactor(int slot, int fac) + { + ModulateColor.a = (uint8_t)fac; + } + + void SetTextureAdditiveColor(int slot, PalEntry rgb) + { + rgb.a = AddColor.a; + AddColor = rgb; + } + + void SetTextureBlendColor(int slot, PalEntry rgb) + { + BlendColor = rgb; + } + + void SetTextureDesaturationFactor(int slot, double fac) + { + DesaturationFactor = (float)fac; + } + + void SetTextureBlendMode(int slot, int mode) + { + AddColor.a = (AddColor.a & ~TextureManipulation::BlendMask) | (mode & TextureManipulation::BlendMask); + } + + void SetTextureInvert(bool on) + { + AddColor.a |= TextureManipulation::InvertBit; + AddColor.a &= ~TextureManipulation::InvertBit; + } + +}; + + diff --git a/src/gamedata/textures/texture.cpp b/src/gamedata/textures/texture.cpp index 241dad9b7..ef2ad07bf 100644 --- a/src/gamedata/textures/texture.cpp +++ b/src/gamedata/textures/texture.cpp @@ -38,31 +38,25 @@ #include "files.h" #include "filesystem.h" #include "templates.h" - -#include "r_data/r_translate.h" +#include "textures.h" #include "bitmap.h" #include "colormatcher.h" #include "c_dispatch.h" -#include "v_video.h" #include "m_fixed.h" -#include "hwrenderer/textures/hw_material.h" -#include "hwrenderer/textures/hw_ihwtexture.h" -#include "swrenderer/textures/r_swtexture.h" #include "imagehelpers.h" #include "image.h" #include "formats/multipatchtexture.h" -#include "g_levellocals.h" +#include "texturemanager.h" + +// Wrappers to keep the definitions of these classes out of here. +void DeleteMaterial(FMaterial* mat); +void DeleteSoftwareTexture(FSoftwareTexture *swtex); + FTexture *CreateBrightmapTexture(FImageSource*); // Make sprite offset adjustment user-configurable per renderer. int r_spriteadjustSW, r_spriteadjustHW; -CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - r_spriteadjustHW = !!(self & 2); - r_spriteadjustSW = !!(self & 1); - TexMan.SpriteAdjustChanged(); -} //========================================================================== // @@ -161,12 +155,12 @@ FTexture::~FTexture () for (int i = 0; i < 2; i++) { - if (Material[i] != nullptr) delete Material[i]; + if (Material[i] != nullptr) DeleteMaterial(Material[i]); Material[i] = nullptr; } if (SoftwareTexture != nullptr) { - delete SoftwareTexture; + DeleteSoftwareTexture(SoftwareTexture); SoftwareTexture = nullptr; } } @@ -740,21 +734,6 @@ bool FTexture::GetTranslucency() return !!bTranslucent; } -//=========================================================================== -// -// Sprite adjust has changed. -// This needs to alter the material's sprite rect. -// -//=========================================================================== - -void FTexture::SetSpriteAdjust() -{ - for (auto mat : Material) - { - if (mat != nullptr) mat->SetSpriteRect(); - } -} - //=========================================================================== // // the default just returns an empty texture. @@ -768,24 +747,6 @@ TArray FTexture::Get8BitPixels(bool alphatex) return Pixels; } -//========================================================================== -// -// -// -//========================================================================== - -FWrapperTexture::FWrapperTexture(int w, int h, int bits) -{ - Width = w; - Height = h; - Format = bits; - UseType = ETextureType::SWCanvas; - bNoCompress = true; - auto hwtex = screen->CreateHardwareTexture(); - // todo: Initialize here. - SystemTextures.AddHardwareTexture(0, false, hwtex); -} - //=========================================================================== // // Coordinate helper. diff --git a/src/gamedata/textures/texturemanager.cpp b/src/gamedata/textures/texturemanager.cpp index 2febde077..5d95de540 100644 --- a/src/gamedata/textures/texturemanager.cpp +++ b/src/gamedata/textures/texturemanager.cpp @@ -38,32 +38,16 @@ #include "doomstat.h" #include "filesystem.h" #include "templates.h" -#include "i_system.h" #include "gstrings.h" - -#include "r_data/r_translate.h" -#include "r_data/sprites.h" +#include "textures.h" +#include "texturemanager.h" #include "c_dispatch.h" -#include "v_text.h" #include "sc_man.h" -#include "gi.h" -#include "st_start.h" -#include "cmdlib.h" -#include "g_level.h" -#include "v_video.h" -#include "r_sky.h" -#include "vm.h" #include "image.h" #include "formats/multipatchtexture.h" -#include "swrenderer/textures/r_swtexture.h" FTextureManager TexMan; -CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE|CVAR_NOINITCALL) -{ - // This is in case the sky texture has been substituted. - R_InitSkyMap (); -} //========================================================================== // @@ -126,6 +110,7 @@ void FTextureManager::DeleteAll() // main reason to call this outside of the destruction code. // //========================================================================== +void DeleteSoftwareTexture(FSoftwareTexture* swtex); void FTextureManager::FlushAll() { @@ -134,7 +119,7 @@ void FTextureManager::FlushAll() for (int j = 0; j < 2; j++) { Textures[i].Texture->SystemTextures.Clean(true, true); - delete Textures[i].Texture->SoftwareTexture; + DeleteSoftwareTexture(Textures[i].Texture->SoftwareTexture); Textures[i].Texture->SoftwareTexture = nullptr; } } @@ -262,20 +247,6 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset return FTextureID(-1); } -static int CheckForTexture(const FString &name, int type, int flags) -{ - return TexMan.CheckForTexture(name, static_cast(type), flags).GetIndex(); -} - -DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckForTexture, CheckForTexture) -{ - PARAM_PROLOGUE; - PARAM_STRING(name); - PARAM_INT(type); - PARAM_INT(flags); - ACTION_RETURN_INT(CheckForTexture(name, type, flags)); -} - //========================================================================== // // FTextureManager :: ListTextures @@ -365,38 +336,14 @@ FTexture *FTextureManager::FindTexture(const char *texname, ETextureType usetype return GetTexture(texnum.GetIndex()); } -//========================================================================== -// -// Defines how graphics substitution is handled. -// 0: Never replace a text-containing graphic with a font-based text. -// 1: Always replace, regardless of any missing information. Useful for testing the substitution without providing full data. -// 2: Only replace for non-default texts, i.e. if some language redefines the string's content, use it instead of the graphic. Never replace a localized graphic. -// 3: Only replace if the string is not the default and the graphic comes from the IWAD. Never replace a localized graphic. -// 4: Like 1, but lets localized graphics pass. -// -// The default is 3, which only replaces known content with non-default texts. -// -//========================================================================== - -CUSTOM_CVAR(Int, cl_gfxlocalization, 3, CVAR_ARCHIVE) -{ - if (self < 0 || self > 4) self = 0; -} - //========================================================================== // // FTextureManager :: OkForLocalization // //========================================================================== -bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitute) +bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitute, int locmode) { - if (!texnum.isValid()) return false; - - // First the unconditional settings, 0='never' and 1='always'. - if (cl_gfxlocalization == 1 || gameinfo.forcetextinmenus) return false; - if (cl_gfxlocalization == 0 || gameinfo.forcenogfxsubstitution) return true; - uint32_t langtable = 0; if (*substitute == '$') substitute = GStrings.GetString(substitute+1, &langtable); else return true; // String literals from the source data should never override graphics from the same definition. @@ -407,11 +354,11 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut if (localizedTex != texnum.GetIndex()) return true; // Do not substitute a localized variant of the graphics patch. // For mode 4 we are done now. - if (cl_gfxlocalization == 4) return false; + if (locmode == 4) return false; // Mode 2 and 3 must reject any text replacement from the default language tables. if ((langtable & MAKE_ID(255,0,0,0)) == MAKE_ID('*', 0, 0, 0)) return true; // Do not substitute if the string comes from the default table. - if (cl_gfxlocalization == 2) return false; + if (locmode == 2) return false; // Mode 3 must also reject substitutions for non-IWAD content. int file = fileSystem.GetFileContainer(Textures[texnum.GetIndex()].Texture->SourceLump); @@ -420,19 +367,6 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut return false; } -static int OkForLocalization(int index, const FString &substitute) -{ - return TexMan.OkForLocalization(FSetTextureID(index), substitute); -} - -DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, OkForLocalization, OkForLocalization) -{ - PARAM_PROLOGUE; - PARAM_INT(name); - PARAM_STRING(subst) - ACTION_RETURN_INT(OkForLocalization(name, subst)); -} - //========================================================================== // // FTextureManager :: AddTexture @@ -576,7 +510,7 @@ void FTextureManager::AddGroup(int wadnum, int ns, ETextureType usetype) { CreateTexture (firsttx, usetype); } - StartScreen->Progress(); + progressFunc(); } else if (ns == ns_flats && fileSystem.GetFileFlags(firsttx) & LUMPF_MAYBEFLAT) { @@ -584,7 +518,7 @@ void FTextureManager::AddGroup(int wadnum, int ns, ETextureType usetype) { CreateTexture (firsttx, usetype); } - StartScreen->Progress(); + progressFunc(); } } } @@ -648,7 +582,7 @@ void FTextureManager::AddHiresTextures (int wadnum) } } } - StartScreen->Progress(); + progressFunc(); } } } @@ -855,7 +789,7 @@ void FTextureManager::AddPatches (int lumpnum) { CreateTexture (fileSystem.CheckNumForName (name, ns_patches), ETextureType::WallPatch); } - StartScreen->Progress(); + progressFunc(); } } @@ -1149,10 +1083,10 @@ void FTextureManager::AddLocalizedVariants() FTexture *CreateShaderTexture(bool, bool); void InitBuildTiles(); -void FTextureManager::Init() +void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildInfo&)) { + progressFunc = progressFunc_; DeleteAll(); - SpriteFrames.Clear(); //if (BuildTileFiles.Size() == 0) CountBuildTiles (); // Texture 0 is a dummy texture used to indicate "no texture" @@ -1167,7 +1101,7 @@ void FTextureManager::Init() int wadcnt = fileSystem.GetNumWads(); - FMultipatchTextureBuilder build(*this); + FMultipatchTextureBuilder build(*this, progressFunc_, checkForHacks); for(int i = 0; i< wadcnt; i++) { @@ -1183,34 +1117,6 @@ void FTextureManager::Init() DefaultTexture = CheckForTexture ("-NOFLAT-", ETextureType::Override, 0); - // The Hexen scripts use BLANK as a blank texture, even though it's really not. - // I guess the Doom renderer must have clipped away the line at the bottom of - // the texture so it wasn't visible. Change its use type to a blank null texture to really make it blank. - if (gameinfo.gametype == GAME_Hexen) - { - FTextureID tex = CheckForTexture ("BLANK", ETextureType::Wall, false); - if (tex.Exists()) - { - auto texture = GetTexture(tex, false); - texture->UseType = ETextureType::Null; - } - } - - // Hexen parallax skies use color 0 to indicate transparency on the front - // layer, so we must not remap color 0 on these textures. Unfortunately, - // the only way to identify these textures is to check the MAPINFO. - for (unsigned int i = 0; i < wadlevelinfos.Size(); ++i) - { - if (wadlevelinfos[i].flags & LEVEL_DOUBLESKY) - { - FTextureID picnum = CheckForTexture (wadlevelinfos[i].SkyPic1, ETextureType::Wall, false); - if (picnum.isValid()) - { - Textures[picnum.GetIndex()].Texture->SetFrontSkyLayer (); - } - } - } - InitPalettedVersions(); AdjustSpriteOffsets(); // Add auto materials to each texture after everything has been set up. @@ -1222,7 +1128,6 @@ void FTextureManager::Init() Textures[i].Texture->AddAutoMaterials(); } - glLight = TexMan.CheckForTexture("glstuff/gllight.png", ETextureType::MiscPatch); glPart2 = TexMan.CheckForTexture("glstuff/glpart2.png", ETextureType::MiscPatch); glPart = TexMan.CheckForTexture("glstuff/glpart.png", ETextureType::MiscPatch); mirrorTexture = TexMan.CheckForTexture("glstuff/mirror.png", ETextureType::MiscPatch); @@ -1269,22 +1174,7 @@ void FTextureManager::InitPalettedVersions() //========================================================================== // -// FTextureManager :: PalCheck // -//========================================================================== - -int FTextureManager::PalCheck(int tex) -{ - // In any true color mode this shouldn't do anything. - if (vid_nopalsubstitutions || V_IsTrueColor()) return tex; - auto ftex = Textures[tex].Texture; - if (ftex != nullptr && ftex->PalVersion != nullptr) return ftex->PalVersion->id.GetIndex(); - return tex; -} - -//========================================================================== -// -// FTextureManager :: PalCheck // //========================================================================== EXTERN_CVAR(String, language) @@ -1481,24 +1371,6 @@ void FTextureManager::AdjustSpriteOffsets() } } -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - -void FTextureManager::SpriteAdjustChanged() -{ - for (auto &texi : Textures) - { - auto tex = texi.Texture; - if (tex->GetLeftOffset(0) != tex->GetLeftOffset(1) || tex->GetTopOffset(0) != tex->GetTopOffset(1)) - { - tex->SetSpriteAdjust(); - } - } -} - //========================================================================== // @@ -1522,146 +1394,6 @@ void FTextureManager::SetTranslation(FTextureID fromtexnum, FTextureID totexnum) -//========================================================================== -// -// -// -//========================================================================== - -DEFINE_ACTION_FUNCTION(_TexMan, GetName) -{ - PARAM_PROLOGUE; - PARAM_INT(texid); - auto tex = TexMan.ByIndex(texid); - FString retval; - - if (tex != nullptr) - { - if (tex->GetName().IsNotEmpty()) retval = tex->GetName(); - else - { - // Textures for full path names do not have their own name, they merely link to the source lump. - auto lump = tex->GetSourceLump(); - if (fileSystem.GetLinkedTexture(lump) == tex) - retval = fileSystem.GetFileFullName(lump); - } - } - ACTION_RETURN_STRING(retval); -} - -//========================================================================== -// -// -// -//========================================================================== - -static int GetTextureSize(int texid, int *py) -{ - auto tex = TexMan.ByIndex(texid); - int x, y; - if (tex != nullptr) - { - x = tex->GetDisplayWidth(); - y = tex->GetDisplayHeight(); - } - else x = y = -1; - if (py) *py = y; - return x; -} - -DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetSize, GetTextureSize) -{ - PARAM_PROLOGUE; - PARAM_INT(texid); - int x, y; - x = GetTextureSize(texid, &y); - if (numret > 0) ret[0].SetInt(x); - if (numret > 1) ret[1].SetInt(y); - return MIN(numret, 2); -} - -//========================================================================== -// -// -// -//========================================================================== -static void GetScaledSize(int texid, DVector2 *pvec) -{ - auto tex = TexMan.ByIndex(texid); - double x, y; - if (tex != nullptr) - { - x = tex->GetDisplayWidthDouble(); - y = tex->GetDisplayHeightDouble(); - } - else x = y = -1; - if (pvec) - { - pvec->X = x; - pvec->Y = y; - } -} - -DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledSize, GetScaledSize) -{ - PARAM_PROLOGUE; - PARAM_INT(texid); - DVector2 vec; - GetScaledSize(texid, &vec); - ACTION_RETURN_VEC2(vec); -} - -//========================================================================== -// -// -// -//========================================================================== -static void GetScaledOffset(int texid, DVector2 *pvec) -{ - auto tex = TexMan.ByIndex(texid); - double x, y; - if (tex != nullptr) - { - x = tex->GetDisplayLeftOffsetDouble(); - y = tex->GetDisplayTopOffsetDouble(); - } - else x = y = -1; - if (pvec) - { - pvec->X = x; - pvec->Y = y; - } -} - -DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledOffset, GetScaledOffset) -{ - PARAM_PROLOGUE; - PARAM_INT(texid); - DVector2 vec; - GetScaledOffset(texid, &vec); - ACTION_RETURN_VEC2(vec); -} - -//========================================================================== -// -// -// -//========================================================================== - -static int CheckRealHeight(int texid) -{ - auto tex = TexMan.ByIndex(texid); - if (tex != nullptr) return tex->CheckRealHeight(); - else return -1; -} - -DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckRealHeight, CheckRealHeight) -{ - PARAM_PROLOGUE; - PARAM_INT(texid); - ACTION_RETURN_INT(CheckRealHeight(texid)); -} - //========================================================================== // // FTextureID::operator+ diff --git a/src/gamedata/textures/texturemanager.h b/src/gamedata/textures/texturemanager.h new file mode 100644 index 000000000..ac47b170b --- /dev/null +++ b/src/gamedata/textures/texturemanager.h @@ -0,0 +1,186 @@ +#pragma once + +#include +#include "tarray.h" +#include "textureid.h" +#include "basics.h" +#include "texmanip.h" +#include "name.h" + +class FxAddSub; +class FTexture; +struct BuildInfo; +int PalCheck(int tex); + +// Texture manager +class FTextureManager +{ + void (*progressFunc)(); + friend class FxAddSub; // needs access to do a bounds check on the texture ID. +public: + FTextureManager (); + ~FTextureManager (); + +private: + int ResolveLocalizedTexture(int texnum); + + FTexture *InternalGetTexture(int texnum, bool animate, bool localize, bool palettesubst) + { + if ((unsigned)texnum >= Textures.Size()) return nullptr; + if (animate) texnum = Translation[texnum]; + if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum); + if (palettesubst) texnum = PalCheck(texnum); + return Textures[texnum].Texture; + } +public: + // This only gets used in UI code so we do not need PALVERS handling. + FTexture *GetTextureByName(const char *name, bool animate = false) + { + FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch); + return InternalGetTexture(texnum.GetIndex(), animate, true, false); + } + + FTexture *GetTexture(FTextureID texnum, bool animate = false) + { + return InternalGetTexture(texnum.GetIndex(), animate, true, false); + } + + // This is the only access function that should be used inside the software renderer. + FTexture *GetPalettedTexture(FTextureID texnum, bool animate) + { + return InternalGetTexture(texnum.GetIndex(), animate, true, true); + } + + FTexture *ByIndex(int i, bool animate = false) + { + return InternalGetTexture(i, animate, true, false); + } + + FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny); + bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum); + + void FlushAll(); + + + enum + { + TEXMAN_TryAny = 1, + TEXMAN_Overridable = 2, + TEXMAN_ReturnFirst = 4, + TEXMAN_AllowSkins = 8, + TEXMAN_ShortNameOnly = 16, + TEXMAN_DontCreate = 32, + TEXMAN_Localize = 64 + }; + + enum + { + HIT_Wall = 1, + HIT_Flat = 2, + HIT_Sky = 4, + HIT_Sprite = 8, + + HIT_Columnmode = HIT_Wall|HIT_Sky|HIT_Sprite + }; + + FTextureID CheckForTexture (const char *name, ETextureType usetype, BITFIELD flags=TEXMAN_TryAny); + FTextureID GetTextureID (const char *name, ETextureType usetype, BITFIELD flags=0); + int ListTextures (const char *name, TArray &list, bool listall = false); + + void AddGroup(int wadnum, int ns, ETextureType usetype); + void AddPatches (int lumpnum); + void AddHiresTextures (int wadnum); + void LoadTextureDefs(int wadnum, const char *lumpname, FMultipatchTextureBuilder &build); + void ParseColorization(FScanner& sc); + void ParseTextureDef(int remapLump, FMultipatchTextureBuilder &build); + void SortTexturesByType(int start, int end); + bool AreTexturesCompatible (FTextureID picnum1, FTextureID picnum2); + void AddLocalizedVariants(); + + FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture + FTextureID AddTexture (FTexture *texture); + FTextureID GetDefaultTexture() const { return DefaultTexture; } + + void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build); + void AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &build); + void Init(void (*progressFunc_)(), void (*checkForHacks)(BuildInfo &)); + void DeleteAll(); + + void ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free); + + int NumTextures () const { return (int)Textures.Size(); } + + int GuesstimateNumTextures (); + + TextureManipulation* GetTextureManipulation(FName name) + { + return tmanips.CheckKey(name); + } + void InsertTextureManipulation(FName cname, TextureManipulation tm) + { + tmanips.Insert(cname, tm); + } + void RemoveTextureManipulation(FName cname) + { + tmanips.Remove(cname); + } + +private: + + // texture counting + int CountTexturesX (); + int CountLumpTextures (int lumpnum); + void AdjustSpriteOffsets(); + + // Build tiles + //int CountBuildTiles (); + +public: + + TArray& GetNewBuildTileData() + { + BuildTileData.Reserve(1); + return BuildTileData.Last(); + } + + FTexture* Texture(FTextureID id) { return Textures[id.GetIndex()].Texture; } + void SetTranslation(FTextureID fromtexnum, FTextureID totexnum); + +private: + + void InitPalettedVersions(); + + // Switches + + struct TextureHash + { + FTexture *Texture; + int HashNext; + bool HasLocalization; + }; + enum { HASH_END = -1, HASH_SIZE = 1027 }; + TArray Textures; + TMap LocalizedTextures; + int HashFirst[HASH_SIZE]; + FTextureID DefaultTexture; + TArray FirstTextureForFile; + TArray > BuildTileData; + TArray Translation; + + TMap tmanips; + +public: + + short sintable[2048]; // for texture warping + enum + { + SINMASK = 2047 + }; + + FTextureID glPart2; + FTextureID glPart; + FTextureID mirrorTexture; + +}; + +extern FTextureManager TexMan; diff --git a/src/gamedata/textures/textures.h b/src/gamedata/textures/textures.h index c99461955..8f4b620ec 100644 --- a/src/gamedata/textures/textures.h +++ b/src/gamedata/textures/textures.h @@ -35,15 +35,19 @@ #ifndef __TEXTURES_H #define __TEXTURES_H -#include "doomtype.h" +#include "basics.h" #include "vectors.h" -#include "v_palette.h" -#include "r_data/v_colortables.h" #include "colormatcher.h" #include "r_data/renderstyle.h" -#include "r_data/r_translate.h" -#include "hwrenderer/textures/hw_texcontainer.h" +#include "textureid.h" #include +#include "hwrenderer/textures/hw_texcontainer.h" + +/* +#include "v_palette.h" +#include "r_data/v_colortables.h" +#include "r_data/r_translate.h" +*/ // 15 because 0th texture is our texture #define MAX_CUSTOM_HW_SHADER_TEXTURES 15 @@ -134,14 +138,6 @@ public: FNullTextureID() : FTextureID(0) {} }; -// -// Animating textures and planes -// -// [RH] Expanded to work with a Hexen ANIMDEFS lump -// - -// All FTextures present their data to the world in 8-bit format, but if -// the source data is something else, this is it. enum FTextureFormat : uint32_t { TEX_Pal, @@ -256,6 +252,8 @@ public: int GetTexelWidth() { return Width; } int GetTexelHeight() { return Height; } + int GetTexelLeftOffset(int adjusted) { return _LeftOffset[adjusted]; } + int GetTexelTopOffset(int adjusted) { return _TopOffset[adjusted]; } bool isValid() const { return UseType != ETextureType::Null; } @@ -310,6 +308,13 @@ public: Scale = BaseTexture->Scale; } + // This is only used for the null texture and for Heretic's skies. + void SetSize(int w, int h) + { + Width = w; + Height = h; + } + // Returns the whole texture, stored in column-major order virtual TArray Get8BitPixels(bool alphatex); @@ -388,13 +393,6 @@ protected: float shaderspeed = 1.f; int shaderindex = 0; - // This is only used for the null texture and for Heretic's skies. - void SetSize(int w, int h) - { - Width = w; - Height = h; - } - int GetScaledWidth () { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); } int GetScaledHeight () { int foo = int((Height * 2) / Scale.Y); return (foo >> 1) + (foo & 1); } double GetScaledWidthDouble () { return Width / Scale.X; } @@ -432,6 +430,14 @@ protected: public: FTextureBuffer CreateTexBuffer(int translation, int flags = 0); bool GetTranslucency(); + FMaterial* GetMaterial(int num) + { + return Material[num]; + } + FTexture* GetPalVersion() + { + return PalVersion; + } private: int CheckDDPK3(); @@ -446,195 +452,17 @@ public: void CheckTrans(unsigned char * buffer, int size, int trans); bool ProcessData(unsigned char * buffer, int w, int h, bool ispatch); int CheckRealHeight(); - void SetSpriteAdjust(); friend class FTextureManager; }; -class FxAddSub; -// Texture manager -class FTextureManager -{ - friend class FxAddSub; // needs access to do a bounds check on the texture ID. -public: - FTextureManager (); - ~FTextureManager (); - -private: - int ResolveLocalizedTexture(int texnum); - int PalCheck(int tex); - - FTexture *InternalGetTexture(int texnum, bool animate, bool localize, bool palettesubst) - { - if ((unsigned)texnum >= Textures.Size()) return nullptr; - if (animate) texnum = Translation[texnum]; - if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum); - if (palettesubst) texnum = PalCheck(texnum); - return Textures[texnum].Texture; - } -public: - // This only gets used in UI code so we do not need PALVERS handling. - FTexture *GetTextureByName(const char *name, bool animate = false) - { - FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch); - return InternalGetTexture(texnum.GetIndex(), animate, true, false); - } - - FTexture *GetTexture(FTextureID texnum, bool animate = false) - { - return InternalGetTexture(texnum.GetIndex(), animate, true, false); - } - - // This is the only access function that should be used inside the software renderer. - FTexture *GetPalettedTexture(FTextureID texnum, bool animate) - { - return InternalGetTexture(texnum.GetIndex(), animate, true, true); - } - - FTexture *ByIndex(int i, bool animate = false) - { - return InternalGetTexture(i, animate, true, false); - } - - FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny); - bool OkForLocalization(FTextureID texnum, const char *substitute); - - void FlushAll(); - - - enum - { - TEXMAN_TryAny = 1, - TEXMAN_Overridable = 2, - TEXMAN_ReturnFirst = 4, - TEXMAN_AllowSkins = 8, - TEXMAN_ShortNameOnly = 16, - TEXMAN_DontCreate = 32, - TEXMAN_Localize = 64 - }; - - enum - { - HIT_Wall = 1, - HIT_Flat = 2, - HIT_Sky = 4, - HIT_Sprite = 8, - - HIT_Columnmode = HIT_Wall|HIT_Sky|HIT_Sprite - }; - - FTextureID CheckForTexture (const char *name, ETextureType usetype, BITFIELD flags=TEXMAN_TryAny); - FTextureID GetTextureID (const char *name, ETextureType usetype, BITFIELD flags=0); - int ListTextures (const char *name, TArray &list, bool listall = false); - - void AddGroup(int wadnum, int ns, ETextureType usetype); - void AddPatches (int lumpnum); - void AddHiresTextures (int wadnum); - void LoadTextureDefs(int wadnum, const char *lumpname, FMultipatchTextureBuilder &build); - void ParseColorization(FScanner& sc); - void ParseTextureDef(int remapLump, FMultipatchTextureBuilder &build); - void SortTexturesByType(int start, int end); - bool AreTexturesCompatible (FTextureID picnum1, FTextureID picnum2); - void AddLocalizedVariants(); - - FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture - FTextureID AddTexture (FTexture *texture); - FTextureID GetDefaultTexture() const { return DefaultTexture; } - - void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build); - void AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &build); - void Init(); - void DeleteAll(); - void SpriteAdjustChanged(); - - void ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free); - - int NumTextures () const { return (int)Textures.Size(); } - - int GuesstimateNumTextures (); - - TextureManipulation* GetTextureManipulation(FName name) - { - return tmanips.CheckKey(name); - } - void InsertTextureManipulation(FName cname, TextureManipulation tm) - { - tmanips.Insert(cname, tm); - } - void RemoveTextureManipulation(FName cname) - { - tmanips.Remove(cname); - } - -private: - - // texture counting - int CountTexturesX (); - int CountLumpTextures (int lumpnum); - void AdjustSpriteOffsets(); - - // Build tiles - //int CountBuildTiles (); - -public: - - TArray& GetNewBuildTileData() - { - BuildTileData.Reserve(1); - return BuildTileData.Last(); - } - - FTexture* Texture(FTextureID id) { return Textures[id.GetIndex()].Texture; } - void SetTranslation(FTextureID fromtexnum, FTextureID totexnum); - -private: - - void InitPalettedVersions(); - - // Switches - - struct TextureHash - { - FTexture *Texture; - int HashNext; - bool HasLocalization; - }; - enum { HASH_END = -1, HASH_SIZE = 1027 }; - TArray Textures; - TMap LocalizedTextures; - int HashFirst[HASH_SIZE]; - FTextureID DefaultTexture; - TArray FirstTextureForFile; - TArray > BuildTileData; - TArray Translation; - - TMap tmanips; - -public: - - short sintable[2048]; // for texture warping - enum - { - SINMASK = 2047 - }; - - FTextureID glLight; - FTextureID glPart2; - FTextureID glPart; - FTextureID mirrorTexture; - -}; - - // A texture that can be drawn to. -class DCanvas; -class AActor; class FCanvasTexture : public FTexture { public: - FCanvasTexture(const char *name, int width, int height) + FCanvasTexture(const char* name, int width, int height) { Name = name; Width = width; @@ -660,6 +488,7 @@ public: friend struct FCanvasTextureInfo; }; + // A wrapper around a hardware texture, to allow using it in the 2D drawing interface. class FWrapperTexture : public FTexture { @@ -694,9 +523,6 @@ public: }; - -extern FTextureManager TexMan; - struct FTexCoordInfo { int mRenderWidth; @@ -715,7 +541,6 @@ struct FTexCoordInfo }; - #endif diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index a053115e5..9dc235b80 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -51,6 +51,7 @@ #include "g_levellocals.h" #include "g_game.h" #include "sbar.h" +#include "texturemanager.h" // MACROS ------------------------------------------------------------------ diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index 5393b9381..76eb457cc 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -52,6 +52,7 @@ #include "utf8.h" #include "templates.h" #include "s_music.h" +#include "texturemanager.h" FIntermissionDescriptorList IntermissionDescriptors; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 98cc79bdc..4a3b66bd6 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -80,6 +80,7 @@ #include "hwrenderer/data/flatvertices.h" #include "xlat/xlat.h" #include "vm.h" +#include "texturemanager.h" enum { diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index 1ba5a2b14..5a059be0b 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -51,6 +51,7 @@ #include "vm.h" #include "xlat/xlat.h" #include "maploader.h" +#include "texturemanager.h" //=========================================================================== // diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 81f737637..a9edc516f 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -55,6 +55,7 @@ #include "i_system.h" #include "c_buttons.h" #include "scripting/types.h" +#include "texturemanager.h" int DMenu::InMenu; static ScaleOverrider *CurrentScaleOverrider; @@ -127,6 +128,8 @@ void D_ToggleHud(); #define KEY_REPEAT_DELAY (TICRATE*5/12) #define KEY_REPEAT_RATE (3) +bool OkForLocalization(FTextureID texnum, const char* substitute); + //============================================================================ // // @@ -442,7 +445,7 @@ void M_SetMenu(FName menu, int param) // This assumes that replacing one graphic will replace all of them. // So this only checks the "New game" entry for localization capability. FTextureID texid = TexMan.CheckForTexture("M_NGAME", ETextureType::MiscPatch); - if (!TexMan.OkForLocalization(texid, "$MNU_NEWGAME")) + if (!OkForLocalization(texid, "$MNU_NEWGAME")) { menu = NAME_MainmenuTextOnly; } diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index f68c73d49..8289fda58 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -51,6 +51,7 @@ #include "teaminfo.h" #include "r_data/sprites.h" #include +#include "texturemanager.h" void ClearSaveGames(); @@ -67,6 +68,37 @@ PClass *DefaultOptionMenuClass; void I_BuildALDeviceList(FOptionValues *opt); void I_BuildALResamplersList(FOptionValues *opt); + +//========================================================================== +// +// Defines how graphics substitution is handled. +// 0: Never replace a text-containing graphic with a font-based text. +// 1: Always replace, regardless of any missing information. Useful for testing the substitution without providing full data. +// 2: Only replace for non-default texts, i.e. if some language redefines the string's content, use it instead of the graphic. Never replace a localized graphic. +// 3: Only replace if the string is not the default and the graphic comes from the IWAD. Never replace a localized graphic. +// 4: Like 1, but lets localized graphics pass. +// +// The default is 3, which only replaces known content with non-default texts. +// +//========================================================================== + +CUSTOM_CVAR(Int, cl_gfxlocalization, 3, CVAR_ARCHIVE) +{ + if (self < 0 || self > 4) self = 0; +} + +bool OkForLocalization(FTextureID texnum, const char* substitute) +{ + if (!texnum.isValid()) return false; + + // First the unconditional settings, 0='never' and 1='always'. + if (cl_gfxlocalization == 1 || gameinfo.forcetextinmenus) return false; + if (cl_gfxlocalization == 0 || gameinfo.forcenogfxsubstitution) return true; + return TexMan.OkForLocalization(texnum, substitute, cl_gfxlocalization); +} + + + DEFINE_GLOBAL_NAMED(OptionSettings, OptionMenuSettings) DEFINE_ACTION_FUNCTION(FOptionValues, GetCount) @@ -1141,7 +1173,7 @@ void M_StartupEpisodeMenu(FGameStartup *gs) if (AllEpisodes[i].mPicName.IsNotEmpty()) { FTextureID tex = GetMenuTexture(AllEpisodes[i].mPicName); - if (AllEpisodes[i].mEpisodeName.IsEmpty() || TexMan.OkForLocalization(tex, AllEpisodes[i].mEpisodeName)) + if (AllEpisodes[i].mEpisodeName.IsEmpty() || OkForLocalization(tex, AllEpisodes[i].mEpisodeName)) continue; // We do not measure patch based entries. They are assumed to fit } const char *c = AllEpisodes[i].mEpisodeName; @@ -1157,7 +1189,7 @@ void M_StartupEpisodeMenu(FGameStartup *gs) if (AllEpisodes[i].mPicName.IsNotEmpty()) { FTextureID tex = GetMenuTexture(AllEpisodes[i].mPicName); - if (AllEpisodes[i].mEpisodeName.IsEmpty() || TexMan.OkForLocalization(tex, AllEpisodes[i].mEpisodeName)) + if (AllEpisodes[i].mEpisodeName.IsEmpty() || OkForLocalization(tex, AllEpisodes[i].mEpisodeName)) it = CreateListMenuItemPatch(posx, posy, ld->mLinespacing, AllEpisodes[i].mShortcut, tex, NAME_Skillmenu, i); } if (it == nullptr) @@ -1753,7 +1785,7 @@ void M_StartupSkillMenu(FGameStartup *gs) if (skill.PicName.Len() != 0 && pItemText == nullptr) { FTextureID tex = GetMenuTexture(skill.PicName); - if (skill.MenuName.IsEmpty() || TexMan.OkForLocalization(tex, skill.MenuName)) + if (skill.MenuName.IsEmpty() || OkForLocalization(tex, skill.MenuName)) continue; } const char *c = pItemText ? pItemText->GetChars() : skill.MenuName.GetChars(); @@ -1782,7 +1814,7 @@ void M_StartupSkillMenu(FGameStartup *gs) if (skill.PicName.Len() != 0 && pItemText == nullptr) { FTextureID tex = GetMenuTexture(skill.PicName); - if (skill.MenuName.IsEmpty() || TexMan.OkForLocalization(tex, skill.MenuName)) + if (skill.MenuName.IsEmpty() || OkForLocalization(tex, skill.MenuName)) li = CreateListMenuItemPatch(posx, y, ld->mLinespacing, skill.Shortcut, tex, action, SkillIndices[i]); } if (li == nullptr) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index c7d511990..97072b882 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -77,6 +77,7 @@ #include "fragglescript/t_script.h" #include "s_music.h" #include "animations.h" +#include "texturemanager.h" extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position); diff --git a/src/playsim/a_decals.cpp b/src/playsim/a_decals.cpp index 8eb4af153..5aded921a 100644 --- a/src/playsim/a_decals.cpp +++ b/src/playsim/a_decals.cpp @@ -44,6 +44,7 @@ #include "doomdata.h" #include "g_levellocals.h" #include "vm.h" +#include "texturemanager.h" EXTERN_CVAR (Bool, cl_spreaddecals) EXTERN_CVAR (Int, cl_maxdecals) diff --git a/src/playsim/fragglescript/t_func.cpp b/src/playsim/fragglescript/t_func.cpp index 6b58177e0..826d51908 100644 --- a/src/playsim/fragglescript/t_func.cpp +++ b/src/playsim/fragglescript/t_func.cpp @@ -52,6 +52,7 @@ #include "vm.h" #include "a_lights.h" #include "s_music.h" +#include "texturemanager.h" static FRandom pr_script("FScript"); diff --git a/src/playsim/fragglescript/t_load.cpp b/src/playsim/fragglescript/t_load.cpp index 96df4dc49..dd7ddd815 100644 --- a/src/playsim/fragglescript/t_load.cpp +++ b/src/playsim/fragglescript/t_load.cpp @@ -35,6 +35,7 @@ #include "xlat/xlat.h" #include "maploader/maploader.h" #include "s_music.h" +#include "texturemanager.h" class FScriptLoader { diff --git a/src/playsim/mapthinkers/a_doors.cpp b/src/playsim/mapthinkers/a_doors.cpp index 8342ff4b4..7994e8820 100644 --- a/src/playsim/mapthinkers/a_doors.cpp +++ b/src/playsim/mapthinkers/a_doors.cpp @@ -39,6 +39,7 @@ #include "p_spec.h" #include "g_levellocals.h" #include "animations.h" +#include "texturemanager.h" //============================================================================ // diff --git a/src/playsim/p_3dmidtex.cpp b/src/playsim/p_3dmidtex.cpp index be5ab9000..bf46a5ed9 100644 --- a/src/playsim/p_3dmidtex.cpp +++ b/src/playsim/p_3dmidtex.cpp @@ -43,6 +43,7 @@ #include "p_spec.h" #include "g_levellocals.h" #include "actor.h" +#include "texturemanager.h" //============================================================================ diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index 771fa7fbe..f8e3b0193 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -76,6 +76,7 @@ #include "scriptutil.h" #include "s_music.h" #include "v_video.h" +#include "texturemanager.h" // P-codes for ACS scripts enum diff --git a/src/playsim/p_sectors.cpp b/src/playsim/p_sectors.cpp index 41bf380d1..d7a1a12bd 100644 --- a/src/playsim/p_sectors.cpp +++ b/src/playsim/p_sectors.cpp @@ -70,6 +70,7 @@ #include "r_sky.h" #include "g_levellocals.h" #include "vm.h" +#include "texturemanager.h" //========================================================================== // diff --git a/src/r_data/colormaps.cpp b/src/r_data/colormaps.cpp index cc2666b30..b46a9b49c 100644 --- a/src/r_data/colormaps.cpp +++ b/src/r_data/colormaps.cpp @@ -43,6 +43,7 @@ #include "r_sky.h" #include "colormaps.h" #include "templates.h" +#include "c_cvars.h" CUSTOM_CVAR(Bool, cl_customizeinvulmap, false, CVAR_ARCHIVE|CVAR_NOINITCALL) { diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 9a4ce48bb..e0f6deff0 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -47,6 +47,7 @@ #include "textures/skyboxtexture.h" #include "hwrenderer/postprocessing/hw_postprocessshader.h" #include "hwrenderer/textures/hw_material.h" +#include "texturemanager.h" void AddLightDefaults(FLightDefaults *defaults, double attnFactor); void AddLightAssociation(const char *actor, const char *frame, const char *light); diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 0b0dabbce..21eaec7ae 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -42,6 +42,7 @@ #include "r_data/models/models_ue1.h" #include "r_data/models/models_obj.h" #include "i_time.h" +#include "texturemanager.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data diff --git a/src/r_data/models/models_md2.cpp b/src/r_data/models/models_md2.cpp index 42a3288f1..a27d079e4 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/r_data/models/models_md2.cpp @@ -28,6 +28,7 @@ #include "filesystem.h" #include "r_data/models/models.h" +#include "texturemanager.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index 23c603a9f..e5e91463a 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -23,6 +23,7 @@ #include "filesystem.h" #include "cmdlib.h" #include "r_data/models/models.h" +#include "texturemanager.h" #define MAX_QPATH 64 diff --git a/src/r_data/models/models_obj.cpp b/src/r_data/models/models_obj.cpp index 5ad5c9e11..0c59b6875 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/r_data/models/models_obj.cpp @@ -21,6 +21,7 @@ #include "filesystem.h" #include "r_data/models/models_obj.h" +#include "texturemanager.h" /** * Load an OBJ model diff --git a/src/r_data/models/models_ue1.cpp b/src/r_data/models/models_ue1.cpp index 007bd0f4a..e32aacdf2 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/r_data/models/models_ue1.cpp @@ -23,6 +23,7 @@ #include "filesystem.h" #include "cmdlib.h" #include "r_data/models/models_ue1.h" +#include "texturemanager.h" float unpackuvert( uint32_t n, int c ) { diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index bc52646b6..fd9cc0a3e 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -33,6 +33,7 @@ #include "g_levellocals.h" #include "models.h" #include "image.h" +#include "texturemanager.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data diff --git a/src/r_data/r_canvastexture.cpp b/src/r_data/r_canvastexture.cpp index 4a159170f..c0d0187bb 100644 --- a/src/r_data/r_canvastexture.cpp +++ b/src/r_data/r_canvastexture.cpp @@ -38,6 +38,7 @@ #include "r_canvastexture.h" #include "g_levellocals.h" #include "serializer.h" +#include "texturemanager.h" //========================================================================== // diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index cca72b8de..7b8caf0b3 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -46,77 +46,6 @@ int R_FindCustomTranslation(FName name); void R_ParseTrnslate(); void StaticSerializeTranslations(FSerializer& arc); -struct TextureManipulation -{ - enum - { - BlendNone = 0, - BlendAlpha = 1, - BlendScreen = 2, - BlendOverlay = 3, - BlendHardLight = 4, - BlendMask = 7, - InvertBit = 8, - ActiveBit = 16, // Must be set for the shader to do something - }; - PalEntry AddColor; // Alpha contains the blend flags - PalEntry ModulateColor; // Alpha may contain a multiplier to get higher values than 1.0 without promoting this to 4 full floats. - PalEntry BlendColor; - float DesaturationFactor; - - bool CheckIfEnabled() // check if this manipulation is doing something. NoOps do not need to be preserved, unless they override older setttings. - { - if (AddColor != 0 || // this includes a check for the blend mode without which BlendColor is not active - ModulateColor != 0x01ffffff || // 1 in alpha must be the default for a no-op. - DesaturationFactor != 0) - { - AddColor.a |= ActiveBit; // mark as active for the shader's benefit. - return true; - } - return false; - } - - void SetTextureModulateColor(int slot, PalEntry rgb) - { - rgb.a = ModulateColor.a; - ModulateColor = rgb; - } - - void SetTextureModulateScaleFactor(int slot, int fac) - { - ModulateColor.a = (uint8_t)fac; - } - - void SetTextureAdditiveColor(int slot, PalEntry rgb) - { - rgb.a = AddColor.a; - AddColor = rgb; - } - - void SetTextureBlendColor(int slot, PalEntry rgb) - { - BlendColor = rgb; - } - - void SetTextureDesaturationFactor(int slot, double fac) - { - DesaturationFactor = (float)fac; - } - - void SetTextureBlendMode(int slot, int mode) - { - AddColor.a = (AddColor.a & ~TextureManipulation::BlendMask) | (mode & TextureManipulation::BlendMask); - } - - void SetTextureInvert(bool on) - { - AddColor.a |= TextureManipulation::InvertBit; - AddColor.a &= ~TextureManipulation::InvertBit; - } - -}; - - #endif // __R_TRANSLATE_H diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index 7bbe733cd..431866051 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -33,6 +33,7 @@ #include "r_data/sprites.h" #include "r_data/voxels.h" #include "vm.h" +#include "texturemanager.h" void InitModels(); diff --git a/src/rendering/2d/v_draw.cpp b/src/rendering/2d/v_draw.cpp index 13589073f..c41b4fa37 100644 --- a/src/rendering/2d/v_draw.cpp +++ b/src/rendering/2d/v_draw.cpp @@ -49,6 +49,7 @@ #include "g_levellocals.h" #include "vm.h" #include "hwrenderer/utility/hw_cvars.h" +#include "texturemanager.h" CVAR(Float, underwater_fade_scalar, 1.0f, CVAR_ARCHIVE) // [Nash] user-settable underwater blend intensity diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 7b66b43b3..d8690fd80 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -59,6 +59,7 @@ #include "r_data/models/models.h" #include "gl/renderer/gl_postprocessstate.h" #include "gl/system/gl_buffers.h" +#include "texturemanager.h" EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Bool, cl_capfps) diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index 38905f7be..9d80fc46c 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -25,6 +25,7 @@ #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" #include "hwrenderer/postprocessing/hw_postprocessshader.h" #include +#include "texturemanager.h" Postprocess hw_postprocess; diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index 54ea30c0a..9c89689b6 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -33,6 +33,7 @@ #include "po_man.h" #include "m_fixed.h" #include "ctpl.h" +#include "texturemanager.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_clipper.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index ec5343cc5..2372a64cd 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -37,6 +37,7 @@ #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" #include "hw_renderstate.h" +#include "texturemanager.h" //========================================================================== // diff --git a/src/rendering/hwrenderer/scene/hw_fakeflat.cpp b/src/rendering/hwrenderer/scene/hw_fakeflat.cpp index b37d8b67f..f1d7d4d9b 100644 --- a/src/rendering/hwrenderer/scene/hw_fakeflat.cpp +++ b/src/rendering/hwrenderer/scene/hw_fakeflat.cpp @@ -35,6 +35,7 @@ #include "hw_drawinfo.h" #include "hwrenderer/utility/hw_cvars.h" #include "r_utility.h" +#include "texturemanager.h" static sector_t **fakesectorbuffer; diff --git a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp index 201b6a907..45f48bf0f 100644 --- a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp @@ -30,6 +30,7 @@ #include "r_sky.h" #include "g_levellocals.h" #include "a_dynlight.h" +#include "texturemanager.h" #include "hw_drawinfo.h" #include "hw_drawstructs.h" diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index 94fb097d4..adc22b38a 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -27,6 +27,7 @@ #include "doomdata.h" #include "g_levellocals.h" #include "p_lnspec.h" +#include "texturemanager.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_portal.h" diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 4d44f29ef..111c299ac 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -41,6 +41,7 @@ #include "matrix.h" #include "r_data/models/models.h" #include "vectors.h" +#include "texturemanager.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index ac456487c..7724106fd 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -30,6 +30,7 @@ #include "doomdata.h" #include "g_levellocals.h" #include "actorinlines.h" +#include "texturemanager.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/textures/hw_material.h" #include "hwrenderer/utility/hw_cvars.h" diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index 8eec8a13a..3cb286741 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -34,6 +34,7 @@ #include "r_data/models/models.h" #include "hw_weapon.h" #include "hw_fakeflat.h" +#include "texturemanager.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" diff --git a/src/rendering/hwrenderer/textures/hw_material.cpp b/src/rendering/hwrenderer/textures/hw_material.cpp index dafb4ba98..5c2dc1269 100644 --- a/src/rendering/hwrenderer/textures/hw_material.cpp +++ b/src/rendering/hwrenderer/textures/hw_material.cpp @@ -29,6 +29,7 @@ #include "v_video.h" #include "hw_ihwtexture.h" #include "hw_material.h" +#include "texturemanager.h" //=========================================================================== // @@ -493,3 +494,54 @@ FMaterial * FMaterial::ValidateTexture(FTextureID no, bool expand, bool translat { return ValidateTexture(TexMan.GetTexture(no, translate), expand, create); } + + +//----------------------------------------------------------------------------- +// +// Make sprite offset adjustment user-configurable per renderer. +// +//----------------------------------------------------------------------------- + +extern int r_spriteadjustSW, r_spriteadjustHW; + +CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + r_spriteadjustHW = !!(self & 2); + r_spriteadjustSW = !!(self & 1); + for (int i = 0; i < TexMan.NumTextures(); i++) + { + auto tex = TexMan.GetTexture(FSetTextureID(i)); + if (tex->GetTexelLeftOffset(0) != tex->GetTexelLeftOffset(1) || tex->GetTexelTopOffset(0) != tex->GetTexelTopOffset(1)) + { + for (int i = 0; i < 2; i++) + { + auto mat = tex->GetMaterial(i); + if (mat != nullptr) mat->SetSpriteRect(); + } + } + + } +} + +//========================================================================== +// +// this must be copied back to textures.cpp later. +// +//========================================================================== + +FWrapperTexture::FWrapperTexture(int w, int h, int bits) +{ + Width = w; + Height = h; + Format = bits; + UseType = ETextureType::SWCanvas; + bNoCompress = true; + auto hwtex = screen->CreateHardwareTexture(); + // todo: Initialize here. + SystemTextures.AddHardwareTexture(0, false, hwtex); +} + +void DeleteMaterial(FMaterial* mat) +{ + delete mat; +} diff --git a/src/rendering/hwrenderer/textures/hw_material.h b/src/rendering/hwrenderer/textures/hw_material.h index 98a0ebffe..7debe882f 100644 --- a/src/rendering/hwrenderer/textures/hw_material.h +++ b/src/rendering/hwrenderer/textures/hw_material.h @@ -7,8 +7,6 @@ #include "r_defs.h" -EXTERN_CVAR(Bool, gl_precache) - struct FRemapTable; class FTextureShader; class IHardwareTexture; diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 73a0d571b..c4a1fe1d3 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -36,7 +36,9 @@ #include "image.h" #include "v_video.h" #include "v_font.h" +#include "texturemanager.h" +EXTERN_CVAR(Bool, gl_precache) //========================================================================== // @@ -238,14 +240,14 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl { if (tex->GetImage() && tex->SystemTextures.GetHardwareTexture(0, false) == nullptr) { - FImageSource::RegisterForPrecache(tex->GetImage()); + FImageSource::RegisterForPrecache(tex->GetImage(), V_IsTrueColor()); } } // Only register untranslated sprites. Translated ones are very unlikely to require data that can be reused. if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CheckKey(0)) { - FImageSource::RegisterForPrecache(tex->GetImage()); + FImageSource::RegisterForPrecache(tex->GetImage(), V_IsTrueColor()); } } } diff --git a/src/rendering/hwrenderer/textures/hw_texcontainer.h b/src/rendering/hwrenderer/textures/hw_texcontainer.h index 1eaa57a51..ad57cfe60 100644 --- a/src/rendering/hwrenderer/textures/hw_texcontainer.h +++ b/src/rendering/hwrenderer/textures/hw_texcontainer.h @@ -2,6 +2,7 @@ #include "tarray.h" #include "hwrenderer/textures/hw_ihwtexture.h" +#include "palettecontainer.h" struct FTextureBuffer; class IHardwareTexture; diff --git a/src/rendering/hwrenderer/utility/hw_cvars.cpp b/src/rendering/hwrenderer/utility/hw_cvars.cpp index 18adec826..7f4eb832f 100644 --- a/src/rendering/hwrenderer/utility/hw_cvars.cpp +++ b/src/rendering/hwrenderer/utility/hw_cvars.cpp @@ -27,6 +27,7 @@ #include "hw_cvars.h" #include "hwrenderer/textures/hw_material.h" #include "menu/menu.h" +#include "texturemanager.h" diff --git a/src/rendering/r_sky.cpp b/src/rendering/r_sky.cpp index 1c34c9c32..b3813e324 100644 --- a/src/rendering/r_sky.cpp +++ b/src/rendering/r_sky.cpp @@ -38,6 +38,7 @@ #include "r_utility.h" #include "v_text.h" #include "g_levellocals.h" +#include "texturemanager.h" // // sky mapping diff --git a/src/rendering/swrenderer/line/r_line.cpp b/src/rendering/swrenderer/line/r_line.cpp index 5bdebea0a..d18c2d9a5 100644 --- a/src/rendering/swrenderer/line/r_line.cpp +++ b/src/rendering/swrenderer/line/r_line.cpp @@ -42,6 +42,7 @@ #include "v_palette.h" #include "r_utility.h" #include "r_data/colormaps.h" +#include "texturemanager.h" #include "swrenderer/r_memory.h" #include "swrenderer/scene/r_opaque_pass.h" #include "swrenderer/scene/r_3dfloors.h" diff --git a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp index 2fac2a8ef..fc5a2cbb0 100644 --- a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp @@ -38,6 +38,7 @@ #include "po_man.h" #include "r_data/colormaps.h" #include "d_net.h" +#include "texturemanager.h" #include "swrenderer/r_memory.h" #include "swrenderer/r_renderthread.h" #include "swrenderer/drawers/r_draw.h" diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 9a05b36d5..13361e397 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -35,6 +35,7 @@ #include "cmdlib.h" #include "d_net.h" #include "g_level.h" +#include "texturemanager.h" #include "swrenderer/scene/r_opaque_pass.h" #include "r_skyplane.h" #include "swrenderer/scene/r_3dfloors.h" diff --git a/src/rendering/swrenderer/plane/r_visibleplane.cpp b/src/rendering/swrenderer/plane/r_visibleplane.cpp index b6237c3ee..00f76a8f3 100644 --- a/src/rendering/swrenderer/plane/r_visibleplane.cpp +++ b/src/rendering/swrenderer/plane/r_visibleplane.cpp @@ -37,6 +37,7 @@ #include "d_net.h" #include "g_level.h" #include "a_dynlight.h" +#include "texturemanager.h" #include "swrenderer/r_memory.h" #include "swrenderer/r_renderthread.h" #include "swrenderer/scene/r_opaque_pass.h" diff --git a/src/rendering/swrenderer/r_swrenderer.cpp b/src/rendering/swrenderer/r_swrenderer.cpp index f0d2830d3..aa56f5947 100644 --- a/src/rendering/swrenderer/r_swrenderer.cpp +++ b/src/rendering/swrenderer/r_swrenderer.cpp @@ -52,6 +52,7 @@ #include "g_levellocals.h" #include "image.h" #include "imagehelpers.h" +#include "texturemanager.h" // [BB] Use ZDoom's freelook limit for the sotfware renderer. // Note: ZDoom's limit is chosen such that the sky is rendered properly. @@ -95,7 +96,7 @@ void FSoftwareRenderer::PreparePrecache(FTexture *ttex, int cache) } else if (cache != 0) { - FImageSource::RegisterForPrecache(ttex->GetImage()); + FImageSource::RegisterForPrecache(ttex->GetImage(), V_IsTrueColor()); } } } diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index 26c596445..3b6e5afc9 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -35,6 +35,7 @@ #include "swrenderer/scene/r_light.h" #include "image.h" #include "engineerrors.h" +#include "texturemanager.h" // [RH] Base blending values (for e.g. underwater) int BaseBlendR, BaseBlendG, BaseBlendB; diff --git a/src/rendering/swrenderer/scene/r_opaque_pass.cpp b/src/rendering/swrenderer/scene/r_opaque_pass.cpp index ad838d807..c8158e8cf 100644 --- a/src/rendering/swrenderer/scene/r_opaque_pass.cpp +++ b/src/rendering/swrenderer/scene/r_opaque_pass.cpp @@ -37,6 +37,7 @@ #include "engineerrors.h" #include "p_lnspec.h" #include "p_setup.h" +#include "texturemanager.h" #include "swrenderer/drawers/r_draw.h" #include "swrenderer/plane/r_visibleplane.h" diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index b5aee3f01..37695fa7d 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -598,3 +598,8 @@ void FSoftwareTexture::FreeAllSpans() } } +void DeleteSoftwareTexture(FSoftwareTexture* swtex) +{ + delete swtex; +} + diff --git a/src/rendering/swrenderer/textures/warpbuffer.h b/src/rendering/swrenderer/textures/warpbuffer.h index 62b0db13d..114b8af00 100644 --- a/src/rendering/swrenderer/textures/warpbuffer.h +++ b/src/rendering/swrenderer/textures/warpbuffer.h @@ -32,7 +32,8 @@ ** */ -#include "textures/textures.h" +#include "textures.h" +#include "texturemanager.h" template void WarpBuffer(TYPE *Pixels, const TYPE *source, int width, int height, int xmul, int ymul, uint64_t time, float Speed, int warptype) diff --git a/src/rendering/swrenderer/things/r_decal.cpp b/src/rendering/swrenderer/things/r_decal.cpp index 997fd2593..7ede9a574 100644 --- a/src/rendering/swrenderer/things/r_decal.cpp +++ b/src/rendering/swrenderer/things/r_decal.cpp @@ -41,6 +41,7 @@ #include "swrenderer/drawers/r_draw.h" #include "v_palette.h" #include "r_data/colormaps.h" +#include "texturemanager.h" #include "swrenderer/line/r_wallsetup.h" #include "swrenderer/line/r_walldraw.h" #include "swrenderer/segments/r_drawsegment.h" diff --git a/src/rendering/swrenderer/things/r_model.cpp b/src/rendering/swrenderer/things/r_model.cpp index 38356f30d..43f52ccfa 100644 --- a/src/rendering/swrenderer/things/r_model.cpp +++ b/src/rendering/swrenderer/things/r_model.cpp @@ -29,6 +29,7 @@ #include "r_data/r_vanillatrans.h" #include "actorinlines.h" #include "i_time.h" +#include "texturemanager.h" #include "swrenderer/r_memory.h" #include "swrenderer/r_swcolormaps.h" #include "swrenderer/viewport/r_viewport.h" diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index 8ce25cba9..74ff3d8d4 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -56,6 +56,7 @@ #include "p_local.h" #include "p_maputl.h" #include "r_voxel.h" +#include "texturemanager.h" #include "swrenderer/segments/r_drawsegment.h" #include "swrenderer/scene/r_portal.h" #include "swrenderer/scene/r_scene.h" diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 774f2a503..86316c724 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -50,6 +50,7 @@ #include "g_levellocals.h" #include "v_video.h" #include "utf8.h" +#include "texturemanager.h" extern FRandom pr_exrandom; FMemArena FxAlloc(65536); diff --git a/src/scripting/backend/codegen.h b/src/scripting/backend/codegen.h index 2ab7f8104..e73d06e66 100644 --- a/src/scripting/backend/codegen.h +++ b/src/scripting/backend/codegen.h @@ -48,6 +48,7 @@ #include "scopebarrier.h" #include "types.h" #include "vmintern.h" +#include "c_cvars.h" #define CHECKRESOLVED() if (isresolved) return this; isresolved=true; diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index e1f693f18..6add94538 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -56,6 +56,7 @@ #include "types.h" #include "a_dynlight.h" #include "v_video.h" +#include "texturemanager.h" //========================================================================== // diff --git a/src/scripting/vm/jit_move.cpp b/src/scripting/vm/jit_move.cpp index b575399c7..767000c7d 100644 --- a/src/scripting/vm/jit_move.cpp +++ b/src/scripting/vm/jit_move.cpp @@ -3,6 +3,7 @@ #include "v_video.h" #include "s_sound.h" #include "r_state.h" +#include "texturemanager.h" void JitCompiler::EmitMOVE() { diff --git a/src/scripting/vm/vmexec.cpp b/src/scripting/vm/vmexec.cpp index 0d0e2125f..2ac0d4e70 100644 --- a/src/scripting/vm/vmexec.cpp +++ b/src/scripting/vm/vmexec.cpp @@ -38,6 +38,7 @@ #include "stats.h" #include "vmintern.h" #include "types.h" +#include "texturemanager.h" extern cycle_t VMCycles[10]; extern int VMCalls[10]; diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index c976f5186..0cc9258c8 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -57,6 +57,7 @@ #include "c_bind.h" #include "c_dispatch.h" #include "s_music.h" +#include "texturemanager.h" DVector2 AM_GetPosition(); int Net_GetLatency(int *ld, int *ad); @@ -1912,6 +1913,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, ReplaceTextures, ReplaceTextures) return 0; } +//===================================================================================== +// +// textures +// +//===================================================================================== + void SetCameraToTexture(AActor *viewpoint, const FString &texturename, double fov); DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, SetCameraToTexture, SetCameraToTexture) @@ -1924,6 +1931,177 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, SetCameraToTexture, SetCameraToTexture) return 0; } +static int CheckForTexture(const FString& name, int type, int flags) +{ + return TexMan.CheckForTexture(name, static_cast(type), flags).GetIndex(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckForTexture, CheckForTexture) +{ + PARAM_PROLOGUE; + PARAM_STRING(name); + PARAM_INT(type); + PARAM_INT(flags); + ACTION_RETURN_INT(CheckForTexture(name, type, flags)); +} + +//========================================================================== +// +// +// +//========================================================================== + +DEFINE_ACTION_FUNCTION(_TexMan, GetName) +{ + PARAM_PROLOGUE; + PARAM_INT(texid); + auto tex = TexMan.ByIndex(texid); + FString retval; + + if (tex != nullptr) + { + if (tex->GetName().IsNotEmpty()) retval = tex->GetName(); + else + { + // Textures for full path names do not have their own name, they merely link to the source lump. + auto lump = tex->GetSourceLump(); + if (fileSystem.GetLinkedTexture(lump) == tex) + retval = fileSystem.GetFileFullName(lump); + } + } + ACTION_RETURN_STRING(retval); +} + +//========================================================================== +// +// +// +//========================================================================== + +static int GetTextureSize(int texid, int* py) +{ + auto tex = TexMan.ByIndex(texid); + int x, y; + if (tex != nullptr) + { + x = tex->GetDisplayWidth(); + y = tex->GetDisplayHeight(); + } + else x = y = -1; + if (py) *py = y; + return x; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetSize, GetTextureSize) +{ + PARAM_PROLOGUE; + PARAM_INT(texid); + int x, y; + x = GetTextureSize(texid, &y); + if (numret > 0) ret[0].SetInt(x); + if (numret > 1) ret[1].SetInt(y); + return MIN(numret, 2); +} + +//========================================================================== +// +// +// +//========================================================================== +static void GetScaledSize(int texid, DVector2* pvec) +{ + auto tex = TexMan.ByIndex(texid); + double x, y; + if (tex != nullptr) + { + x = tex->GetDisplayWidthDouble(); + y = tex->GetDisplayHeightDouble(); + } + else x = y = -1; + if (pvec) + { + pvec->X = x; + pvec->Y = y; + } +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledSize, GetScaledSize) +{ + PARAM_PROLOGUE; + PARAM_INT(texid); + DVector2 vec; + GetScaledSize(texid, &vec); + ACTION_RETURN_VEC2(vec); +} + +//========================================================================== +// +// +// +//========================================================================== +static void GetScaledOffset(int texid, DVector2* pvec) +{ + auto tex = TexMan.ByIndex(texid); + double x, y; + if (tex != nullptr) + { + x = tex->GetDisplayLeftOffsetDouble(); + y = tex->GetDisplayTopOffsetDouble(); + } + else x = y = -1; + if (pvec) + { + pvec->X = x; + pvec->Y = y; + } +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledOffset, GetScaledOffset) +{ + PARAM_PROLOGUE; + PARAM_INT(texid); + DVector2 vec; + GetScaledOffset(texid, &vec); + ACTION_RETURN_VEC2(vec); +} + +//========================================================================== +// +// +// +//========================================================================== + +static int CheckRealHeight(int texid) +{ + auto tex = TexMan.ByIndex(texid); + if (tex != nullptr) return tex->CheckRealHeight(); + else return -1; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckRealHeight, CheckRealHeight) +{ + PARAM_PROLOGUE; + PARAM_INT(texid); + ACTION_RETURN_INT(CheckRealHeight(texid)); +} + +bool OkForLocalization(FTextureID texnum, const char* substitute); + +static int OkForLocalization_(int index, const FString& substitute) +{ + return OkForLocalization(FSetTextureID(index), substitute); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, OkForLocalization, OkForLocalization_) +{ + PARAM_PROLOGUE; + PARAM_INT(name); + PARAM_STRING(subst) + ACTION_RETURN_INT(OkForLocalization_(name, subst)); +} + + + //===================================================================================== // @@ -3447,7 +3625,6 @@ DEFINE_ACTION_FUNCTION(DObject, S_ChangeMusic) } - //========================================================================== // // diff --git a/src/serializer.cpp b/src/serializer.cpp index 4d3e78a77..ed1eb5266 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -60,6 +60,7 @@ #include "cmdlib.h" #include "g_levellocals.h" #include "utf8.h" +#include "texturemanager.h" bool save_full = false; // for testing. Should be removed afterward. diff --git a/src/utility/v_collection.cpp b/src/utility/v_collection.cpp index 51cdd3a75..9bb11a162 100644 --- a/src/utility/v_collection.cpp +++ b/src/utility/v_collection.cpp @@ -36,6 +36,7 @@ #include "v_font.h" #include "v_video.h" #include "filesystem.h" +#include "texturemanager.h" FImageCollection::FImageCollection () { diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 29a7957ba..c05ff22b7 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -54,6 +54,7 @@ #include "cmdlib.h" #include "g_levellocals.h" #include "vm.h" +#include "texturemanager.h" CVAR(Bool, wi_percents, true, CVAR_ARCHIVE) CVAR(Bool, wi_showtotaltime, true, CVAR_ARCHIVE)