summaryrefslogtreecommitdiff
path: root/src/mbgl/util/raster.hpp
blob: 860c5330861e0da9e56f391a110b670cd0852d8d (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
#pragma once

#include <mbgl/gl/object_store.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/optional.hpp>

#include <atomic>
#include <array>

namespace mbgl {

namespace gl {
class Config;
} // namespace gl

class Raster {
public:
    enum class MipMap : bool { No = false, Yes = true };
    enum class Scaling : bool { Nearest = false, Linear = true };

    // load image data
    void load(PremultipliedImage, uint32_t mipmapLevel = 0);

    // bind current texture
    void bind(gl::ObjectStore&,
              gl::Config&,
              uint32_t unit,
              Scaling = Scaling::Nearest,
              MipMap = MipMap::No);

    // uploads the texture if it hasn't been uploaded yet.
    void upload(gl::ObjectStore&, gl::Config&, uint32_t unit);

    // loaded status
    bool isLoaded() const;

    // returns the OpenGL texture ID
    GLuint getID() const;

    // size of uploaded image.
    std::array<uint16_t, 2> getSize() const;

private:
    // raw pixels have been loaded
    std::atomic<bool> loaded { false };
    std::array<uint16_t, 2> size = {{ 0, 0 }};

    // filters
    Scaling filter = Scaling::Nearest;
    MipMap mipmap = MipMap::No;

    // the raw pixels
    std::vector<PremultipliedImage> images;

    // GL buffer object handle.
    mbgl::optional<gl::UniqueTexture> texture;
};

} // namespace mbgl