From 69cc1f831c7cc9f5988b2974fddf9fb106de8747 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 7 Dec 2018 03:35:10 +0100 Subject: [PATCH] Renamed FTexture::GetPixels This was needed to allow refactoring without letting all the other GetPixels get in the way. --- src/swrenderer/textures/r_swtexture.h | 2 +- src/textures/formats/canvastexture.cpp | 2 +- src/textures/formats/multipatchtexture.cpp | 4 +-- src/textures/formats/worldtexture.cpp | 2 +- src/textures/skyboxtexture.cpp | 4 +-- src/textures/skyboxtexture.h | 2 +- src/textures/texture.cpp | 39 +++++++++++++++++----- src/textures/textures.h | 6 ++-- src/v_font.cpp | 14 ++++---- 9 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/swrenderer/textures/r_swtexture.h b/src/swrenderer/textures/r_swtexture.h index 8c3e5a2f1c7..273a748db4b 100644 --- a/src/swrenderer/textures/r_swtexture.h +++ b/src/swrenderer/textures/r_swtexture.h @@ -96,7 +96,7 @@ class FSoftwareTexture // Returns the whole texture, stored in column-major order virtual const uint8_t *GetPixels(FRenderStyle style) { - return mTexture->GetPixels(style); + return mTexture->Get8BitPixels(style); } void Unload() diff --git a/src/textures/formats/canvastexture.cpp b/src/textures/formats/canvastexture.cpp index eb398270288..683e9f9d6cc 100644 --- a/src/textures/formats/canvastexture.cpp +++ b/src/textures/formats/canvastexture.cpp @@ -56,7 +56,7 @@ FCanvasTexture::~FCanvasTexture () Unload (); } -const uint8_t *FCanvasTexture::GetPixels (FRenderStyle style) +const uint8_t *FCanvasTexture::Get8BitPixels (FRenderStyle style) { bNeedsUpdate = true; if (Canvas == NULL) diff --git a/src/textures/formats/multipatchtexture.cpp b/src/textures/formats/multipatchtexture.cpp index e89c66ddefe..226f85de96a 100644 --- a/src/textures/formats/multipatchtexture.cpp +++ b/src/textures/formats/multipatchtexture.cpp @@ -198,7 +198,7 @@ class FMultiPatchTexture : public FWorldTexture uint8_t *MakeTexture (FRenderStyle style); // The getters must optionally redirect if it's a simple one-patch texture. - const uint8_t *GetPixels(FRenderStyle style) override { return bRedirect ? Parts->Texture->GetPixels(style) : FWorldTexture::GetPixels(style); } + const uint8_t *Get8BitPixels(FRenderStyle style) override { return bRedirect ? Parts->Texture->Get8BitPixels(style) : FWorldTexture::Get8BitPixels(style); } private: @@ -1289,7 +1289,7 @@ void FMultiPatchTexture::ResolvePatches() CheckForHacks(); // If this texture is just a wrapper around a single patch, we can simply - // forward GetPixels() and GetColumn() calls to that patch. + // forward getter calls to that patch. if (NumParts == 1) { diff --git a/src/textures/formats/worldtexture.cpp b/src/textures/formats/worldtexture.cpp index 6613265fda4..edba839c61f 100644 --- a/src/textures/formats/worldtexture.cpp +++ b/src/textures/formats/worldtexture.cpp @@ -83,7 +83,7 @@ void FWorldTexture::Unload () // //========================================================================== -const uint8_t *FWorldTexture::GetPixels (FRenderStyle style) +const uint8_t *FWorldTexture::Get8BitPixels (FRenderStyle style) { int index = !!(style.Flags & STYLEF_RedIsAlpha); if (Pixeldata[index] == nullptr) diff --git a/src/textures/skyboxtexture.cpp b/src/textures/skyboxtexture.cpp index 9cc1baa4b95..a1f22d9f4ff 100644 --- a/src/textures/skyboxtexture.cpp +++ b/src/textures/skyboxtexture.cpp @@ -59,9 +59,9 @@ FSkyBox::~FSkyBox() // //----------------------------------------------------------------------------- -const uint8_t *FSkyBox::GetPixels (FRenderStyle style) +const uint8_t *FSkyBox::Get8BitPixels (FRenderStyle style) { - if (faces[0]) return faces[0]->GetPixels(style); + if (faces[0]) return faces[0]->Get8BitPixels(style); return NULL; } diff --git a/src/textures/skyboxtexture.h b/src/textures/skyboxtexture.h index b796d428195..08dfdd653f3 100644 --- a/src/textures/skyboxtexture.h +++ b/src/textures/skyboxtexture.h @@ -18,7 +18,7 @@ class FSkyBox : public FTexture FSkyBox(const char *name = nullptr); ~FSkyBox(); //const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out); - const uint8_t *GetPixels (FRenderStyle style); + const uint8_t *Get8BitPixels (FRenderStyle style); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf); bool UseBasePalette(); void Unload (); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index ed3eedb282a..61cc9ab44f5 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -256,7 +256,7 @@ void FTexture::SetFrontSkyLayer () void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation, FRenderStyle style) { - const uint8_t *pixels = GetPixels(style); + const uint8_t *pixels = Get8BitPixels(style); int srcwidth = Width; int srcheight = Height; int step_x = Height; @@ -435,7 +435,7 @@ void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat f { case TEX_Pal: case TEX_Gray: - pix = GetPixels(fmt == TEX_Pal? DefaultRenderStyle() : LegacyRenderStyles[STYLE_Shaded]); + pix = Get8BitPixels(fmt == TEX_Pal? DefaultRenderStyle() : LegacyRenderStyles[STYLE_Shaded]); stride = pitch - w; for (y = 0; y < h; ++y) { @@ -479,14 +479,14 @@ int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyI { PalEntry *palette = screen->GetPalette(); for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values - bmp->CopyPixelData(x, y, GetPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, palette, inf); + bmp->CopyPixelData(x, y, Get8BitPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, palette, inf); for(int i=1;i<256;i++) palette[i].a = 0; return 0; } int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf) { - bmp->CopyPixelData(x, y, GetPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, remap, inf); + bmp->CopyPixelData(x, y, Get8BitPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, remap, inf); return 0; } @@ -596,7 +596,7 @@ PalEntry FTexture::GetSkyCapColor(bool bottom) int FTexture::CheckRealHeight() { - auto pixels = GetPixels(DefaultRenderStyle()); + auto pixels = Get8BitPixels(DefaultRenderStyle()); for(int h = GetHeight()-1; h>= 0; h--) { @@ -683,11 +683,11 @@ void FTexture::CreateDefaultBrightmap() if (UseBasePalette() && TexMan.HasGlobalBrightmap && UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar && Brightmap == NULL && bWarped == 0 && - GetPixels(DefaultRenderStyle()) + Get8BitPixels(DefaultRenderStyle()) ) { // May have one - let's check when we use this texture - const uint8_t *texbuf = GetPixels(DefaultRenderStyle()); + const uint8_t *texbuf = Get8BitPixels(DefaultRenderStyle()); const int white = ColorMatcher.Pick(255, 255, 255); int size = GetWidth() * GetHeight(); @@ -1054,7 +1054,7 @@ void FTexture::SetSpriteAdjust() // //=========================================================================== -const uint8_t *FTexture::GetPixels(FRenderStyle style) +const uint8_t *FTexture::Get8BitPixels(FRenderStyle style) { return nullptr; } @@ -1212,3 +1212,26 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y) mWidth = tex->GetWidth(); } +///////////// + + +class TextureCache +{ + struct ItemCacheInfo + { + int palettedCount; // counts use of final paletted textures + int palettedCountCompose; // counts use of images needed for composition (can be freed after precaching) + int rgbaCount; // counts use of final true color software textures + int rawCount; // counts use of raw images needed for composition (can be freed after precaching) + int textureCount; // counts use of hardware textures + }; + TMap> pixelCachePaletted; // 8 bit column major for composition and software rendering + TMap> pixelCacheRgba; // 32 bit column major for software true color rendering + TMap> pixelCacheRaw; // 32 bit row major for composition + TMap hwTextureCache; // native system textures. + + TMap cacheMarker; + + void PrecacheLevel(); +}; + diff --git a/src/textures/textures.h b/src/textures/textures.h index a7b80e58f5a..ec0df68ee7c 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -387,7 +387,7 @@ class FTexture // Returns the whole texture, stored in column-major order - virtual const uint8_t *GetPixels(FRenderStyle style); + virtual const uint8_t *Get8BitPixels(FRenderStyle style); // Returns true if GetPixelsBgra includes mipmaps virtual bool Mipmapped() { return true; } @@ -746,7 +746,7 @@ class FWorldTexture : public FTexture ~FWorldTexture(); void Unload() override; - const uint8_t *GetPixels(FRenderStyle style) override; + const uint8_t *Get8BitPixels(FRenderStyle style) override; virtual uint8_t *MakeTexture(FRenderStyle style) = 0; }; @@ -772,7 +772,7 @@ class FCanvasTexture : public FTexture //const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out); //const uint32_t *GetPixelsBgra() override; - const uint8_t *GetPixels (FRenderStyle style); + const uint8_t *Get8BitPixels (FRenderStyle style); void Unload (); bool CheckModified (FRenderStyle) /*override*/; void NeedUpdate() { bNeedsUpdate=true; } diff --git a/src/v_font.cpp b/src/v_font.cpp index 276b7cb629e..c2d56717cbd 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -171,7 +171,7 @@ class FFontChar1 : public FTexture { public: FFontChar1 (FTexture *sourcelump); - const uint8_t *GetPixels (FRenderStyle style); + const uint8_t *Get8BitPixels (FRenderStyle style); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); ~FFontChar1 (); @@ -191,7 +191,7 @@ class FFontChar2 : public FTexture FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0); ~FFontChar2 (); - const uint8_t *GetPixels (FRenderStyle style); + const uint8_t *Get8BitPixels (FRenderStyle style); void SetSourceRemap(const uint8_t *sourceremap); void Unload (); @@ -530,7 +530,7 @@ void RecordTextureColors (FTexture *pic, uint8_t *usedcolors) { int x; - auto pixels = pic->GetPixels(DefaultRenderStyle()); + auto pixels = pic->Get8BitPixels(DefaultRenderStyle()); auto size = pic->GetWidth() * pic->GetHeight(); for(x = 0;x < size; x++) @@ -1569,7 +1569,7 @@ FFontChar1::FFontChar1 (FTexture *sourcelump) // //========================================================================== -const uint8_t *FFontChar1::GetPixels (FRenderStyle) +const uint8_t *FFontChar1::Get8BitPixels (FRenderStyle) { if (Pixels == NULL) { @@ -1589,7 +1589,7 @@ void FFontChar1::MakeTexture () // Make the texture as normal, then remap it so that all the colors // are at the low end of the palette Pixels = new uint8_t[Width*Height]; - const uint8_t *pix = BaseTexture->GetPixels(DefaultRenderStyle()); + const uint8_t *pix = BaseTexture->Get8BitPixels(DefaultRenderStyle()); if (!SourceRemap) { @@ -1690,13 +1690,13 @@ void FFontChar2::Unload () //========================================================================== // -// FFontChar2 :: GetPixels +// FFontChar2 :: Get8BitPixels // // Like for FontChar1, the render style has no relevance here as well. // //========================================================================== -const uint8_t *FFontChar2::GetPixels (FRenderStyle) +const uint8_t *FFontChar2::Get8BitPixels (FRenderStyle) { if (Pixels == NULL) {