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

#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/texture_pool.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/optional.hpp>

#include <mutex>

namespace mbgl {

class Raster : public std::enable_shared_from_this<Raster> {

public:
    Raster(gl::TexturePool&);

    // load image data
    void load(PremultipliedImage);

    // bind current texture
    void bind(bool linear, gl::ObjectStore&);

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

    // loaded status
    bool isLoaded() const;

public:
    // loaded image dimensions
    GLsizei width = 0;
    GLsizei height = 0;

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

    // texture opacity
    double opacity = 0;

private:
    mutable std::mutex mtx;

    // raw pixels have been loaded
    bool loaded = false;

    // shared texture pool
    gl::TexturePool& texturePool;

    // min/mag filter
    GLint filter = 0;

    // the raw pixels
    PremultipliedImage img;
};

} // namespace mbgl