Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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#if QT_CONFIG(quick_shadereffect)
24#include <QtQuick/private/qquickshadereffectsource_p.h>
25#endif
26
27#include <QtQuick3DRuntimeRender/private/qssgrenderpickresult_p.h>
28
32
34
35class QSSGView3DPrivate;
36class QQuick3DCamera;
38class QQuick3DNode;
43
47
48class Q_QUICK3D_EXPORT QQuick3DViewport : public QQuickItem
49{
51 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false FINAL)
52 Q_PROPERTY(QQuick3DCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged FINAL)
53 Q_PROPERTY(QQuick3DSceneEnvironment *environment READ environment WRITE setEnvironment NOTIFY environmentChanged FINAL)
54 Q_PROPERTY(QQuick3DNode *scene READ scene NOTIFY sceneChanged)
55 Q_PROPERTY(QQuick3DNode *importScene READ importScene WRITE setImportScene NOTIFY importSceneChanged FINAL)
56 Q_PROPERTY(RenderMode renderMode READ renderMode WRITE setRenderMode NOTIFY renderModeChanged FINAL)
57#if QT_CONFIG(quick_shadereffect)
58 Q_PROPERTY(QQuickShaderEffectSource::Format renderFormat READ renderFormat WRITE setRenderFormat NOTIFY renderFormatChanged FINAL REVISION(6, 4))
59#endif
60 Q_PROPERTY(QQuick3DRenderStats *renderStats READ renderStats CONSTANT)
61 Q_PROPERTY(QQmlListProperty<QQuick3DObject> extensions READ extensions FINAL REVISION(6, 6))
62 Q_PROPERTY(int explicitTextureWidth READ explicitTextureWidth WRITE setExplicitTextureWidth NOTIFY explicitTextureWidthChanged FINAL REVISION(6, 7))
63 Q_PROPERTY(int explicitTextureHeight READ explicitTextureHeight WRITE setExplicitTextureHeight NOTIFY explicitTextureHeightChanged FINAL REVISION(6, 7))
64 Q_PROPERTY(QSize effectiveTextureSize READ effectiveTextureSize NOTIFY effectiveTextureSizeChanged FINAL REVISION(6, 7))
65 Q_CLASSINFO("DefaultProperty", "data")
66
67 QML_NAMED_ELEMENT(View3D)
68
69public:
76 Q_ENUM(RenderMode)
77
78 explicit QQuick3DViewport(QQuickItem *parent = nullptr);
79 ~QQuick3DViewport() override;
80
81 QQmlListProperty<QObject> data();
82
83 QQuick3DCamera *camera() const;
84 QQuick3DSceneEnvironment *environment() const;
85 QQuick3DNode *scene() const;
86 QQuick3DNode *importScene() const;
87 RenderMode renderMode() const;
88#if QT_CONFIG(quick_shadereffect)
89 Q_REVISION(6, 4) QQuickShaderEffectSource::Format renderFormat() const;
90#endif
91 QQuick3DRenderStats *renderStats() const;
92
93 QQuick3DSceneRenderer *createRenderer() const;
94
95 bool isTextureProvider() const override;
96 QSGTextureProvider *textureProvider() const override;
97 void releaseResources() override;
98
99 Q_INVOKABLE QVector3D mapFrom3DScene(const QVector3D &scenePos) const;
100 Q_INVOKABLE QVector3D mapTo3DScene(const QVector3D &viewPos) const;
101
102 Q_INVOKABLE QQuick3DPickResult pick(float x, float y) const;
104 Q_REVISION(6, 8) Q_INVOKABLE QList<QQuick3DPickResult> pickSubset(float x, float y, const QJSValue &models) const;
105 Q_REVISION(6, 2) Q_INVOKABLE QList<QQuick3DPickResult> pickAll(float x, float y) const;
106 Q_REVISION(6, 2) Q_INVOKABLE QQuick3DPickResult rayPick(const QVector3D &origin, const QVector3D &direction) const;
107 Q_REVISION(6, 2) Q_INVOKABLE QList<QQuick3DPickResult> rayPickAll(const QVector3D &origin, const QVector3D &direction) const;
108
109 void processPointerEventFromRay(const QVector3D &origin, const QVector3D &direction, QPointerEvent *event);
110 bool singlePointPick(QSinglePointEvent *event, const QVector3D &origin, const QVector3D &direction);
111
112 Q_REVISION(6, 8) Q_INVOKABLE void setTouchpoint(QQuickItem *target, const QPointF &position, int pointId, bool active);
113
114 QQuick3DLightmapBaker *maybeLightmapBaker();
115 QQuick3DLightmapBaker *lightmapBaker();
116
117 Q_INVOKABLE void bakeLightmap();
118
120
121 Q_REVISION(6, 7) int explicitTextureWidth() const;
122 Q_REVISION(6, 7) int explicitTextureHeight() const;
123 Q_REVISION(6, 7) QSize effectiveTextureSize() const;
124
125 // Private helpers
126 [[nodiscard]] bool extensionListDirty() const { return m_extensionListDirty; }
127 [[nodiscard]] const QList<QQuick3DObject *> &extensionList() const { return m_extensions; }
128 void clearExtensionListDirty() { m_extensionListDirty = false; }
129
130 Q_REVISION(6, 7) Q_INVOKABLE void rebuildExtensionList();
131
132protected:
133 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
134 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
135 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override;
136
137 bool event(QEvent *) override;
138 void componentComplete() override;
139
140public Q_SLOTS:
141 void setCamera(QQuick3DCamera *camera);
142 void setEnvironment(QQuick3DSceneEnvironment * environment);
143 void setImportScene(QQuick3DNode *inScene);
144 void setRenderMode(QQuick3DViewport::RenderMode renderMode);
145#if QT_CONFIG(quick_shadereffect)
146 Q_REVISION(6, 4) void setRenderFormat(QQuickShaderEffectSource::Format format);
147#endif
148 Q_REVISION(6, 7) void setExplicitTextureWidth(int width);
149 Q_REVISION(6, 7) void setExplicitTextureHeight(int height);
150 void cleanupDirectRenderer();
151
152 // Setting this true enables picking for all the models, regardless of
153 // the models pickable property.
154 void setGlobalPickingEnabled(bool isEnabled);
155
157 void invalidateSceneGraph();
158 void updateInputProcessing();
159 void onReleaseCachedResources();
160
162 void cameraChanged();
163 void environmentChanged();
164 void sceneChanged();
165 void importSceneChanged();
166 void renderModeChanged();
167 Q_REVISION(6, 4) void renderFormatChanged();
168 Q_REVISION(6, 7) void explicitTextureWidthChanged();
169 Q_REVISION(6, 7) void explicitTextureHeightChanged();
170 Q_REVISION(6, 7) void effectiveTextureSizeChanged();
171
172private:
173 void setMultiViewCameras(QQuick3DCamera **firstCamera, int count);
174
176 friend class QQuick3DXrManager;
179
180 Q_DISABLE_COPY(QQuick3DViewport)
181 struct SubsceneInfo {
182 QQuick3DObject* obj = nullptr;
183 QVarLengthArray<QPointF, 16> eventPointScenePositions;
184 };
185 QQuick3DSceneRenderer *getRenderer() const;
186 void updateDynamicTextures();
187 QSGNode *setupOffscreenRenderer(QSGNode *node);
188 QSGNode *setupInlineRenderer(QSGNode *node);
189 void setupDirectRenderer(RenderMode mode);
190 bool checkIsVisible() const;
191 bool internalPick(QPointerEvent *event, const QVector3D &origin = QVector3D(), const QVector3D &direction = QVector3D()) const;
192 QPair<QQuickItem *, QPointF> getItemAndPosition(const QSSGRenderPickResult &pickResult);
193 QVarLengthArray<QSSGRenderPickResult, 20> getPickResults(QQuick3DSceneRenderer *renderer, const QVector3D &origin, const QVector3D &direction) const;
194 QVarLengthArray<QSSGRenderPickResult, 20> getPickResults(QQuick3DSceneRenderer *renderer, const QEventPoint &eventPoint) const;
195 bool forwardEventToSubscenes(QPointerEvent *event,
196 bool useRayPicking,
198 const QFlatMap<QQuickItem *, SubsceneInfo> &visitedSubscenes) const;
199
200 void processPickedObject(const QSSGRenderPickResult &pickResult,
201 int pointIndex,
203 QFlatMap<QQuickItem *, SubsceneInfo> &vistedSubscenes) const;
204 QQuickItem *getSubSceneRootItem(QQuick3DMaterial *material) const;
205 QQuick3DPickResult getNearestPickResult(const QVarLengthArray<QSSGRenderPickResult, 20> &pickResults) const;
206 QQuick3DPickResult processPickResult(const QSSGRenderPickResult &pickResult) const;
207 QQuick3DObject *findFrontendNode(const QSSGRenderGraphObject *backendObject) const;
208 QQuick3DSceneManager *findChildSceneManager(QQuick3DObject *inObject, QQuick3DSceneManager *manager = nullptr);
209 QQuick3DCamera *m_camera = nullptr;
210 QVarLengthArray<QQuick3DCamera *, 2> m_multiViewCameras;
211 QQuick3DSceneEnvironment *m_environment = nullptr;
212 QQuick3DSceneRootNode *m_sceneRoot = nullptr;
213 QQuick3DNode *m_importScene = nullptr;
214 mutable SGFramebufferObjectNode *m_node = nullptr;
215 mutable QQuick3DSGRenderNode *m_renderNode = nullptr;
216 mutable QQuick3DSGDirectRenderer *m_directRenderer = nullptr;
217 bool m_renderModeDirty = false;
218 RenderMode m_renderMode = Offscreen;
219#if QT_CONFIG(quick_shadereffect)
221#endif
222 int m_explicitTextureWidth = 0;
223 int m_explicitTextureHeight = 0;
224 QSize m_effectiveTextureSize;
225 float m_widthMultiplier = 1.0f;
226 float m_heightMultiplier = 1.0f;
227 QQuick3DRenderStats *m_renderStats = nullptr;
228 bool m_enableInputProcessing = false;
229 QQuick3DLightmapBaker *m_lightmapBaker = nullptr;
230 QList<QQuick3DObject *> m_extensions;
231 bool m_extensionListDirty = false;
232
233 struct TouchState {
234 QQuickItem *target = nullptr;
236 bool isPressed = false;
237 };
238 QPointingDevice *m_syntheticTouchDevice = nullptr;
239 QVarLengthArray<TouchState, 2> m_touchState{2};
240
242};
243
245
246#endif // QSSGVIEW3D_H
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
\inmodule QtCore
Definition qcoreevent.h:45
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
Definition qlist.h:76
\inmodule QtCore\reentrant
Definition qpoint.h:217
A base class for pointer events.
Definition qevent.h:73
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
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
Q_REVISION(6, 7) void setExplicitTextureWidth(int width)
Q_REVISION(6, 7) Q_INVOKABLE void rebuildExtensionList()
QQmlListProperty< QObject > data()
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:144
\inmodule QtCore\reentrant
Definition qrect.h:484
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
The QSGTextureProvider class encapsulates texture based entities in QML.
A base class for pointer events containing a single point, such as mouse events.
Definition qevent.h:109
\inmodule QtCore
Definition qsize.h:25
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 height
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei width
GLenum target
GLint GLsizei GLsizei GLenum format
GLint y
struct _cl_event * event
GLhandleARB obj
[2]
#define QML_NAMED_ELEMENT(NAME)
#define Q_QUICK3D_PROFILE_ID
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#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
QSqlQueryModel * model
[16]
QGraphicsScene scene
[0]
QNetworkAccessManager manager
QSvgRenderer * renderer
[0]
\inmodule QtQuick
Definition qquickitem.h:159