summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Adams <chris.adams@jollamobile.com>2012-11-27 11:05:48 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-28 21:05:45 +0100
commit01928c91ff0ae76cdb02f50af3c62368e28cafb6 (patch)
tree4b6d8b1d5db7c004983c6a410137eecad2081834 /src
parent4ca0c45b80b00b984414ac674909cb03917cbe4d (diff)
Observe GL context loss in ShaderEffectItem
Recreate the shader program as required when the GL context changes. Also delete the shader program when the ShaderEffectItem is deactivated, to save graphics memory. Previously, this was done only for Symbian platforms, and in a suboptimal fashion. This patch implements the behaviour for all platforms in a more optimal manner. Task-number: QTBUG-28136 Change-Id: I8281e77f7285ea0046bdf092ab827cae3b00a6d2 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Alan Alpert <aalpert@rim.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/shaders/shadereffectitem.cpp39
-rw-r--r--src/imports/shaders/shadereffectitem.h2
2 files changed, 7 insertions, 34 deletions
diff --git a/src/imports/shaders/shadereffectitem.cpp b/src/imports/shaders/shadereffectitem.cpp
index 85a4076a..7d4ca497 100644
--- a/src/imports/shaders/shadereffectitem.cpp
+++ b/src/imports/shaders/shadereffectitem.cpp
@@ -218,21 +218,15 @@ ShaderEffectItem::ShaderEffectItem(QDeclarativeItem *parent)
, m_hasShaderPrograms(false)
, m_mirrored(false)
, m_defaultVertexShader(true)
- , m_contextObserver(0)
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
connect(this, SIGNAL(visibleChanged()), this, SLOT(handleVisibilityChange()));
m_active = isVisible();
-
-#ifndef OBSERVE_GL_CONTEXT_LOSS
- m_program = new QGLShaderProgram(this);
-#endif
}
ShaderEffectItem::~ShaderEffectItem()
{
reset();
- delete m_contextObserver;
}
@@ -412,30 +406,15 @@ void ShaderEffectItem::renderEffect(QPainter *painter, const QMatrix4x4 &matrix)
if (!painter || !painter->device())
return;
-#ifdef OBSERVE_GL_CONTEXT_LOSS
- QGLContext *context = const_cast <QGLContext*> (QGLContext::currentContext());
- if (!m_program || !m_contextObserver || !m_contextObserver->isValid()) {
- // Context has changed, re-create QGLShaderProgram
- if (context) {
- delete m_program;
- m_program = 0;
-
- delete m_contextObserver;
- m_contextObserver = 0;
-
+ if (!m_program || !m_program->programId()) {
+ // Deleted due to deactivation, to save GPU memory,
+ // or invalidated due to GL context change.
+ delete m_program;
+ if (QGLContext::currentContext())
m_program = new QGLShaderProgram(this);
- m_contextObserver = new QGLFramebufferObject(QSize(2,2));
-
- if (!m_contextObserver || !m_program) {
- delete m_program;
- m_program = 0;
- delete m_contextObserver;
- m_contextObserver = 0;
- qWarning() << "ShaderEffectItem::renderEffect - Creating QGLShaderProgram or QGLFrameBufferObject failed!";
- }
- }
+ if (!m_program)
+ qWarning() << "ShaderEffectItem::renderEffect - Creating QGLShaderProgram failed!";
}
-#endif
if (!m_program)
return;
@@ -682,14 +661,10 @@ void ShaderEffectItem::setActive(bool enable)
}
// QGLShaderProgram is deleted when not active (to minimize GPU memory usage).
-#ifdef OBSERVE_GL_CONTEXT_LOSS
if (!m_active && m_program) {
delete m_program;
m_program = 0;
- delete m_contextObserver;
- m_contextObserver = 0;
}
-#endif
emit activeChanged();
markDirty();
diff --git a/src/imports/shaders/shadereffectitem.h b/src/imports/shaders/shadereffectitem.h
index ea390625..29dd799b 100644
--- a/src/imports/shaders/shadereffectitem.h
+++ b/src/imports/shaders/shadereffectitem.h
@@ -146,8 +146,6 @@ private:
bool m_hasShaderPrograms : 1;
bool m_mirrored : 1;
bool m_defaultVertexShader : 1;
-
- QGLFramebufferObject* m_contextObserver;
};
QT_END_HEADER