From 0c3521d46caeac7ba6c27840f883b4cd3b612316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 27 Feb 2017 17:00:42 -0800 Subject: [PATCH] [core] privatize OffscreenTexture implementation --- src/mbgl/util/offscreen_texture.cpp | 70 +++++++++++++++++++++-------- src/mbgl/util/offscreen_texture.hpp | 13 +++--- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp index aad20e59d..cbe33c8d5 100644 --- a/src/mbgl/util/offscreen_texture.cpp +++ b/src/mbgl/util/offscreen_texture.cpp @@ -1,35 +1,69 @@ -#include #include +#include -#include #include +#include 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(size); + } + + gl::Texture& getTexture() { + assert(texture); + return *texture; + } + + const Size& getSize() const { + return size; + } + +private: + gl::Context& context; + const Size size; + optional framebuffer; + optional texture; +}; + +OffscreenTexture::OffscreenTexture(gl::Context& context, const Size size) + : impl(std::make_unique(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; - } - - context.viewport = { 0, 0, size }; -} - -gl::Texture& OffscreenTexture::getTexture() { - assert(texture); - return *texture; + impl->bind(); } PremultipliedImage OffscreenTexture::readStillImage() { - return context.readFramebuffer(size); + return impl->readStillImage(); } +gl::Texture& OffscreenTexture::getTexture() { + return impl->getTexture(); +} + +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 64eb7bc56..b8bfabf7d 100644 --- a/src/mbgl/util/offscreen_texture.hpp +++ b/src/mbgl/util/offscreen_texture.hpp @@ -1,20 +1,19 @@ #pragma once #include -#include -#include -#include #include 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 framebuffer; - optional texture; + class Impl; + const std::unique_ptr impl; }; } // namespace mbgl