| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKSHADEREFFECT_P_P_H |
| 5 | #define QQUICKSHADEREFFECT_P_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <private/qtquickglobal_p.h> |
| 19 | |
| 20 | QT_REQUIRE_CONFIG(quick_shadereffect); |
| 21 | |
| 22 | #include <private/qquickshadereffect_p.h> |
| 23 | #include <private/qquickitem_p.h> |
| 24 | #include <private/qquickshadereffectmesh_p.h> |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | namespace QtPrivate { |
| 29 | class EffectSlotMapper; |
| 30 | } |
| 31 | |
| 32 | class QQuickShaderEffectPrivate : public QQuickItemPrivate |
| 33 | { |
| 34 | Q_DECLARE_PUBLIC(QQuickShaderEffect) |
| 35 | |
| 36 | public: |
| 37 | QQuickShaderEffectPrivate(); |
| 38 | ~QQuickShaderEffectPrivate(); |
| 39 | |
| 40 | void updatePolish() override; |
| 41 | |
| 42 | QUrl fragmentShader() const { return m_fragShader; } |
| 43 | void setFragmentShader(const QUrl &fileUrl); |
| 44 | |
| 45 | QUrl vertexShader() const { return m_vertShader; } |
| 46 | void setVertexShader(const QUrl &fileUrl); |
| 47 | |
| 48 | bool blending() const { return m_blending; } |
| 49 | void setBlending(bool enable); |
| 50 | |
| 51 | QVariant mesh() const; |
| 52 | void setMesh(const QVariant &mesh); |
| 53 | |
| 54 | QQuickShaderEffect::CullMode cullMode() const { return m_cullMode; } |
| 55 | void setCullMode(QQuickShaderEffect::CullMode face); |
| 56 | |
| 57 | QString log() const; |
| 58 | QQuickShaderEffect::Status status() const; |
| 59 | |
| 60 | bool supportsAtlasTextures() const { return m_supportsAtlasTextures; } |
| 61 | void setSupportsAtlasTextures(bool supports); |
| 62 | |
| 63 | QString parseLog(); |
| 64 | |
| 65 | void handleEvent(QEvent *); |
| 66 | void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
| 67 | QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *); |
| 68 | void handleComponentComplete(); |
| 69 | void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value); |
| 70 | void maybeUpdateShaders(); |
| 71 | bool updateUniformValue(const QByteArray &name, const QVariant &value, |
| 72 | QSGShaderEffectNode *node); |
| 73 | |
| 74 | void propertyChanged(int mappedId); |
| 75 | void sourceDestroyed(QObject *object); |
| 76 | void markGeometryDirtyAndUpdate(); |
| 77 | void markGeometryDirtyAndUpdateIfSupportsAtlas(); |
| 78 | void shaderCodePrepared(bool ok, QSGGuiThreadShaderEffectManager::ShaderInfo::Type typeHint, |
| 79 | const QUrl &loadUrl, QSGGuiThreadShaderEffectManager::ShaderInfo *result); |
| 80 | |
| 81 | private: |
| 82 | QSGGuiThreadShaderEffectManager *shaderEffectManager() const; |
| 83 | |
| 84 | enum Shader { |
| 85 | Vertex, |
| 86 | Fragment, |
| 87 | |
| 88 | NShader |
| 89 | }; |
| 90 | bool updateShader(Shader shaderType, const QUrl &fileUrl); |
| 91 | void updateShaderVars(Shader shaderType); |
| 92 | void disconnectSignals(Shader shaderType); |
| 93 | void clearMappers(Shader shaderType); |
| 94 | std::optional<int> findMappedShaderVariableId(const QByteArray &name) const; |
| 95 | std::optional<int> findMappedShaderVariableId(const QByteArray &name, Shader shaderType) const; |
| 96 | bool sourceIsUnique(QQuickItem *source, Shader typeToSkip, int indexToSkip) const; |
| 97 | |
| 98 | bool inDestructor = false; |
| 99 | const QMetaObject *m_itemMetaObject = nullptr; |
| 100 | QSize m_meshResolution; |
| 101 | QQuickShaderEffectMesh *m_mesh; |
| 102 | QMetaObject::Connection m_meshConnection; |
| 103 | QQuickGridMesh m_defaultMesh; |
| 104 | QQuickShaderEffect::CullMode m_cullMode; |
| 105 | bool m_blending; |
| 106 | bool m_supportsAtlasTextures; |
| 107 | mutable QSGGuiThreadShaderEffectManager *m_mgr; |
| 108 | QUrl m_fragShader; |
| 109 | bool m_fragNeedsUpdate; |
| 110 | QUrl m_vertShader; |
| 111 | bool m_vertNeedsUpdate; |
| 112 | |
| 113 | QSGShaderEffectNode::ShaderData m_shaders[NShader]; |
| 114 | QSGShaderEffectNode::DirtyShaderFlags m_dirty; |
| 115 | QSet<int> m_dirtyConstants[NShader]; |
| 116 | QSet<int> m_dirtyTextures[NShader]; |
| 117 | QSGGuiThreadShaderEffectManager::ShaderInfo *m_inProgress[NShader]; |
| 118 | |
| 119 | QVector<QtPrivate::EffectSlotMapper *> m_mappers[NShader]; |
| 120 | |
| 121 | QHash<QQuickItem *, QMetaObject::Connection> m_destroyedConnections; |
| 122 | }; |
| 123 | |
| 124 | QT_END_NAMESPACE |
| 125 | |
| 126 | #endif // QQUICKSHADEREFFECT_P_P_H |
| 127 | |