46882217e6778d71bcc9af6bc8651b9f353f65b5
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickshadereffect_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKSHADEREFFECT_P_H
43 #define QQUICKSHADEREFFECT_P_H
44
45 #include <QtQuick/qquickitem.h>
46
47 #include <QtQuick/qsgmaterial.h>
48 #include <private/qsgadaptationlayer_p.h>
49 #include <private/qquickshadereffectnode_p.h>
50 #include "qquickshadereffectmesh_p.h"
51
52 #include <QtCore/qpointer.h>
53
54 QT_BEGIN_HEADER
55
56 QT_BEGIN_NAMESPACE
57
58 const char *qtPositionAttributeName();
59 const char *qtTexCoordAttributeName();
60
61 class QSGContext;
62 class QSignalMapper;
63 class QQuickCustomMaterialShader;
64
65 class Q_AUTOTEST_EXPORT QQuickShaderEffect : public QQuickItem
66 {
67     Q_OBJECT
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)
75     Q_ENUMS(CullMode)
76     Q_ENUMS(Status)
77
78 public:
79     enum CullMode
80     {
81         NoCulling = QQuickShaderEffectMaterial::NoCulling,
82         BackFaceCulling = QQuickShaderEffectMaterial::BackFaceCulling,
83         FrontFaceCulling = QQuickShaderEffectMaterial::FrontFaceCulling
84     };
85
86     enum Status
87     {
88         Compiled,
89         Uncompiled,
90         Error
91     };
92
93     QQuickShaderEffect(QQuickItem *parent = 0);
94     ~QQuickShaderEffect();
95
96     QByteArray fragmentShader() const { return m_source.fragmentCode; }
97     void setFragmentShader(const QByteArray &code);
98
99     QByteArray vertexShader() const { return m_source.vertexCode; }
100     void setVertexShader(const QByteArray &code);
101
102     bool blending() const { return m_blending; }
103     void setBlending(bool enable);
104
105     QVariant mesh() const;
106     void setMesh(const QVariant &mesh);
107
108     CullMode cullMode() const { return m_cullMode; }
109     void setCullMode(CullMode face);
110
111     QString log() const { return m_log; }
112     Status status() const { return m_status; }
113
114     void ensureCompleted();
115     QString parseLog() { return m_parseLog; }
116
117 Q_SIGNALS:
118     void fragmentShaderChanged();
119     void vertexShaderChanged();
120     void blendingChanged();
121     void meshChanged();
122     void cullModeChanged();
123     void logChanged();
124     void statusChanged();
125
126 protected:
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);
130
131 private Q_SLOTS:
132     void changeSource(int index);
133     void updateData();
134     void updateGeometry();
135     void updateLogAndStatus(const QString &log, int status);
136
137 private:
138     friend class QQuickCustomMaterialShader;
139     friend class QQuickShaderEffectNode;
140
141     void setSource(const QVariant &var, int index);
142     void disconnectPropertySignals();
143     void connectPropertySignals();
144     void reset();
145     void updateProperties();
146     void lookThroughShaderCode(const QByteArray &code);
147
148     QQuickShaderEffectProgram m_source;
149     QSize m_meshResolution;
150     QQuickShaderEffectMesh *m_mesh;
151     QQuickGridMesh m_defaultMesh;
152     CullMode m_cullMode;
153     QString m_log;
154     Status m_status;
155
156     struct SourceData
157     {
158         QSignalMapper *mapper;
159         QPointer<QQuickItem> sourceObject;
160         QByteArray name;
161     };
162     QVector<SourceData> m_sources;
163     QString m_parseLog;
164
165     uint m_blending : 1;
166     uint m_dirtyData : 1;
167
168     uint m_programDirty : 1;
169     uint m_dirtyMesh : 1;
170     uint m_dirtyGeometry : 1;
171
172     uint m_complete : 1;
173 };
174
175 QT_END_NAMESPACE
176
177 QT_END_HEADER
178
179 #endif // QQUICKSHADEREFFECT_P_H