1 /****************************************************************************
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the Qt Graphical Effects module.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
46 \inqmlmodule QtGraphicalEffects 1.0
47 \since QtGraphicalEffects 1.0
48 \inherits QtQuick2::Item
49 \ingroup qtgraphicaleffects-mask
50 \brief Masks the source item with another item.
58 \li \image Original_bug.png
59 \li \image OpacityMask_mask.png
60 \li \image OpacityMask_bug.png
65 The following example shows how to apply the effect.
66 \snippet OpacityMask-example.qml example
73 This property defines the source item that is going to be masked.
75 \note It is not supported to let the effect include itself, for
76 instance by setting source to the effect's parent.
78 property variant source
81 This property defines the item that is going to be used as the mask. The
82 mask item gets rendered into an intermediate pixel buffer and the alpha
83 values from the result are used to determine the source item's pixels
84 visibility in the display.
92 \li \image Original_bug.png
93 \li \image OpacityMask_mask.png
94 \li \image OpacityMask_bug.png
97 property variant maskSource
100 This property allows the effect output pixels to be cached in order to
101 improve the rendering performance.
103 Every time the source or effect properties are changed, the pixels in
104 the cache must be updated. Memory consumption is increased, because an
105 extra buffer of memory is required for storing the effect output.
107 It is recommended to disable the cache when the source or the effect
108 properties are animated.
110 By default, the property is set to \c false.
112 \note It is not supported to let the effect include itself, for
113 instance by setting maskSource to the effect's parent.
115 property bool cached: false
119 input: rootItem.source
124 input: rootItem.maskSource
130 visible: rootItem.cached
132 sourceItem: shaderItem
139 property variant source: sourceProxy.output
140 property variant maskSource: maskSourceProxy.output
145 varying highp vec2 qt_TexCoord0;
146 uniform highp float qt_Opacity;
147 uniform lowp sampler2D source;
148 uniform lowp sampler2D maskSource;
150 gl_FragColor = texture2D(source, qt_TexCoord0.st) * (texture2D(maskSource, qt_TexCoord0.st).a) * qt_Opacity;