diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-04-01 16:56:24 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-04-05 11:49:17 +0200 |
commit | 66c020034e8260e5e071481e68ab61cd264723ba (patch) | |
tree | b5263772d72175474d91ce2daa9dc037b99fab0d /platform/qt | |
parent | a782a6d15b80dd83105604f3f779f6c83ba222e5 (diff) | |
download | qtlocation-mapboxgl-66c020034e8260e5e071481e68ab61cd264723ba.tar.gz |
[core] refactor RendererBackend
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/src/headless_backend_qt.cpp | 12 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_map_renderer.cpp | 2 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_map_renderer.hpp | 1 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_renderer_backend.cpp | 46 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_renderer_backend.hpp | 35 | ||||
-rw-r--r-- | platform/qt/src/qt_geojson.cpp | 2 |
6 files changed, 60 insertions, 38 deletions
diff --git a/platform/qt/src/headless_backend_qt.cpp b/platform/qt/src/headless_backend_qt.cpp index 3702fdf14a..1d62afabff 100644 --- a/platform/qt/src/headless_backend_qt.cpp +++ b/platform/qt/src/headless_backend_qt.cpp @@ -6,21 +6,22 @@ #include <cassert> namespace mbgl { +namespace gl { -class QtBackendImpl : public HeadlessBackend::Impl { +class QtBackendImpl final : public HeadlessBackend::Impl { public: - ~QtBackendImpl() final = default; + ~QtBackendImpl() = default; - gl::ProcAddress getExtensionFunctionPointer(const char* name) final { + gl::ProcAddress getExtensionFunctionPointer(const char* name) { QOpenGLContext* thisContext = QOpenGLContext::currentContext(); return thisContext->getProcAddress(name); } - void activateContext() final { + void activateContext() { widget.makeCurrent(); } - void deactivateContext() final { + void deactivateContext() { widget.doneCurrent(); } @@ -33,4 +34,5 @@ void HeadlessBackend::createImpl() { impl = std::make_unique<QtBackendImpl>(); } +} // namespace gl } // namespace mbgl diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp index 6b4103eabf..d10df50149 100644 --- a/platform/qt/src/qmapboxgl_map_renderer.cpp +++ b/platform/qt/src/qmapboxgl_map_renderer.cpp @@ -1,6 +1,8 @@ #include "qmapboxgl_map_renderer.hpp" #include "qmapboxgl_scheduler.hpp" +#include <mbgl/gfx/backend_scope.hpp> + #include <QThreadStorage> #include <QtGlobal> diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/qmapboxgl_map_renderer.hpp index d771a416da..7db0da99fa 100644 --- a/platform/qt/src/qmapboxgl_map_renderer.hpp +++ b/platform/qt/src/qmapboxgl_map_renderer.hpp @@ -4,7 +4,6 @@ #include "qmapboxgl_renderer_backend.hpp" #include <mbgl/renderer/renderer.hpp> -#include <mbgl/renderer/renderer_backend.hpp> #include <mbgl/renderer/renderer_observer.hpp> #include <mbgl/util/shared_thread_pool.hpp> #include <mbgl/util/util.hpp> diff --git a/platform/qt/src/qmapboxgl_renderer_backend.cpp b/platform/qt/src/qmapboxgl_renderer_backend.cpp index ac12981279..2a9706eb48 100644 --- a/platform/qt/src/qmapboxgl_renderer_backend.cpp +++ b/platform/qt/src/qmapboxgl_renderer_backend.cpp @@ -1,39 +1,51 @@ #include "qmapboxgl_renderer_backend.hpp" +#include <mbgl/gfx/backend_scope.hpp> +#include <mbgl/gl/renderable_resource.hpp> + #include <QOpenGLContext> #include <QtGlobal> -void QMapboxGLRendererBackend::updateAssumedState() -{ - assumeFramebufferBinding(ImplicitFramebufferBinding); - assumeViewport(0, 0, m_size); +class QMapboxGLRenderableResource final : public mbgl::gl::RenderableResource { +public: + QMapboxGLRenderableResource(QMapboxGLRendererBackend& backend_) : backend(backend_) { + } + + void bind() override { + assert(mbgl::gfx::BackendScope::exists()); + backend.restoreFramebufferBinding(); + backend.setViewport(0, 0, backend.getSize()); + } + +private: + QMapboxGLRendererBackend& backend; +}; + +QMapboxGLRendererBackend::QMapboxGLRendererBackend() + : mbgl::gfx::Renderable({ 0, 0 }, std::make_unique<QMapboxGLRenderableResource>(*this)) { } -void QMapboxGLRendererBackend::bind() -{ - assert(mbgl::gfx::BackendScope::exists()); +QMapboxGLRendererBackend::~QMapboxGLRendererBackend() = default; - setFramebufferBinding(m_fbo); - setViewport(0, 0, m_size); +void QMapboxGLRendererBackend::updateAssumedState() { + assumeFramebufferBinding(ImplicitFramebufferBinding); + assumeViewport(0, 0, size); } -mbgl::Size QMapboxGLRendererBackend::getFramebufferSize() const -{ - return m_size; +void QMapboxGLRendererBackend::restoreFramebufferBinding() { + setFramebufferBinding(m_fbo); } -void QMapboxGLRendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size &size) -{ +void QMapboxGLRendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size& newSize) { m_fbo = fbo; - m_size = size; + size = newSize; } /*! Initializes an OpenGL extension function such as Vertex Array Objects (VAOs), required by Mapbox GL Native engine. */ -mbgl::gl::ProcAddress QMapboxGLRendererBackend::getExtensionFunctionPointer(const char* name) -{ +mbgl::gl::ProcAddress QMapboxGLRendererBackend::getExtensionFunctionPointer(const char* name) { QOpenGLContext* thisContext = QOpenGLContext::currentContext(); return thisContext->getProcAddress(name); } diff --git a/platform/qt/src/qmapboxgl_renderer_backend.hpp b/platform/qt/src/qmapboxgl_renderer_backend.hpp index 476b3502c1..8d015f500d 100644 --- a/platform/qt/src/qmapboxgl_renderer_backend.hpp +++ b/platform/qt/src/qmapboxgl_renderer_backend.hpp @@ -2,32 +2,37 @@ #include "qmapboxgl.hpp" -#include <mbgl/renderer/renderer_backend.hpp> +#include <mbgl/gfx/renderable.hpp> +#include <mbgl/gl/renderer_backend.hpp> #include <mbgl/util/shared_thread_pool.hpp> -class QMapboxGLRendererBackend : public mbgl::RendererBackend -{ +class QMapboxGLRendererBackend final : public mbgl::gl::RendererBackend, + public mbgl::gfx::Renderable { public: - QMapboxGLRendererBackend() = default; - virtual ~QMapboxGLRendererBackend() = default; + QMapboxGLRendererBackend(); + ~QMapboxGLRendererBackend() override; - // mbgl::RendererBackend implementation - void updateAssumedState() final; - void bind() final; - mbgl::Size getFramebufferSize() const final; + void updateFramebuffer(quint32 fbo, const mbgl::Size&); + void restoreFramebufferBinding(); - void updateFramebuffer(quint32 fbo, const mbgl::Size &); + // mbgl::gfx::RendererBackend implementation +public: + mbgl::gfx::Renderable& getDefaultRenderable() override { + return *this; + } protected: - mbgl::gl::ProcAddress getExtensionFunctionPointer(const char*) final; - // No-op, implicit mode. - void activate() final {} - void deactivate() final {} + void activate() override {} + void deactivate() override {} + + // mbgl::gl::RendererBackend implementation +protected: + mbgl::gl::ProcAddress getExtensionFunctionPointer(const char*) override; + void updateAssumedState() override; private: quint32 m_fbo = 0; - mbgl::Size m_size = { 0, 0 }; Q_DISABLE_COPY(QMapboxGLRendererBackend) }; diff --git a/platform/qt/src/qt_geojson.cpp b/platform/qt/src/qt_geojson.cpp index cd808f016c..48d78abfe0 100644 --- a/platform/qt/src/qt_geojson.cpp +++ b/platform/qt/src/qt_geojson.cpp @@ -3,6 +3,8 @@ #include <mbgl/util/geometry.hpp> #include <mbgl/util/feature.hpp> +#pragma clang diagnostic ignored "-Wenum-compare-switch" + namespace QMapbox { mbgl::Point<double> asMapboxGLPoint(const QMapbox::Coordinate &coordinate) { |