1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKSHADEREFFECTNODE_P_H
43 #define QQUICKSHADEREFFECTNODE_P_H
45 #include <QtQuick/qsgnode.h>
46 #include <QtQuick/qsgmaterial.h>
47 #include <QtQuick/qsgtextureprovider.h>
48 #include <QtQuick/qquickitem.h>
49 #include <private/qtquickglobal_p.h>
51 #include <QtCore/qsharedpointer.h>
52 #include <QtCore/qpointer.h>
58 struct QQuickShaderEffectMaterialKey {
66 QByteArray sourceCode[ShaderTypeCount];
67 const char *className;
69 bool operator == (const QQuickShaderEffectMaterialKey &other) const;
72 uint qHash(const QQuickShaderEffectMaterialKey &key);
75 class QQuickCustomMaterialShader;
76 class QQuickShaderEffectNode;
77 class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectMaterial : public QSGMaterial
82 enum SpecialType { None, Sampler, SubRect, Opacity, Matrix };
86 SpecialType specialType;
96 explicit QQuickShaderEffectMaterial(QQuickShaderEffectNode *node = 0);
97 virtual QSGMaterialType *type() const;
98 virtual QSGMaterialShader *createShader() const;
99 virtual int compare(const QSGMaterial *other) const;
101 QVector<QByteArray> attributes;
102 QVector<UniformData> uniforms[QQuickShaderEffectMaterialKey::ShaderTypeCount];
103 QVector<QSGTextureProvider *> textureProviders;
106 void setProgramSource(const QQuickShaderEffectMaterialKey &source);
107 void updateTextures() const;
108 void invalidateTextureProvider(QSGTextureProvider *provider);
111 friend class QQuickCustomMaterialShader;
113 // The type pointer needs to be unique. It is not safe to let the type object be part of the
114 // QQuickShaderEffectMaterial, since it can be deleted and a new one constructed on top of the old
115 // one. The new QQuickShaderEffectMaterial would then get the same type pointer as the old one, and
116 // CustomMaterialShaders based on the old one would incorrectly be used together with the new
117 // one. To guarantee that the type pointer is unique, the type object must live as long as
118 // there are any CustomMaterialShaders of that type.
119 QSharedPointer<QSGMaterialType> m_type;
120 QQuickShaderEffectMaterialKey m_source;
122 QQuickShaderEffectNode *m_node;
123 bool m_emittedLogChanged;
125 static QHash<QQuickShaderEffectMaterialKey, QSharedPointer<QSGMaterialType> > materialMap;
129 class QSGShaderEffectMesh;
131 class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectNode : public QObject, public QSGGeometryNode
135 QQuickShaderEffectNode();
136 virtual ~QQuickShaderEffectNode();
138 virtual void preprocess();
141 void logAndStatusChanged(const QString &, int status);
144 void markDirtyTexture();
145 void textureProviderDestroyed(QObject *object);
152 #endif // QQUICKSHADEREFFECTNODE_P_H