Renamed FTexture::GetPixels

This was needed to allow refactoring without letting all the other GetPixels get in the way.
This commit is contained in:
Christoph Oelckers 2018-12-07 03:35:10 +01:00
parent 9409843931
commit 69cc1f831c
9 changed files with 49 additions and 26 deletions

View file

@ -96,7 +96,7 @@ public:
// Returns the whole texture, stored in column-major order // Returns the whole texture, stored in column-major order
virtual const uint8_t *GetPixels(FRenderStyle style) virtual const uint8_t *GetPixels(FRenderStyle style)
{ {
return mTexture->GetPixels(style); return mTexture->Get8BitPixels(style);
} }
void Unload() void Unload()

View file

@ -56,7 +56,7 @@ FCanvasTexture::~FCanvasTexture ()
Unload (); Unload ();
} }
const uint8_t *FCanvasTexture::GetPixels (FRenderStyle style) const uint8_t *FCanvasTexture::Get8BitPixels (FRenderStyle style)
{ {
bNeedsUpdate = true; bNeedsUpdate = true;
if (Canvas == NULL) if (Canvas == NULL)

View file

@ -198,7 +198,7 @@ protected:
uint8_t *MakeTexture (FRenderStyle style); uint8_t *MakeTexture (FRenderStyle style);
// The getters must optionally redirect if it's a simple one-patch texture. // 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: private:
@ -1289,7 +1289,7 @@ void FMultiPatchTexture::ResolvePatches()
CheckForHacks(); CheckForHacks();
// If this texture is just a wrapper around a single patch, we can simply // 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) if (NumParts == 1)
{ {

View file

@ -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); int index = !!(style.Flags & STYLEF_RedIsAlpha);
if (Pixeldata[index] == nullptr) if (Pixeldata[index] == nullptr)

View file

@ -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; return NULL;
} }

View file

@ -18,7 +18,7 @@ public:
FSkyBox(const char *name = nullptr); FSkyBox(const char *name = nullptr);
~FSkyBox(); ~FSkyBox();
//const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out); //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); int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf);
bool UseBasePalette(); bool UseBasePalette();
void Unload (); void Unload ();

View file

@ -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) 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 srcwidth = Width;
int srcheight = Height; int srcheight = Height;
int step_x = 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_Pal:
case TEX_Gray: case TEX_Gray:
pix = GetPixels(fmt == TEX_Pal? DefaultRenderStyle() : LegacyRenderStyles[STYLE_Shaded]); pix = Get8BitPixels(fmt == TEX_Pal? DefaultRenderStyle() : LegacyRenderStyles[STYLE_Shaded]);
stride = pitch - w; stride = pitch - w;
for (y = 0; y < h; ++y) 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(); PalEntry *palette = screen->GetPalette();
for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values 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; for(int i=1;i<256;i++) palette[i].a = 0;
return 0; return 0;
} }
int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf) 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; return 0;
} }
@ -596,7 +596,7 @@ PalEntry FTexture::GetSkyCapColor(bool bottom)
int FTexture::CheckRealHeight() int FTexture::CheckRealHeight()
{ {
auto pixels = GetPixels(DefaultRenderStyle()); auto pixels = Get8BitPixels(DefaultRenderStyle());
for(int h = GetHeight()-1; h>= 0; h--) for(int h = GetHeight()-1; h>= 0; h--)
{ {
@ -683,11 +683,11 @@ void FTexture::CreateDefaultBrightmap()
if (UseBasePalette() && TexMan.HasGlobalBrightmap && if (UseBasePalette() && TexMan.HasGlobalBrightmap &&
UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar && UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar &&
Brightmap == NULL && bWarped == 0 && Brightmap == NULL && bWarped == 0 &&
GetPixels(DefaultRenderStyle()) Get8BitPixels(DefaultRenderStyle())
) )
{ {
// May have one - let's check when we use this texture // 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); const int white = ColorMatcher.Pick(255, 255, 255);
int size = GetWidth() * GetHeight(); 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; return nullptr;
} }
@ -1212,3 +1212,26 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y)
mWidth = tex->GetWidth(); 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<uint64_t, TArray<uint8_t>> pixelCachePaletted; // 8 bit column major for composition and software rendering
TMap<uint64_t, TArray<uint8_t>> pixelCacheRgba; // 32 bit column major for software true color rendering
TMap<uint64_t, TArray<uint8_t>> pixelCacheRaw; // 32 bit row major for composition
TMap<uint64_t, IHardwareTexture *> hwTextureCache; // native system textures.
TMap<uint64_t, ItemCacheInfo> cacheMarker;
void PrecacheLevel();
};

View file

@ -387,7 +387,7 @@ protected:
// Returns the whole texture, stored in column-major order // 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 // Returns true if GetPixelsBgra includes mipmaps
virtual bool Mipmapped() { return true; } virtual bool Mipmapped() { return true; }
@ -746,7 +746,7 @@ protected:
~FWorldTexture(); ~FWorldTexture();
void Unload() override; void Unload() override;
const uint8_t *GetPixels(FRenderStyle style) override; const uint8_t *Get8BitPixels(FRenderStyle style) override;
virtual uint8_t *MakeTexture(FRenderStyle style) = 0; virtual uint8_t *MakeTexture(FRenderStyle style) = 0;
}; };
@ -772,7 +772,7 @@ public:
//const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out); //const uint8_t *GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out);
//const uint32_t *GetPixelsBgra() override; //const uint32_t *GetPixelsBgra() override;
const uint8_t *GetPixels (FRenderStyle style); const uint8_t *Get8BitPixels (FRenderStyle style);
void Unload (); void Unload ();
bool CheckModified (FRenderStyle) /*override*/; bool CheckModified (FRenderStyle) /*override*/;
void NeedUpdate() { bNeedsUpdate=true; } void NeedUpdate() { bNeedsUpdate=true; }

