- moved the bit size variables to FSoftwareTexture

They are only needed by the software rasterizer.
This commit is contained in:
Christoph Oelckers 2018-12-07 02:13:11 +01:00
parent 18c1a3abe5
commit bde3558dc2
22 changed files with 61 additions and 129 deletions

View file

@ -160,7 +160,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded)
mShaderIndex = SHADER_Default;
sourcetex = tex = tx;
if (tx->UseType == ETextureType::SWCanvas && tx->WidthBits == 0)
if (tx->UseType == ETextureType::SWCanvas && static_cast<FWrapperTexture*>(tx)->GetColorFormat() == 0)
{
mShaderIndex = SHADER_Paletted;
}

View file

@ -70,9 +70,6 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox)
SourceVox = vox;
Width = 16;
Height = 16;
WidthBits = 4;
HeightBits = 4;
WidthMask = 15;
bNoCompress = true;
}

View file

@ -41,6 +41,40 @@
//==========================================================================
//
//
//
//==========================================================================
void FSoftwareTexture::CalcBitSize ()
{
// WidthBits is rounded down, and HeightBits is rounded up
int i;
for (i = 0; (1 << i) < GetWidth(); ++i)
{ }
WidthBits = i;
// Having WidthBits that would allow for columns past the end of the
// texture is not allowed, even if it means the entire texture is
// not drawn.
if (GetWidth() < (1 << WidthBits))
{
WidthBits--;
}
WidthMask = (1 << WidthBits) - 1;
// <hr>The minimum height is 2, because we cannot shift right 32 bits.</hr>
// Scratch that. Somebody actually made a 1x1 texture, so now we have to handle it.
for (i = 0; (1 << i) < GetHeight(); ++i)
{ }
HeightBits = i;
}
//==========================================================================
//
//
@ -61,7 +95,7 @@ const uint32_t *FSoftwareTexture::GetColumnBgra(unsigned int column, const FSoft
const uint32_t *FSoftwareTexture::GetPixelsBgra()
{
if (PixelsBgra.empty() || CheckModified(DefaultRenderStyle()))
if (PixelsBgra.Size() == 0 || CheckModified(DefaultRenderStyle()))
{
if (!GetColumn(DefaultRenderStyle(), 0, nullptr))
return nullptr;
@ -71,7 +105,7 @@ const uint32_t *FSoftwareTexture::GetPixelsBgra()
mTexture->CopyTrueColorPixels(&bitmap, 0, 0);
GenerateBgraFromBitmap(bitmap);
}
return PixelsBgra.data();
return PixelsBgra.Data();
}
//==========================================================================
@ -191,7 +225,7 @@ void FSoftwareTexture::GenerateBgraFromBitmap(const FBitmap &bitmap)
// Transpose
const uint32_t *src = (const uint32_t *)bitmap.GetPixels();
uint32_t *dest = PixelsBgra.data();
uint32_t *dest = PixelsBgra.Data();
for (int x = 0; x < GetWidth(); x++)
{
for (int y = 0; y < GetHeight(); y++)
@ -213,7 +247,7 @@ void FSoftwareTexture::CreatePixelsBgraWithMipmaps()
int h = MAX(GetHeight() >> i, 1);
buffersize += w * h;
}
PixelsBgra.resize(buffersize, 0xffff0000);
PixelsBgra.Resize(buffersize);
}
int FSoftwareTexture::MipmapLevels()
@ -249,7 +283,7 @@ void FSoftwareTexture::GenerateBgraMipmaps()
};
int levels = MipmapLevels();
std::vector<Color4f> image(PixelsBgra.size());
std::vector<Color4f> image(PixelsBgra.Size());
// Convert to normalized linear colorspace
{
@ -335,7 +369,7 @@ void FSoftwareTexture::GenerateBgraMipmaps()
// Convert to bgra8 sRGB colorspace
{
Color4f *src = image.data() + GetWidth() * GetHeight();
uint32_t *dest = PixelsBgra.data() + GetWidth() * GetHeight();
uint32_t *dest = PixelsBgra.Data() + GetWidth() * GetHeight();
for (int i = 1; i < levels; i++)
{
int w = MAX(GetWidth() >> i, 1);
@ -362,7 +396,7 @@ void FSoftwareTexture::GenerateBgraMipmaps()
void FSoftwareTexture::GenerateBgraMipmapsFast()
{
uint32_t *src = PixelsBgra.data();
uint32_t *src = PixelsBgra.Data();
uint32_t *dest = src + GetWidth() * GetHeight();
int levels = MipmapLevels();
for (int i = 1; i < levels; i++)
@ -413,9 +447,9 @@ const uint8_t *FSoftwareTexture::GetColumn(FRenderStyle style, unsigned int colu
auto Pixeldata = GetPixels(style);
if ((unsigned)column >= (unsigned)GetWidth())
{
if (mTexture->WidthMask + 1 == GetWidth())
if (WidthMask + 1 == GetWidth())
{
column &= mTexture->WidthMask;
column &= WidthMask;
}
else
{

View file

@ -15,9 +15,11 @@ class FSoftwareTexture
protected:
FTexture *mTexture;
FTexture *mSource;
uint8_t *Pixels[2];
std::vector<uint32_t> PixelsBgra;
TArray<uint32_t> PixelsBgra;
FSoftwareTextureSpan **Spandata[2] = { nullptr, nullptr };
uint8_t WidthBits = 0, HeightBits = 0;
uint16_t WidthMask = 0;
public:
@ -25,6 +27,7 @@ public:
{
mTexture = tex;
mSource = tex;
CalcBitSize();
}
virtual ~FSoftwareTexture()
@ -48,14 +51,15 @@ public:
return mTexture->bMasked;
}
void CalcBitSize();
bool UseBasePalette() const { return mTexture->UseBasePalette(); }
int GetSkyOffset() const { return mTexture->GetSkyOffset(); }
PalEntry GetSkyCapColor(bool bottom) const { return mTexture->GetSkyCapColor(bottom); }
int GetWidth () { return mTexture->GetWidth(); }
int GetHeight () { return mTexture->GetHeight(); }
int GetWidthBits() { return mTexture->WidthBits; }
int GetHeightBits() { return mTexture->HeightBits; }
int GetWidthBits() { return WidthBits; }
int GetHeightBits() { return HeightBits; }
bool Mipmapped() { return mTexture->Mipmapped(); }
int GetScaledWidth () { return mTexture->GetScaledWidth(); }
@ -98,7 +102,7 @@ public:
void Unload()
{
mTexture->Unload();
PixelsBgra = std::vector<uint32_t>();
PixelsBgra.Reset();
}
// Returns true if the next call to GetPixels() will return an image different from the

View file

@ -80,7 +80,6 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
{
Width = 320;
Height = uint16_t(Wads.LumpLength(lumpnum) / 320);
CalcBitSize ();
}
//==========================================================================

View file

@ -81,7 +81,6 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8
Height = height;
_LeftOffset[1] = _LeftOffset[0] = left;
_TopOffset[1] = _TopOffset[0] = top;
CalcBitSize ();
Name.Format("%sBTIL%04d", pathprefix.GetChars(), tilenum);
UseType = ETextureType::Override;
}

View file

@ -41,15 +41,8 @@ FCanvasTexture::FCanvasTexture (const char *name, int width, int height)
Name = name;
Width = width;
Height = height;
CalcBitSize ();
bMasked = false;
/*
DummySpans[0].TopOffset = 0;
DummySpans[0].Length = height;
DummySpans[1].TopOffset = 0;
DummySpans[1].Length = 0;
*/
UseType = ETextureType::Wall;
bNeedsUpdate = true;
bDidUpdate = false;
@ -63,33 +56,6 @@ FCanvasTexture::~FCanvasTexture ()
Unload ();
}
#if 0
const uint8_t *FCanvasTexture::GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out)
{
bNeedsUpdate = true;
if (Canvas == NULL)
{
MakeTexture (style);
}
if ((unsigned)column >= (unsigned)Width)
{
if (WidthMask + 1 == Width)
{
column &= WidthMask;
}
else
{
column %= Width;
}
}
if (spans_out != NULL)
{
*spans_out = DummySpans;
}
return Pixels + column*Height;
}
#endif
const uint8_t *FCanvasTexture::GetPixels (FRenderStyle style)
{
bNeedsUpdate = true;

View file

@ -292,7 +292,6 @@ FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc)
Width = uint16_t(surf->Width);
Height = uint16_t(surf->Height);
CalcBitSize ();
if (surf->PixelFormat.Flags & DDPF_FOURCC)
{

View file

@ -81,9 +81,7 @@ FEmptyTexture::FEmptyTexture (int lumpnum)
: FWorldTexture(NULL, lumpnum)
{
bMasked = true;
WidthBits = HeightBits = 1;
Width = Height = 1;
WidthMask = 0;
PixelsAreStatic = 3;
}

View file

@ -92,9 +92,7 @@ FFlatTexture::FFlatTexture (int lumpnum)
bMasked = false;
bTranslucent = false;
WidthBits = HeightBits = bits;
Width = Height = 1 << bits;
WidthMask = (1 << bits) - 1;
}
//==========================================================================

View file

@ -113,7 +113,6 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
_LeftOffset[1] = _LeftOffset[0] = l;
_TopOffset[1] = _TopOffset[0] = t;
isalpha = _isalpha;
CalcBitSize ();
}
//==========================================================================
@ -132,7 +131,6 @@ uint8_t *FIMGZTexture::MakeTexture (FRenderStyle style)
int dest_adv = Height;
int dest_rew = Width * Height - 1;
CalcBitSize ();
auto Pixels = new uint8_t[Width*Height];
dest_p = Pixels;

View file

@ -253,7 +253,6 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height)
Width = width;
Height = height;
CalcBitSize ();
}
//==========================================================================

