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
qquick3dscenemanager_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#ifndef QSSGSCENEMANAGER_P_H
7#define QSSGSCENEMANAGER_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtCore/QObject>
21#include <QtCore/QSet>
22
23#include <QtQuick3D/private/qtquick3dglobal_p.h>
24
25#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
26
27#include "qquick3dnode_p.h"
28
29#include <QtCore/qpointer.h>
30
31QT_BEGIN_NAMESPACE
32
33class QSGDynamicTexture;
34class QQuickWindow;
35class QSSGBufferManager;
37class QSSGRenderRoot;
38struct QSSGRenderLayer;
39class QSSGRenderExtension;
40class QSSGRenderUserPass;
41
42class Q_QUICK3D_EXPORT QQuick3DWindowAttachment : public QObject
43{
44 Q_OBJECT
45public:
46 enum SyncResultFlag : quint32
47 {
48 None,
49 SharedResourcesDirty = 0x1,
50 ExtensionsDiry = 0x2,
51 };
52
53 using SyncResult = std::underlying_type_t<SyncResultFlag>;
54
55 explicit QQuick3DWindowAttachment(QQuickWindow *window);
56 ~QQuick3DWindowAttachment() override;
57
58 Q_INVOKABLE void preSync();
59 Q_INVOKABLE void cleanupResources();
60 Q_INVOKABLE SyncResult synchronize(QSet<QSSGRenderGraphObject *> &resourceLoaders);
61 Q_INVOKABLE void requestUpdate();
62 Q_INVOKABLE void evaluateEol();
63
64 QQuickWindow *window() const;
65
66 QSSGRenderRoot *rootNode() const { return m_rootNode; }
67
68 const std::shared_ptr<QSSGRenderContextInterface> &rci() const { return m_rci; }
69 void setRci(const std::shared_ptr<QSSGRenderContextInterface> &rciptr);
70
71 void registerSceneManager(QQuick3DSceneManager &manager);
72 void unregisterSceneManager(QQuick3DSceneManager &manager);
73
74 void queueForCleanup(QSSGRenderGraphObject *obj);
75 void queueForCleanup(QQuick3DSceneManager *manager);
76 void queueForCleanup(QSSGRenderLayer *layer);
77
78Q_SIGNALS:
79 void releaseCachedResources();
80 void renderContextInterfaceChanged();
81
82private:
83 Q_INVOKABLE void onReleaseCachedResources();
84 Q_INVOKABLE void onInvalidated();
85
86 QPointer<QQuickWindow> m_window;
87 QSSGRenderRoot *m_rootNode = nullptr;
88 std::shared_ptr<QSSGRenderContextInterface> m_rci;
89 QList<QQuick3DSceneManager *> sceneManagers;
90 QList<QQuick3DSceneManager *> sceneManagerCleanupQueue;
91 QList<QSSGRenderGraphObject *> pendingResourceCleanupQueue;
92 QSet<QSSGRenderGraphObject *> resourceCleanupQueue;
93 QList<QSSGRenderLayer *> pendingLayerCleanupQueue;
94};
95
96class Q_QUICK3D_EXPORT QQuick3DSceneManager : public QObject
97{
98 Q_OBJECT
99public:
100 using SyncResultFlag = QQuick3DWindowAttachment::SyncResultFlag;
101 using SyncResult = QQuick3DWindowAttachment::SyncResult;
102
103 explicit QQuick3DSceneManager(QObject *parent = nullptr);
104 ~QQuick3DSceneManager() override;
105
106 void setWindow(QQuickWindow *window);
107 QQuickWindow *window();
108
109 void dirtyItem(QQuick3DObject *item);
110 void requestUpdate();
111 void cleanup(QSSGRenderGraphObject *item);
112
113 void polishItems();
114 void forcePolish();
115 void sync();
116 void preSync();
117
118 SyncResult cleanupNodes();
119 SyncResult updateDirtyResourceNodes();
120 void updateDirtySpatialNodes();
121 SyncResult updateDiryExtensions();
122 SyncResult updateDirtyResourceSecondPass();
123
124 void updateDirtyResource(QQuick3DObject *resourceObject);
125 void updateDirtySpatialNode(QQuick3DNode *spatialNode);
126 void updateBoundingBoxes(QSSGBufferManager &mgr);
127
128 QQuick3DObject *lookUpNode(const QSSGRenderGraphObject *node) const;
129
130 // Where the enumerator is placed will decide the priority it gets.
131 // NOTE: Place new list types before 'Count'.
132 // NOTE: InstanceNodes are nodes that have an instance root set, we'll process these
133 // after the other nodes but before light nodes; this implies that lights are not good candidates
134 // for being instance roots...
135 enum class NodePriority { Skeleton, Other, ModelWithInstanceRoot, Lights, Count };
136 enum class ResourcePriority { TextureData, Texture, Other, Count };
137 enum class ExtensionPriority { RenderExtension, Count };
138
139 static inline size_t resourceListIndex(QSSGRenderGraphObject::Type type)
140 {
141 Q_ASSERT(!QSSGRenderGraphObject::isNodeType(type));
142
143 if (QSSGRenderGraphObject::isTexture(type))
144 return size_t(ResourcePriority::Texture);
145
146 if (type == QSSGRenderGraphObject::Type::TextureData)
147 return size_t(ResourcePriority::TextureData);
148
149 return size_t(ResourcePriority::Other);
150 }
151
152 static inline size_t nodeListIndex(QSSGRenderGraphObject::Type type)
153 {
154 Q_ASSERT(QSSGRenderGraphObject::isNodeType(type));
155
156 if (QSSGRenderGraphObject::isLight(type))
157 return size_t(NodePriority::Lights);
158
159 if (type == QSSGRenderGraphObject::Type::Skeleton)
160 return size_t(NodePriority::Skeleton);
161
162 return size_t(NodePriority::Other);
163 }
164
165 static constexpr size_t extensionListIndex(QSSGRenderGraphObject::Type type)
166 {
167 Q_ASSERT(QSSGRenderGraphObject::isExtension(type));
168
169 return size_t(ExtensionPriority::RenderExtension);
170 }
171
172 static QQuick3DWindowAttachment *getOrSetWindowAttachment(QQuickWindow &window);
173
174 QQuick3DObject *dirtyResources[size_t(ResourcePriority::Count)] {};
175 QQuick3DObject *dirtyNodes[size_t(NodePriority::Count)] {};
176 QQuick3DObject *dirtyExtensions[size_t(ExtensionPriority::Count)] {};
177 // For exceptions to the norm we create a list of resources that
178 // we get a second update.
179 // In the case of the render extensions the resources are update first and for the
180 // first time the extensions have not been run and therefore have no backend node, which
181 // we'll need to use connect the render result from the extension with the texture.
182 QSet<QQuick3DObject *> dirtySecondPassResources;
183
184 QList<QQuick3DObject *> dirtyBoundingBoxList;
185 QSet<QSSGRenderGraphObject *> cleanupNodeList;
186 QList<QSSGRenderGraphObject *> resourceCleanupQueue;
187
188 QSet<QQuick3DObject *> parentlessItems;
189 QVector<QSGDynamicTexture *> qsgDynamicTextures;
190 QHash<QSSGRenderGraphObject *, QQuick3DObject *> m_nodeMap;
191 QSet<QSSGRenderGraphObject *> resourceLoaders;
192 QList<QSSGRenderExtension *> autoRegisteredExtensions;
193 QList<QSSGRenderUserPass *> userRenderPasses;
194 QQuickWindow *m_window = nullptr;
195 QPointer<QQuick3DWindowAttachment> wattached;
196 int inputHandlingEnabled = 0; // Holds the count of active item2Ds, input disabled if zero.
197 bool sharedResourceRemoved = false;
198 bool autoRegisteredExtensionsDirty = false;
199 friend QQuick3DObject;
200
201Q_SIGNALS:
202 void needsUpdate();
203 void windowChanged();
204
205private Q_SLOTS:
206 SyncResult updateResources(QQuick3DObject **listHead);
207 void updateNodes(QQuick3DObject **listHead);
208 SyncResult updateExtensions(QQuick3DObject **listHead);
209};
210
212{
214public:
218
220
222
223private:
224 std::shared_ptr<QSSGRenderContextInterface> m_rci;
225 QPointer<QQuickWindow> m_window;
226 QList<QSSGRenderGraphObject *> m_resourceCleanupQueue;
227};
228
229QT_END_NAMESPACE
230
231QML_DECLARE_TYPE(QQuick3DSceneManager)
232
233#endif // QSSGSCENEMANAGER_P_H
\qmltype Object3D \inqmlmodule QtQuick3D \nativetype QQuick3DObject \inherits QtObject
Q_INVOKABLE void cleanupResources()
friend class QSSGRenderContextInterface
Combined button and popup list for selecting options.
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192