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 SHADEREFFECTITEM_H
43 #define SHADEREFFECTITEM_H
47 #include "qsgmaterial.h"
48 #include <private/qsgadaptationlayer_p.h>
49 #include <private/qsgshadereffectnode_p.h>
50 #include "qsgshadereffectmesh_p.h"
52 #include <QtCore/qpointer.h>
58 QT_MODULE(Declarative)
60 const char *qtPositionAttributeName();
61 const char *qtTexCoordAttributeName();
65 class QSGCustomMaterialShader;
67 class QSGShaderEffect : public QSGItem
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)
80 NoCulling = QSGShaderEffectMaterial::NoCulling,
81 BackFaceCulling = QSGShaderEffectMaterial::BackFaceCulling,
82 FrontFaceCulling = QSGShaderEffectMaterial::FrontFaceCulling
85 QSGShaderEffect(QSGItem *parent = 0);
88 virtual void componentComplete();
90 QByteArray fragmentShader() const { return m_source.fragmentCode; }
91 void setFragmentShader(const QByteArray &code);
93 QByteArray vertexShader() const { return m_source.vertexCode; }
94 void setVertexShader(const QByteArray &code);
96 bool blending() const { return m_blending; }
97 void setBlending(bool enable);
99 QVariant mesh() const;
100 void setMesh(const QVariant &mesh);
102 CullMode cullMode() const { return m_cullMode; }
103 void setCullMode(CullMode face);
106 void fragmentShaderChanged();
107 void vertexShaderChanged();
108 void blendingChanged();
110 void cullModeChanged();
113 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
114 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
117 void changeSource(int index);
119 void updateGeometry();
122 friend class QSGCustomMaterialShader;
123 friend class QSGShaderEffectNode;
125 void setSource(const QVariant &var, int index);
126 void disconnectPropertySignals();
127 void connectPropertySignals();
129 void updateProperties();
130 void lookThroughShaderCode(const QByteArray &code);
132 QSGShaderEffectProgram m_source;
133 QSize m_meshResolution;
134 QSGShaderEffectMesh *m_deprecatedMesh; // TODO: Remove after grace period.
135 QSGGridMesh m_defaultMesh;
140 QSignalMapper *mapper;
141 QPointer<QSGItem> item;
144 QVector<SourceData> m_sources;
145 QSGShaderEffectMaterial m_material;
148 uint m_dirtyData : 1;
150 uint m_programDirty : 1;
151 uint m_dirtyMesh : 1;
152 uint m_dirtyGeometry : 1;
155 // TODO: Remove after grace period.
156 class QSGShaderEffectItem : public QSGShaderEffect
159 QSGShaderEffectItem(QSGItem *parent = 0);
166 #endif // SHADEREFFECTITEM_H