View file

@ -254,7 +254,6 @@ FMultiPatchTexture::FMultiPatchTexture (const void *texdef, FPatchLookup *patchl
Width = SAFESHORT(mtexture.d->width);
Height = SAFESHORT(mtexture.d->height);
Name = (char *)mtexture.d->name;
CalcBitSize ();
Scale.X = mtexture.d->ScaleX ? mtexture.d->ScaleX / 8. : 1.;
Scale.Y = mtexture.d->ScaleY ? mtexture.d->ScaleY / 8. : 1.;
@ -400,9 +399,7 @@ uint8_t *GetBlendMap(PalEntry blend, uint8_t *blendwork)
uint8_t *FMultiPatchTexture::MakeTexture (FRenderStyle style)
{
// Add a little extra space at the end if the texture's height is not
// a power of 2, in case somebody accidentally makes it repeat vertically.
int numpix = Width * Height + (1 << HeightBits) - Height;
int numpix = Width * Height;
uint8_t blendwork[256];
bool buildrgb = bComplex;
@ -620,7 +617,6 @@ void FMultiPatchTexture::CheckForHacks ()
Height == 128)
{
Height = 200;
HeightBits = 8;
return;
}
@ -1220,8 +1216,6 @@ FMultiPatchTexture::FMultiPatchTexture (FScanner &sc, ETextureType usetype)
Printf("Texture %s has invalid dimensions (%d, %d)\n", Name.GetChars(), Width, Height);
Width = Height = 1;
}
CalcBitSize ();
sc.SetCMode(false);
}

