From 8ab1323842433fb6b45e7d6f381b4b9710a81da9 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 23 Apr 2014 15:20:33 +0200 Subject: Don't use GL_REPEAT for image-brush drawing on OpenGL ES2 Backport of commit 8dfeb1c374972f06759a92b4edc5d6a18b96ccec in QtGui to the same class in the QtOpenGL module. OpenGL ES2 doesn't support NPOT textures in combination with GL_REPEAT, so for OpenGL ES2 we use a custom program that emulates repeat by taking the fractional part of the texture coordinates. This is not enough though, as merely setting GL_TEXTURE_WRAP_x to GL_REPEAT with a NPOT texture is an error in some implementations, so we have to guard the call to updateTextureFilter() in updateBrushTexture() with a check for OpenGL ES2 and use GL_CLAMP_TO_EDGE instead. Change-Id: Icbdd784c2c6d562849679f87da18b20d5441f389 Reviewed-by: Laszlo Agocs --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/opengl') diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 2b49e4d2d1..2ec4434d57 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -223,11 +223,19 @@ void QGL2PaintEngineExPrivate::updateBrushTexture() if (currentBrushPixmap.width() > max_texture_size || currentBrushPixmap.height() > max_texture_size) currentBrushPixmap = currentBrushPixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio); + GLuint wrapMode = GL_REPEAT; + if (ctx->contextHandle()->isES()) { + // OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead, + // we emulate GL_REPEAT by only taking the fractional part of the texture coords + // in the qopenglslTextureBrushSrcFragmentShader program. + wrapMode = GL_CLAMP_TO_EDGE; + } + funcs.glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); 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); + updateTextureFilter(GL_TEXTURE_2D, wrapMode, q->state()->renderHints & QPainter::SmoothPixmapTransform); textureInvertedY = tex->options & QGLContext::InvertedYBindOption ? -1 : 1; } brushTextureDirty = false; -- cgit v1.2.3