#pragma once #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { class GlyphAtlas : public util::noncopyable { public: GlyphAtlas(uint16_t width, uint16_t height); ~GlyphAtlas(); void addGlyphs(uintptr_t tileUID, const std::u32string& text, const FontStack&, const GlyphSet&, GlyphPositions&); void removeGlyphs(uintptr_t tileUID); // Binds the atlas texture to the GPU, and uploads data if it is out of date. void bind(gl::ObjectStore&); // Uploads the texture to the GPU to be available when we need it. This is a lazy operation; // the texture is only bound when the data is out of date (=dirty). void upload(gl::ObjectStore&); const GLsizei width; const GLsizei height; private: struct GlyphValue { GlyphValue(Rect rect_, uintptr_t id) : rect(std::move(rect_)), ids({ id }) {} Rect rect; std::set ids; }; Rect addGlyph(uintptr_t tileID, const FontStack&, const SDFGlyph&); std::mutex mtx; BinPack bin; std::unordered_map, FontStackHash> index; const std::unique_ptr data; util::Atomic dirty; mbgl::optional texture; }; } // namespace mbgl