Skip to content

Commit

Permalink
Renamed FTexture::GetPixels
Browse files Browse the repository at this point in the history
This was needed to allow refactoring without letting all the other GetPixels get in the way.
  • Loading branch information
coelckers committed Dec 7, 2018
1 parent 9409843 commit 69cc1f8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/swrenderer/textures/r_swtexture.h
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/textures/formats/canvastexture.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/textures/formats/multipatchtexture.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/textures/formats/worldtexture.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/textures/skyboxtexture.cpp
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/textures/skyboxtexture.h
Expand Up @@ -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 ();
Expand Down
39 changes: 31 additions & 8 deletions src/textures/texture.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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--)
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void FTexture::SetSpriteAdjust()
//
//===========================================================================

const uint8_t *FTexture::GetPixels(FRenderStyle style)
const uint8_t *FTexture::Get8BitPixels(FRenderStyle style)
{
return nullptr;
}
Expand Down Expand Up @@ -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<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();
};

6 changes: 3 additions & 3 deletions src/textures/textures.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
};

Expand All @@ -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; }
Expand Down
14 changes: 7 additions & 7 deletions src/v_font.cpp
Expand Up @@ -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 ();
Expand All @@ -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 ();

Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -1569,7 +1569,7 @@ FFontChar1::FFontChar1 (FTexture *sourcelump)
//
//==========================================================================

const uint8_t *FFontChar1::GetPixels (FRenderStyle)
const uint8_t *FFontChar1::Get8BitPixels (FRenderStyle)
{
if (Pixels == NULL)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 69cc1f8

Please sign in to comment.