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 QQUICKSHADEREFFECTNODE_P_H
43 #define QQUICKSHADEREFFECTNODE_P_H
46 #include "qsgmaterial.h"
47 #include <private/qsgtextureprovider_p.h>
48 #include <qquickitem.h>
50 #include <QtCore/qsharedpointer.h>
51 #include <QtCore/qpointer.h>
57 QT_MODULE(Declarative)
59 struct QQuickShaderEffectMaterialKey {
60 QByteArray vertexCode;
61 QByteArray fragmentCode;
62 const char *className;
64 bool operator == (const QQuickShaderEffectMaterialKey &other) const;
67 uint qHash(const QQuickShaderEffectMaterialKey &key);
69 // TODO: Implement support for multisampling.
70 struct QQuickShaderEffectProgram : public QQuickShaderEffectMaterialKey
72 QQuickShaderEffectProgram() : respectsOpacity(false), respectsMatrix(false) {}
74 QVector<QByteArray> attributeNames;
75 QSet<QByteArray> uniformNames;
77 uint respectsOpacity : 1;
78 uint respectsMatrix : 1;
82 class QQuickCustomMaterialShader;
83 class QQuickShaderEffectMaterial : public QSGMaterial
93 QQuickShaderEffectMaterial();
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 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;
108 friend class QQuickCustomMaterialShader;
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;
118 QQuickShaderEffectProgram m_source;
119 QVector<QPair<QByteArray, QVariant> > m_uniformValues;
120 QVector<QPair<QByteArray, QSGTextureProvider *> > m_textures;
123 static QHash<QQuickShaderEffectMaterialKey, QSharedPointer<QSGMaterialType> > materialMap;
127 class QSGShaderEffectMesh;
129 class QQuickShaderEffectNode : public QObject, public QSGGeometryNode
133 QQuickShaderEffectNode();
134 virtual ~QQuickShaderEffectNode();
136 virtual void preprocess();
138 QQuickShaderEffectMaterial *shaderMaterial() { return &m_material; }
141 void markDirtyTexture();
144 QQuickShaderEffectMaterial m_material;
151 #endif // QQUICKSHADEREFFECTNODE_P_H