Commit d324db88 authored by Gunnar Sletta's avatar Gunnar Sletta
Browse files

Make QQuickFramebufferObject a texture provider.


Change-Id: Ib9cf0f99dc07e4125c4ccd2d45da2839d8af88b6
Reviewed-by: default avatarLaszlo Agocs <laszlo.agocs@digia.com>
parent 04f0d937
dev 5.10 5.11 5.12 5.12.1 5.12.10 5.12.11 5.12.12 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13 5.13.0 5.13.1 5.13.2 5.14 5.14.0 5.14.1 5.14.2 5.15 5.15.0 5.15.1 5.15.2 5.4 5.5 5.6 5.7 5.8 5.9 5.9.8 6.0 6.0.0 6.1 6.1.0 6.1.1 6.1.2 6.1.3 6.2 6.2.0 6.2.1 6.2.2 wip/cmake wip/dbus wip/itemviews wip/nacl wip/new-backend wip/pointerhandler wip/propertycache-refactor wip/qquickdeliveryagent wip/scenegraphng wip/tizen wip/webassembly v5.15.0-alpha1 v5.14.1 v5.14.0 v5.14.0-rc2 v5.14.0-rc1 v5.14.0-beta3 v5.14.0-beta2 v5.14.0-beta1 v5.14.0-alpha1 v5.13.2 v5.13.1 v5.13.0 v5.13.0-rc3 v5.13.0-rc2 v5.13.0-rc1 v5.13.0-beta4 v5.13.0-beta3 v5.13.0-beta2 v5.13.0-beta1 v5.13.0-alpha1 v5.12.7 v5.12.6 v5.12.5 v5.12.4 v5.12.3 v5.12.2 v5.12.1 v5.12.0 v5.12.0-rc2 v5.12.0-rc1 v5.12.0-beta4 v5.12.0-beta3 v5.12.0-beta2 v5.12.0-beta1 v5.12.0-alpha1 v5.11.3 v5.11.2 v5.11.1 v5.11.0 v5.11.0-rc2 v5.11.0-rc1 v5.11.0-beta4 v5.11.0-beta3 v5.11.0-beta2 v5.11.0-beta1 v5.11.0-alpha1 v5.10.1 v5.10.0 v5.10.0-rc3 v5.10.0-rc2 v5.10.0-rc1 v5.10.0-beta4 v5.10.0-beta3 v5.10.0-beta2 v5.10.0-beta1 v5.10.0-alpha1 v5.9.9 v5.9.8 v5.9.7 v5.9.6 v5.9.5 v5.9.4 v5.9.3 v5.9.2 v5.9.1 v5.9.0 v5.9.0-rc2 v5.9.0-rc1 v5.9.0-beta4 v5.9.0-beta3 v5.9.0-beta2 v5.9.0-beta1 v5.9.0-alpha1 v5.8.0 v5.8.0-rc1 v5.8.0-beta1 v5.8.0-alpha1 v5.7.1 v5.7.0 v5.7.0-rc1 v5.7.0-beta1 v5.7.0-alpha1 v5.6.3 v5.6.2 v5.6.1 v5.6.1-1 v5.6.0 v5.6.0-rc1 v5.6.0-beta1 v5.6.0-alpha1 v5.5.1 v5.5.0 v5.5.0-rc1 v5.5.0-beta1 v5.5.0-alpha1 v5.4.2 v5.4.1 v5.4.0 v5.4.0-rc1 v5.4.0-beta1 v5.4.0-alpha1
No related merge requests found
Showing with 60 additions and 4 deletions
......@@ -47,10 +47,12 @@ class QQuickFramebufferObjectPrivate : public QQuickItemPrivate
public:
QQuickFramebufferObjectPrivate()
: followsItemSize(true)
, node(0)
{
}
bool followsItemSize;
mutable QSGFramebufferObjectNode *node;
};
/*!
......@@ -91,6 +93,11 @@ public:
* to \c false and return a texture of your choosing from
* QQuickFramebufferObject::Renderer::createFramebufferObject().
*
* Starting Qt 5.4, the QQuickFramebufferObject class is a
* \l{QSGTextureProvider}{texture provider}
* and can be used directly in \l {ShaderEffect}{ShaderEffects} and other
* classes that consume texture providers.
*
* \sa {Scene Graph - Rendering FBOs}, {Scene Graph and Rendering}
*/
......@@ -101,6 +108,7 @@ QQuickFramebufferObject::QQuickFramebufferObject(QQuickItem *parent) :
QQuickItem(*new QQuickFramebufferObjectPrivate, parent)
{
setFlag(ItemHasContents);
connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
/*!
......@@ -142,7 +150,7 @@ void QQuickFramebufferObject::geometryChanged(const QRectF &newGeometry, const Q
update();
}
class QSGFramebufferObjectNode : public QObject, public QSGSimpleTextureNode
class QSGFramebufferObjectNode : public QSGTextureProvider, public QSGSimpleTextureNode
{
Q_OBJECT
......@@ -155,7 +163,7 @@ public:
, renderPending(true)
, invalidatePending(false)
{
qsgnode_set_description(this, QStringLiteral("fbonode"));
}
~QSGFramebufferObjectNode()
......@@ -172,6 +180,11 @@ public:
window->update();
}
QSGTexture *texture() const Q_DECL_OVERRIDE
{
return QSGSimpleTextureNode::texture();
}
public Q_SLOTS:
void render()
{
......@@ -186,6 +199,7 @@ public Q_SLOTS:
QOpenGLFramebufferObject::blitFramebuffer(msDisplayFbo, fbo);
markDirty(QSGNode::DirtyMaterial);
emit textureChanged();
}
}
......@@ -217,11 +231,13 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode
Q_D(QQuickFramebufferObject);
if (!n) {
n = new QSGFramebufferObjectNode;
n->window = window();
if (!d->node)
d->node = new QSGFramebufferObjectNode;
n = d->node;
}
if (!n->renderer) {
n->window = window();
n->renderer = createRenderer();
n->renderer->data = n;
connect(window(), SIGNAL(beforeRendering()), n, SLOT(render()));
......@@ -265,6 +281,39 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode
return n;
}
bool QQuickFramebufferObject::isTextureProvider() const
{
return true;
}
QSGTextureProvider *QQuickFramebufferObject::textureProvider() const
{
Q_D(const QQuickFramebufferObject);
QQuickWindow *w = window();
if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) {
qWarning("QQuickFramebufferObject::textureProvider: can only be queried on the rendering thread of an exposed window");
return 0;
}
if (!d->node)
d->node = new QSGFramebufferObjectNode;
return d->node;
}
void QQuickFramebufferObject::releaseResources()
{
// When release resources is called on the GUI thread, we only need to
// forget about the node. Since it is the node we returned from updatePaintNode
// it will be managed by the scene graph.
Q_D(QQuickFramebufferObject);
d->node = 0;
}
void QQuickFramebufferObject::invalidateSG()
{
Q_D(QQuickFramebufferObject);
d->node = 0;
}
/*!
* \class QQuickFramebufferObject::Renderer
* \inmodule QtQuick
......
......@@ -75,6 +75,10 @@ public:
virtual Renderer *createRenderer() const = 0;
bool isTextureProvider() const Q_DECL_OVERRIDE;
QSGTextureProvider *textureProvider() const Q_DECL_OVERRIDE;
void releaseResources() Q_DECL_OVERRIDE;
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
......@@ -83,6 +87,9 @@ protected:
Q_SIGNALS:
void textureFollowsItemSizeChanged(bool);
private Q_SLOTS:
void invalidateSG();
};
QT_END_NAMESPACE
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment