summaryrefslogtreecommitdiff
path: root/src/mbgl/programs/heatmap_program.hpp
blob: 9e8b9c53574ddbc09b76549923df16180f392e23 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/heatmap_texture_program.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shaders/heatmap.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/style/layers/heatmap_layer_properties.hpp>

namespace mbgl {

namespace uniforms {
MBGL_DEFINE_UNIFORM_SCALAR(float, u_intensity);
} // namespace uniforms

class HeatmapProgram : public Program<
    HeatmapProgram,
    shaders::heatmap,
    gfx::PrimitiveType::Triangle,
    TypeList<
        attributes::a_pos>,
    TypeList<
        uniforms::u_intensity,
        uniforms::u_matrix,
        uniforms::heatmap::u_extrude_scale>,
    TypeList<>,
    style::HeatmapPaintProperties>
{
public:
    using Program::Program;

    /*
     * @param {number} x vertex position
     * @param {number} y vertex position
     * @param {number} ex extrude normal
     * @param {number} ey extrude normal
     */
    static LayoutVertex vertex(Point<int16_t> p, float ex, float ey) {
        return LayoutVertex {
            {{
                static_cast<int16_t>((p.x * 2) + ((ex + 1) / 2)),
                static_cast<int16_t>((p.y * 2) + ((ey + 1) / 2))
            }}
        };
    }
};

using HeatmapLayoutVertex = HeatmapProgram::LayoutVertex;
using HeatmapAttributes = HeatmapProgram::AttributeList;

class HeatmapLayerPrograms final : public LayerTypePrograms  {
public:
    HeatmapLayerPrograms(gl::Context& context, const ProgramParameters& programParameters) 
        : heatmap(context, programParameters),
          heatmapTexture(context, programParameters) {}
    ProgramMap<HeatmapProgram> heatmap;
    HeatmapTextureProgram heatmapTexture;
};

} // namespace mbgl