aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/util/qsgtexture.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-01-16 11:01:58 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-01-19 19:52:21 +0100
commit0a6323c2de23bd7a23e44ff3a534b06f7be994c6 (patch)
treebc3c6d28af5dd3a8f47631669bd8a23237046582 /src/quick/scenegraph/util/qsgtexture.cpp
parente5627b505e39db4cbd1d9670cfdfe234881ed227 (diff)
Scale mipmapped npot images when not supported
Task-number: QTBUG-43847 Task-number: QTBUG-40789 Change-Id: Iceacaa49bafffb31752a9fb26c896df570153fec Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/quick/scenegraph/util/qsgtexture.cpp')
-rw-r--r--src/quick/scenegraph/util/qsgtexture.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp
index fc5050014e..bfc9212138 100644
--- a/src/quick/scenegraph/util/qsgtexture.cpp
+++ b/src/quick/scenegraph/util/qsgtexture.cpp
@@ -35,6 +35,7 @@
#include <qopenglfunctions.h>
#include <QtQuick/private/qsgcontext_p.h>
#include <qthread.h>
+#include <qmath.h>
#include <private/qquickprofiler_p.h>
#include <private/qqmlglobal_p.h>
#include <QtGui/qguiapplication.h>
@@ -75,13 +76,11 @@ static bool qsg_leak_check = !qgetenv("QML_LEAK_CHECK").isEmpty();
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_DEBUG
inline static bool isPowerOfTwo(int x)
{
// Assumption: x >= 1
return x == (x & -x);
}
-#endif
QSGTexturePrivate::QSGTexturePrivate()
: wrapChanged(false)
@@ -686,6 +685,16 @@ void QSGPlainTexture::bind()
m_texture_size = tmp.size();
}
+ // Scale to a power of two size if mipmapping is requested and the
+ // texture is npot and npot textures are not properly supported.
+ if (mipmapFiltering() != QSGTexture::None
+ && (!isPowerOfTwo(m_texture_size.width()) || !isPowerOfTwo(m_texture_size.height()))
+ && !funcs->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)) {
+ tmp = tmp.scaled(qNextPowerOfTwo(m_texture_size.width()), qNextPowerOfTwo(m_texture_size.height()),
+ Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ m_texture_size = tmp.size();
+ }
+
if (tmp.width() * 4 != tmp.bytesPerLine())
tmp = tmp.copy();