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 QQUICKSHADEREFFECTSOURCE_P_H
43 #define QQUICKSHADEREFFECTSOURCE_P_H
45 #include "qquickitem.h"
46 #include <QtQuick/qsgtextureprovider.h>
47 #include <private/qsgadaptationlayer_p.h>
48 #include <QtQuick/private/qsgcontext_p.h>
49 #include <private/qsgdefaultimagenode_p.h>
50 #include <private/qquickitemchangelistener_p.h>
56 #define QSG_DEBUG_FBO_OVERLAY
63 class UpdatePaintNodeData;
64 class QOpenGLFramebufferObject;
66 class QQuickShaderEffectSourceTextureProvider;
68 class QQuickShaderEffectSourceNode : public QObject, public QSGDefaultImageNode
73 QQuickShaderEffectSourceNode();
76 void markDirtyTexture();
79 class Q_QUICK_EXPORT QQuickShaderEffectTexture : public QSGDynamicTexture
83 QQuickShaderEffectTexture(QQuickItem *shaderSource);
84 ~QQuickShaderEffectTexture();
86 virtual bool updateTexture();
88 // The item's "paint node", not effect node.
89 QSGNode *item() const { return m_item; }
90 void setItem(QSGNode *item);
92 QRectF rect() const { return m_rect; }
93 void setRect(const QRectF &rect);
95 QSize size() const { return m_size; }
96 void setSize(const QSize &size);
98 void setHasMipmaps(bool mipmap);
102 bool hasAlphaChannel() const;
103 bool hasMipmaps() const;
104 int textureId() const;
105 QSize textureSize() const { return m_size; }
107 GLenum format() const { return m_format; }
108 void setFormat(GLenum format);
110 bool live() const { return bool(m_live); }
111 void setLive(bool live);
113 bool recursive() const { return bool(m_recursive); }
114 void setRecursive(bool recursive);
116 void scheduleUpdate();
118 QImage toImage() const;
121 void updateRequested();
122 void scheduledUpdateCompleted();
125 void markDirtyTexture();
135 QQuickItem *m_shaderSource;
136 QSGRenderer *m_renderer;
137 QOpenGLFramebufferObject *m_fbo;
138 QOpenGLFramebufferObject *m_secondaryFbo;
140 #ifdef QSG_DEBUG_FBO_OVERLAY
141 QSGRectangleNode *m_debugOverlay;
144 QSGContext *m_context;
148 uint m_recursive : 1;
149 uint m_dirtyTexture : 1;
150 uint m_multisamplingSupportChecked : 1;
151 uint m_multisampling : 1;
155 class Q_QUICK_EXPORT QQuickShaderEffectSource : public QQuickItem, public QQuickItemChangeListener
158 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
159 Q_PROPERTY(QQuickItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged)
160 Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged)
161 Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
162 Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged)
163 Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
164 Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged)
165 Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)
166 Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
168 Q_ENUMS(Format WrapMode)
183 QQuickShaderEffectSource(QQuickItem *parent = 0);
184 ~QQuickShaderEffectSource();
186 WrapMode wrapMode() const;
187 void setWrapMode(WrapMode mode);
189 QQuickItem *sourceItem() const;
190 void setSourceItem(QQuickItem *item);
192 QRectF sourceRect() const;
193 void setSourceRect(const QRectF &rect);
195 QSize textureSize() const;
196 void setTextureSize(const QSize &size);
198 Format format() const;
199 void setFormat(Format format);
202 void setLive(bool live);
204 bool hideSource() const;
205 void setHideSource(bool hide);
208 void setMipmap(bool enabled);
210 bool recursive() const;
211 void setRecursive(bool enabled);
213 bool isTextureProvider() const { return true; }
214 QSGTextureProvider *textureProvider() const;
216 Q_INVOKABLE void scheduleUpdate();
219 void wrapModeChanged();
220 void sourceItemChanged();
221 void sourceRectChanged();
222 void textureSizeChanged();
223 void formatChanged();
225 void hideSourceChanged();
226 void mipmapChanged();
227 void recursiveChanged();
229 void scheduledUpdateCompleted();
232 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
234 virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect);
235 virtual void itemChange(ItemChange change, const ItemChangeData &value);
238 void ensureTexture();
240 QQuickShaderEffectSourceTextureProvider *m_provider;
241 QQuickShaderEffectTexture *m_texture;
243 QPointer<QQuickItem> m_sourceItem;
248 uint m_hideSource : 1;
250 uint m_recursive : 1;
258 #endif // QQUICKSHADEREFFECTSOURCE_P_H