summaryrefslogtreecommitdiff
path: root/platform/glfw
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-06-28 10:55:43 -0700
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-07-18 10:45:12 +0200
commit8401325a82a5affd9f4fe2348d065d8aa0aa0bc4 (patch)
tree1257134471367de3d0e71301c808c1bd8e9ed8cd /platform/glfw
parentd68d8a7846ef0b4d06c31e0ed451b31354a7dec9 (diff)
downloadqtlocation-mapboxgl-8401325a82a5affd9f4fe2348d065d8aa0aa0bc4.tar.gz
[glfw] rendering interface changes
Diffstat (limited to 'platform/glfw')
-rw-r--r--platform/glfw/glfw_renderer_frontend.cpp39
-rw-r--r--platform/glfw/glfw_renderer_frontend.hpp29
-rw-r--r--platform/glfw/glfw_view.cpp16
-rw-r--r--platform/glfw/glfw_view.hpp7
-rw-r--r--platform/glfw/main.cpp6
5 files changed, 89 insertions, 8 deletions
diff --git a/platform/glfw/glfw_renderer_frontend.cpp b/platform/glfw/glfw_renderer_frontend.cpp
new file mode 100644
index 0000000000..99f409e338
--- /dev/null
+++ b/platform/glfw/glfw_renderer_frontend.cpp
@@ -0,0 +1,39 @@
+#include "glfw_renderer_frontend.hpp"
+
+#include <mbgl/renderer/renderer.hpp>
+
+GLFWRendererFrontend::GLFWRendererFrontend(std::unique_ptr<mbgl::Renderer> renderer_, GLFWView& glfwView_)
+ : glfwView(glfwView_)
+ , renderer(std::move(renderer_)) {
+ glfwView.setRenderFrontend(this);
+}
+
+GLFWRendererFrontend::~GLFWRendererFrontend() = default;
+
+void GLFWRendererFrontend::reset() {
+ assert(renderer);
+ renderer.reset();
+}
+
+void GLFWRendererFrontend::setObserver(mbgl::RendererObserver& observer) {
+ assert(renderer);
+ renderer->setObserver(&observer);
+}
+
+void GLFWRendererFrontend::update(std::shared_ptr<mbgl::UpdateParameters> params) {
+ updateParameters = std::move(params);
+ glfwView.invalidate();
+}
+
+void GLFWRendererFrontend::render() {
+ assert(renderer);
+
+ if (!updateParameters) return;
+
+ renderer->render(glfwView, *updateParameters);
+}
+
+mbgl::Renderer* GLFWRendererFrontend::getRenderer() {
+ assert(renderer);
+ return renderer.get();
+}
diff --git a/platform/glfw/glfw_renderer_frontend.hpp b/platform/glfw/glfw_renderer_frontend.hpp
new file mode 100644
index 0000000000..c992fe20fe
--- /dev/null
+++ b/platform/glfw/glfw_renderer_frontend.hpp
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "glfw_view.hpp"
+#include <mbgl/renderer/renderer_frontend.hpp>
+
+#include <memory>
+
+namespace mbgl {
+class Renderer;
+} // namespace mbgl
+
+class GLFWRendererFrontend : public mbgl::RendererFrontend {
+public:
+ GLFWRendererFrontend(std::unique_ptr<mbgl::Renderer>, GLFWView&);
+ ~GLFWRendererFrontend() override;
+
+ void reset() override;
+ void setObserver(mbgl::RendererObserver&) override;
+
+ void update(std::shared_ptr<mbgl::UpdateParameters>) override;
+ void render();
+
+ mbgl::Renderer* getRenderer();
+
+private:
+ GLFWView& glfwView;
+ std::unique_ptr<mbgl::Renderer> renderer;
+ std::shared_ptr<mbgl::UpdateParameters> updateParameters;
+};
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 1beaf2b52b..ffc6588464 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -1,4 +1,5 @@
#include "glfw_view.hpp"
+#include "glfw_renderer_frontend.hpp"
#include "ny_route.hpp"
#include <mbgl/annotation/annotation.hpp>
@@ -11,6 +12,7 @@
#include <mbgl/util/string.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/map/backend_scope.hpp>
+#include <mbgl/renderer/renderer.hpp>
#include <mbgl/map/camera.hpp>
#include <mapbox/cheap_ruler.hpp>
@@ -142,6 +144,10 @@ void GLFWView::setMap(mbgl::Map *map_) {
map->addAnnotationImage(makeImage("default_marker", 22, 22, 1));
}
+void GLFWView::setRenderFrontend(GLFWRendererFrontend* rendererFrontend_) {
+ rendererFrontend = rendererFrontend_;
+}
+
void GLFWView::updateAssumedState() {
assumeFramebufferBinding(0);
assumeViewport(0, 0, getFramebufferSize());
@@ -196,7 +202,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
view->nextOrientation();
break;
case GLFW_KEY_Q: {
- auto result = view->map->queryPointAnnotations({ {}, { double(view->getSize().width), double(view->getSize().height) } });
+ auto result = view->rendererFrontend->getRenderer()->queryPointAnnotations({ {}, { double(view->getSize().width), double(view->getSize().height) } });
printf("visible point annotations: %lu\n", result.size());
} break;
case GLFW_KEY_P:
@@ -489,16 +495,17 @@ void GLFWView::run() {
glfwPollEvents();
- if (dirty) {
+ if (dirty && rendererFrontend) {
+ dirty = false;
const double started = glfwGetTime();
if (animateRouteCallback)
animateRouteCallback(map);
activate();
- mbgl::BackendScope scope { *this, mbgl::BackendScope::ScopeType::Implicit };
+ mbgl::BackendScope guard { *this, getScopeType() };
- map->render(*this);
+ rendererFrontend->render();
glfwSwapBuffers(window);
@@ -507,7 +514,6 @@ void GLFWView::run() {
invalidate();
}
- dirty = false;
}
};
diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp
index 3b0c31009c..02e98a831d 100644
--- a/platform/glfw/glfw_view.hpp
+++ b/platform/glfw/glfw_view.hpp
@@ -8,6 +8,7 @@
#include <mbgl/util/geometry.hpp>
struct GLFWwindow;
+class GLFWRendererFrontend;
class GLFWView : public mbgl::View, public mbgl::Backend, public mbgl::MapObserver {
public:
@@ -17,6 +18,8 @@ public:
float getPixelRatio() const;
void setMap(mbgl::Map*);
+
+ void setRenderFrontend(GLFWRendererFrontend*);
// Callback called when the user presses the key mapped to style change.
// The expected action is to set a new style, different to the current one.
@@ -31,6 +34,8 @@ public:
void setWindowTitle(const std::string&);
void run();
+
+ void invalidate();
// mbgl::View implementation
void bind() override;
@@ -38,7 +43,6 @@ public:
mbgl::Size getFramebufferSize() const;
// mbgl::Backend implementation
- void invalidate() override;
void updateAssumedState() override;
// mbgl::MapObserver implementation
@@ -83,6 +87,7 @@ private:
void toggle3DExtrusions(bool visible);
mbgl::Map* map = nullptr;
+ GLFWRendererFrontend* rendererFrontend = nullptr;
bool fullscreen = false;
const bool benchmark = false;
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 0cd9543f9c..6418ddcf78 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -1,4 +1,5 @@
#include "glfw_view.hpp"
+#include "glfw_renderer_frontend.hpp"
#include "settings_json.hpp"
#include <mbgl/util/default_styles.hpp>
@@ -7,6 +8,7 @@
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/style/style.hpp>
+#include <mbgl/renderer/renderer.hpp>
#include <csignal>
#include <getopt.h>
@@ -120,8 +122,8 @@ int main(int argc, char *argv[]) {
}
mbgl::ThreadPool threadPool(4);
-
- mbgl::Map map(backend, backend, view->getSize(), view->getPixelRatio(), fileSource, threadPool);
+ GLFWRendererFrontend rendererFrontend { std::make_unique<mbgl::Renderer>(backend, view->getPixelRatio(), fileSource, threadPool), backend };
+ mbgl::Map map(rendererFrontend, backend, view->getSize(), view->getPixelRatio(), fileSource, threadPool);
backend.setMap(&map);