- fixed code that deternines when to upscale a texture.

This was very much non-functional.
This commit is contained in:
Christoph Oelckers 2020-06-10 00:21:19 +02:00
parent 2d13dcfc81
commit 60a20af8ff
5 changed files with 14 additions and 21 deletions

View file

@ -241,10 +241,6 @@ public:
DisplayHeight = h; DisplayHeight = h;
ScaleX = TexelWidth / w; ScaleX = TexelWidth / w;
ScaleY = TexelHeight / h; ScaleY = TexelHeight / h;
if (shouldUpscaleFlag < 2)
{
shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2;
}
// compensate for roundoff errors // compensate for roundoff errors
if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.); if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.);
@ -271,10 +267,6 @@ public:
{ {
ScaleX = x; ScaleX = x;
ScaleY = y; ScaleY = y;
if (shouldUpscaleFlag < 2)
{
shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2;
}
DisplayWidth = TexelWidth / x; DisplayWidth = TexelWidth / x;
DisplayHeight = TexelHeight / y; DisplayHeight = TexelHeight / y;
} }
@ -374,7 +366,7 @@ enum EUpscaleFlags
extern int upscalemask; extern int upscalemask;
void UpdateUpscaleMask(); void UpdateUpscaleMask();
int calcShouldUpscale(FGameTexture* tex); void calcShouldUpscale(FGameTexture* tex);
inline int shouldUpscale(FGameTexture* tex, EUpscaleFlags UseType) inline int shouldUpscale(FGameTexture* tex, EUpscaleFlags UseType)
{ {
// This only checks the global scale mask and the texture's validation for upscaling. Everything else has been done up front elsewhere. // This only checks the global scale mask and the texture's validation for upscaling. Everything else has been done up front elsewhere.

View file

@ -502,20 +502,21 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA
// //
//=========================================================================== //===========================================================================
int calcShouldUpscale(FGameTexture *tex) void calcShouldUpscale(FGameTexture *tex)
{ {
tex->SetUpscaleFlag(0);
// [BB] Don't resample if width * height of the input texture is bigger than gl_texture_hqresize_maxinputsize squared. // [BB] Don't resample if width * height of the input texture is bigger than gl_texture_hqresize_maxinputsize squared.
const int maxInputSize = gl_texture_hqresize_maxinputsize; const int maxInputSize = gl_texture_hqresize_maxinputsize;
if (tex->GetTexelWidth() * tex->GetTexelHeight() > maxInputSize * maxInputSize) if (tex->GetTexelWidth() * tex->GetTexelHeight() > maxInputSize * maxInputSize)
return 0; return;
// [BB] Don't try to upsample textures based off FCanvasTexture. (This should never get here in the first place!) // [BB] Don't try to upsample textures based off FCanvasTexture. (This should never get here in the first place!)
if (tex->isHardwareCanvas()) if (tex->isHardwareCanvas())
return 0; return;
// already scaled? // already scaled?
if (tex->GetScaleX() >= 2.f || tex->GetScaleY() > 2.f) if (tex->GetScaleX() >= 2.f || tex->GetScaleY() > 2.f)
return 0; return;
return CTF_Upscale; tex->SetUpscaleFlag(1);
} }

View file

@ -106,7 +106,7 @@ void FTextureManager::DeleteAll()
// This must not, under any circumstances, delete the wipe textures, because // This must not, under any circumstances, delete the wipe textures, because
// all CCMDs triggering a flush can be executed while a wipe is in progress // all CCMDs triggering a flush can be executed while a wipe is in progress
// //
// This now also deletes the software textures because having the software // This now also deletes the software textures because the software
// renderer can also use the texture scalers and that is the // renderer can also use the texture scalers and that is the
// main reason to call this outside of the destruction code. // main reason to call this outside of the destruction code.
// //
@ -120,8 +120,8 @@ void FTextureManager::FlushAll()
{ {
Textures[i].Texture->CleanHardwareData(); Textures[i].Texture->CleanHardwareData();
delete Textures[i].Texture->GetSoftwareTexture(); delete Textures[i].Texture->GetSoftwareTexture();
Textures[i].Texture->SetSoftwareTexture(nullptr);
calcShouldUpscale(Textures[i].Texture); calcShouldUpscale(Textures[i].Texture);
Textures[i].Texture->SetSoftwareTexture(nullptr);
} }
} }
} }

View file

@ -241,6 +241,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *camtex, AActor *viewp
cameraViewwindow = r_viewwindow; cameraViewwindow = r_viewwindow;
auto tex = GetSWCamTex(camtex); auto tex = GetSWCamTex(camtex);
if (!tex) return;
DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas(); DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas();

View file

@ -68,11 +68,10 @@ FSoftwareTexture::FSoftwareTexture(FGameTexture *tex)
mSource = tex->GetTexture(); mSource = tex->GetTexture();
mBufferFlags = CTF_ProcessData; mBufferFlags = CTF_ProcessData;
auto f = mBufferFlags;
if (shouldUpscale(tex, scaleFlagFromUseType(tex->GetUseType()))) f |= CTF_Upscale; if (shouldUpscale(tex, scaleFlagFromUseType(tex->GetUseType()))) mBufferFlags |= CTF_Upscale;
// calculate the real size after running the scaler. // calculate the real size after running the scaler.
auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| f); auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| mBufferFlags);
mPhysicalWidth = info.mWidth; mPhysicalWidth = info.mWidth;
mPhysicalHeight = info.mHeight; mPhysicalHeight = info.mHeight;
mPhysicalScale = tex->GetTexelWidth() > 0 ? mPhysicalWidth / tex->GetTexelWidth() : mPhysicalWidth; mPhysicalScale = tex->GetTexelWidth() > 0 ? mPhysicalWidth / tex->GetTexelWidth() : mPhysicalWidth;
@ -130,7 +129,7 @@ const uint8_t *FSoftwareTexture::GetPixels(int style)
} }
else else
{ {
auto f = mBufferFlags | CTF_Upscale; auto f = mBufferFlags;
auto tempbuffer = mSource->CreateTexBuffer(0, f); auto tempbuffer = mSource->CreateTexBuffer(0, f);
Pixels.Resize(GetPhysicalWidth()*GetPhysicalHeight()); Pixels.Resize(GetPhysicalWidth()*GetPhysicalHeight());
PalEntry *pe = (PalEntry*)tempbuffer.mBuffer; PalEntry *pe = (PalEntry*)tempbuffer.mBuffer;
@ -176,7 +175,7 @@ const uint32_t *FSoftwareTexture::GetPixelsBgra()
} }
else else
{ {
auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags | CTF_Upscale); auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags);
CreatePixelsBgraWithMipmaps(); CreatePixelsBgraWithMipmaps();
PalEntry *pe = (PalEntry*)tempbuffer.mBuffer; PalEntry *pe = (PalEntry*)tempbuffer.mBuffer;
for (int y = 0; y < GetPhysicalHeight(); y++) for (int y = 0; y < GetPhysicalHeight(); y++)