1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKSHADEREFFECT_P_H
43 #define QQUICKSHADEREFFECT_P_H
45 #include <QtQuick/qquickitem.h>
47 #include <QtQuick/qsgmaterial.h>
48 #include <private/qtquickglobal_p.h>
49 #include <private/qsgadaptationlayer_p.h>
50 #include <private/qquickshadereffectnode_p.h>
51 #include "qquickshadereffectmesh_p.h"
53 #include <QtCore/qpointer.h>
59 const char *qtPositionAttributeName();
60 const char *qtTexCoordAttributeName();
64 class QQuickCustomMaterialShader;
66 // Common class for QQuickShaderEffect and QQuickCustomParticle.
67 struct Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectCommon
69 typedef QQuickShaderEffectMaterialKey Key;
70 typedef QQuickShaderEffectMaterial::UniformData UniformData;
72 ~QQuickShaderEffectCommon();
73 void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType);
74 void connectPropertySignals(QQuickItem *item, Key::ShaderType shaderType);
75 void updateParseLog(bool ignoreAttributes);
76 void lookThroughShaderCode(QQuickItem *item, Key::ShaderType shaderType, const QByteArray &code);
77 void updateShader(QQuickItem *item, Key::ShaderType shaderType);
78 void updateMaterial(QQuickShaderEffectNode *node, QQuickShaderEffectMaterial *material,
79 bool updateUniforms, bool updateUniformValues, bool updateTextureProviders);
80 void updateWindow(QQuickWindow *window);
82 // Called by slots in QQuickShaderEffect:
83 void sourceDestroyed(QObject *object);
84 void propertyChanged(QQuickItem *item, int mappedId, bool *textureProviderChanged);
87 QVector<QByteArray> attributes;
88 QVector<UniformData> uniformData[Key::ShaderTypeCount];
89 QVector<QSignalMapper *> signalMappers[Key::ShaderTypeCount];
94 class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffect : public QQuickItem
97 Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
98 Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
99 Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY blendingChanged)
100 Q_PROPERTY(QVariant mesh READ mesh WRITE setMesh NOTIFY meshChanged)
101 Q_PROPERTY(CullMode cullMode READ cullMode WRITE setCullMode NOTIFY cullModeChanged)
102 Q_PROPERTY(QString log READ log NOTIFY logChanged)
103 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
110 NoCulling = QQuickShaderEffectMaterial::NoCulling,
111 BackFaceCulling = QQuickShaderEffectMaterial::BackFaceCulling,
112 FrontFaceCulling = QQuickShaderEffectMaterial::FrontFaceCulling
122 QQuickShaderEffect(QQuickItem *parent = 0);
123 ~QQuickShaderEffect();
125 QByteArray fragmentShader() const { return m_common.source.sourceCode[Key::FragmentShader]; }
126 void setFragmentShader(const QByteArray &code);
128 QByteArray vertexShader() const { return m_common.source.sourceCode[Key::VertexShader]; }
129 void setVertexShader(const QByteArray &code);
131 bool blending() const { return m_blending; }
132 void setBlending(bool enable);
134 QVariant mesh() const;
135 void setMesh(const QVariant &mesh);
137 CullMode cullMode() const { return m_cullMode; }
138 void setCullMode(CullMode face);
140 QString log() const { return m_log; }
141 Status status() const { return m_status; }
145 virtual bool event(QEvent *);
148 void fragmentShaderChanged();
149 void vertexShaderChanged();
150 void blendingChanged();
152 void cullModeChanged();
154 void statusChanged();
157 virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
158 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
159 virtual void componentComplete();
160 virtual void itemChange(ItemChange change, const ItemChangeData &value);
163 void updateGeometry();
164 void updateLogAndStatus(const QString &log, int status);
165 void sourceDestroyed(QObject *object);
166 void propertyChanged(int mappedId);
169 friend class QQuickCustomMaterialShader;
170 friend class QQuickShaderEffectNode;
172 typedef QQuickShaderEffectMaterialKey Key;
173 typedef QQuickShaderEffectMaterial::UniformData UniformData;
175 QSize m_meshResolution;
176 QQuickShaderEffectMesh *m_mesh;
177 QQuickGridMesh m_defaultMesh;
182 QQuickShaderEffectCommon m_common;
185 uint m_dirtyUniforms : 1;
186 uint m_dirtyUniformValues : 1;
187 uint m_dirtyTextureProviders : 1;
188 uint m_dirtyProgram : 1;
189 uint m_dirtyParseLog : 1;
190 uint m_dirtyMesh : 1;
191 uint m_dirtyGeometry : 1;
198 #endif // QQUICKSHADEREFFECT_P_H