Qt 4.8
Classes | Signals | Public Functions | Protected Functions | Private Slots | Private Functions | Properties | List of all members
ShaderEffectItem Class Reference

The ShaderEffectItem object alters the output of given item with OpenGL shaders. More...

#include <shadereffectitem.h>

Inheritance diagram for ShaderEffectItem:
QDeclarativeItem Item QGraphicsObject QDeclarativeParserStatus QObject QGraphicsItem

Classes

struct  SourceData
 

Signals

void activeChanged ()
 
void blendingChanged ()
 
void fragmentShaderChanged ()
 
void meshResolutionChanged ()
 
void vertexShaderChanged ()
 
- Signals inherited from QDeclarativeItem
void activeFocusChanged (bool)
 
void baselineOffsetChanged (qreal)
 
void childrenRectChanged (const QRectF &)
 
void clipChanged (bool)
 
void focusChanged (bool)
 
void implicitHeightChanged ()
 
void implicitWidthChanged ()
 
void parentChanged (QDeclarativeItem *)
 
void smoothChanged (bool)
 
void stateChanged (const QString &)
 
void transformOriginChanged (TransformOrigin)
 
- Signals inherited from QGraphicsObject
void childrenChanged ()
 This signal gets emitted whenever the children list changes. More...
 
void enabledChanged ()
 This signal gets emitted whenever the item get's enabled or disabled. More...
 
void heightChanged ()
 
void opacityChanged ()
 This signal gets emitted whenever the opacity of the item changes. More...
 
void parentChanged ()
 This signal gets emitted whenever the parent of the item changes. More...
 
void rotationChanged ()
 This signal gets emitted whenever the roation of the item changes. More...
 
void scaleChanged ()
 This signal is emitted when the scale of the item changes. More...
 
void visibleChanged ()
 This signal gets emitted whenever the visibility of the item changes. More...
 
void widthChanged ()
 
void xChanged ()
 This signal gets emitted whenever the x position of the item changes. More...
 
void yChanged ()
 This signal gets emitted whenever the y position of the item changes. More...
 
void zChanged ()
 This signal gets emitted whenever the z value of the item changes. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

bool blending () const
 
virtual void componentComplete ()
 
QString fragmentShader () const
 
QSize meshResolution () const
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
 
void preprocess ()
 
void setBlending (bool enable)
 
void setFragmentShader (const QString &code)
 
void setMeshResolution (const QSize &size)
 
void setVertexShader (const QString &code)
 
 ShaderEffectItem (QDeclarativeItem *parent=0)
 
QString vertexShader () const
 
 ~ShaderEffectItem ()
 
- Public Functions inherited from QDeclarativeItem
qreal baselineOffset () const
 
QRectF boundingRect () const
 
Q_INVOKABLE QDeclarativeItemchildAt (qreal x, qreal y) const
 Returns the visible child item at point (x, y), which is in this item's coordinate system, or 0 if there is no such item. More...
 
QRectF childrenRect ()
 
bool clip () const
 
Q_INVOKABLE void forceActiveFocus ()
 Forces active focus on the item. More...
 
bool hasActiveFocus () const
 
bool hasFocus () const
 
qreal height () const
 
qreal implicitHeight () const
 
qreal implicitWidth () const
 
bool keepMouseGrab () const
 Returns a value indicating whether mouse input should remain with this item exclusively. More...
 
Q_INVOKABLE QScriptValue mapFromItem (const QScriptValue &item, qreal x, qreal y) const
 Maps the point (x, y), which is in item's coordinate system, to this item's coordinate system, and returns a script value with x and y properties matching the mapped cooordinate. More...
 
Q_INVOKABLE QScriptValue mapToItem (const QScriptValue &item, qreal x, qreal y) const
 Maps the point (x, y), which is in this item's coordinate system, to item's coordinate system, and returns a script value with x and y properties matching the mapped cooordinate. More...
 
QDeclarativeItemparentItem () const
 Returns the QDeclarativeItem parent of this item. More...
 
 QDeclarativeItem (QDeclarativeItem *parent=0)
 Constructs a QDeclarativeItem with the given parent. More...
 
void resetHeight ()
 
void resetWidth ()
 
void setBaselineOffset (qreal)
 
void setClip (bool)
 
void setFocus (bool)
 
void setHeight (qreal)
 
void setKeepMouseGrab (bool)
 The flag indicating whether the mouse should remain with this item is set to keep. More...
 
void setParentItem (QDeclarativeItem *parent)
 
void setSize (const QSizeF &size)
 
void setSmooth (bool)
 Sets whether the item should be drawn with antialiasing and smooth pixmap filtering to smooth. More...
 
void setTransformOrigin (TransformOrigin)
 Set the transform origin. More...
 
void setWidth (qreal)
 
bool smooth () const
 
QDeclarativeListProperty< QGraphicsTransformtransform ()
 
TransformOrigin transformOrigin () const
 
qreal width () const
 
virtual ~QDeclarativeItem ()
 Destroys the QDeclarativeItem. More...
 
- Public Functions inherited from QGraphicsObject
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the graphics object to the given gesture with specific flags. More...
 
 QGraphicsObject (QGraphicsItem *parent=0)
 Constructs a QGraphicsObject with parent. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the graphics object from the given gesture. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QGraphicsItem
bool acceptDrops () const
 Returns true if this item can accept drag and drop events; otherwise, returns false. More...
 
Qt::MouseButtons acceptedMouseButtons () const
 Returns the mouse buttons that this item accepts mouse events for. More...
 
bool acceptHoverEvents () const
 Returns true if an item accepts hover events (QGraphicsSceneHoverEvent); otherwise, returns false. More...
 
bool acceptsHoverEvents () const
 Call acceptHoverEvents() instead. More...
 
bool acceptTouchEvents () const
 Returns true if an item accepts touch events; otherwise, returns false. More...
 
virtual void advance (int phase)
 This virtual function is called twice for all items by the QGraphicsScene::advance() slot. More...
 
QRegion boundingRegion (const QTransform &itemToDeviceTransform) const
 Returns the bounding region for this item. More...
 
qreal boundingRegionGranularity () const
 Returns the item's bounding region granularity; a value between and including 0 and 1. More...
 
CacheMode cacheMode () const
 Returns the cache mode for this item. More...
 
QList< QGraphicsItem * > childItems () const
 Returns a list of this item's children. More...
 
QList< QGraphicsItem * > children () const
 Use childItems() instead. More...
 
QRectF childrenBoundingRect () const
 Returns the bounding rect of this item's descendants (i.e., its children, their children, etc.) in local coordinates. More...
 
void clearFocus ()
 Takes keyboard input focus from the item. More...
 
QPainterPath clipPath () const
 Returns this item's clip path, or an empty QPainterPath if this item is not clipped. More...
 
