From c962253085265e2a9f1cfb42919cf44d04b2c45f Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Mon, 9 May 2011 12:58:40 +0200 Subject: [PATCH] Fixed issues with ShaderEffectSource and threaded rendering. --- src/declarative/items/qsgshadereffectsource.cpp | 29 ++++++++++++++++------ src/declarative/items/qsgshadereffectsource_p.h | 12 +++++++++ .../scenegraph/coreapi/qsgdefaultrenderer.cpp | 4 ++- src/declarative/scenegraph/coreapi/qsgnode.h | 8 +++--- .../scenegraph/coreapi/qsgnodeupdater.cpp | 2 +- src/declarative/scenegraph/coreapi/qsgrenderer.cpp | 2 +- src/declarative/scenegraph/coreapi/qsgrenderer_p.h | 8 +++--- 7 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/declarative/items/qsgshadereffectsource.cpp b/src/declarative/items/qsgshadereffectsource.cpp index a39398f..11d7f6f 100644 --- a/src/declarative/items/qsgshadereffectsource.cpp +++ b/src/declarative/items/qsgshadereffectsource.cpp @@ -54,6 +54,17 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(qmlFboOverlay, QML_FBO_OVERLAY) +QSGShaderEffectSourceNode::QSGShaderEffectSourceNode() +{ + setFlag(UsePreprocess, true); +} + +void QSGShaderEffectSourceNode::markDirtyTexture() +{ + markDirty(DirtyMaterial); +} + + QSGShaderEffectTexture::QSGShaderEffectTexture(QSGItem *shaderSource) : QSGDynamicTexture() , m_item(0) @@ -260,9 +271,8 @@ void QSGShaderEffectTexture::grab() } // Render texture. - QSGNode::DirtyFlags dirty = root->dirtyFlags(); - root->markDirty(QSGNode::DirtyNodeAdded); // Force matrix and clip update. - m_renderer->nodeChanged(root, QSGNode::DirtyNodeAdded); // Force render list update. + root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update. + m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update. #ifdef QSG_DEBUG_FBO_OVERLAY if (qmlFboOverlay()) { @@ -329,7 +339,7 @@ void QSGShaderEffectTexture::grab() ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D); } - root->markDirty(dirty | QSGNode::DirtyNodeAdded); // Force matrix, clip and render list update. + root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip, opacity and render list update. #ifdef QSG_DEBUG_FBO_OVERLAY if (qmlFboOverlay()) @@ -488,7 +498,6 @@ void QSGShaderEffectSource::setMipmap(bool enabled) { if (enabled == m_mipmap) return; - printf("setting mipmap to: %d\n", enabled); m_mipmap = enabled; update(); emit mipmapChanged(); @@ -560,13 +569,17 @@ QSGNode *QSGShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNod return 0; } - QSGImageNode *node = static_cast(oldNode); + QSGShaderEffectSourceNode *node = static_cast(oldNode); if (!node) { - node = QSGItemPrivate::get(this)->sceneGraphContext()->createImageNode(); - node->setFlag(QSGNode::UsePreprocess, true); + node = new QSGShaderEffectSourceNode; node->setTexture(m_texture); + connect(m_texture, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()), Qt::DirectConnection); } + // If live and recursive, update continuously. + if (m_live && m_recursive) + node->markDirty(QSGNode::DirtyMaterial); + QSGShaderEffectTexture *tex = qobject_cast(m_texture); tex->setItem(QSGItemPrivate::get(m_sourceItem)->itemNode()); diff --git a/src/declarative/items/qsgshadereffectsource_p.h b/src/declarative/items/qsgshadereffectsource_p.h index e7e3ad6..891cc1e 100644 --- a/src/declarative/items/qsgshadereffectsource_p.h +++ b/src/declarative/items/qsgshadereffectsource_p.h @@ -46,6 +46,7 @@ #include #include #include +#include #include "qpointer.h" #include "qsize.h" @@ -63,6 +64,17 @@ class QSGNode; class UpdatePaintNodeData; class QGLFramebufferObject; +class QSGShaderEffectSourceNode : public QObject, public QSGDefaultImageNode +{ + Q_OBJECT + +public: + QSGShaderEffectSourceNode(); + +private Q_SLOTS: + void markDirtyTexture(); +}; + class QSGShaderEffectTexture : public QSGDynamicTexture { Q_OBJECT diff --git a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp index 4569e7f..badaa2c 100644 --- a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp +++ b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp @@ -177,7 +177,9 @@ void QMLRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyFlags flags) { QSGRenderer::nodeChanged(node, flags); - quint32 rebuildFlags = QSGNode::DirtyNodeAdded | QSGNode::DirtyNodeRemoved | QSGNode::DirtyMaterial | QSGNode::DirtyOpacity; + quint32 rebuildFlags = QSGNode::DirtyNodeAdded | QSGNode::DirtyNodeRemoved + | QSGNode::DirtyMaterial | QSGNode::DirtyOpacity + | QSGNode::DirtyForceUpdate; if (flags & rebuildFlags) m_rebuild_lists = true; diff --git a/src/declarative/scenegraph/coreapi/qsgnode.h b/src/declarative/scenegraph/coreapi/qsgnode.h index b00ef4e..a905696 100644 --- a/src/declarative/scenegraph/coreapi/qsgnode.h +++ b/src/declarative/scenegraph/coreapi/qsgnode.h @@ -83,14 +83,16 @@ public: DirtyNodeRemoved = 0x0008, DirtyGeometry = 0x0010, DirtyRenderOrder = 0x0020, - DirtyMaterial = 0x0100, - DirtyOpacity = 0x0200, + DirtyMaterial = 0x0040, + DirtyOpacity = 0x0080, + DirtyForceUpdate = 0x0100, DirtyAll = 0xffff, DirtyPropagationMask = DirtyMatrix | DirtyClipList | DirtyNodeAdded - | DirtyOpacity, + | DirtyOpacity + | DirtyForceUpdate, }; Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) diff --git a/src/declarative/scenegraph/coreapi/qsgnodeupdater.cpp b/src/declarative/scenegraph/coreapi/qsgnodeupdater.cpp index d81248b..6eff011 100644 --- a/src/declarative/scenegraph/coreapi/qsgnodeupdater.cpp +++ b/src/declarative/scenegraph/coreapi/qsgnodeupdater.cpp @@ -227,7 +227,7 @@ void QSGNodeUpdater::visitNode(QSGNode *n) #endif if (n->dirtyFlags() || m_force_update) { - bool forceUpdate = n->dirtyFlags() & (QSGNode::DirtyNodeAdded); + bool forceUpdate = n->dirtyFlags() & (QSGNode::DirtyNodeAdded | QSGNode::DirtyForceUpdate); if (forceUpdate) ++m_force_update; diff --git a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp index 04c0817..e267e3d 100644 --- a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp @@ -126,10 +126,10 @@ QSGRenderer::QSGRenderer(QSGContext *context) , m_context(context) , m_root_node(0) , m_node_updater(0) + , m_bindable(0) , m_changed_emitted(false) , m_mirrored(false) , m_is_rendering(false) - , m_bindable(0) { initializeGLFunctions(); } diff --git a/src/declarative/scenegraph/coreapi/qsgrenderer_p.h b/src/declarative/scenegraph/coreapi/qsgrenderer_p.h index fcf966d..272df80 100644 --- a/src/declarative/scenegraph/coreapi/qsgrenderer_p.h +++ b/src/declarative/scenegraph/coreapi/qsgrenderer_p.h @@ -174,11 +174,11 @@ private: QGLShaderProgram m_clip_program; int m_clip_matrix_id; - bool m_changed_emitted; - bool m_mirrored; - bool m_is_rendering; - const Bindable *m_bindable; + + bool m_changed_emitted : 1; + bool m_mirrored : 1; + bool m_is_rendering : 1; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QSGRenderer::ClearMode) -- 2.7.4