diff options
author | Paolo Angelelli <paolo.angelelli.qt@gmail.com> | 2019-12-27 22:39:47 +0100 |
---|---|---|
committer | paolo <paolo.angelelli.qt@gmail.com> | 2020-02-11 19:35:35 +0100 |
commit | a4469cad4041f21e640efa9ca5d0b192dd702955 (patch) | |
tree | a6f40549c8679410f65ad84446a69b19b918d75d /src/location/labs/qsg/qmappolylineobjectqsg.cpp | |
parent | e82c41d35ddd6ef0d14e1d01ea1dfd46742bc0fe (diff) | |
download | qtlocation-a4469cad4041f21e640efa9ca5d0b192dd702955.tar.gz |
Port Map*ObjectPrivateQSG to the shader-based projection geometriesv5.15.0-alpha1
This patch changes the implementation of the scenegraph-based
mapobjects (those created by QGeoTiledMap) to be the recently
introduced one sporting shader-based map projection.
This is much faster than the previous, but may introduce small glitches
at this time (mostly on minified polylines).
Adding polyline LOD simplification will solve this problem.
Compared to equivalent Map Items (that is, Map Items backed by the
same underlying implementation), map objects now are approximately
1.5x faster.
This measure has been gathered using medium-size polygons (contained
in the file 10_countries.json from the geojson_viewer example).
The difference is caused by the additional QtQuick geometry related
operations (essentially projecting the bounding box for each item)
present in MapItems.
Smaller polygons may therefore yield larger improvements, larger polygons
the opposite.
Change-Id: I3fc92b02b74a3a4d001e69755949a98f80d8a3d3
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/labs/qsg/qmappolylineobjectqsg.cpp')
-rw-r--r-- | src/location/labs/qsg/qmappolylineobjectqsg.cpp | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/src/location/labs/qsg/qmappolylineobjectqsg.cpp b/src/location/labs/qsg/qmappolylineobjectqsg.cpp index 96f66565..817d4df5 100644 --- a/src/location/labs/qsg/qmappolylineobjectqsg.cpp +++ b/src/location/labs/qsg/qmappolylineobjectqsg.cpp @@ -53,9 +53,9 @@ QMapPolylineObjectPrivateQSG::QMapPolylineObjectPrivateQSG(QGeoMapObject *q) QMapPolylineObjectPrivateQSG::QMapPolylineObjectPrivateQSG(const QMapPolylineObjectPrivate &other) : QMapPolylineObjectPrivateDefault(other) { - m_geoPath.setPath(m_path); // rest of the data already cloned by the *Default copy constructor, but necessary // update operations triggered only by setters overrides + markSourceDirty(); updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -75,28 +75,31 @@ QList<QDoubleVector2D> QMapPolylineObjectPrivateQSG::projectPath() const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); - geopathProjected_.reserve(m_geoPath.path().size()); - for (const QGeoCoordinate &c : m_geoPath.path()) + geopathProjected_.reserve(m_path.path().size()); + for (const QGeoCoordinate &c : m_path.path()) geopathProjected_ << p.geoToMapProjection(c); return geopathProjected_; } void QMapPolylineObjectPrivateQSG::updateGeometry() { - if (!m_map || m_geoPath.path().length() == 0 - || m_map->geoProjection().projectionType() != QGeoProjection::ProjectionWebMercator) + if (!m_map || m_map->geoProjection().projectionType() != QGeoProjection::ProjectionWebMercator) return; - QScopedValueRollback<bool> rollback(m_updatingGeometry); - m_updatingGeometry = true; - m_geometry.markSourceDirty(); - const QList<QDoubleVector2D> &geopathProjected = projectPath(); - m_geometry.setPreserveGeometry(true, m_geoPath.boundingGeoRectangle().topLeft()); - m_geometry.updateSourcePoints(*m_map.data(), geopathProjected, m_geoPath.boundingGeoRectangle().topLeft()); - m_geometry.updateScreenPoints(*m_map.data(), width(), false); + if (m_path.path().length() == 0) { // Possibly cleared + m_borderGeometry.clear(); + return; + } - QPointF origin = m_map->geoProjection().coordinateToItemPosition(m_geometry.origin(), false).toPointF(); - m_geometry.translate(origin - m_geometry.firstPointOffset()); + const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); + if (m_borderGeometry.isSourceDirty()) { + m_borderGeometry.setPreserveGeometry(true, m_path.boundingGeoRectangle().topLeft()); + m_borderGeometry.m_dataChanged = true; + m_borderGeometry.updateSourcePoints(*m_map, m_path); + m_leftBoundMercator = p.geoToMapProjection(m_borderGeometry.origin()); + } + m_borderGeometry.markScreenDirty(); + m_borderGeometry.m_wrapOffset = p.projectionWrapFactor(m_leftBoundMercator) + 1; } QSGNode *QMapPolylineObjectPrivateQSG::updateMapObjectNode(QSGNode *oldNode, @@ -104,41 +107,52 @@ QSGNode *QMapPolylineObjectPrivateQSG::updateMapObjectNode(QSGNode *oldNode, QSGNode *root, QQuickWindow * /*window*/) { - Q_UNUSED(visibleNode); - MapPolylineNode *node = static_cast<MapPolylineNode *>(oldNode); - - if (!node) { - if (!m_geometry.size()) // condition to block the subtree - return nullptr; - node = new MapPolylineNode(); - *visibleNode = static_cast<VisibleNode *>(node); + if (!m_polylinenode || !oldNode) { + m_polylinenode = new MapPolylineNodeOpenGLExtruded(); + *visibleNode = static_cast<VisibleNode *>(m_polylinenode); + if (oldNode) + delete oldNode; + } else { + m_polylinenode = static_cast<MapPolylineNodeOpenGLExtruded *>(oldNode); } - //TODO: update only material - if (m_geometry.isScreenDirty() || !oldNode) { - node->update(color(), &m_geometry); - m_geometry.setPreserveGeometry(false); - m_geometry.markClean(); + const QMatrix4x4 &combinedMatrix = m_map->geoProjection().qsgTransform(); + const QDoubleVector3D &cameraCenter = m_map->geoProjection().centerMercator(); + + if (m_borderGeometry.isScreenDirty()) { + /* Do the border update first */ + m_polylinenode->update(color(), + float(width()), + &m_borderGeometry, + combinedMatrix, + cameraCenter, + Qt::SquareCap, + true); + m_borderGeometry.setPreserveGeometry(false); + m_borderGeometry.markClean(); } - if (m_geometry.size()) { - root->appendChildNode(node); + if (!m_polylinenode->isSubtreeBlocked() ) { + m_polylinenode->setSubtreeBlocked(false); + root->appendChildNode(m_polylinenode); + return m_polylinenode; } else { - delete node; + delete m_polylinenode; + m_polylinenode = nullptr; + *visibleNode = nullptr; return nullptr; } - return node; } QList<QGeoCoordinate> QMapPolylineObjectPrivateQSG::path() const { - return m_geoPath.path(); + return m_path.path(); } void QMapPolylineObjectPrivateQSG::setPath(const QList<QGeoCoordinate> &path) { - m_path = path; - m_geoPath.setPath(path); + m_path.setPath(path); + markSourceDirty(); updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -147,7 +161,6 @@ void QMapPolylineObjectPrivateQSG::setPath(const QList<QGeoCoordinate> &path) void QMapPolylineObjectPrivateQSG::setColor(const QColor &color) { QMapPolylineObjectPrivateDefault::setColor(color); - updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -156,7 +169,6 @@ void QMapPolylineObjectPrivateQSG::setColor(const QColor &color) void QMapPolylineObjectPrivateQSG::setWidth(qreal width) { QMapPolylineObjectPrivateDefault::setWidth(width); - updateGeometry(); if (m_map) emit m_map->sgNodeChanged(); @@ -169,7 +181,12 @@ QGeoMapObjectPrivate *QMapPolylineObjectPrivateQSG::clone() QGeoShape QMapPolylineObjectPrivateQSG::geoShape() const { - return m_geoPath; + return m_path; +} + +void QMapPolylineObjectPrivateQSG::markSourceDirty() +{ + m_borderGeometry.markSourceDirty(); } QT_END_NAMESPACE |