- added a 'check only' option to CreateTexBuffer.

This is meant to calculate the content ID without constructing the texture buffer.
This commit is contained in:
Christoph Oelckers 2018-12-12 00:46:58 +01:00
parent 200188b3a4
commit 368c788789
4 changed files with 91 additions and 81 deletions

View File

@ -358,7 +358,7 @@ int FTexture::CheckExternalFile(bool & hascolorkey)
//
//==========================================================================
bool FTexture::LoadHiresTexture(FTextureBuffer &texbuffer)
bool FTexture::LoadHiresTexture(FTextureBuffer &texbuffer, bool checkonly)
{
if (HiresLump == -1)
{
@ -377,6 +377,8 @@ bool FTexture::LoadHiresTexture(FTextureBuffer &texbuffer)
int w = HiresTexture->GetWidth();
int h = HiresTexture->GetHeight();
if (!checkonly)
{
unsigned char * buffer = new unsigned char[w*(h + 1) * 4];
memset(buffer, 0, w * (h + 1) * 4);
@ -392,11 +394,12 @@ bool FTexture::LoadHiresTexture(FTextureBuffer &texbuffer)
// This is a crappy Doomsday color keyed image
// We have to remove the key manually. :(
uint32_t * dwdata = (uint32_t*)buffer;
for (int i = (w*h); i>0; i--)
for (int i = (w*h); i > 0; i--)
{
if (dwdata[i] == 0xffffff00 || dwdata[i] == 0xffff00ff) dwdata[i] = 0;
}
}
}
FContentIdBuilder contentId;
contentId.id = 0;
contentId.imageID = HiresTexture->GetImage()->GetId();

View File

@ -352,7 +352,7 @@ static void xbrzOldScale(size_t factor, const uint32_t* src, uint32_t* trg, int
// the upsampled buffer.
//
//===========================================================================
void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha)
void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly)
{
// [BB] Make sure that inWidth and inHeight denote the size of
// the returned buffer even if we don't upsample the input buffer.
@ -398,10 +398,12 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA
type = 2;
}
#endif
if (mult < 2)
type = 0;
// These checks are to ensure consistency of the content ID.
if (mult < 2 || mult > 6 || type < 1 || type > 6) return;
if (type < 4 && mult > 4) mult = 4;
if (!checkonly)
{
if (type == 1)
{
if (mult == 2)
@ -442,7 +444,7 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA
texbuffer.mBuffer = normalNxHelper(&normalNx, mult, texbuffer.mBuffer, inWidth, inHeight, texbuffer.mWidth, texbuffer.mHeight);
else
return;
}
// Encode the scaling method in the content ID.
FContentIdBuilder contentId;
contentId.id = texbuffer.mContentId;

View File

@ -668,6 +668,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
unsigned char * buffer = nullptr;
int W, H;
int isTransparent = -1;
bool checkonly = !!(flags & CTF_CheckOnly);
if (flags & CTF_CheckHires)
{
@ -679,10 +680,12 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
W = GetWidth() + 2 * exx;
H = GetHeight() + 2 * exx;
if (!checkonly)
{
buffer = new unsigned char[W*(H + 1) * 4];
memset(buffer, 0, W * (H + 1) * 4);
auto remap = translation <= 0? nullptr : FUniquePalette::GetPalette(translation);
auto remap = translation <= 0 ? nullptr : FUniquePalette::GetPalette(translation);
FBitmap bmp(buffer, W * 4, W, H);
int trans;
@ -699,6 +702,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
isTransparent = 0;
// A translated image is not conclusive for setting the texture's transparency info.
}
}
if (GetImage())
{
@ -718,8 +722,8 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
// Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.)
if (GetImage() && flags & CTF_ProcessData)
{
CreateUpsampledTextureBuffer(result, !!isTransparent);
ProcessData(result.mBuffer, result.mWidth, result.mHeight, false);
CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly);
if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false);
}
return result;

View File

@ -109,6 +109,7 @@ enum ECreateTexBufferFlags
CTF_CheckHires = 1, // use external hires replacement if found
CTF_Expand = 2, // create buffer with a one-pixel wide border
CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures.
};
@ -282,7 +283,7 @@ public:
virtual ~FTexture ();
virtual FImageSource *GetImage() const { return nullptr; }
void AddAutoMaterials();
void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha);
void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly);
// These are mainly meant for 2D code which only needs logical information about the texture to position it properly.
int GetDisplayWidth() { return GetScaledWidth(); }
@ -491,7 +492,7 @@ public:
private:
int CheckDDPK3();
int CheckExternalFile(bool & hascolorkey);
bool LoadHiresTexture(FTextureBuffer &texbuffer);
bool LoadHiresTexture(FTextureBuffer &texbuffer, bool checkonly);
bool bSWSkyColorDone = false;
PalEntry FloorSkyColor;