From 9f6d3ebf349dbf77a9c499aeea75cb220181658c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 15 Jul 2011 14:37:47 +0200 Subject: 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 --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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; -- cgit v0.12 From 7ddf40aa71ca0adb7846bf8b0df2240a3870d894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 18 Jul 2011 14:52:16 +0200 Subject: Prevent failed rendering for NPOT textures in GLES2. Shouldn't use the (default) GL_REPEAT wrap mode on GLES2 unless GL_OES_texture_npot is present. Reviewed-by: Kim --- src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp b/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp index ec6c33f..73435df 100644 --- a/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp +++ b/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp @@ -159,7 +159,9 @@ Qt::HANDLE QMeeGoPixmapData::imageToEGLSharedImage(const QImage &image) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glBindTexture(GL_TEXTURE_2D, textureId); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + EGLImageKHR eglimage = QEgl::eglCreateImageKHR(QEgl::display(), QEglContext::currentContext(QEgl::OpenGL)->context(), EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer) textureId, -- cgit v0.12