diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-06-06 18:49:07 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-06-09 10:58:44 +0200 |
commit | 1a819c0ca5744d3537944126ff013686d5efbffe (patch) | |
tree | 89d55d7f662244b564c77047861b5ef015d10556 /src/effects/Glow.qml | |
parent | b7e24192352bee955d37a89fc061f1dafd32b73a (diff) | |
download | qtgraphicaleffects-1a819c0ca5744d3537944126ff013686d5efbffe.tar.gz |
Port 17 effects to RHI, remove 8 unportable ones
The following are based on static shader code, and after porting the
shaders they will work fully identically to 5.15:
FastBlur
Colorize
OpacityMask
BrightnessContrast
ColorOverlay
Desaturate
Displace
GammaAdjust
HueSaturation
LevelAdjust
RectangularGlow
Thresholdmask
LinearGradient
RadialGradient
ConicalGradient
The following change behavior:
Glow
DropShadow
These now only have the fast variants, because those rely on static shader code.
So we are going back to the Qt 5.5 versions and make them behave as if 'fast'
was always set to true. The 'fast' and 'samples' properties are removed.
The following are removed:
Blend
GaussianBlur
DirectionalBlur
MaskedBlur
RadialBlur
RecursiveBlur
ZoomBlur
InnerShadow
The autotest and the gallery application (run qmlscene testBed.qml in
tests/manual/testbed) have been adjusted accordingly and now work across
all QRhi backends.
The docs may still refer to removed effects in some code snippets. Updating
that is left as a separate exercise.
[ChangeLog] Graphical Effects no longer relies on dynamically generated
shader strings. The following effects have been removed: Blend, GaussianBlur,
MaskedBlur, RadialBlur, RecursiveBlur, ZoomBlur, InnerShadow. Glow
and DropShadow always use the 'fast' variant. The fast and samples
properties for these are thus no longer applicable and have been
removed.
Change-Id: Ife83f3828f37977596fd34f8da8b61961f0ed28a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/effects/Glow.qml')
-rw-r--r-- | src/effects/Glow.qml | 144 |
1 files changed, 43 insertions, 101 deletions
diff --git a/src/effects/Glow.qml b/src/effects/Glow.qml index 39e69a3..12a2c69 100644 --- a/src/effects/Glow.qml +++ b/src/effects/Glow.qml @@ -47,13 +47,8 @@ import QtGraphicalEffects.private 1.12 \since QtGraphicalEffects 1.0 \inherits QtQuick2::Item \ingroup qtgraphicaleffects-glow - \brief Generates a halo like glow around the source item. - - The Glow effect blurs the alpha channel of the source and colorizes it - with \l {Glow::color}{color} and places it behind the source, resulting in a halo or glow - around the object. The quality of the blurred edge can be controlled using - \l samples and \l radius and the strength of the glow can be changed using - \l spread. + \brief Generates a blurred and colorized image of the source and places it + behind the original, giving impression that the source is glowing. \table \header @@ -64,13 +59,6 @@ import QtGraphicalEffects.private 1.12 \li \image Glow_butterfly.png \endtable - The glow is created by blurring the image live using a gaussian blur. - Performing blur live is a costly operation. Fullscreen gaussian blur with - even a moderate number of samples will only run at 60 fps on highend - graphics hardware. - - \note This effect is available when running with OpenGL. - \section1 Example The following example shows how to apply the effect. @@ -78,16 +66,7 @@ import QtGraphicalEffects.private 1.12 */ Item { - id: root - - DropShadowBase { - id: dps - anchors.fill: parent - color: "white" - spread: 0.5 - horizontalOffset: 0 - verticalOffset: 0 - } + id: rootItem /*! This property defines the source item that is going to be used as source @@ -96,27 +75,14 @@ Item { \note It is not supported to let the effect include itself, for instance by setting source to the effect's parent. */ - property alias source: dps.source + property variant source /*! Radius defines the softness of the glow. A larger radius causes the edges of the glow to appear more blurry. - Depending on the radius value, value of the \l{Glow::samples}{samples} - should be set to sufficiently large to ensure the visual quality. - - The ideal blur is achieved by selecting \c samples and \c radius such - that \c {samples = 1 + radius * 2}, such as: - - \table - \header \li Radius \li Samples - \row \li 0 \e{(no blur)} \li 1 - \row \li 1 \li 3 - \row \li 2 \li 5 - \row \li 3 \li 7 - \endtable - - By default, the property is set to \c {floor(samples/2)}. + The value ranges from 0.0 (no blur) to inf. By default, the property is + set to \c 0.0 (no blur). \table \header @@ -132,10 +98,6 @@ Item { \li \b { radius: 6 } \li \b { radius: 12 } \row - \li \l samples: 25 - \li \l samples: 25 - \li \l samples: 25 - \row \li \l color: #ffffff \li \l color: #ffffff \li \l color: #ffffff @@ -145,42 +107,15 @@ Item { \li \l spread: 0 \endtable */ - property alias radius: dps.radius + property real radius: 0.0 /*! - This property defines how many samples are taken per pixel when edge - softening blur calculation is done. Larger value produces better - quality, but is slower to render. - - Ideally, this value should be twice as large as the highest required - radius value plus one, such as: - - \table - \header \li Radius \li Samples - \row \li 0 \e{(no blur)} \li 1 - \row \li 1 \li 3 - \row \li 2 \li 5 - \row \li 3 \li 7 - \endtable - - By default, the property is set to \c 9. - - This property is not intended to be animated. Changing this property will - cause the underlying OpenGL shaders to be recompiled. - */ - property alias samples: dps.samples - - /*! - This property defines how large part of the glow color is strengthened + This property defines how large part of the glow color is strenghtened near the source edges. The values range from 0.0 to 1.0. By default, the property is set to \c 0.5. - \note The implementation is optimized for medium and low spread values. - Depending on the source, spread values closer to 1.0 may yield visually - asymmetrical results. - \table \header \li Output examples with different spread values @@ -199,16 +134,12 @@ Item { \li \l radius: 8 \li \l radius: 8 \row - \li \l samples: 17 - \li \l samples: 17 - \li \l samples: 17 - \row \li \l color: #ffffff \li \l color: #ffffff \li \l color: #ffffff \endtable */ - property alias spread: dps.spread + property real spread: 0.0 /*! This property defines the RGBA color value which is used for the glow. @@ -233,27 +164,13 @@ Item { \li \l radius: 8 \li \l radius: 8 \row - \li \l samples: 17 - \li \l samples: 17 - \li \l samples: 17 - \row \li \l spread: 0.5 \li \l spread: 0.5 \li \l spread: 0.5 \endtable */ - property alias color: dps.color - - /*! - \internal - - Starting Qt 5.6, this property has no effect. It is left here - for source compatibility only. - - ### Qt 6: remove - */ - property bool fast: false + property color color: "white" /*! This property allows the effect output pixels to be cached in order to @@ -269,26 +186,51 @@ Item { By default, the property is set to \c false. */ - property alias cached: dps.cached + property bool cached: false /*! This property determines whether or not the effect has a transparent border. - When set to \c true, the exterior of the item is padded with a - transparent edge, making sampling outside the source texture use + When set to \c true, the exterior of the item is padded with a 1 pixel + wide transparent edge, making sampling outside the source texture use transparency instead of the edge pixels. Without this property, an image which has opaque edges will not get a blurred edge. - By default, the property is set to \c true. Set it to false if the source - already has a transparent edge to make the blurring a tiny bit faster. - In the snippet below, the Rectangle on the left has transparent borders and has blurred edges, whereas the Rectangle on the right does not. \snippet Glow-transparentBorder-example.qml example - \image Glow-transparentBorder.png + \image transparentBorder.png */ - property alias transparentBorder: dps.transparentBorder + property bool transparentBorder: false + + Loader { + anchors.fill: parent + sourceComponent: fastGlow + } + + Component { + id: fastGlow + FastGlow { + anchors.fill: parent + source: sourceProxy.output + blur: Math.pow(rootItem.radius / 64.0, 0.4) + color: rootItem.color + cached: rootItem.cached + spread: rootItem.spread + transparentBorder: rootItem.transparentBorder + } + } + + SourceProxy { + id: sourceProxy + input: rootItem.source + sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0) + } + ShaderEffect { + anchors.fill: parent + property variant source: sourceProxy.output + } } |