1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2019 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Quick 3D. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL$ 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 General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 or (at your option) any later version 20 ** approved by the KDE Free Qt Foundation. The licenses are as published by 21 ** the Free Software Foundation and appearing in the file LICENSE.GPL3 22 ** included in the packaging of this file. Please review the following 23 ** information to ensure the GNU General Public License requirements will 24 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 25 ** 26 ** $QT_END_LICENSE$ 27 ** 28 ****************************************************************************/ 29 30 #ifndef QSSGIMAGE_H 31 #define QSSGIMAGE_H 32 33 // 34 // W A R N I N G 35 // ------------- 36 // 37 // This file is not part of the Qt API. It exists purely as an 38 // implementation detail. This header file may change from version to 39 // version without notice, or even be removed. 40 // 41 // We mean it. 42 // 43 44 #include <QtQuick3D/qquick3dobject.h> 45 #include <QtQuick/private/qquickitemchangelistener_p.h> 46 #include <QtQuick/QSGNode> 47 #include <QtCore/QUrl> 48 #include <QtCore/QPointer> 49 50 QT_BEGIN_NAMESPACE 51 52 class QQuickItem; 53 class QSGLayer; 54 struct QSSGRenderImage; 55 class Q_QUICK3D_EXPORT QQuick3DTexture : public QQuick3DObject, public QQuickItemChangeListener 56 { 57 Q_OBJECT 58 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) 59 Q_PROPERTY(QQuickItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged) 60 Q_PROPERTY(float scaleU READ scaleU WRITE setScaleU NOTIFY scaleUChanged) 61 Q_PROPERTY(float scaleV READ scaleV WRITE setScaleV NOTIFY scaleVChanged) 62 Q_PROPERTY(MappingMode mappingMode READ mappingMode WRITE setMappingMode NOTIFY mappingModeChanged) 63 Q_PROPERTY(TilingMode tilingModeHorizontal READ horizontalTiling WRITE setHorizontalTiling NOTIFY horizontalTilingChanged) 64 Q_PROPERTY(TilingMode tilingModeVertical READ verticalTiling WRITE setVerticalTiling NOTIFY verticalTilingChanged) 65 Q_PROPERTY(float rotationUV READ rotationUV WRITE setRotationUV NOTIFY rotationUVChanged) 66 Q_PROPERTY(float positionU READ positionU WRITE setPositionU NOTIFY positionUChanged) 67 Q_PROPERTY(float positionV READ positionV WRITE setPositionV NOTIFY positionVChanged) 68 Q_PROPERTY(float pivotU READ pivotU WRITE setPivotU NOTIFY pivotUChanged) 69 Q_PROPERTY(float pivotV READ pivotV WRITE setPivotV NOTIFY pivotVChanged) 70 Q_PROPERTY(bool flipV READ flipV WRITE setFlipV NOTIFY flipVChanged) 71 Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged) 72 73 public: 74 enum MappingMode 75 { 76 UV = 0, 77 Environment = 1, 78 LightProbe = 2, 79 }; 80 Q_ENUM(MappingMode) 81 82 enum TilingMode 83 { 84 ClampToEdge = 1, 85 MirroredRepeat, 86 Repeat 87 }; 88 Q_ENUM(TilingMode) 89 90 enum Format { 91 Automatic = 0, 92 R8, 93 R16, 94 R16F, 95 R32I, 96 R32UI, 97 R32F, 98 RG8, 99 RGBA8, 100 RGB8, 101 SRGB8, 102 SRGB8A8, 103 RGB565, 104 RGBA5551, 105 Alpha8, 106 Luminance8, 107 Luminance16, 108 LuminanceAlpha8, 109 RGBA16F, 110 RG16F, 111 RG32F, 112 RGB32F, 113 RGBA32F, 114 R11G11B10, 115 RGB9E5, 116 RGBA_DXT1, 117 RGB_DXT1, 118 RGBA_DXT3, 119 RGBA_DXT5, 120 Depth16, 121 Depth24, 122 Depth32, 123 Depth24Stencil8 124 }; 125 Q_ENUM(Format) 126 127 explicit QQuick3DTexture(QQuick3DObject *parent = nullptr); 128 ~QQuick3DTexture() override; 129 130 QUrl source() const; 131 QQuickItem *sourceItem() const; 132 float scaleU() const; 133 float scaleV() const; 134 MappingMode mappingMode() const; 135 TilingMode horizontalTiling() const; 136 TilingMode verticalTiling() const; 137 float rotationUV() const; 138 float positionU() const; 139 float positionV() const; 140 float pivotU() const; 141 float pivotV() const; 142 bool flipV() const; 143 144 QSSGRenderImage *getRenderImage(); 145 146 Format format() const; 147 148 public Q_SLOTS: 149 void setSource(const QUrl &source); 150 void setSourceItem(QQuickItem *sourceItem); 151 void setScaleU(float scaleU); 152 void setScaleV(float scaleV); 153 void setMappingMode(MappingMode mappingMode); 154 void setHorizontalTiling(TilingMode tilingModeHorizontal); 155 void setVerticalTiling(TilingMode tilingModeVertical); 156 void setRotationUV(float rotationUV); 157 void setPositionU(float positionU); 158 void setPositionV(float positionV); 159 void setPivotU(float pivotU); 160 void setPivotV(float pivotV); 161 void setFlipV(bool flipV); 162 void setFormat(Format format); 163 164 Q_SIGNALS: 165 void sourceChanged(); 166 void sourceItemChanged(); 167 void scaleUChanged(); 168 void scaleVChanged(); 169 void mappingModeChanged(); 170 void horizontalTilingChanged(); 171 void verticalTilingChanged(); 172 void rotationUVChanged(); 173 void positionUChanged(); 174 void positionVChanged(); 175 void pivotUChanged(); 176 void pivotVChanged(); 177 void flipVChanged(); 178 void formatChanged(); 179 180 protected: 181 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override; 182 void markAllDirty() override; 183 void itemChange(ItemChange change, const ItemChangeData &value) override; 184 185 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &geometry) override; 186 187 private Q_SLOTS: 188 void sourceItemDestroyed(QObject *item); 189 190 private: 191 void createLayerTexture(); 192 193 enum class DirtyFlag { 194 TransformDirty = (1 << 0), 195 SourceDirty = (1 << 1), 196 SourceItemDirty = (1 << 2) 197 }; 198 Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag) 199 200 QUrl m_source; 201 QQuickItem *m_sourceItem = nullptr; 202 bool m_sourceItemReparented = false; 203 bool m_sourceItemRefed = false; 204 QSGLayer *m_layer = nullptr; 205 float m_scaleU = 1.0f; 206 float m_scaleV = 1.0f; 207 MappingMode m_mappingMode = UV; 208 TilingMode m_tilingModeHorizontal = ClampToEdge; 209 TilingMode m_tilingModeVertical = ClampToEdge; 210 float m_rotationUV = 0; 211 float m_positionU = 0; 212 float m_positionV = 0; 213 float m_pivotU = 0; 214 float m_pivotV = 0; 215 bool m_flipV = false; 216 Format m_format = Automatic; 217 DirtyFlags m_dirtyFlags = DirtyFlags(DirtyFlag::TransformDirty) 218 | DirtyFlags(DirtyFlag::SourceDirty); 219 QMetaObject::Connection m_textureProviderConnection; 220 QMetaObject::Connection m_textureUpdateConnection; 221 QSharedPointer<QQuick3DSceneManager> m_sceneManagerForLayer; 222 QMetaObject::Connection m_sceneManagerWindowChangeConnection; 223 QQuickItem *m_initializedSourceItem = nullptr; 224 QSizeF m_initializedSourceItemSize; 225 void trySetSourceParent(); 226 }; 227 228 QT_END_NAMESPACE 229 230 #endif // QSSGIMAGE_H 231