diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-09-01 14:45:05 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-09-02 09:11:56 +0300 |
commit | 3c2d0623c74cc51d0c3b73e0b56b5f5052676ee4 (patch) | |
tree | a808859fae11c73df396768f5783c10b66d16592 /src/datavisualization/data | |
parent | a20806dac74415f3d8cb6679c9eae86ce074ddae (diff) |
Add option to use low definition volume shader.
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ää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data')
-rw-r--r-- | src/datavisualization/data/customrenderitem.cpp | 3 | ||||
-rw-r--r-- | src/datavisualization/data/customrenderitem_p.h | 3 | ||||
-rw-r--r-- | src/datavisualization/data/qcustom3dvolume.cpp | 58 | ||||
-rw-r--r-- | src/datavisualization/data/qcustom3dvolume.h | 5 | ||||
-rw-r--r-- | src/datavisualization/data/qcustom3dvolume_p.h | 5 |
5 files changed, 70 insertions, 4 deletions
diff --git a/src/datavisualization/data/customrenderitem.cpp b/src/datavisualization/data/customrenderitem.cpp index c316fd38..555f48b7 100644 --- a/src/datavisualization/data/customrenderitem.cpp +++ b/src/datavisualization/data/customrenderitem.cpp @@ -42,7 +42,8 @@ CustomRenderItem::CustomRenderItem() m_sliceIndexY(-1), m_sliceIndexZ(-1), m_alphaMultiplier(1.0f), - m_preserveOpacity(true) + m_preserveOpacity(true), + m_useHighDefShader(true) { } diff --git a/src/datavisualization/data/customrenderitem_p.h b/src/datavisualization/data/customrenderitem_p.h index 5428ce43..5024270a 100644 --- a/src/datavisualization/data/customrenderitem_p.h +++ b/src/datavisualization/data/customrenderitem_p.h @@ -96,6 +96,8 @@ public: inline float alphaMultiplier() const { return m_alphaMultiplier; } inline void setPreserveOpacity(bool enable) { m_preserveOpacity = enable; } inline bool preserveOpacity() const { return m_preserveOpacity; } + inline void setUseHighDefShader(bool enable) { m_useHighDefShader = enable; } + inline bool useHighDefShader() const {return m_useHighDefShader; } private: Q_DISABLE_COPY(CustomRenderItem) @@ -126,6 +128,7 @@ private: int m_sliceIndexZ; float m_alphaMultiplier; bool m_preserveOpacity; + bool m_useHighDefShader; }; typedef QHash<QCustom3DItem *, CustomRenderItem *> CustomRenderItemArray; 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 @@ -136,6 +136,24 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION */ /*! + * \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. */ QCustom3DVolume::QCustom3DVolume(QObject *parent) : @@ -673,6 +691,40 @@ bool QCustom3DVolume::preserveOpacity() const } /*! + * \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; diff --git a/src/datavisualization/data/qcustom3dvolume.h b/src/datavisualization/data/qcustom3dvolume.h index 8627eb71..23ae07d9 100644 --- a/src/datavisualization/data/qcustom3dvolume.h +++ b/src/datavisualization/data/qcustom3dvolume.h @@ -41,6 +41,7 @@ class QT_DATAVISUALIZATION_EXPORT QCustom3DVolume : public QCustom3DItem Q_PROPERTY(QVector<uchar> *textureData READ textureData WRITE setTextureData NOTIFY textureDataChanged) Q_PROPERTY(float alphaMultiplier READ alphaMultiplier WRITE setAlphaMultiplier NOTIFY alphaMultiplierChanged) Q_PROPERTY(bool preserveOpacity READ preserveOpacity WRITE setPreserveOpacity NOTIFY preserveOpacityChanged) + Q_PROPERTY(bool useHighDefShader READ useHighDefShader WRITE setUseHighDefShader NOTIFY useHighDefShaderChanged) public: @@ -86,6 +87,9 @@ public: void setPreserveOpacity(bool enable); bool preserveOpacity() const; + void setUseHighDefShader(bool enable); + bool useHighDefShader() const; + QImage renderSlice(Qt::Axis axis, int index); signals: @@ -100,6 +104,7 @@ signals: void textureFormatChanged(QImage::Format format); void alphaMultiplierChanged(float mult); void preserveOpacityChanged(bool enabled); + void useHighDefShaderChanged(bool enabled); protected: QCustom3DVolumePrivate *dptr(); diff --git a/src/datavisualization/data/qcustom3dvolume_p.h b/src/datavisualization/data/qcustom3dvolume_p.h index b83e27fb..8b0b439e 100644 --- a/src/datavisualization/data/qcustom3dvolume_p.h +++ b/src/datavisualization/data/qcustom3dvolume_p.h @@ -41,6 +41,7 @@ struct QCustomVolumeDirtyBitField { bool textureDataDirty : 1; bool textureFormatDirty : 1; bool alphaDirty : 1; + bool shaderDirty : 1; QCustomVolumeDirtyBitField() : textureDimensionsDirty(false), @@ -48,7 +49,8 @@ struct QCustomVolumeDirtyBitField { colorTableDirty(false), textureDataDirty(false), textureFormatDirty(false), - alphaDirty(false) + alphaDirty(false), + shaderDirty(false) { } }; @@ -84,6 +86,7 @@ public: float m_alphaMultiplier; bool m_preserveOpacity; + bool m_useHighDefShader; QCustomVolumeDirtyBitField m_dirtyBitsVolume; |