From 8736de61dc30d70e05ad1be4ef456e8eedbe51b8 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Fri, 2 Nov 2012 13:50:58 +1000 Subject: Observe GL context loss in ShaderEffectItem This is a backport of commit: 01928c91ff0ae76cdb02f50af3c62368e28cafb6 with change id: I8281e77f7285ea0046bdf092ab827cae3b00a6d2 from qt5/qtquick1 to qt4. Task-number: QTBUG-28136 Change-Id: Idbeffce919d85f55df5184f8a8c9a89649687f93 Reviewed-by: Robin Burchell --- src/imports/shaders/shadereffectitem.cpp | 43 ++++++-------------------------- src/imports/shaders/shadereffectitem.h | 2 -- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/src/imports/shaders/shadereffectitem.cpp b/src/imports/shaders/shadereffectitem.cpp index 330cc85..ab2698b 100644 --- a/src/imports/shaders/shadereffectitem.cpp +++ b/src/imports/shaders/shadereffectitem.cpp @@ -199,10 +199,6 @@ Rectangle { */ -#ifdef Q_OS_SYMBIAN -#define OBSERVE_GL_CONTEXT_LOSS 1 -#endif - ShaderEffectItem::ShaderEffectItem(QDeclarativeItem *parent) : QDeclarativeItem(parent) , m_program(0) @@ -219,21 +215,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; } @@ -413,30 +403,15 @@ void ShaderEffectItem::renderEffect(QPainter *painter, const QMatrix4x4 &matrix) if (!painter || !painter->device()) return; -#ifdef OBSERVE_GL_CONTEXT_LOSS - QGLContext *context = const_cast (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; @@ -683,14 +658,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 5260cdc..a32e7dc 100644 --- a/src/imports/shaders/shadereffectitem.h +++ b/src/imports/shaders/shadereffectitem.h @@ -143,8 +143,6 @@ private: bool m_hasShaderPrograms : 1; bool m_mirrored : 1; bool m_defaultVertexShader : 1; - - QGLFramebufferObject* m_contextObserver; }; QT_END_HEADER -- cgit v0.12