[core] privatize OffscreenTexture implementation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
context.viewport = { 0, 0, size };
|
||||
}
|
||||
|
||||
gl::Texture& OffscreenTexture::getTexture() {
|
||||
assert(texture);
|
||||
return *texture;
|
||||
impl->bind();
|
||||
}
|
||||
|
||||
PremultipliedImage OffscreenTexture::readStillImage() {
|
||||
return context.readFramebuffer<PremultipliedImage>(size);
|
||||
return impl->readStillImage();
|
||||
}
|
||||
|
||||
gl::Texture& OffscreenTexture::getTexture() {
|
||||
return impl->getTexture();
|
||||
}
|
||||
|
||||
const Size& OffscreenTexture::getSize() const {
|
||||
return impl->getSize();
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user