summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-10 17:16:37 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-10-25 13:52:36 -0700
commita4d259c33f9bb890bba97fd89552720e3e0ec09b (patch)
tree342ecc27a6993c48f3a2e1d739fce890350bc44d /include
parent5cc390d694fc7510d445310d8eb9e32429a5e67b (diff)
downloadqtlocation-mapboxgl-a4d259c33f9bb890bba97fd89552720e3e0ec09b.tar.gz
[core] move gl::Context to Backend and refactor View
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/map/backend.hpp15
-rw-r--r--include/mbgl/map/map.hpp17
-rw-r--r--include/mbgl/map/update.hpp31
-rw-r--r--include/mbgl/map/view.hpp28
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp12
-rw-r--r--include/mbgl/platform/default/headless_view.hpp41
-rw-r--r--include/mbgl/platform/default/offscreen_view.hpp33
7 files changed, 66 insertions, 111 deletions
diff --git a/include/mbgl/map/backend.hpp b/include/mbgl/map/backend.hpp
index e4a5634b88..c11d094906 100644
--- a/include/mbgl/map/backend.hpp
+++ b/include/mbgl/map/backend.hpp
@@ -2,13 +2,21 @@
#include <mbgl/map/change.hpp>
+#include <memory>
+
namespace mbgl {
-class Map;
+namespace gl {
+class Context;
+} // namespace gl
class Backend {
public:
- virtual ~Backend() = default;
+ Backend();
+ virtual ~Backend();
+
+ // Returns the backend's context which manages OpenGL state.
+ gl::Context& getContext();
// Called when the backend's GL context needs to be made active or inactive. These are called,
// as a matched pair, in four situations:
@@ -29,6 +37,9 @@ public:
// Notifies a watcher of map x/y/scale/rotation changes.
virtual void notifyMapChange(MapChange change);
+
+private:
+ const std::unique_ptr<gl::Context> context;
};
} // namespace mbgl
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 4f6207fc6f..b1c840e68d 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -2,8 +2,6 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/chrono.hpp>
-#include <mbgl/util/image.hpp>
-#include <mbgl/map/update.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/feature.hpp>
@@ -35,7 +33,7 @@ class Layer;
class Map : private util::noncopyable {
public:
explicit Map(Backend&,
- View&,
+ std::array<uint16_t, 2> size,
float pixelRatio,
FileSource&,
Scheduler&,
@@ -47,14 +45,14 @@ public:
// Register a callback that will get called (on the render thread) when all resources have
// been loaded and a complete render occurs.
- using StillImageCallback = std::function<void (std::exception_ptr, PremultipliedImage&&)>;
- void renderStill(StillImageCallback callback);
+ using StillImageCallback = std::function<void (std::exception_ptr)>;
+ void renderStill(View&, StillImageCallback callback);
- // Main render function.
- void render();
+ // Triggers a repaint.
+ void triggerRepaint();
- // Notifies the Map that the state has changed and an update might be necessary.
- void update(Update update);
+ // Main render function.
+ void render(View&);
// Styling
void addClass(const std::string&);
@@ -138,6 +136,7 @@ public:
ViewportMode getViewportMode() const;
// Size
+ void setSize(const std::array<uint16_t, 2>&);
uint16_t getWidth() const;
uint16_t getHeight() const;
diff --git a/include/mbgl/map/update.hpp b/include/mbgl/map/update.hpp
deleted file mode 100644
index 1da7e3ac92..0000000000
--- a/include/mbgl/map/update.hpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-#include <mbgl/util/traits.hpp>
-
-namespace mbgl {
-
-enum class Update {
- Nothing = 0,
- Dimensions = 1 << 1,
- Classes = 1 << 2,
- RecalculateStyle = 1 << 3,
- RenderStill = 1 << 4,
- Repaint = 1 << 5,
- AnnotationStyle = 1 << 6,
- AnnotationData = 1 << 7,
- Layout = 1 << 8
-};
-
-constexpr Update operator|(Update lhs, Update rhs) {
- return Update(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs));
-}
-
-constexpr Update& operator|=(Update& lhs, const Update& rhs) {
- return (lhs = lhs | rhs);
-}
-
-constexpr bool operator& (Update lhs, Update rhs) {
- return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs);
-}
-
-} // namespace mbgl
diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp
index 0dff4b3602..6517c6b220 100644
--- a/include/mbgl/map/view.hpp
+++ b/include/mbgl/map/view.hpp
@@ -1,8 +1,6 @@
#pragma once
-#include <mbgl/util/image.hpp>
-
-#include <array>
+#include <mbgl/util/noncopyable.hpp>
namespace mbgl {
@@ -12,29 +10,11 @@ class View : private util::noncopyable {
public:
virtual ~View() = default;
- // Called when this View is associated with a Map object.
- virtual void initialize(Map*);
-
// Called when this View is used for rendering. Implementations should ensure that a renderable
- // object is bound and glClear/glDraw* calls can be done.
+ // object is bound and glClear/glDraw* calls can be done. They should also make sure that
+ // calling .bind() repeatedly is a no-op and that the appropriate gl::Context values are
+ // set to the current state.
virtual void bind() = 0;
-
- // Called when the View signaled a dimension change. Must return the logical dimension
- // of this map in pixels.
- virtual std::array<uint16_t, 2> getSize() const = 0;
-
- // Called for every frame that is being rendered. Must return the absolute dimensions of
- // the current framebuffer. Typically, this is the logical width scaled by the pixel ratio,
- // but in case the view was moved to display with a different pixel ratio, it can also be
- // different from that rule.
- virtual std::array<uint16_t, 2> getFramebufferSize() const = 0;
-
- // Reads the pixel data from the current framebuffer. If your View implementation
- // doesn't support reading from the framebuffer, return a null pointer.
- virtual PremultipliedImage readStillImage(std::array<uint16_t, 2> size = {{ 0, 0 }});
-
-protected:
- mbgl::Map *map = nullptr;
};
} // namespace mbgl
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index a115d03d7f..e832cd70d1 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -19,6 +19,8 @@ public:
float getPixelRatio() const;
+ void setMap(mbgl::Map*);
+
// 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.
void setChangeStyleCallback(std::function<void()> callback);
@@ -29,18 +31,18 @@ public:
void run();
-private:
// mbgl::View implementation
- void initialize(mbgl::Map*) override;
+ void updateViewBinding();
void bind() override;
- std::array<uint16_t, 2> getSize() const override;
- std::array<uint16_t, 2> getFramebufferSize() const override;
+ std::array<uint16_t, 2> getSize() const;
+ std::array<uint16_t, 2> getFramebufferSize() const;
// mbgl::Backend implementation
void activate() override;
void deactivate() override;
void invalidate() override;
+private:
// Window callbacks
static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods);
static void onScroll(GLFWwindow *window, double xoffset, double yoffset);
@@ -76,6 +78,8 @@ private:
std::function<void(mbgl::MapChange)> mapChangeCallback;
private:
+ mbgl::Map* map = nullptr;
+
bool fullscreen = false;
const bool benchmark = false;
bool tracking = false;
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp
deleted file mode 100644
index 27af4fc9d9..0000000000
--- a/include/mbgl/platform/default/headless_view.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-
-#include <mbgl/map/view.hpp>
-#include <mbgl/gl/types.hpp>
-
-namespace mbgl {
-
-class HeadlessView : public View {
-public:
- HeadlessView(float pixelRatio = 1, uint16_t width = 256, uint16_t height = 256);
- ~HeadlessView() override;
-
- void bind() override;
-
- std::array<uint16_t, 2> getSize() const override;
- std::array<uint16_t, 2> getFramebufferSize() const override;
-
-
- PremultipliedImage readStillImage(std::array<uint16_t, 2> size = {{ 0, 0 }}) override;
-
- float getPixelRatio() const;
-
- void resize(uint16_t width, uint16_t height);
-
-private:
- void clearBuffers();
- void resizeFramebuffer();
- void bindFramebuffer();
-
-private:
- const float pixelRatio;
- std::array<uint16_t, 2> dimensions;
-
- bool needsResize = false;
-
- gl::FramebufferID fbo = 0;
- gl::RenderbufferID fboDepthStencil = 0;
- gl::RenderbufferID fboColor = 0;
-};
-
-} // namespace mbgl
diff --git a/include/mbgl/platform/default/offscreen_view.hpp b/include/mbgl/platform/default/offscreen_view.hpp
new file mode 100644
index 0000000000..034aa3aaf3
--- /dev/null
+++ b/include/mbgl/platform/default/offscreen_view.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <mbgl/map/view.hpp>
+#include <mbgl/gl/framebuffer.hpp>
+#include <mbgl/gl/renderbuffer.hpp>
+#include <mbgl/util/optional.hpp>
+#include <mbgl/util/image.hpp>
+
+namespace mbgl {
+
+namespace gl {
+class Context;
+} // namespace gl
+
+class OffscreenView : public View {
+public:
+ OffscreenView(gl::Context&, std::array<uint16_t, 2> size = {{ 256, 256 }});
+
+ void bind() override;
+
+ PremultipliedImage readStillImage();
+
+ std::array<uint16_t, 2> getSize() const;
+
+private:
+ gl::Context& context;
+ std::array<uint16_t, 2> size;
+ optional<gl::Framebuffer> framebuffer;
+ optional<gl::Renderbuffer<gl::RenderbufferType::RGBA>> color;
+ optional<gl::Renderbuffer<gl::RenderbufferType::DepthStencil>> depthStencil;
+};
+
+} // namespace mbgl