#pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { namespace gl { class Config; } // namespace gl class SpriteStore; class SpriteImage; class SpritePosition; struct SpriteAtlasPosition { std::array size = {{ 0, 0 }}; std::array tl = {{ 0, 0 }}; std::array br = {{ 0, 0 }}; }; struct SpriteAtlasElement { Rect pos; std::shared_ptr spriteImage; float relativePixelRatio; }; class SpriteAtlas : public util::noncopyable { public: typedef uint16_t dimension; SpriteAtlas(dimension width, dimension height, float pixelRatio, SpriteStore& store); ~SpriteAtlas(); // If the sprite is loaded, copies the requsted image from it into the atlas and returns // the resulting icon measurements. If not, returns an empty optional. optional getImage(const std::string& name, const bool wrap); // This function is used for getting the position during render time. optional getPosition(const std::string& name, bool repeating = false); // Binds the atlas texture to the GPU, and uploads data if it is out of date. void bind(bool linear, gl::ObjectStore&, gl::Config&, uint32_t unit); // Updates sprites in the atlas texture that may have changed in the source SpriteStore object. void updateDirty(); // 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&, gl::Config&, uint32_t unit); dimension getWidth() const { return width; } dimension getHeight() const { return height; } dimension getTextureWidth() const { return pixelWidth; } dimension getTextureHeight() const { return pixelHeight; } float getPixelRatio() const { return pixelRatio; } // Only for use in tests. const uint32_t* getData() const { return data.get(); } private: const GLsizei width, height; const dimension pixelWidth, pixelHeight; const float pixelRatio; struct Holder : private util::noncopyable { Holder(std::shared_ptr, Rect); Holder(Holder&&); std::shared_ptr spriteImage; const Rect pos; }; using Key = std::pair; Rect allocateImage(const SpriteImage&); void copy(const Holder& holder, const bool wrap); std::recursive_mutex mtx; SpriteStore& store; BinPack bin; std::map images; std::set uninitialized; std::unique_ptr data; std::atomic dirty; bool fullUploadRequired = true; mbgl::optional texture; uint32_t filter = 0; static const int buffer = 1; }; } // namespace mbgl