summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-07-15 12:37:47 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2011-07-18 13:14:34 (GMT)
commit9f6d3ebf349dbf77a9c499aeea75cb220181658c (patch)
treeb601474b2b079c57ec44942d1ffc7fa9cf1eaeef /src/opengl
parentb5d357d63aeb28b8be62f1a3004a6a7969c7a81e (diff)
downloadQt-9f6d3ebf349dbf77a9c499aeea75cb220181658c.zip
Qt-9f6d3ebf349dbf77a9c499aeea75cb220181658c.tar.gz
Qt-9f6d3ebf349dbf77a9c499aeea75cb220181658c.tar.bz2
Don't use GL_REPEAT for NPOT textures in GLES2.
We already handle NPOT textures correctly by calling fract() on the texture coordinates in the fragment shader, but we also need to make sure not to set GL_REPEAT as the wrap mode, because the GLES2 spec says that the driver should return (0, 0, 0, 1) if an NPOT texture has wrap mode different from GL_CLAMP_TO_EDGE. Previous GLES2-implementations we've tested on have thus not been GLES2-compliant (or supported GL_OES_texture_npot). Partial back-port / modification of c5a377e944f9a87c372ff8371c66b03d861803a6 in 4.8. Reviewed-by: Kim
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index 803f949..047d589 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -90,6 +90,11 @@
QT_BEGIN_NAMESPACE
+inline static bool isPowerOfTwo(uint x)
+{
+ return x && !(x & (x - 1));
+}
+
#if defined(Q_WS_WIN)
extern Q_GUI_EXPORT bool qt_cleartype_enabled;
#endif
@@ -229,7 +234,13 @@ void QGL2PaintEngineExPrivate::updateBrushTexture()
QGLTexture *tex = ctx->d_func()->bindTexture(currentBrushPixmap, GL_TEXTURE_2D, GL_RGBA,
QGLContext::InternalBindOption |
QGLContext::CanFlipNativePixmapBindOption);
- updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform);
+ GLenum wrapMode = GL_REPEAT;
+#ifdef QT_OPENGL_ES_2
+ // should check for GL_OES_texture_npot or GL_IMG_texture_npot extension
+ if (!isPowerOfTwo(currentBrushPixmap.width()) || !isPowerOfTwo(currentBrushPixmap.height()))
+ wrapMode = GL_CLAMP_TO_EDGE;
+#endif
+ updateTextureFilter(GL_TEXTURE_2D, wrapMode, q->state()->renderHints & QPainter::SmoothPixmapTransform);
textureInvertedY = tex->options & QGLContext::InvertedYBindOption ? -1 : 1;
}
brushTextureDirty = false;