From 3c2d0623c74cc51d0c3b73e0b56b5f5052676ee4 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 1 Sep 2014 14:45:05 +0300 Subject: Add option to use low definition volume shader. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Low definition volume shader samples the texture at even intervals, so it will sometimes skip texels, causing flickering. Change-Id: Iee6cb0e8893498b89ce1a40f34701a53d100283e Reviewed-by: Tomi Korpipää --- src/datavisualization/data/qcustom3dvolume.cpp | 58 +++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'src/datavisualization/data/qcustom3dvolume.cpp') diff --git a/src/datavisualization/data/qcustom3dvolume.cpp b/src/datavisualization/data/qcustom3dvolume.cpp index 503d324d..789b7718 100644 --- a/src/datavisualization/data/qcustom3dvolume.cpp +++ b/src/datavisualization/data/qcustom3dvolume.cpp @@ -135,6 +135,24 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION * \sa alphaMultiplier */ +/*! + * \qmlproperty bool Custom3DVolume::useHighDefShader + * + * If this property value is \c{true}, a high definition shader is used to render the volume. + * If it is \c{false}, a low definition shader is used. + * + * The high definition shader guarantees that every visible texel of the volume texture is sampled + * when the volume is rendered. + * The low definition shader renders only a rough approximation of the volume contents, + * but at much higher frame rate. The low definition shader doesn't guarantee every texel of the + * volume texture is sampled, so there may be flickering if the volume contains distinct thin + * features. + * + * \note This value doesn't affect the level of detail when rendering the slices of the volume. + * + * Defaults to \c{true}. + */ + /*! * Constructs QCustom3DVolume with given \a parent. */ @@ -672,6 +690,40 @@ bool QCustom3DVolume::preserveOpacity() const return dptrc()->m_preserveOpacity; } +/*! + * \property QCustom3DVolume::useHighDefShader + * + * If this property value is \c{true}, a high definition shader is used to render the volume. + * If it is \c{false}, a low definition shader is used. + * + * The high definition shader guarantees that every visible texel of the volume texture is sampled + * when the volume is rendered. + * The low definition shader renders only a rough approximation of the volume contents, + * but at much higher frame rate. The low definition shader doesn't guarantee every texel of the + * volume texture is sampled, so there may be flickering if the volume contains distinct thin + * features. + * + * \note This value doesn't affect the level of detail when rendering the slices of the volume. + * + * Defaults to \c{true}. + * + * \sa renderSlice() + */ +void QCustom3DVolume::setUseHighDefShader(bool enable) +{ + if (dptr()->m_useHighDefShader != enable) { + dptr()->m_useHighDefShader = enable; + dptr()->m_dirtyBitsVolume.shaderDirty = true; + emit useHighDefShaderChanged(enable); + emit dptr()->needUpdate(); + } +} + +bool QCustom3DVolume::useHighDefShader() const +{ + return dptrc()->m_useHighDefShader; +} + /*! * Renders the slice specified by \a index along \a axis into an image. * The texture format of this object is used. @@ -712,7 +764,8 @@ QCustom3DVolumePrivate::QCustom3DVolumePrivate(QCustom3DVolume *q) : m_textureFormat(QImage::Format_ARGB32), m_textureData(0), m_alphaMultiplier(1.0f), - m_preserveOpacity(true) + m_preserveOpacity(true), + m_useHighDefShader(true) { m_isVolumeItem = true; m_meshFile = QStringLiteral(":/defaultMeshes/barFull"); @@ -736,7 +789,8 @@ QCustom3DVolumePrivate::QCustom3DVolumePrivate(QCustom3DVolume *q, const QVector m_colorTable(colorTable), m_textureData(textureData), m_alphaMultiplier(1.0f), - m_preserveOpacity(true) + m_preserveOpacity(true), + m_useHighDefShader(true) { m_isVolumeItem = true; m_shadowCasting = false; -- cgit v1.2.3