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