aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickframebufferobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickframebufferobject.cpp')
-rw-r--r--src/quick/items/qquickframebufferobject.cpp85
1 files changed, 30 insertions, 55 deletions
diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp
index 190bc6853c..cdae6fbec7 100644
--- a/src/quick/items/qquickframebufferobject.cpp
+++ b/src/quick/items/qquickframebufferobject.cpp
@@ -1,52 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickframebufferobject.h"
-#include <QtGui/QOpenGLFramebufferObject>
-#include <QtGui/QOpenGLFunctions>
+#include <QOpenGLFramebufferObject>
+#include <QOpenGLFunctions>
#include <private/qquickitem_p.h>
#include <private/qsgadaptationlayer_p.h>
#include <qsgtextureprovider.h>
+#include <rhi/qrhi.h>
#include <QSGSimpleTextureNode>
#include <QSGRendererInterface>
+#include <QQuickOpenGLUtils>
QT_BEGIN_NAMESPACE
@@ -75,6 +41,12 @@ public:
* for integrating OpenGL rendering using a framebuffer object (FBO)
* with Qt Quick.
*
+ * \warning This class is only functional when Qt Quick is rendering via
+ * OpenGL. It is not compatible with other graphics APIs, such as Vulkan or
+ * Metal. It should be treated as a legacy class that is only present in order
+ * to enable Qt 5 applications to function without source compatibility breaks
+ * as long as they tie themselves to OpenGL.
+ *
* On most platforms, the rendering will occur on a \l {Scene Graph and Rendering}{dedicated thread}.
* For this reason, the QQuickFramebufferObject class enforces a strict
* separation between the item implementation and the FBO rendering. All
@@ -109,11 +81,7 @@ 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}
+ * \sa {Scene Graph and Rendering}
*/
/*!
@@ -183,9 +151,9 @@ bool QQuickFramebufferObject::mirrorVertically() const
/*!
* \internal
*/
-void QQuickFramebufferObject::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+void QQuickFramebufferObject::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
{
- QQuickItem::geometryChanged(newGeometry, oldGeometry);
+ QQuickItem::geometryChange(newGeometry, oldGeometry);
Q_D(QQuickFramebufferObject);
if (newGeometry.size() != oldGeometry.size() && d->followsItemSize)
@@ -233,6 +201,10 @@ public Q_SLOTS:
{
if (renderPending) {
renderPending = false;
+
+ window->beginExternalCommands();
+ QQuickOpenGLUtils::resetOpenGLState();
+
fbo->bind();
QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo->width(), fbo->height());
renderer->render();
@@ -241,6 +213,8 @@ public Q_SLOTS:
if (msDisplayFbo)
QOpenGLFramebufferObject::blitFramebuffer(msDisplayFbo, fbo);
+ window->endExternalCommands();
+
markDirty(QSGNode::DirtyMaterial);
emit textureChanged();
}
@@ -270,7 +244,7 @@ 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;
}
/*!
@@ -335,9 +309,11 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode
displayTexture = n->msDisplayFbo->texture();
}
- n->setTexture(window()->createTextureFromId(displayTexture,
- n->fbo->size(),
- QQuickWindow::TextureHasAlphaChannel));
+ QSGTexture *wrapper = QNativeInterface::QSGOpenGLTexture::fromNative(displayTexture,
+ window(),
+ n->fbo->size(),
+ QQuickWindow::TextureHasAlphaChannel);
+ n->setTexture(wrapper);
}
n->setTextureCoordinatesTransform(d->mirrorVertically ? QSGSimpleTextureNode::MirrorVertically : QSGSimpleTextureNode::NoTransform);
@@ -370,7 +346,7 @@ QSGTextureProvider *QQuickFramebufferObject::textureProvider() const
Q_D(const QQuickFramebufferObject);
QQuickWindow *w = window();
- if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) {
+ if (!w || !w->isSceneGraphInitialized() || QThread::currentThread() != QQuickWindowPrivate::get(w)->context->thread()) {
qWarning("QQuickFramebufferObject::textureProvider: can only be queried on the rendering thread of an exposed window");
return nullptr;
}
@@ -461,7 +437,7 @@ QOpenGLFramebufferObject *QQuickFramebufferObject::Renderer::framebufferObject()
* context. This means that the state might have been modified by Quick before
* invoking this function.
*
- * \note It is recommended to call QQuickWindow::resetOpenGLState() before
+ * \note It is recommended to call QQuickOpenGLUtils::resetOpenGLState() before
* returning. This resets OpenGL state used by the Qt Quick renderer and thus
* avoids interference from the state changes made by the rendering code in this
* function.
@@ -537,8 +513,7 @@ void QQuickFramebufferObject::Renderer::update()
((QSGFramebufferObjectNode *) data)->scheduleRender();
}
+QT_END_NAMESPACE
#include "qquickframebufferobject.moc"
#include "moc_qquickframebufferobject.cpp"
-
-QT_END_NAMESPACE