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
22QT_BEGIN_NAMESPACE
23
24class QOffscreenSurface;
25
26namespace Qt3DCore {
27class QAspectEngine;
28class QEntity;
29}
30
31namespace Qt3DRender {
32
33class QCamera;
34class QRenderAspect;
35class Scene3DRenderer;
36class Scene3DCleaner;
37class QFrameGraphNode;
38class QRenderSurfaceSelector;
39class AspectEngineDestroyer;
40
41class Scene3DItem : public QQuickItem
42{
43 Q_OBJECT
44 Q_PROPERTY(Qt3DCore::QEntity* entity READ entity WRITE setEntity NOTIFY entityChanged)
45 Q_PROPERTY(QStringList aspects READ aspects WRITE setAspects NOTIFY aspectsChanged)
46 Q_PROPERTY(bool multisample READ multisample WRITE setMultisample NOTIFY multisampleChanged)
47 Q_PROPERTY(CameraAspectRatioMode cameraAspectRatioMode READ cameraAspectRatioMode WRITE setCameraAspectRatioMode NOTIFY cameraAspectRatioModeChanged)
48 Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
49 Q_PROPERTY(CompositingMode compositingMode READ compositingMode WRITE setCompositingMode NOTIFY compositingModeChanged REVISION 14)
50 Q_CLASSINFO("DefaultProperty", "entity")
51public:
52 explicit Scene3DItem(QQuickItem *parent = 0);
53 ~Scene3DItem();
54
55 QStringList aspects() const;
56 Qt3DCore::QEntity *entity() const;
57
58 bool multisample() const;
59 void setMultisample(bool enable);
60 Q_INVOKABLE void setItemAreaAndDevicePixelRatio(QSize area, qreal devicePixelRatio);
61 bool isHoverEnabled() const;
62
63 enum CameraAspectRatioMode {
64 AutomaticAspectRatio,
65 UserAspectRatio
66 };
67 Q_ENUM(CameraAspectRatioMode); // LCOV_EXCL_LINE
68 CameraAspectRatioMode cameraAspectRatioMode() const;
69
70 enum CompositingMode {
71 FBO,
72 Underlay
73 };
74 Q_ENUM(CompositingMode) // LCOV_EXCL_LINE
75 CompositingMode compositingMode() const;
76
77public Q_SLOTS:
78 void setAspects(const QStringList &aspects);
79 void setEntity(Qt3DCore::QEntity *entity);
80 void setCameraAspectRatioMode(CameraAspectRatioMode mode);
81 void setHoverEnabled(bool enabled);
82 void setCompositingMode(CompositingMode mode);
83
84Q_SIGNALS:
85 void aspectsChanged();
86 void entityChanged();
87 void multisampleChanged();
88 void cameraAspectRatioModeChanged(CameraAspectRatioMode mode);
89 void hoverEnabledChanged();
90 void compositingModeChanged();
91
92private Q_SLOTS:
93 void applyRootEntityChange();
94 void requestUpdate();
95
96private:
97 void synchronize();
98 bool prepareQt3DFrame();
99 QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *nodeData) override;
100 void setWindowSurface(QObject *rootObject);
101 void setCameraAspectModeHelper();
102 void updateCameraAspectRatio();
103 void mousePressEvent(QMouseEvent *event) override;
104 bool needsRender(QRenderAspect *renderAspect);
105 void updateWindowSurface();
106 void createDummySurface(QWindow *window, QRenderSurfaceSelector *surfaceSelector);
107 void applyAspects();
108
109 QStringList m_aspects;
110 Qt3DCore::QEntity *m_entity;
111
112 Qt3DCore::QAspectEngine *m_aspectEngine;
113 Qt3DCore::QAspectEngine *m_aspectToDelete;
114 QSGNode *m_lastManagerNode;
115 AspectEngineDestroyer *m_aspectEngineDestroyer;
116
117 bool m_multisample;
118 bool m_dirty;
119 bool m_wasFrameProcessed;
120 bool m_wasSGUpdated;
121
122 QPointer<Qt3DRender::QCamera> m_camera;
123 CameraAspectRatioMode m_cameraAspectRatioMode;
124 CompositingMode m_compositingMode;
125 QOffscreenSurface *m_dummySurface;
126 QMetaObject::Connection m_windowConnection;
127 qint8 m_framesToRender;
128
129 static const qint8 ms_framesNeededToFlushPipeline = 3;
130};
131
132} // Qt3DRender
133
134QT_END_NAMESPACE
135
136#endif
137

source code of qt3d/src/quick3d/imports/scene3d/scene3ditem_p.h