- split out the span generation from most texture classes

Until now each subclass of FTexture had to implement the entire span generation itself, presumably so that a few classes can use simpler structures.
This does not work if a texture can have more than one pixel buffer as is needed for alpha textures.
Even though it means that some classes will allocate more data now, it's the only way to do it properly.
In addition this removes a significant amount of mostly redundant code from the texture classes.

- added alpha texture processing to all converted classes

As of now this is not active and not tested.
Note that as part of the conversion even those textures that were working as alphatextures will not look correct until the higher level code gets adjusted.
This commit is contained in:
Christoph Oelckers 2018-03-18 12:36:14 +01:00
commit 7e169eb76f
21 changed files with 484 additions and 1416 deletions

View file

@ -81,32 +81,24 @@ struct PCXHeader
//
//==========================================================================
class FPCXTexture : public FTexture
class FPCXTexture : public FWorldTexture
{
public:
FPCXTexture (int lumpnum, PCXHeader &);
~FPCXTexture ();
const uint8_t *GetColumn (unsigned int column, const Span **spans_out);
const uint8_t *GetPixels ();
void Unload ();
FTextureFormat GetFormat ();
FTextureFormat GetFormat () override;
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
bool UseBasePalette();
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
bool UseBasePalette() override;
protected:
uint8_t *Pixels;
Span DummySpans[2];
void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
void ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);
virtual void MakeTexture ();
friend class FTexture;
uint8_t *MakeTexture (FRenderStyle style) override;
};
@ -154,44 +146,12 @@ FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum)
//==========================================================================
FPCXTexture::FPCXTexture(int lumpnum, PCXHeader & hdr)
: FTexture(NULL, lumpnum), Pixels(0)
: FWorldTexture(NULL, lumpnum)
{
bMasked = false;
Width = LittleShort(hdr.xmax) - LittleShort(hdr.xmin) + 1;
Height = LittleShort(hdr.ymax) - LittleShort(hdr.ymin) + 1;
CalcBitSize();
DummySpans[0].TopOffset = 0;
DummySpans[0].Length = Height;
DummySpans[1].TopOffset = 0;
DummySpans[1].Length = 0;
}
//==========================================================================
//
//
//
//==========================================================================
FPCXTexture::~FPCXTexture ()
{
Unload ();
}
//==========================================================================
//
//
//
//==========================================================================
void FPCXTexture::Unload ()
{
if (Pixels != NULL)
{
delete[] Pixels;
Pixels = NULL;
}
FTexture::Unload();
}
//==========================================================================
@ -211,51 +171,6 @@ FTextureFormat FPCXTexture::GetFormat()
//
//==========================================================================
const uint8_t *FPCXTexture::GetColumn (unsigned int column, const Span **spans_out)
{
if (Pixels == NULL)
{
MakeTexture ();
}
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;
}
//==========================================================================
//
//
//
//==========================================================================
const uint8_t *FPCXTexture::GetPixels ()
{
if (Pixels == NULL)
{
MakeTexture ();
}
return Pixels;
}
//==========================================================================
//
//
//
//==========================================================================
void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
{
int y, i, bytes;
@ -457,18 +372,19 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr
//
//==========================================================================
void FPCXTexture::MakeTexture()
uint8_t *FPCXTexture::MakeTexture(FRenderStyle style)
{
uint8_t PaletteMap[256];
PCXHeader header;
int bitcount;
bool alphatex = !!(style.Flags & STYLEF_RedIsAlpha);
auto lump = Wads.OpenLumpReader(SourceLump);
lump.Read(&header, sizeof(header));
bitcount = header.bitsPerPixel * header.numColorPlanes;
Pixels = new uint8_t[Width*Height];
auto Pixels = new uint8_t[Width*Height];
if (bitcount < 24)
{
@ -476,7 +392,8 @@ void FPCXTexture::MakeTexture()
{
for (int i=0;i<16;i++)
{
PaletteMap[i] = ColorMatcher.Pick(header.palette[i*3],header.palette[i*3+1],header.palette[i*3+2]);
if (!alphatex) PaletteMap[i] = ColorMatcher.Pick(header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]);
else PaletteMap[i] = header.palette[i * 3];
}
switch (bitcount)
@ -502,7 +419,7 @@ void FPCXTexture::MakeTexture()
uint8_t r = lump.ReadUInt8();
uint8_t g = lump.ReadUInt8();
uint8_t b = lump.ReadUInt8();
PaletteMap[i] = ColorMatcher.Pick(r,g,b);
PaletteMap[i] = !alphatex? ColorMatcher.Pick(r,g,b) : r;
}
lump.Seek(sizeof(header), FileReader::SeekSet);
ReadPCX8bits (Pixels, lump, &header);
@ -529,12 +446,13 @@ void FPCXTexture::MakeTexture()
{
for(int x=0; x < Width; x++)
{
Pixels[y+Height*x] = RGB256k.RGB[row[0]>>2][row[1]>>2][row[2]>>2];
Pixels[y + Height * x] = !alphatex? RGB256k.RGB[row[0] >> 2][row[1] >> 2][row[2] >> 2] : row[0];
row+=3;
}
}
delete [] buffer;
}
return Pixels;
}
//===========================================================================