summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/raster_bucket.cpp
blob: 137574b7319e11cebd85731c706597a2421eefcf (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
36
37
38
39
#include <mbgl/renderer/raster_bucket.hpp>
#include <mbgl/layer/raster_layer.hpp>
#include <mbgl/shader/raster_shader.hpp>
#include <mbgl/renderer/painter.hpp>

using namespace mbgl;

RasterBucket::RasterBucket(gl::TexturePool& texturePool)
: raster(texturePool) {
}

void RasterBucket::upload(gl::GLObjectStore& glObjectStore) {
    if (hasData()) {
        raster.upload(glObjectStore);
        uploaded = true;
    }
}

void RasterBucket::render(Painter& painter,
                          const StyleLayer& layer,
                          const TileID& id,
                          const mat4& matrix) {
    painter.renderRaster(*this, *layer.as<RasterLayer>(), id, matrix);
}

void RasterBucket::setImage(PremultipliedImage image) {
    raster.load(std::move(image));
}

void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, gl::GLObjectStore& glObjectStore) {
    raster.bind(true, glObjectStore);
    shader.u_image = 0;
    array.bind(shader, vertices, BUFFER_OFFSET_0, glObjectStore);
    MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index()));
}

bool RasterBucket::hasData() const {
    return raster.isLoaded();
}