QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickshadereffect_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
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/qtquickglobal_p.h>
49 #include <private/qsgadaptationlayer_p.h>
50 #include <private/qquickshadereffectnode_p.h>
51 #include "qquickshadereffectmesh_p.h"
52
53 #include <QtCore/qpointer.h>
54
55 QT_BEGIN_HEADER
56
57 QT_BEGIN_NAMESPACE
58
59 const char *qtPositionAttributeName();
60 const char *qtTexCoordAttributeName();
61
62 class QSGContext;
63 class QSignalMapper;
64 class QQuickCustomMaterialShader;
65
66 // Common class for QQuickShaderEffect and QQuickCustomParticle.
67 struct Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectCommon
68 {
69     typedef QQuickShaderEffectMaterialKey Key;
70     typedef QQuickShaderEffectMaterial::UniformData UniformData;
71
72     ~QQuickShaderEffectCommon();
73     void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType);
74     void connectPropertySignals(QQuickItem *item, Key::ShaderType shaderType);
75     void updateParseLog(bool ignoreAttributes);
76     void lookThroughShaderCode(QQuickItem *item, Key::ShaderType shaderType, const QByteArray &code);
77     void updateShader(QQuickItem *item, Key::ShaderType shaderType);
78     void updateMaterial(QQuickShaderEffectNode *node, QQuickShaderEffectMaterial *material,
79                         bool updateUniforms, bool updateUniformValues, bool updateTextureProviders);
80     void updateWindow(QQuickWindow *window);
81
82     // Called by slots in QQuickShaderEffect:
83     void sourceDestroyed(QObject *object);
84     void propertyChanged(QQuickItem *item, int mappedId, bool *textureProviderChanged);
85
86     Key source;
87     QVector<QByteArray> attributes;
88     QVector<UniformData> uniformData[Key::ShaderTypeCount];
89     QVector<QSignalMapper *> signalMappers[Key::ShaderTypeCount];
90     QString parseLog;
91 };
92
93
94 class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffect : public QQuickItem
95 {
96     Q_OBJECT
97     Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
98     Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
99     Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY blendingChanged)
100     Q_PROPERTY(QVariant mesh READ mesh WRITE setMesh NOTIFY meshChanged)
101     Q_PROPERTY(CullMode culling READ cullMode WRITE setCullMode NOTIFY cullModeChanged)
102     Q_PROPERTY(QString log READ log NOTIFY logChanged)
103     Q_PROPERTY(Status status READ status NOTIFY statusChanged)
104     Q_ENUMS(CullMode)
105     Q_ENUMS(Status)
106
107 public:
108     enum CullMode
109     {
110         NoCulling = QQuickShaderEffectMaterial::NoCulling,
111         BackFaceCulling = QQuickShaderEffectMaterial::BackFaceCulling,
112         FrontFaceCulling = QQuickShaderEffectMaterial::FrontFaceCulling
113     };
114
115     enum Status
116     {
117         Compiled,
118         Uncompiled,
119         Error
120     };
121
122     QQuickShaderEffect(QQuickItem *parent = 0);
123     ~QQuickShaderEffect();
124
125     QByteArray fragmentShader() const { return m_common.source.sourceCode[Key::FragmentShader]; }
126     void setFragmentShader(const QByteArray &code);
127
128     QByteArray vertexShader() const { return m_common.source.sourceCode[Key::VertexShader]; }
129     void setVertexShader(const QByteArray &code);
130
131     bool blending() const { return m_blending; }
132     void setBlending(bool enable);
133
134     QVariant mesh() const;
135     void setMesh(const QVariant &mesh);
136
137     CullMode cullMode() const { return m_cullMode; }
138     void setCullMode(CullMode face);
139
140     QString log() const { return m_log; }
141     Status status() const { return m_status; }
142
143     QString parseLog();
144
145     virtual bool event(QEvent *);
146
147 Q_SIGNALS:
148     void fragmentShaderChanged();
149     void vertexShaderChanged();
150     void blendingChanged();
151     void meshChanged();
152     void cullModeChanged();
153     void logChanged();
154     void statusChanged();
155
156 protected:
157     virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
158     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
159     virtual void componentComplete();
160     virtual void itemChange(ItemChange change, const ItemChangeData &value);
161
162 private Q_SLOTS:
163     void updateGeometry();
164     void updateLogAndStatus(const QString &log, int status);
165     void sourceDestroyed(QObject *object);
166     void propertyChanged(int mappedId);
167
168 private:
169     friend class QQuickCustomMaterialShader;
170     friend class QQuickShaderEffectNode;
171
172     typedef QQuickShaderEffectMaterialKey Key;
173     typedef QQuickShaderEffectMaterial::UniformData UniformData;
174
175     QSize m_meshResolution;
176     QQuickShaderEffectMesh *m_mesh;
177     QQuickGridMesh m_defaultMesh;
178     CullMode m_cullMode;
179     QString m_log;
180     Status m_status;
181
182     QQuickShaderEffectCommon m_common;
183
184     uint m_blending : 1;
185     uint m_dirtyUniforms : 1;
186     uint m_dirtyUniformValues : 1;
187     uint m_dirtyTextureProviders : 1;
188     uint m_dirtyProgram : 1;
189     uint m_dirtyParseLog : 1;
190     uint m_dirtyMesh : 1;
191     uint m_dirtyGeometry : 1;
192 };
193
194 QT_END_NAMESPACE
195
196 QT_END_HEADER
197
198 #endif // QQUICKSHADEREFFECT_P_H