- 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:
parent
102d2647d3
commit
7e169eb76f
21 changed files with 484 additions and 1416 deletions
|
|
@ -39,6 +39,7 @@
|
|||
#include "templates.h"
|
||||
#include "v_palette.h"
|
||||
#include "textures/textures.h"
|
||||
#include "r_data/r_translate.h"
|
||||
|
||||
|
||||
// posts are runs of non masked source pixels
|
||||
|
|
@ -55,24 +56,13 @@ struct column_t
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
class FPatchTexture : public FTexture
|
||||
class FPatchTexture : public FWorldTexture
|
||||
{
|
||||
bool badflag = false;
|
||||
public:
|
||||
FPatchTexture (int lumpnum, patch_t *header);
|
||||
~FPatchTexture ();
|
||||
|
||||
const uint8_t *GetColumn (unsigned int column, const Span **spans_out);
|
||||
const uint8_t *GetPixels ();
|
||||
void Unload ();
|
||||
|
||||
protected:
|
||||
uint8_t *Pixels;
|
||||
Span **Spans;
|
||||
bool hackflag;
|
||||
|
||||
|
||||
virtual void MakeTexture ();
|
||||
void HackHack (int newheight);
|
||||
uint8_t *MakeTexture (FRenderStyle style) override;
|
||||
void DetectBadPatches();
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
|
|
@ -149,12 +139,13 @@ FTexture *PatchTexture_TryCreate(FileReader & file, int lumpnum)
|
|||
//==========================================================================
|
||||
|
||||
FPatchTexture::FPatchTexture (int lumpnum, patch_t * header)
|
||||
: FTexture(NULL, lumpnum), Pixels(0), Spans(0), hackflag(false)
|
||||
: FWorldTexture(NULL, lumpnum)
|
||||
{
|
||||
Width = header->width;
|
||||
Height = header->height;
|
||||
LeftOffset = header->leftoffset;
|
||||
TopOffset = header->topoffset;
|
||||
DetectBadPatches();
|
||||
CalcBitSize ();
|
||||
}
|
||||
|
||||
|
|
@ -164,89 +155,7 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FPatchTexture::~FPatchTexture ()
|
||||
{
|
||||
Unload ();
|
||||
if (Spans != NULL)
|
||||
{
|
||||
FreeSpans (Spans);
|
||||
Spans = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FPatchTexture::Unload ()
|
||||
{
|
||||
if (Pixels != NULL)
|
||||
{
|
||||
delete[] Pixels;
|
||||
Pixels = NULL;
|
||||
}
|
||||
FTexture::Unload();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
const uint8_t *FPatchTexture::GetPixels ()
|
||||
{
|
||||
if (Pixels == NULL)
|
||||
{
|
||||
MakeTexture ();
|
||||
}
|
||||
return Pixels;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
const uint8_t *FPatchTexture::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)
|
||||
{
|
||||
if (Spans == NULL)
|
||||
{
|
||||
Spans = CreateSpans(Pixels);
|
||||
}
|
||||
*spans_out = Spans[column];
|
||||
}
|
||||
return Pixels + column*Height;
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FPatchTexture::MakeTexture ()
|
||||
uint8_t *FPatchTexture::MakeTexture (FRenderStyle style)
|
||||
{
|
||||
uint8_t *remap, remaptable[256];
|
||||
int numspans;
|
||||
|
|
@ -258,23 +167,11 @@ void FPatchTexture::MakeTexture ()
|
|||
|
||||
maxcol = (const column_t *)((const uint8_t *)patch + Wads.LumpLength (SourceLump) - 3);
|
||||
|
||||
// Check for badly-sized patches
|
||||
#if 0 // Such textures won't be created so there's no need to check here
|
||||
if (LittleShort(patch->width) <= 0 || LittleShort(patch->height) <= 0)
|
||||
if (style.Flags & STYLEF_RedIsAlpha)
|
||||
{
|
||||
lump = Wads.ReadLump ("-BADPATC");
|
||||
patch = (const patch_t *)lump.GetMem();
|
||||
Printf (PRINT_BOLD, "Patch %s has a non-positive size.\n", Name);
|
||||
remap = translationtables[TRANSLATION_Standard][8]->Remap;
|
||||
}
|
||||
else if (LittleShort(patch->width) > 2048 || LittleShort(patch->height) > 2048)
|
||||
{
|
||||
lump = Wads.ReadLump ("-BADPATC");
|
||||
patch = (const patch_t *)lump.GetMem();
|
||||
Printf (PRINT_BOLD, "Patch %s is too big.\n", Name);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bNoRemap0)
|
||||
else if (bNoRemap0)
|
||||
{
|
||||
memcpy (remaptable, GPalette.Remap, 256);
|
||||
remaptable[0] = 0;
|
||||
|
|
@ -286,9 +183,9 @@ void FPatchTexture::MakeTexture ()
|
|||
}
|
||||
|
||||
|
||||
if (hackflag)
|
||||
if (badflag)
|
||||
{
|
||||
Pixels = new uint8_t[Width * Height];
|
||||
auto Pixels = new uint8_t[Width * Height];
|
||||
uint8_t *out;
|
||||
|
||||
// Draw the image to the buffer
|
||||
|
|
@ -302,7 +199,7 @@ void FPatchTexture::MakeTexture ()
|
|||
out++, in++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
return Pixels;
|
||||
}
|
||||
|
||||
// Add a little extra space at the end if the texture's height is not
|
||||
|
|
@ -311,7 +208,7 @@ void FPatchTexture::MakeTexture ()
|
|||
|
||||
numspans = Width;
|
||||
|
||||
Pixels = new uint8_t[numpix];
|
||||
auto Pixels = new uint8_t[numpix];
|
||||
memset (Pixels, 0, numpix);
|
||||
|
||||
// Draw the image to the buffer
|
||||
|
|
@ -355,6 +252,7 @@ void FPatchTexture::MakeTexture ()
|
|||
column = (const column_t *)((const uint8_t *)column + column->length + 4);
|
||||
}
|
||||
}
|
||||
return Pixels;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -364,8 +262,11 @@ void FPatchTexture::MakeTexture ()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FPatchTexture::HackHack (int newheight)
|
||||
void FPatchTexture::DetectBadPatches ()
|
||||
{
|
||||
// The patch must look like it is large enough for the rules to apply to avoid using this on truly empty patches.
|
||||
if (Wads.LumpLength(SourceLump) < Width * Height / 2) return;
|
||||
|
||||
// Check if this patch is likely to be a problem.
|
||||
// It must be 256 pixels tall, and all its columns must have exactly
|
||||
// one post, where each post has a supposed length of 0.
|
||||
|
|
@ -381,29 +282,17 @@ void FPatchTexture::HackHack (int newheight)
|
|||
const column_t *col = (column_t*)((uint8_t*)realpatch+LittleLong(cofs[x]));
|
||||
if (col->topdelta != 0 || col->length != 0)
|
||||
{
|
||||
break; // It's not bad!
|
||||
return; // It's not bad!
|
||||
}
|
||||
col = (column_t *)((uint8_t *)col + 256 + 4);
|
||||
if (col->topdelta != 0xFF)
|
||||
{
|
||||
break; // More than one post in a column!
|
||||
return; // More than one post in a column!
|
||||
}
|
||||
}
|
||||
if (x == x2)
|
||||
{
|
||||
// If all the columns were checked, it needs fixing.
|
||||
Unload ();
|
||||
if (Spans != NULL)
|
||||
{
|
||||
FreeSpans (Spans);
|
||||
}
|
||||
|
||||
Height = newheight;
|
||||
LeftOffset = 0;
|
||||
TopOffset = 0;
|
||||
|
||||
hackflag = true;
|
||||
bMasked = false; // Hacked textures don't have transparent parts.
|
||||
}
|
||||
LeftOffset = 0;
|
||||
TopOffset = 0;
|
||||
badflag = true;
|
||||
bMasked = false; // Hacked textures don't have transparent parts.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue