aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/scenegraph
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick/scenegraph')
-rw-r--r--examples/quick/scenegraph/customgeometry/beziercurve.h2
-rw-r--r--examples/quick/scenegraph/customgeometry/customgeometry.pro4
-rw-r--r--examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc15
-rw-r--r--examples/quick/scenegraph/customgeometry/main.cpp2
-rw-r--r--examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro4
-rw-r--r--examples/quick/scenegraph/d3d11underqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/fboitem/fboitem.pro4
-rw-r--r--examples/quick/scenegraph/fboitem/main.cpp2
-rw-r--r--examples/quick/scenegraph/graph/graph.pro4
-rw-r--r--examples/quick/scenegraph/graph/main.cpp2
-rw-r--r--examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc2
-rw-r--r--examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro5
-rw-r--r--examples/quick/scenegraph/metalunderqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/metalunderqml/metalsquircle.mm5
-rw-r--r--examples/quick/scenegraph/metalunderqml/metalunderqml.pro9
-rw-r--r--examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc5
-rw-r--r--examples/quick/scenegraph/openglunderqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/openglunderqml/openglunderqml.pro4
-rw-r--r--examples/quick/scenegraph/rendernode/customrenderitem.cpp11
-rw-r--r--examples/quick/scenegraph/rendernode/customrenderitem.h2
-rw-r--r--examples/quick/scenegraph/rendernode/d3d12renderer.cpp309
-rw-r--r--examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc2
-rw-r--r--examples/quick/scenegraph/rendernode/main.cpp4
-rw-r--r--examples/quick/scenegraph/rendernode/main.qml1
-rw-r--r--examples/quick/scenegraph/rendernode/rendernode.pro10
-rw-r--r--examples/quick/scenegraph/rendernode/rendernode.qrc2
-rw-r--r--examples/quick/scenegraph/rendernode/shader_frag.csobin908 -> 0 bytes
-rw-r--r--examples/quick/scenegraph/rendernode/shader_vert.csobin1720 -> 0 bytes
-rw-r--r--examples/quick/scenegraph/rendernode/softwarerenderer.cpp2
-rw-r--r--examples/quick/scenegraph/scenegraph.pro6
-rw-r--r--examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc26
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerial.cpp154
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerial.pro10
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerialitem.cpp169
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerialitem.h82
-rw-r--r--examples/quick/scenegraph/textureinthread/main.cpp1
-rw-r--r--examples/quick/scenegraph/textureinthread/textureinthread.pro4
-rw-r--r--examples/quick/scenegraph/threadedanimation/main.cpp2
-rw-r--r--examples/quick/scenegraph/threadedanimation/threadedanimation.pro4
-rw-r--r--examples/quick/scenegraph/twotextureproviders/main.cpp2
-rw-r--r--examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro4
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpgbin0 -> 28887 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc48
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/main.cpp70
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/main.qml123
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/squircle.frag.spvbin0 -> 1432 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/squircle.vert.spvbin0 -> 644 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp823
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h (renamed from examples/quick/scenegraph/rendernode/d3d12renderer.h)63
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro12
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc7
51 files changed, 1460 insertions, 568 deletions
diff --git a/examples/quick/scenegraph/customgeometry/beziercurve.h b/examples/quick/scenegraph/customgeometry/beziercurve.h
index be9e4ef49f..fd0085a08e 100644
--- a/examples/quick/scenegraph/customgeometry/beziercurve.h
+++ b/examples/quick/scenegraph/customgeometry/beziercurve.h
@@ -64,7 +64,9 @@ class BezierCurve : public QQuickItem
Q_PROPERTY(QPointF p4 READ p4 WRITE setP4 NOTIFY p4Changed)
Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged)
+//! [3]
QML_ELEMENT
+//! [3]
public:
BezierCurve(QQuickItem *parent = 0);
diff --git a/examples/quick/scenegraph/customgeometry/customgeometry.pro b/examples/quick/scenegraph/customgeometry/customgeometry.pro
index 17c30fc560..3785f88c7e 100644
--- a/examples/quick/scenegraph/customgeometry/customgeometry.pro
+++ b/examples/quick/scenegraph/customgeometry/customgeometry.pro
@@ -1,6 +1,10 @@
TARGET = customgeometry
QT += quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = CustomGeometry
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += \
main.cpp \
beziercurve.cpp
diff --git a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
index 959114b424..bd235e5dfb 100644
--- a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
+++ b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
@@ -169,11 +169,16 @@
\snippet scenegraph/customgeometry/main.cpp 1
The application is a straightforward QML application, with a
- QGuiApplication and a QQuickView that we pass a .qml file. To make
- use of the BezierCurve item, we need to register it in the QML
- engine, using the qmlRegisterType() function. We give it the name
- BezierCurve and make it part of the \c {CustomGeometry 1.0}
- module.
+ QGuiApplication and a QQuickView that we pass a .qml file.
+
+ \snippet scenegraph/customgeometry/beziercurve.h 3
+
+ To make use of the BezierCurve item, we need to register it in the QML
+ engine, using the QML_ELEMENT macro. This gives it the name
+ BezierCurve and makes it part of the \c {CustomGeometry 1.0}
+ module as defined in the customgeometry.pro file:
+
+ \quotefile scenegraph/customgeometry/customgeometry.pro
As the bezier curve is drawn using GL_LINE_STRIP, we specify that
the view should be multisampled to get antialiasing. This is not
diff --git a/examples/quick/scenegraph/customgeometry/main.cpp b/examples/quick/scenegraph/customgeometry/main.cpp
index 9352e4bd24..15310d279f 100644
--- a/examples/quick/scenegraph/customgeometry/main.cpp
+++ b/examples/quick/scenegraph/customgeometry/main.cpp
@@ -58,8 +58,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<BezierCurve>("CustomGeometry", 1);
-
QQuickView view;
QSurfaceFormat format = view.format();
format.setSamples(16);
diff --git a/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro b/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro
index 7658a9a813..4f052cf388 100644
--- a/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro
+++ b/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro
@@ -2,6 +2,10 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = D3D11UnderQML
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += d3d11squircle.h
SOURCES += d3d11squircle.cpp main.cpp
RESOURCES += d3d11underqml.qrc
diff --git a/examples/quick/scenegraph/d3d11underqml/main.cpp b/examples/quick/scenegraph/d3d11underqml/main.cpp
index dcab8c879c..bcefae6cb5 100644
--- a/examples/quick/scenegraph/d3d11underqml/main.cpp
+++ b/examples/quick/scenegraph/d3d11underqml/main.cpp
@@ -56,8 +56,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<D3D11Squircle>("D3D11UnderQML", 1);
-
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi);
QQuickView view;
diff --git a/examples/quick/scenegraph/fboitem/fboitem.pro b/examples/quick/scenegraph/fboitem/fboitem.pro
index e40e5f4cf8..180c2288e2 100644
--- a/examples/quick/scenegraph/fboitem/fboitem.pro
+++ b/examples/quick/scenegraph/fboitem/fboitem.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += fboinsgrenderer.h
SOURCES += fboinsgrenderer.cpp main.cpp
diff --git a/examples/quick/scenegraph/fboitem/main.cpp b/examples/quick/scenegraph/fboitem/main.cpp
index 056bf24ade..153bd931ec 100644
--- a/examples/quick/scenegraph/fboitem/main.cpp
+++ b/examples/quick/scenegraph/fboitem/main.cpp
@@ -58,8 +58,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<FboInSGRenderer>("SceneGraphRendering", 1);
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/fboitem/main.qml"));
diff --git a/examples/quick/scenegraph/graph/graph.pro b/examples/quick/scenegraph/graph/graph.pro
index 1a880b61f1..fe36585d77 100644
--- a/examples/quick/scenegraph/graph/graph.pro
+++ b/examples/quick/scenegraph/graph/graph.pro
@@ -4,6 +4,10 @@ TARGET = graph
TEMPLATE = app
+CONFIG += qmltypes
+QML_IMPORT_NAME = Graph
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += main.cpp \
graph.cpp \
noisynode.cpp \
diff --git a/examples/quick/scenegraph/graph/main.cpp b/examples/quick/scenegraph/graph/main.cpp
index 9a575944b9..854fad84e3 100644
--- a/examples/quick/scenegraph/graph/main.cpp
+++ b/examples/quick/scenegraph/graph/main.cpp
@@ -58,8 +58,6 @@ int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
- qmlRegisterTypesAndRevisions<Graph>("Graph", 1);
-
QQuickView view;
view.resize(800, 400);
view.setResizeMode(QQuickView::SizeRootObjectToView);
diff --git a/examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc b/examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc
index 2a584c26cc..55cbcd8f2e 100644
--- a/examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc
+++ b/examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc
@@ -29,7 +29,7 @@
\example scenegraph/metaltextureimport
\title Scene Graph - Metal Texture Import
\ingroup qtquickexamples
- \brief Shows how to use a texture created directly with Metal
+ \brief Shows how to use a texture created directly with Metal.
\image metaltextureimport-example.jpg
diff --git a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
index 5b11606946..bbdfd358d3 100644
--- a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
+++ b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
@@ -1,4 +1,4 @@
-!macos: error("This example requires macOS")
+!macos:!ios: error("This example requires macOS or iOS")
QT += qml quick
@@ -6,7 +6,8 @@ HEADERS += metaltextureimport.h
SOURCES += metaltextureimport.mm main.cpp
RESOURCES += metaltextureimport.qrc
-LIBS += -framework Metal -framework AppKit
+LIBS += -framework Metal
+macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metaltextureimport
INSTALLS += target
diff --git a/examples/quick/scenegraph/metalunderqml/main.cpp b/examples/quick/scenegraph/metalunderqml/main.cpp
index 3e620137cd..cefb1c10a9 100644
--- a/examples/quick/scenegraph/metalunderqml/main.cpp
+++ b/examples/quick/scenegraph/metalunderqml/main.cpp
@@ -56,8 +56,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<MetalSquircle>("MetalUnderQML", 1);
-
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
QQuickView view;
diff --git a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
index 5ca6daa01a..4844df0c70 100644
--- a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
+++ b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
@@ -349,10 +349,13 @@ void SquircleRenderer::init(int framesInFlight)
rpDesc.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOne;
rpDesc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne;
+#ifdef Q_OS_MACOS
if (m_device.depth24Stencil8PixelFormatSupported) {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
- } else {
+ } else
+#endif
+ {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
}
diff --git a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
index 9fd131fe1b..3b0489ecdf 100644
--- a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
+++ b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
@@ -1,12 +1,17 @@
-!macos: error("This example requires macOS")
+!macos:!ios: error("This example requires macOS or iOS")
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = MetalUnderQML
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += metalsquircle.h
SOURCES += metalsquircle.mm main.cpp
RESOURCES += metalunderqml.qrc
-LIBS += -framework Metal -framework AppKit
+LIBS += -framework Metal
+macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metalunderqml
INSTALLS += target
diff --git a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
index 9676815c44..c2944970a5 100644
--- a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
+++ b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
@@ -60,6 +60,7 @@
First of all, we need an object we can expose to QML. This is a
subclass of QQuickItem so we can easily access \l QQuickItem::window().
+ We expose it to QML using the QML_ELEMENT macro.
\snippet scenegraph/openglunderqml/squircle.h 1
@@ -145,9 +146,7 @@
\snippet scenegraph/openglunderqml/main.cpp 1
The application's \c main() function instantiates a QQuickView and
- launches the \c main.qml file. The only thing worth noting is that
- we export the \c Squircle class to QML using the \l
- qmlRegisterType() macro.
+ launches the \c main.qml file.
\snippet scenegraph/openglunderqml/main.qml 1
diff --git a/examples/quick/scenegraph/openglunderqml/main.cpp b/examples/quick/scenegraph/openglunderqml/main.cpp
index c04d0da68f..4ca8d05f1c 100644
--- a/examples/quick/scenegraph/openglunderqml/main.cpp
+++ b/examples/quick/scenegraph/openglunderqml/main.cpp
@@ -59,8 +59,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<Squircle>("OpenGLUnderQML", 1);
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml"));
diff --git a/examples/quick/scenegraph/openglunderqml/openglunderqml.pro b/examples/quick/scenegraph/openglunderqml/openglunderqml.pro
index 54558ce9e9..7eaace1133 100644
--- a/examples/quick/scenegraph/openglunderqml/openglunderqml.pro
+++ b/examples/quick/scenegraph/openglunderqml/openglunderqml.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = OpenGLUnderQML
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += squircle.h
SOURCES += squircle.cpp main.cpp
RESOURCES += openglunderqml.qrc
diff --git a/examples/quick/scenegraph/rendernode/customrenderitem.cpp b/examples/quick/scenegraph/rendernode/customrenderitem.cpp
index e55cf0a2f4..aae91120a7 100644
--- a/examples/quick/scenegraph/rendernode/customrenderitem.cpp
+++ b/examples/quick/scenegraph/rendernode/customrenderitem.cpp
@@ -53,8 +53,9 @@
#include <QSGRendererInterface>
#include "openglrenderer.h"
+#ifdef Q_OS_MACOS
#include "metalrenderer.h"
-#include "d3d12renderer.h"
+#endif
#include "softwarerenderer.h"
//! [1]
@@ -101,14 +102,6 @@ QSGNode *CustomRenderItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
#endif
break;
- case QSGRendererInterface::Direct3D12: // ### Qt 6: remove
-#if QT_CONFIG(d3d12)
- if (!n)
- n = new D3D12RenderNode;
- static_cast<D3D12RenderNode *>(n)->sync(this);
-#endif
- break;
-
case QSGRendererInterface::Software:
if (!n)
n = new SoftwareRenderNode;
diff --git a/examples/quick/scenegraph/rendernode/customrenderitem.h b/examples/quick/scenegraph/rendernode/customrenderitem.h
index 74115b2505..28be54925b 100644
--- a/examples/quick/scenegraph/rendernode/customrenderitem.h
+++ b/examples/quick/scenegraph/rendernode/customrenderitem.h
@@ -53,6 +53,7 @@
#include <QQuickItem>
+//! [0]
class CustomRenderItem : public QQuickItem
{
Q_OBJECT
@@ -62,5 +63,6 @@ public:
CustomRenderItem(QQuickItem *parent = nullptr);
QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
};
+//! [0]
#endif
diff --git a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp
deleted file mode 100644
index e85811c089..0000000000
--- a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp
+++ /dev/null
@@ -1,309 +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 "d3d12renderer.h"
-#include <QQuickItem>
-#include <QQuickWindow>
-#include <QSGRendererInterface>
-#include <QFile>
-
-// ### Qt 6: remove
-
-#if QT_CONFIG(d3d12)
-
-D3D12RenderNode::~D3D12RenderNode()
-{
- releaseResources();
-}
-
-void D3D12RenderNode::releaseResources()
-{
- if (vbPtr) {
- vertexBuffer->Unmap(0, nullptr);
- vbPtr = nullptr;
- }
- if (cbPtr) {
- constantBuffer->Unmap(0, nullptr);
- cbPtr = nullptr;
- }
- constantBuffer = nullptr;
- vertexBuffer = nullptr;
- rootSignature = nullptr;
- pipelineState = nullptr;
- m_device = nullptr;
-}
-
-void D3D12RenderNode::init()
-{
- QSGRendererInterface *rif = m_window->rendererInterface();
- m_device = static_cast<ID3D12Device *>(rif->getResource(m_window, QSGRendererInterface::DeviceResource));
- Q_ASSERT(m_device);
-
- D3D12_ROOT_PARAMETER rootParameter;
- rootParameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
- rootParameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
- rootParameter.Descriptor.ShaderRegister = 0; // b0
- rootParameter.Descriptor.RegisterSpace = 0;
-
- D3D12_ROOT_SIGNATURE_DESC desc;
- desc.NumParameters = 1;
- desc.pParameters = &rootParameter;
- desc.NumStaticSamplers = 0;
- desc.pStaticSamplers = nullptr;
- desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
-
- ComPtr<ID3DBlob> signature;
- ComPtr<ID3DBlob> error;
- if (FAILED(D3D12SerializeRootSignature(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error))) {
- qWarning("Failed to serialize root signature");
- return;
- }
- if (FAILED(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(),
- IID_PPV_ARGS(&rootSignature)))) {
- qWarning("Failed to create root signature");
- return;
- }
-
- D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
- { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
- { "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 8, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }
- };
-
- QFile f(QStringLiteral(":/scenegraph/rendernode/shader_vert.cso"));
- if (!f.open(QIODevice::ReadOnly)) {
- qWarning("Failed to open file with vertex shader bytecode");
- return;
- }
- QByteArray vshader_cso = f.readAll();
- f.close();
- f.setFileName(QStringLiteral(":/scenegraph/rendernode/shader_frag.cso"));
- if (!f.open(QIODevice::ReadOnly)) {
- qWarning("Failed to open file with fragment shader bytecode");
- return;
- }
- QByteArray fshader_cso = f.readAll();
- D3D12_SHADER_BYTECODE vshader;
- vshader.pShaderBytecode = vshader_cso.constData();
- vshader.BytecodeLength = vshader_cso.size();
- D3D12_SHADER_BYTECODE pshader;
- pshader.pShaderBytecode = fshader_cso.constData();
- pshader.BytecodeLength = fshader_cso.size();
-
- D3D12_RASTERIZER_DESC rastDesc = {};
- rastDesc.FillMode = D3D12_FILL_MODE_SOLID;
- rastDesc.CullMode = D3D12_CULL_MODE_BACK;
- rastDesc.FrontCounterClockwise = TRUE; // Vertices are given CCW
-
- // Enable color write and blending (premultiplied alpha). The latter is
- // needed because the example changes the item's opacity and we pass
- // inheritedOpacity() into the pixel shader. If that wasn't the case,
- // blending could have stayed disabled.
- const D3D12_RENDER_TARGET_BLEND_DESC premulBlendDesc = {
- TRUE, FALSE,
- D3D12_BLEND_ONE, D3D12_BLEND_INV_SRC_ALPHA, D3D12_BLEND_OP_ADD,
- D3D12_BLEND_ONE, D3D12_BLEND_INV_SRC_ALPHA, D3D12_BLEND_OP_ADD,
- D3D12_LOGIC_OP_NOOP,
- D3D12_COLOR_WRITE_ENABLE_ALL
- };
- D3D12_BLEND_DESC blendDesc = {};
- blendDesc.RenderTarget[0] = premulBlendDesc;
-
- D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
- psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) };
- psoDesc.pRootSignature = rootSignature.Get();
- psoDesc.VS = vshader;
- psoDesc.PS = pshader;
- psoDesc.RasterizerState = rastDesc;
- psoDesc.BlendState = blendDesc;
- // No depth. The correct stacking of the item is ensured by the projection matrix.
- // Note that this does not support clipping.
- // If clipping is desired, render() needs to set a different PSO
- // with stencil enabled whenever the RenderState indicates so.
- psoDesc.SampleMask = UINT_MAX;
- psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
- psoDesc.NumRenderTargets = 1;
- psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
- psoDesc.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT; // not in use due to !DepthEnable, but this would be the correct format otherwise
- // We are rendering on the default render target so if the QuickWindow/View
- // has requested samples > 0 then we have to follow suit.
- const uint samples = qMax(1, m_window->format().samples());
- psoDesc.SampleDesc.Count = samples;
- if (samples > 1) {
- D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS msaaInfo = {};
- msaaInfo.Format = psoDesc.RTVFormats[0];
- msaaInfo.SampleCount = samples;
- if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &msaaInfo, sizeof(msaaInfo)))) {
- if (msaaInfo.NumQualityLevels > 0)
- psoDesc.SampleDesc.Quality = msaaInfo.NumQualityLevels - 1;
- }
- }
-
- if (FAILED(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)))) {
- qWarning("Failed to create graphics pipeline state");
- return;
- }
-
- const UINT vertexBufferSize = (2 + 3) * 3 * sizeof(float);
-
- D3D12_HEAP_PROPERTIES heapProp = {};
- heapProp.Type = D3D12_HEAP_TYPE_UPLOAD;
-
- D3D12_RESOURCE_DESC bufDesc;
- bufDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- bufDesc.Alignment = 0;
- bufDesc.Width = vertexBufferSize;
- bufDesc.Height = 1;
- bufDesc.DepthOrArraySize = 1;
- bufDesc.MipLevels = 1;
- bufDesc.Format = DXGI_FORMAT_UNKNOWN;
- bufDesc.SampleDesc.Count = 1;
- bufDesc.SampleDesc.Quality = 0;
- bufDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
- bufDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
-
- if (FAILED(m_device->CreateCommittedResource(&heapProp, D3D12_HEAP_FLAG_NONE, &bufDesc,
- D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
- IID_PPV_ARGS(&vertexBuffer)))) {
- qWarning("Failed to create committed resource (vertex buffer)");
- return;
- }
-
- vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
- vertexBufferView.StrideInBytes = vertexBufferSize / 3;
- vertexBufferView.SizeInBytes = vertexBufferSize;
-
- bufDesc.Width = 256;
- if (FAILED(m_device->CreateCommittedResource(&heapProp, D3D12_HEAP_FLAG_NONE, &bufDesc,
- D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
- IID_PPV_ARGS(&constantBuffer)))) {
- qWarning("Failed to create committed resource (constant buffer)");
- return;
- }
-
- const D3D12_RANGE readRange = { 0, 0 };
- if (FAILED(vertexBuffer->Map(0, &readRange, reinterpret_cast<void **>(&vbPtr)))) {
- qWarning("Map failed");
- return;
- }
-
- if (FAILED(constantBuffer->Map(0, &readRange, reinterpret_cast<void **>(&cbPtr)))) {
- qWarning("Map failed (constant buffer)");
- return;
- }
-
- float *vp = reinterpret_cast<float *>(vbPtr);
- vp += 2;
- *vp++ = 1.0f; *vp++ = 0.0f; *vp++ = 0.0f;
- vp += 2;
- *vp++ = 0.0f; *vp++ = 1.0f; *vp++ = 0.0f;
- vp += 2;
- *vp++ = 0.0f; *vp++ = 0.0f; *vp++ = 1.0f;
-}
-
-void D3D12RenderNode::render(const RenderState *state)
-{
- if (!m_device)
- init();
-
- QSGRendererInterface *rif = m_window->rendererInterface();
- ID3D12GraphicsCommandList *commandList = static_cast<ID3D12GraphicsCommandList *>(
- rif->getResource(m_window, QSGRendererInterface::CommandListResource));
- Q_ASSERT(commandList);
-
- const int msize = 16 * sizeof(float);
- memcpy(cbPtr, matrix()->constData(), msize);
- memcpy(cbPtr + msize, state->projectionMatrix()->constData(), msize);
- const float opacity = inheritedOpacity();
- memcpy(cbPtr + 2 * msize, &opacity, sizeof(float));
-
- const QPointF p0(m_width - 1, m_height - 1);
- const QPointF p1(0, 0);
- const QPointF p2(0, m_height - 1);
-
- float *vp = reinterpret_cast<float *>(vbPtr);
- *vp++ = p0.x();
- *vp++ = p0.y();
- vp += 3;
- *vp++ = p1.x();
- *vp++ = p1.y();
- vp += 3;
- *vp++ = p2.x();
- *vp++ = p2.y();
-
- commandList->SetPipelineState(pipelineState.Get());
- commandList->SetGraphicsRootSignature(rootSignature.Get());
- commandList->SetGraphicsRootConstantBufferView(0, constantBuffer->GetGPUVirtualAddress());
- commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- commandList->IASetVertexBuffers(0, 1, &vertexBufferView);
-
- commandList->DrawInstanced(3, 1, 0, 0);
-}
-
-// No need to reimplement changedStates() because no relevant commands are
-// added to the command list in render().
-
-QSGRenderNode::RenderingFlags D3D12RenderNode::flags() const
-{
- return BoundedRectRendering | DepthAwareRendering;
-}
-
-QRectF D3D12RenderNode::rect() const
-{
- return QRect(0, 0, m_width, m_height);
-}
-
-void D3D12RenderNode::sync(QQuickItem *item)
-{
- m_window = item->window();
- m_width = item->width();
- m_height = item->height();
-}
-
-#endif // d3d12
diff --git a/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc b/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc
index ba6551fddf..87e3c8b506 100644
--- a/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc
+++ b/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc
@@ -69,7 +69,7 @@
Let's go through the most important parts of the code:
- \snippet scenegraph/rendernode/main.cpp 1
+ \snippet scenegraph/rendernode/customrenderitem.h 0
Our custom QML type is implemented in the class CustomRenderItem.
diff --git a/examples/quick/scenegraph/rendernode/main.cpp b/examples/quick/scenegraph/rendernode/main.cpp
index b1dfe47829..645360eaba 100644
--- a/examples/quick/scenegraph/rendernode/main.cpp
+++ b/examples/quick/scenegraph/rendernode/main.cpp
@@ -58,10 +58,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
-//! [1]
- qmlRegisterTypesAndRevisions<CustomRenderItem>("SceneGraphRendering", 2);
-//! [1]
-
QQuickView view;
QCoreApplication::setApplicationName("Qt Scene Graph Render Node Example");
diff --git a/examples/quick/scenegraph/rendernode/main.qml b/examples/quick/scenegraph/rendernode/main.qml
index 153a71e097..2c407796cf 100644
--- a/examples/quick/scenegraph/rendernode/main.qml
+++ b/examples/quick/scenegraph/rendernode/main.qml
@@ -143,7 +143,6 @@ Item {
var apiStr;
switch (api) {
case GraphicsInfo.OpenGL: apiStr = "OpenGL (direct)"; break;
- case GraphicsInfo.Direct3D12: apiStr = "Direct3D 12 (direct)"; break;
case GraphicsInfo.Software: apiStr = "Software (QPainter)"; break;
case GraphicsInfo.OpenGLRhi: apiStr = "OpenGL (RHI)"; break;
case GraphicsInfo.MetalRhi: apiStr = "Metal (RHI)"; break;
diff --git a/examples/quick/scenegraph/rendernode/rendernode.pro b/examples/quick/scenegraph/rendernode/rendernode.pro
index 897b0b1f08..4ae46de2a4 100644
--- a/examples/quick/scenegraph/rendernode/rendernode.pro
+++ b/examples/quick/scenegraph/rendernode/rendernode.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 2
+
HEADERS += customrenderitem.h \
openglrenderer.h \
softwarerenderer.h
@@ -17,12 +21,6 @@ INSTALLS += target
OTHER_FILES += \
main.qml
-qtConfig(d3d12) {
- HEADERS += d3d12renderer.h
- SOURCES += d3d12renderer.cpp
- LIBS += -ld3d12
-}
-
macos {
HEADERS += metalrenderer.h
SOURCES += metalrenderer.mm
diff --git a/examples/quick/scenegraph/rendernode/rendernode.qrc b/examples/quick/scenegraph/rendernode/rendernode.qrc
index 5907eab62c..a93fd0270f 100644
--- a/examples/quick/scenegraph/rendernode/rendernode.qrc
+++ b/examples/quick/scenegraph/rendernode/rendernode.qrc
@@ -1,8 +1,6 @@
<RCC>
<qresource prefix="/scenegraph/rendernode">
<file>main.qml</file>
- <file>shader_vert.cso</file>
- <file>shader_frag.cso</file>
<file>metalshader.vert</file>
<file>metalshader.frag</file>
</qresource>
diff --git a/examples/quick/scenegraph/rendernode/shader_frag.cso b/examples/quick/scenegraph/rendernode/shader_frag.cso
deleted file mode 100644
index 686c6af3fc..0000000000
--- a/examples/quick/scenegraph/rendernode/shader_frag.cso
+++ /dev/null
Binary files differ
diff --git a/examples/quick/scenegraph/rendernode/shader_vert.cso b/examples/quick/scenegraph/rendernode/shader_vert.cso
deleted file mode 100644
index fa13be5160..0000000000
--- a/examples/quick/scenegraph/rendernode/shader_vert.cso
+++ /dev/null
Binary files differ
diff --git a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
index bba364ac97..a0f288d575 100644
--- a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
+++ b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
@@ -95,7 +95,7 @@ void SoftwareRenderNode::render(const RenderState *renderState)
QSGRenderNode::StateFlags SoftwareRenderNode::changedStates() const
{
- return nullptr;
+ return {};
}
QSGRenderNode::RenderingFlags SoftwareRenderNode::flags() const
diff --git a/examples/quick/scenegraph/scenegraph.pro b/examples/quick/scenegraph/scenegraph.pro
index 5fea3b974a..08ca18fa0c 100644
--- a/examples/quick/scenegraph/scenegraph.pro
+++ b/examples/quick/scenegraph/scenegraph.pro
@@ -16,7 +16,7 @@ SUBDIRS += \
rendernode \
threadedanimation
-macos {
+macos|ios {
SUBDIRS += \
metalunderqml \
metaltextureimport
@@ -27,7 +27,9 @@ win32 {
}
qtConfig(vulkan) {
- SUBDIRS += vulkanunderqml
+ SUBDIRS += \
+ vulkanunderqml \
+ vulkantextureimport
}
EXAMPLE_FILES += \
diff --git a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
index 67ca2d8dbd..d7de1613e4 100644
--- a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
+++ b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
@@ -47,7 +47,7 @@
material state is what we assign to each individual node; in this
case to give them different colors.
- \snippet scenegraph/simplematerial/simplematerial.cpp 1
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 1
The first thing we do when creating custom materials with the
simplified scheme is to create a state class. In this case the
@@ -55,7 +55,7 @@
compare function which the scene graph can use to reorder the node
rendering.
- \snippet scenegraph/simplematerial/simplematerial.cpp 2
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 2
Next we define the material shader, by subclassing a template
instantiation of \l QSGSimpleMaterialShader with our \c State.
@@ -74,21 +74,21 @@
classes. Using the same \c State class in multiple shaders will
will lead to undefined behavior.
- \snippet scenegraph/simplematerial/simplematerial.cpp 3
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 3
Next comes the declaration of the shader source code, where we
define a vertex and fragment shader. The simple material assumes
the presence of \c qt_Matrix in the vertex shader and \c
qt_Opacity in the fragment shader.
- \snippet scenegraph/simplematerial/simplematerial.cpp 4
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 4
We reimplement the \c attributes function to return the name of
the \c aVertex and \c aTexCoord attributes. These attributes
will be mapped to attribute indices 0 and 1 in the node's
geometry.
- \snippet scenegraph/simplematerial/simplematerial.cpp 6
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 6
Uniforms can be accessed either by name or by index, where index
is faster than name. We reimplement the \c resolveUniforms()
@@ -96,7 +96,7 @@
to worry about resolving \c qt_Opacity or \c qt_Matrix as these
are handled by the baseclass.
- \snippet scenegraph/simplematerial/simplematerial.cpp 5
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 5
The \c updateState() function is called once for every unique
state and we use it to update the shader program with the current
@@ -105,7 +105,7 @@
use case, where all the colors are different, the updateState()
function will be called once for every node.
- \snippet scenegraph/simplematerial/simplematerial.cpp 7
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 7
The \c ColorNode class is supposed to draw something, so it needs
to be a subclass of \l QSGGeometryNode.
@@ -129,12 +129,13 @@
Finally, we tell the node to take ownership of the material, so we
do not have to explicitly memory-manage it.
- \snippet scenegraph/simplematerial/simplematerial.cpp 8
+ \snippet scenegraph/simplematerial/simplematerialitem.h 8
Since the Item is providing its own graphics to the scene graph,
- we set the flag \l QQuickItem::ItemHasContents.
+ we set the flag \l QQuickItem::ItemHasContents. We also make sure
+ the item is exposed to QML by adding the QML_ELEMENT macro.
- \snippet scenegraph/simplematerial/simplematerial.cpp 9
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 9
Whenever the Item has changed graphically, the \l
QQuickItem::updatePaintNode() function is called.
@@ -159,9 +160,8 @@
\snippet scenegraph/simplematerial/simplematerial.cpp 11
- The \c main() function of the application adds the custom QML type
- using \l qmlRegisterType() and opens up a \l QQuickView with our
- QML file.
+ The \c main() function of the application opens up a \l QQuickView
+ with our QML file.
\snippet scenegraph/simplematerial/main.qml 1
diff --git a/examples/quick/scenegraph/simplematerial/simplematerial.cpp b/examples/quick/scenegraph/simplematerial/simplematerial.cpp
index 55e1d879ca..35866bd6d0 100644
--- a/examples/quick/scenegraph/simplematerial/simplematerial.cpp
+++ b/examples/quick/scenegraph/simplematerial/simplematerial.cpp
@@ -49,163 +49,13 @@
****************************************************************************/
#include <qguiapplication.h>
-
-#include <qsgmaterial.h>
-#include <qsgnode.h>
-
-#include <qquickitem.h>
#include <qquickview.h>
-#include <qsgsimplerectnode.h>
-
-#include <qsgsimplematerial.h>
-
-//! [1]
-struct State
-{
- QColor color;
-
- int compare(const State *other) const {
- uint rgb = color.rgba();
- uint otherRgb = other->color.rgba();
-
- if (rgb == otherRgb) {
- return 0;
- } else if (rgb < otherRgb) {
- return -1;
- } else {
- return 1;
- }
- }
-};
-//! [1]
-
-//! [2]
-class Shader : public QSGSimpleMaterialShader<State>
-{
- QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State);
-//! [2] //! [3]
-public:
-
- const char *vertexShader() const override {
- return
- "attribute highp vec4 aVertex; \n"
- "attribute highp vec2 aTexCoord; \n"
- "uniform highp mat4 qt_Matrix; \n"
- "varying highp vec2 texCoord; \n"
- "void main() { \n"
- " gl_Position = qt_Matrix * aVertex; \n"
- " texCoord = aTexCoord; \n"
- "}";
- }
-
- const char *fragmentShader() const override {
- return
- "uniform lowp float qt_Opacity; \n"
- "uniform lowp vec4 color; \n"
- "varying highp vec2 texCoord; \n"
- "void main () \n"
- "{ \n"
- " gl_FragColor = texCoord.y * texCoord.x * color * qt_Opacity; \n"
- "}";
- }
-//! [3] //! [4]
- QList<QByteArray> attributes() const override
- {
- return QList<QByteArray>() << "aVertex" << "aTexCoord";
- }
-//! [4] //! [5]
- void updateState(const State *state, const State *) override
- {
- program()->setUniformValue(id_color, state->color);
- }
-//! [5] //! [6]
- void resolveUniforms() override
- {
- id_color = program()->uniformLocation("color");
- }
-
-private:
- int id_color;
-//! [6]
-};
-
-
-//! [7]
-class ColorNode : public QSGGeometryNode
-{
-public:
- ColorNode()
- : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
- {
- setGeometry(&m_geometry);
-
- QSGSimpleMaterial<State> *material = Shader::createMaterial();
- material->setFlag(QSGMaterial::Blending);
- setMaterial(material);
- setFlag(OwnsMaterial);
- }
-
- QSGGeometry m_geometry;
-};
-//! [7]
-
-
-//! [8]
-class Item : public QQuickItem
-{
- Q_OBJECT
-
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- QML_NAMED_ELEMENT(SimpleMaterialItem)
-
-public:
-
- Item()
- {
- setFlag(ItemHasContents, true);
- }
-
- void setColor(const QColor &color) {
- if (m_color != color) {
- m_color = color;
- emit colorChanged();
- update();
- }
- }
- QColor color() const {
- return m_color;
- }
-
-signals:
- void colorChanged();
-
-private:
- QColor m_color;
-
-//! [8] //! [9]
-public:
- QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override
- {
- ColorNode *n = static_cast<ColorNode *>(node);
- if (!node)
- n = new ColorNode();
-
- QSGGeometry::updateTexturedRectGeometry(n->geometry(), boundingRect(), QRectF(0, 0, 1, 1));
- static_cast<QSGSimpleMaterial<State>*>(n->material())->state()->color = m_color;
-
- n->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);
-
- return n;
- }
-};
-//! [9] //! [11]
+//! [11]
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<Item>("SimpleMaterial", 1);
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/simplematerial/main.qml"));
@@ -213,6 +63,4 @@ int main(int argc, char **argv)
return app.exec();
}
-
-#include "simplematerial.moc"
//! [11]
diff --git a/examples/quick/scenegraph/simplematerial/simplematerial.pro b/examples/quick/scenegraph/simplematerial/simplematerial.pro
index 6ae935f357..131af45974 100644
--- a/examples/quick/scenegraph/simplematerial/simplematerial.pro
+++ b/examples/quick/scenegraph/simplematerial/simplematerial.pro
@@ -1,8 +1,13 @@
QT += quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SimpleMaterial
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += \
- simplematerial.cpp
+ simplematerial.cpp \
+ simplematerialitem.cpp
RESOURCES += simplematerial.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
@@ -10,3 +15,6 @@ qml.files = main.qml
qml.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
INSTALLS += target qml
+
+HEADERS += \
+ simplematerialitem.h
diff --git a/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp b/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp
new file mode 100644
index 0000000000..c4c7b2e07e
--- /dev/null
+++ b/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications 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 "simplematerialitem.h"
+
+#include <QtQuick/qsgsimplematerial.h>
+#include <QtQuick/qsggeometry.h>
+#include <QtQuick/qsgnode.h>
+
+//! [1]
+struct State
+{
+ QColor color;
+
+ int compare(const State *other) const {
+ uint rgb = color.rgba();
+ uint otherRgb = other->color.rgba();
+
+ if (rgb == otherRgb) {
+ return 0;
+ } else if (rgb < otherRgb) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+};
+//! [1]
+
+//! [2]
+class Shader : public QSGSimpleMaterialShader<State>
+{
+ QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State);
+//! [2] //! [3]
+public:
+
+ const char *vertexShader() const override {
+ return
+ "attribute highp vec4 aVertex; \n"
+ "attribute highp vec2 aTexCoord; \n"
+ "uniform highp mat4 qt_Matrix; \n"
+ "varying highp vec2 texCoord; \n"
+ "void main() { \n"
+ " gl_Position = qt_Matrix * aVertex; \n"
+ " texCoord = aTexCoord; \n"
+ "}";
+ }
+
+ const char *fragmentShader() const override {
+ return
+ "uniform lowp float qt_Opacity; \n"
+ "uniform lowp vec4 color; \n"
+ "varying highp vec2 texCoord; \n"
+ "void main () \n"
+ "{ \n"
+ " gl_FragColor = texCoord.y * texCoord.x * color * qt_Opacity; \n"
+ "}";
+ }
+//! [3] //! [4]
+ QList<QByteArray> attributes() const override
+ {
+ return QList<QByteArray>() << "aVertex" << "aTexCoord";
+ }
+//! [4] //! [5]
+ void updateState(const State *state, const State *) override
+ {
+ program()->setUniformValue(id_color, state->color);
+ }
+//! [5] //! [6]
+ void resolveUniforms() override
+ {
+ id_color = program()->uniformLocation("color");
+ }
+
+private:
+ int id_color;
+//! [6]
+};
+
+
+//! [7]
+class ColorNode : public QSGGeometryNode
+{
+public:
+ ColorNode()
+ : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
+ {
+ setGeometry(&m_geometry);
+
+ QSGSimpleMaterial<State> *material = Shader::createMaterial();
+ material->setFlag(QSGMaterial::Blending);
+ setMaterial(material);
+ setFlag(OwnsMaterial);
+ }
+
+ QSGGeometry m_geometry;
+};
+//! [7]
+
+void SimpleMaterialItem::setColor(const QColor &color) {
+ if (m_color != color) {
+ m_color = color;
+ emit colorChanged();
+ update();
+ }
+}
+
+//! [9]
+QSGNode *SimpleMaterialItem::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *)
+{
+ ColorNode *n = static_cast<ColorNode *>(node);
+ if (!node)
+ n = new ColorNode();
+
+ QSGGeometry::updateTexturedRectGeometry(n->geometry(), boundingRect(), QRectF(0, 0, 1, 1));
+ static_cast<QSGSimpleMaterial<State>*>(n->material())->state()->color = m_color;
+
+ n->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);
+
+ return n;
+}
+//! [9]
diff --git a/examples/quick/scenegraph/simplematerial/simplematerialitem.h b/examples/quick/scenegraph/simplematerial/simplematerialitem.h
new file mode 100644
index 0000000000..5775ad097b
--- /dev/null
+++ b/examples/quick/scenegraph/simplematerial/simplematerialitem.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications 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$
+**
+****************************************************************************/
+
+#ifndef SIMPLEMATERIALITEM_H
+#define SIMPLEMATERIALITEM_H
+
+#include <QtQuick/qquickitem.h>
+
+//! [8]
+class SimpleMaterialItem : public QQuickItem
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ QML_ELEMENT
+
+public:
+
+ SimpleMaterialItem() { setFlag(ItemHasContents, true); }
+
+ void setColor(const QColor &color);
+ QColor color() const { return m_color; }
+
+signals:
+ void colorChanged();
+
+private:
+ QColor m_color;
+
+public:
+ QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
+};
+//! [8]
+
+#endif // SIMPLEMATERIALITEM_H
diff --git a/examples/quick/scenegraph/textureinthread/main.cpp b/examples/quick/scenegraph/textureinthread/main.cpp
index 7c22fa7fdf..cb00946bf7 100644
--- a/examples/quick/scenegraph/textureinthread/main.cpp
+++ b/examples/quick/scenegraph/textureinthread/main.cpp
@@ -70,7 +70,6 @@ int main(int argc, char **argv)
return app.exec();
}
- qmlRegisterTypesAndRevisions<ThreadRenderer>("SceneGraphRendering", 1);
int execReturn = 0;
{
diff --git a/examples/quick/scenegraph/textureinthread/textureinthread.pro b/examples/quick/scenegraph/textureinthread/textureinthread.pro
index 7f5fbb76e9..4d41daa7bf 100644
--- a/examples/quick/scenegraph/textureinthread/textureinthread.pro
+++ b/examples/quick/scenegraph/textureinthread/textureinthread.pro
@@ -3,6 +3,10 @@ QT += quick
# To make threaded gl check...
QT += core-private gui-private
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += threadrenderer.h
SOURCES += threadrenderer.cpp main.cpp
diff --git a/examples/quick/scenegraph/threadedanimation/main.cpp b/examples/quick/scenegraph/threadedanimation/main.cpp
index c77a291f5d..85ff486b16 100644
--- a/examples/quick/scenegraph/threadedanimation/main.cpp
+++ b/examples/quick/scenegraph/threadedanimation/main.cpp
@@ -57,8 +57,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<Spinner>("Spinner", 1);
-
QQuickView view;
view.setSource(QUrl("qrc:///scenegraph/threadedanimation/main.qml"));
view.show();
diff --git a/examples/quick/scenegraph/threadedanimation/threadedanimation.pro b/examples/quick/scenegraph/threadedanimation/threadedanimation.pro
index 419ee97e2e..3caf3fa94b 100644
--- a/examples/quick/scenegraph/threadedanimation/threadedanimation.pro
+++ b/examples/quick/scenegraph/threadedanimation/threadedanimation.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = Spinner
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += spinner.h
SOURCES += spinner.cpp main.cpp
RESOURCES += threadedanimation.qrc
diff --git a/examples/quick/scenegraph/twotextureproviders/main.cpp b/examples/quick/scenegraph/twotextureproviders/main.cpp
index 3f53bb6e32..df0454ce40 100644
--- a/examples/quick/scenegraph/twotextureproviders/main.cpp
+++ b/examples/quick/scenegraph/twotextureproviders/main.cpp
@@ -58,8 +58,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterTypesAndRevisions<XorBlender>("SceneGraphRendering", 1);
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/twotextureproviders/main.qml"));
diff --git a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro
index 7b7c093b48..b87a0a2611 100644
--- a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro
+++ b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += xorblender.h
SOURCES += xorblender.cpp main.cpp
diff --git a/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg b/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg
new file mode 100644
index 0000000000..e7bbe62bf3
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc b/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc
new file mode 100644
index 0000000000..334291f990
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example scenegraph/vulkantextureimport
+ \title Scene Graph - Vulkan Texture Import
+ \ingroup qtquickexamples
+ \brief Shows how to use a texture created directly with use a texture created directly withulkan.
+
+ \image vulkantextureimport-example.jpg
+
+
+ The Vulkan Texture Import example shows how an application can import and
+ use a
+ \l{https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkImage.html}
+ {VkImage} in the Qt Quick scene. This provides an alternative to the \l{Scene Graph -
+ Vulkan Under QML}{underlay}, overlay, or \l{Scene Graph - Custom Rendering
+ with QSGRenderNode}{render node} approaches when it comes to integrating
+ native Vulkan rendering.
+
+ This example is equivalent in most ways to the \l{Scene Graph - Metal Texture Import}{Metal Texture Import}
+ example. The Vulkan rendering code is taken from the \l{Scene Graph - Vulkan Under QML}{Vulkan Under QML} example.
+
+ */
diff --git a/examples/quick/scenegraph/vulkantextureimport/main.cpp b/examples/quick/scenegraph/vulkantextureimport/main.cpp
new file mode 100644
index 0000000000..1c42e87043
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications 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 <QGuiApplication>
+#include <QtQuick/QQuickView>
+#include "vulkantextureimport.h"
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ qmlRegisterType<CustomTextureItem>("VulkanTextureImport", 1, 0, "CustomTextureItem");
+
+ QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);
+
+ QQuickView view;
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:///scenegraph/vulkantextureimport/main.qml"));
+ view.resize(400, 400);
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/quick/scenegraph/vulkantextureimport/main.qml b/examples/quick/scenegraph/vulkantextureimport/main.qml
new file mode 100644
index 0000000000..91adf4c394
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/main.qml
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+//! [1]
+import VulkanTextureImport 1.0
+//! [1]
+
+Rectangle {
+ gradient: Gradient {
+ GradientStop { position: 0; color: "firebrick" }
+ GradientStop { position: 1; color: "black" }
+ }
+
+ //! [2]
+ CustomTextureItem {
+ id: renderer
+ anchors.fill: parent
+ anchors.margins: 10
+
+ SequentialAnimation on t {
+ NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
+ NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
+ loops: Animation.Infinite
+ running: true
+ }
+ //! [2]
+
+ transform: [
+ Rotation { id: rotation; axis.x: 0; axis.z: 0; axis.y: 1; angle: 0; origin.x: renderer.width / 2; origin.y: renderer.height / 2; },
+ Translate { id: txOut; x: -renderer.width / 2; y: -renderer.height / 2 },
+ Scale { id: scale; },
+ Translate { id: txIn; x: renderer.width / 2; y: renderer.height / 2 }
+ ]
+ }
+
+ SequentialAnimation {
+ PauseAnimation { duration: 5000 }
+ ParallelAnimation {
+ NumberAnimation { target: scale; property: "xScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack }
+ NumberAnimation { target: scale; property: "yScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack }
+ }
+ NumberAnimation { target: rotation; property: "angle"; to: 80; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: rotation; property: "angle"; to: -80; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: rotation; property: "angle"; to: 0; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: renderer; property: "opacity"; to: 0.1; duration: 1000; easing.type: Easing.InOutCubic }
+ PauseAnimation { duration: 1000 }
+ NumberAnimation { target: renderer; property: "opacity"; to: 1.0; duration: 1000; easing.type: Easing.InOutCubic }
+ ParallelAnimation {
+ NumberAnimation { target: scale; property: "xScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack }
+ NumberAnimation { target: scale; property: "yScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack }
+ }
+ running: true
+ loops: Animation.Infinite
+ }
+
+ Rectangle {
+ id: labelFrame
+ anchors.margins: -10
+ radius: 5
+ color: "white"
+ border.color: "black"
+ opacity: 0.5
+ anchors.fill: label
+ }
+
+ Text {
+ id: label
+ anchors.bottom: renderer.bottom
+ anchors.left: renderer.left
+ anchors.right: renderer.right
+ anchors.margins: 20
+ wrapMode: Text.WordWrap
+ text: "The squircle, using rendering code borrowed from the vulkanunderqml example, is rendered into a texture directly with Vulkan. The VkImage is then imported and used in a custom Qt Quick item."
+ }
+}
diff --git a/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv b/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv
new file mode 100644
index 0000000000..e4d13a871d
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv b/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv
new file mode 100644
index 0000000000..5df94a47e4
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp
new file mode 100644
index 0000000000..a4201c1dfa
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp
@@ -0,0 +1,823 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications 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 "vulkantextureimport.h"
+
+#include <QtGui/QScreen>
+#include <QtQuick/QQuickWindow>
+#include <QtQuick/QSGTextureProvider>
+#include <QtQuick/QSGSimpleTextureNode>
+
+#include <QVulkanInstance>
+#include <QVulkanFunctions>
+
+class CustomTextureNode : public QSGTextureProvider, public QSGSimpleTextureNode
+{
+ Q_OBJECT
+
+public:
+ CustomTextureNode(QQuickItem *item);
+ ~CustomTextureNode() override;
+
+ QSGTexture *texture() const override;
+
+ void sync();
+
+private slots:
+ void render();
+
+private:
+ enum Stage {
+ VertexStage,
+ FragmentStage
+ };
+ void prepareShader(Stage stage);
+ bool buildTexture(const QSize &size);
+ void freeTexture();
+ bool createRenderPass();
+ bool initialize();
+
+ QQuickItem *m_item;
+ QQuickWindow *m_window;
+ QSize m_size;
+ qreal m_dpr;
+
+ QByteArray m_vert;
+ QByteArray m_frag;
+
+ VkImage m_texture = VK_NULL_HANDLE;
+ VkDeviceMemory m_textureMemory = VK_NULL_HANDLE;
+ VkFramebuffer m_textureFramebuffer = VK_NULL_HANDLE;
+ VkImageView m_textureView = VK_NULL_HANDLE;
+
+ bool m_initialized = false;
+
+ float m_t;
+
+ VkPhysicalDevice m_physDev = VK_NULL_HANDLE;
+ VkDevice m_dev = VK_NULL_HANDLE;
+ QVulkanDeviceFunctions *m_devFuncs = nullptr;
+ QVulkanFunctions *m_funcs = nullptr;
+
+ VkBuffer m_vbuf = VK_NULL_HANDLE;
+ VkDeviceMemory m_vbufMem = VK_NULL_HANDLE;
+ VkBuffer m_ubuf = VK_NULL_HANDLE;
+ VkDeviceMemory m_ubufMem = VK_NULL_HANDLE;
+ VkDeviceSize m_allocPerUbuf = 0;
+
+ VkPipelineCache m_pipelineCache = VK_NULL_HANDLE;
+
+ VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE;
+ VkDescriptorSetLayout m_resLayout = VK_NULL_HANDLE;
+ VkPipeline m_pipeline = VK_NULL_HANDLE;
+
+ VkDescriptorPool m_descriptorPool = VK_NULL_HANDLE;
+ VkDescriptorSet m_ubufDescriptor = VK_NULL_HANDLE;
+
+ VkRenderPass m_renderPass = VK_NULL_HANDLE;
+};
+
+CustomTextureItem::CustomTextureItem()
+{
+ setFlag(ItemHasContents, true);
+}
+
+void CustomTextureItem::invalidateSceneGraph() // called on the render thread when the scenegraph is invalidated
+{
+ m_node = nullptr;
+}
+
+void CustomTextureItem::releaseResources() // called on the gui thread if the item is removed from scene
+{
+ m_node = nullptr;
+}
+
+QSGNode *CustomTextureItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
+{
+ CustomTextureNode *n = static_cast<CustomTextureNode *>(node);
+
+ if (!n && (width() <= 0 || height() <= 0))
+ return nullptr;
+
+ if (!n) {
+ m_node = new CustomTextureNode(this);
+ n = m_node;
+ }
+
+ m_node->sync();
+
+ n->setTextureCoordinatesTransform(QSGSimpleTextureNode::NoTransform);
+ n->setFiltering(QSGTexture::Linear);
+ n->setRect(0, 0, width(), height());
+
+ window()->update(); // ensure getting to beforeRendering() at some point
+
+ return n;
+}
+
+void CustomTextureItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+
+ if (newGeometry.size() != oldGeometry.size())
+ update();
+}
+
+void CustomTextureItem::setT(qreal t)
+{
+ if (t == m_t)
+ return;
+
+ m_t = t;
+ emit tChanged();
+
+ update();
+}
+
+CustomTextureNode::CustomTextureNode(QQuickItem *item)
+ : m_item(item)
+{
+ m_window = m_item->window();
+ connect(m_window, &QQuickWindow::beforeRendering, this, &CustomTextureNode::render);
+ connect(m_window, &QQuickWindow::screenChanged, this, [this]() {
+ if (m_window->effectiveDevicePixelRatio() != m_dpr)
+ m_item->update();
+ });
+}
+
+CustomTextureNode::~CustomTextureNode()
+{
+ m_devFuncs->vkDestroyBuffer(m_dev, m_vbuf, nullptr);
+ m_devFuncs->vkDestroyBuffer(m_dev, m_ubuf, nullptr);
+ m_devFuncs->vkFreeMemory(m_dev, m_vbufMem, nullptr);
+ m_devFuncs->vkFreeMemory(m_dev, m_ubufMem, nullptr);
+
+ m_devFuncs->vkDestroyPipelineCache(m_dev, m_pipelineCache, nullptr);
+ m_devFuncs->vkDestroyPipelineLayout(m_dev, m_pipelineLayout, nullptr);
+ m_devFuncs->vkDestroyPipeline(m_dev, m_pipeline, nullptr);
+
+ m_devFuncs->vkDestroyRenderPass(m_dev, m_renderPass, nullptr);
+
+ m_devFuncs->vkDestroyDescriptorSetLayout(m_dev, m_resLayout, nullptr);
+ m_devFuncs->vkDestroyDescriptorPool(m_dev, m_descriptorPool, nullptr);
+
+ delete texture();
+ freeTexture();
+}
+
+QSGTexture *CustomTextureNode::texture() const
+{
+ return QSGSimpleTextureNode::texture();
+}
+
+static const float vertices[] = {
+ -1, -1,
+ 1, -1,
+ -1, 1,
+ 1, 1
+};
+
+const int UBUF_SIZE = 4;
+
+
+bool CustomTextureNode::buildTexture(const QSize &size)
+{
+ VkImageCreateInfo imageInfo;
+ memset(&imageInfo, 0, sizeof(imageInfo));
+ imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
+ imageInfo.flags = 0;
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
+ imageInfo.extent.width = uint32_t(size.width());
+ imageInfo.extent.height = uint32_t(size.height());
+ imageInfo.extent.depth = 1;
+ imageInfo.mipLevels = 1;
+ imageInfo.arrayLayers = 1;
+ imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
+ imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
+ imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
+
+ imageInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+ imageInfo.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+
+ VkImage image = VK_NULL_HANDLE;
+ if (m_devFuncs->vkCreateImage(m_dev, &imageInfo, nullptr, &image) != VK_SUCCESS) {
+ qCritical("VulkanWrapper: failed to create image!");
+ return false;
+ }
+
+ m_texture = image;
+
+ VkMemoryRequirements memReq;
+ m_devFuncs->vkGetImageMemoryRequirements(m_dev, image, &memReq);
+
+ quint32 memIndex = 0;
+ VkPhysicalDeviceMemoryProperties physDevMemProps;
+ m_window->vulkanInstance()->functions()->vkGetPhysicalDeviceMemoryProperties(m_physDev, &physDevMemProps);
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (!(memReq.memoryTypeBits & (1 << i)))
+ continue;
+ memIndex = i;
+ }
+
+ VkMemoryAllocateInfo allocInfo = {
+ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ nullptr,
+ memReq.size,
+ memIndex
+ };
+
+ VkResult err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_textureMemory);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to allocate memory for linear image: %d", err);
+ return false;
+ }
+
+ err = m_devFuncs->vkBindImageMemory(m_dev, image, m_textureMemory, 0);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to bind linear image memory: %d", err);
+ return false;
+ }
+
+ VkImageViewCreateInfo viewInfo;
+ memset(&viewInfo, 0, sizeof(viewInfo));
+ viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+ viewInfo.image = image;
+ viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
+ viewInfo.format = imageInfo.format;
+ viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
+ viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
+ viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
+ viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
+ viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ viewInfo.subresourceRange.baseMipLevel = 0;
+ viewInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
+ viewInfo.subresourceRange.baseArrayLayer = 0;
+ viewInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
+
+ err = m_devFuncs->vkCreateImageView(m_dev, &viewInfo, nullptr, &m_textureView);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create render target image view: %d", err);
+ return false;
+ }
+
+ VkFramebufferCreateInfo fbInfo;
+ memset(&fbInfo, 0, sizeof(fbInfo));
+ fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+ fbInfo.renderPass = m_renderPass;
+ fbInfo.attachmentCount = 1;
+ fbInfo.pAttachments = &m_textureView;
+ fbInfo.width = uint32_t(size.width());
+ fbInfo.height = uint32_t(size.height());
+ fbInfo.layers = 1;
+
+ err = m_devFuncs->vkCreateFramebuffer(m_dev, &fbInfo, nullptr, &m_textureFramebuffer);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create framebuffer: %d", err);
+ return false;
+ }
+ return true;
+}
+
+void CustomTextureNode::freeTexture()
+{
+ if (m_texture) {
+ m_devFuncs->vkDestroyFramebuffer(m_dev, m_textureFramebuffer, nullptr);
+ m_textureFramebuffer = VK_NULL_HANDLE;
+ m_devFuncs->vkFreeMemory(m_dev, m_textureMemory, nullptr);
+ m_textureMemory = VK_NULL_HANDLE;
+ m_devFuncs->vkDestroyImageView(m_dev, m_textureView, nullptr);
+ m_textureView = VK_NULL_HANDLE;
+ m_devFuncs->vkDestroyImage(m_dev, m_texture, nullptr);
+ m_texture = VK_NULL_HANDLE;
+ }
+}
+
+
+
+static inline VkDeviceSize aligned(VkDeviceSize v, VkDeviceSize byteAlign)
+{
+ return (v + byteAlign - 1) & ~(byteAlign - 1);
+}
+
+bool CustomTextureNode::createRenderPass()
+{
+ const VkFormat vkformat = VK_FORMAT_R8G8B8A8_UNORM;
+ const VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
+ VkAttachmentDescription colorAttDesc;
+ memset(&colorAttDesc, 0, sizeof(colorAttDesc));
+ colorAttDesc.format = vkformat;
+ colorAttDesc.samples = samples;
+ colorAttDesc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
+ colorAttDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ colorAttDesc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ colorAttDesc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ colorAttDesc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ colorAttDesc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
+ const VkAttachmentReference colorRef = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
+
+ VkSubpassDescription subpassDesc;
+ memset(&subpassDesc, 0, sizeof(subpassDesc));
+ subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
+ subpassDesc.colorAttachmentCount = 1;
+ subpassDesc.pColorAttachments = &colorRef;
+ subpassDesc.pDepthStencilAttachment = nullptr;
+ subpassDesc.pResolveAttachments = nullptr;
+
+ VkRenderPassCreateInfo rpInfo;
+ memset(&rpInfo, 0, sizeof(rpInfo));
+ rpInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
+ rpInfo.attachmentCount = 1;
+ rpInfo.pAttachments = &colorAttDesc;
+ rpInfo.subpassCount = 1;
+ rpInfo.pSubpasses = &subpassDesc;
+
+ VkResult err = m_devFuncs->vkCreateRenderPass(m_dev, &rpInfo, nullptr, &m_renderPass);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create renderpass: %d", err);
+ return false;
+ }
+
+ return true;
+}
+
+bool CustomTextureNode::initialize()
+{
+ const int framesInFlight = m_window->graphicsStateInfo().framesInFlight;
+ m_initialized = true;
+
+ QSGRendererInterface *rif = m_window->rendererInterface();
+ QVulkanInstance *inst = reinterpret_cast<QVulkanInstance *>(
+ rif->getResource(m_window, QSGRendererInterface::VulkanInstanceResource));
+ Q_ASSERT(inst && inst->isValid());
+
+ m_physDev = *static_cast<VkPhysicalDevice *>(rif->getResource(m_window, QSGRendererInterface::PhysicalDeviceResource));
+ m_dev = *static_cast<VkDevice *>(rif->getResource(m_window, QSGRendererInterface::DeviceResource));
+ Q_ASSERT(m_physDev && m_dev);
+
+ m_devFuncs = inst->deviceFunctions(m_dev);
+ m_funcs = inst->functions();
+ Q_ASSERT(m_devFuncs && m_funcs);
+
+ createRenderPass();
+
+ VkPhysicalDeviceProperties physDevProps;
+ m_funcs->vkGetPhysicalDeviceProperties(m_physDev, &physDevProps);
+
+ VkPhysicalDeviceMemoryProperties physDevMemProps;
+ m_funcs->vkGetPhysicalDeviceMemoryProperties(m_physDev, &physDevMemProps);
+
+ VkBufferCreateInfo bufferInfo;
+ memset(&bufferInfo, 0, sizeof(bufferInfo));
+ bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
+ bufferInfo.size = sizeof(vertices);
+ bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
+ VkResult err = m_devFuncs->vkCreateBuffer(m_dev, &bufferInfo, nullptr, &m_vbuf);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create vertex buffer: %d", err);
+
+ VkMemoryRequirements memReq;
+ m_devFuncs->vkGetBufferMemoryRequirements(m_dev, m_vbuf, &memReq);
+ VkMemoryAllocateInfo allocInfo;
+ memset(&allocInfo, 0, sizeof(allocInfo));
+ allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ allocInfo.allocationSize = memReq.size;
+
+ uint32_t memTypeIndex = uint32_t(-1);
+ const VkMemoryType *memType = physDevMemProps.memoryTypes;
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (memReq.memoryTypeBits & (1 << i)) {
+ if ((memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ && (memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ {
+ memTypeIndex = i;
+ break;
+ }
+ }
+ }
+ if (memTypeIndex == uint32_t(-1))
+ qFatal("Failed to find host visible and coherent memory type");
+
+ allocInfo.memoryTypeIndex = memTypeIndex;
+ err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_vbufMem);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate vertex buffer memory of size %u: %d", uint(allocInfo.allocationSize), err);
+
+ void *p = nullptr;
+ err = m_devFuncs->vkMapMemory(m_dev, m_vbufMem, 0, allocInfo.allocationSize, 0, &p);
+ if (err != VK_SUCCESS || !p)
+ qFatal("Failed to map vertex buffer memory: %d", err);
+ memcpy(p, vertices, sizeof(vertices));
+ m_devFuncs->vkUnmapMemory(m_dev, m_vbufMem);
+ err = m_devFuncs->vkBindBufferMemory(m_dev, m_vbuf, m_vbufMem, 0);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to bind vertex buffer memory: %d", err);
+
+ m_allocPerUbuf = aligned(UBUF_SIZE, physDevProps.limits.minUniformBufferOffsetAlignment);
+
+ bufferInfo.size = framesInFlight * m_allocPerUbuf;
+ bufferInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
+ err = m_devFuncs->vkCreateBuffer(m_dev, &bufferInfo, nullptr, &m_ubuf);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create uniform buffer: %d", err);
+ m_devFuncs->vkGetBufferMemoryRequirements(m_dev, m_ubuf, &memReq);
+ memTypeIndex = -1;
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (memReq.memoryTypeBits & (1 << i)) {
+ if ((memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ && (memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ {
+ memTypeIndex = i;
+ break;
+ }
+ }
+ }
+ if (memTypeIndex == uint32_t(-1))
+ qFatal("Failed to find host visible and coherent memory type");
+
+ allocInfo.allocationSize = qMax(memReq.size, framesInFlight * m_allocPerUbuf);
+ allocInfo.memoryTypeIndex = memTypeIndex;
+ err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_ubufMem);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate uniform buffer memory of size %u: %d", uint(allocInfo.allocationSize), err);
+
+ err = m_devFuncs->vkBindBufferMemory(m_dev, m_ubuf, m_ubufMem, 0);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to bind uniform buffer memory: %d", err);
+
+ // Now onto the pipeline.
+
+ VkPipelineCacheCreateInfo pipelineCacheInfo;
+ memset(&pipelineCacheInfo, 0, sizeof(pipelineCacheInfo));
+ pipelineCacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
+ err = m_devFuncs->vkCreatePipelineCache(m_dev, &pipelineCacheInfo, nullptr, &m_pipelineCache);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create pipeline cache: %d", err);
+
+ VkDescriptorSetLayoutBinding descLayoutBinding;
+ memset(&descLayoutBinding, 0, sizeof(descLayoutBinding));
+ descLayoutBinding.binding = 0;
+ descLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
+ descLayoutBinding.descriptorCount = 1;
+ descLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
+ VkDescriptorSetLayoutCreateInfo layoutInfo;
+ memset(&layoutInfo, 0, sizeof(layoutInfo));
+ layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
+ layoutInfo.bindingCount = 1;
+ layoutInfo.pBindings = &descLayoutBinding;
+ err = m_devFuncs->vkCreateDescriptorSetLayout(m_dev, &layoutInfo, nullptr, &m_resLayout);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create descriptor set layout: %d", err);
+
+ VkPipelineLayoutCreateInfo pipelineLayoutInfo;
+ memset(&pipelineLayoutInfo, 0, sizeof(pipelineLayoutInfo));
+ pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
+ pipelineLayoutInfo.setLayoutCount = 1;
+ pipelineLayoutInfo.pSetLayouts = &m_resLayout;
+ err = m_devFuncs->vkCreatePipelineLayout(m_dev, &pipelineLayoutInfo, nullptr, &m_pipelineLayout);
+ if (err != VK_SUCCESS)
+ qWarning("Failed to create pipeline layout: %d", err);
+
+ VkGraphicsPipelineCreateInfo pipelineInfo;
+ memset(&pipelineInfo, 0, sizeof(pipelineInfo));
+ pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
+
+ VkShaderModuleCreateInfo shaderInfo;
+ memset(&shaderInfo, 0, sizeof(shaderInfo));
+ shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
+ shaderInfo.codeSize = m_vert.size();
+ shaderInfo.pCode = reinterpret_cast<const quint32 *>(m_vert.constData());
+ VkShaderModule vertShaderModule;
+ err = m_devFuncs->vkCreateShaderModule(m_dev, &shaderInfo, nullptr, &vertShaderModule);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create vertex shader module: %d", err);
+
+ shaderInfo.codeSize = m_frag.size();
+ shaderInfo.pCode = reinterpret_cast<const quint32 *>(m_frag.constData());
+ VkShaderModule fragShaderModule;
+ err = m_devFuncs->vkCreateShaderModule(m_dev, &shaderInfo, nullptr, &fragShaderModule);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create fragment shader module: %d", err);
+
+ VkPipelineShaderStageCreateInfo stageInfo[2];
+ memset(&stageInfo, 0, sizeof(stageInfo));
+ stageInfo[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ stageInfo[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
+ stageInfo[0].module = vertShaderModule;
+ stageInfo[0].pName = "main";
+ stageInfo[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ stageInfo[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
+ stageInfo[1].module = fragShaderModule;
+ stageInfo[1].pName = "main";
+ pipelineInfo.stageCount = 2;
+ pipelineInfo.pStages = stageInfo;
+
+ VkVertexInputBindingDescription vertexBinding = {
+ 0, // binding
+ 2 * sizeof(float), // stride
+ VK_VERTEX_INPUT_RATE_VERTEX
+ };
+ VkVertexInputAttributeDescription vertexAttr = {
+ 0, // location
+ 0, // binding
+ VK_FORMAT_R32G32_SFLOAT, // 'vertices' only has 2 floats per vertex
+ 0 // offset
+ };
+ VkPipelineVertexInputStateCreateInfo vertexInputInfo;
+ memset(&vertexInputInfo, 0, sizeof(vertexInputInfo));
+ vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
+ vertexInputInfo.vertexBindingDescriptionCount = 1;
+ vertexInputInfo.pVertexBindingDescriptions = &vertexBinding;
+ vertexInputInfo.vertexAttributeDescriptionCount = 1;
+ vertexInputInfo.pVertexAttributeDescriptions = &vertexAttr;
+ pipelineInfo.pVertexInputState = &vertexInputInfo;
+
+ VkDynamicState dynStates[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
+ VkPipelineDynamicStateCreateInfo dynamicInfo;
+ memset(&dynamicInfo, 0, sizeof(dynamicInfo));
+ dynamicInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
+ dynamicInfo.dynamicStateCount = 2;
+ dynamicInfo.pDynamicStates = dynStates;
+ pipelineInfo.pDynamicState = &dynamicInfo;
+
+ VkPipelineViewportStateCreateInfo viewportInfo;
+ memset(&viewportInfo, 0, sizeof(viewportInfo));
+ viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
+ viewportInfo.viewportCount = viewportInfo.scissorCount = 1;
+ pipelineInfo.pViewportState = &viewportInfo;
+
+ VkPipelineInputAssemblyStateCreateInfo iaInfo;
+ memset(&iaInfo, 0, sizeof(iaInfo));
+ iaInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
+ iaInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
+ pipelineInfo.pInputAssemblyState = &iaInfo;
+
+ VkPipelineRasterizationStateCreateInfo rsInfo;
+ memset(&rsInfo, 0, sizeof(rsInfo));
+ rsInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
+ rsInfo.lineWidth = 1.0f;
+ pipelineInfo.pRasterizationState = &rsInfo;
+
+ VkPipelineMultisampleStateCreateInfo msInfo;
+ memset(&msInfo, 0, sizeof(msInfo));
+ msInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
+ msInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+ pipelineInfo.pMultisampleState = &msInfo;
+
+ VkPipelineDepthStencilStateCreateInfo dsInfo;
+ memset(&dsInfo, 0, sizeof(dsInfo));
+ dsInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
+ pipelineInfo.pDepthStencilState = &dsInfo;
+
+ // SrcAlpha, One
+ VkPipelineColorBlendStateCreateInfo blendInfo;
+ memset(&blendInfo, 0, sizeof(blendInfo));
+ blendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
+ VkPipelineColorBlendAttachmentState blend;
+ memset(&blend, 0, sizeof(blend));
+ blend.blendEnable = true;
+ blend.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ blend.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
+ blend.colorBlendOp = VK_BLEND_OP_ADD;
+ blend.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ blend.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
+ blend.alphaBlendOp = VK_BLEND_OP_ADD;
+ blend.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT
+ | VK_COLOR_COMPONENT_A_BIT;
+ blendInfo.attachmentCount = 1;
+ blendInfo.pAttachments = &blend;
+ pipelineInfo.pColorBlendState = &blendInfo;
+
+ pipelineInfo.layout = m_pipelineLayout;
+
+ pipelineInfo.renderPass = m_renderPass;
+
+ err = m_devFuncs->vkCreateGraphicsPipelines(m_dev, m_pipelineCache, 1, &pipelineInfo, nullptr, &m_pipeline);
+
+ m_devFuncs->vkDestroyShaderModule(m_dev, vertShaderModule, nullptr);
+ m_devFuncs->vkDestroyShaderModule(m_dev, fragShaderModule, nullptr);
+
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create graphics pipeline: %d", err);
+
+ // Now just need some descriptors.
+ VkDescriptorPoolSize descPoolSizes[] = {
+ { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1 }
+ };
+ VkDescriptorPoolCreateInfo descPoolInfo;
+ memset(&descPoolInfo, 0, sizeof(descPoolInfo));
+ descPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
+ descPoolInfo.flags = 0; // won't use vkFreeDescriptorSets
+ descPoolInfo.maxSets = 1;
+ descPoolInfo.poolSizeCount = sizeof(descPoolSizes) / sizeof(descPoolSizes[0]);
+ descPoolInfo.pPoolSizes = descPoolSizes;
+ err = m_devFuncs->vkCreateDescriptorPool(m_dev, &descPoolInfo, nullptr, &m_descriptorPool);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create descriptor pool: %d", err);
+
+ VkDescriptorSetAllocateInfo descAllocInfo;
+ memset(&descAllocInfo, 0, sizeof(descAllocInfo));
+ descAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
+ descAllocInfo.descriptorPool = m_descriptorPool;
+ descAllocInfo.descriptorSetCount = 1;
+ descAllocInfo.pSetLayouts = &m_resLayout;
+ err = m_devFuncs->vkAllocateDescriptorSets(m_dev, &descAllocInfo, &m_ubufDescriptor);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate descriptor set");
+
+ VkWriteDescriptorSet writeInfo;
+ memset(&writeInfo, 0, sizeof(writeInfo));
+ writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ writeInfo.dstSet = m_ubufDescriptor;
+ writeInfo.dstBinding = 0;
+ writeInfo.descriptorCount = 1;
+ writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
+ VkDescriptorBufferInfo bufInfo;
+ bufInfo.buffer = m_ubuf;
+ bufInfo.offset = 0; // dynamic offset is used so this is ignored
+ bufInfo.range = UBUF_SIZE;
+ writeInfo.pBufferInfo = &bufInfo;
+
+ m_devFuncs->vkUpdateDescriptorSets(m_dev, 1, &writeInfo, 0, nullptr);
+ return true;
+}
+
+void CustomTextureNode::sync()
+{
+ m_dpr = m_window->effectiveDevicePixelRatio();
+ const QSize newSize = m_window->size() * m_dpr;
+ bool needsNew = false;
+
+ if (!m_initialized) {
+ prepareShader(VertexStage);
+ prepareShader(FragmentStage);
+ initialize();
+ m_initialized = true;
+ }
+
+ if (!texture())
+ needsNew = true;
+
+ if (newSize != m_size) {
+ needsNew = true;
+ m_size = newSize;
+ }
+
+ if (needsNew) {
+ delete texture();
+ freeTexture();
+ buildTexture(m_size);
+ QSGTexture *wrapper = m_window->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture,
+ &m_texture,
+ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
+ m_size);
+ setTexture(wrapper);
+ }
+
+ m_t = float(static_cast<CustomTextureItem *>(m_item)->t());
+}
+
+void CustomTextureNode::render()
+{
+ if (!m_initialized)
+ return;
+
+ VkResult err = VK_SUCCESS;
+
+ uint currentFrameSlot = m_window->graphicsStateInfo().currentFrameSlot;
+ VkDeviceSize ubufOffset = currentFrameSlot * m_allocPerUbuf;
+ void *p = nullptr;
+ err = m_devFuncs->vkMapMemory(m_dev, m_ubufMem, ubufOffset, m_allocPerUbuf, 0, &p);
+ if (err != VK_SUCCESS || !p)
+ qFatal("Failed to map uniform buffer memory: %d", err);
+ float t = m_t;
+ memcpy(p, &t, 4);
+ m_devFuncs->vkUnmapMemory(m_dev, m_ubufMem);
+
+ VkClearValue clearColor = {{ {0, 0, 0, 1} }};
+
+ VkRenderPassBeginInfo rpBeginInfo = {};
+ rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
+ rpBeginInfo.renderPass = m_renderPass;
+ rpBeginInfo.framebuffer = m_textureFramebuffer;
+ rpBeginInfo.renderArea.extent.width = m_size.width();
+ rpBeginInfo.renderArea.extent.height = m_size.height();
+ rpBeginInfo.clearValueCount = 1;
+ rpBeginInfo.pClearValues = &clearColor;
+
+ QSGRendererInterface *rif = m_window->rendererInterface();
+ VkCommandBuffer cmdBuf = *reinterpret_cast<VkCommandBuffer *>(
+ rif->getResource(m_window, QSGRendererInterface::CommandListResource));
+
+ m_devFuncs->vkCmdBeginRenderPass(cmdBuf, &rpBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
+
+ m_devFuncs->vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline);
+
+ VkDeviceSize vbufOffset = 0;
+ m_devFuncs->vkCmdBindVertexBuffers(cmdBuf, 0, 1, &m_vbuf, &vbufOffset);
+
+ uint32_t dynamicOffset = m_allocPerUbuf * currentFrameSlot;
+ m_devFuncs->vkCmdBindDescriptorSets(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1,
+ &m_ubufDescriptor, 1, &dynamicOffset);
+
+ VkViewport vp = { 0, 0, float(m_size.width()), float(m_size.height()), 0.0f, 1.0f };
+ m_devFuncs->vkCmdSetViewport(cmdBuf, 0, 1, &vp);
+ VkRect2D scissor = { { 0, 0 }, { uint32_t(m_size.width()), uint32_t(m_size.height()) } };
+ m_devFuncs->vkCmdSetScissor(cmdBuf, 0, 1, &scissor);
+
+ m_devFuncs->vkCmdDraw(cmdBuf, 4, 1, 0, 0);
+ m_devFuncs->vkCmdEndRenderPass(cmdBuf);
+
+ // Memory barrier before the texture can be used as a source.
+ // Since we are not using a sub-pass, we have to do this explicitly.
+
+ VkImageMemoryBarrier imageTransitionBarrier = {};
+ imageTransitionBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ imageTransitionBarrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
+ imageTransitionBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
+ imageTransitionBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ imageTransitionBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+ imageTransitionBarrier.image = m_texture;
+ imageTransitionBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ imageTransitionBarrier.subresourceRange.levelCount = imageTransitionBarrier.subresourceRange.layerCount = 1;
+
+ m_devFuncs->vkCmdPipelineBarrier(cmdBuf,
+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
+ 0, 0, nullptr, 0, nullptr,
+ 1, &imageTransitionBarrier);
+}
+
+void CustomTextureNode::prepareShader(Stage stage)
+{
+ QString filename;
+ if (stage == VertexStage) {
+ filename = QLatin1String(":/scenegraph/vulkantextureimport/squircle.vert.spv");
+ } else {
+ Q_ASSERT(stage == FragmentStage);
+ filename = QLatin1String(":/scenegraph/vulkantextureimport/squircle.frag.spv");
+ }
+ QFile f(filename);
+ if (!f.open(QIODevice::ReadOnly))
+ qFatal("Failed to read shader %s", qPrintable(filename));
+
+ const QByteArray contents = f.readAll();
+
+ if (stage == VertexStage) {
+ m_vert = contents;
+ Q_ASSERT(!m_vert.isEmpty());
+ } else {
+ m_frag = contents;
+ Q_ASSERT(!m_frag.isEmpty());
+ }
+}
+
+#include "vulkantextureimport.moc"
diff --git a/examples/quick/scenegraph/rendernode/d3d12renderer.h b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h
index 7186b72c04..f604faf66f 100644
--- a/examples/quick/scenegraph/rendernode/d3d12renderer.h
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the examples of the Qt Toolkit.
+** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@@ -48,48 +48,41 @@
**
****************************************************************************/
-#ifndef D3D12RENDERER_H
-#define D3D12RENDERER_H
+#ifndef VULKANTEXTUREIMPORT_H
+#define VULKANTEXTUREIMPORT_H
-#include <qsgrendernode.h>
-#include <QQuickItem>
+#include <QtQuick/QQuickItem>
-#if QT_CONFIG(d3d12)
+class CustomTextureNode;
-#include <d3d12.h>
-#include <wrl/client.h>
-
-using namespace Microsoft::WRL;
-
-class D3D12RenderNode : public QSGRenderNode
+//! [1]
+class CustomTextureItem : public QQuickItem
{
+ Q_OBJECT
+ Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+
public:
- ~D3D12RenderNode();
+ CustomTextureItem();
- void render(const RenderState *state) override;
- void releaseResources() override;
- RenderingFlags flags() const override;
- QRectF rect() const override;
+ qreal t() const { return m_t; }
+ void setT(qreal t);
- void sync(QQuickItem *item);
+signals:
+ void tChanged();
-private:
- void init();
+protected:
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
- QQuickWindow *m_window = nullptr;
- int m_width = 0;
- int m_height = 0;
+private slots:
+ void invalidateSceneGraph();
- ID3D12Device *m_device = nullptr;
- ComPtr<ID3D12PipelineState> pipelineState;
- ComPtr<ID3D12RootSignature> rootSignature;
- ComPtr<ID3D12Resource> vertexBuffer;
- ComPtr<ID3D12Resource> constantBuffer;
- D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
- quint8 *vbPtr = nullptr;
- quint8 *cbPtr = nullptr;
-};
+private:
+ void releaseResources() override;
-#endif // d3d12
+ CustomTextureNode *m_node = nullptr;
+ qreal m_t = 0;
+};
+//! [1]
-#endif
+#endif // VULKANTEXTUREIMPORT_H
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro
new file mode 100644
index 0000000000..f2f78a6ed3
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro
@@ -0,0 +1,12 @@
+!qtConfig(vulkan): error("This example requires Qt built with Vulkan support")
+
+QT += qml quick
+
+HEADERS += vulkantextureimport.h
+SOURCES += vulkantextureimport.cpp main.cpp
+RESOURCES += vulkantextureimport.qrc
+
+
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/vulkantextureimport
+INSTALLS += target
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc
new file mode 100644
index 0000000000..a1aec6c950
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/scenegraph/vulkantextureimport">
+ <file>main.qml</file>
+ <file>squircle.vert.spv</file>
+ <file>squircle.frag.spv</file>
+ </qresource>
+</RCC>