Rename Qt Quick-specific classes to QQuick*
[profile/ivi/qtdeclarative.git] / src / declarative / items / qquickshadereffectnode_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 QQUICKSHADEREFFECTNODE_P_H
43 #define QQUICKSHADEREFFECTNODE_P_H
44
45 #include "qsgnode.h"
46 #include "qsgmaterial.h"
47 #include <private/qsgtextureprovider_p.h>
48 #include <qquickitem.h>
49
50 #include <QtCore/qsharedpointer.h>
51 #include <QtCore/qpointer.h>
52
53 QT_BEGIN_HEADER
54
55 QT_BEGIN_NAMESPACE
56
57 QT_MODULE(Declarative)
58
59 struct QQuickShaderEffectMaterialKey {
60     QByteArray vertexCode;
61     QByteArray fragmentCode;
62     const char *className;
63
64     bool operator == (const QQuickShaderEffectMaterialKey &other) const;
65 };
66
67 uint qHash(const QQuickShaderEffectMaterialKey &key);
68
69 // TODO: Implement support for multisampling.
70 struct QQuickShaderEffectProgram : public QQuickShaderEffectMaterialKey
71 {
72     QQuickShaderEffectProgram() : respectsOpacity(false), respectsMatrix(false) {}
73
74     QVector<QByteArray> attributeNames;
75     QSet<QByteArray> uniformNames;
76
77     uint respectsOpacity : 1;
78     uint respectsMatrix : 1;
79 };
80
81
82 class QQuickCustomMaterialShader;
83 class QQuickShaderEffectMaterial : public QSGMaterial
84 {
85 public:
86     enum CullMode
87     {
88         NoCulling,
89         BackFaceCulling,
90         FrontFaceCulling
91     };
92
93     QQuickShaderEffectMaterial();
94     virtual QSGMaterialType *type() const;
95     virtual QSGMaterialShader *createShader() const;
96     virtual int compare(const QSGMaterial *other) const;
97
98     void setCullMode(CullMode face);
99     CullMode cullMode() const;
100
101     void setProgramSource(const QQuickShaderEffectProgram &);
102     void setUniforms(const QVector<QPair<QByteArray, QVariant> > &uniformValues);
103     void setTextureProviders(const QVector<QPair<QByteArray, QSGTextureProvider *> > &textures);
104     const QVector<QPair<QByteArray, QSGTextureProvider *> > &textureProviders() const;
105     void updateTextures() const;
106
107 protected:
108     friend class QQuickCustomMaterialShader;
109
110     // The type pointer needs to be unique. It is not safe to let the type object be part of the
111     // QQuickShaderEffectMaterial, since it can be deleted and a new one constructed on top of the old
112     // one. The new QQuickShaderEffectMaterial would then get the same type pointer as the old one, and
113     // CustomMaterialShaders based on the old one would incorrectly be used together with the new
114     // one. To guarantee that the type pointer is unique, the type object must live as long as
115     // there are any CustomMaterialShaders of that type.
116     QSharedPointer<QSGMaterialType> m_type;
117
118     QQuickShaderEffectProgram m_source;
119     QVector<QPair<QByteArray, QVariant> > m_uniformValues;
120     QVector<QPair<QByteArray, QSGTextureProvider *> > m_textures;
121     CullMode m_cullMode;
122
123     static QHash<QQuickShaderEffectMaterialKey, QSharedPointer<QSGMaterialType> > materialMap;
124 };
125
126
127 class QSGShaderEffectMesh;
128
129 class QQuickShaderEffectNode : public QObject, public QSGGeometryNode
130 {
131     Q_OBJECT
132 public:
133     QQuickShaderEffectNode();
134     virtual ~QQuickShaderEffectNode();
135
136     virtual void preprocess();
137
138     QQuickShaderEffectMaterial *shaderMaterial() { return &m_material; }
139
140 private Q_SLOTS:
141     void markDirtyTexture();
142
143 private:
144     QQuickShaderEffectMaterial m_material;
145 };
146
147 QT_END_NAMESPACE
148
149 QT_END_HEADER
150
151 #endif // QQUICKSHADEREFFECTNODE_P_H