- make sure that warping textures never create a warped true color image.

This replaces the old redirection hackery that had to work differently for the legacy render path.
Overriding CopyTrueColorTranslated is far more robust and ensures that no edge cases can reach the GetPixels function, which wasn't the case before.
This commit is contained in:
Christoph Oelckers 2018-04-24 21:58:26 +02:00
parent c37ff22a05
commit 5e8a4b96fe
6 changed files with 23 additions and 27 deletions

View File

@ -132,7 +132,7 @@ int FMaterial::mMaxBound;
FMaterial::FMaterial(FTexture * tx, bool expanded)
{
mShaderIndex = SHADER_Default;
tex = tx;
sourcetex = tex = tx;
// TODO: apply custom shader object here
/* if (tx->CustomShaderDefinition)
@ -211,10 +211,11 @@ FMaterial::FMaterial(FTexture * tx, bool expanded)
mSpriteU[0] = mSpriteV[0] = 0.f;
mSpriteU[1] = mSpriteV[1] = 1.f;
FTexture *basetex = (tx->bWarped && gl.legacyMode)? tx : tx->GetRedirect(false);
FTexture *basetex = tx->GetRedirect();
// allow the redirect only if the texture is not expanded or the scale matches.
if (!expanded || (tx->Scale.X == basetex->Scale.X && tx->Scale.Y == basetex->Scale.Y))
{
sourcetex = basetex;
mBaseLayer = ValidateSysTexture(basetex, expanded);
}
@ -326,7 +327,7 @@ bool FMaterial::TrimBorders(uint16_t *rect)
int w;
int h;
unsigned char *buffer = tex->CreateTexBuffer(0, w, h);
unsigned char *buffer = sourcetex->CreateTexBuffer(0, w, h);
if (buffer == NULL)
{
@ -549,8 +550,8 @@ int FMaterial::GetAreas(FloatRect **pAreas) const
{
if (mShaderIndex == SHADER_Default) // texture splitting can only be done if there's no attached effects
{
*pAreas = tex->areas;
return tex->areacount;
*pAreas = sourcetex->areas;
return sourcetex->areacount;
}
else
{
@ -569,7 +570,7 @@ void FMaterial::BindToFrameBuffer()
if (mBaseLayer == nullptr)
{
// must create the hardware texture first
mBaseLayer->BindOrCreate(tex, 0, 0, 0, 0);
mBaseLayer->BindOrCreate(sourcetex, 0, 0, 0, 0);
FHardwareTexture::Unbind(0);
ClearLastTexture();
}

View File

@ -87,6 +87,7 @@ class FMaterial
public:
FTexture *tex;
FTexture *sourcetex; // in case of redirection this is different from tex.
FMaterial(FTexture *tex, bool forceexpand);
~FMaterial();
@ -101,7 +102,7 @@ public:
}
bool isMasked() const
{
return !!tex->bMasked;
return !!sourcetex->bMasked;
}
int GetLayers() const

View File

@ -158,7 +158,7 @@ public:
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
int GetSourceLump() override { return DefinitionLump; }
FTexture *GetRedirect(bool wantwarped) override;
FTexture *GetRedirect() override;
FTexture *GetRawTexture() override;
void ResolvePatches();
@ -692,7 +692,7 @@ void FMultiPatchTexture::CheckForHacks ()
//
//==========================================================================
FTexture *FMultiPatchTexture::GetRedirect(bool wantwarped)
FTexture *FMultiPatchTexture::GetRedirect()
{
return bRedirect ? Parts->Texture : this;
}

View File

@ -120,24 +120,13 @@ int FWarpTexture::NextPo2 (int v)
return ++v;
}
//==========================================================================
//
// FMultiPatchTexture :: TexPart :: TexPart
//
//==========================================================================
FTexture *FWarpTexture::GetRedirect(bool wantwarped)
{
if (!wantwarped) return SourcePic->GetRedirect(false);
else return this;
}
//==========================================================================
//
// FMultiPatchTexture :: CopyTrueColorPixels
//
// This doesn't warp. It's just here in case someone tries to use a warp
// texture for compositing a multipatch texture
// True color texture generation must never hit the paletted path which
// always warps the buffer.
// As a result even CopyTrueColorTranslated must be overrideen here.
//
//==========================================================================
@ -146,3 +135,8 @@ int FWarpTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FC
return SourcePic->CopyTrueColorPixels(bmp, x, y, rotate, inf);
}
int FWarpTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf)
{
return SourcePic->CopyTrueColorTranslated(bmp, x, y, rotate, remap, inf);
}

View File

@ -888,7 +888,7 @@ bool FTexture::UseBasePalette()
return true;
}
FTexture *FTexture::GetRedirect(bool wantwarped)
FTexture *FTexture::GetRedirect()
{
return this;
}

View File

@ -302,10 +302,10 @@ public:
virtual bool Mipmapped() { return true; }
virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL);
int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf = NULL);
virtual int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf = NULL);
virtual bool UseBasePalette();
virtual int GetSourceLump() { return SourceLump; }
virtual FTexture *GetRedirect(bool wantwarped);
virtual FTexture *GetRedirect();
virtual FTexture *GetRawTexture(); // for FMultiPatchTexture to override
virtual void Unload ();
@ -725,13 +725,13 @@ public:
void Unload() override;
virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL) override;
virtual int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf = NULL) override;
const uint32_t *GetPixelsBgra() override;
bool CheckModified (FRenderStyle) override;
float GetSpeed() const { return Speed; }
int GetSourceLump() { return SourcePic->GetSourceLump(); }
void SetSpeed(float fac) { Speed = fac; }
FTexture *GetRedirect(bool wantwarped);
uint64_t GenTime[2] = { 0, 0 };
uint64_t GenTimeBgra = 0;