summaryrefslogtreecommitdiff
path: root/src/mbgl/util/offscreen_texture.cpp
diff options
context:
space:
mode:
authorLauren Budorick <lauren@mapbox.com>2017-05-08 09:06:07 -0700
committerGitHub <noreply@github.com>2017-05-08 09:06:07 -0700
commit1c9af3226f0ad306cf2ec8be9ff1558938f69736 (patch)
tree407389df9fd8c9c807fcab09d4ba99482829dc6f /src/mbgl/util/offscreen_texture.cpp
parentb622aed3490d623a31ec576aefe9696f221ead76 (diff)
downloadqtlocation-mapboxgl-1c9af3226f0ad306cf2ec8be9ff1558938f69736.tar.gz
[core] Reuse fill-extrusion textures between frames (#8896)
Diffstat (limited to 'src/mbgl/util/offscreen_texture.cpp')
-rw-r--r--src/mbgl/util/offscreen_texture.cpp41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp
index e719ac566e..fe24774b7c 100644
--- a/src/mbgl/util/offscreen_texture.cpp
+++ b/src/mbgl/util/offscreen_texture.cpp
@@ -6,16 +6,28 @@
namespace mbgl {
+OffscreenTexture::OffscreenTexture(OffscreenTexture&&) = default;
+OffscreenTexture& OffscreenTexture::operator=(OffscreenTexture&&) = default;
+
class OffscreenTexture::Impl {
public:
- Impl(gl::Context& context_, const Size size_) : context(context_), size(std::move(size_)) {
+ Impl(gl::Context& context_, const Size size_, OffscreenTextureAttachment type_)
+ : context(context_), size(std::move(size_)), type(type_) {
assert(!size.isEmpty());
}
void bind() {
if (!framebuffer) {
texture = context.createTexture(size, gl::TextureFormat::RGBA);
- framebuffer = context.createFramebuffer(*texture);
+
+ if (type == OffscreenTextureAttachment::Depth) {
+ gl::Renderbuffer<gl::RenderbufferType::DepthComponent> depth =
+ context.createRenderbuffer<gl::RenderbufferType::DepthComponent>(size);
+ framebuffer = context.createFramebuffer(*texture, depth);
+
+ } else {
+ framebuffer = context.createFramebuffer(*texture);
+ }
} else {
context.bindFramebuffer = framebuffer->framebuffer;
}
@@ -37,29 +49,18 @@ public:
return size;
}
- void bindRenderbuffers(gl::TextureUnit unit) {
- if (!framebuffer) {
- texture = context.createTexture(size, gl::TextureFormat::RGBA, unit);
- gl::Renderbuffer<gl::RenderbufferType::DepthComponent> depthTarget = context.createRenderbuffer<gl::RenderbufferType::DepthComponent>(size);
- framebuffer = context.createFramebuffer(*texture, depthTarget);
-
- } else {
- context.bindFramebuffer = framebuffer->framebuffer;
- }
-
- context.activeTexture = unit;
- context.viewport = { 0, 0, size };
- }
-
private:
gl::Context& context;
const Size size;
+ OffscreenTextureAttachment type;
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))) {
+OffscreenTexture::OffscreenTexture(gl::Context& context,
+ const Size size,
+ OffscreenTextureAttachment type)
+ : impl(std::make_unique<Impl>(context, std::move(size), type)) {
assert(!size.isEmpty());
}
@@ -81,8 +82,4 @@ const Size& OffscreenTexture::getSize() const {
return impl->getSize();
}
-void OffscreenTexture::bindRenderbuffers(gl::TextureUnit unit) {
- impl->bindRenderbuffers(unit);
-}
-
} // namespace mbgl