1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKSHADEREFFECT_P_H
43 #define QQUICKSHADEREFFECT_P_H
45 #include <QtQuick/qquickitem.h>
47 #include <QtQuick/qsgmaterial.h>
48 #include <private/qsgadaptationlayer_p.h>
49 #include <private/qquickshadereffectnode_p.h>
50 #include "qquickshadereffectmesh_p.h"
52 #include <QtCore/qpointer.h>
58 const char *qtPositionAttributeName();
59 const char *qtTexCoordAttributeName();
63 class QQuickCustomMaterialShader;
65 class Q_AUTOTEST_EXPORT QQuickShaderEffect : public QQuickItem
68 Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
69 Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
70 Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY blendingChanged)
71 Q_PROPERTY(QVariant mesh READ mesh WRITE setMesh NOTIFY meshChanged)
72 Q_PROPERTY(CullMode culling READ cullMode WRITE setCullMode NOTIFY cullModeChanged)
78 NoCulling = QQuickShaderEffectMaterial::NoCulling,
79 BackFaceCulling = QQuickShaderEffectMaterial::BackFaceCulling,
80 FrontFaceCulling = QQuickShaderEffectMaterial::FrontFaceCulling
83 QQuickShaderEffect(QQuickItem *parent = 0);
84 ~QQuickShaderEffect();
86 QByteArray fragmentShader() const { return m_source.fragmentCode; }
87 void setFragmentShader(const QByteArray &code);
89 QByteArray vertexShader() const { return m_source.vertexCode; }
90 void setVertexShader(const QByteArray &code);
92 bool blending() const { return m_blending; }
93 void setBlending(bool enable);
95 QVariant mesh() const;
96 void setMesh(const QVariant &mesh);
98 CullMode cullMode() const { return m_cullMode; }
99 void setCullMode(CullMode face);
101 void ensureCompleted();
104 void fragmentShaderChanged();
105 void vertexShaderChanged();
106 void blendingChanged();
108 void cullModeChanged();
111 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
112 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
113 virtual void itemChange(ItemChange change, const ItemChangeData &value);
116 void changeSource(int index);
118 void updateGeometry();
121 friend class QQuickCustomMaterialShader;
122 friend class QQuickShaderEffectNode;
124 void setSource(const QVariant &var, int index);
125 void disconnectPropertySignals();
126 void connectPropertySignals();
128 void updateProperties();
129 void lookThroughShaderCode(const QByteArray &code);
131 QQuickShaderEffectProgram m_source;
132 QSize m_meshResolution;
133 QQuickShaderEffectMesh *m_mesh;
134 QQuickGridMesh m_defaultMesh;
139 QSignalMapper *mapper;
140 QPointer<QQuickItem> sourceObject;
143 QVector<SourceData> m_sources;
146 uint m_dirtyData : 1;
148 uint m_programDirty : 1;
149 uint m_dirtyMesh : 1;
150 uint m_dirtyGeometry : 1;
159 #endif // QQUICKSHADEREFFECT_P_H