From 3b0d382a28b450f223a14be14cb59223cb2f4335 Mon Sep 17 00:00:00 2001 From: Tadej Novak Date: Mon, 20 Nov 2023 02:04:41 +0100 Subject: [PATCH] Update to upstream OpenGL 2 branch of MapLibre Native --- src/core/CMakeLists.txt | 12 ++++--- src/core/map.cpp | 3 +- src/core/map_renderer.cpp | 2 +- src/core/map_renderer_p.hpp | 3 +- src/core/renderer_backend.cpp | 61 -------------------------------- src/core/renderer_backend_p.hpp | 43 ---------------------- src/core/renderer_observer_p.hpp | 49 ------------------------- src/core/scheduler.cpp | 45 ----------------------- src/core/scheduler_p.hpp | 43 ---------------------- vendor/maplibre-native | 2 +- 10 files changed, 14 insertions(+), 249 deletions(-) delete mode 100644 src/core/renderer_backend.cpp delete mode 100644 src/core/renderer_backend_p.hpp delete mode 100644 src/core/renderer_observer_p.hpp delete mode 100644 src/core/scheduler.cpp delete mode 100644 src/core/scheduler_p.hpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index cdc79ea..d806219 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -50,9 +50,6 @@ target_sources( map_observer.cpp map_observer_p.hpp map_renderer.cpp map_renderer_p.hpp map.cpp map_p.hpp - renderer_backend.cpp renderer_backend_p.hpp - renderer_observer_p.hpp - scheduler.cpp scheduler_p.hpp settings.cpp settings_p.hpp types.cpp utils.cpp @@ -100,6 +97,7 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/style ${CMAKE_CURRENT_BINARY_DIR}/include ${MLN_CORE_PATH}/src + ${MLN_CORE_PATH}/platform/qt/src ) # Common link libraries @@ -111,7 +109,6 @@ target_link_libraries( Qt${QT_VERSION_MAJOR}::Network PRIVATE $ - $ $ $ ) @@ -122,6 +119,13 @@ if(NOT MLN_QT_WITH_INTERNAL_SQLITE) Qt${QT_VERSION_MAJOR}::Sql ) endif() +foreach(target ${MLN_QT_VENDOR_LIBRARIES}) + target_link_libraries( + Core + PRIVATE + $ + ) +endforeach() # Apple specifics if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") diff --git a/src/core/map.cpp b/src/core/map.cpp index 551f5c1..0ac7778 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -9,7 +9,8 @@ #include "conversion_p.hpp" #include "geojson_p.hpp" #include "map_observer_p.hpp" -#include "renderer_observer_p.hpp" + +#include "utils/renderer_observer.hpp" #include #include diff --git a/src/core/map_renderer.cpp b/src/core/map_renderer.cpp index dd3a7c9..6b16a9c 100644 --- a/src/core/map_renderer.cpp +++ b/src/core/map_renderer.cpp @@ -5,7 +5,7 @@ #include "map_renderer_p.hpp" -#include "scheduler_p.hpp" +#include "utils/scheduler.hpp" #include diff --git a/src/core/map_renderer_p.hpp b/src/core/map_renderer_p.hpp index 7332962..b9a087c 100644 --- a/src/core/map_renderer_p.hpp +++ b/src/core/map_renderer_p.hpp @@ -5,9 +5,10 @@ #pragma once -#include "renderer_backend_p.hpp" #include "settings.hpp" +#include "utils/renderer_backend.hpp" + #include #include #include diff --git a/src/core/renderer_backend.cpp b/src/core/renderer_backend.cpp deleted file mode 100644 index 0e01d16..0000000 --- a/src/core/renderer_backend.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2023 MapLibre contributors -// Copyright (C) 2019 Mapbox, Inc. - -// SPDX-License-Identifier: BSD-2-Clause - -#include "renderer_backend_p.hpp" - -#include -#include - -#include - -#include - -namespace QMapLibre { - -class RenderableResource final : public mbgl::gl::RenderableResource { -public: - explicit RenderableResource(RendererBackend &backend_) - : backend(backend_) {} - - void bind() override { - assert(mbgl::gfx::BackendScope::exists()); - backend.restoreFramebufferBinding(); - backend.setViewport(0, 0, backend.getSize()); - } - -private: - RendererBackend &backend; -}; - -RendererBackend::RendererBackend(const mbgl::gfx::ContextMode mode) - : mbgl::gl::RendererBackend(mode), - mbgl::gfx::Renderable({0, 0}, std::make_unique(*this)) {} - -RendererBackend::~RendererBackend() = default; - -void RendererBackend::updateAssumedState() { - assumeFramebufferBinding(ImplicitFramebufferBinding); - assumeViewport(0, 0, size); -} - -void RendererBackend::restoreFramebufferBinding() { - setFramebufferBinding(m_fbo); -} - -void RendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size &newSize) { - m_fbo = fbo; - size = newSize; -} - -/*! - Initializes an OpenGL extension function such as Vertex Array Objects (VAOs), - required by MapLibre Native engine. -*/ -mbgl::gl::ProcAddress RendererBackend::getExtensionFunctionPointer(const char *name) { - QOpenGLContext *thisContext = QOpenGLContext::currentContext(); - return thisContext->getProcAddress(name); -} - -} // namespace QMapLibre diff --git a/src/core/renderer_backend_p.hpp b/src/core/renderer_backend_p.hpp deleted file mode 100644 index e8fc337..0000000 --- a/src/core/renderer_backend_p.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2023 MapLibre contributors -// Copyright (C) 2019 Mapbox, Inc. - -// SPDX-License-Identifier: BSD-2-Clause - -#pragma once - -#include -#include - -#include - -namespace QMapLibre { - -class RendererBackend final : public mbgl::gl::RendererBackend, public mbgl::gfx::Renderable { -public: - explicit RendererBackend(mbgl::gfx::ContextMode mode); - ~RendererBackend() override; - - void updateFramebuffer(quint32 fbo, const mbgl::Size &newSize); - void restoreFramebufferBinding(); - - // mbgl::gfx::RendererBackend implementation -public: - mbgl::gfx::Renderable &getDefaultRenderable() override { return *this; } - -protected: - // No-op, implicit mode. - void activate() override {} - void deactivate() override {} - - // mbgl::gl::RendererBackend implementation -protected: - mbgl::gl::ProcAddress getExtensionFunctionPointer(const char *name) override; - void updateAssumedState() override; - -private: - quint32 m_fbo{}; - - Q_DISABLE_COPY(RendererBackend) -}; - -} // namespace QMapLibre diff --git a/src/core/renderer_observer_p.hpp b/src/core/renderer_observer_p.hpp deleted file mode 100644 index 5b02d50..0000000 --- a/src/core/renderer_observer_p.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2023 MapLibre contributors -// Copyright (C) 2019 Mapbox, Inc. - -// SPDX-License-Identifier: BSD-2-Clause - -#pragma once - -#include -#include -#include -#include -#include - -#include - -namespace QMapLibre { - -// Forwards RendererObserver signals to the given -// Delegate RendererObserver on the given RunLoop -class RendererObserver final : public mbgl::RendererObserver { -public: - RendererObserver(mbgl::util::RunLoop &mapRunLoop, mbgl::RendererObserver &delegate_) - : mailbox(std::make_shared(mapRunLoop)), - delegate(delegate_, mailbox) {} - - ~RendererObserver() final { mailbox->close(); } - - void onInvalidate() final { delegate.invoke(&mbgl::RendererObserver::onInvalidate); } - - void onResourceError(std::exception_ptr err) final { - delegate.invoke(&mbgl::RendererObserver::onResourceError, err); - } - - void onWillStartRenderingMap() final { delegate.invoke(&mbgl::RendererObserver::onWillStartRenderingMap); } - - void onWillStartRenderingFrame() final { delegate.invoke(&mbgl::RendererObserver::onWillStartRenderingFrame); } - - void onDidFinishRenderingFrame(RenderMode mode, bool repaintNeeded, bool placementChanged) final { - delegate.invoke(&mbgl::RendererObserver::onDidFinishRenderingFrame, mode, repaintNeeded, placementChanged); - } - - void onDidFinishRenderingMap() final { delegate.invoke(&mbgl::RendererObserver::onDidFinishRenderingMap); } - -private: - std::shared_ptr mailbox{}; - mbgl::ActorRef delegate; -}; - -} // namespace QMapLibre diff --git a/src/core/scheduler.cpp b/src/core/scheduler.cpp deleted file mode 100644 index 18252f5..0000000 --- a/src/core/scheduler.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2023 MapLibre contributors -// Copyright (C) 2019 Mapbox, Inc. - -// SPDX-License-Identifier: BSD-2-Clause - -#include "scheduler_p.hpp" - -#include - -#include - -namespace QMapLibre { - -Scheduler::Scheduler() = default; - -Scheduler::~Scheduler() { - MBGL_VERIFY_THREAD(tid); -} - -void Scheduler::schedule(std::function function) { - const std::lock_guard lock(m_taskQueueMutex); - m_taskQueue.push(std::move(function)); - - // Need to force the main thread to wake - // up this thread and process the events. - emit needsProcessing(); -} - -void Scheduler::processEvents() { - std::queue> taskQueue; - { - const std::unique_lock lock(m_taskQueueMutex); - std::swap(taskQueue, m_taskQueue); - } - - while (!taskQueue.empty()) { - auto& function = taskQueue.front(); - if (function) { - function(); - } - taskQueue.pop(); - } -} - -} // namespace QMapLibre diff --git a/src/core/scheduler_p.hpp b/src/core/scheduler_p.hpp deleted file mode 100644 index 4f5673f..0000000 --- a/src/core/scheduler_p.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2023 MapLibre contributors -// Copyright (C) 2019 Mapbox, Inc. - -// SPDX-License-Identifier: BSD-2-Clause - -#pragma once - -#include -#include - -#include - -#include -#include -#include - -namespace QMapLibre { - -class Scheduler : public QObject, public mbgl::Scheduler { - Q_OBJECT - -public: - Scheduler(); - ~Scheduler() override; - - // mbgl::Scheduler implementation. - void schedule(std::function function) final; - mapbox::base::WeakPtr makeWeakPtr() override { return weakFactory.makeWeakPtr(); } - - void processEvents(); - -signals: - void needsProcessing(); - -private: - MBGL_STORE_THREAD(tid); - - std::mutex m_taskQueueMutex; - std::queue> m_taskQueue; - mapbox::base::WeakPtrFactory weakFactory{this}; -}; - -} // namespace QMapLibre diff --git a/vendor/maplibre-native b/vendor/maplibre-native index 85c0ab7..2b87bd9 160000 --- a/vendor/maplibre-native +++ b/vendor/maplibre-native @@ -1 +1 @@ -Subproject commit 85c0ab7e5145213194b2a4b73997f10fab1d1cd8 +Subproject commit 2b87bd9eb30ed8567c4a1dfb8a9c690a5464151a