diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-02-24 16:03:31 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-02-27 16:51:17 -0800 |
commit | 9ca9adf69c4ad1d946af611c3d08800e0e301fb8 (patch) | |
tree | df70792e808ce57e0154f4a253a6a40dbb91b50d /platform | |
parent | e3500c1f791be82d64b50c7fa80b29b4e3c8a031 (diff) | |
download | qtlocation-mapboxgl-9ca9adf69c4ad1d946af611c3d08800e0e301fb8.tar.gz |
[core] private OffscreenView implementation
Diffstat (limited to 'platform')
-rw-r--r-- | platform/default/mbgl/gl/offscreen_view.cpp | 60 | ||||
-rw-r--r-- | platform/default/mbgl/gl/offscreen_view.hpp | 13 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 2 |
3 files changed, 52 insertions, 23 deletions
diff --git a/platform/default/mbgl/gl/offscreen_view.cpp b/platform/default/mbgl/gl/offscreen_view.cpp index 16faf6a4a9..a517cefad9 100644 --- a/platform/default/mbgl/gl/offscreen_view.cpp +++ b/platform/default/mbgl/gl/offscreen_view.cpp @@ -1,30 +1,64 @@ #include <mbgl/gl/offscreen_view.hpp> #include <mbgl/gl/context.hpp> +#include <mbgl/gl/framebuffer.hpp> +#include <mbgl/gl/renderbuffer.hpp> +#include <mbgl/util/optional.hpp> #include <cstring> #include <cassert> namespace mbgl { -OffscreenView::OffscreenView(gl::Context& context_, const Size size_) - : size(std::move(size_)), context(context_) { - assert(size); -} +class OffscreenView::Impl { +public: + Impl(gl::Context& context_, const Size size_) : context(context_), size(std::move(size_)) { + assert(size); + } -void OffscreenView::bind() { - if (!framebuffer) { - color = context.createRenderbuffer<gl::RenderbufferType::RGBA>(size); - depthStencil = context.createRenderbuffer<gl::RenderbufferType::DepthStencil>(size); - framebuffer = context.createFramebuffer(*color, *depthStencil); - } else { - context.bindFramebuffer = framebuffer->framebuffer; + void bind() { + if (!framebuffer) { + color = context.createRenderbuffer<gl::RenderbufferType::RGBA>(size); + depthStencil = context.createRenderbuffer<gl::RenderbufferType::DepthStencil>(size); + framebuffer = context.createFramebuffer(*color, *depthStencil); + } else { + context.bindFramebuffer = framebuffer->framebuffer; + } + + context.viewport = { 0, 0, size }; + } + + PremultipliedImage readStillImage() { + return context.readFramebuffer<PremultipliedImage>(size); + } + + const Size& getSize() const { + return size; } - context.viewport = { 0, 0, size }; +private: + gl::Context& context; + const Size size; + optional<gl::Framebuffer> framebuffer; + optional<gl::Renderbuffer<gl::RenderbufferType::RGBA>> color; + optional<gl::Renderbuffer<gl::RenderbufferType::DepthStencil>> depthStencil; +}; + +OffscreenView::OffscreenView(gl::Context& context, const Size size) + : impl(std::make_unique<Impl>(context, std::move(size))) { +} + +OffscreenView::~OffscreenView() = default; + +void OffscreenView::bind() { + impl->bind(); } PremultipliedImage OffscreenView::readStillImage() { - return context.readFramebuffer<PremultipliedImage>(size); + return impl->readStillImage(); +} + +const Size& OffscreenView::getSize() const { + return impl->getSize(); } } // namespace mbgl diff --git a/platform/default/mbgl/gl/offscreen_view.hpp b/platform/default/mbgl/gl/offscreen_view.hpp index 0e839e14cc..bf1a9889cd 100644 --- a/platform/default/mbgl/gl/offscreen_view.hpp +++ b/platform/default/mbgl/gl/offscreen_view.hpp @@ -1,9 +1,6 @@ #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 { @@ -15,19 +12,17 @@ class Context; class OffscreenView : public View { public: OffscreenView(gl::Context&, Size size = { 256, 256 }); + ~OffscreenView(); void bind() override; PremultipliedImage readStillImage(); -public: - const Size size; + const Size& getSize() const; private: - gl::Context& context; - optional<gl::Framebuffer> framebuffer; - optional<gl::Renderbuffer<gl::RenderbufferType::RGBA>> color; - optional<gl::Renderbuffer<gl::RenderbufferType::DepthStencil>> depthStencil; + class Impl; + const std::unique_ptr<Impl> impl; }; } // namespace mbgl diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index b73206c6cb..66cdb3eda7 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -365,7 +365,7 @@ void NodeMap::startRender(NodeMap::RenderOptions options) { const mbgl::Size fbSize{ static_cast<uint32_t>(options.width * pixelRatio), static_cast<uint32_t>(options.height * pixelRatio) }; - if (!view || view->size != fbSize) { + if (!view || view->getSize() != fbSize) { view.reset(); view = std::make_unique<mbgl::OffscreenView>(backend.getContext(), fbSize); } |