From 65755f9a68947e774c640ce92c022d677acdcc4a Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 6 Nov 2012 12:22:39 +0100 Subject: Fix native RGB text on OpenGL ES 2 without BGRA extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Angle, for instance, which is now the default on Windows, does not support the GL_BGRA_EXT format as input for glTexSubImage2D(). In the case where it's not detected, we therefore need to flip the bytes in the input. Change-Id: Ibe78d0223e3c2c39cb1943cdcf67103044d00aa7 Reviewed-by: Samuel Rødal --- src/gui/opengl/qopenglfunctions.cpp | 4 ++++ src/gui/opengl/qopengltextureglyphcache.cpp | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp index e2191d6f3a..4d6a0e437d 100644 --- a/src/gui/opengl/qopenglfunctions.cpp +++ b/src/gui/opengl/qopenglfunctions.cpp @@ -344,6 +344,10 @@ static int qt_gl_resolve_extensions() extensions |= QOpenGLExtensions::ElementIndexUint; if (extensionMatcher.match("GL_OES_depth24")) extensions |= QOpenGLExtensions::Depth24; + + if (extensionMatcher.match("GL_EXT_bgra")) + extensions |= QOpenGLExtensions::BGRATextureFormat; + #else extensions |= QOpenGLExtensions::ElementIndexUint | QOpenGLExtensions::MapBuffer; diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp index 4538961359..4e20f6aad2 100644 --- a/src/gui/opengl/qopengltextureglyphcache.cpp +++ b/src/gui/opengl/qopengltextureglyphcache.cpp @@ -42,6 +42,7 @@ #include "qopengltextureglyphcache_p.h" #include "qopenglpaintengine_p.h" #include "private/qopenglengineshadersource_p.h" +#include "qopenglextensions_p.h" QT_BEGIN_NAMESPACE @@ -301,6 +302,11 @@ void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed const int maskWidth = mask.width(); const int maskHeight = mask.height(); +#if defined(QT_OPENGL_ES_2) + QOpenGLExtensions extensions(ctx); + bool hasBGRA = extensions.hasOpenGLExtension(QOpenGLExtensions::BGRATextureFormat); +#endif + if (mask.format() == QImage::Format_Mono) { mask = mask.convertToFormat(QImage::Format_Indexed8); for (int y = 0; y < maskHeight; ++y) { @@ -318,7 +324,14 @@ void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed uchar g = src[x] >> 8; uchar b = src[x]; quint32 avg = (quint32(r) + quint32(g) + quint32(b) + 1) / 3; // "+1" for rounding. - src[x] = (src[x] & 0x00ffffff) | (avg << 24); + +#if defined(QT_OPENGL_ES_2) + if (!hasBGRA) { + // Reverse bytes to match GL_RGBA + src[x] = (avg << 24) | (quint32(r) << 0) | (quint32(g) << 8) | (quint32(b) << 16); + } else +#endif + src[x] = (src[x] & 0x00ffffff) | (avg << 24); } } } @@ -326,8 +339,7 @@ void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture); if (mask.format() == QImage::Format_RGB32) { #if defined(QT_OPENGL_ES_2) - // ###TODO Ensure extension is actually present on ES2 - glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA_EXT, GL_UNSIGNED_BYTE, mask.bits()); + glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, hasBGRA ? GL_BGRA_EXT : GL_RGBA, GL_UNSIGNED_BYTE, mask.bits()); #else glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits()); #endif -- cgit v1.2.3