[Qt] Added QQuickMapboxGL{,Renderer}
This commit is contained in:
@@ -20,7 +20,7 @@ addons_shortcuts:
|
||||
addons_qt5: &qt5
|
||||
apt:
|
||||
sources: [ 'ubuntu-toolchain-r-test' ]
|
||||
packages: [ 'gdb', 'g++-4.9', 'gcc-4.9', 'mesa-utils', 'qt5-default', 'libqt5opengl5-dev' ]
|
||||
packages: [ 'gdb', 'g++-4.9', 'gcc-4.9', 'mesa-utils', 'qt5-default', 'libqt5opengl5-dev', 'qtdeclarative5-dev' ]
|
||||
|
||||
env:
|
||||
global:
|
||||
|
||||
1
platform/qt/include/QQuickMapboxGL
Normal file
1
platform/qt/include/QQuickMapboxGL
Normal file
@@ -0,0 +1 @@
|
||||
#include "qquickmapboxgl.hpp"
|
||||
20
platform/qt/include/qquickmapboxgl.hpp
Normal file
20
platform/qt/include/qquickmapboxgl.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef QQUICKMAPBOXGL_H
|
||||
#define QQUICKMAPBOXGL_H
|
||||
|
||||
#include <QQuickFramebufferObject>
|
||||
|
||||
class QQuickItem;
|
||||
|
||||
class Q_DECL_EXPORT QQuickMapboxGL : public QQuickFramebufferObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QQuickMapboxGL(QQuickItem *parent = 0);
|
||||
virtual ~QQuickMapboxGL();
|
||||
|
||||
// Called from render thread.
|
||||
virtual Renderer *createRenderer() const Q_DECL_FINAL;
|
||||
};
|
||||
|
||||
#endif // QQUICKMAPBOXGL_H
|
||||
@@ -46,6 +46,7 @@
|
||||
'../default/webp_reader.cpp',
|
||||
'include/qmapbox.hpp',
|
||||
'include/qmapboxgl.hpp',
|
||||
'include/qquickmapboxgl.hpp',
|
||||
'qmapbox.qrc',
|
||||
'src/async_task.cpp',
|
||||
'src/async_task_impl.hpp',
|
||||
@@ -57,6 +58,9 @@
|
||||
'src/qmapbox.cpp',
|
||||
'src/qmapboxgl.cpp',
|
||||
'src/qmapboxgl_p.hpp',
|
||||
'src/qquickmapboxgl.cpp',
|
||||
'src/qquickmapboxglrenderer.cpp',
|
||||
'src/qquickmapboxglrenderer.hpp',
|
||||
'src/run_loop.cpp',
|
||||
'src/run_loop_impl.hpp',
|
||||
'src/timer.cpp',
|
||||
@@ -106,6 +110,18 @@
|
||||
],
|
||||
|
||||
'conditions': [
|
||||
['qt_version == 5', {
|
||||
'variables': {
|
||||
'cflags': [
|
||||
'<@(qt_quick_cflags)',
|
||||
],
|
||||
'ldflags': [
|
||||
'<@(qt_quick_ldflags)',
|
||||
],
|
||||
},
|
||||
}, {
|
||||
'sources/': [ [ 'exclude', 'qquick*' ] ],
|
||||
}],
|
||||
['OS == "mac"', {
|
||||
'xcode_settings': {
|
||||
'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags)' ],
|
||||
|
||||
@@ -42,6 +42,14 @@ function print_qt_flags {
|
||||
CONFIG+=" 'qt_network_ldflags%': $(quote_flags $(mason ldflags Qt system "QtNetwork")),"$LN
|
||||
|
||||
QT_VERSION_MAJOR=$(qmake -query QT_VERSION | cut -d. -f1)
|
||||
if [ ${QT_VERSION_MAJOR} -gt 4 ]; then
|
||||
CONFIG+=" 'qt_qml_cflags%': $(quote_flags $(mason cflags Qt system "QtQml")), "$LN
|
||||
CONFIG+=" 'qt_quick_cflags%': $(quote_flags $(mason cflags Qt system "QtQuick")), "$LN
|
||||
|
||||
CONFIG+=" 'qt_qml_ldflags%': $(quote_flags $(mason ldflags Qt system "QtQml")), "$LN
|
||||
CONFIG+=" 'qt_quick_ldflags%': $(quote_flags $(mason ldflags Qt system "QtQuick")), "$LN
|
||||
fi
|
||||
|
||||
if hash moc 2>/dev/null && hash rcc 2>/dev/null; then
|
||||
CONFIG+=" 'qt_moc%': '$(which moc)',"$LN
|
||||
CONFIG+=" 'qt_rcc%': '$(which rcc)',"$LN
|
||||
|
||||
19
platform/qt/src/qquickmapboxgl.cpp
Normal file
19
platform/qt/src/qquickmapboxgl.cpp
Normal file
@@ -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();
|
||||
}
|
||||
46
platform/qt/src/qquickmapboxglrenderer.cpp
Normal file
46
platform/qt/src/qquickmapboxglrenderer.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
28
platform/qt/src/qquickmapboxglrenderer.hpp
Normal file
28
platform/qt/src/qquickmapboxglrenderer.hpp
Normal file
@@ -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
|
||||
@@ -89,6 +89,9 @@ $(PLATFORM_CONFIG_OUTPUT): .mason configure $(PLATFORM_CONFIG_INPUT)
|
||||
GYP_FLAGS += -I$(PLATFORM_CONFIG_OUTPUT)
|
||||
GYP_FLAGS += -Dcoverage=$(ENABLE_COVERAGE)
|
||||
GYP_FLAGS += -Dcxx_host=$(CXX_HOST)
|
||||
ifeq ($(PLATFORM),qt)
|
||||
GYP_FLAGS += -Dqt_version=$(shell qmake -query QT_VERSION | cut -d. -f1)
|
||||
endif
|
||||
GYP_FLAGS += -Goutput_dir=.
|
||||
GYP_FLAGS += --depth=.
|
||||
GYP_FLAGS += --generator-output=$(PLATFORM_OUTPUT)
|
||||
|
||||
Reference in New Issue
Block a user