View file

@ -159,7 +159,6 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header, bool isalphatex)
_LeftOffset[1] = _LeftOffset[0] = header->leftoffset;
_TopOffset[1] = _TopOffset[0] = header->topoffset;
DetectBadPatches();
CalcBitSize ();
}
//==========================================================================
@ -208,9 +207,7 @@ uint8_t *FPatchTexture::MakeTexture (FRenderStyle style)
return Pixels;
}
// Add a little extra space at the end if the texture's height is not
// a power of 2, in case somebody accidentally makes it repeat vertically.
int numpix = Width * Height + (1 << HeightBits) - Height;
int numpix = Width * Height;
numspans = Width;

View file

@ -148,7 +148,6 @@ FPCXTexture::FPCXTexture(int lumpnum, PCXHeader & hdr)
bMasked = false;
Width = LittleShort(hdr.xmax) - LittleShort(hdr.xmin) + 1;
Height = LittleShort(hdr.ymax) - LittleShort(hdr.ymin) + 1;
CalcBitSize();
}
//==========================================================================

View file

@ -209,7 +209,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename
Width = width;
Height = height;
CalcBitSize ();
memset(trans, 255, 256);

View file

@ -159,9 +159,6 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
{
Width = 320;
Height = 200;
WidthBits = 8;
HeightBits = 8;
WidthMask = 255;
// Special case hack for Heretic's E2 end pic. This is not going to be exposed as an editing feature because the implications would be horrible.
if (Name.CompareNoCase("E2END") == 0 && gameinfo.gametype == GAME_Heretic)

View file

@ -51,7 +51,6 @@ public:
Name.Format("BarShader%c%c", vertical ? 'v' : 'h', reverse ? 'r' : 'f');
Width = vertical ? 2 : 256;
Height = vertical ? 256 : 2;
CalcBitSize();
bMasked = false;
bTranslucent = false;
PixelsAreStatic = 2; // The alpha buffer is static, but if this gets used as a regular texture, a separate buffer needs to be made.

View file

@ -136,7 +136,6 @@ FTGATexture::FTGATexture (int lumpnum, TGAHeader * hdr)
Height = hdr->height;
// Alpha channel is used only for 32 bit RGBA and paletted images with RGBA palettes.
bMasked = (hdr->img_desc&15)==8 && (hdr->bpp==32 || (hdr->img_type==1 && hdr->cm_size==32));
CalcBitSize();
}
//==========================================================================

