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 SHADEREFFECTNODE_H
43 #define SHADEREFFECTNODE_H
46 #include "qsgmaterial.h"
47 #include <private/qsgtextureprovider_p.h>
50 #include <QtCore/qsharedpointer.h>
51 #include <QtCore/qpointer.h>
57 QT_MODULE(Declarative)
59 struct QSGShaderEffectMaterialKey {
60 QByteArray vertexCode;
61 QByteArray fragmentCode;
62 const char *className;
64 bool operator == (const QSGShaderEffectMaterialKey &other) const;
67 uint qHash(const QSGShaderEffectMaterialKey &key);
69 // TODO: Implement support for multisampling.
70 struct QSGShaderEffectProgram : public QSGShaderEffectMaterialKey
72 QSGShaderEffectProgram() : respectsOpacity(false), respectsMatrix(false) {}
74 QVector<QByteArray> attributeNames;
75 QSet<QByteArray> uniformNames;
77 uint respectsOpacity : 1;
78 uint respectsMatrix : 1;
82 class QSGCustomMaterialShader;
83 class QSGShaderEffectMaterial : public QSGMaterial
93 QSGShaderEffectMaterial();
94 virtual QSGMaterialType *type() const;
95 virtual QSGMaterialShader *createShader() const;
96 virtual int compare(const QSGMaterial *other) const;
98 void setCullMode(CullMode face);
99 CullMode cullMode() const;
101 void setProgramSource(const QSGShaderEffectProgram &);
102 void setUniforms(const QVector<QPair<QByteArray, QVariant> > &uniformValues);
103 void setTextureProviders(const QVector<QPair<QByteArray, QPointer<QSGItem> > > &textures);
104 const QVector<QPair<QByteArray, QPointer<QSGItem> > > &textureProviders() const;
105 void updateTextures() const;
108 friend class QSGShaderEffect;
109 friend class QSGCustomMaterialShader;
111 // The type pointer needs to be unique. It is not safe to let the type object be part of the
112 // QSGShaderEffectMaterial, since it can be deleted and a new one constructed on top of the old
113 // one. The new QSGShaderEffectMaterial would then get the same type pointer as the old one, and
114 // CustomMaterialShaders based on the old one would incorrectly be used together with the new
115 // one. To guarantee that the type pointer is unique, the type object must live as long as
116 // there are any CustomMaterialShaders of that type.
117 QSharedPointer<QSGMaterialType> m_type;
119 QSGShaderEffectProgram m_source;
120 QVector<QPair<QByteArray, QVariant> > m_uniformValues;
121 QVector<QPair<QByteArray, QPointer<QSGItem> > > m_textures;
124 static QHash<QSGShaderEffectMaterialKey, QSharedPointer<QSGMaterialType> > materialMap;
128 class QSGShaderEffectMesh;
130 class QSGShaderEffectNode : public QObject, public QSGGeometryNode
134 QSGShaderEffectNode();
135 virtual ~QSGShaderEffectNode();
137 virtual void preprocess();
139 QSGShaderEffectMaterial *shaderMaterial() { return &m_material; }
142 void markDirtyTexture();
145 QSGShaderEffectMaterial m_material;
154 #endif // SHADEREFFECTNODE_H