summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Burke <patrick.burke@nokia.com>2011-12-14 17:40:47 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-11 08:05:36 +0100
commitd5e26f4a770fb9116e12d998e5c530c3a329db31 (patch)
tree1136f66cd44fcee961ab059bb5a0ecfdec0495d3
parent7cd6e7b614ec8415372291f3d86fcbe7296f6d5d (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: Christopher Ham <christopher.ham@nokia.com> 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 31f0ee6c..07fe9891 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 7a401c68..0e9ac634 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);
};