Remove QSGEngine and move QSGAbstractRenderer back to private

QSGEngine goes away. Same for the associated example, which is the only
place this is used anywhere in Qt.

As a consequence, the renderer base class can be moved back to private:
there is no use for it to be public anymore, since that made sense only
in combination with QSGEngine. With the RHI-based rendering path driving
a renderer directly is more complicated than before so it is not
reasonable to allow the QSGEngine-style access anymore.

Instead, one has QQuickRenderControl, which allows redirecting and
manually driving the rendering of a QQuickWindow, thus providing an
alternative to the legacy QSGEngine approach.

Task-number: QTBUG-78596
Change-Id: If57c6b657b2053da1c4e545e517026382a71d998
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
Laszlo Agocs 2020-04-06 13:43:18 +02:00
parent 494063ccc8
commit 07d1dbcf7f
18 changed files with 93 additions and 1098 deletions

View File

@ -4,7 +4,6 @@ qtConfig(opengl(es1|es2)?) {
SUBDIRS += \
graph \
simplematerial \
sgengine \
fboitem \
openglunderqml \
textureinthread \

View File

@ -1,116 +0,0 @@
# Generated from sgengine.pro.
cmake_minimum_required(VERSION 3.14)
project(sgengine LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(INSTALL_EXAMPLEDIR "examples/quick/scenegraph/sgengine")
find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Quick)
add_qt_gui_executable(sgengine
main.cpp
window.cpp window.h
)
target_link_libraries(sgengine PUBLIC
Qt::Core
Qt::Gui
Qt::Quick
)
# Resources:
set(sgengine_resource_files
"face-smile.png"
)
qt6_add_resources(sgengine "sgengine"
PREFIX
"/scenegraph/sgengine"
FILES
${sgengine_resource_files}
)
set_source_files_properties("../../shared/Button.qml"
PROPERTIES QT_RESOURCE_ALIAS "Button.qml"
)
set_source_files_properties("../../shared/CheckBox.qml"
PROPERTIES QT_RESOURCE_ALIAS "CheckBox.qml"
)
set_source_files_properties("../../shared/FlickrRssModel.qml"
PROPERTIES QT_RESOURCE_ALIAS "FlickrRssModel.qml"
)
set_source_files_properties("../../shared/Label.qml"
PROPERTIES QT_RESOURCE_ALIAS "Label.qml"
)
set_source_files_properties("../../shared/LauncherList.qml"
PROPERTIES QT_RESOURCE_ALIAS "LauncherList.qml"
)
set_source_files_properties("../../shared/SimpleLauncherDelegate.qml"
PROPERTIES QT_RESOURCE_ALIAS "SimpleLauncherDelegate.qml"
)
set_source_files_properties("../../shared/Slider.qml"
PROPERTIES QT_RESOURCE_ALIAS "Slider.qml"
)
set_source_files_properties("../../shared/TabSet.qml"
PROPERTIES QT_RESOURCE_ALIAS "TabSet.qml"
)
set_source_files_properties("../../shared/TextField.qml"
PROPERTIES QT_RESOURCE_ALIAS "TextField.qml"
)
set_source_files_properties("../../shared/images/back.png"
PROPERTIES QT_RESOURCE_ALIAS "images/back.png"
)
set_source_files_properties("../../shared/images/checkmark.png"
PROPERTIES QT_RESOURCE_ALIAS "images/checkmark.png"
)
set_source_files_properties("../../shared/images/next.png"
PROPERTIES QT_RESOURCE_ALIAS "images/next.png"
)
set_source_files_properties("../../shared/images/qt-logo.png"
PROPERTIES QT_RESOURCE_ALIAS "images/qt-logo.png"
)
set_source_files_properties("../../shared/images/slider_handle.png"
PROPERTIES QT_RESOURCE_ALIAS "images/slider_handle.png"
)
set_source_files_properties("../../shared/images/tab.png"
PROPERTIES QT_RESOURCE_ALIAS "images/tab.png"
)
set(shared_resource_files
"Button.qml"
"CheckBox.qml"
"FlickrRssModel.qml"
"Label.qml"
"LauncherList.qml"
"SimpleLauncherDelegate.qml"
"Slider.qml"
"TabSet.qml"
"TextField.qml"
"images/back.png"
"images/checkmark.png"
"images/next.png"
"images/qt-logo.png"
"images/slider_handle.png"
"images/tab.png"
)
qt6_add_resources(sgengine "shared"
PREFIX
"/shared"
BASE
"../../shared"
FILES
${shared_resource_files}
)
install(TARGETS sgengine
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,62 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** 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.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "window.h"
#include <QGuiApplication>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}

View File

@ -1,11 +0,0 @@
QT += quick
HEADERS += window.h
SOURCES += window.cpp main.cpp
RESOURCES += \
sgengine.qrc \
../../shared/shared.qrc
# install
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/sgengine
INSTALLS += target

View File

@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/scenegraph/sgengine">
<file>face-smile.png</file>
</qresource>
</RCC>

View File

@ -1,254 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** 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.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "window.h"
#include <QOpenGLContext>
#include <QSGAbstractRenderer>
#include <QSGEngine>
#include <QSGSimpleTextureNode>
#include <QSGTransformNode>
#include <QScreen>
#include <QVariantAnimation>
#include <QOpenGLFunctions>
#include <QRandomGenerator>
class Item {
public:
Item(QSGNode *parentNode, QSGTexture *texture, const QPointF &fromPos, const QPointF &toPos) {
textureNode = new QSGSimpleTextureNode;
textureNode->setRect(QRect(QPoint(), texture->textureSize()));
textureNode->setTexture(texture);
transformNode = new QSGTransformNode;
transformNode->setFlag(QSGNode::OwnedByParent, false);
transformNode->appendChildNode(textureNode);
parentNode->appendChildNode(transformNode);
int duration = QRandomGenerator::global()->generateDouble() * 400 + 800;
rotAnimation.setStartValue(QRandomGenerator::global()->generateDouble() * 720 - 180);
rotAnimation.setEndValue(QRandomGenerator::global()->generateDouble() * 720 - 180);
rotAnimation.setDuration(duration);
rotAnimation.start();
posAnimation.setStartValue(fromPos);
posAnimation.setEndValue(toPos);
posAnimation.setDuration(duration);
posAnimation.start();
}
~Item() {
delete transformNode;
}
bool isDone() const { return posAnimation.state() != QAbstractAnimation::Running; }
void sync() {
QPointF currentPos = posAnimation.currentValue().toPointF();
QPointF center = textureNode->rect().center();
QMatrix4x4 m;
m.translate(currentPos.x(), currentPos.y());
m.translate(center.x(), center.y());
m.rotate(rotAnimation.currentValue().toFloat(), 0, 0, 1);
m.translate(-center.x(), -center.y());
transformNode->setMatrix(m);
}
private:
QSGTransformNode *transformNode;
QSGSimpleTextureNode *textureNode;
QVariantAnimation posAnimation;
QVariantAnimation rotAnimation;
};
Window::Window()
: m_initialized(false)
, m_context(new QOpenGLContext)
, m_sgEngine(new QSGEngine)
, m_sgRootNode(new QSGRootNode)
{
setSurfaceType(QWindow::OpenGLSurface);
QRect g(0, 0, 640, 480);
g.moveCenter(screen()->geometry().center());
setGeometry(g);
setTitle(QStringLiteral("Click me!"));
QSurfaceFormat format;
format.setDepthBufferSize(16);
setFormat(format);
m_context->setFormat(format);
m_context->create();
m_animationDriver.install();
connect(&m_animationDriver, &QAnimationDriver::started, this, &Window::update);
}
Window::~Window()
{
}
void Window::timerEvent(QTimerEvent *e)
{
if (e->timerId() == m_updateTimer.timerId()) {
m_updateTimer.stop();
if (!m_context->makeCurrent(this))
return;
if (!m_initialized)
initialize();
sync();
render();
if (m_animationDriver.isRunning()) {
m_animationDriver.advance();
update();
}
} else
QWindow::timerEvent(e);
}
void Window::exposeEvent(QExposeEvent *)
{
if (isExposed())
update();
else
invalidate();
}
void Window::mousePressEvent(QMouseEvent *)
{
addItems();
}
void Window::keyPressEvent(QKeyEvent *)
{
addItems();
}
void Window::addItems()
{
if (!m_initialized)
return;
QSGTexture *textures[] = { m_smileTexture.data(), m_qtTexture.data() };
for (int i = 0; i < 50; ++i) {
QSGTexture *tex = textures[i%2];
QPointF fromPos(-tex->textureSize().width(), QRandomGenerator::global()->generateDouble() * (height() - tex->textureSize().height()));
QPointF toPos(width(), QRandomGenerator::global()->generateDouble() * height() * 1.5 - height() * 0.25);
m_items.append(QSharedPointer<Item>::create(m_sgRootNode.data(), tex, fromPos, toPos));
}
update();
}
void Window::update()
{
if (!m_updateTimer.isActive())
m_updateTimer.start(0, this);
}
void Window::sync()
{
QList<QSharedPointer<Item> > validItems;
for (QSharedPointer<Item> item : qAsConst(m_items)) {
if (!item->isDone()) {
validItems.append(item);
item->sync();
}
}
m_items.swap(validItems);
}
void Window::render()
{
m_sgRenderer->setDeviceRect(size());
m_sgRenderer->setViewportRect(size());
m_sgRenderer->setProjectionMatrixToRect(QRectF(QPointF(), size()));
m_sgRenderer->renderScene();
m_context->swapBuffers(this);
}
void Window::initialize()
{
m_sgEngine->initialize(m_context.data());
m_sgRenderer.reset(m_sgEngine->createRenderer());
m_sgRenderer->setRootNode(m_sgRootNode.data());
m_sgRenderer->setClearColor(QColor(32, 32, 32));
// With QSGEngine::createTextureFromId
QOpenGLFunctions glFuncs(m_context.data());
GLuint glTexture;
glFuncs.glGenTextures(1, &glTexture);
glFuncs.glBindTexture(GL_TEXTURE_2D, glTexture);
QImage smile = QImage(":/scenegraph/sgengine/face-smile.png").scaled(48, 48, Qt::KeepAspectRatio, Qt::SmoothTransformation);
smile = smile.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
Q_ASSERT(!smile.isNull());
glFuncs.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, smile.width(), smile.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, smile.constBits());
m_smileTexture.reset(m_sgEngine->createTextureFromId(glTexture, smile.size(), QFlag(QSGEngine::TextureOwnsGLTexture | QSGEngine::TextureHasAlphaChannel)));
// With QSGEngine::createTextureFromImage
QImage qtLogo = QImage(":/shared/images/qt-logo.png").scaled(48, 48, Qt::KeepAspectRatio, Qt::SmoothTransformation);
Q_ASSERT(!qtLogo.isNull());
m_qtTexture.reset(m_sgEngine->createTextureFromImage(qtLogo));
m_initialized = true;
}
void Window::invalidate()
{
m_updateTimer.stop();
m_items.clear();
m_smileTexture.reset();
m_qtTexture.reset();
m_sgRenderer.reset();
m_sgEngine->invalidate();
m_initialized = false;
}

View File

@ -1,95 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** 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.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QWindow>
#include <QAnimationDriver>
#include <QBasicTimer>
#include <QSharedPointer>
class Item;
QT_FORWARD_DECLARE_CLASS(QSGAbstractRenderer)
QT_FORWARD_DECLARE_CLASS(QSGEngine)
QT_FORWARD_DECLARE_CLASS(QSGRootNode)
QT_FORWARD_DECLARE_CLASS(QSGTexture)
class Window : public QWindow
{
Q_OBJECT
public:
Window();
~Window();
void addItems();
void update();
private:
void timerEvent(QTimerEvent *);
void exposeEvent(QExposeEvent *);
void mousePressEvent(QMouseEvent *);
void keyPressEvent(QKeyEvent *);
void sync();
void render();
void initialize();
void invalidate();
bool m_initialized;
QScopedPointer<QOpenGLContext> m_context;
QScopedPointer<QSGEngine> m_sgEngine;
QScopedPointer<QSGRootNode> m_sgRootNode;
QScopedPointer<QSGAbstractRenderer> m_sgRenderer;
QScopedPointer<QSGTexture> m_smileTexture;
QScopedPointer<QSGTexture> m_qtTexture;
QList<QSharedPointer<Item> > m_items;
QBasicTimer m_updateTimer;
QAnimationDriver m_animationDriver;
};

View File

@ -37,26 +37,16 @@
**
****************************************************************************/
#include "qsgabstractrenderer_p.h"
#include "qsgabstractrenderer_p_p.h"
QT_BEGIN_NAMESPACE
/*!
\class QSGAbstractRenderer
\brief QSGAbstractRenderer gives access to the scene graph nodes and rendering of a QSGEngine.
\brief QSGAbstractRenderer gives access to the scene graph nodes and rendering.
\inmodule QtQuick
\since 5.4
A QSGAbstractRenderer created by a QSGEngine allows you to set your QSGNode
tree through setRootNode() and control the rendering viewport through
setDeviceRect(), setViewportRect() and setProjectionMatrixToRect().
You can finally trigger the rendering to the desired framebuffer through
renderScene().
The QSGAbstractRenderer is only available when used with a QSGEngine
and isn't exposed when used internally by QQuickWindow.
\sa QSGEngine, QSGNode
\internal
*/
/*!
@ -387,5 +377,3 @@ QSGAbstractRenderer::ClearMode QSGAbstractRenderer::clearMode() const
*/
QT_END_NAMESPACE
#include "moc_qsgabstractrenderer.cpp"

View File

@ -1,116 +0,0 @@
/****************************************************************************
**
** 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$
**
****************************************************************************/
#ifndef QSGABSTRACTRENDERER_H
#define QSGABSTRACTRENDERER_H
#include <QtQuick/qsgnode.h>
#ifndef GLuint
#define GLuint uint
#endif
QT_BEGIN_NAMESPACE
class QSGAbstractRendererPrivate;
class Q_QUICK_EXPORT QSGAbstractRenderer : public QObject
{
Q_OBJECT
public:
enum ClearModeBit
{
ClearColorBuffer = 0x0001,
ClearDepthBuffer = 0x0002,
ClearStencilBuffer = 0x0004
};
Q_DECLARE_FLAGS(ClearMode, ClearModeBit)
Q_FLAG(ClearMode)
enum MatrixTransformFlag
{
MatrixTransformFlipY = 0x01
};
Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)
Q_FLAG(MatrixTransformFlags)
~QSGAbstractRenderer() override;
void setRootNode(QSGRootNode *node);
QSGRootNode *rootNode() const;
void setDeviceRect(const QRect &rect);
inline void setDeviceRect(const QSize &size) { setDeviceRect(QRect(QPoint(), size)); }
QRect deviceRect() const;
void setViewportRect(const QRect &rect);
inline void setViewportRect(const QSize &size) { setViewportRect(QRect(QPoint(), size)); }
QRect viewportRect() const;
void setProjectionMatrixToRect(const QRectF &rect);
void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags);
void setProjectionMatrix(const QMatrix4x4 &matrix);
void setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix);
QMatrix4x4 projectionMatrix() const;
QMatrix4x4 projectionMatrixWithNativeNDC() const;
void setClearColor(const QColor &color);
QColor clearColor() const;
void setClearMode(ClearMode mode);
ClearMode clearMode() const;
virtual void renderScene(GLuint fboId = 0) = 0;
Q_SIGNALS:
void sceneGraphChanged();
protected:
explicit QSGAbstractRenderer(QObject *parent = nullptr);
virtual void nodeChanged(QSGNode *node, QSGNode::DirtyState state) = 0;
private:
Q_DECLARE_PRIVATE(QSGAbstractRenderer)
friend class QSGRootNode;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSGAbstractRenderer::ClearMode)
QT_END_NAMESPACE
#endif

View File

@ -51,37 +51,78 @@
// We mean it.
//
#include "qsgabstractrenderer.h"
#include "qsgnode.h"
#include <qcolor.h>
#include <QtCore/private/qobject_p.h>
#include <QtQuick/private/qtquickglobal_p.h>
#include <QtQuick/qsgnode.h>
#ifndef GLuint
#define GLuint uint
#endif
QT_BEGIN_NAMESPACE
class Q_QUICK_PRIVATE_EXPORT QSGAbstractRendererPrivate : public QObjectPrivate
class QSGAbstractRendererPrivate;
class Q_QUICK_PRIVATE_EXPORT QSGAbstractRenderer : public QObject
{
Q_DECLARE_PUBLIC(QSGAbstractRenderer)
Q_OBJECT
public:
static const QSGAbstractRendererPrivate *get(const QSGAbstractRenderer *q) { return q->d_func(); }
enum ClearModeBit
{
ClearColorBuffer = 0x0001,
ClearDepthBuffer = 0x0002,
ClearStencilBuffer = 0x0004
};
Q_DECLARE_FLAGS(ClearMode, ClearModeBit)
Q_FLAG(ClearMode)
QSGAbstractRendererPrivate();
void updateProjectionMatrix();
enum MatrixTransformFlag
{
MatrixTransformFlipY = 0x01
};
Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)
Q_FLAG(MatrixTransformFlags)
QSGRootNode *m_root_node;
QColor m_clear_color;
QSGAbstractRenderer::ClearMode m_clear_mode;
~QSGAbstractRenderer() override;
QRect m_device_rect;
QRect m_viewport_rect;
void setRootNode(QSGRootNode *node);
QSGRootNode *rootNode() const;
void setDeviceRect(const QRect &rect);
inline void setDeviceRect(const QSize &size) { setDeviceRect(QRect(QPoint(), size)); }
QRect deviceRect() const;
QMatrix4x4 m_projection_matrix;
QMatrix4x4 m_projection_matrix_native_ndc;
uint m_mirrored : 1;
void setViewportRect(const QRect &rect);
inline void setViewportRect(const QSize &size) { setViewportRect(QRect(QPoint(), size)); }
QRect viewportRect() const;
void setProjectionMatrixToRect(const QRectF &rect);
void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags);
void setProjectionMatrix(const QMatrix4x4 &matrix);
void setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix);
QMatrix4x4 projectionMatrix() const;
QMatrix4x4 projectionMatrixWithNativeNDC() const;
void setClearColor(const QColor &color);
QColor clearColor() const;
void setClearMode(ClearMode mode);
ClearMode clearMode() const;
virtual void renderScene(GLuint fboId = 0) = 0;
Q_SIGNALS:
void sceneGraphChanged();
protected:
explicit QSGAbstractRenderer(QObject *parent = nullptr);
virtual void nodeChanged(QSGNode *node, QSGNode::DirtyState state) = 0;
private:
Q_DECLARE_PRIVATE(QSGAbstractRenderer)
friend class QSGRootNode;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSGAbstractRenderer::ClearMode)
QT_END_NAMESPACE
#endif

View File

@ -37,8 +37,8 @@
**
****************************************************************************/
#ifndef QSGENGINE_P_H
#define QSGENGINE_P_H
#ifndef QSGABSTRACTRENDERER_P_P_H
#define QSGABSTRACTRENDERER_P_P_H
//
// W A R N I N G
@ -51,25 +51,37 @@
// We mean it.
//
#include "qsgengine.h"
#include <private/qobject_p.h>
#include "qsgabstractrenderer_p.h"
#include "qsgnode.h"
#include <qcolor.h>
#include <QtCore/private/qobject_p.h>
#include <QtQuick/private/qtquickglobal_p.h>
QT_BEGIN_NAMESPACE
class QSGContext;
class QSGRenderContext;
class QSGEnginePrivate : public QObjectPrivate
class Q_QUICK_PRIVATE_EXPORT QSGAbstractRendererPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QSGEngine)
Q_DECLARE_PUBLIC(QSGAbstractRenderer)
public:
static QSGEnginePrivate *get(QSGEngine *engine) { return engine->d_func(); }
QSGEnginePrivate();
static const QSGAbstractRendererPrivate *get(const QSGAbstractRenderer *q) { return q->d_func(); }
QScopedPointer<QSGContext> sgContext;
QScopedPointer<QSGRenderContext> sgRenderContext;
QSGAbstractRendererPrivate();
void updateProjectionMatrix();
QSGRootNode *m_root_node;
QColor m_clear_color;
QSGAbstractRenderer::ClearMode m_clear_mode;
QRect m_device_rect;
QRect m_viewport_rect;
QMatrix4x4 m_projection_matrix;
QMatrix4x4 m_projection_matrix_native_ndc;
uint m_mirrored : 1;
};
QT_END_NAMESPACE
#endif // QSGENGINE_P_H
#endif

View File

@ -51,8 +51,7 @@
// We mean it.
//
#include "qsgabstractrenderer.h"
#include "qsgabstractrenderer_p.h"
#include "qsgabstractrenderer_p_p.h"
#include "qsgnode.h"
#include "qsgmaterial.h"

View File

@ -12,8 +12,8 @@ HEADERS += \
$$PWD/coreapi/qsgnode.h \
$$PWD/coreapi/qsgnode_p.h \
$$PWD/coreapi/qsgnodeupdater_p.h \
$$PWD/coreapi/qsgabstractrenderer.h \
$$PWD/coreapi/qsgabstractrenderer_p.h \
$$PWD/coreapi/qsgabstractrenderer_p_p.h \
$$PWD/coreapi/qsgrenderer_p.h \
$$PWD/coreapi/qsgrendernode.h \
$$PWD/coreapi/qsgrendernode_p.h \
@ -50,8 +50,6 @@ qtConfig(opengl(es1|es2)?) {
# Util API
HEADERS += \
$$PWD/util/qsgareaallocator_p.h \
$$PWD/util/qsgengine.h \
$$PWD/util/qsgengine_p.h \
$$PWD/util/qsgplaintexture_p.h \
$$PWD/util/qsgsimplerectnode.h \
$$PWD/util/qsgsimpletexturenode.h \
@ -67,7 +65,6 @@ HEADERS += \
SOURCES += \
$$PWD/util/qsgareaallocator.cpp \
$$PWD/util/qsgengine.cpp \
$$PWD/util/qsgplaintexture.cpp \
$$PWD/util/qsgsimplerectnode.cpp \
$$PWD/util/qsgsimpletexturenode.cpp \

View File

@ -1,290 +0,0 @@
/****************************************************************************
**
** 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$
**
****************************************************************************/
#include "qsgengine_p.h"
#include <QtQuick/qsgtexture.h>
#include <private/qsgcontext_p.h>
#include <private/qsgrenderer_p.h>
#include <private/qsgplaintexture_p.h>
#if QT_CONFIG(opengl)
# include <QOpenGLContext>
# include <private/qsgdefaultrendercontext_p.h>
#endif
QT_BEGIN_NAMESPACE
/*!
\class QSGEngine
\brief The QSGEngine class allows low level rendering of a scene graph.
\inmodule QtQuick
\since 5.4
A QSGEngine can be used to render a tree of QSGNode directly on a QWindow
or QOpenGLFramebufferObject without any integration with QML, QQuickWindow
or QQuickItem and the convenience that they provide.
This means that you must handle event propagation, animation timing,
and node lifetime yourself.
\note This class is for very low level access to an independent scene graph.
Most of the time you will instead want to subclass QQuickItem and insert
your QSGNode in a normal QtQuick scene by overriding QQuickItem::updatePaintNode().
\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 QSGAbstractRenderer
*/
/*!
\enum QSGEngine::CreateTextureOption
The CreateTextureOption enums are used to customize how a texture is wrapped.
\value TextureHasAlphaChannel The texture has an alpha channel and should
be drawn using blending.
\value TextureOwnsGLTexture The texture object owns the texture id and
will delete the GL texture when the texture object is deleted.
\value TextureCanUseAtlas The image can be uploaded into a texture atlas.
\value TextureIsOpaque The texture object is opaque.
*/
QSGEnginePrivate::QSGEnginePrivate()
: sgContext(QSGContext::createDefaultContext())
, sgRenderContext(sgContext.data()->createRenderContext())
{
}
/*!
Constructs a new QSGEngine with its \a parent
*/
QSGEngine::QSGEngine(QObject *parent)
: QObject(*(new QSGEnginePrivate), parent)
{
}
/*!
Destroys the engine
*/
QSGEngine::~QSGEngine()
{
}
/*!
Initialize the engine with \a context.
\warning You have to make sure that you call
QOpenGLContext::makeCurrent() on \a context before calling this.
*/
void QSGEngine::initialize(QOpenGLContext *context)
{
Q_D(QSGEngine);
#if QT_CONFIG(opengl)
if (context && QOpenGLContext::currentContext() != context) {
qWarning("WARNING: The context must be current before calling QSGEngine::initialize.");
return;
}
#endif
if (d->sgRenderContext && !d->sgRenderContext->isValid()) {
d->sgRenderContext->setAttachToGraphicsContext(false);
#if QT_CONFIG(opengl)
QSGDefaultRenderContext *rc = qobject_cast<QSGDefaultRenderContext *>(d->sgRenderContext.data());
if (rc) {
QSGDefaultRenderContext::InitParams params;
params.sampleCount = qMax(1, context->format().samples());
params.openGLContext = context;
// leave the size hint and surface unset, we do not know, that's fine
rc->initialize(&params);
} else {
d->sgRenderContext->initialize(nullptr);
}
#else
d->sgRenderContext->initialize(nullptr);
#endif
#if QT_CONFIG(opengl)
if (context)
connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate);
#endif
}
#if !QT_CONFIG(opengl)
Q_UNUSED(context);
#endif
}
/*!
Invalidate the engine releasing its resources
You will have to call initialize() and createRenderer() if you
want to use it again.
*/
void QSGEngine::invalidate()
{
Q_D(QSGEngine);
d->sgRenderContext->invalidate();
}
/*!
Returns a renderer that can be used to render a QSGNode tree
You call initialize() first with the QOpenGLContext that you
want to use with this renderer. This will return a null
renderer otherwise.
*/
QSGAbstractRenderer *QSGEngine::createRenderer() const
{
Q_D(const QSGEngine);
if (!d->sgRenderContext->isValid())
return nullptr;
QSGRenderer *renderer = d->sgRenderContext->createRenderer();
renderer->setCustomRenderMode(qgetenv("QSG_VISUALIZE"));
return renderer;
}
/*!
Creates a texture using the data of \a image
Valid \a options are TextureCanUseAtlas and TextureIsOpaque.
The caller takes ownership of the texture and the
texture should only be used with this engine.
\sa createTextureFromId(), QSGSimpleTextureNode::setOwnsTexture(), QQuickWindow::createTextureFromImage()
*/
QSGTexture *QSGEngine::createTextureFromImage(const QImage &image, CreateTextureOptions options) const
{
Q_D(const QSGEngine);
if (!d->sgRenderContext->isValid())
return nullptr;
uint flags = 0;
if (options & TextureCanUseAtlas) flags |= QSGRenderContext::CreateTexture_Atlas;
if (!(options & TextureIsOpaque)) flags |= QSGRenderContext::CreateTexture_Alpha;
return d->sgRenderContext->createTexture(image, flags);
}
/*!
Creates a texture object that wraps the GL texture \a id uploaded with \a size
Valid \a options are TextureHasAlphaChannel and TextureOwnsGLTexture
The caller takes ownership of the texture object and the
texture should only be used with this engine.
\sa createTextureFromImage(), QSGSimpleTextureNode::setOwnsTexture(), QQuickWindow::createTextureFromId()
*/
QSGTexture *QSGEngine::createTextureFromId(uint id, const QSize &size, CreateTextureOptions options) const
{
Q_D(const QSGEngine);
if (d->sgRenderContext->isValid()) {
QSGPlainTexture *texture = new QSGPlainTexture();
texture->setTextureId(id);
texture->setHasAlphaChannel(options & TextureHasAlphaChannel);
texture->setOwnsTexture(options & TextureOwnsGLTexture);
texture->setTextureSize(size);
return texture;
}
return nullptr;
}
/*!
Returns the current renderer interface if there is one. Otherwise null is returned.
\sa QSGRenderNode, QSGRendererInterface
\since 5.8
*/
QSGRendererInterface *QSGEngine::rendererInterface() const
{
Q_D(const QSGEngine);
return d->sgRenderContext->isValid()
? d->sgRenderContext->sceneGraphContext()->rendererInterface(d->sgRenderContext.data())
: nullptr;
}
/*!
Creates a simple rectangle node. When the scenegraph is not initialized, the return value is null.
This is cross-backend alternative to constructing a QSGSimpleRectNode directly.
\since 5.8
\sa QSGRectangleNode
*/
QSGRectangleNode *QSGEngine::createRectangleNode() const
{
Q_D(const QSGEngine);
return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createRectangleNode() : nullptr;
}
/*!
Creates a simple image node. When the scenegraph is not initialized, the return value is null.
This is cross-backend alternative to constructing a QSGSimpleTextureNode directly.
\since 5.8
\sa QSGImageNode
*/
QSGImageNode *QSGEngine::createImageNode() const
{
Q_D(const QSGEngine);
return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createImageNode() : nullptr;
}
/*!
Creates a nine patch node. When the scenegraph is not initialized, the return value is null.
\since 5.8
*/
QSGNinePatchNode *QSGEngine::createNinePatchNode() const
{
Q_D(const QSGEngine);
return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createNinePatchNode() : nullptr;
}
QT_END_NAMESPACE
#include "moc_qsgengine.cpp"

View File

@ -1,90 +0,0 @@
/****************************************************************************
**
** 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$
**
****************************************************************************/
#ifndef QSGENGINE_H
#define QSGENGINE_H
#include <QtCore/QObject>
#include <QtQuick/qtquickglobal.h>
QT_BEGIN_NAMESPACE
class QOpenGLContext;
class QSGAbstractRenderer;
class QSGEnginePrivate;
class QSGTexture;
class QSGRendererInterface;
class QSGRectangleNode;
class QSGImageNode;
class QSGNinePatchNode;
// ### Qt 6: Remove or redesign.
class Q_QUICK_EXPORT QSGEngine : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QSGEngine)
public:
enum CreateTextureOption {
TextureHasAlphaChannel = 0x0001,
TextureOwnsGLTexture = 0x0004,
TextureCanUseAtlas = 0x0008,
TextureIsOpaque = 0x0010
};
Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)
Q_FLAG(CreateTextureOptions)
explicit QSGEngine(QObject *parent = nullptr);
~QSGEngine() override;
void initialize(QOpenGLContext *context);
void invalidate();
QSGAbstractRenderer *createRenderer() const;
QSGTexture *createTextureFromImage(const QImage &image, CreateTextureOptions options = CreateTextureOption()) const;
QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption()) const;
QSGRendererInterface *rendererInterface() const;
QSGRectangleNode *createRectangleNode() const;
QSGImageNode *createImageNode() const;
QSGNinePatchNode *createNinePatchNode() const;
};
QT_END_NAMESPACE
#endif // QSGENGINE_H

View File

@ -51,8 +51,7 @@ QT_BEGIN_NAMESPACE
\warning This utility class is only functional when running with the default
or software backends of the Qt Quick scenegraph. As an alternative, prefer
using QSGRectangleNode via QQuickWindow::createRectangleNode() or
QSGEngine::createRectangleNode().
using QSGRectangleNode via QQuickWindow::createRectangleNode().
\deprecated
*/

View File

@ -99,8 +99,7 @@ static void qsgsimpletexturenode_update(QSGGeometry *g,
\warning This utility class is only functional when running with the default
or software backends of the Qt Quick scenegraph. As an alternative, prefer
using QSGImageNode via QQuickWindow::createImageNode() or
QSGEngine::createImageNode().
using QSGImageNode via QQuickWindow::createImageNode().
\deprecated
*/