diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-04-27 13:12:23 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-04-27 17:36:35 +0300 |
commit | 72bcad210ddc9ad8e2ca8e7e53e134b5d9c06cdf (patch) | |
tree | 5cc14f5ea4aa87e56c1a793f2285df2b1def325e /platform/qt/src/qquickmapboxglrenderer.cpp | |
parent | 205ecff6d7e3b4b89f98c303e5faa807037dc587 (diff) | |
download | qtlocation-mapboxgl-72bcad210ddc9ad8e2ca8e7e53e134b5d9c06cdf.tar.gz |
[Qt] Added QQuickMapboxGL{,Renderer}
Diffstat (limited to 'platform/qt/src/qquickmapboxglrenderer.cpp')
-rw-r--r-- | platform/qt/src/qquickmapboxglrenderer.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/platform/qt/src/qquickmapboxglrenderer.cpp b/platform/qt/src/qquickmapboxglrenderer.cpp new file mode 100644 index 0000000000..5871e05536 --- /dev/null +++ b/platform/qt/src/qquickmapboxglrenderer.cpp @@ -0,0 +1,46 @@ +#include "qquickmapboxglrenderer.hpp" + +#include <QMapboxGL> + +#include <QSize> +#include <QOpenGLFramebufferObject> +#include <QOpenGLFramebufferObjectFormat> +#include <QQuickWindow> + +QQuickMapboxGLRenderer::QQuickMapboxGLRenderer() +{ + QMapboxGLSettings settings; + settings.setAccessToken(qgetenv("MAPBOX_ACCESS_TOKEN")); + settings.setCacheDatabasePath("/tmp/mbgl-cache.db"); + settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024); + + m_map.reset(new QMapboxGL(nullptr, settings)); +} + +QQuickMapboxGLRenderer::~QQuickMapboxGLRenderer() +{ +} + +QOpenGLFramebufferObject* QQuickMapboxGLRenderer::createFramebufferObject(const QSize &size) +{ + m_map->resize(size); + + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + + return new QOpenGLFramebufferObject(size, format); +} + +void QQuickMapboxGLRenderer::render() +{ + m_map->render(); +} + +void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item) +{ + if (!m_initialized) { + m_map->setStyleURL(QMapbox::defaultStyles()[0].first); + QObject::connect(m_map.data(), SIGNAL(needsRendering()), item, SLOT(update())); + m_initialized = true; + } +} |