Qt 4.8
shadereffectitem.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QML Shaders plugin of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef SHADEREFFECTITEM_H
43 #define SHADEREFFECTITEM_H
44 
45 #include <QDeclarativeItem>
46 #include <QtOpenGL>
47 #include "shadereffectsource.h"
48 #include "scenegraph/qsggeometry.h"
49 
51 
53 
55 {
56  Q_OBJECT
60  bool blending;
62 
63 public:
66 
67  virtual void componentComplete();
68  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
69 
70  QString fragmentShader() const { return m_fragment_code; }
71  void setFragmentShader(const QString &code);
72 
73  QString vertexShader() const { return m_vertex_code; }
74  void setVertexShader(const QString &code);
75 
76  bool blending() const { return m_blending; }
77  void setBlending(bool enable);
78 
80  void setMeshResolution(const QSize &size);
81 
82  void preprocess();
83 
84 Q_SIGNALS:
85  void fragmentShaderChanged();
86  void vertexShaderChanged();
87  void blendingChanged();
88  void activeChanged();
89  void meshResolutionChanged();
90 
91 protected:
92  virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
93 
94 private Q_SLOTS:
95  void changeSource(int index);
97  void markDirty();
98 
99 private:
101  void renderEffect(QPainter *painter, const QMatrix4x4 &matrix);
102  void updateEffectState(const QMatrix4x4 &matrix);
103  void updateGeometry();
104  void bindGeometry();
105  void setSource(const QVariant &var, int index);
107  void connectPropertySignals();
108  void reset();
109  void updateProperties();
110  void updateShaderProgram();
111  void lookThroughShaderCode(const QString &code);
112  bool active() const { return m_active; }
113  void setActive(bool enable);
114 
115 private:
123 
124  struct SourceData
125  {
130  };
131 
133 
134  bool m_changed : 1;
135  bool m_blending : 1;
136  bool m_program_dirty : 1;
137  bool m_active : 1;
141  bool m_checkedOpenGL : 1;
144  bool m_mirrored : 1;
146 };
147 
149 
151 
152 #endif // SHADEREFFECTITEM_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void lookThroughShaderCode(const QString &code)
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void setMeshResolution(const QSize &size)
void meshResolutionChanged()
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void changeSource(int index)
QPointer< QWidget > widget
void setSource(const QVariant &var, int index)
QSize meshResolution() const
void setFragmentShader(const QString &code)
QVector< const char * > m_attributeNames
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item&#39;s changes in geometry from oldGeometry to newGeometry...
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QSGGeometry m_geometry
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setVertexShader(const QString &code)
void vertexShaderChanged()
The QSignalMapper class bundles signals from identifiable senders.
Definition: qsignalmapper.h:56
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual void componentComplete()
void setBlending(bool enable)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
#define Q_SIGNALS
Definition: qobjectdefs.h:72
QString vertexShader() const
QMatrix matrix() const
Returns the item&#39;s affine transformation matrix.
void renderEffect(QPainter *painter, const QMatrix4x4 &matrix)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QDeclarativeItem class provides the most basic of all visual items in QML.
The QDeclarativeParserStatus class provides updates on the QML parser state.
bool active() const
void blendingChanged()
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
bool blending() const
#define Q_OBJECT
Definition: qobjectdefs.h:157
QPointer< ShaderEffectSource > source
The ShaderEffectItem object alters the output of given item with OpenGL shaders.
QGLShaderProgram * m_program
#define Q_INTERFACES(x)
This macro tells Qt which interfaces the class implements.
Definition: qobjectdefs.h:79
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
quint16 index
QString fragmentShader() const
void updateEffectState(const QMatrix4x4 &matrix)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QVector< SourceData > m_sources
#define QT_END_HEADER
Definition: qglobal.h:137
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
QPointer< QDeclarativeItem > item
void fragmentShaderChanged()
void setActive(bool enable)
QSet< QByteArray > m_uniformNames