summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/qt/app/mapwindow.cpp4
-rw-r--r--platform/qt/include/qmapboxgl.hpp1
-rw-r--r--platform/qt/qt4.cmake4
-rw-r--r--platform/qt/src/qmapboxgl.cpp30
-rw-r--r--platform/qt/src/qmapboxgl_p.hpp12
-rw-r--r--platform/qt/test/qmapboxgl.cpp20
6 files changed, 55 insertions, 16 deletions
diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp
index e29e62f157..926d504904 100644
--- a/platform/qt/app/mapwindow.cpp
+++ b/platform/qt/app/mapwindow.cpp
@@ -399,5 +399,9 @@ void MapWindow::paintGL()
{
m_frameDraws++;
m_map->resize(size(), size() * pixelRatio());
+#if QT_VERSION >= 0x050400
+ // When we're using QOpenGLWidget, we need to tell Mapbox GL about the framebuffer we're using.
+ m_map->setFramebufferObject(defaultFramebufferObject());
+#endif
m_map->render();
}
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp
index 117fce515c..00c5735a93 100644
--- a/platform/qt/include/qmapboxgl.hpp
+++ b/platform/qt/include/qmapboxgl.hpp
@@ -192,6 +192,7 @@ public:
void rotateBy(const QPointF &first, const QPointF &second);
void resize(const QSize &size, const QSize &framebufferSize);
+ void setFramebufferObject(quint32 fbo);
double metersPerPixelAtLatitude(double latitude, double zoom) const;
QMapbox::ProjectedMeters projectedMetersForCoordinate(const QMapbox::Coordinate &) const;
diff --git a/platform/qt/qt4.cmake b/platform/qt/qt4.cmake
index 80fd4f00d3..66aed87c38 100644
--- a/platform/qt/qt4.cmake
+++ b/platform/qt/qt4.cmake
@@ -13,6 +13,10 @@ set(MBGL_QT_TEST_LIBRARIES
PRIVATE Qt4::QtOpenGL
)
+target_compile_options(qmapboxgl
+ PRIVATE -Wno-inconsistent-missing-override
+)
+
target_link_libraries(qmapboxgl
PRIVATE mbgl-core
PRIVATE Qt4::QtCore
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index ab727a62e7..b1c0a11ee1 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -5,10 +5,9 @@
#include "qt_geojson.hpp"
#include <mbgl/annotation/annotation.hpp>
-#include <mbgl/gl/gl.hpp>
-#include <mbgl/gl/context.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/gl/context.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/source.hpp>
@@ -31,6 +30,7 @@
#include <QOpenGLContext>
#else
#include <QCoreApplication>
+#include <QGLContext>
#endif
#include <QDebug>
@@ -1084,6 +1084,14 @@ void QMapboxGL::resize(const QSize& size, const QSize& framebufferSize)
}
/*!
+ If Mapbox GL needs to rebind the default framebuffer, it will use the
+ ID supplied here.
+*/
+void QMapboxGL::setFramebufferObject(quint32 fbo) {
+ d_ptr->fbObject = fbo;
+}
+
+/*!
Adds an \a icon to the annotation icon pool. This can be later used by the annotation
functions to shown any drawing on the map by referencing its \a name.
@@ -1484,6 +1492,7 @@ void QMapboxGL::render()
#endif
d_ptr->dirty = false;
+ d_ptr->updateViewBinding();
d_ptr->mapObj->render(*d_ptr);
}
@@ -1554,11 +1563,20 @@ QMapboxGLPrivate::~QMapboxGLPrivate()
{
}
+mbgl::Size QMapboxGLPrivate::framebufferSize() const {
+ return { static_cast<uint32_t>(fbSize.width()), static_cast<uint32_t>(fbSize.height()) };
+}
+
+void QMapboxGLPrivate::updateViewBinding() {
+ getContext().bindFramebuffer.setCurrentValue(fbObject);
+ assert(mbgl::gl::value::BindFramebuffer::Get() == getContext().bindFramebuffer.getCurrentValue());
+ getContext().viewport.setCurrentValue({ 0, 0, framebufferSize() });
+ assert(mbgl::gl::value::Viewport::Get() == getContext().viewport.getCurrentValue());
+}
+
void QMapboxGLPrivate::bind() {
- getContext().bindFramebuffer = 0;
- getContext().viewport = {
- 0, 0, { static_cast<uint32_t>(fbSize.width()), static_cast<uint32_t>(fbSize.height()) }
- };
+ getContext().bindFramebuffer = fbObject;
+ getContext().viewport = { 0, 0, framebufferSize() };
}
void QMapboxGLPrivate::invalidate()
diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp
index 2d8bfaaf53..4112542431 100644
--- a/platform/qt/src/qmapboxgl_p.hpp
+++ b/platform/qt/src/qmapboxgl_p.hpp
@@ -20,17 +20,18 @@ public:
explicit QMapboxGLPrivate(QMapboxGL *, const QMapboxGLSettings &, const QSize &size, qreal pixelRatio);
virtual ~QMapboxGLPrivate();
+ mbgl::Size framebufferSize() const;
+ void updateViewBinding();
+
// mbgl::View implementation.
- float getPixelRatio() const;
void bind() final;
- std::array<uint16_t, 2> getSize() const;
- std::array<uint16_t, 2> getFramebufferSize() const;
+ // mbgl::Backend implementation.
+ void invalidate() final;
void activate() final {}
void deactivate() final {}
- void invalidate() final;
- // mbgl::Backend (mbgl::MapObserver) implementation.
+ // mbgl::MapObserver implementation.
void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) final;
void onCameraIsChanging() final;
void onCameraDidChange(mbgl::MapObserver::CameraChangeMode) final;
@@ -47,6 +48,7 @@ public:
mbgl::EdgeInsets margins;
QSize size { 0, 0 };
QSize fbSize { 0, 0 };
+ quint32 fbObject = 0;
QMapboxGL *q_ptr { nullptr };
diff --git a/platform/qt/test/qmapboxgl.cpp b/platform/qt/test/qmapboxgl.cpp
index 8b88a4f6f6..650c635b99 100644
--- a/platform/qt/test/qmapboxgl.cpp
+++ b/platform/qt/test/qmapboxgl.cpp
@@ -2,24 +2,28 @@
#include <mbgl/util/io.hpp>
#include <QApplication>
-#include <QGLWidget>
#include <QMapbox>
#include <QMapboxGL>
+// We're using QGLFramebufferObject, which is only available in Qt 5 and up.
+#if QT_VERSION >= 0x050000
+
+#include <QGLWidget>
+#include <QGLFramebufferObject>
+
class QMapboxGLTest : public QObject, public ::testing::Test {
Q_OBJECT
public:
- QMapboxGLTest() : map(nullptr, settings) {
+ QMapboxGLTest() : fbo((assert(widget.context()->isValid()), widget.makeCurrent(), QSize(512, 512))), map(nullptr, settings) {
connect(&map, SIGNAL(mapChanged(QMapboxGL::MapChange)),
this, SLOT(onMapChanged(QMapboxGL::MapChange)));
connect(&map, SIGNAL(needsRendering()),
this, SLOT(onNeedsRendering()));
-
- widget.makeCurrent();
QMapbox::initializeGLExtensions();
- map.resize(QSize(512, 512), QSize(512, 512));
+ map.resize(fbo.size(), fbo.size());
+ map.setFramebufferObject(fbo.handle());
map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14);
}
@@ -36,6 +40,7 @@ public:
private:
QGLWidget widget;
+ QGLFramebufferObject fbo;
protected:
QMapboxGLSettings settings;
@@ -51,6 +56,9 @@ private slots:
};
void onNeedsRendering() {
+ widget.makeCurrent();
+ fbo.bind();
+ glViewport(0, 0, fbo.width(), fbo.height());
map.render();
};
};
@@ -88,3 +96,5 @@ TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleUrl)) {
}
#include "qmapboxgl.moc"
+
+#endif