Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquick3dviewport_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 QSSGVIEW3D_H
5#define QSSGVIEW3D_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 <QtQuick/QQuickItem>
19#include <QtCore/qurl.h>
20
21#include <QtQuick3D/qtquick3dglobal.h>
22#include <QtQuick3D/private/qquick3dpickresult_p.h>
23#include <QtQuick/private/qquickshadereffectsource_p.h>
24
28
30
31class QSSGView3DPrivate;
32class QQuick3DCamera;
34class QQuick3DNode;
39
43
44class Q_QUICK3D_EXPORT QQuick3DViewport : public QQuickItem
45{
47 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false FINAL)
48 Q_PROPERTY(QQuick3DCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged FINAL)
49 Q_PROPERTY(QQuick3DSceneEnvironment *environment READ environment WRITE setEnvironment NOTIFY environmentChanged FINAL)
50 Q_PROPERTY(QQuick3DNode *scene READ scene NOTIFY sceneChanged)
51 Q_PROPERTY(QQuick3DNode *importScene READ importScene WRITE setImportScene NOTIFY importSceneChanged FINAL)
52 Q_PROPERTY(RenderMode renderMode READ renderMode WRITE setRenderMode NOTIFY renderModeChanged FINAL)
53 Q_PROPERTY(QQuickShaderEffectSource::Format renderFormat READ renderFormat WRITE setRenderFormat NOTIFY renderFormatChanged FINAL REVISION(6, 4))
54 Q_PROPERTY(QQuick3DRenderStats *renderStats READ renderStats CONSTANT)
55 Q_PROPERTY(QQmlListProperty<QQuick3DObject> extensions READ extensions FINAL REVISION(6, 6))
56 Q_CLASSINFO("DefaultProperty", "data")
57
58 QML_NAMED_ELEMENT(View3D)
59
60public:
65 Inline
66 };
67 Q_ENUM(RenderMode)
68
69 explicit QQuick3DViewport(QQuickItem *parent = nullptr);
70 ~QQuick3DViewport() override;
71
73
74 QQuick3DCamera *camera() const;
75 QQuick3DSceneEnvironment *environment() const;
76 QQuick3DNode *scene() const;
77 QQuick3DNode *importScene() const;
78 RenderMode renderMode() const;
79 Q_REVISION(6, 4) QQuickShaderEffectSource::Format renderFormat() const;
80 QQuick3DRenderStats *renderStats() const;
81
82 QQuick3DSceneRenderer *createRenderer() const;
83
84 bool isTextureProvider() const override;
85 QSGTextureProvider *textureProvider() const override;
86 void releaseResources() override;
87
88 Q_INVOKABLE QVector3D mapFrom3DScene(const QVector3D &scenePos) const;
89 Q_INVOKABLE QVector3D mapTo3DScene(const QVector3D &viewPos) const;
90
91 Q_INVOKABLE QQuick3DPickResult pick(float x, float y) const;
92 Q_REVISION(6, 2) Q_INVOKABLE QList<QQuick3DPickResult> pickAll(float x, float y) const;
93 Q_REVISION(6, 2) Q_INVOKABLE QQuick3DPickResult rayPick(const QVector3D &origin, const QVector3D &direction) const;
94 Q_REVISION(6, 2) Q_INVOKABLE QList<QQuick3DPickResult> rayPickAll(const QVector3D &origin, const QVector3D &direction) const;
95
96 void processPointerEventFromRay(const QVector3D &origin, const QVector3D &direction, QPointerEvent *event);
97
98 QQuick3DLightmapBaker *maybeLightmapBaker();
99 QQuick3DLightmapBaker *lightmapBaker();
100
101 Q_INVOKABLE void bakeLightmap();
102
104
105 // Private helpers
106 [[nodiscard]] bool extensionListDirty() const { return m_extensionListDirty; }
107 [[nodiscard]] const QList<QQuick3DObject *> &extensionList() const { return m_extensions; }
108 void clearExtensionListDirty() { m_extensionListDirty = false; }
109
110protected:
111 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
112 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
114
115 bool event(QEvent *) override;
116 void componentComplete() override;
117
118public Q_SLOTS:
119 void setCamera(QQuick3DCamera *camera);
120 void setEnvironment(QQuick3DSceneEnvironment * environment);
121 void setImportScene(QQuick3DNode *inScene);
122 void setRenderMode(QQuick3DViewport::RenderMode renderMode);
123 Q_REVISION(6, 4) void setRenderFormat(QQuickShaderEffectSource::Format format);
124 void cleanupDirectRenderer();
125
126 // Setting this true enables picking for all the models, regardless of
127 // the models pickable property.
128 void setGlobalPickingEnabled(bool isEnabled);
129
131 void invalidateSceneGraph();
132 void updateInputProcessing();
133 void onReleaseCachedResources();
134
136 void cameraChanged();
137 void environmentChanged();
138 void sceneChanged();
139 void importSceneChanged();
140 void renderModeChanged();
141 Q_REVISION(6, 4) void renderFormatChanged();
142
143private:
145
146 Q_DISABLE_COPY(QQuick3DViewport)
147 struct SubsceneInfo {
148 QQuick3DObject* obj = nullptr;
149 QVarLengthArray<QPointF, 16> eventPointScenePositions;
150 };
151 QQuick3DSceneRenderer *getRenderer() const;
152 void updateDynamicTextures();
153 QSGNode *setupOffscreenRenderer(QSGNode *node);
154 QSGNode *setupInlineRenderer(QSGNode *node);
155 void setupDirectRenderer(RenderMode mode);
156 bool checkIsVisible() const;
157 bool internalPick(QPointerEvent *event, const QVector3D &origin = QVector3D(), const QVector3D &direction = QVector3D()) const;
160 bool forwardEventToSubscenes(QPointerEvent *event,
161 bool useRayPicking,
163 const QFlatMap<QQuickItem *, SubsceneInfo> &visitedSubscenes) const;
164
165 void processPickedObject(const QSSGRenderGraphObject *backendObject,
166 const QSSGRenderPickResult &pickResult,
167 int pointIndex,
169 QFlatMap<QQuickItem *, SubsceneInfo> &vistedSubscenes) const;
170 QQuickItem *getSubSceneRootItem(QQuick3DMaterial *material) const;
171 QQuick3DPickResult processPickResult(const QSSGRenderPickResult &pickResult) const;
172 QQuick3DObject *findFrontendNode(const QSSGRenderGraphObject *backendObject) const;
173 QQuick3DSceneManager *findChildSceneManager(QQuick3DObject *inObject, QQuick3DSceneManager *manager = nullptr);
174 QQuick3DCamera *m_camera = nullptr;
175 QQuick3DSceneEnvironment *m_environment = nullptr;
176 QQuick3DSceneRootNode *m_sceneRoot = nullptr;
177 QQuick3DNode *m_importScene = nullptr;
178 mutable SGFramebufferObjectNode *m_node = nullptr;
179 mutable QQuick3DSGRenderNode *m_renderNode = nullptr;
180 mutable QQuick3DSGDirectRenderer *m_directRenderer = nullptr;
181 bool m_renderModeDirty = false;
182 RenderMode m_renderMode = Offscreen;
184 QQuick3DRenderStats *m_renderStats = nullptr;
185 bool m_enableInputProcessing = false;
186 QQuick3DLightmapBaker *m_lightmapBaker = nullptr;
187 QList<QQuick3DObject *> m_extensions;
188 bool m_extensionListDirty = false;
190};
191
193
194#endif // QSSGVIEW3D_H
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
\inmodule QtCore
Definition qcoreevent.h:45
Definition qlist.h:74
A base class for pointer events.
Definition qevent.h:73
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
\qmltype Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DObject \inherits QtObject
const QList< QQuick3DObject * > & extensionList() const
QQmlListProperty< QObject > data()
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
virtual QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *)
Called on the render thread when it is time to sync the state of the item with the scene graph.
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
Q_REVISION(2, 1) void activeFocusOnTabChanged(bool)
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:143
\inmodule QtCore\reentrant
Definition qrect.h:483
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
The QSGTextureProvider class encapsulates texture based entities in QML.
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Format
Definition ddsheader.h:14
QCamera * camera
Definition camera.cpp:19
direction
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static int pick(bool vertical, const QSize &size)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLint y
struct _cl_event * event
GLhandleARB obj
[2]
#define QML_NAMED_ELEMENT(NAME)
#define Q_QUICK3D_PROFILE_ID
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_CLASSINFO(name, value)
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
QGraphicsScene scene
[0]
QNetworkAccessManager manager
QSvgRenderer * renderer
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
\inmodule QtQuick
Definition qquickitem.h:158