Skip to content

Commit

Permalink
- fixed code that deternines when to upscale a texture.
Browse files Browse the repository at this point in the history
This was very much non-functional.
  • Loading branch information
coelckers committed Jun 9, 2020
1 parent 2d13dcf commit 60a20af
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
10 changes: 1 addition & 9 deletions src/common/textures/gametexture.h
Expand Up @@ -241,10 +241,6 @@ class FGameTexture
DisplayHeight = h;
ScaleX = TexelWidth / w;
ScaleY = TexelHeight / h;
if (shouldUpscaleFlag < 2)
{
shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2;
}

// compensate for roundoff errors
if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.);
Expand All @@ -271,10 +267,6 @@ class FGameTexture
{
ScaleX = x;
ScaleY = y;
if (shouldUpscaleFlag < 2)
{
shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2;
}
DisplayWidth = TexelWidth / x;
DisplayHeight = TexelHeight / y;
}
Expand Down Expand Up @@ -374,7 +366,7 @@ enum EUpscaleFlags
extern int upscalemask;
void UpdateUpscaleMask();

int calcShouldUpscale(FGameTexture* tex);
void calcShouldUpscale(FGameTexture* tex);
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.
Expand Down
11 changes: 6 additions & 5 deletions src/common/textures/hires/hqresize.cpp
Expand Up @@ -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.
const int maxInputSize = gl_texture_hqresize_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!)
if (tex->isHardwareCanvas())
return 0;
return;

// already scaled?
if (tex->GetScaleX() >= 2.f || tex->GetScaleY() > 2.f)
return 0;
return;

return CTF_Upscale;
tex->SetUpscaleFlag(1);
}
4 changes: 2 additions & 2 deletions src/common/textures/texturemanager.cpp
Expand Up @@ -106,7 +106,7 @@ void FTextureManager::DeleteAll()
// 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
//
// 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
// main reason to call this outside of the destruction code.
//
Expand All @@ -120,8 +120,8 @@ void FTextureManager::FlushAll()
{
Textures[i].Texture->CleanHardwareData();
delete Textures[i].Texture->GetSoftwareTexture();
Textures[i].Texture->SetSoftwareTexture(nullptr);
calcShouldUpscale(Textures[i].Texture);
Textures[i].Texture->SetSoftwareTexture(nullptr);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rendering/swrenderer/r_swrenderer.cpp
Expand Up @@ -241,6 +241,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *camtex, AActor *viewp
cameraViewwindow = r_viewwindow;

auto tex = GetSWCamTex(camtex);
if (!tex) return;

DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas();

Expand Down
9 changes: 4 additions & 5 deletions src/rendering/swrenderer/textures/r_swtexture.cpp
Expand Up @@ -68,11 +68,10 @@ FSoftwareTexture::FSoftwareTexture(FGameTexture *tex)
mSource = tex->GetTexture();

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.
auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| f);
auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| mBufferFlags);
mPhysicalWidth = info.mWidth;
mPhysicalHeight = info.mHeight;
mPhysicalScale = tex->GetTexelWidth() > 0 ? mPhysicalWidth / tex->GetTexelWidth() : mPhysicalWidth;
Expand Down Expand Up @@ -130,7 +129,7 @@ const uint8_t *FSoftwareTexture::GetPixels(int style)
}
else
{
auto f = mBufferFlags | CTF_Upscale;
auto f = mBufferFlags;
auto tempbuffer = mSource->CreateTexBuffer(0, f);
Pixels.Resize(GetPhysicalWidth()*GetPhysicalHeight());
PalEntry *pe = (PalEntry*)tempbuffer.mBuffer;
Expand Down Expand Up @@ -176,7 +175,7 @@ const uint32_t *FSoftwareTexture::GetPixelsBgra()
}
else
{
auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags | CTF_Upscale);
auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags);
CreatePixelsBgraWithMipmaps();
PalEntry *pe = (PalEntry*)tempbuffer.mBuffer;
for (int y = 0; y < GetPhysicalHeight(); y++)
Expand Down

0 comments on commit 60a20af

Please sign in to comment.