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 | |
parent | 205ecff6d7e3b4b89f98c303e5faa807037dc587 (diff) | |
download | qtlocation-mapboxgl-72bcad210ddc9ad8e2ca8e7e53e134b5d9c06cdf.tar.gz |
[Qt] Added QQuickMapboxGL{,Renderer}
Diffstat (limited to 'platform/qt/src')
-rw-r--r-- | platform/qt/src/qquickmapboxgl.cpp | 19 | ||||
-rw-r--r-- | platform/qt/src/qquickmapboxglrenderer.cpp | 46 | ||||
-rw-r--r-- | platform/qt/src/qquickmapboxglrenderer.hpp | 28 |
3 files changed, 93 insertions, 0 deletions
diff --git a/platform/qt/src/qquickmapboxgl.cpp b/platform/qt/src/qquickmapboxgl.cpp new file mode 100644 index 0000000000..2a8bdffccf --- /dev/null +++ b/platform/qt/src/qquickmapboxgl.cpp @@ -0,0 +1,19 @@ +#include "qquickmapboxglrenderer.hpp" + +#include <QQuickMapboxGL> + +#include <QQuickItem> + +QQuickMapboxGL::QQuickMapboxGL(QQuickItem *parent_) + : QQuickFramebufferObject(parent_) +{ +} + +QQuickMapboxGL::~QQuickMapboxGL() +{ +} + +QQuickFramebufferObject::Renderer *QQuickMapboxGL::createRenderer() const +{ + return new QQuickMapboxGLRenderer(); +} 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; + } +} diff --git a/platform/qt/src/qquickmapboxglrenderer.hpp b/platform/qt/src/qquickmapboxglrenderer.hpp new file mode 100644 index 0000000000..a30afc243c --- /dev/null +++ b/platform/qt/src/qquickmapboxglrenderer.hpp @@ -0,0 +1,28 @@ +#ifndef QQUICKMAPBOXGLRENDERER_H +#define QQUICKMAPBOXGLRENDERER_H + +#include <QScopedPointer> +#include <QQuickFramebufferObject> + +class QOpenGLFramebufferObject; +class QSize; +class QMapboxGL; + +class QQuickMapboxGLRenderer : public QQuickFramebufferObject::Renderer +{ +public: + QQuickMapboxGLRenderer(); + virtual ~QQuickMapboxGLRenderer(); + + virtual QOpenGLFramebufferObject* createFramebufferObject(const QSize& size); + + virtual void render(); + virtual void synchronize(QQuickFramebufferObject *item); + +private: + bool m_initialized = false; + + QScopedPointer<QMapboxGL> m_map; +}; + +#endif // QQUICKMAPBOXGLRENDERER_H |