diff --git a/src/common/textures/hires/hqresize.cpp b/src/common/textures/hires/hqresize.cpp index 67e20acfb..c72ac2be4 100644 --- a/src/common/textures/hires/hqresize.cpp +++ b/src/common/textures/hires/hqresize.cpp @@ -405,6 +405,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, bool checkonly) { // [BB] Make sure that inWidth and inHeight denote the size of @@ -482,8 +483,17 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA texbuffer.mContentId = contentId.id; } -bool shouldUpscale(FGameTexture *tex, ETextureType UseType) +//=========================================================================== +// +// This was pulled out of the above function to allow running these +// checks before the texture is passed to the render state. +// +//=========================================================================== + +bool calcShouldUpscale(FGameTexture *tex, ETextureType UseType) { + if (gl_texture_hqresizemode == 0 || gl_texture_hqresizemult == 1) return false; + // [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) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 65a5a7dce..391fb9604 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -632,10 +632,14 @@ public: class FGameTexture { FTexture *wrapped; + int8_t shouldUpscaleFlag = -1; public: FGameTexture(FTexture* wrap) : wrapped(wrap) {} ~FGameTexture(); + void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; } + int GetUpscaleFlag() { return shouldUpscaleFlag; } + FTexture* GetTexture() { return wrapped; } int GetSourceLump() const { return wrapped->GetSourceLump(); } void SetBrightmap(FGameTexture* tex) { wrapped->Brightmap = tex->GetTexture(); } @@ -755,7 +759,16 @@ inline FGameTexture* MakeGameTexture(FTexture* tex) return new FGameTexture(tex); } -bool shouldUpscale(FGameTexture* tex, ETextureType UseType); +bool calcShouldUpscale(FGameTexture* tex, ETextureType UseType); +inline bool shouldUpscale(FGameTexture* tex, ETextureType UseType) +{ + auto f = tex->GetUpscaleFlag(); + // Cache this value in the texture to save time because it is very frequently polled. + if (f != -1) return f; + auto res = calcShouldUpscale(tex, UseType); + tex->SetUpscaleFlag(res); + return res; +} #endif