Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dinstancing.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef Q_QUICK3D_INSTANCING_H
5#define Q_QUICK3D_INSTANCING_H
6
7#include <QtQuick3D/qquick3dobject.h>
8#include <QtGui/QVector4D>
9#include <QtGui/QQuaternion>
10#include <QtGui/QColor>
11
12QT_BEGIN_NAMESPACE
13
14class QQuick3DInstancingPrivate;
15
16class Q_QUICK3D_EXPORT QQuick3DInstancing : public QQuick3DObject
17{
18 Q_OBJECT
19 Q_DECLARE_PRIVATE(QQuick3DInstancing)
20
21 QML_NAMED_ELEMENT(Instancing)
22 QML_UNCREATABLE("Instancing is Abstract")
23 QML_ADDED_IN_VERSION(6, 2)
24 Q_PROPERTY(int instanceCountOverride READ instanceCountOverride WRITE setInstanceCountOverride NOTIFY instanceCountOverrideChanged)
25 Q_PROPERTY(bool hasTransparency READ hasTransparency WRITE setHasTransparency NOTIFY hasTransparencyChanged)
26 Q_PROPERTY(bool depthSortingEnabled READ depthSortingEnabled WRITE setDepthSortingEnabled NOTIFY depthSortingEnabledChanged)
27 Q_PROPERTY(QVector3D shadowBoundsMinimum READ shadowBoundsMinimum WRITE setShadowBoundsMinimum NOTIFY
28 shadowBoundsMinimumChanged REVISION(6, 9))
29 Q_PROPERTY(QVector3D shadowBoundsMaximum READ shadowBoundsMaximum WRITE setShadowBoundsMaximum NOTIFY
30 shadowBoundsMaximumChanged REVISION(6, 9))
31
32public:
33 struct Q_QUICK3D_EXPORT InstanceTableEntry {
34 QVector4D row0;
35 QVector4D row1;
36 QVector4D row2;
37 QVector4D color;
38 QVector4D instanceData;
39
40 QVector3D getPosition() const;
41 QVector3D getScale() const;
42 QQuaternion getRotation() const;
43 QColor getColor() const;
44 };
45
46 explicit QQuick3DInstancing(QQuick3DObject *parent = nullptr);
47 ~QQuick3DInstancing() override;
48
49 QByteArray instanceBuffer(int *instanceCount);
50 int instanceCountOverride() const;
51 bool hasTransparency() const;
52 bool depthSortingEnabled() const;
53 Q_REVISION(6, 9) QVector3D shadowBoundsMinimum() const;
54 Q_REVISION(6, 9) QVector3D shadowBoundsMaximum() const;
55
56 Q_REVISION(6, 3) Q_INVOKABLE QVector3D instancePosition(int index);
57 Q_REVISION(6, 3) Q_INVOKABLE QVector3D instanceScale(int index);
58 Q_REVISION(6, 3) Q_INVOKABLE QQuaternion instanceRotation(int index);
59 Q_REVISION(6, 3) Q_INVOKABLE QColor instanceColor(int index);
60 Q_REVISION(6, 3) Q_INVOKABLE QVector4D instanceCustomData(int index);
61
62public Q_SLOTS:
63 void setInstanceCountOverride(int instanceCountOverride);
64 void setHasTransparency(bool hasTransparency);
65 void setDepthSortingEnabled(bool enabled);
66 Q_REVISION(6, 9) void setShadowBoundsMinimum(const QVector3D &newShadowBoundsMinimum);
67 Q_REVISION(6, 9) void setShadowBoundsMaximum(const QVector3D &newShadowBoundsMinimum);
68
69Q_SIGNALS:
70 void instanceTableChanged();
71 void instanceNodeDirty();
72 void instanceCountOverrideChanged();
73 void hasTransparencyChanged();
74 void depthSortingEnabledChanged();
75 Q_REVISION(6, 9) void shadowBoundsMinimumChanged();
76 Q_REVISION(6, 9) void shadowBoundsMaximumChanged();
77
78protected:
79 virtual QByteArray getInstanceBuffer(int *instanceCount) = 0;
80 void markDirty();
81 static InstanceTableEntry calculateTableEntry(const QVector3D &position,
82 const QVector3D &scale, const QVector3D &eulerRotation,
83 const QColor &color, const QVector4D &customData = {});
84 static InstanceTableEntry calculateTableEntryFromQuaternion(const QVector3D &position,
85 const QVector3D &scale, const QQuaternion &rotation,
86 const QColor &color, const QVector4D &customData = {});
87 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
88
89private:
90 const InstanceTableEntry *getInstanceEntry(int index);
91};
92
93QT_END_NAMESPACE
94
95#endif // Q_QUICK3D_INSTANCING_H
\qmlproperty vector3d Instancing::shadowBoundsMinimum