summaryrefslogtreecommitdiff
path: root/src/mbgl/util/offscreen_texture.cpp
blob: aad20e59d3117866f5f75f73a9a3d08f5ed41cb3 (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
31
32
33
34
35
#include <mbgl/util/offscreen_texture.hpp>
#include <mbgl/gl/context.hpp>

#include <cstring>
#include <cassert>

namespace mbgl {

OffscreenTexture::OffscreenTexture(gl::Context& context_, const Size size_)
    : size(std::move(size_)), context(context_) {
    assert(size);
}

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;
}

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


} // namespace mbgl