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)
73 Q_PROPERTY(QString log READ log NOTIFY logChanged)
74 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
81 NoCulling = QQuickShaderEffectMaterial::NoCulling,
82 BackFaceCulling = QQuickShaderEffectMaterial::BackFaceCulling,
83 FrontFaceCulling = QQuickShaderEffectMaterial::FrontFaceCulling
93 QQuickShaderEffect(QQuickItem *parent = 0);
94 ~QQuickShaderEffect();
96 QByteArray fragmentShader() const { return m_source.fragmentCode; }
97 void setFragmentShader(const QByteArray &code);
99 QByteArray vertexShader() const { return m_source.vertexCode; }
100 void setVertexShader(const QByteArray &code);
102 bool blending() const { return m_blending; }
103 void setBlending(bool enable);
105 QVariant mesh() const;
106 void setMesh(const QVariant &mesh);
108 CullMode cullMode() const { return m_cullMode; }
109 void setCullMode(CullMode face);
111 QString log() const { return m_log; }
112 Status status() const { return m_status; }
114 void ensureCompleted();
115 QString parseLog() { return m_parseLog; }
118 void fragmentShaderChanged();
119 void vertexShaderChanged();
120 void blendingChanged();
122 void cullModeChanged();
124 void statusChanged();
127 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
128 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
129 virtual void itemChange(ItemChange change, const ItemChangeData &value);
132 void changeSource(int index);
134 void updateGeometry();
135 void updateLogAndStatus(const QString &log, int status);
138 friend class QQuickCustomMaterialShader;
139 friend class QQuickShaderEffectNode;
141 void setSource(const QVariant &var, int index);
142 void disconnectPropertySignals();
143 void connectPropertySignals();
145 void updateProperties();
146 void lookThroughShaderCode(const QByteArray &code);
148 QQuickShaderEffectProgram m_source;
149 QSize m_meshResolution;
150 QQuickShaderEffectMesh *m_mesh;
151 QQuickGridMesh m_defaultMesh;
158 QSignalMapper *mapper;
159 QPointer<QQuickItem> sourceObject;
162 QVector<SourceData> m_sources;
166 uint m_dirtyData : 1;
168 uint m_programDirty : 1;
169 uint m_dirtyMesh : 1;
170 uint m_dirtyGeometry : 1;
179 #endif // QQUICKSHADEREFFECT_P_H