1 | // Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef SCENE3DITEM_H |
4 | #define SCENE3DITEM_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists purely as an |
11 | // implementation detail. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include <QtCore/qpointer.h> |
18 | #include <QtQuick/QQuickItem> |
19 | #include <Qt3DCore/qentity.h> |
20 | #include <private/qglobal_p.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | class QOffscreenSurface; |
25 | |
26 | namespace Qt3DCore { |
27 | class QAspectEngine; |
28 | class QEntity; |
29 | } |
30 | |
31 | namespace Qt3DRender { |
32 | |
33 | class QCamera; |
34 | class QRenderAspect; |
35 | class Scene3DRenderer; |
36 | class Scene3DCleaner; |
37 | class QFrameGraphNode; |
38 | class QRenderSurfaceSelector; |
39 | class AspectEngineDestroyer; |
40 | |
41 | class Scene3DItem : public QQuickItem |
42 | { |
43 | Q_OBJECT |
44 | QML_NAMED_ELEMENT(Scene3D) |
45 | QML_ADDED_IN_VERSION(2, 0) |
46 | Q_PROPERTY(Qt3DCore::QEntity* entity READ entity WRITE setEntity NOTIFY entityChanged) |
47 | Q_PROPERTY(QStringList aspects READ aspects WRITE setAspects NOTIFY aspectsChanged) |
48 | Q_PROPERTY(bool multisample READ multisample WRITE setMultisample NOTIFY multisampleChanged) |
49 | Q_PROPERTY(CameraAspectRatioMode cameraAspectRatioMode READ cameraAspectRatioMode WRITE setCameraAspectRatioMode NOTIFY cameraAspectRatioModeChanged) |
50 | Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) |
51 | Q_PROPERTY(CompositingMode compositingMode READ compositingMode WRITE setCompositingMode NOTIFY compositingModeChanged REVISION(2, 14)) |
52 | Q_CLASSINFO("DefaultProperty" , "entity" ) |
53 | public: |
54 | explicit Scene3DItem(QQuickItem *parent = 0); |
55 | ~Scene3DItem(); |
56 | |
57 | QStringList aspects() const; |
58 | Qt3DCore::QEntity *entity() const; |
59 | |
60 | bool multisample() const; |
61 | void setMultisample(bool enable); |
62 | Q_INVOKABLE void setItemAreaAndDevicePixelRatio(QSize area, qreal devicePixelRatio); |
63 | bool isHoverEnabled() const; |
64 | |
65 | enum CameraAspectRatioMode { |
66 | AutomaticAspectRatio, |
67 | UserAspectRatio |
68 | }; |
69 | Q_ENUM(CameraAspectRatioMode); // LCOV_EXCL_LINE |
70 | CameraAspectRatioMode cameraAspectRatioMode() const; |
71 | |
72 | enum CompositingMode { |
73 | FBO, |
74 | Underlay |
75 | }; |
76 | Q_ENUM(CompositingMode) // LCOV_EXCL_LINE |
77 | CompositingMode compositingMode() const; |
78 | |
79 | public Q_SLOTS: |
80 | void setAspects(const QStringList &aspects); |
81 | void setEntity(Qt3DCore::QEntity *entity); |
82 | void setCameraAspectRatioMode(CameraAspectRatioMode mode); |
83 | void setHoverEnabled(bool enabled); |
84 | void setCompositingMode(CompositingMode mode); |
85 | |
86 | Q_SIGNALS: |
87 | void aspectsChanged(); |
88 | void entityChanged(); |
89 | void multisampleChanged(); |
90 | void cameraAspectRatioModeChanged(CameraAspectRatioMode mode); |
91 | void hoverEnabledChanged(); |
92 | void compositingModeChanged(); |
93 | |
94 | private Q_SLOTS: |
95 | void applyRootEntityChange(); |
96 | void requestUpdate(); |
97 | |
98 | private: |
99 | void synchronize(); |
100 | bool prepareQt3DFrame(); |
101 | QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *nodeData) override; |
102 | void setWindowSurface(QObject *rootObject); |
103 | void setCameraAspectModeHelper(); |
104 | void updateCameraAspectRatio(); |
105 | void mousePressEvent(QMouseEvent *event) override; |
106 | bool needsRender(QRenderAspect *renderAspect); |
107 | void updateWindowSurface(); |
108 | void createDummySurface(QWindow *window, QRenderSurfaceSelector *surfaceSelector); |
109 | void applyAspects(); |
110 | |
111 | QStringList m_aspects; |
112 | Qt3DCore::QEntity *m_entity; |
113 | |
114 | Qt3DCore::QAspectEngine *m_aspectEngine; |
115 | Qt3DCore::QAspectEngine *m_aspectToDelete; |
116 | QSGNode *m_lastManagerNode; |
117 | AspectEngineDestroyer *m_aspectEngineDestroyer; |
118 | |
119 | bool m_multisample; |
120 | bool m_dirty; |
121 | bool m_wasFrameProcessed; |
122 | bool m_wasSGUpdated; |
123 | |
124 | QPointer<Qt3DRender::QCamera> m_camera; |
125 | CameraAspectRatioMode m_cameraAspectRatioMode; |
126 | CompositingMode m_compositingMode; |
127 | QOffscreenSurface *m_dummySurface; |
128 | QMetaObject::Connection m_windowConnection; |
129 | qint8 m_framesToRender; |
130 | |
131 | static const qint8 ms_framesNeededToFlushPipeline = 3; |
132 | }; |
133 | |
134 | } // Qt3DRender |
135 | |
136 | QT_END_NAMESPACE |
137 | |
138 | #endif |
139 | |