Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / qquickshadereffect_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 "qquickitem.h"
46
47 #include "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 QT_MODULE(Declarative)
59
60 const char *qtPositionAttributeName();
61 const char *qtTexCoordAttributeName();
62
63 class QSGContext;
64 class QSignalMapper;
65 class QQuickCustomMaterialShader;
66
67 class QQuickShaderEffect : public QQuickItem
68 {
69     Q_OBJECT
70     Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
71     Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
72     Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY blendingChanged)
73     Q_PROPERTY(QVariant mesh READ mesh WRITE setMesh NOTIFY meshChanged)
74     Q_PROPERTY(CullMode culling READ cullMode WRITE setCullMode NOTIFY cullModeChanged)
75     Q_ENUMS(CullMode)
76
77 public:
78     enum CullMode
79     {
80         NoCulling = QQuickShaderEffectMaterial::NoCulling,
81         BackFaceCulling = QQuickShaderEffectMaterial::BackFaceCulling,
82         FrontFaceCulling = QQuickShaderEffectMaterial::FrontFaceCulling
83     };
84
85     QQuickShaderEffect(QQuickItem *parent = 0);
86     ~QQuickShaderEffect();
87
88     virtual void componentComplete();
89
90     QByteArray fragmentShader() const { return m_source.fragmentCode; }
91     void setFragmentShader(const QByteArray &code);
92
93     QByteArray vertexShader() const { return m_source.vertexCode; }
94     void setVertexShader(const QByteArray &code);
95
96     bool blending() const { return m_blending; }
97     void setBlending(bool enable);
98
99     QVariant mesh() const;
100     void setMesh(const QVariant &mesh);
101
102     CullMode cullMode() const { return m_cullMode; }
103     void setCullMode(CullMode face);
104
105 Q_SIGNALS:
106     void fragmentShaderChanged();
107     void vertexShaderChanged();
108     void blendingChanged();
109     void meshChanged();
110     void cullModeChanged();
111
112 protected:
113     virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
114     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
115
116 private Q_SLOTS:
117     void changeSource(int index);
118     void updateData();
119     void updateGeometry();
120
121 private:
122     friend class QQuickCustomMaterialShader;
123     friend class QQuickShaderEffectNode;
124
125     void setSource(const QVariant &var, int index);
126     void disconnectPropertySignals();
127     void connectPropertySignals();
128     void reset();
129     void updateProperties();
130     void lookThroughShaderCode(const QByteArray &code);
131
132     QQuickShaderEffectProgram m_source;
133     QSize m_meshResolution;
134     QQuickShaderEffectMesh *m_mesh;
135     QQuickGridMesh m_defaultMesh;
136     CullMode m_cullMode;
137
138     struct SourceData
139     {
140         QSignalMapper *mapper;
141         QPointer<QQuickItem> sourceObject;
142         QByteArray name;
143     };
144     QVector<SourceData> m_sources;
145
146     uint m_blending : 1;
147     uint m_dirtyData : 1;
148
149     uint m_programDirty : 1;
150     uint m_dirtyMesh : 1;
151     uint m_dirtyGeometry : 1;
152 };
153
154 // TODO: Remove after grace period.
155 class QQuickShaderEffectItem : public QQuickShaderEffect
156 {
157 public:
158     QQuickShaderEffectItem(QQuickItem *parent = 0);
159 };
160
161 QT_END_NAMESPACE
162
163 QT_END_HEADER
164
165 #endif // QQUICKSHADEREFFECT_P_H