generic-poky/recipes-qt/qt5/qtdeclarative-5.0.2/0005-Avoid-swizzling-on-Ope...

89 lines
2.9 KiB
Diff

From 9d85c3c5823c6f73db245d4de786d911fd96edfd Mon Sep 17 00:00:00 2001
From: Florian Haenel <florian.haenel@lge.com>
Date: Sat, 8 Jun 2013 00:34:35 +0200
Subject: [PATCH 5/5] Avoid swizzling on OpenGL ES when possible
Add support for APPLE_texture_format_BGRA8888,
IMG_texture_format_BGRA8888,
EXT_texture_format_BGRA8888 and EXT_bgra. The apple one acts
just like the desktop EXT_bgra one, so they need slightly
different handling than the ES extensions.
This change also has the benefit that we no longer have a dedicated
ES path.
Upstream-Status: Backport https://codereview.qt-project.org/46549
Signed-off-by: Florian Haenel <florian.haenel@lge.com>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Change-Id: I5ecb0a02c3a7bd984d6752fa87163726118b93de
---
src/quick/scenegraph/util/qsgtexture.cpp | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp
index 16cc461..3d574f3 100644
--- a/src/quick/scenegraph/util/qsgtexture.cpp
+++ b/src/quick/scenegraph/util/qsgtexture.cpp
@@ -65,6 +65,10 @@
#include <QHash>
#endif
+#ifndef GL_BGRA
+#define GL_BGRA 0x80E1
+#endif
+
QT_BEGIN_NAMESPACE
inline static bool isPowerOfTwo(int x)
@@ -523,7 +527,6 @@ QSGPlainTexture::~QSGPlainTexture()
glDeleteTextures(1, &m_texture_id);
}
-#ifdef QT_OPENGL_ES
void qsg_swizzleBGRAToRGBA(QImage *image)
{
const int width = image->width();
@@ -534,7 +537,6 @@ void qsg_swizzleBGRAToRGBA(QImage *image)
p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00);
}
}
-#endif
void QSGPlainTexture::setImage(const QImage &image)
{
@@ -621,12 +623,26 @@ void QSGPlainTexture::bind()
updateBindOptions(m_dirty_bind_options);
+ GLenum externalFormat = GL_RGBA;
+ GLenum internalFormat = GL_RGBA;
+
+ const char *extensions = (const char *) glGetString(GL_EXTENSIONS);
+ if (strstr(extensions, "GL_EXT_bgra")) {
+ externalFormat = GL_BGRA;
#ifdef QT_OPENGL_ES
- qsg_swizzleBGRAToRGBA(&tmp);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp.constBits());
-#else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, tmp.constBits());
+ internalFormat = GL_BGRA;
#endif
+ } else if (strstr(extensions, "GL_APPLE_texture_format_BGRA8888")) {
+ externalFormat = GL_BGRA;
+ } else if (strstr(extensions, "GL_EXT_texture_format_BGRA8888")
+ || strstr(extensions, "GL_IMG_texture_format_BGRA8888")) {
+ externalFormat = GL_BGRA;
+ internalFormat = GL_BGRA;
+ } else {
+ qsg_swizzleBGRAToRGBA(&tmp);
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, externalFormat, GL_UNSIGNED_BYTE, tmp.constBits());
if (m_has_mipmaps) {
QOpenGLContext *ctx = QOpenGLContext::currentContext();
--
1.8.2.1