View file

@ -177,10 +177,10 @@ FTexture * FTexture::CreateTexture (const char *name, int lumpnum, ETextureType
FTexture::FTexture (const char *name, int lumpnum)
:
WidthBits(0), HeightBits(0), Scale(1,1), SourceLump(lumpnum),
Scale(1,1), SourceLump(lumpnum),
UseType(ETextureType::Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false),
bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bKeepAround(false), bFullNameTexture(false),
Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0), WidthMask(0)
Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0)
{
bBrightmapChecked = false;
bGlowing = false;
@ -254,39 +254,6 @@ void FTexture::SetFrontSkyLayer ()
//
//==========================================================================
void FTexture::CalcBitSize ()
{
// WidthBits is rounded down, and HeightBits is rounded up
int i;
for (i = 0; (1 << i) < Width; ++i)
{ }
WidthBits = i;
// Having WidthBits that would allow for columns past the end of the
// texture is not allowed, even if it means the entire texture is
// not drawn.
if (Width < (1 << WidthBits))
{
WidthBits--;
}
WidthMask = (1 << WidthBits) - 1;
// <hr>The minimum height is 2, because we cannot shift right 32 bits.</hr>
// Scratch that. Somebody actually made a 1x1 texture, so now we have to handle it.
for (i = 0; (1 << i) < Height; ++i)
{ }
HeightBits = i;
}
//==========================================================================
//
//
//
//==========================================================================
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);
@ -1102,9 +1069,6 @@ FDummyTexture::FDummyTexture ()
{
Width = 64;
Height = 64;
HeightBits = 6;
WidthBits = 6;
WidthMask = 63;
UseType = ETextureType::Null;
}
@ -1112,7 +1076,6 @@ void FDummyTexture::SetSize (int width, int height)
{
Width = width;
Height = height;
CalcBitSize ();
}
@ -1126,7 +1089,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
{
Width = w;
Height = h;
WidthBits = bits;
Format = bits;
UseType = ETextureType::SWCanvas;
bNoCompress = true;
SystemTexture[0] = screen->CreateHardwareTexture(this);

View file

@ -315,8 +315,6 @@ public:
protected:
//int16_t LeftOffset, TopOffset;
uint8_t WidthBits, HeightBits;
DVector2 Scale;
int SourceLump;
@ -455,16 +453,13 @@ protected:
_TopOffset[1] = BaseTexture->_TopOffset[1];
_LeftOffset[0] = BaseTexture->_LeftOffset[0];
_LeftOffset[1] = BaseTexture->_LeftOffset[1];
WidthBits = BaseTexture->WidthBits;
HeightBits = BaseTexture->HeightBits;
Scale = BaseTexture->Scale;
WidthMask = (1 << WidthBits) - 1;
}
void SetScaledSize(int fitwidth, int fitheight);
protected:
uint16_t Width, Height, WidthMask;
uint16_t Width, Height;
int16_t _LeftOffset[2], _TopOffset[2];
static uint8_t GrayMap[256];
uint8_t *GetRemap(FRenderStyle style, bool srcisgrayscale = false)
@ -516,7 +511,6 @@ protected:
FTexture (const char *name = NULL, int lumpnum = -1);
void CalcBitSize ();
void CopyInfo(FTexture *other)
{
CopySize(other);
@ -813,6 +807,7 @@ public:
// A wrapper around a hardware texture, to allow using it in the 2D drawing interface.
class FWrapperTexture : public FTexture
{
int Format;
public:
FWrapperTexture(int w, int h, int bits = 1);
IHardwareTexture *GetSystemTexture(int slot)
@ -822,7 +817,7 @@ public:
int GetColorFormat() const
{
return WidthBits;
return Format;
}
};

View file

@ -1659,7 +1659,6 @@ FFontChar2::FFontChar2 (int sourcelump, int sourcepos, int width, int height, in
Height = height;
_LeftOffset[1] = _LeftOffset[0] = leftofs;
_TopOffset[1] = _TopOffset[0] = topofs;
CalcBitSize ();
}
//==========================================================================