virtual bool collidesWithItem (const QGraphicsItem *other, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns true if this item collides with other; otherwise returns false. More...
 
virtual bool collidesWithPath (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns true if this item collides with path. More...
 
QList< QGraphicsItem * > collidingItems (Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Returns a list of all items that collide with this item. More...
 
QGraphicsItemcommonAncestorItem (const QGraphicsItem *other) const
 Returns the closest common ancestor item of this item and other, or 0 if either other is 0, or there is no common ancestor. More...
 
virtual bool contains (const QPointF &point) const
 Returns true if this item contains point, which is in local coordinates; otherwise, false is returned. More...
 
QCursor cursor () const
 Returns the current cursor shape for the item. More...
 
QVariant data (int key) const
 Returns this item's custom data for the key key as a QVariant. More...
 
QTransform deviceTransform (const QTransform &viewportTransform) const
 Returns this item's device transformation matrix, using viewportTransform to map from scene to device coordinates. More...
 
qreal effectiveOpacity () const
 Returns this item's effective opacity, which is between 0. More...
 
void ensureVisible (const QRectF &rect=QRectF(), int xmargin=50, int ymargin=50)
 If this item is part of a scene that is viewed by a QGraphicsView, this convenience function will attempt to scroll the view to ensure that rect is visible inside the view's viewport. More...
 
void ensureVisible (qreal x, qreal y, qreal w, qreal h, int xmargin=50, int ymargin=50)
 This convenience function is equivalent to calling ensureVisible(QRectF(x, y, w, h), xmargin, ymargin): More...
 
bool filtersChildEvents () const
 Returns true if this item filters child events (i. More...
 
GraphicsItemFlags flags () const
 Returns this item's flags. More...
 
QGraphicsItemfocusItem () const
 If this item, a child or descendant of this item currently has input focus, this function will return a pointer to that item. More...
 
QGraphicsItemfocusProxy () const
 Returns this item's focus proxy, or 0 if this item has no focus proxy. More...
 
QGraphicsItemfocusScopeItem () const
 Returns this item's focus scope item. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
QGraphicsEffectgraphicsEffect () const
 Returns a pointer to this item's effect if it has one; otherwise 0. More...
 
QGraphicsItemGroupgroup () const
 Returns a pointer to this item's item group, or 0 if this item is not member of a group. More...
 
bool handlesChildEvents () const
 Returns true if this item handles child events (i. More...
 
bool hasCursor () const
 Returns true if this item has a cursor set; otherwise, false is returned. More...
 
bool hasFocus () const
 Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise, returns false. More...
 
void hide ()
 Hides the item. More...
 
Qt::InputMethodHints inputMethodHints () const
 Returns the current input method hints of this item. More...
 
void installSceneEventFilter (QGraphicsItem *filterItem)
 Installs an event filter for this item on filterItem, causing all events for this item to first pass through filterItem's sceneEventFilter() function. More...
 
bool isActive () const
 Returns true if this item is active; otherwise returns false. More...
 
bool isAncestorOf (const QGraphicsItem *child) const
 Returns true if this item is an ancestor of child (i.e., if this item is child's parent, or one of child's parent's ancestors). More...
 
bool isBlockedByModalPanel (QGraphicsItem **blockingPanel=0) const
 Returns true if this item is blocked by a modal panel, false otherwise. More...
 
bool isClipped () const
 Returns true if this item is clipped. More...
 
bool isEnabled () const
 Returns true if the item is enabled; otherwise, false is returned. More...
 
bool isObscured () const
 Returns true if this item's bounding rect is completely obscured by the opaque shape of any of colliding items above it (i.e., with a higher Z value than this item). More...
 
bool isObscured (const QRectF &rect) const
 Returns true if rect is completely obscured by the opaque shape of any of colliding items above it (i. More...
 
bool isObscured (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling isObscured(QRectF(x, y, w, h)). More...
 
virtual bool isObscuredBy (const QGraphicsItem *item) const
 Returns true if this item's bounding rect is completely obscured by the opaque shape of item. More...
 
bool isPanel () const
 Returns true if the item is a panel; otherwise returns false. More...
 
bool isSelected () const
 Returns true if this item is selected; otherwise, false is returned. More...
 
bool isUnderMouse () const
 Returns true if this item is currently under the mouse cursor in one of the views; otherwise, false is returned. More...
 
bool isVisible () const
 Returns true if the item is visible; otherwise, false is returned. More...
 
bool isVisibleTo (const QGraphicsItem *parent) const
 Returns true if the item is visible to parent; otherwise, false is returned. More...
 
bool isWidget () const
 Returns true if this item is a widget (i. More...
 
bool isWindow () const
 Returns true if the item is a QGraphicsWidget window, otherwise returns false. More...
 
QTransform itemTransform (const QGraphicsItem *other, bool *ok=0) const
 Returns a QTransform that maps coordinates from this item to other. More...
 
QPointF mapFromItem (const QGraphicsItem *item, const QPointF &point) const
 Maps the point point, which is in item's coordinate system, to this item's coordinate system, and returns the mapped coordinate. More...
 
QPolygonF mapFromItem (const QGraphicsItem *item, const QRectF &rect) const
 Maps the rectangle rect, which is in item's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon. More...
 
QPolygonF mapFromItem (const QGraphicsItem *item, const QPolygonF &polygon) const
 Maps the polygon polygon, which is in item's coordinate system, to this item's coordinate system, and returns the mapped polygon. More...
 
QPainterPath mapFromItem (const QGraphicsItem *item, const QPainterPath &path) const
 Maps the path path, which is in item's coordinate system, to this item's coordinate system, and returns the mapped path. More...
 
QPointF mapFromItem (const QGraphicsItem *item, qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapFromItem(item, QPointF(x, y)). More...
 
QPolygonF mapFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QPointF mapFromParent (const QPointF &point) const
 Maps the point point, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped coordinate. More...
 
QPolygonF mapFromParent (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon. More...
 
QPolygonF mapFromParent (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped polygon. More...
 
QPainterPath mapFromParent (const QPainterPath &path) const
 Maps the path path, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped path. More...
 
QPointF mapFromParent (qreal x, qreal y) const
 This convenience function is equivalent to calling mapFromParent(QPointF(x, y)). More...
 
QPolygonF mapFromParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapFromItem(QRectF(x, y, w, h)). More...
 
QPointF mapFromScene (const QPointF &point) const
 Maps the point point, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped coordinate. More...
 
QPolygonF mapFromScene (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon. More...
 
QPolygonF mapFromScene (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped polygon. More...
 
QPainterPath mapFromScene (const QPainterPath &path) const
 Maps the path path, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped path. More...
 
QPointF mapFromScene (qreal x, qreal y) const
 This convenience function is equivalent to calling mapFromScene(QPointF(x, y)). More...
 
QPolygonF mapFromScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapFromScene(QRectF(x, y, w, h)). More...
 
QRectF mapRectFromItem (const QGraphicsItem *item, const QRectF &rect) const
 Maps the rectangle rect, which is in item's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i. More...
 
QRectF mapRectFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromParent (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i. More...
 
QRectF mapRectFromParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectFromParent(QRectF(x, y, w, h)). More...
 
QRectF mapRectFromScene (const QRectF &rect) const
 Maps the rectangle rect, which is in scene coordinates, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i. More...
 
QRectF mapRectFromScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectFromScene(QRectF(x, y, w, h)). More...
 
QRectF mapRectToItem (const QGraphicsItem *item, const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to item's coordinate system, and returns the mapped rectangle as a new rectangle (i. More...
 
QRectF mapRectToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToParent (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped rectangle as a new rectangle (i. More...
 
QRectF mapRectToParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectToParent(QRectF(x, y, w, h)). More...
 
QRectF mapRectToScene (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to the scene coordinate system, and returns the mapped rectangle as a new rectangle (i. More...
 
QRectF mapRectToScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapRectToScene(QRectF(x, y, w, h)). More...
 
QPointF mapToItem (const QGraphicsItem *item, const QPointF &point) const
 Maps the point point, which is in this item's coordinate system, to item's coordinate system, and returns the mapped coordinate. More...
 
QPolygonF mapToItem (const QGraphicsItem *item, const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to item's coordinate system, and returns the mapped rectangle as a polygon. More...
 
QPolygonF mapToItem (const QGraphicsItem *item, const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's coordinate system, to item's coordinate system, and returns the mapped polygon. More...
 
QPainterPath mapToItem (const QGraphicsItem *item, const QPainterPath &path) const
 Maps the path path, which is in this item's coordinate system, to item's coordinate system, and returns the mapped path. More...
 
QPointF mapToItem (const QGraphicsItem *item, qreal x, qreal y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This convenience function is equivalent to calling mapToItem(item, QPointF(x, y)). More...
 
QPolygonF mapToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QPointF mapToParent (const QPointF &point) const
 Maps the point point, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped coordinate. More...
 
QPolygonF mapToParent (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped rectangle as a polygon. More...
 
QPolygonF mapToParent (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped polygon. More...
 
QPainterPath mapToParent (const QPainterPath &path) const
 Maps the path path, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped path. More...
 
QPointF mapToParent (qreal x, qreal y) const
 This convenience function is equivalent to calling mapToParent(QPointF(x, y)). More...
 
QPolygonF mapToParent (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapToParent(QRectF(x, y, w, h)). More...
 
QPointF mapToScene (const QPointF &point) const
 Maps the point point, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped coordinate. More...
 
QPolygonF mapToScene (const QRectF &rect) const
 Maps the rectangle rect, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped rectangle as a polygon. More...
 
QPolygonF mapToScene (const QPolygonF &polygon) const
 Maps the polygon polygon, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped polygon. More...
 
QPainterPath mapToScene (const QPainterPath &path) const
 Maps the path path, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped path. More...
 
QPointF mapToScene (qreal x, qreal y) const
 This convenience function is equivalent to calling mapToScene(QPointF(x, y)). More...
 
QPolygonF mapToScene (qreal x, qreal y, qreal w, qreal h) const
 This convenience function is equivalent to calling mapToScene(QRectF(x, y, w, h)). More...
 
QMatrix matrix () const
 Returns the item's affine transformation matrix. More...
 
void moveBy (qreal dx, qreal dy)
 Moves the item by dx points horizontally, and dy point vertically. More...
 
qreal opacity () const
 Returns this item's local opacity, which is between 0. More...
 
virtual QPainterPath opaqueArea () const
 This virtual function returns a shape representing the area where this item is opaque. More...
 
QGraphicsItempanel () const
 Returns the item's panel, or 0 if this item does not have a panel. More...
 
PanelModality panelModality () const
 Returns the modality for this item. More...
 
QGraphicsItemparentItem () const
 Returns a pointer to this item's parent item. More...
 
QGraphicsObjectparentObject () const
 Returns a pointer to the item's parent, cast to a QGraphicsObject. More...
 
QGraphicsWidgetparentWidget () const
 Returns a pointer to the item's parent widget. More...
 
QPointF pos () const
 Returns the position of the item in parent coordinates. More...
 
 QGraphicsItem (QGraphicsItem *parent=0)
 Constructs a QGraphicsItem with the given parent item. More...
 
void removeSceneEventFilter (QGraphicsItem *filterItem)
 Removes an event filter on this item from filterItem. More...
 
void resetMatrix ()
 Use resetTransform() instead. More...
 
void resetTransform ()
 Resets this item's transformation matrix to the identity matrix or all the transformation properties to their default values. More...
 
void rotate (qreal angle)
 Use. More...
 
qreal rotation () const
 Returns the clockwise rotation, in degrees, around the Z axis. More...
 
void scale (qreal sx, qreal sy)
 Use. More...
 
qreal scale () const
 Returns the scale factor of the item. More...
 
QGraphicsScenescene () const
 Returns the current scene for the item, or 0 if the item is not stored in a scene. More...
 
QRectF sceneBoundingRect () const
 Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with boundingRect(). More...
 
QMatrix sceneMatrix () const
 Use sceneTransform() instead. More...
 
QPointF scenePos () const
 Returns the item's position in scene coordinates. More...
 
QTransform sceneTransform () const
 Returns this item's scene transformation matrix. More...
 
void scroll (qreal dx, qreal dy, const QRectF &rect=QRectF())
 Scrolls the contents of rect by dx, dy. More...
 
void setAcceptDrops (bool on)
 If on is true, this item will accept drag and drop events; otherwise, it is transparent for drag and drop events. More...
 
void setAcceptedMouseButtons (Qt::MouseButtons buttons)
 Sets the mouse buttons that this item accepts mouse events for. More...
 
void setAcceptHoverEvents (bool enabled)
 If enabled is true, this item will accept hover events; otherwise, it will ignore them. More...
 
void setAcceptsHoverEvents (bool enabled)
 Use setAcceptHoverEvents(enabled) instead. More...
 
void setAcceptTouchEvents (bool enabled)
 If enabled is true, this item will accept touch events; otherwise, it will ignore them. More...
 
void setActive (bool active)
 If active is true, and the scene is active, this item's panel will be activated. More...
 
void setBoundingRegionGranularity (qreal granularity)
 Sets the bounding region granularity to granularity; a value between and including 0 and 1. More...
 
void setCacheMode (CacheMode mode, const QSize &cacheSize=QSize())
 Sets the item's cache mode to mode. More...
 
void setCursor (const QCursor &cursor)
 Sets the current cursor shape for the item to cursor. More...
 
void setData (int key, const QVariant &value)
 Sets this item's custom data for the key key to value. More...
 
void setEnabled (bool enabled)
 If enabled is true, the item is enabled; otherwise, it is disabled. More...
 
void setFiltersChildEvents (bool enabled)
 If enabled is true, this item is set to filter all events for all its children (i. More...
 
void setFlag (GraphicsItemFlag flag, bool enabled=true)
 If enabled is true, the item flag flag is enabled; otherwise, it is disabled. More...
 
void setFlags (GraphicsItemFlags flags)
 Sets the item flags to flags. More...
 
void setFocus (Qt::FocusReason focusReason=Qt::OtherFocusReason)
 Gives keyboard input focus to this item. More...
 
void setFocusProxy (QGraphicsItem *item)
 Sets the item's focus proxy to item. More...
 
void setGraphicsEffect (QGraphicsEffect *effect)
 Sets effect as the item's effect. More...
 
void setGroup (QGraphicsItemGroup *group)
 Adds this item to the item group group. More...
 
void setHandlesChildEvents (bool enabled)
 If enabled is true, this item is set to handle all events for all its children (i. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 Sets the current input method hints of this item to hints. More...
 
void setMatrix (const QMatrix &matrix, bool combine=false)
 Sets the item's affine transformation matrix. More...
 
void setOpacity (qreal opacity)
 Sets this item's local opacity, between 0. More...
 
void setPanelModality (PanelModality panelModality)
 Sets the modality for this item to panelModality. More...
 
void setParentItem (QGraphicsItem *parent)
 Sets this item's parent item to newParent. More...
 
void setPos (const QPointF &pos)
 Sets the position of the item to pos, which is in parent coordinates. More...
 
void setPos (qreal x, qreal y)
 This convenience function is equivalent to calling setPos(QPointF(x, y)). More...
 
void setRotation (qreal angle)
 Sets the clockwise rotation angle, in degrees, around the Z axis. More...
 
void setScale (qreal scale)
 Sets the scale factor of the item. More...
 
void setSelected (bool selected)
 If selected is true and this item is selectable, this item is selected; otherwise, it is unselected. More...
 
void setToolTip (const QString &toolTip)
 Sets the item's tool tip to toolTip. More...
 
void setTransform (const QTransform &matrix, bool combine=false)
 Sets the item's current transformation matrix to matrix. More...
 
void setTransformations (const QList< QGraphicsTransform *> &transformations)
 Sets a list of graphics transformations (QGraphicsTransform) that currently apply to this item. More...
 
void setTransformOriginPoint (const QPointF &origin)
 Sets the origin point for the transformation in item coordinates. More...
 
void setTransformOriginPoint (qreal ax, qreal ay)
 Sets the origin point for the transformation in item coordinates. More...
 
void setVisible (bool visible)
 If visible is true, the item is made visible. More...
 
void setX (qreal x)
 Set's the x coordinate of the item's position. More...
 
void setY (qreal y)
 Set's the y coordinate of the item's position. More...
 
void setZValue (qreal z)
 Sets the Z-value of the item to z. More...
 
virtual QPainterPath shape () const
 Returns the shape of this item as a QPainterPath in local coordinates. More...
 
void shear (qreal sh, qreal sv)
 Use. More...
 
void show ()
 Shows the item. More...
 
void stackBefore (const QGraphicsItem *sibling)
 Stacks this item before sibling, which must be a sibling item (i. More...
 
QGraphicsObjecttoGraphicsObject ()
 Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object, 0 otherwise. More...
 
const QGraphicsObjecttoGraphicsObject () const
 Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object, 0 otherwise. More...
 
QString toolTip () const
 Returns the item's tool tip, or an empty QString if no tool tip has been set. More...
 
QGraphicsItemtopLevelItem () const
 Returns this item's top-level item. More...
 
QGraphicsWidgettopLevelWidget () const
 Returns a pointer to the item's top level widget (i. More...
 
QTransform transform () const
 Returns this item's transformation matrix. More...
 
QList< QGraphicsTransform * > transformations () const
 Returns a list of graphics transforms that currently apply to this item. More...
 
QPointF transformOriginPoint () const
 Returns the origin point for the transformation in item coordinates. More...
 
void translate (qreal dx, qreal dy)
 Use setPos() or setTransformOriginPoint() instead. More...
 
virtual int type () const
 Returns the type of an item as an int. More...
 
void ungrabKeyboard ()
 Releases the keyboard grab. More...
 
void ungrabMouse ()
 Releases the mouse grab. More...
 
void unsetCursor ()
 Clears the cursor from this item. More...
 
void update (const QRectF &rect=QRectF())
 Schedules a redraw of the area covered by rect in this item. More...
 
void update (qreal x, qreal y, qreal width, qreal height)
 This convenience function is equivalent to calling update(QRectF(x, y, width, height)). More...
 
QGraphicsWidgetwindow () const
 Returns the item's window, or 0 if this item does not have a window. More...
 
qreal x () const
 This convenience function is equivalent to calling pos(). More...
 
qreal y () const
 This convenience function is equivalent to calling pos(). More...
 
qreal zValue () const
 Returns the Z-value of the item. More...
 
virtual ~QGraphicsItem ()
 Destroys the QGraphicsItem and all its children. More...
 
- Public Functions inherited from QDeclarativeParserStatus
 QDeclarativeParserStatus ()
 
virtual ~QDeclarativeParserStatus ()
 

Protected Functions

virtual void geometryChanged (const QRectF &newGeometry, const QRectF &oldGeometry)
 This function is called to handle this item's changes in geometry from oldGeometry to newGeometry. More...
 
- Protected Functions inherited from QDeclarativeItem
virtual void classBegin ()
 
virtual bool event (QEvent *)
 
bool heightValid () const
 Returns whether the height property has been set explicitly. More...
 
virtual void inputMethodEvent (QInputMethodEvent *)
 
void inputMethodPreHandler (QInputMethodEvent *)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
bool isComponentComplete () const
 Returns true if construction of the QML component is complete; otherwise returns false. More...
 
virtual QVariant itemChange (GraphicsItemChange, const QVariant &)
 Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is not called during initial widget polishing. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 
void keyPressPreHandler (QKeyEvent *)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
void keyReleasePreHandler (QKeyEvent *)
 
 QDeclarativeItem (QDeclarativeItemPrivate &dd, QDeclarativeItem *parent=0)
 
virtual bool sceneEvent (QEvent *)
 
void setImplicitHeight (qreal)
 Sets the implied height of the item to h. More...
 
void setImplicitWidth (qreal)
 Sets the implied width of the item to w. More...
 
bool widthValid () const
 Returns whether the width property has been set explicitly. More...
 
- Protected Functions inherited from QGraphicsObject
 QGraphicsObject (QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QGraphicsItem
void addToIndex ()
 Adds this item to the scene's index. More...
 
virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event)
 This event handler can be reimplemented in a subclass to process context menu events. More...
 
virtual void dragEnterEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag enter events for this item. More...
 
virtual void dragLeaveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag leave events for this item. More...
 
virtual void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drag move events for this item. More...
 
virtual void dropEvent (QGraphicsSceneDragDropEvent *event)
 This event handler, for event event, can be reimplemented to receive drop events for this item. More...
 
virtual QVariant extension (const QVariant &variant) const
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 
virtual void focusInEvent (QFocusEvent *event)
 This event handler, for event event, can be reimplemented to receive focus in events for this item. More...
 
virtual void focusOutEvent (QFocusEvent *event)
 This event handler, for event event, can be reimplemented to receive focus out events for this item. More...
 
virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover enter events for this item. More...
 
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover leave events for this item. More...
 
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
 This event handler, for event event, can be reimplemented to receive hover move events for this item. More...
 
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse doubleclick events for this item. More...
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse move events for this item. More...
 
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse press events for this item. More...
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 This event handler, for event event, can be reimplemented to receive mouse release events for this item. More...
 
void prepareGeometryChange ()
 Prepares the item for a geometry change. More...
 
 QGraphicsItem (QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene)
 
void removeFromIndex ()
 Removes this item from the scene's index. More...
 
virtual bool sceneEventFilter (QGraphicsItem *watched, QEvent *event)
 Filters events for the item watched. More...
 
virtual void setExtension (Extension extension, const QVariant &variant)
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 
virtual bool supportsExtension (Extension extension) const
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 
void updateMicroFocus ()
 Updates the item's micro focus. More...
 
virtual void wheelEvent (QGraphicsSceneWheelEvent *event)
 This event handler, for event event, can be reimplemented to receive wheel events for this item. More...
 

Private Slots

void changeSource (int index)
 
void handleVisibilityChange ()
 
void markDirty ()
 

Private Functions

bool active () const
 
void bindGeometry ()
 
void checkViewportUpdateMode ()
 
void connectPropertySignals ()
 
void disconnectPropertySignals ()
 
void lookThroughShaderCode (const QString &code)
 
void renderEffect (QPainter *painter, const QMatrix4x4 &matrix)
 
void reset ()
 
void setActive (bool enable)
 
void setSource (const QVariant &var, int index)
 
void updateEffectState (const QMatrix4x4 &matrix)
 
void updateGeometry ()
 
void updateProperties ()
 
void updateShaderProgram ()
 

Properties

bool blending
 This property defines whether item is drawn using blending. More...
 
QString fragmentShader
 This property holds the OpenGL fragment shader code. More...
 
bool m_active: 1
 
QVector< const char * > m_attributeNames
 
bool m_blending: 1
 
bool m_changed: 1
 
bool m_checkedOpenGL: 1
 
bool m_checkedShaderPrograms: 1
 
bool m_checkedViewportUpdateMode: 1
 
bool m_defaultVertexShader: 1
 
QString m_fragment_code
 
QSGGeometry m_geometry
 
bool m_hasShaderPrograms: 1
 
QSize m_meshResolution
 
bool m_mirrored: 1
 
QGLShaderProgramm_program
 
bool m_program_dirty: 1
 
bool m_respectsMatrix: 1
 
bool m_respectsOpacity: 1
 
QVector< SourceDatam_sources
 
QSet< QByteArraym_uniformNames
 
QString m_vertex_code
 
QSize meshResolution
 This property defines to how many triangles the item is divided into before its vertices are passed to the vertex shader. More...
 
QString vertexShader
 This property holds the OpenGL vertex shader code. More...
 

Additional Inherited Members

- Public Types inherited from QDeclarativeItem
enum  TransformOrigin {
  TopLeft, Top, TopRight, Left,
  Center, Right, BottomLeft, Bottom,
  BottomRight
}
 Controls the point about which simple transforms like scale apply. More...
 
- Public Types inherited from QGraphicsItem
enum  { Type = 1, UserType = 65536 }
 
enum  CacheMode { NoCache, ItemCoordinateCache, DeviceCoordinateCache }
 This enum describes QGraphicsItem's cache modes. More...
 
enum  GraphicsItemChange {
  ItemPositionChange, ItemMatrixChange, ItemVisibleChange, ItemEnabledChange,
  ItemSelectedChange, ItemParentChange, ItemChildAddedChange, ItemChildRemovedChange,
  ItemTransformChange, ItemPositionHasChanged, ItemTransformHasChanged, ItemSceneChange,
  ItemVisibleHasChanged, ItemEnabledHasChanged, ItemSelectedHasChanged, ItemParentHasChanged,
  ItemSceneHasChanged, ItemCursorChange, ItemCursorHasChanged, ItemToolTipChange,
  ItemToolTipHasChanged, ItemFlagsChange, ItemFlagsHaveChanged, ItemZValueChange,
  ItemZValueHasChanged, ItemOpacityChange, ItemOpacityHasChanged, ItemScenePositionHasChanged,
  ItemRotationChange, ItemRotationHasChanged, ItemScaleChange, ItemScaleHasChanged,
  ItemTransformOriginPointChange, ItemTransformOriginPointHasChanged
}
 This enum describes the state changes that are notified by QGraphicsItem::itemChange(). More...
 
enum  GraphicsItemFlag {
  ItemIsMovable = 0x1, ItemIsSelectable = 0x2, ItemIsFocusable = 0x4, ItemClipsToShape = 0x8,
  ItemClipsChildrenToShape = 0x10, ItemIgnoresTransformations = 0x20, ItemIgnoresParentOpacity = 0x40, ItemDoesntPropagateOpacityToChildren = 0x80,
  ItemStacksBehindParent = 0x100, ItemUsesExtendedStyleOption = 0x200, ItemHasNoContents = 0x400, ItemSendsGeometryChanges = 0x800,
  ItemAcceptsInputMethod = 0x1000, ItemNegativeZStacksBehindParent = 0x2000, ItemIsPanel = 0x4000, ItemIsFocusScope = 0x8000,
  ItemSendsScenePositionChanges = 0x10000, ItemStopsClickFocusPropagation = 0x20000, ItemStopsFocusHandling = 0x40000
}
 This enum describes different flags that you can set on an item to toggle different features in the item's behavior. More...
 
enum  PanelModality { NonModal, PanelModal, SceneModal }
 This enum specifies the behavior of a modal panel. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Types inherited from QGraphicsItem
enum  Extension { UserExtension = 0x80000000 }
 Note: This is provided as a hook to avoid future problems related to adding virtual functions. More...
 
- Protected Slots inherited from QGraphicsObject
void updateMicroFocus ()
 Updates the item's micro focus. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QGraphicsItem
QScopedPointer< QGraphicsItemPrivated_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The ShaderEffectItem object alters the output of given item with OpenGL shaders.

ShaderEffectItem is available in the Qt.labs.shaders 1.0 module. {Elements in the Qt.labs module are not guaranteed to remain compatible in future versions.}

This element provides preliminary support for embedding OpenGL shader code into QML, and may be heavily changed or removed in later versions.

Requirement for the use of shaders is that the application is either using Qt OpenGL graphicssystem or is using OpenGL by setting QGLWidget as the viewport to QDeclarativeView (depending on which one is the recommened way in the targeted platform).

ShaderEffectItem internal behaviour is such that during the paint event it first renders its ShaderEffectSource items into a OpenGL framebuffer object which can be used as a texture. If the ShaderEffectSource is defined to be an image, it is directly uploaded as a texture. The texture(s) containing the source pixelcontent are then bound to graphics pipeline texture units. Finally a textured mesh is passed to the vertex- and fragmentshaders which then produce the final output for the ShaderEffectItem. It is possible to alter the mesh structure by defining the amount vertices it contains, but currently it is not possible to import complex 3D-models to be used as the mesh.

It is possible to define one or more ShaderEffectItems to be a ShaderEffectSource for other ShaderEffectItems, but ShaderEffectItem should never be declared as a child element of its source item(s) because it would cause circular loop in the painting.

A standard set of vertex attributes are provided for the shaders:

Additionally following uniforms are available for shaders:

Furthermore, it is possible to utilize automatic QML propertybinding into vertex- and fragment shader uniforms. Conversions are done according to the table below:

QML property GLSL uniform
property double foo: 1.0 uniform highp float foo
property real foo: 1.0 uniform highp float foo
property bool foo: true uniform bool foo
property int foo: 1 uniform int foo
property variant foo: Qt.point(1,1) uniform highp vec2 foo
property variant foo: Qt.size(1, 1) uniform highp vec2 foo
property variant foo: Qt.rect(1, 1, 2, 2) uniform highp vec4 foo
property color foo: "#00000000" uniform lowp vec4 foo
property variant foo: Qt.vector3d(1.0, 2.0, 0.0) uniform highp vec3 foo
property variant foo: ShaderEffectSource { SourceItem: bar } uniform lowp sampler2D foo
Note
The uniform precision definitions in the above table are not strict, it is possible to choose the uniform precision based on what is the most suitable for the shader code for that particular uniform.
The below example uses fragment shader to create simple wiggly effect to a text label.
Automatic property binding takes care of binding the properties to the uniforms if their
names are identical. ShaderEffectSource referring to textLabel is bound to sampler2D uniform inside the fragment
shader code.
import QtQuick 1.0
import Qt.labs.shaders 1.0
Rectangle {
width: 300
height: 300
color: "black"
Text {
id: textLabel
text: "Hello World"
anchors.centerIn: parent
font.pixelSize: 32
color: "white"
}
property variant source: ShaderEffectSource { sourceItem: textLabel; hideSource: true }
property real wiggleAmount: 0.005
anchors.fill: textLabel
varying highp vec2 qt_TexCoord0;
uniform sampler2D source;
uniform highp float wiggleAmount;
void main(void)
{
highp vec2 wiggledTexCoord = qt_TexCoord0;
wiggledTexCoord.s += sin(4.0 * 3.141592653589 * wiggledTexCoord.t) * wiggleAmount;
gl_FragColor = texture2D(source, wiggledTexCoord.st);
}
"
}
}
shaderexample.png

Definition at line 54 of file shadereffectitem.h.

Constructors and Destructors

◆ ShaderEffectItem()

ShaderEffectItem::ShaderEffectItem ( QDeclarativeItem parent = 0)

Definition at line 205 of file shadereffectitem.cpp.

206  : QDeclarativeItem(parent)
207  , m_program(0)
208  , m_meshResolution(1, 1)
210  , m_blending(true)
211  , m_program_dirty(true)
212  , m_active(true)
213  , m_respectsMatrix(false)
214  , m_respectsOpacity(false)
216  , m_checkedOpenGL(false)
217  , m_checkedShaderPrograms(false)
218  , m_hasShaderPrograms(false)
219  , m_mirrored(false)
220  , m_defaultVertexShader(true)
221 {
224  m_active = isVisible();
225 }
void visibleChanged()
This signal gets emitted whenever the visibility of the item changes.
static const AttributeSet & defaultAttributes_TexturedPoint2D()
Definition: qsggeometry.cpp:57
QDeclarativeItem(QDeclarativeItem *parent=0)
Constructs a QDeclarativeItem with the given parent.
#define SLOT(a)
Definition: qobjectdefs.h:226
QSGGeometry m_geometry
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QGLShaderProgram * m_program
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.

◆ ~ShaderEffectItem()

ShaderEffectItem::~ShaderEffectItem ( )

Definition at line 227 of file shadereffectitem.cpp.

228 {
229  reset();
230 }

Functions

◆ active()

bool ShaderEffectItem::active ( ) const
inlineprivate

Definition at line 112 of file shadereffectitem.h.

112 { return m_active; }

◆ activeChanged

void ShaderEffectItem::activeChanged ( )
signal

Referenced by meshResolution(), and setActive().

◆ bindGeometry()

void ShaderEffectItem::bindGeometry ( )
private

Definition at line 568 of file shadereffectitem.cpp.

Referenced by meshResolution(), and renderEffect().

569 {
570  if (!m_program)
571  return;
572 
573  char const *const *attrNames = m_attributeNames.constData();
574  int offset = 0;
575  for (int j = 0; j < m_attributeNames.size(); ++j) {
576  if (!*attrNames[j])
577  continue;
578  Q_ASSERT_X(j < m_geometry.attributeCount(), "ShaderEffectItem::bindGeometry()", "Geometry lacks attribute required by material");
580  Q_ASSERT_X(j == a.position, "ShaderEffectItem::bindGeometry()", "Geometry does not have continuous attribute positions");
581 #if defined(QT_OPENGL_ES_2)
582  GLboolean normalize = a.type != GL_FLOAT;
583 #else
584  GLboolean normalize = a.type != GL_FLOAT && a.type != GL_DOUBLE;
585 #endif
586  if (normalize)
587  qWarning() << "ShaderEffectItem::bindGeometry() - non supported attribute type!";
588 
589  m_program->setAttributeArray(a.position, (GLfloat*) (((char*) m_geometry.vertexData()) + offset), a.tupleSize, m_geometry.stride());
590  //glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, m_geometry.stride(), (char *) m_geometry.vertexData() + offset);
591  offset += a.tupleSize * size_of_type(a.type);
592  }
593 }
void * vertexData()
Definition: qsggeometry.h:88
static int size_of_type(GLenum type)
QVector< const char * > m_attributeNames
void setAttributeArray(int location, const GLfloat *values, int tupleSize, int stride=0)
Sets an array of vertex values on the attribute at location in this shader program.
QSGGeometry m_geometry
long ASN1_INTEGER_get ASN1_INTEGER * a
int stride() const
Definition: qsggeometry.h:112
Q_CORE_EXPORT void qWarning(const char *,...)
#define GL_FLOAT
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QGLShaderProgram * m_program
const Attribute * attributes() const
Definition: qsggeometry.h:111
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
static void normalize(double &x, double &y)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
typedef GLboolean
Definition: glfunctions.h:67
int attributeCount() const
Definition: qsggeometry.h:110

◆ blending()

bool ShaderEffectItem::blending ( ) const
inline

Definition at line 76 of file shadereffectitem.h.

76 { return m_blending; }

◆ blendingChanged

void ShaderEffectItem::blendingChanged ( )
signal

Referenced by meshResolution(), and setBlending().

◆ changeSource

void ShaderEffectItem::changeSource ( int  index)
privateslot

Definition at line 698 of file shadereffectitem.cpp.

Referenced by connectPropertySignals(), and meshResolution().

699 {
700  Q_ASSERT(index >= 0 && index < m_sources.size());
701  QVariant v = property(m_sources.at(index).name.constData());
702  setSource(v, index);
703 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setSource(const QVariant &var, int index)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QVector< SourceData > m_sources

◆ checkViewportUpdateMode()

void ShaderEffectItem::checkViewportUpdateMode ( )
private

Definition at line 364 of file shadereffectitem.cpp.

Referenced by meshResolution(), and paint().

365 {
367  QGraphicsScene *s = scene();
368  if (s){
369  QList<QGraphicsView*> views = s->views();
370  for (int i = 0; i < views.count(); i++) {
371  if (views[i]->viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
372  qWarning() << "ShaderEffectItem::checkViewportUpdateMode - consider setting QGraphicsView::FullViewportUpdate mode with OpenGL!";
373  }
374  }
375  }
377  }
378 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
Q_CORE_EXPORT void qWarning(const char *,...)
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ componentComplete()

void ShaderEffectItem::componentComplete ( )
virtual
Warning
This function is not part of the public interface.

componentComplete() is called when all items in the component have been constructed. It is often desirable to delay some processing until the component is complete an all bindings in the component have been resolved.

Reimplemented from QDeclarativeItem.

Definition at line 358 of file shadereffectitem.cpp.

359 {
362 }
virtual void componentComplete()

◆ connectPropertySignals()

void ShaderEffectItem::connectPropertySignals ( )
private

Definition at line 761 of file shadereffectitem.cpp.

Referenced by meshResolution(), and updateProperties().

762 {
764  for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) {
765  int pi = metaObject()->indexOfProperty(it->constData());
766  if (pi >= 0) {
767  QMetaProperty mp = metaObject()->property(pi);
768  if (!mp.hasNotifySignal())
769  qWarning("ShaderEffectItem: property '%s' does not have notification method!", it->constData());
770  QByteArray signalName("2");
771  signalName.append(mp.notifySignal().signature());
772  connect(this, signalName, this, SLOT(markDirty()));
773  } else {
774  qWarning("ShaderEffectItem: '%s' does not have a matching property!", it->constData());
775  }
776  }
777  for (int i = 0; i < m_sources.size(); ++i) {
778  SourceData &source = m_sources[i];
779  int pi = metaObject()->indexOfProperty(source.name.constData());
780  if (pi >= 0) {
781  QMetaProperty mp = metaObject()->property(pi);
782  QByteArray signalName("2");
783  signalName.append(mp.notifySignal().signature());
784  connect(this, signalName, source.mapper, SLOT(map()));
785  source.mapper->setMapping(this, i);
786  connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
787  } else {
788  qWarning("ShaderEffectItem: '%s' does not have a matching source!", source.name.constData());
789  }
790  }
791 }
void changeSource(int index)
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
iterator begin()
Definition: qset.h:166
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QFuture< void > map(Sequence &sequence, MapFunction function)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QMetaMethod notifySignal() const
Returns the QMetaMethod instance of the property change notifying signal if one was specified...
iterator end()
Definition: qset.h:169
Q_CORE_EXPORT void qWarning(const char *,...)
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
QVector< SourceData > m_sources
bool hasNotifySignal() const
Returns true if this property has a corresponding change notify signal; otherwise returns false...
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
QSet< QByteArray > m_uniformNames

◆ disconnectPropertySignals()

void ShaderEffectItem::disconnectPropertySignals ( )
private

Definition at line 751 of file shadereffectitem.cpp.

Referenced by meshResolution(), and reset().

752 {
753  disconnect(this, 0, this, SLOT(markDirty()));
754  for (int i = 0; i < m_sources.size(); ++i) {
755  SourceData &source = m_sources[i];
756  disconnect(this, 0, source.mapper, 0);
757  disconnect(source.mapper, 0, this, 0);
758  }
759 }
#define SLOT(a)
Definition: qobjectdefs.h:226
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QVector< SourceData > m_sources

◆ fragmentShader()

QString ShaderEffectItem::fragmentShader ( ) const
inline

Definition at line 70 of file shadereffectitem.h.

70 { return m_fragment_code; }

◆ fragmentShaderChanged

void ShaderEffectItem::fragmentShaderChanged ( )
signal

◆ geometryChanged()

void ShaderEffectItem::geometryChanged ( const QRectF newGeometry,
const QRectF oldGeometry 
)
protectedvirtual

This function is called to handle this item's changes in geometry from oldGeometry to newGeometry.

If the two geometries are the same, it doesn't do anything.

Reimplemented from QDeclarativeItem.

Definition at line 691 of file shadereffectitem.cpp.

Referenced by meshResolution().

692 {
693  if (newGeometry.size() != oldGeometry.size())
694  updateGeometry();
695  QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
696 }
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...
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713

◆ handleVisibilityChange

void ShaderEffectItem::handleVisibilityChange ( )
privateslot

Definition at line 935 of file shadereffectitem.cpp.

Referenced by meshResolution(), and ShaderEffectItem().

936 {
937  setActive(isVisible());
938 }
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
void setActive(bool enable)

◆ lookThroughShaderCode()

void ShaderEffectItem::lookThroughShaderCode ( const QString code)
private

Definition at line 884 of file shadereffectitem.cpp.

Referenced by meshResolution(), and updateProperties().

885 {
886  // Regexp for matching attributes and uniforms.
887  // In human readable form: attribute|uniform [lowp|mediump|highp] <type> <name>
888  static QRegExp re(QLatin1String("\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)"));
889  Q_ASSERT(re.isValid());
890 
891  int pos = -1;
892 
893  //QString wideCode = QString::fromLatin1(code.constData(), code.size());
894  QString wideCode = code;
895 
896  while ((pos = re.indexIn(wideCode, pos + 1)) != -1) {
897  QByteArray decl = re.cap(1).toLatin1(); // uniform or attribute
898  QByteArray type = re.cap(2).toLatin1(); // type
899  QByteArray name = re.cap(3).toLatin1(); // variable name
900 
901  if (decl == "attribute") {
902  if (name == qt_postion_attribute_name) {
904  } else if (name == "qt_MultiTexCoord0") {
905  if (m_attributeNames.at(0) == 0) {
907  }
909  } else {
910  // TODO: Support user defined attributes.
911  qWarning("ShaderEffectItem: Attribute \'%s\' not recognized.", name.constData());
912  }
913  } else {
914  Q_ASSERT(decl == "uniform");
915 
916  if (name == "qt_ModelViewProjectionMatrix") {
917  m_respectsMatrix = true;
918  } else if (name == "qt_Opacity") {
919  m_respectsOpacity = true;
920  } else {
921  m_uniformNames.insert(name);
922  if (type == "sampler2D") {
923  SourceData d;
924  d.mapper = new QSignalMapper;
925  d.source = 0;
926  d.name = name;
927  d.item = 0;
928  m_sources.append(d);
929  }
930  }
931  }
932  }
933 }
QDeclarativeParserStatus ** d
QVector< const char * > m_attributeNames
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QSignalMapper class bundles signals from identifiable senders.
Definition: qsignalmapper.h:56
QPointF pos() const
Returns the position of the item in parent coordinates.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const char qt_emptyAttributeName[]
const char * name
virtual int type() const
Returns the type of an item as an int.
static const char qt_postion_attribute_name[]
Q_CORE_EXPORT void qWarning(const char *,...)
const_iterator insert(const T &value)
Definition: qset.h:179
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
static const char qt_texcoord_attribute_name[]
QVector< SourceData > m_sources
QSet< QByteArray > m_uniformNames

◆ markDirty

void ShaderEffectItem::markDirty ( )
privateslot

Definition at line 705 of file shadereffectitem.cpp.

Referenced by connectPropertySignals(), disconnectPropertySignals(), meshResolution(), setActive(), and setSource().

705  {
706  update();
707 }
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.

◆ meshResolution()

QSize ShaderEffectItem::meshResolution ( ) const
inline

Definition at line 79 of file shadereffectitem.h.

79 { return m_meshResolution; }

◆ meshResolutionChanged

void ShaderEffectItem::meshResolutionChanged ( )
signal

◆ paint()

void ShaderEffectItem::paint ( QPainter ,
const QStyleOptionGraphicsItem ,
QWidget = 0 
)
virtual
Warning
This function is not part of the public interface.

Reimplemented from QDeclarativeItem.

Definition at line 380 of file shadereffectitem.cpp.

381 {
382  if (!m_active) return;
383 
384  const QGLContext *context = QGLContext::currentContext();
385 
386  if (context) {
390 
391  if (!m_hasShaderPrograms)
392  qWarning() << "ShaderEffectItem::paint - Shader programs are not supported";
393  }
394 
395  if ( !m_hasShaderPrograms )
396  return;
397 
399  painter->save();
400  painter->beginNativePainting();
401  QMatrix4x4 combinedMatrix = QMatrix4x4(painter->transform());
402  renderEffect(painter, combinedMatrix);
403  painter->endNativePainting();
404  painter->restore();
405  } else {
406  if (!m_checkedOpenGL) {
407  qWarning() << "ShaderEffectItem::paint - OpenGL not available";
408  m_checkedOpenGL = true;
409  }
410  }
411 }
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
void renderEffect(QPainter *painter, const QMatrix4x4 &matrix)
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
static bool hasOpenGLShaderPrograms(const QGLContext *context=0)
Returns true if shader programs written in the OpenGL Shading Language (GLSL) are supported on this s...

◆ preprocess()

void ShaderEffectItem::preprocess ( )

Definition at line 682 of file shadereffectitem.cpp.

Referenced by meshResolution().

683 {
684  for (int i = 0; i < m_sources.size(); ++i) {
685  ShaderEffectSource *source = m_sources.at(i).source;
686  if (source)
687  source->updateBackbuffer();
688  }
689 }
The ShaderEffectSource object encapsulates the source content for the ShaderEffectItem.
QVector< SourceData > m_sources

◆ renderEffect()

void ShaderEffectItem::renderEffect ( QPainter painter,
const QMatrix4x4 matrix 
)
private

Definition at line 413 of file shadereffectitem.cpp.

Referenced by meshResolution(), and paint().

414 {
415  if (!painter || !painter->device())
416  return;
417 
418  if (!m_program || !m_program->programId()) {
419  // Deleted due to deactivation, to save GPU memory,
420  // or invalidated due to GL context change.
421  delete m_program;
423  m_program = new QGLShaderProgram(this);
424  if (!m_program)
425  qWarning() << "ShaderEffectItem::renderEffect - Creating QGLShaderProgram failed!";
426  }
427 
428  if (!m_program)
429  return;
430 
433 
434  m_program->bind();
435 
436  QMatrix4x4 combinedMatrix;
437  combinedMatrix.scale(2.0 / painter->device()->width(), -2.0 / painter->device()->height(), 1.0);
438  combinedMatrix.translate(-painter->device()->width() / 2.0, -painter->device()->height() / 2.0 );
439  combinedMatrix *= matrix;
440  updateEffectState(combinedMatrix);
441 
442  for (int i = 0; i < m_attributeNames.size(); ++i) {
444  }
445 
446  bindGeometry();
447 
448  // Optimization, disable depth test when we know we don't need it.
449  if (m_defaultVertexShader) {
450  glDepthMask(false);
451  glDisable(GL_DEPTH_TEST);
452  } else {
453  glEnable(GL_DEPTH_TEST);
454  glDepthFunc(GL_GREATER);
455  glDepthMask(true);
456 #if defined(QT_OPENGL_ES)
457  glClearDepthf(0);
458 #else
459  glClearDepth(0);
460 #endif
461  glClearColor(0, 0, 0, 0);
462  glClear(GL_DEPTH_BUFFER_BIT);
463  }
464 
465  if (m_blending){
466  glEnable(GL_BLEND);
467  glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
468  } else {
469  glDisable(GL_BLEND);
470  }
471 
472  if (m_geometry.indexCount())
474  else
475  glDrawArrays(m_geometry.drawingMode(), 0, m_geometry.vertexCount());
476 
477  glDepthMask(false);
478  glDisable(GL_DEPTH_TEST);
479 
480  for (int i = 0; i < m_attributeNames.size(); ++i)
482 }
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector...
Definition: qmatrix4x4.cpp:944
#define GL_ONE_MINUS_SRC_ALPHA
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
void disableAttributeArray(int location)
Disables the vertex array at location in this shader program that was enabled by a previous call to e...
GLenum drawingMode() const
Definition: qsggeometry.h:82
int indexType() const
Definition: qsggeometry.h:98
QVector< const char * > m_attributeNames
GLuint programId() const
Returns the OpenGL identifier associated with this shader program.
#define GL_DEPTH_TEST
void * indexData()
int height() const
Definition: qpaintdevice.h:92
QSGGeometry m_geometry
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
QMatrix matrix() const
Returns the item&#39;s affine transformation matrix.
int width() const
Definition: qpaintdevice.h:91
#define GL_GREATER
Q_CORE_EXPORT void qWarning(const char *,...)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
#define GL_DEPTH_BUFFER_BIT
#define GL_BLEND
QGLShaderProgram * m_program
void scale(const QVector3D &vector)
Multiplies this matrix by another that scales coordinates by the components of vector.
Definition: qmatrix4x4.cpp:775
const Attribute * attributes() const
Definition: qsggeometry.h:111
void updateEffectState(const QMatrix4x4 &matrix)
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...
void enableAttributeArray(int location)
Enables the vertex array at location in this shader program so that the value set by setAttributeArra...
int indexCount() const
Definition: qsggeometry.h:100
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
bool isLinked() const
Returns true if this shader program has been linked; false otherwise.
#define GL_ONE
int vertexCount() const
Definition: qsggeometry.h:86

◆ reset()

void ShaderEffectItem::reset ( )
private

Definition at line 793 of file shadereffectitem.cpp.

Referenced by meshResolution(), setFragmentShader(), setVertexShader(), and ~ShaderEffectItem().

794 {
796 
797  if (m_program)
799 
802  for (int i = 0; i < m_sources.size(); ++i) {
803  const SourceData &source = m_sources.at(i);
804  if (m_active && source.source)
805  source.source->derefFromEffectItem();
806  delete source.mapper;
807  }
808 
809  m_sources.clear();
810  m_program_dirty = true;
811 }
void removeAllShaders()
Removes all of the shaders that were added to this program previously.
QVector< const char * > m_attributeNames
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
void clear()
Definition: qset.h:87
QGLShaderProgram * m_program
QVector< SourceData > m_sources
QSet< QByteArray > m_uniformNames

◆ setActive()

void ShaderEffectItem::setActive ( bool  enable)
private

Definition at line 645 of file shadereffectitem.cpp.

Referenced by active(), and handleVisibilityChange().

646 {
647  if (m_active == enable)
648  return;
649 
650  if (m_active) {
651  for (int i = 0; i < m_sources.size(); ++i) {
652  ShaderEffectSource *source = m_sources.at(i).source;
653  if (!source)
654  continue;
655  disconnect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
656  source->derefFromEffectItem();
657  }
658  }
659 
660  m_active = enable;
661 
662  if (m_active) {
663  for (int i = 0; i < m_sources.size(); ++i) {
664  ShaderEffectSource *source = m_sources.at(i).source;
665  if (!source)
666  continue;
667  source->refFromEffectItem();
668  connect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
669  }
670  }
671 
672  // QGLShaderProgram is deleted when not active (to minimize GPU memory usage).
673  if (!m_active && m_program) {
674  delete m_program;
675  m_program = 0;
676  }
677 
679  markDirty();
680 }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
#define emit
Definition: qobjectdefs.h:76
The ShaderEffectSource object encapsulates the source content for the ShaderEffectItem.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QGLShaderProgram * m_program
QVector< SourceData > m_sources

◆ setBlending()

void ShaderEffectItem::setBlending ( bool  enable)

Definition at line 323 of file shadereffectitem.cpp.

Referenced by blending().

324 {
325  if (m_blending == enable)
326  return;
327 
328  m_blending = enable;
329  m_changed = true;
331 }
#define emit
Definition: qobjectdefs.h:76
void blendingChanged()

◆ setFragmentShader()

void ShaderEffectItem::setFragmentShader ( const QString code)

Definition at line 253 of file shadereffectitem.cpp.

Referenced by fragmentShader().

254 {
255  if (m_fragment_code.constData() == code.constData())
256  return;
257 
258  m_fragment_code = code;
259  if (isComponentComplete()) {
260  reset();
262  }
264 }
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
#define emit
Definition: qobjectdefs.h:76
void fragmentShaderChanged()
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ setMeshResolution()

void ShaderEffectItem::setMeshResolution ( const QSize size)

Definition at line 348 of file shadereffectitem.cpp.

Referenced by meshResolution().

349 {
350  if (size == m_meshResolution)
351  return;
352 
353  m_meshResolution = size;
355  updateGeometry();
356 }
void meshResolutionChanged()
#define emit
Definition: qobjectdefs.h:76

◆ setSource()

void ShaderEffectItem::setSource ( const QVariant var,
int  index 
)
private

Definition at line 709 of file shadereffectitem.cpp.

Referenced by changeSource(), meshResolution(), and updateProperties().

710 {
711  Q_ASSERT(index >= 0 && index < m_sources.size());
712 
713  SourceData &source = m_sources[index];
714 
715  source.source = 0;
716  source.item = 0;
717  if (var.isNull()) {
718  return;
719  } else if (!qVariantCanConvert<QObject *>(var)) {
720  qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData());
721  return;
722  }
723 
724  QObject *obj = qVariantValue<QObject *>(var);
725 
726  source.source = qobject_cast<ShaderEffectSource *>(obj);
727  source.item = qobject_cast<QDeclarativeItem *>(obj);
728 
729  if (!source.item)
730  qWarning("Could not assign property '%s', did not implement QDeclarativeItem.", source.name.constData());
731 
732  if (!source.source)
733  qWarning("Could not assign property '%s', did not implement ShaderEffectSource.", source.name.constData());
734 
735  // TODO: Find better solution.
736  // 'source.item' needs a canvas to get a scenegraph node.
737  // The easiest way to make sure it gets a canvas is to
738  // make it a part of the same item tree as 'this'.
739  if (source.item && source.item->parentItem() == 0) {
740  source.item->setParentItem(this);
741  // Unlike in scenegraph, we cannot set item invisible here because qgraphicsview would optimize it away.
742  }
743 
744  // Unlike in scenegraph, ref counting is used to optimize memory consumption. Sources themself may free fbos when not referenced.
745  if (m_active && source.source) {
746  source.source->refFromEffectItem();
747  connect(source.source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
748  }
749 }
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
#define SLOT(a)
Definition: qobjectdefs.h:226
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QDeclarativeItem class provides the most basic of all visual items in QML.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
Q_CORE_EXPORT void qWarning(const char *,...)
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
The ShaderEffectSource object encapsulates the source content for the ShaderEffectItem.
quint16 index
QVector< SourceData > m_sources

◆ setVertexShader()

void ShaderEffectItem::setVertexShader ( const QString code)

Definition at line 286 of file shadereffectitem.cpp.

Referenced by vertexShader().

287 {
288  if (m_vertex_code.constData() == code.constData())
289  return;
290 
291  m_vertex_code = code;
292  m_defaultVertexShader = false;
293  if (isComponentComplete()) {
294  reset();
296  }
298 }
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
void vertexShaderChanged()
#define emit
Definition: qobjectdefs.h:76
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ updateEffectState()

void ShaderEffectItem::updateEffectState ( const QMatrix4x4 matrix)
private

Definition at line 484 of file shadereffectitem.cpp.

Referenced by meshResolution(), and renderEffect().

485 {
486  if (!m_program)
487  return;
488 
489  for (int i = m_sources.size() - 1; i >= 0; --i) {
490  const ShaderEffectItem::SourceData &source = m_sources.at(i);
491  if (!source.source)
492  continue;
493 
495  source.source->bind();
496  }
497 
498  if (m_respectsOpacity)
499  m_program->setUniformValue("qt_Opacity", static_cast<float> (effectiveOpacity()));
500 
501  if (m_respectsMatrix){
502  m_program->setUniformValue("qt_ModelViewProjectionMatrix", matrix);
503  }
504 
506  for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) {
507  const QByteArray &name = *it;
508  QVariant v = property(name.constData());
509 
510  switch (v.type()) {
511  case QVariant::Color:
513  break;
514  case QVariant::Double:
515  m_program->setUniformValue(name.constData(), (float) qvariant_cast<double>(v));
516  break;
517  case QVariant::Transform:
519  break;
520  case QVariant::Int:
522  break;
523  case QVariant::Bool:
525  break;
526  case QVariant::Size:
527  case QVariant::SizeF:
529  break;
530  case QVariant::Point:
531  case QVariant::PointF:
533  break;
534  case QVariant::Rect:
535  case QVariant::RectF:
536  {
537  QRectF r = v.toRectF();
538  m_program->setUniformValue(name.constData(), r.x(), r.y(), r.width(), r.height());
539  }
540  break;
541  case QVariant::Vector3D:
543  break;
544  default:
545  break;
546  }
547  }
548 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
qreal effectiveOpacity() const
Returns this item&#39;s effective opacity, which is between 0.
iterator begin()
Definition: qset.h:166
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
#define GL_TEXTURE0
Definition: glfunctions.h:61
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const char * name
iterator end()
Definition: qset.h:169
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
#define glActiveTexture
Definition: glfunctions.h:69
QPointer< ShaderEffectSource > source
QSizeF toSizeF() const
Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF...
Definition: qvariant.cpp:2447
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void setUniformValue(int location, GLfloat value)
Sets the uniform variable at location in the current context to value.
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QGLShaderProgram * m_program
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
typedef GLint
Definition: glfunctions.h:67
QVector< SourceData > m_sources
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QSet< QByteArray > m_uniformNames

◆ updateGeometry()

void ShaderEffectItem::updateGeometry ( )
private

Definition at line 595 of file shadereffectitem.cpp.

Referenced by geometryChanged(), meshResolution(), and setMeshResolution().

596 {
597  QRectF srcRect(0, 1, 1, -1);
598 
599  if (m_mirrored)
600  srcRect = QRectF(0, 0, 1, 1);
601 
602  QRectF dstRect = QRectF(0,0, width(), height());
603 
604  int vmesh = m_meshResolution.height();
605  int hmesh = m_meshResolution.width();
606 
607  QSGGeometry *g = &m_geometry;
608  if (vmesh == 1 && hmesh == 1) {
609  if (g->vertexCount() != 4)
610  g->allocate(4);
611  QSGGeometry::updateTexturedRectGeometry(g, dstRect, srcRect);
612  return;
613  }
614 
615  g->allocate((vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2));
616 
618 
619  for (int iy = 0; iy <= vmesh; ++iy) {
620  float fy = iy / float(vmesh);
621  float y = float(dstRect.top()) + fy * float(dstRect.height());
622  float ty = float(srcRect.top()) + fy * float(srcRect.height());
623  for (int ix = 0; ix <= hmesh; ++ix) {
624  float fx = ix / float(hmesh);
625  vdata->x = float(dstRect.left()) + fx * float(dstRect.width());
626  vdata->y = y;
627  vdata->tx = float(srcRect.left()) + fx * float(srcRect.width());
628  vdata->ty = ty;
629  ++vdata;
630  }
631  }
632 
633  quint16 *indices = (quint16 *)g->indexDataAsUShort();
634  int i = 0;
635  for (int iy = 0; iy < vmesh; ++iy) {
636  *(indices++) = i + hmesh + 1;
637  for (int ix = 0; ix <= hmesh; ++ix, ++i) {
638  *(indices++) = i + hmesh + 1;
639  *(indices++) = i;
640  }
641  *(indices++) = i - 1;
642  }
643 }
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Definition: qsggeometry.h:168
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
QSGGeometry m_geometry
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
int width() const
Returns the width.
Definition: qsize.h:126
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
unsigned short quint16
Definition: qglobal.h:936
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
quint16 * indexDataAsUShort()
Definition: qsggeometry.h:140
qreal y() const
This convenience function is equivalent to calling pos().
int height() const
Returns the height.
Definition: qsize.h:129
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
void allocate(int vertexCount, int indexCount=0)
int vertexCount() const
Definition: qsggeometry.h:86

◆ updateProperties()

void ShaderEffectItem::updateProperties ( )
private

Definition at line 813 of file shadereffectitem.cpp.

Referenced by componentComplete(), meshResolution(), setFragmentShader(), and setVertexShader().

814 {
815  QString vertexCode = m_vertex_code;
816  QString fragmentCode = m_fragment_code;
817 
818  if (vertexCode.isEmpty())
819  vertexCode = qt_default_vertex_code;
820 
821  if (fragmentCode.isEmpty())
822  fragmentCode = qt_default_fragment_code;
823 
824  lookThroughShaderCode(vertexCode);
825  lookThroughShaderCode(fragmentCode);
826 
828  qWarning("ShaderEffectItem: Missing reference to \'%s\'.", qt_postion_attribute_name);
830  qWarning("ShaderEffectItem: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
831  if (!m_respectsMatrix)
832  qWarning("ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
833 
834  for (int i = 0; i < m_sources.size(); ++i) {
835  QVariant v = property(m_sources.at(i).name);
836  setSource(v, i); // Property exists.
837  }
838 
840 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void lookThroughShaderCode(const QString &code)
void setSource(const QVariant &var, int index)
QVector< const char * > m_attributeNames
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char qt_default_vertex_code[]
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static const char qt_postion_attribute_name[]
Q_CORE_EXPORT void qWarning(const char *,...)
static const char qt_default_fragment_code[]
static const char qt_texcoord_attribute_name[]
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QVector< SourceData > m_sources

◆ updateShaderProgram()

void ShaderEffectItem::updateShaderProgram ( )
private

Definition at line 842 of file shadereffectitem.cpp.

Referenced by meshResolution(), and renderEffect().

843 {
844  if (!m_program)
845  return;
846 
847  QString vertexCode = m_vertex_code;
848  QString fragmentCode = m_fragment_code;
849 
850  if (vertexCode.isEmpty())
852 
853  if (fragmentCode.isEmpty())
855 
858 
859  for (int i = 0; i < m_attributeNames.size(); ++i) {
861  }
862 
863  if (!m_program->link()) {
864  qWarning("ShaderEffectItem: Shader compilation failed:");
865  qWarning() << m_program->log();
866  }
867 
869  qWarning("ShaderEffectItem: Missing reference to \'qt_Vertex\'.");
871  qWarning("ShaderEffectItem: Missing reference to \'qt_MultiTexCoord0\'.");
872  if (!m_respectsMatrix)
873  qWarning("ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
874 
875  if (m_program->isLinked()) {
876  m_program->bind();
877  for (int i = 0; i < m_sources.size(); ++i)
878  m_program->setUniformValue(m_sources.at(i).name.constData(), (GLint) i);
879  }
880 
881  m_program_dirty = false;
882 }
void bindAttributeLocation(const char *name, int location)
Binds the attribute name to the specified location.
QVector< const char * > m_attributeNames
QSGGeometry m_geometry
QString log() const
Returns the errors and warnings that occurred during the last link() or addShader() with explicitly s...
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool addShaderFromSourceCode(QGLShader::ShaderType type, const char *source)
Compiles source as a shader of the specified type and adds it to this shader program.
static const char qt_default_vertex_code[]
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static const char qt_postion_attribute_name[]
Q_CORE_EXPORT void qWarning(const char *,...)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static const char qt_default_fragment_code[]
virtual bool link()
Links together the shaders that were added to this program with addShader().
static const char qt_texcoord_attribute_name[]
void setUniformValue(int location, GLfloat value)
Sets the uniform variable at location in the current context to value.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QGLShaderProgram * m_program
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
typedef GLint
Definition: glfunctions.h:67
const Attribute * attributes() const
Definition: qsggeometry.h:111
QVector< SourceData > m_sources
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
bool isLinked() const
Returns true if this shader program has been linked; false otherwise.

◆ vertexShader()

QString ShaderEffectItem::vertexShader ( ) const
inline

Definition at line 73 of file shadereffectitem.h.

73 { return m_vertex_code; }

◆ vertexShaderChanged

void ShaderEffectItem::vertexShaderChanged ( )
signal

Referenced by meshResolution(), and setVertexShader().

Properties

◆ blending

bool ShaderEffectItem::blending
private

This property defines whether item is drawn using blending.

If true, the RGBA pixel output from the fragment shader is blended with the pixel RGBA-values already in the framebuffer.

If false, fragment shader output is written to framebuffer as such.

Usually drawing without blending is slightly faster, thus disabling blending might be a good choice when item is used as a background element.

Note
By default the pixel data in textures is stored in 32-bit premultiplied alpha format. This should be taken into account when blending or reading the pixel values in the fragment shader code.

The default value is true.

Definition at line 60 of file shadereffectitem.h.

◆ fragmentShader

string ShaderEffectItem::fragmentShader
private

This property holds the OpenGL fragment shader code.

The default fragment shader is following:

varying highp vec2 qt_TexCoord0;
uniform sampler2D source;
void main(void)
{
gl_FragColor = texture2D(source, qt_TexCoord0.st);
}

Definition at line 58 of file shadereffectitem.h.

◆ m_active

bool ShaderEffectItem::m_active
private

Definition at line 137 of file shadereffectitem.h.

Referenced by active(), paint(), reset(), setActive(), setSource(), and ShaderEffectItem().

◆ m_attributeNames

QVector<const char *> ShaderEffectItem::m_attributeNames
private

◆ m_blending

bool ShaderEffectItem::m_blending
private

Definition at line 135 of file shadereffectitem.h.

Referenced by blending(), renderEffect(), and setBlending().

◆ m_changed

bool ShaderEffectItem::m_changed
private

Definition at line 134 of file shadereffectitem.h.

Referenced by setBlending().

◆ m_checkedOpenGL

bool ShaderEffectItem::m_checkedOpenGL
private

Definition at line 141 of file shadereffectitem.h.

Referenced by paint().

◆ m_checkedShaderPrograms

bool ShaderEffectItem::m_checkedShaderPrograms
private

Definition at line 142 of file shadereffectitem.h.

Referenced by paint().

◆ m_checkedViewportUpdateMode

bool ShaderEffectItem::m_checkedViewportUpdateMode
private

Definition at line 140 of file shadereffectitem.h.

Referenced by checkViewportUpdateMode().

◆ m_defaultVertexShader

bool ShaderEffectItem::m_defaultVertexShader
private

Definition at line 145 of file shadereffectitem.h.

Referenced by renderEffect(), and setVertexShader().

◆ m_fragment_code

QString ShaderEffectItem::m_fragment_code
private

◆ m_geometry

QSGGeometry ShaderEffectItem::m_geometry
private

◆ m_hasShaderPrograms

bool ShaderEffectItem::m_hasShaderPrograms
private

Definition at line 143 of file shadereffectitem.h.

Referenced by paint().

◆ m_meshResolution

QSize ShaderEffectItem::m_meshResolution
private

Definition at line 121 of file shadereffectitem.h.

Referenced by meshResolution(), setMeshResolution(), and updateGeometry().

◆ m_mirrored

bool ShaderEffectItem::m_mirrored
private

Definition at line 144 of file shadereffectitem.h.

Referenced by updateGeometry().

◆ m_program

QGLShaderProgram* ShaderEffectItem::m_program
private

◆ m_program_dirty

bool ShaderEffectItem::m_program_dirty
private

Definition at line 136 of file shadereffectitem.h.

Referenced by renderEffect(), reset(), and updateShaderProgram().

◆ m_respectsMatrix

bool ShaderEffectItem::m_respectsMatrix
private

◆ m_respectsOpacity

bool ShaderEffectItem::m_respectsOpacity
private

Definition at line 139 of file shadereffectitem.h.

Referenced by lookThroughShaderCode(), and updateEffectState().

◆ m_sources

QVector<SourceData> ShaderEffectItem::m_sources
private

◆ m_uniformNames

QSet<QByteArray> ShaderEffectItem::m_uniformNames
private

◆ m_vertex_code

QString ShaderEffectItem::m_vertex_code
private

◆ meshResolution

QSize ShaderEffectItem::meshResolution
private

This property defines to how many triangles the item is divided into before its vertices are passed to the vertex shader.

Triangles are defined as triangle strips and the amount of triangles can be controlled separately for x and y-axis.

The default value is QSize(1,1).

Definition at line 61 of file shadereffectitem.h.

◆ vertexShader

string ShaderEffectItem::vertexShader
private

This property holds the OpenGL vertex shader code.

The default vertex shader is following:

uniform highp mat4 qt_ModelViewProjectionMatrix;
attribute highp vec4 qt_Vertex;
attribute highp vec2 qt_MultiTexCoord0;
varying highp vec2 qt_TexCoord0;
void main(void)
{
qt_TexCoord0 = qt_MultiTexCoord0;
gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
}

Definition at line 59 of file shadereffectitem.h.


The documentation for this class was generated from the following files: