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