Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgshadereffectsource_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef SHADEREFFECTSOURCE_H
43 #define SHADEREFFECTSOURCE_H
44
45 #include "qsgitem.h"
46 #include <private/qsgtextureprovider_p.h>
47 #include <private/qsgadaptationlayer_p.h>
48 #include <private/qsgcontext_p.h>
49
50 #include "qpointer.h"
51 #include "qsize.h"
52 #include "qrect.h"
53
54 #define QSG_DEBUG_FBO_OVERLAY
55
56 QT_BEGIN_HEADER
57
58 QT_BEGIN_NAMESPACE
59
60 QT_MODULE(Declarative)
61
62 class QSGNode;
63 class UpdatePaintNodeData;
64 class QGLFramebufferObject;
65
66 class QSGShaderEffectTexture : public QSGDynamicTexture
67 {
68     Q_OBJECT
69 public:
70     QSGShaderEffectTexture(QSGItem *shaderSource);
71     ~QSGShaderEffectTexture();
72
73     virtual bool updateTexture();
74
75     // The item's "paint node", not effect node.
76     QSGNode *item() const { return m_item; }
77     void setItem(QSGNode *item);
78
79     QRectF rect() const { return m_rect; }
80     void setRect(const QRectF &rect);
81
82     QSize size() const { return m_size; }
83     void setSize(const QSize &size);
84
85     void setHasMipmaps(QSGTexture::Filtering filtering);
86
87     void bind();
88
89     bool hasAlphaChannel() const;
90     bool hasMipmaps() const;
91     int textureId() const;
92     QSize textureSize() const { return m_size; }
93
94     GLenum format() const { return m_format; }
95     void setFormat(GLenum format);
96
97     bool live() const { return bool(m_live); }
98     void setLive(bool live);
99
100     void grab();
101
102 public Q_SLOTS:
103     void markDirtyTexture();
104
105 private:
106     QSGNode *m_item;
107     QRectF m_rect;
108     QSize m_size;
109     GLenum m_format;
110
111     QSGItem *m_shaderSource;
112     QSGRenderer *m_renderer;
113     QGLFramebufferObject *m_fbo;
114     QGLFramebufferObject *m_multisampledFbo;
115
116 #ifdef QSG_DEBUG_FBO_OVERLAY
117     QSGRectangleNode *m_debugOverlay;
118 #endif
119
120     uint m_hWrapMode : 1;
121     uint m_vWrapMode : 1;
122     uint m_filtering : 2;
123     uint m_mipmapFiltering : 2;
124
125     uint m_live : 1;
126     uint m_dirtyTexture : 1;
127     uint m_multisamplingSupportChecked : 1;
128     uint m_multisampling : 1;
129 };
130
131 class QSGShaderEffectSource : public QSGItem, public QSGTextureProvider
132 {
133     Q_OBJECT
134     Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
135     Q_PROPERTY(QSGItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged)
136     Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged)
137     Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
138     Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged)
139     Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
140     Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged)
141     Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)
142     Q_INTERFACES(QSGTextureProvider)
143     Q_ENUMS(Format WrapMode)
144 public:
145     enum WrapMode {
146         ClampToEdge,
147         RepeatHorizontally,
148         RepeatVertically,
149         Repeat
150     };
151
152     enum Format {
153         Alpha = GL_ALPHA,
154         RGB = GL_RGB,
155         RGBA = GL_RGBA
156     };
157
158     QSGShaderEffectSource(QSGItem *parent = 0);
159     ~QSGShaderEffectSource();
160
161     WrapMode wrapMode() const;
162     void setWrapMode(WrapMode mode);
163
164     QSGItem *sourceItem() const;
165     void setSourceItem(QSGItem *item);
166
167     QRectF sourceRect() const;
168     void setSourceRect(const QRectF &rect);
169
170     QSize textureSize() const;
171     void setTextureSize(const QSize &size);
172
173     Format format() const;
174     void setFormat(Format format);
175
176     bool live() const;
177     void setLive(bool live);
178
179     bool hideSource() const;
180     void setHideSource(bool hide);
181
182     bool mipmap() const;
183     void setMipmap(bool enabled);
184
185     QSGTexture *texture() const;
186     const char *textureChangedSignal() const { return SIGNAL(textureChanged); }
187
188     Q_INVOKABLE void grab();
189
190 Q_SIGNALS:
191     void wrapModeChanged();
192     void sourceItemChanged();
193     void sourceRectChanged();
194     void textureSizeChanged();
195     void formatChanged();
196     void liveChanged();
197     void hideSourceChanged();
198     void mipmapChanged();
199
200 protected:
201     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
202
203 private:
204     QSGTexture *m_texture;
205     WrapMode m_wrapMode;
206     QPointer<QSGItem> m_sourceItem;
207     QRectF m_sourceRect;
208     QSize m_textureSize;
209     Format m_format;
210     uint m_live : 1;
211     uint m_hideSource : 1;
212     uint m_mipmap : 1;
213 };
214
215 QT_END_NAMESPACE
216
217 QT_END_HEADER
218
219 #endif // SHADEREFFECTSOURCE_H