1
From 6fd6369328f66b426680d115be961fba0bcd2b8e Mon Sep 17 00:00:00 2001
2
From: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
3
Date: Mon, 29 Jul 2013 13:49:42 +0200
4
Subject: [PATCH] Add workaround for GL on Android emulator
6
On the Android Emulator, the shaders will be compiled by a desktop
7
GL driver, since the GL driver in the emulator is just a thin
8
wrapper. The GL driver does not necessarily support the precision
9
qualifiers, which can cause applications to break. We detect this
10
at runtime in the platform plugin and set a workaround flag to
12
Backport from upstream patch 9eeb1bd (5.1.1+, Android specific).
14
Task-number: QTBUG-32557
15
Change-Id: Ied00cfe8e804d1f7862697dd379a14f3bed3d980
16
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
17
Signed-off-by: Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
19
src/gui/kernel/qopenglcontext.cpp | 5 +++++
20
src/gui/kernel/qopenglcontext_p.h | 7 +++++++
21
src/gui/opengl/qopenglshaderprogram.cpp | 3 ++-
22
3 files changed, 14 insertions(+), 1 deletion(-)
24
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
25
index 645c13a..a440730 100644
26
--- a/src/gui/kernel/qopenglcontext.cpp
27
+++ b/src/gui/kernel/qopenglcontext.cpp
28
@@ -523,6 +523,11 @@ bool QOpenGLContext::makeCurrent(QSurface *surface)
30
d->shareGroup->d_func()->deletePendingResources(this);
32
+ const char *rendererString = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
33
+ if (rendererString != 0 && qstrncmp(rendererString, "Android Emulator", 16) == 0) {
34
+ QOpenGLContextPrivate *ctx_d = QOpenGLContextPrivate::get(this);
35
+ ctx_d->workaround_missingPrecisionQualifiers = true;
38
QOpenGLContextPrivate::toggleMakeCurrentTracker(this, true);
40
diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h
41
index fb81412..5e51a38 100644
42
--- a/src/gui/kernel/qopenglcontext_p.h
43
+++ b/src/gui/kernel/qopenglcontext_p.h
44
@@ -205,6 +205,7 @@ public:
45
, max_texture_size(-1)
46
, workaround_brokenFBOReadBack(false)
47
, workaround_brokenTexSubImage(false)
48
+ , workaround_missingPrecisionQualifiers(false)
52
@@ -232,6 +233,7 @@ public:
54
bool workaround_brokenFBOReadBack;
55
bool workaround_brokenTexSubImage;
56
+ bool workaround_missingPrecisionQualifiers;
58
QPaintEngineEx *active_engine;
60
@@ -239,6 +241,11 @@ public:
64
+ static QOpenGLContextPrivate *get(QOpenGLContext *context)
66
+ return context->d_func();
69
#if !defined(QT_NO_DEBUG)
70
static bool toggleMakeCurrentTracker(QOpenGLContext *context, bool value)
72
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
73
index 88c9c80..0c36973 100644
74
--- a/src/gui/opengl/qopenglshaderprogram.cpp
75
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
76
@@ -385,7 +385,8 @@ bool QOpenGLShader::compileSourceCode(const char *source)
77
srclen.append(GLint(sizeof(qualifierDefines) - 1));
79
#ifdef QOpenGL_REDEFINE_HIGHP
80
- if (d->shaderType == Fragment) {
81
+ QOpenGLContextPrivate *ctx_d = QOpenGLContextPrivate::get(QOpenGLContext::currentContext());
82
+ if (d->shaderType == Fragment && !ctx_d->workaround_missingPrecisionQualifiers) {
83
src.append(redefineHighp);
84
srclen.append(GLint(sizeof(redefineHighp) - 1));