summaryrefslogtreecommitdiff
path: root/platform/default/mbgl/gl/offscreen_view.cpp
blob: 16faf6a4a9cb2a22483a03dbf3f020d11b5ba367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <mbgl/gl/offscreen_view.hpp>
#include <mbgl/gl/context.hpp>

#include <cstring>
#include <cassert>

namespace mbgl {

OffscreenView::OffscreenView(gl::Context& context_, const Size size_)
    : size(std::move(size_)), context(context_) {
    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;
    }

    context.viewport = { 0, 0, size };
}

PremultipliedImage OffscreenView::readStillImage() {
    return context.readFramebuffer<PremultipliedImage>(size);
}

} // namespace mbgl