diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2014-05-19 10:16:11 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2014-05-19 10:17:15 +0300 |
commit | 806fd8ab43dd59da89d04651b22c5c0440032b94 (patch) | |
tree | 41ff37fcebbe02d6c22209935b758ba7ddd59fd9 /src/datavisualization | |
parent | 92ee7767f81f7a15b8773ed97356f01ecac68d0c (diff) |
Added property for disabling shadows on custom items
Task-number: QTRD-3093
Change-Id: Ia24a1bc657af1bb1a528581e1f65fb50277e6874
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization')
7 files changed, 82 insertions, 15 deletions
diff --git a/src/datavisualization/data/customrenderitem_p.h b/src/datavisualization/data/customrenderitem_p.h index 1722163b..1dce62e5 100644 --- a/src/datavisualization/data/customrenderitem_p.h +++ b/src/datavisualization/data/customrenderitem_p.h @@ -59,6 +59,8 @@ public: inline bool isValid() const { return m_valid; } inline void setIndex(int index) { m_index = index; } inline int index() const { return m_index; } + inline void setShadowCasting(bool shadowCasting) { m_shadowCasting = shadowCasting; } + inline bool isShadowCasting() const { return m_shadowCasting; } private: GLuint m_texture; @@ -68,6 +70,7 @@ private: bool m_visible; bool m_valid; int m_index; + bool m_shadowCasting; QCustom3DItem *m_item; }; typedef QHash<QCustom3DItem *, CustomRenderItem *> CustomRenderItemArray; diff --git a/src/datavisualization/data/qcustom3ditem.cpp b/src/datavisualization/data/qcustom3ditem.cpp index bb6c96eb..0428d59b 100644 --- a/src/datavisualization/data/qcustom3ditem.cpp +++ b/src/datavisualization/data/qcustom3ditem.cpp @@ -56,6 +56,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION * * Holds the texture file name for the item. If left unset, a solid gray texture will be * used. + * + * \note To conserve memory the Image loaded from the file is cleared after a texture is created. */ // TODO: Position check in task QTRD-3057 @@ -78,6 +80,18 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION * Holds the item \a rotation as a quaternion. Defaults to \c {quaternion(0.0, 0.0, 0.0, 0.0)}. */ +/*! \qmlproperty bool Custom3DItem::visible + * + * Sets the item \a visible. Defaults to \c{true}. + */ + +/*! \qmlproperty bool Custom3DItem::shadowCasting + * + * Sets shadow casting for the item to \a enabled. Defaults to \c{true}. + * If set \c{false}, the item does not cast shadows regardless of + * \l{QAbstract3DGraph::ShadowQuality}{ShadowQuality}. + */ + /*! * \qmlmethod void Custom3DItem::setRotationAxisAndAngle(vector3d axis, real angle) * @@ -129,7 +143,7 @@ void QCustom3DItem::setMeshFile(const QString &meshFile) } } -QString QCustom3DItem::meshFile() +QString QCustom3DItem::meshFile() const { return d_ptr->m_meshFile; } @@ -152,7 +166,7 @@ void QCustom3DItem::setPosition(const QVector3D &position) } } -QVector3D QCustom3DItem::position() +QVector3D QCustom3DItem::position() const { return d_ptr->m_position; } @@ -171,7 +185,7 @@ void QCustom3DItem::setScaling(const QVector3D &scaling) } } -QVector3D QCustom3DItem::scaling() +QVector3D QCustom3DItem::scaling() const { return d_ptr->m_scaling; } @@ -209,11 +223,32 @@ void QCustom3DItem::setVisible(bool visible) } } -bool QCustom3DItem::isVisible() +bool QCustom3DItem::isVisible() const { return d_ptr->m_visible; } + +/*! \property QCustom3DItem::shadowCasting + * + * Sets shadow casting for the item to \a enabled. Defaults to \c{true}. + * If set \c{false}, the item does not cast shadows regardless of QAbstract3DGraph::ShadowQuality. + */ +void QCustom3DItem::setShadowCasting(bool enabled) +{ + if (d_ptr->m_shadowCasting != enabled) { + d_ptr->m_shadowCasting = enabled; + d_ptr->m_dirtyBits.shadowCastingDirty = true; + emit shadowCastingChanged(enabled); + emit d_ptr->needUpdate(); + } +} + +bool QCustom3DItem::isShadowCasting() const +{ + return d_ptr->m_shadowCasting; +} + /*! * A convenience function to construct rotation quaternion from \a axis and \a angle. * @@ -226,6 +261,8 @@ void QCustom3DItem::setRotationAxisAndAngle(const QVector3D &axis, float angle) /*! * Set the \a textureImage as a QImage for the item. Texture defaults to solid gray. + * + * \note To conserve memory the given QImage is cleared after a texture is created. */ void QCustom3DItem::setTextureImage(const QImage &textureImage) { @@ -249,8 +286,10 @@ void QCustom3DItem::setTextureImage(const QImage &textureImage) /*! \property QCustom3DItem::textureFile * - * Holds the texture file name for the item. If both this and textureImage are unset, a solid + * Holds the texture file name for the item. If both this and texture image are unset, a solid * gray texture will be used. + * + * \note To conserve memory the QImage loaded from the file is cleared after a texture is created. */ void QCustom3DItem::setTextureFile(const QString &textureFile) { @@ -268,7 +307,7 @@ void QCustom3DItem::setTextureFile(const QString &textureFile) } } -QString QCustom3DItem::textureFile() +QString QCustom3DItem::textureFile() const { return d_ptr->m_textureFile; } @@ -279,7 +318,8 @@ QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent) : m_position(QVector3D(0.0f, 0.0f, 0.0f)), m_scaling(QVector3D(0.1f, 0.1f, 0.1f)), m_rotation(QQuaternion(0.0f, 0.0f, 0.0f, 0.0f)), - m_visible(true) + m_visible(true), + m_shadowCasting(true) { } @@ -292,7 +332,8 @@ QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, const QString &mesh m_position(position), m_scaling(scaling), m_rotation(rotation), - m_visible(true) + m_visible(true), + m_shadowCasting(true) { } @@ -318,6 +359,7 @@ void QCustom3DItemPrivate::resetDirtyBits() m_dirtyBits.scalingDirty = false; m_dirtyBits.rotationDirty = false; m_dirtyBits.visibleDirty = false; + m_dirtyBits.shadowCastingDirty = false; } QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/data/qcustom3ditem.h b/src/datavisualization/data/qcustom3ditem.h index 77e33404..72aad604 100644 --- a/src/datavisualization/data/qcustom3ditem.h +++ b/src/datavisualization/data/qcustom3ditem.h @@ -37,6 +37,7 @@ class QT_DATAVISUALIZATION_EXPORT QCustom3DItem : public QObject Q_PROPERTY(QVector3D scaling READ scaling WRITE setScaling NOTIFY scalingChanged) Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(bool shadowCasting READ isShadowCasting WRITE setShadowCasting NOTIFY shadowCastingChanged) public: explicit QCustom3DItem(QObject *parent = 0); @@ -46,22 +47,25 @@ public: virtual ~QCustom3DItem(); void setMeshFile(const QString &meshFile); - QString meshFile(); + QString meshFile() const; void setTextureFile(const QString &textureFile); - QString textureFile(); + QString textureFile() const; void setPosition(const QVector3D &position); - QVector3D position(); + QVector3D position() const; void setScaling(const QVector3D &scaling); - QVector3D scaling(); + QVector3D scaling() const; void setRotation(const QQuaternion &rotation); QQuaternion rotation(); void setVisible(bool visible); - bool isVisible(); + bool isVisible() const; + + void setShadowCasting(bool enabled); + bool isShadowCasting() const; Q_INVOKABLE void setRotationAxisAndAngle(const QVector3D &axis, float angle); @@ -74,6 +78,7 @@ signals: void scalingChanged(const QVector3D &scaling); void rotationChanged(const QQuaternion &rotation); void visibleChanged(bool visible); + void shadowCastingChanged(bool shadowCasting); protected: QScopedPointer<QCustom3DItemPrivate> d_ptr; diff --git a/src/datavisualization/data/qcustom3ditem_p.h b/src/datavisualization/data/qcustom3ditem_p.h index 007c9fc4..2523abd4 100644 --- a/src/datavisualization/data/qcustom3ditem_p.h +++ b/src/datavisualization/data/qcustom3ditem_p.h @@ -40,6 +40,7 @@ struct QCustomItemDirtyBitField { bool scalingDirty : 1; bool rotationDirty : 1; bool visibleDirty : 1; + bool shadowCastingDirty : 1; QCustomItemDirtyBitField() : textureDirty(false), @@ -47,7 +48,8 @@ struct QCustomItemDirtyBitField { positionDirty(false), scalingDirty(false), rotationDirty(false), - visibleDirty(false) + visibleDirty(false), + shadowCastingDirty(false) { } }; @@ -74,6 +76,7 @@ public: QVector3D m_scaling; QQuaternion m_rotation; bool m_visible; + bool m_shadowCasting; QCustomItemDirtyBitField m_dirtyBits; diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc index 4fac937b..a71bd28b 100644 --- a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc +++ b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc @@ -192,6 +192,10 @@ * Gets ownership of \a item back and removes the \a item from the graph. * * \since Qt Data Visualization 1.1 + * + * \note If the same item is added back to the graph, the texture file needs to be re-set. + * + * \sa Custom3DItem::textureFile */ /*! diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp index a2181271..82952a26 100644 --- a/src/datavisualization/engine/abstract3drenderer.cpp +++ b/src/datavisualization/engine/abstract3drenderer.cpp @@ -582,6 +582,7 @@ CustomRenderItem *Abstract3DRenderer::addCustomItem(QCustom3DItem *item) QVector3D translation = convertPositionToTranslation(item->position()); newItem->setTranslation(translation); newItem->setVisible(item->isVisible()); + newItem->setShadowCasting(item->isShadowCasting()); m_customRenderCache.insert(item, newItem); return newItem; } @@ -620,6 +621,10 @@ void Abstract3DRenderer::updateCustomItem(CustomRenderItem *renderItem) renderItem->setVisible(item->isVisible()); item->d_ptr->m_dirtyBits.visibleDirty = false; } + if (item->d_ptr->m_dirtyBits.shadowCastingDirty) { + renderItem->setShadowCasting(item->isShadowCasting()); + item->d_ptr->m_dirtyBits.shadowCastingDirty = false; + } } void Abstract3DRenderer::drawCustomItems(RenderingState state, @@ -700,7 +705,7 @@ void Abstract3DRenderer::drawCustomItems(RenderingState state, itemColor /= 255.0f; shader->setUniformValue(shader->color(), itemColor); m_drawer->drawObject(shader, item->mesh()); - } else { + } else if (item->isShadowCasting()) { // Depth render shader->setUniformValue(shader->MVP(), depthProjectionViewMatrix * modelMatrix); m_drawer->drawObject(shader, item->mesh()); diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp index 9818d176..196460da 100644 --- a/src/datavisualization/engine/qabstract3dgraph.cpp +++ b/src/datavisualization/engine/qabstract3dgraph.cpp @@ -430,6 +430,11 @@ void QAbstract3DGraph::removeCustomItemAt(const QVector3D &position) * Gets ownership of given \a item back and removes the \a item from the graph. * * \since Qt Data Visualization 1.1 + * + * \note If the same item is added back to the graph, the texture or the texture file needs to be + * re-set. + * + * \sa QCustom3DItem::setTextureImage(), QCustom3DItem::setTextureFile() */ void QAbstract3DGraph::releaseCustomItem(QCustom3DItem *item) { |