summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Burke <patrick.burke@nokia.com>2011-12-14 17:40:47 +1000
committerDanny Pope <daniel.pope@nokia.com>2012-02-01 02:58:37 +0100
commit2f085b274b6fc597b79e837a5b2cf896c9a32e58 (patch)
treed016d2300d9d952ccc5ea7beafec7ffddbf20aaf
parentd9c5034634efb2dec0a4d3976d4931ef6f1ef9b4 (diff)
Fix for Power-of-Two texture problem.
Work around for POTT-support problem - we now check for POTT support and convert if necessary. Change-Id: I8121c9f86c137c28a24bc9b81231fb4f27b707e8 Reviewed-by: Danny Pope <daniel.pope@nokia.com>
-rw-r--r--src/threed/textures/qgltexture2d.cpp23
-rw-r--r--src/threed/textures/qgltexture2d_p.h8
2 files changed, 31 insertions, 0 deletions
diff --git a/src/threed/textures/qgltexture2d.cpp b/src/threed/textures/qgltexture2d.cpp
index 31f0ee6c3..07fe98919 100644
--- a/src/threed/textures/qgltexture2d.cpp
+++ b/src/threed/textures/qgltexture2d.cpp
@@ -47,6 +47,7 @@
#include "qabstractdownloadmanager.h"
#include "qdownloadmanager.h"
#include "qthreadeddownloadmanager.h"
+#include "qopenglfunctions.h"
#include <QtCore/qfile.h>
#include <QtCore/qfileinfo.h>
@@ -92,6 +93,8 @@ QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QSize, getMaxImageSize)
+QGLTexture2DPrivate::ForcePowerOfTwo QGLTexture2DPrivate::forcePowerOfTwo = QGLTexture2DPrivate::ForcePowerOfTwoUndefined;
+
QGLTexture2DPrivate::QGLTexture2DPrivate()
{
horizontalWrap = QGL::Repeat;
@@ -105,6 +108,13 @@ QGLTexture2DPrivate::QGLTexture2DPrivate()
parameterGeneration = 0;
infos = 0;
downloadManager = 0;
+
+ if (forcePowerOfTwo == ForcePowerOfTwoUndefined) {
+ if (qgetenv("NPOT_MIPMAP_UNSUPPORTED").toInt() == 1)
+ forcePowerOfTwo = ForcePowerOfTwoTrue;
+ else
+ forcePowerOfTwo = ForcePowerOfTwoFalse;
+ }
}
QGLTexture2DPrivate::~QGLTexture2DPrivate()
@@ -606,6 +616,15 @@ bool QGLTexture2DPrivate::bind(GLenum target)
if (!ctx)
return false;
+ QOpenGLFunctions glFuncs(ctx);
+ if (!glFuncs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures))
+ {
+ QSize oldSize = size;
+ size = QGL::nextPowerOfTwo(size);
+ if (size != oldSize)
+ ++imageGeneration;
+ }
+
// Find the information block for the context, or create one.
QGLTexture2DTextureInfo *info = infos;
QGLTexture2DTextureInfo *prev = 0;
@@ -664,6 +683,10 @@ void QGLTexture2DPrivate::bindImages(QGLTexture2DTextureInfo *info)
scaledSize = QGL::nextPowerOfTwo(scaledSize);
}
#endif
+
+ if (forcePowerOfTwo == ForcePowerOfTwoTrue)
+ scaledSize = QGL::nextPowerOfTwo(scaledSize);
+
if (!image.isNull())
info->tex.uploadFace(GL_TEXTURE_2D, image, scaledSize);
else if (size.isValid())
diff --git a/src/threed/textures/qgltexture2d_p.h b/src/threed/textures/qgltexture2d_p.h
index 7a401c68c..0e9ac634b 100644
--- a/src/threed/textures/qgltexture2d_p.h
+++ b/src/threed/textures/qgltexture2d_p.h
@@ -109,6 +109,14 @@ public:
QGLTexture2DTextureInfo *infos;
QAbstractDownloadManager *downloadManager;
+ enum ForcePowerOfTwo {
+ ForcePowerOfTwoUndefined = -1,
+ ForcePowerOfTwoFalse = 0,
+ ForcePowerOfTwoTrue = 1
+ };
+
+ static ForcePowerOfTwo forcePowerOfTwo;
+
bool bind(GLenum target);
virtual void bindImages(QGLTexture2DTextureInfo *info);
};