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 QSSGRenderUserPassBase;
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 QQuick3DRenderExtension;
97class Q_QUICK3D_EXPORT QQuick3DSceneManager : public QObject
98{
99 Q_OBJECT
100public:
101 using SyncResultFlag = QQuick3DWindowAttachment::SyncResultFlag;
102 using SyncResult = QQuick3DWindowAttachment::SyncResult;
103
104 explicit QQuick3DSceneManager(QObject *parent = nullptr);
105 ~QQuick3DSceneManager() override;
106
107 void setWindow(QQuickWindow *window);
108 QQuickWindow *window();
109
110 void dirtyItem(QQuick3DObject *item);
111 void requestUpdate();
112 void cleanup(QSSGRenderGraphObject *item);
113
114 void polishItems();
115 void forcePolish();
116 void sync();
117 void preSync();
118
119 SyncResult cleanupNodes();
120 SyncResult updateDirtyResourceNodes();
121 void updateDirtySpatialNodes();
122 SyncResult updateDiryExtensions();
123 SyncResult updateDirtyResourceSecondPass();
124
125 void updateDirtyResource(QQuick3DObject *resourceObject);
126 void updateDirtySpatialNode(QQuick3DNode *spatialNode);
127 void updateBoundingBoxes(QSSGBufferManager &mgr);
128
129 QQuick3DObject *lookUpNode(const QSSGRenderGraphObject *node) const;
130
131 // Where the enumerator is placed will decide the priority it gets.
132 // NOTE: Place new list types before 'Count'.
133 // NOTE: InstanceNodes are nodes that have an instance root set, we'll process these
134 // after the other nodes but before light nodes; this implies that lights are not good candidates
135 // for being instance roots...
136 enum class NodePriority { Skeleton, Other, ModelWithInstanceRoot, Lights, Count };
137 enum class ResourcePriority { TextureData, Texture, Other, Count };
138 enum class ExtensionPriority { RenderExtension, Count };
139
140 static inline size_t resourceListIndex(QSSGRenderGraphObject::Type type)
141 {
142 Q_ASSERT(!QSSGRenderGraphObject::isNodeType(type));
143
144 if (QSSGRenderGraphObject::isTexture(type)
145 || type == QSSGRenderGraphObject::Type::ShaderStorageBuffer
146 || type == QSSGRenderGraphObject::Type::ShaderStorageImage) {
147 return size_t(ResourcePriority::Texture);
148 }
149
150 if (type == QSSGRenderGraphObject::Type::TextureData)
151 return size_t(ResourcePriority::TextureData);
152
153 // The RenderPassTexture is specific to the render pass API and not a "Texture" type,
154 // we still want it to be processed in the same priority as other textures, so we return the same index.
155 if (type == QSSGRenderGraphObject::Type::RenderPassTexture)
156 return size_t(ResourcePriority::Texture);
157
158 return size_t(ResourcePriority::Other);
159 }
160
161 static inline size_t nodeListIndex(QSSGRenderGraphObject::Type type)
162 {
163 Q_ASSERT(QSSGRenderGraphObject::isNodeType(type));
164
165 if (QSSGRenderGraphObject::isLight(type))
166 return size_t(NodePriority::Lights);
167
168 if (type == QSSGRenderGraphObject::Type::Skeleton)
169 return size_t(NodePriority::Skeleton);
170
171 return size_t(NodePriority::Other);
172 }
173
174 static constexpr size_t extensionListIndex(QSSGRenderGraphObject::Type type)
175 {
176 Q_ASSERT(QSSGRenderGraphObject::isExtension(type));
177
178 return size_t(ExtensionPriority::RenderExtension);
179 }
180
181 static QQuick3DWindowAttachment *getOrSetWindowAttachment(QQuickWindow &window);
182
183 QQuick3DObject *dirtyResources[size_t(ResourcePriority::Count)] {};
184 QQuick3DObject *dirtyNodes[size_t(NodePriority::Count)] {};
185 QQuick3DObject *dirtyExtensions[size_t(ExtensionPriority::Count)] {};
186 // For exceptions to the norm we create a list of resources that
187 // we get a second update.
188 // In the case of the render extensions the resources are update first and for the
189 // first time the extensions have not been run and therefore have no backend node, which
190 // we'll need to use connect the render result from the extension with the texture.
191 QSet<QQuick3DObject *> dirtySecondPassResources;
192
193 QList<QQuick3DObject *> dirtyBoundingBoxList;
194 QSet<QSSGRenderGraphObject *> cleanupNodeList;
195 QList<QSSGRenderGraphObject *> resourceCleanupQueue;
196
197 QSet<QQuick3DObject *> parentlessItems;
198 QVector<QSGDynamicTexture *> qsgDynamicTextures;
199 QHash<QSSGRenderGraphObject *, QQuick3DObject *> m_nodeMap;
200 QSet<QSSGRenderGraphObject *> resourceLoaders;
201 QList<QSSGRenderExtension *> autoRegisteredExtensions;
202 QList<QSSGRenderUserPassBase *> userRenderPasses;
203 QQuickWindow *m_window = nullptr;
204 QPointer<QQuick3DWindowAttachment> wattached;
205 int inputHandlingEnabled = 0; // Holds the count of active item2Ds, input disabled if zero.
206 bool sharedResourceRemoved = false;
207 bool autoRegisteredExtensionsDirty = false;
208 bool userRenderPassesDirty = true;
209 friend QQuick3DObject;
210 struct LightmapSourceTracker
211 {
212 QString lightmapSource;
213 bool isDirty = true;
214 } lightmapSourceTracker;
215
216Q_SIGNALS:
217 void needsUpdate();
218 void windowChanged();
219
220private Q_SLOTS:
221 SyncResult updateResources(QQuick3DObject **listHead);
222 void updateNodes(QQuick3DObject **listHead);
223 SyncResult updateExtensions(QQuick3DObject **listHead);
224};
225
227{
229public:
233
235
237
238private:
239 std::shared_ptr<QSSGRenderContextInterface> m_rci;
240 QPointer<QQuickWindow> m_window;
241 QList<QSSGRenderGraphObject *> m_resourceCleanupQueue;
242};
243
244QT_END_NAMESPACE
245
246QML_DECLARE_TYPE(QQuick3DSceneManager)
247
248#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(QDateTime::Data, Q_RELOCATABLE_TYPE)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192