diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-12-02 12:59:46 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-12-03 10:17:58 +0200 |
commit | 9549c09d4cfee485c31f54360a32d100d06a2095 (patch) | |
tree | 59e2d31fc305dd37f22d216a3809313228869253 /src/datavisualization | |
parent | 1aafc43b5646eae86a53a7121aa29e0096b5fde8 (diff) |
Move series specific visual elements to series, part 2
Surface series grid visibility and smoothness
Task-number: QTRD-2557
Change-Id: I0beecb7785bf2fb489d0faba797a145151513a79
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization')
-rw-r--r-- | src/datavisualization/data/qabstract3dseries.cpp | 87 | ||||
-rw-r--r-- | src/datavisualization/data/qsurface3dseries.cpp | 100 | ||||
-rw-r--r-- | src/datavisualization/data/qsurface3dseries.h | 14 | ||||
-rw-r--r-- | src/datavisualization/data/qsurface3dseries_p.h | 4 | ||||
-rw-r--r-- | src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc | 9 | ||||
-rw-r--r-- | src/datavisualization/engine/q3dscene.h | 1 | ||||
-rw-r--r-- | src/datavisualization/engine/q3dsurface.cpp | 37 | ||||
-rw-r--r-- | src/datavisualization/engine/q3dsurface.h | 10 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3dcontroller.cpp | 80 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3dcontroller_p.h | 16 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3drenderer.cpp | 41 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3drenderer_p.h | 7 | ||||
-rw-r--r-- | src/datavisualization/utils/shaderhelper.cpp | 4 |
13 files changed, 235 insertions, 175 deletions
diff --git a/src/datavisualization/data/qabstract3dseries.cpp b/src/datavisualization/data/qabstract3dseries.cpp index d5c4c6b8..93ce7fb0 100644 --- a/src/datavisualization/data/qabstract3dseries.cpp +++ b/src/datavisualization/data/qabstract3dseries.cpp @@ -64,6 +64,33 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE */ /*! + * \qmlproperty Abstract3DSeries.Mesh Abstract3DSeries::mesh + * + * Sets the mesh of the items in the series, or the selection pointer in case of + * Surface3DSeries. If the \a mesh is \l{QAbstract3DSeries::MeshUserDefined}{Abstract3DSeries.MeshUserDefined}, + * then the userDefinedMesh property must also be set for items to render properly. + * The default value depends on the graph type. + */ + +/*! + * \qmlproperty bool Abstract3DSeries::meshSmooth + * + * If \a enable is \c true, smooth versions of predefined meshes set via mesh property are used. + * This property doesn't affect custom meshes used when mesh is + * \l{QAbstract3DSeries::MeshUserDefined}{Abstract3DSeries.MeshUserDefined}. + * Defaults to \c false. + */ + +/*! + * \qmlproperty string Abstract3DSeries::userDefinedMesh + * + * Sets the \a fileName for user defined custom mesh for objects that is used when mesh + * is \l{QAbstract3DSeries::MeshUserDefined}{Abstract3DSeries.MeshUserDefined}. + * \note The file specified by \a fileName needs to be in Wavefront obj format and include + * vertices, normals and UVs. It also needs to be in triangles. + */ + +/*! * \enum QAbstract3DSeries::SeriesType * * Type of the series. @@ -79,34 +106,34 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE */ /*! - \enum QAbstract3DSeries::Mesh - - Predefined mesh types. All styles are not usable with all visualization types. - - \value MeshUserDefined - User defined mesh, set via QAbstract3DSeries::userDefinedMesh property. - \value MeshBar - Basic rectangular bar. - \value MeshCube - Basic cube. - \value MeshPyramid - Four-sided pyramid. - \value MeshCone - Basic cone. - \value MeshCylinder - Basic cylinder. - \value MeshBevelBar - Slightly beveled (rounded) rectangular bar. - \value MeshBevelCube - Slightly beveled (rounded) cube. - \value MeshSphere - Sphere. - \value MeshMinimal - The minimal 3D mesh: a triangular pyramid. Usable only with Q3DScatter. - \value MeshPoint - 2D point. Usable only with Q3DScatter. - \b Note: Shadows and color gradients do not affect this style. -*/ + * \enum QAbstract3DSeries::Mesh + * + * Predefined mesh types. All styles are not usable with all visualization types. + * + * \value MeshUserDefined + * User defined mesh, set via QAbstract3DSeries::userDefinedMesh property. + * \value MeshBar + * Basic rectangular bar. + * \value MeshCube + * Basic cube. + * \value MeshPyramid + * Four-sided pyramid. + * \value MeshCone + * Basic cone. + * \value MeshCylinder + * Basic cylinder. + * \value MeshBevelBar + * Slightly beveled (rounded) rectangular bar. + * \value MeshBevelCube + * Slightly beveled (rounded) cube. + * \value MeshSphere + * Sphere. + * \value MeshMinimal + * The minimal 3D mesh: a triangular pyramid. Usable only with Q3DScatter. + * \value MeshPoint + * 2D point. Usable only with Q3DScatter. + * \b Note: Shadows and color gradients do not affect this style. + */ /*! * \internal @@ -201,9 +228,9 @@ QAbstract3DSeries::Mesh QAbstract3DSeries::mesh() const /*! * \property QAbstract3DSeries::meshSmooth * - * If \a enable is true, smooth versions of predefined meshes set via mesh property are used. + * If \a enable is \c true, smooth versions of predefined meshes set via mesh property are used. * This property doesn't affect custom meshes used when mesh is MeshUserDefined. - * Defaults to false. + * Defaults to \c false. */ void QAbstract3DSeries::setMeshSmooth(bool enable) { diff --git a/src/datavisualization/data/qsurface3dseries.cpp b/src/datavisualization/data/qsurface3dseries.cpp index baae3a78..5a47a6e4 100644 --- a/src/datavisualization/data/qsurface3dseries.cpp +++ b/src/datavisualization/data/qsurface3dseries.cpp @@ -104,6 +104,32 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE */ /*! + * \qmlproperty bool Surface3DSeries::flatShadingEnabled + * + * Sets surface flat shading to \a enabled. It is preset to \c true by default. + * When disabled, the normals on the surface are interpolated making edges looking round. + * When enabled, the normals are kept same on a triangle making the color of the triangle solid. + * This makes the data more readable from the model. + * \note Flat shaded surfaces require at least GLSL version 1.2 with GL_EXT_gpu_shader4 extension. + * The value of flatShadingSupported property indicates if flat shading is supported at runtime. + */ + +/*! + * \qmlproperty bool Surface3DSeries::surfaceGridEnabled + * + * Sets surface grid to \a enabled. It is preset to \c true by default. + */ + +/*! + * \qmlproperty bool Surface3DSeries::flatShadingSupported + * + * Flat shading for surfaces requires at least GLSL version 1.2 with GL_EXT_gpu_shader4 extension. + * If true, flat shading for surfaces is supported by current system. + * \note This read-only property is set to its correct value after first render pass. + * Before then it is always true. + */ + +/*! * Constructs QSurface3DSeries with the given \a parent. */ QSurface3DSeries::QSurface3DSeries(QObject *parent) : @@ -188,6 +214,62 @@ QPoint QSurface3DSeries::invalidSelectionPosition() const } /*! + * \property QSurface3DSeries::flatShadingEnabled + * + * Sets surface flat shading to \a enabled. It is preset to \c true by default. + * When disabled, the normals on the surface are interpolated making edges looking round. + * When enabled, the normals are kept same on a triangle making the color of the triangle solid. + * This makes the data more readable from the model. + * \note Flat shaded surfaces require at least GLSL version 1.2 with GL_EXT_gpu_shader4 extension. + * The value of flatShadingSupported property indicates if flat shading is supported at runtime. + */ +void QSurface3DSeries::setFlatShadingEnabled(bool enabled) +{ + if (dptr()->m_flatShadingEnabled != enabled) { + dptr()->setFlatShadingEnabled(enabled); + emit flatShadingEnabledChanged(enabled); + } +} + +bool QSurface3DSeries::isFlatShadingEnabled() const +{ + return dptrc()->m_flatShadingEnabled; +} + +/*! + * \property QSurface3DSeries::flatShadingSupported + * Flat shading for surfaces requires at least GLSL version 1.2 with GL_EXT_gpu_shader4 extension. + * If true, flat shading for surfaces is supported by current system. + * \note This read-only property is set to its correct value after first render pass. + * Before then it is always true. + */ +bool QSurface3DSeries::isFlatShadingSupported() const +{ + if (d_ptr->m_controller) + return static_cast<Surface3DController *>(d_ptr->m_controller)->isFlatShadingSupported(); + else + return true; +} + +/*! + * \property QSurface3DSeries::surfaceGridEnabled + * + * Sets surface grid to \a enabled. It is preset to \c true by default. + */ +void QSurface3DSeries::setSurfaceGridEnabled(bool enabled) +{ + if (dptr()->m_surfaceGridEnabled != enabled) { + dptr()->setSurfaceGridEnabled(enabled); + emit surfaceGridEnabledChanged(enabled); + } +} + +bool QSurface3DSeries::isSurfaceGridEnabled() const +{ + return dptrc()->m_surfaceGridEnabled; +} + +/*! * \internal */ QSurface3DSeriesPrivate *QSurface3DSeries::dptr() @@ -207,7 +289,9 @@ const QSurface3DSeriesPrivate *QSurface3DSeries::dptrc() const QSurface3DSeriesPrivate::QSurface3DSeriesPrivate(QSurface3DSeries *q) : QAbstract3DSeriesPrivate(q, QAbstract3DSeries::SeriesTypeSurface), - m_selectedPoint(Surface3DController::invalidSelectionPosition()) + m_selectedPoint(Surface3DController::invalidSelectionPosition()), + m_flatShadingEnabled(true), + m_surfaceGridEnabled(true) { m_itemLabelFormat = QStringLiteral("(@xLabel, @yLabel, @zLabel)"); m_mesh = QAbstract3DSeries::MeshSphere; @@ -259,4 +343,18 @@ void QSurface3DSeriesPrivate::setSelectedPoint(const QPoint &position) } } +void QSurface3DSeriesPrivate::setFlatShadingEnabled(bool enabled) +{ + m_flatShadingEnabled = enabled; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + +void QSurface3DSeriesPrivate::setSurfaceGridEnabled(bool enabled) +{ + m_surfaceGridEnabled = enabled; + if (m_controller) + m_controller->markSeriesVisualsDirty(); +} + QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/data/qsurface3dseries.h b/src/datavisualization/data/qsurface3dseries.h index e449af58..f4b64b96 100644 --- a/src/datavisualization/data/qsurface3dseries.h +++ b/src/datavisualization/data/qsurface3dseries.h @@ -31,6 +31,9 @@ class QT_DATAVISUALIZATION_EXPORT QSurface3DSeries : public QAbstract3DSeries Q_OBJECT Q_PROPERTY(QSurfaceDataProxy *dataProxy READ dataProxy WRITE setDataProxy NOTIFY dataProxyChanged) Q_PROPERTY(QPoint selectedPoint READ selectedPoint WRITE setSelectedPoint NOTIFY selectedPointChanged) + Q_PROPERTY(bool flatShadingEnabled READ isFlatShadingEnabled WRITE setFlatShadingEnabled NOTIFY flatShadingEnabledChanged) + Q_PROPERTY(bool surfaceGridEnabled READ isSurfaceGridEnabled WRITE setSurfaceGridEnabled NOTIFY surfaceGridEnabledChanged) + Q_PROPERTY(bool flatShadingSupported READ isFlatShadingSupported NOTIFY flatShadingSupportedChanged) public: explicit QSurface3DSeries(QObject *parent = 0); @@ -44,9 +47,20 @@ public: QPoint selectedPoint() const; QPoint invalidSelectionPosition() const; + void setFlatShadingEnabled(bool enabled); + bool isFlatShadingEnabled() const; + + void setSurfaceGridEnabled(bool enabled); + bool isSurfaceGridEnabled() const; + + bool isFlatShadingSupported() const; + signals: void dataProxyChanged(QSurfaceDataProxy *proxy); void selectedPointChanged(QPoint position); + void flatShadingEnabledChanged(bool enable); + void surfaceGridEnabledChanged(bool enable); + void flatShadingSupportedChanged(bool enable); protected: explicit QSurface3DSeries(QSurface3DSeriesPrivate *d, QObject *parent = 0); diff --git a/src/datavisualization/data/qsurface3dseries_p.h b/src/datavisualization/data/qsurface3dseries_p.h index a1752b77..a3acb8d5 100644 --- a/src/datavisualization/data/qsurface3dseries_p.h +++ b/src/datavisualization/data/qsurface3dseries_p.h @@ -45,11 +45,15 @@ public: virtual void connectControllerAndProxy(Abstract3DController *newController); void setSelectedPoint(const QPoint &position); + void setFlatShadingEnabled(bool enabled); + void setSurfaceGridEnabled(bool enabled); private: QSurface3DSeries *qptr(); QPoint m_selectedPoint; + bool m_flatShadingEnabled; + bool m_surfaceGridEnabled; private: friend class QSurface3DSeries; diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc index cbc8a900..a3886008 100644 --- a/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc +++ b/src/datavisualization/doc/src/qtdatavisualization-qml-surface3d.qdoc @@ -67,15 +67,6 @@ */ /*! - \qmlproperty bool Surface3D::smoothSurfaceEnabled - The smoothing of surface. If false, the shading of the surface is flat. - */ - -/*! - \qmlproperty bool Surface3D::surfaceGridEnabled - The surface grid visibility. If false, no surface grid is drawn. - */ - /*! \qmlproperty ColorGradient Surface3D::gradient The current surface gradient. Setting this property replaces the previous gradient. diff --git a/src/datavisualization/engine/q3dscene.h b/src/datavisualization/engine/q3dscene.h index 14854361..8033b595 100644 --- a/src/datavisualization/engine/q3dscene.h +++ b/src/datavisualization/engine/q3dscene.h @@ -82,6 +82,7 @@ public: float fixedRotation = 0.0f, float distanceModifier = 0.0f); private: + // TODO: Move to private void emitNeedRender(); signals: diff --git a/src/datavisualization/engine/q3dsurface.cpp b/src/datavisualization/engine/q3dsurface.cpp index b678ba16..9a0fcd03 100644 --- a/src/datavisualization/engine/q3dsurface.cpp +++ b/src/datavisualization/engine/q3dsurface.cpp @@ -105,10 +105,6 @@ Q3DSurface::Q3DSurface() &Q3DSurface::themeChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::shadowQualityChanged, this, &Q3DSurface::shadowQualityChanged); - QObject::connect(d_ptr->m_shared, &Surface3DController::smoothSurfaceEnabledChanged, this, - &Q3DSurface::smoothSurfaceEnabledChanged); - QObject::connect(d_ptr->m_shared, &Surface3DController::surfaceGridEnabledChanged, this, - &Q3DSurface::surfaceGridEnabledChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::needRender, this, &Q3DWindow::renderLater); } @@ -244,24 +240,6 @@ QDataVis::ShadowQuality Q3DSurface::shadowQuality() const } /*! - * \property Q3DSurface::smoothSurfaceEnabled - * - * Sets surface smoothing to \a enabled. It is preset to \c false by default. - * When enabled the normals on the surface are interpolated making edges looking round. If turned - * off the normals are kept same on a triangle making the color of the triangle solid. This makes - * the data more readable from the model. - */ -void Q3DSurface::setSmoothSurfaceEnabled(bool enabled) -{ - d_ptr->m_shared->setSmoothSurface(enabled); -} - -bool Q3DSurface::isSmoothSurfaceEnabled() const -{ - return d_ptr->m_shared->smoothSurface(); -} - -/*! * \property Q3DSurface::selectionMode * * Sets point selection \a mode to one of \c QDataVis::SelectionMode. Surface supports @@ -279,21 +257,6 @@ QDataVis::SelectionFlags Q3DSurface::selectionMode() const } /*! - * \property Q3DSurface::surfaceGridEnabled - * - * Sets surface grid to \a enabled. It is preset to \c true by default. - */ -void Q3DSurface::setSurfaceGridEnabled(bool enabled) -{ - d_ptr->m_shared->setSurfaceGrid(enabled); -} - -bool Q3DSurface::isSurfaceGridEnabled() const -{ - return d_ptr->m_shared->surfaceGrid(); -} - -/*! * \property Q3DSurface::gradient * * The current surface gradient. Setting this property replaces the previous gradient with diff --git a/src/datavisualization/engine/q3dsurface.h b/src/datavisualization/engine/q3dsurface.h index 2a4a56dd..bbe2d47a 100644 --- a/src/datavisualization/engine/q3dsurface.h +++ b/src/datavisualization/engine/q3dsurface.h @@ -38,8 +38,6 @@ class QT_DATAVISUALIZATION_EXPORT Q3DSurface : public Q3DWindow Q_PROPERTY(QtDataVisualization::QDataVis::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) Q_PROPERTY(Q3DTheme* theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) - Q_PROPERTY(bool smoothSurfaceEnabled READ isSmoothSurfaceEnabled WRITE setSmoothSurfaceEnabled NOTIFY smoothSurfaceEnabledChanged) - Q_PROPERTY(bool surfaceGridEnabled READ isSurfaceGridEnabled WRITE setSurfaceGridEnabled NOTIFY surfaceGridEnabledChanged) Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient) Q_PROPERTY(Q3DScene* scene READ scene) @@ -57,14 +55,8 @@ public: void setShadowQuality(QDataVis::ShadowQuality quality); QDataVis::ShadowQuality shadowQuality() const; - void setSmoothSurfaceEnabled(bool enabled); - bool isSmoothSurfaceEnabled() const; - void setSelectionMode(QDataVis::SelectionFlags mode); QDataVis::SelectionFlags selectionMode() const; - void setSurfaceGridEnabled(bool enabled); - bool isSurfaceGridEnabled() const; - void setGradient(const QLinearGradient &gradient); QLinearGradient gradient() const; @@ -87,8 +79,6 @@ signals: void selectionModeChanged(QDataVis::SelectionFlags mode); void themeChanged(Q3DTheme *theme); void shadowQualityChanged(QDataVis::ShadowQuality quality); - void smoothSurfaceEnabledChanged(bool enabled); - void surfaceGridEnabledChanged(bool visible); protected: void mouseDoubleClickEvent(QMouseEvent *event); diff --git a/src/datavisualization/engine/surface3dcontroller.cpp b/src/datavisualization/engine/surface3dcontroller.cpp index 5b603a62..b1586a78 100644 --- a/src/datavisualization/engine/surface3dcontroller.cpp +++ b/src/datavisualization/engine/surface3dcontroller.cpp @@ -24,6 +24,7 @@ #include "q3dcategoryaxis.h" #include "qsurfacedataproxy_p.h" #include "qsurface3dseries_p.h" +#include "shaderhelper_p.h" #include <QMatrix4x4> @@ -34,13 +35,11 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE Surface3DController::Surface3DController(QRect rect) : Abstract3DController(rect), m_renderer(0), - m_isSmoothSurfaceEnabled(false), - m_isSurfaceEnabled(true), - m_isSurfaceGridEnabled(true), m_selectedPoint(invalidSelectionPosition()), m_selectedSeries(0), m_rowsChangeStartId(0), - m_rowsChangeCount(0) + m_rowsChangeCount(0), + m_flatShadingSupported(true) { // Setting a null axis creates a new default axis according to orientation and graph type. // Note: these cannot be set in the Abstract3DController constructor, as they will call virtual @@ -68,8 +67,6 @@ void Surface3DController::initializeOpenGL() synchDataToRenderer(); QObject::connect(m_renderer, &Surface3DRenderer::pointClicked, this, &Surface3DController::handlePointClicked, Qt::QueuedConnection); - QObject::connect(m_renderer, &Surface3DRenderer::requestSmoothSurface, this, - &Surface3DController::handleRequestSmoothSurface, Qt::QueuedConnection); emitNeedRender(); } @@ -78,11 +75,6 @@ void Surface3DController::synchDataToRenderer() if (!isInitialized()) return; - if (m_changeTracker.surfaceGridChanged) { - m_renderer->updateSurfaceGridStatus(m_isSurfaceGridEnabled); - m_changeTracker.surfaceGridChanged = false; - } - Abstract3DController::synchDataToRenderer(); // Notify changes to renderer @@ -91,14 +83,6 @@ void Surface3DController::synchDataToRenderer() m_changeTracker.gradientColorChanged = false; } - if (m_changeTracker.smoothStatusChanged) { - bool oldSmoothStatus = m_isSmoothSurfaceEnabled; - m_isSmoothSurfaceEnabled = m_renderer->updateSmoothStatus(m_isSmoothSurfaceEnabled); - m_changeTracker.smoothStatusChanged = false; - if (oldSmoothStatus != m_isSmoothSurfaceEnabled) - emit smoothSurfaceEnabledChanged(m_isSmoothSurfaceEnabled); - } - if (m_changeTracker.rowsChanged) { m_renderer->updateRows(m_rowsChangeStartId, m_rowsChangeCount); m_changeTracker.rowsChanged = false; @@ -108,7 +92,6 @@ void Surface3DController::synchDataToRenderer() m_renderer->updateSelectedPoint(m_selectedPoint, m_selectedSeries); m_changeTracker.selectedPointChanged = false; } - } void Surface3DController::handleAxisAutoAdjustRangeChangedInOrientation(Q3DAbstractAxis::AxisOrientation orientation, bool autoAdjust) @@ -142,6 +125,11 @@ QPoint Surface3DController::invalidSelectionPosition() return invalidSelectionPoint; } +bool Surface3DController::isFlatShadingSupported() +{ + return m_flatShadingSupported; +} + void Surface3DController::addSeries(QAbstract3DSeries *series) { Q_ASSERT(series && series->type() == QAbstract3DSeries::SeriesTypeSurface); @@ -154,7 +142,7 @@ void Surface3DController::addSeries(QAbstract3DSeries *series) qWarning("Surface graph only supports a single series."); } - QSurface3DSeries *surfaceSeries = static_cast<QSurface3DSeries *>(series); + QSurface3DSeries *surfaceSeries = static_cast<QSurface3DSeries *>(series); if (surfaceSeries->selectedPoint() != invalidSelectionPosition()) setSelectedPoint(surfaceSeries->selectedPoint(), surfaceSeries); } @@ -184,37 +172,6 @@ QList<QSurface3DSeries *> Surface3DController::surfaceSeriesList() return surfaceSeriesList; } -void Surface3DController::setSmoothSurface(bool enable) -{ - if (enable != m_isSmoothSurfaceEnabled) { - m_isSmoothSurfaceEnabled = enable; - m_changeTracker.smoothStatusChanged = true; - emit smoothSurfaceEnabledChanged(enable); - emitNeedRender(); - } -} - -bool Surface3DController::smoothSurface() -{ - return m_isSmoothSurfaceEnabled; -} - -void Surface3DController::setSurfaceGrid(bool enable) -{ - if (enable != m_isSurfaceGridEnabled) { - m_isSurfaceGridEnabled = enable; - m_changeTracker.surfaceGridChanged = true; - emit surfaceGridEnabledChanged(enable); - emitNeedRender(); - m_isDataDirty = true; - } -} - -bool Surface3DController::surfaceGrid() -{ - return m_isSurfaceGridEnabled; -} - void Surface3DController::setGradient(const QLinearGradient &gradient) { if (gradient != m_userDefinedGradient) { @@ -347,6 +304,19 @@ void Surface3DController::handlePointClicked(const QPoint &position, QSurface3DS // TODO: Also hover needed? (QTRD-2131) } +void Surface3DController::handleFlatShadingSupportedChange(bool supported) +{ + // Handle renderer flat surface support indicator signal. This happens exactly once per renderer. + if (m_flatShadingSupported != supported) { + m_flatShadingSupported = supported; + // Emit the change for all added surfaces + foreach (QAbstract3DSeries *series, m_seriesList) { + QSurface3DSeries *surfaceSeries = static_cast<QSurface3DSeries *>(series); + emit surfaceSeries->flatShadingSupportedChanged(m_flatShadingSupported); + } + } +} + void Surface3DController::handleRowsChanged(int startIndex, int count) { QSurfaceDataProxy *sender = static_cast<QSurfaceDataProxy *>(QObject::sender()); @@ -363,12 +333,6 @@ void Surface3DController::handleRowsChanged(int startIndex, int count) } } -void Surface3DController::handleRequestSmoothSurface(bool enable) -{ - setSmoothSurface(enable); - emitNeedRender(); -} - void Surface3DController::adjustValueAxisRange() { if (m_seriesList.size()) { diff --git a/src/datavisualization/engine/surface3dcontroller_p.h b/src/datavisualization/engine/surface3dcontroller_p.h index ffc3b4f3..ef9c8494 100644 --- a/src/datavisualization/engine/surface3dcontroller_p.h +++ b/src/datavisualization/engine/surface3dcontroller_p.h @@ -63,15 +63,13 @@ class QT_DATAVISUALIZATION_EXPORT Surface3DController : public Abstract3DControl private: Surface3DChangeBitField m_changeTracker; Surface3DRenderer *m_renderer; - bool m_isSmoothSurfaceEnabled; - bool m_isSurfaceEnabled; - bool m_isSurfaceGridEnabled; QLinearGradient m_userDefinedGradient; QPoint m_selectedPoint; QSurface3DSeries *m_selectedSeries; // Points to the series for which the point is selected in // single series selection cases. int m_rowsChangeStartId; int m_rowsChangeCount; + bool m_flatShadingSupported; public: explicit Surface3DController(QRect rect); @@ -80,12 +78,6 @@ public: void initializeOpenGL(); virtual void synchDataToRenderer(); - void setSmoothSurface(bool enable); - bool smoothSurface(); - - void setSurfaceGrid(bool enable); - bool surfaceGrid(); - void setGradient(const QLinearGradient &gradient); QLinearGradient gradient() const; @@ -99,6 +91,7 @@ public: virtual void handleSeriesVisibilityChangedBySender(QObject *sender); static QPoint invalidSelectionPosition(); + bool isFlatShadingSupported(); virtual void addSeries(QAbstract3DSeries *series); virtual void removeSeries(QAbstract3DSeries *series); @@ -110,11 +103,8 @@ public slots: // Renderer callback handlers void handlePointClicked(const QPoint &position, QSurface3DSeries *series); - void handleRequestSmoothSurface(bool enable); -signals: - void smoothSurfaceEnabledChanged(bool enable); - void surfaceGridEnabledChanged(bool enable); + void handleFlatShadingSupportedChange(bool supported); private: void adjustValueAxisRange(); diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 5b9aa9d8..bb74e084 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -99,7 +99,7 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) m_selectionTexture(0), m_selectionResultTexture(0), m_shadowQualityToShader(33.3f), - m_cachedSmoothSurface(true), + m_cachedFlatShading(false), m_flatSupported(true), m_cachedSurfaceVisible(true), m_cachedSurfaceGridOn(true), @@ -120,7 +120,9 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) QStringLiteral(":/shaders/fragmentSurfaceFlat")); if (!tester.testCompile()) { m_flatSupported = false; - emit requestSmoothSurface(true); + connect(this, &Surface3DRenderer::flatShadingSupportedChanged, + controller, &Surface3DController::handleFlatShadingSupportedChange); + emit flatShadingSupportedChanged(m_flatSupported); qWarning() << "Warning: Flat qualifier not supported on your platform's GLSL language." " Requires at least GLSL version 1.2 with GL_EXT_gpu_shader4 extension."; } @@ -244,7 +246,7 @@ void Surface3DRenderer::updateData() loadSurfaceObj(); // Note: Data setup can change sample space (as min width/height is 1) - if (m_cachedSmoothSurface) { + if (!m_cachedFlatShading) { m_surfaceObj->setUpSmoothData(m_dataArray, m_sampleSpace, m_heightNormalizer, m_axisCacheY.min(), dimensionChanged); } else { @@ -270,6 +272,19 @@ void Surface3DRenderer::updateData() updateSelectedPoint(m_selectedPoint, m_selectedSeries); } +void Surface3DRenderer::updateSeries(const QList<QAbstract3DSeries *> &seriesList, bool updateVisibility) +{ + Abstract3DRenderer::updateSeries(seriesList, updateVisibility); + + // TODO: move to render cache when multiseries support implemented QTRD-2657 + // TODO: until then just update them always. + if (m_visibleSeriesList.size()) { + QSurface3DSeries *series = static_cast<QSurface3DSeries *>(m_visibleSeriesList.at(0).series()); + updateFlatStatus(series->isFlatShadingEnabled()); + updateSurfaceGridStatus(series->isSurfaceGridEnabled()); + } +} + void Surface3DRenderer::updateRows(int startIndex, int count) { // TODO: Properly support non-straight rows and columns (QTRD-2643) @@ -300,7 +315,7 @@ void Surface3DRenderer::updateRows(int startIndex, int count) (*(m_dataArray.at(i)))[j] = array->at(i + m_sampleSpace.y())->at(j + m_sampleSpace.x()); } - if (m_cachedSmoothSurface) { + if (!m_cachedFlatShading) { m_surfaceObj->updateSmoothRows(m_dataArray, startIndex, endRow, m_heightNormalizer, m_axisCacheY.min()); } else { @@ -355,7 +370,7 @@ void Surface3DRenderer::updateSliceDataModel(const QPoint &point) if (!m_sliceSurfaceObj) loadSliceSurfaceObj(); - if (m_cachedSmoothSurface) { + if (!m_cachedFlatShading) { m_sliceSurfaceObj->setUpSmoothData(m_sliceDataArray, sliceRect, m_heightNormalizer, m_axisCacheY.min(), true); } else { @@ -1781,24 +1796,24 @@ void Surface3DRenderer::calculateSceneScalingFactors() #endif } -bool Surface3DRenderer::updateSmoothStatus(bool enable) +bool Surface3DRenderer::updateFlatStatus(bool enable) { - if (!enable && !m_flatSupported) { + if (enable && !m_flatSupported) { qWarning() << "Warning: Flat qualifier not supported on your platform's GLSL language." " Requires at least GLSL version 1.2 with GL_EXT_gpu_shader4 extension."; - enable = true; + enable = false; } bool changed = false; - if (enable != m_cachedSmoothSurface) { - m_cachedSmoothSurface = enable; + if (enable != m_cachedFlatShading) { + m_cachedFlatShading = enable; changed = true; initSurfaceShaders(); } // If no surface object created yet, don't try to update the object if (m_surfaceObj && changed && m_sampleSpace.width() >= 2 && m_sampleSpace.height() >= 2) { - if (m_cachedSmoothSurface) { + if (!m_cachedFlatShading) { m_surfaceObj->setUpSmoothData(m_dataArray, m_sampleSpace, m_heightNormalizer, m_axisCacheY.min(), true); } else { @@ -1807,7 +1822,7 @@ bool Surface3DRenderer::updateSmoothStatus(bool enable) } } - return m_cachedSmoothSurface; + return m_cachedFlatShading; } void Surface3DRenderer::updateSelectedPoint(const QPoint &position, const QSurface3DSeries *series) @@ -2050,7 +2065,7 @@ void Surface3DRenderer::initShaders(const QString &vertexShader, const QString & if (m_surfaceShader) delete m_surfaceShader; #if !defined(QT_OPENGL_ES_2) - if (m_cachedSmoothSurface) { + if (!m_cachedFlatShading) { if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexShadow"), QStringLiteral(":/shaders/fragmentSurfaceShadowNoTex")); diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h index ce49cf13..476ef78e 100644 --- a/src/datavisualization/engine/surface3drenderer_p.h +++ b/src/datavisualization/engine/surface3drenderer_p.h @@ -109,7 +109,7 @@ private: GLuint m_selectionTexture; GLuint m_selectionResultTexture; GLfloat m_shadowQualityToShader; - bool m_cachedSmoothSurface; + bool m_cachedFlatShading; bool m_flatSupported; bool m_cachedSurfaceVisible; bool m_cachedSurfaceGridOn; @@ -134,9 +134,10 @@ public: ~Surface3DRenderer(); void updateData(); + void updateSeries(const QList<QAbstract3DSeries *> &seriesList, bool updateVisibility); void updateRows(int startIndex, int count); void updateScene(Q3DScene *scene); - bool updateSmoothStatus(bool enable); + bool updateFlatStatus(bool enable); void updateSurfaceGridStatus(bool enable); void updateSurfaceGradient(const QLinearGradient &gradient); void updateSlicingActive(bool isSlicing); @@ -150,7 +151,7 @@ protected: signals: void pointClicked(QPoint position, QSurface3DSeries *series); - void requestSmoothSurface(bool enable); + void flatShadingSupportedChanged(bool supported); private: void setViewPorts(); diff --git a/src/datavisualization/utils/shaderhelper.cpp b/src/datavisualization/utils/shaderhelper.cpp index 7eb48945..b4d2ee76 100644 --- a/src/datavisualization/utils/shaderhelper.cpp +++ b/src/datavisualization/utils/shaderhelper.cpp @@ -98,15 +98,17 @@ void ShaderHelper::initialize() bool ShaderHelper::testCompile() { bool result = true; + // Discard warnings, we only need the result QtMessageHandler handler = qInstallMessageHandler(discardDebugMsgs); if (m_program) delete m_program; - m_program = new QOpenGLShaderProgram(m_caller); + m_program = new QOpenGLShaderProgram(); if (!m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, m_vertexShaderFile)) result = false; if (!m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, m_fragmentShaderFile)) result = false; + // Restore actual message handler qInstallMessageHandler(handler); return result; |