| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 31 | ** included in the packaging of this file. Please review the following | 
| 32 | ** information to ensure the GNU General Public License requirements will | 
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 35 | ** | 
| 36 | ** $QT_END_LICENSE$ | 
| 37 | ** | 
| 38 | ****************************************************************************/ | 
| 39 |  | 
| 40 | #ifndef SCENE3DITEM_H | 
| 41 | #define SCENE3DITEM_H | 
| 42 |  | 
| 43 | // | 
| 44 | //  W A R N I N G | 
| 45 | //  ------------- | 
| 46 | // | 
| 47 | // This file is not part of the Qt API.  It exists purely as an | 
| 48 | // implementation detail.  This header file may change from version to | 
| 49 | // version without notice, or even be removed. | 
| 50 | // | 
| 51 | // We mean it. | 
| 52 | // | 
| 53 |  | 
| 54 | #include <QtCore/qpointer.h> | 
| 55 | #include <QtQuick/QQuickItem> | 
| 56 |  | 
| 57 | QT_BEGIN_NAMESPACE | 
| 58 |  | 
| 59 | class QOffscreenSurface; | 
| 60 |  | 
| 61 | namespace Qt3DCore { | 
| 62 | class QAspectEngine; | 
| 63 | class QEntity; | 
| 64 | } | 
| 65 |  | 
| 66 | namespace Qt3DRender { | 
| 67 |  | 
| 68 | class QCamera; | 
| 69 | class QRenderAspect; | 
| 70 | class Scene3DRenderer; | 
| 71 | class Scene3DCleaner; | 
| 72 | class Scene3DView; | 
| 73 | class QFrameGraphNode; | 
| 74 | class QRenderSurfaceSelector; | 
| 75 | class AspectEngineDestroyer; | 
| 76 |  | 
| 77 | class Scene3DItem : public QQuickItem | 
| 78 | { | 
| 79 |     Q_OBJECT | 
| 80 |     Q_PROPERTY(Qt3DCore::QEntity* entity READ entity WRITE setEntity NOTIFY entityChanged) | 
| 81 |     Q_PROPERTY(QStringList aspects READ aspects WRITE setAspects NOTIFY aspectsChanged) | 
| 82 |     Q_PROPERTY(bool multisample READ multisample WRITE setMultisample NOTIFY multisampleChanged) | 
| 83 |     Q_PROPERTY(CameraAspectRatioMode cameraAspectRatioMode READ cameraAspectRatioMode WRITE setCameraAspectRatioMode NOTIFY cameraAspectRatioModeChanged) | 
| 84 |     Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) | 
| 85 |     Q_PROPERTY(CompositingMode compositingMode READ compositingMode WRITE setCompositingMode NOTIFY compositingModeChanged REVISION 14) | 
| 86 |     Q_CLASSINFO("DefaultProperty" , "entity" ) | 
| 87 | public: | 
| 88 |     explicit Scene3DItem(QQuickItem *parent = 0); | 
| 89 |     ~Scene3DItem(); | 
| 90 |  | 
| 91 |     QStringList aspects() const; | 
| 92 |     Qt3DCore::QEntity *entity() const; | 
| 93 |  | 
| 94 |     bool multisample() const; | 
| 95 |     void setMultisample(bool enable); | 
| 96 |     Q_INVOKABLE void setItemAreaAndDevicePixelRatio(QSize area, qreal devicePixelRatio); | 
| 97 |     bool isHoverEnabled() const; | 
| 98 |  | 
| 99 |     enum CameraAspectRatioMode { | 
| 100 |         AutomaticAspectRatio, | 
| 101 |         UserAspectRatio | 
| 102 |     }; | 
| 103 |     Q_ENUM(CameraAspectRatioMode); // LCOV_EXCL_LINE | 
| 104 |     CameraAspectRatioMode cameraAspectRatioMode() const; | 
| 105 |  | 
| 106 |     enum CompositingMode { | 
| 107 |         FBO, | 
| 108 |         Underlay | 
| 109 |     }; | 
| 110 |     Q_ENUM(CompositingMode) // LCOV_EXCL_LINE | 
| 111 |     CompositingMode compositingMode() const; | 
| 112 |  | 
| 113 |     void addView(Scene3DView *view); | 
| 114 |     void removeView(Scene3DView *view); | 
| 115 |  | 
| 116 | public Q_SLOTS: | 
| 117 |     void setAspects(const QStringList &aspects); | 
| 118 |     void setEntity(Qt3DCore::QEntity *entity); | 
| 119 |     void setCameraAspectRatioMode(CameraAspectRatioMode mode); | 
| 120 |     void setHoverEnabled(bool enabled); | 
| 121 |     void setCompositingMode(CompositingMode mode); | 
| 122 |  | 
| 123 | Q_SIGNALS: | 
| 124 |     void aspectsChanged(); | 
| 125 |     void entityChanged(); | 
| 126 |     void multisampleChanged(); | 
| 127 |     void cameraAspectRatioModeChanged(CameraAspectRatioMode mode); | 
| 128 |     void hoverEnabledChanged(); | 
| 129 |     void compositingModeChanged(); | 
| 130 |  | 
| 131 | private Q_SLOTS: | 
| 132 |     void applyRootEntityChange(); | 
| 133 |     void requestUpdate(); | 
| 134 |  | 
| 135 | private: | 
| 136 |     void synchronize(); | 
| 137 |     bool prepareQt3DFrame(); | 
| 138 |     QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *nodeData) override; | 
| 139 |     void setWindowSurface(QObject *rootObject); | 
| 140 |     void setCameraAspectModeHelper(); | 
| 141 |     void updateCameraAspectRatio(); | 
| 142 |     void mousePressEvent(QMouseEvent *event) override; | 
| 143 |     bool needsRender(QRenderAspect *renderAspect); | 
| 144 |     void updateWindowSurface(); | 
| 145 |     void createDummySurface(QWindow *window, QRenderSurfaceSelector *surfaceSelector); | 
| 146 |     void applyAspects(); | 
| 147 |  | 
| 148 |     QStringList m_aspects; | 
| 149 |     Qt3DCore::QEntity *m_entity; | 
| 150 |     Qt3DCore::QEntity *m_viewHolderEntity; | 
| 151 |     Qt3DRender::QFrameGraphNode *m_viewHolderFG; | 
| 152 |  | 
| 153 |     Qt3DCore::QAspectEngine *m_aspectEngine; | 
| 154 |     Qt3DCore::QAspectEngine *m_aspectToDelete; | 
| 155 |     QSGNode *m_lastManagerNode; | 
| 156 |     AspectEngineDestroyer *m_aspectEngineDestroyer; | 
| 157 |  | 
| 158 |     bool m_multisample; | 
| 159 |     bool m_dirty; | 
| 160 |     bool m_dirtyViews; | 
| 161 |     bool m_clearsWindowByDefault; | 
| 162 |     bool m_disableClearWindow; | 
| 163 |     bool m_wasFrameProcessed; | 
| 164 |     bool m_wasSGUpdated; | 
| 165 |  | 
| 166 |     QPointer<Qt3DRender::QCamera> m_camera; | 
| 167 |     CameraAspectRatioMode m_cameraAspectRatioMode; | 
| 168 |     CompositingMode m_compositingMode; | 
| 169 |     QOffscreenSurface *m_dummySurface; | 
| 170 |     QVector<Scene3DView *> m_views; | 
| 171 |     QMetaObject::Connection m_windowConnection; | 
| 172 |     qint8 m_framesToRender; | 
| 173 |  | 
| 174 |     static const qint8 ms_framesNeededToFlushPipeline = 2; | 
| 175 | }; | 
| 176 |  | 
| 177 | } // Qt3DRender | 
| 178 |  | 
| 179 | QT_END_NAMESPACE | 
| 180 |  | 
| 181 | #endif | 
| 182 |  |