diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-02-27 17:00:42 -0800 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-03-01 17:25:22 -0800 |
commit | 0c3521d46caeac7ba6c27840f883b4cd3b612316 (patch) | |
tree | 106998e5e8a0c9c64b303f179bb391ab2afc0b5c | |
parent | ef82095a21b46916cc5a69e0c6996e599e550a80 (diff) | |
download | qtlocation-mapboxgl-0c3521d46caeac7ba6c27840f883b4cd3b612316.tar.gz |
[core] privatize OffscreenTexture implementation
-rw-r--r-- | src/mbgl/util/offscreen_texture.cpp | 66 | ||||
-rw-r--r-- | src/mbgl/util/offscreen_texture.hpp | 13 |
2 files changed, 55 insertions, 24 deletions
diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp index aad20e59d3..cbe33c8d58 100644 --- a/src/mbgl/util/offscreen_texture.cpp +++ b/src/mbgl/util/offscreen_texture.cpp @@ -1,35 +1,69 @@ -#include <mbgl/util/offscreen_texture.hpp> #include <mbgl/gl/context.hpp> +#include <mbgl/util/offscreen_texture.hpp> -#include <cstring> #include <cassert> +#include <cstring> namespace mbgl { -OffscreenTexture::OffscreenTexture(gl::Context& context_, const Size size_) - : size(std::move(size_)), context(context_) { +class OffscreenTexture::Impl { +public: + Impl(gl::Context& context_, const Size size_) : context(context_), size(std::move(size_)) { + assert(size); + } + + void bind() { + if (!framebuffer) { + texture = context.createTexture(size); + framebuffer = context.createFramebuffer(*texture); + } else { + context.bindFramebuffer = framebuffer->framebuffer; + } + + context.viewport = { 0, 0, size }; + } + + PremultipliedImage readStillImage() { + return context.readFramebuffer<PremultipliedImage>(size); + } + + gl::Texture& getTexture() { + assert(texture); + return *texture; + } + + const Size& getSize() const { + return size; + } + +private: + gl::Context& context; + const Size size; + optional<gl::Framebuffer> framebuffer; + optional<gl::Texture> texture; +}; + +OffscreenTexture::OffscreenTexture(gl::Context& context, const Size size) + : impl(std::make_unique<Impl>(context, std::move(size))) { assert(size); } +OffscreenTexture::~OffscreenTexture() = default; + void OffscreenTexture::bind() { - if (!framebuffer) { - texture = context.createTexture(size); - framebuffer = context.createFramebuffer(*texture); - } else { - context.bindFramebuffer = framebuffer->framebuffer; - } + impl->bind(); +} - context.viewport = { 0, 0, size }; +PremultipliedImage OffscreenTexture::readStillImage() { + return impl->readStillImage(); } gl::Texture& OffscreenTexture::getTexture() { - assert(texture); - return *texture; + return impl->getTexture(); } -PremultipliedImage OffscreenTexture::readStillImage() { - return context.readFramebuffer<PremultipliedImage>(size); +const Size& OffscreenTexture::getSize() const { + return impl->getSize(); } - } // namespace mbgl diff --git a/src/mbgl/util/offscreen_texture.hpp b/src/mbgl/util/offscreen_texture.hpp index 64eb7bc565..b8bfabf7d3 100644 --- a/src/mbgl/util/offscreen_texture.hpp +++ b/src/mbgl/util/offscreen_texture.hpp @@ -1,20 +1,19 @@ #pragma once #include <mbgl/map/view.hpp> -#include <mbgl/gl/framebuffer.hpp> -#include <mbgl/gl/texture.hpp> -#include <mbgl/util/optional.hpp> #include <mbgl/util/image.hpp> namespace mbgl { namespace gl { class Context; +class Texture; } // namespace gl class OffscreenTexture : public View { public: OffscreenTexture(gl::Context&, Size size = { 256, 256 }); + ~OffscreenTexture(); void bind() override; @@ -22,13 +21,11 @@ public: gl::Texture& getTexture(); -public: - const Size size; + const Size& getSize() const; private: - gl::Context& context; - optional<gl::Framebuffer> framebuffer; - optional<gl::Texture> texture; + class Impl; + const std::unique_ptr<Impl> impl; }; } // namespace mbgl |