summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2018-01-26 18:20:46 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2018-02-09 20:28:54 +0200
commit673730ccd423aed8deeba6889409f02cb1e9071d (patch)
tree1087feccfe8d0d415288a6200e0ca9b02c5f1a19
parenta4e95c3da322113f8db732133cb9541a38accbaf (diff)
downloadqtlocation-mapboxgl-673730ccd423aed8deeba6889409f02cb1e9071d.tar.gz
[qt] Implement FBO handling
Needed for rendering 3D extrusions properly.
-rw-r--r--platform/qt/app/mapwindow.cpp5
-rw-r--r--platform/qt/include/qmapboxgl.hpp6
-rw-r--r--platform/qt/src/qmapboxgl.cpp37
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.cpp5
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.hpp4
-rw-r--r--platform/qt/src/qmapboxgl_renderer_backend.cpp13
-rw-r--r--platform/qt/src/qmapboxgl_renderer_backend.hpp5
-rw-r--r--platform/qt/test/qmapboxgl.test.cpp4
8 files changed, 45 insertions, 34 deletions
diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp
index 89047bd948..f6d5473192 100644
--- a/platform/qt/app/mapwindow.cpp
+++ b/platform/qt/app/mapwindow.cpp
@@ -442,6 +442,9 @@ void MapWindow::initializeGL()
void MapWindow::paintGL()
{
m_frameDraws++;
- m_map->resize(size(), size() * pixelRatio());
+ m_map->resize(size());
+#if QT_VERSION >= 0x050400
+ m_map->setFramebufferObject(defaultFramebufferObject(), size() * pixelRatio());
+#endif
m_map->render();
}
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp
index a1758ba6e6..d3ba643248 100644
--- a/platform/qt/include/qmapboxgl.hpp
+++ b/platform/qt/include/qmapboxgl.hpp
@@ -191,8 +191,7 @@ public:
void scaleBy(double scale, const QPointF &center = QPointF());
void rotateBy(const QPointF &first, const QPointF &second);
- void resize(const QSize &size, const QSize &framebufferSize);
- void setFramebufferObject(quint32 fbo);
+ void resize(const QSize &size);
double metersPerPixelAtLatitude(double latitude, double zoom) const;
QMapbox::ProjectedMeters projectedMetersForCoordinate(const QMapbox::Coordinate &) const;
@@ -227,9 +226,10 @@ public:
void setFilter(const QString &layer, const QVariant &filter);
// When rendering on a different thread,
- // should be called on this thread
+ // should be called on the render thread.
void createRenderer();
void destroyRenderer();
+ void setFramebufferObject(quint32 fbo, const QSize &size);
public slots:
void render();
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 89904ddf88..df5673e35b 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1047,37 +1047,20 @@ void QMapboxGL::rotateBy(const QPointF &first, const QPointF &second)
}
/*!
- Resize the map to \a size and scale to fit at \a framebufferSize. For
- high DPI screens, the size will be smaller than the \a framebufferSize.
-
- This fallowing example will double the pixel density of the map for
- a given \c size:
-
- \code
- map->resize(size / 2, size);
- \endcode
+ Resize the map to \a size_ and scale to fit at the framebuffer. For
+ high DPI screens, the size will be smaller than the framebuffer.
*/
-void QMapboxGL::resize(const QSize& size_, const QSize& framebufferSize)
+void QMapboxGL::resize(const QSize& size_)
{
auto size = sanitizedSize(size_);
if (d_ptr->mapObj->getSize() == size)
return;
- d_ptr->mapRenderer->updateFramebufferSize(sanitizedSize(framebufferSize));
d_ptr->mapObj->setSize(size);
}
/*!
- If Mapbox GL needs to rebind the default \a fbo, it will use the
- ID supplied here.
-*/
-void QMapboxGL::setFramebufferObject(quint32)
-{
- // FIXME: No-op, implicit.
-}
-
-/*!
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.
@@ -1513,6 +1496,20 @@ void QMapboxGL::render()
}
/*!
+ If Mapbox GL needs to rebind the default \a fbo, it will use the
+ ID supplied here. \a size is the size of the framebuffer, which
+ on high DPI screens is usually bigger than the map size.
+*/
+void QMapboxGL::setFramebufferObject(quint32 fbo, const QSize& size)
+{
+ if (!d_ptr->mapRenderer) {
+ createRenderer();
+ }
+
+ d_ptr->mapRenderer->updateFramebuffer(fbo, sanitizedSize(size));
+}
+
+/*!
Informs the map that the network connection has been established, causing
all network requests that previously timed out to be retried immediately.
*/
diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp
index 81293d7da1..f9120379cb 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.cpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.cpp
@@ -25,10 +25,9 @@ void QMapboxGLMapRenderer::updateParameters(std::shared_ptr<mbgl::UpdateParamete
m_updateParameters = std::move(newParameters);
}
-void QMapboxGLMapRenderer::updateFramebufferSize(const mbgl::Size &size)
+void QMapboxGLMapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size)
{
- std::lock_guard<std::mutex> lock(m_updateMutex);
- m_backend.setFramebufferSize(size);
+ m_backend.updateFramebuffer(fbo, size);
}
void QMapboxGLMapRenderer::render()
diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/qmapboxgl_map_renderer.hpp
index c15840a85d..f7523604c7 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.hpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.hpp
@@ -9,6 +9,8 @@
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/shared_thread_pool.hpp>
+#include <QtGlobal>
+
#include <memory>
#include <mutex>
#include <queue>
@@ -31,11 +33,11 @@ public:
void schedule(std::weak_ptr<mbgl::Mailbox> scheduled) final;
void render();
+ void updateFramebuffer(quint32 fbo, const mbgl::Size &size);
void setObserver(std::shared_ptr<mbgl::RendererObserver>);
// Thread-safe, called by the Frontend
void updateParameters(std::shared_ptr<mbgl::UpdateParameters>);
- void updateFramebufferSize(const mbgl::Size &size);
private:
Q_DISABLE_COPY(QMapboxGLMapRenderer)
diff --git a/platform/qt/src/qmapboxgl_renderer_backend.cpp b/platform/qt/src/qmapboxgl_renderer_backend.cpp
index 6cc7de53fe..917741f5ce 100644
--- a/platform/qt/src/qmapboxgl_renderer_backend.cpp
+++ b/platform/qt/src/qmapboxgl_renderer_backend.cpp
@@ -11,7 +11,15 @@
void QMapboxGLRendererBackend::updateAssumedState()
{
assumeFramebufferBinding(ImplicitFramebufferBinding);
- assumeViewport(0, 0, { 800, 600 });
+ assumeViewport(0, 0, m_size);
+}
+
+void QMapboxGLRendererBackend::bind()
+{
+ assert(mbgl::BackendScope::exists());
+
+ setFramebufferBinding(m_fbo);
+ setViewport(0, 0, m_size);
}
mbgl::Size QMapboxGLRendererBackend::getFramebufferSize() const
@@ -19,8 +27,9 @@ mbgl::Size QMapboxGLRendererBackend::getFramebufferSize() const
return m_size;
}
-void QMapboxGLRendererBackend::setFramebufferSize(const mbgl::Size &size)
+void QMapboxGLRendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size &size)
{
+ m_fbo = fbo;
m_size = size;
}
diff --git a/platform/qt/src/qmapboxgl_renderer_backend.hpp b/platform/qt/src/qmapboxgl_renderer_backend.hpp
index fb38556b55..de66b035fc 100644
--- a/platform/qt/src/qmapboxgl_renderer_backend.hpp
+++ b/platform/qt/src/qmapboxgl_renderer_backend.hpp
@@ -14,10 +14,10 @@ public:
// mbgl::RendererBackend implementation
void updateAssumedState() final;
- void bind() final {}
+ void bind() final;
mbgl::Size getFramebufferSize() const final;
- void setFramebufferSize(const mbgl::Size &);
+ void updateFramebuffer(quint32 fbo, const mbgl::Size &);
protected:
mbgl::gl::ProcAddress getExtensionFunctionPointer(const char*) final;
@@ -27,6 +27,7 @@ protected:
void deactivate() final {}
private:
+ quint32 m_fbo = 0;
mbgl::Size m_size = { 0, 0 };
Q_DISABLE_COPY(QMapboxGLRendererBackend)
diff --git a/platform/qt/test/qmapboxgl.test.cpp b/platform/qt/test/qmapboxgl.test.cpp
index 932460b932..2a56b346a3 100644
--- a/platform/qt/test/qmapboxgl.test.cpp
+++ b/platform/qt/test/qmapboxgl.test.cpp
@@ -15,8 +15,8 @@ QMapboxGLTest::QMapboxGLTest() : size(512, 512), fbo((assert(widget.context()->i
this, SLOT(onMapChanged(QMapboxGL::MapChange)));
connect(&map, SIGNAL(needsRendering()),
this, SLOT(onNeedsRendering()));
- map.resize(fbo.size(), fbo.size());
- map.setFramebufferObject(fbo.handle());
+ map.resize(fbo.size());
+ map.setFramebufferObject(fbo.handle(), fbo.size());
map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14);
}