[Qt] Added QQuickMapboxGL{,Renderer}

This commit is contained in:
Bruno de Oliveira Abinader
2016-04-27 13:12:23 +03:00
parent 205ecff6d7
commit 72bcad210d
9 changed files with 142 additions and 1 deletions

View File

@@ -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;
}
}