From e0d97d42dd59b6cb048e97fe7a4612ad4f53aef7 Mon Sep 17 00:00:00 2001 From: RadialApps Date: Wed, 14 Jun 2017 15:50:16 +0530 Subject: [PATCH] Allow Downsizing Textures For some reason, this leads to a huge performance benefit on mobile devices, especially when using MegaSurface --- src/sharedstate.cpp | 35 +++++++++++------------------------ src/window.cpp | 27 +++++++-------------------- 2 files changed, 18 insertions(+), 44 deletions(-) diff --git a/src/sharedstate.cpp b/src/sharedstate.cpp index 0778da9..68d1097 100644 --- a/src/sharedstate.cpp +++ b/src/sharedstate.cpp @@ -263,39 +263,26 @@ void SharedState::bindTex() void SharedState::ensureTexSize(int minW, int minH, Vec2i ¤tSizeOut) { - if (minW > p->globalTexW) + minW = findNextPow2(minW); minH = findNextPow2(minH); + + if (minW != p->globalTexW || minH != p->globalTexH) { + p->globalTexW = minW; + p->globalTexH = minH; p->globalTexDirty = true; - p->globalTexW = findNextPow2(minW); } - - if (minH > p->globalTexH) - { - p->globalTexDirty = true; - p->globalTexH = findNextPow2(minH); - } - + currentSizeOut = Vec2i(p->globalTexW, p->globalTexH); } TEXFBO &SharedState::gpTexFBO(int minW, int minH) { - bool needResize = false; - - if (minW > p->gpTexFBO.width) - { - p->gpTexFBO.width = findNextPow2(minW); - needResize = true; - } - - if (minH > p->gpTexFBO.height) - { - p->gpTexFBO.height = findNextPow2(minH); - needResize = true; - } - - if (needResize) + minW = findNextPow2(minW); minH = findNextPow2(minH); + + if (minW != p->gpTexFBO.width || minH != p->gpTexFBO.height) { + p->gpTexFBO.width = minW; + p->gpTexFBO.height = minH; TEX::bind(p->gpTexFBO.tex); TEX::allocEmpty(p->gpTexFBO.width, p->gpTexFBO.height); } diff --git a/src/window.cpp b/src/window.cpp index 71a8cc9..9c450d0 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -388,29 +388,16 @@ struct WindowPrivate void ensureBaseTexReady() { - /* Make sure texture is big enough */ - int newW = baseTex.width; - int newH = baseTex.height; - bool resizeNeeded = false; + /* Make sure texture is properly sized */ + int newW = findNextPow2(size.x); + int newH = findNextPow2(size.y); - if (size.x > baseTex.width) + if (newW != baseTex.width || newH != baseTex.height) { - newW = findNextPow2(size.x); - resizeNeeded = true; + shState->texPool().release(baseTex); + baseTex = shState->texPool().request(newW, newH); + baseTexDirty = true; } - if (size.y > baseTex.height) - { - newH = findNextPow2(size.y); - resizeNeeded = true; - } - - if (!resizeNeeded) - return; - - shState->texPool().release(baseTex); - baseTex = shState->texPool().request(newW, newH); - - baseTexDirty = true; } void redrawBaseTex()