- 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) FMaterial::FMaterial(FTexture * tx, bool expanded)
{ {
mShaderIndex = SHADER_Default; mShaderIndex = SHADER_Default;
tex = tx; sourcetex = tex = tx;
// TODO: apply custom shader object here // TODO: apply custom shader object here
/* if (tx->CustomShaderDefinition) /* if (tx->CustomShaderDefinition)
@ -211,10 +211,11 @@ FMaterial::FMaterial(FTexture * tx, bool expanded)
mSpriteU[0] = mSpriteV[0] = 0.f; mSpriteU[0] = mSpriteV[0] = 0.f;
mSpriteU[1] = mSpriteV[1] = 1.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. // 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)) if (!expanded || (tx->Scale.X == basetex->Scale.X && tx->Scale.Y == basetex->Scale.Y))
{ {
sourcetex = basetex;
mBaseLayer = ValidateSysTexture(basetex, expanded); mBaseLayer = ValidateSysTexture(basetex, expanded);
} }
@ -326,7 +327,7 @@ bool FMaterial::TrimBorders(uint16_t *rect)
int w; int w;
int h; int h;
unsigned char *buffer = tex->CreateTexBuffer(0, w, h); unsigned char *buffer = sourcetex->CreateTexBuffer(0, w, h);
if (buffer == NULL) 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 if (mShaderIndex == SHADER_Default) // texture splitting can only be done if there's no attached effects
{ {
*pAreas = tex->areas; *pAreas = sourcetex->areas;
return tex->areacount; return sourcetex->areacount;
} }
else else
{ {
@ -569,7 +570,7 @@ void FMaterial::BindToFrameBuffer()
if (mBaseLayer == nullptr) if (mBaseLayer == nullptr)
{ {
// must create the hardware texture first // must create the hardware texture first
mBaseLayer->BindOrCreate(tex, 0, 0, 0, 0); mBaseLayer->BindOrCreate(sourcetex, 0, 0, 0, 0);
FHardwareTexture::Unbind(0); FHardwareTexture::Unbind(0);
ClearLastTexture(); ClearLastTexture();
} }

View file

@ -87,6 +87,7 @@ class FMaterial
public: public:
FTexture *tex; FTexture *tex;
FTexture *sourcetex; // in case of redirection this is different from tex.
FMaterial(FTexture *tex, bool forceexpand); FMaterial(FTexture *tex, bool forceexpand);
~FMaterial(); ~FMaterial();
@ -101,7 +102,7 @@ public:
} }
bool isMasked() const bool isMasked() const
{ {
return !!tex->bMasked; return !!sourcetex->bMasked;
} }
int GetLayers() const 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 CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
int GetSourceLump() override { return DefinitionLump; } int GetSourceLump() override { return DefinitionLump; }
FTexture *GetRedirect(bool wantwarped) override; FTexture *GetRedirect() override;
FTexture *GetRawTexture() override; FTexture *GetRawTexture() override;
void ResolvePatches(); void ResolvePatches();
@ -692,7 +692,7 @@ void FMultiPatchTexture::CheckForHacks ()
// //
//========================================================================== //==========================================================================
FTexture *FMultiPatchTexture::GetRedirect(bool wantwarped) FTexture *FMultiPatchTexture::GetRedirect()
{ {
return bRedirect ? Parts->Texture : this; return bRedirect ? Parts->Texture : this;
} }

View file

@ -120,24 +120,13 @@ int FWarpTexture::NextPo2 (int v)
return ++v; return ++v;
} }
//==========================================================================
//
// FMultiPatchTexture :: TexPart :: TexPart
//
//==========================================================================
FTexture *FWarpTexture::GetRedirect(bool wantwarped)
{
if (!wantwarped) return SourcePic->GetRedirect(false);
else return this;
}
//========================================================================== //==========================================================================
// //
// FMultiPatchTexture :: CopyTrueColorPixels // FMultiPatchTexture :: CopyTrueColorPixels
// //
// This doesn't warp. It's just here in case someone tries to use a warp // True color texture generation must never hit the paletted path which
// texture for compositing a multipatch texture // 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); 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; return true;
} }
FTexture *FTexture::GetRedirect(bool wantwarped) FTexture *FTexture::GetRedirect()
{ {
return this; return this;
} }

View file

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