- cache the upscaling check's result in the texture, as this will be queried quite frequently.

This commit is contained in:
Christoph Oelckers 2020-04-17 00:22:34 +02:00
parent 8505c7ee7d
commit 09898ef6c3
2 changed files with 25 additions and 2 deletions

View file

@ -405,6 +405,7 @@ static void xbrzOldScale(size_t factor, const uint32_t* src, uint32_t* trg, int
// the upsampled buffer. // the upsampled buffer.
// //
//=========================================================================== //===========================================================================
void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly) void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly)
{ {
// [BB] Make sure that inWidth and inHeight denote the size of // [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; 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. // [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)

View file

@ -632,10 +632,14 @@ public:
class FGameTexture class FGameTexture
{ {
FTexture *wrapped; FTexture *wrapped;
int8_t shouldUpscaleFlag = -1;
public: public:
FGameTexture(FTexture* wrap) : wrapped(wrap) {} FGameTexture(FTexture* wrap) : wrapped(wrap) {}
~FGameTexture(); ~FGameTexture();
void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; }
int GetUpscaleFlag() { return shouldUpscaleFlag; }
FTexture* GetTexture() { return wrapped; } FTexture* GetTexture() { return wrapped; }
int GetSourceLump() const { return wrapped->GetSourceLump(); } int GetSourceLump() const { return wrapped->GetSourceLump(); }
void SetBrightmap(FGameTexture* tex) { wrapped->Brightmap = tex->GetTexture(); } void SetBrightmap(FGameTexture* tex) { wrapped->Brightmap = tex->GetTexture(); }
@ -755,7 +759,16 @@ inline FGameTexture* MakeGameTexture(FTexture* tex)
return new FGameTexture(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 #endif