View file

@ -171,7 +171,7 @@ class FFontChar1 : public FTexture
{ {
public: public:
FFontChar1 (FTexture *sourcelump); FFontChar1 (FTexture *sourcelump);
const uint8_t *GetPixels (FRenderStyle style); const uint8_t *Get8BitPixels (FRenderStyle style);
void SetSourceRemap(const uint8_t *sourceremap); void SetSourceRemap(const uint8_t *sourceremap);
void Unload (); void Unload ();
~FFontChar1 (); ~FFontChar1 ();
@ -191,7 +191,7 @@ public:
FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0); FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0);
~FFontChar2 (); ~FFontChar2 ();
const uint8_t *GetPixels (FRenderStyle style); const uint8_t *Get8BitPixels (FRenderStyle style);
void SetSourceRemap(const uint8_t *sourceremap); void SetSourceRemap(const uint8_t *sourceremap);
void Unload (); void Unload ();
@ -530,7 +530,7 @@ void RecordTextureColors (FTexture *pic, uint8_t *usedcolors)
{ {
int x; int x;
auto pixels = pic->GetPixels(DefaultRenderStyle()); auto pixels = pic->Get8BitPixels(DefaultRenderStyle());
auto size = pic->GetWidth() * pic->GetHeight(); auto size = pic->GetWidth() * pic->GetHeight();
for(x = 0;x < size; x++) 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) if (Pixels == NULL)
{ {
@ -1589,7 +1589,7 @@ void FFontChar1::MakeTexture ()
// Make the texture as normal, then remap it so that all the colors // Make the texture as normal, then remap it so that all the colors
// are at the low end of the palette // are at the low end of the palette
Pixels = new uint8_t[Width*Height]; Pixels = new uint8_t[Width*Height];
const uint8_t *pix = BaseTexture->GetPixels(DefaultRenderStyle()); const uint8_t *pix = BaseTexture->Get8BitPixels(DefaultRenderStyle());
if (!SourceRemap) 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. // 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) if (Pixels == NULL)
{ {