diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-11-12 10:57:15 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-11-14 15:33:37 +0100 |
commit | b6b1d5899415fef3231120c08c56a1dc2e246940 (patch) | |
tree | 7bf4db6ba359bf76d968fdd58d5b63a5b997b782 /src/quick/items/qquickframebufferobject.cpp | |
parent | 0a649f25813b8c2ecf679db106cb8ec175b9145a (diff) |
Make QQuickFbo work with the OpenGL backend of QRhi
So no matter if Quick goes directly to OpenGL, or via QRhi,
QQuickFramebufferObject will still work.
Also fix up the fboitem example to use a ShaderEffect that works with
both rendering paths.
With graphics APIs other than OpenGL the item will be empty, as QQuickFbo
is not something we can support there.
Task-number: QTBUG-79222
Change-Id: I52177d3a75f619f7075a2fc829573c17031eded1
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/items/qquickframebufferobject.cpp')
-rw-r--r-- | src/quick/items/qquickframebufferobject.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp index 190bc6853c..d5550e78b6 100644 --- a/src/quick/items/qquickframebufferobject.cpp +++ b/src/quick/items/qquickframebufferobject.cpp @@ -83,6 +83,11 @@ public: * Everything that relates to rendering must be located in the * QQuickFramebufferObject::Renderer class. * + * \warning This class is only functional when Qt Quick is rendering + * via OpenGL, either directly or through the \l{Scene Graph + * Adaptations}{RHI-based rendering path}. It is not compatible with + * other RHI backends, such as, Vulkan or Metal. + * * To avoid race conditions and read/write issues from two threads * it is important that the renderer and the item never read or * write shared variables. Communication between the item and the renderer @@ -109,10 +114,6 @@ public: * and can be used directly in \l {ShaderEffect}{ShaderEffects} and other * classes that consume texture providers. * - * \warning This class is only suitable when working directly with OpenGL. It - * is not compatible with the \l{Scene Graph Adaptations}{RHI-based rendering - * path}. - * * \sa {Scene Graph - Rendering FBOs}, {Scene Graph and Rendering} */ @@ -233,6 +234,13 @@ public Q_SLOTS: { if (renderPending) { renderPending = false; + + const bool needsWrap = QSGRendererInterface::isApiRhiBased(window->rendererInterface()->graphicsApi()); + if (needsWrap) { + window->beginExternalCommands(); + window->resetOpenGLState(); + } + fbo->bind(); QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo->width(), fbo->height()); renderer->render(); @@ -241,6 +249,9 @@ public Q_SLOTS: if (msDisplayFbo) QOpenGLFramebufferObject::blitFramebuffer(msDisplayFbo, fbo); + if (needsWrap) + window->endExternalCommands(); + markDirty(QSGNode::DirtyMaterial); emit textureChanged(); } @@ -270,7 +281,8 @@ public: static inline bool isOpenGL(QSGRenderContext *rc) { QSGRendererInterface *rif = rc->sceneGraphContext()->rendererInterface(rc); - return !rif || rif->graphicsApi() == QSGRendererInterface::OpenGL; + return rif && (rif->graphicsApi() == QSGRendererInterface::OpenGL + || rif->graphicsApi() == QSGRendererInterface::OpenGLRhi); } /*! @@ -335,9 +347,11 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode displayTexture = n->msDisplayFbo->texture(); } - n->setTexture(window()->createTextureFromId(displayTexture, - n->fbo->size(), - QQuickWindow::TextureHasAlphaChannel)); + QSGTexture *wrapper = window()->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture, + &displayTexture, 0, + n->fbo->size(), + QQuickWindow::TextureHasAlphaChannel); + n->setTexture(wrapper); } n->setTextureCoordinatesTransform(d->mirrorVertically ? QSGSimpleTextureNode::MirrorVertically : QSGSimpleTextureNode::NoTransform); |