summaryrefslogtreecommitdiff
path: root/src/renderer/painter_icon.cpp
blob: 158030df19d2510d0f56d3c9f52d631eb2403f5d (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
40
41
42
43
44
45
#include <mbgl/renderer/painter.hpp>
#include <mbgl/renderer/icon_bucket.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/sprite.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/geometry/sprite_atlas.hpp>
#include <mbgl/util/math.hpp>

using namespace mbgl;

void Painter::renderIcon(IconBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id) {
    // Abort early.
    if (!bucket.hasData()) return;
    if (pass == Opaque) return;

    const IconProperties &properties = layer_desc->getProperties<IconProperties>();

// TODO: when translating icon, are we doing this in the bucket already?
//    const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);

    SpriteAtlas &spriteAtlas = *map.getSpriteAtlas();

    useProgram(iconShader->program);
    iconShader->setMatrix(matrix);
// TODO: update
    iconShader->setColor({{ 1, 1, 1, 1 }});
    iconShader->setImage(0);
    iconShader->setRatio(map.getState().getPixelRatio());
    iconShader->setDimension({{
        spriteAtlas.getTextureWidth(),
        spriteAtlas.getTextureHeight(),
    }});

    spriteAtlas.bind(map.getState().isChanging());

    const float iconSize = bucket.properties.size * map.getState().getPixelRatio();
    iconShader->setSize(iconSize);
#ifndef GL_ES_VERSION_2_0
    glPointSize(iconSize);
    glEnable(GL_POINT_SPRITE);
#endif

    glDepthRange(strata, 1.0f);
    bucket.drawIcons(*iconShader);
}