Files
MapLibreParticleLab/src/mbgl/map/sprite.hpp
Konstantin Käfer 48c55af5c1 fix sprites for pixel ratios that are not 1 and 2
- OpenGL ES 2 doesn't allow NPOT textures with wrap-around
- The Sprite object reported the map's pixelRatio, even though it loaded @2x assets
- Copying icons from the sprite into the atlas now uses bilinear scaling to scale up to the actual size
2015-03-17 12:30:40 +01:00

83 lines
1.7 KiB
C++

#ifndef MBGL_STYLE_SPRITE
#define MBGL_STYLE_SPRITE
#include <mbgl/util/image.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
#include <cstdint>
#include <atomic>
#include <iosfwd>
#include <string>
#include <unordered_map>
#include <future>
namespace mbgl {
class Environment;
class SpritePosition {
public:
explicit SpritePosition() {}
explicit SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, float pixelRatio, bool sdf);
operator bool() const {
return !(width == 0 && height == 0 && x == 0 && y == 0);
}
uint16_t x = 0, y = 0;
uint16_t width = 0, height = 0;
float pixelRatio = 1.0f;
bool sdf = false;
};
class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable {
private:
struct Key {};
void load(Environment &env);
public:
Sprite(const Key &, const std::string& base_url, float pixelRatio);
static util::ptr<Sprite>
Create(const std::string &base_url, float pixelRatio, Environment &env);
const SpritePosition &getSpritePosition(const std::string& name) const;
bool hasPixelRatio(float ratio) const;
void waitUntilLoaded() const;
bool isLoaded() const;
operator bool() const;
private:
const bool valid;
public:
const float pixelRatio;
const std::string spriteURL;
const std::string jsonURL;
std::unique_ptr<util::Image> raster;
private:
void parseJSON();
void parseImage();
void complete();
private:
std::string body;
std::string image;
std::atomic<bool> loadedImage;
std::atomic<bool> loadedJSON;
std::unordered_map<std::string, SpritePosition> pos;
const SpritePosition empty;
std::promise<void> promise;
std::future<void> future;
};
}
#endif