From 673730ccd423aed8deeba6889409f02cb1e9071d Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 26 Jan 2018 18:20:46 +0200 Subject: [qt] Implement FBO handling Needed for rendering 3D extrusions properly. --- platform/qt/app/mapwindow.cpp | 5 +++- platform/qt/include/qmapboxgl.hpp | 6 ++--- platform/qt/src/qmapboxgl.cpp | 37 ++++++++++++-------------- platform/qt/src/qmapboxgl_map_renderer.cpp | 5 ++-- platform/qt/src/qmapboxgl_map_renderer.hpp | 4 ++- platform/qt/src/qmapboxgl_renderer_backend.cpp | 13 +++++++-- platform/qt/src/qmapboxgl_renderer_backend.hpp | 5 ++-- platform/qt/test/qmapboxgl.test.cpp | 4 +-- 8 files changed, 45 insertions(+), 34 deletions(-) (limited to 'platform') 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 ¢er = 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,36 +1047,19 @@ 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. @@ -1512,6 +1495,20 @@ void QMapboxGL::render() d_ptr->mapRenderer->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 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 #include +#include + #include #include #include @@ -31,11 +33,11 @@ public: void schedule(std::weak_ptr scheduled) final; void render(); + void updateFramebuffer(quint32 fbo, const mbgl::Size &size); void setObserver(std::shared_ptr); // Thread-safe, called by the Frontend void updateParameters(std::shared_ptr); - 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); } -- cgit v1.2.1