aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/scenegraph/util/qsgtexturematerial.cpp
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2011-05-11 15:12:08 +0200
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2011-05-11 17:09:16 +0200
commite3aef83de3433b50f4263e9b4d54bb4ed389893c (patch)
tree573f614b17358f148b08419c7ae43cf9d96348db /src/declarative/scenegraph/util/qsgtexturematerial.cpp
parent9e037dae270a8879499e53e453bb0176bb19196a (diff)
Fixed image tiling on scene graph.
Repeat wrapping of non-power-of-two textures is not supported on OpenGL ES 2 by default. This commit implements a fallback for tiled QML Images.
Diffstat (limited to 'src/declarative/scenegraph/util/qsgtexturematerial.cpp')
-rw-r--r--src/declarative/scenegraph/util/qsgtexturematerial.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/declarative/scenegraph/util/qsgtexturematerial.cpp b/src/declarative/scenegraph/util/qsgtexturematerial.cpp
index 1e14172de3..cdca59963c 100644
--- a/src/declarative/scenegraph/util/qsgtexturematerial.cpp
+++ b/src/declarative/scenegraph/util/qsgtexturematerial.cpp
@@ -41,10 +41,17 @@
#include "qsgtexturematerial_p.h"
-#include <qglshaderprogram.h>
+#include <QtOpenGL/qglshaderprogram.h>
+#include <QtOpenGL/qglfunctions.h>
QT_BEGIN_NAMESPACE
+inline static bool isPowerOfTwo(int x)
+{
+ // Assumption: x >= 1
+ return x == (x & -x);
+}
+
const char qt_scenegraph_texture_material_vertex_code[] =
"uniform highp mat4 qt_Matrix; \n"
"attribute highp vec4 qt_VertexPosition; \n"
@@ -95,8 +102,19 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa
QSGTexture *t = tx->texture();
t->setFiltering(tx->filtering());
- t->setHorizontalWrapMode(tx->horizontalWrapMode());
- t->setVerticalWrapMode(tx->verticalWrapMode());
+#ifdef QT_OPENGL_ES_2
+ bool npotSupported = state.context()->functions()->hasOpenGLFeature(QGLFunctions::NPOTTextures);
+ QSize size = t->textureSize();
+ bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height());
+ if (!npotSupported && isNpot) {
+ t->setHorizontalWrapMode(QSGTexture::ClampToEdge);
+ t->setVerticalWrapMode(QSGTexture::ClampToEdge);
+ } else
+#endif
+ {
+ t->setHorizontalWrapMode(tx->horizontalWrapMode());
+ t->setVerticalWrapMode(tx->verticalWrapMode());
+ }
t->setMipmapFiltering(tx->mipmapFiltering());
if (oldTx == 0 || oldTx->texture()->textureId() != t->textureId())