SDF icon support (fixes #404)
This commit is contained in:
@@ -19,7 +19,7 @@ class FileSource;
|
||||
class SpritePosition {
|
||||
public:
|
||||
explicit SpritePosition() {}
|
||||
explicit SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, float pixelRatio = 1.0f);
|
||||
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);
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
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 {
|
||||
|
||||
@@ -120,12 +120,24 @@ public:
|
||||
void discardFramebuffers();
|
||||
|
||||
bool needsAnimation() const;
|
||||
|
||||
private:
|
||||
void setupShaders();
|
||||
mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor);
|
||||
|
||||
void prepareTile(const Tile& tile);
|
||||
|
||||
template <typename BucketProperties, typename StyleProperties>
|
||||
void renderSDF(SymbolBucket &bucket,
|
||||
const Tile::ID &id,
|
||||
const mat4 &matrixSymbol,
|
||||
const BucketProperties& bucketProperties,
|
||||
const StyleProperties& styleProperties,
|
||||
float scaleDivisor,
|
||||
std::array<float, 2> texsize,
|
||||
SDFShader& sdfShader,
|
||||
void (SymbolBucket::*drawSDF)(SDFShader&));
|
||||
|
||||
public:
|
||||
void useProgram(uint32_t program);
|
||||
void lineWidth(float lineWidth);
|
||||
@@ -176,7 +188,8 @@ public:
|
||||
std::unique_ptr<PatternShader> patternShader;
|
||||
std::unique_ptr<IconShader> iconShader;
|
||||
std::unique_ptr<RasterShader> rasterShader;
|
||||
std::unique_ptr<SDFShader> sdfShader;
|
||||
std::unique_ptr<SDFGlyphShader> sdfGlyphShader;
|
||||
std::unique_ptr<SDFIconShader> sdfIconShader;
|
||||
std::unique_ptr<DotShader> dotShader;
|
||||
std::unique_ptr<GaussianShader> gaussianShader;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ typedef std::vector<Symbol> Symbols;
|
||||
|
||||
class SymbolBucket : public Bucket {
|
||||
typedef ElementGroup<1> TextElementGroup;
|
||||
typedef ElementGroup<1> IconElementGroup;
|
||||
typedef ElementGroup<2> IconElementGroup;
|
||||
|
||||
public:
|
||||
SymbolBucket(const StyleBucketSymbol &properties, Collision &collision);
|
||||
@@ -68,7 +68,8 @@ public:
|
||||
void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, PlacementRange placementRange,
|
||||
float zoom);
|
||||
|
||||
void drawGlyphs(SDFShader &shader);
|
||||
void drawGlyphs(SDFShader& shader);
|
||||
void drawIcons(SDFShader& shader);
|
||||
void drawIcons(IconShader& shader);
|
||||
|
||||
private:
|
||||
@@ -90,6 +91,7 @@ private:
|
||||
|
||||
public:
|
||||
const StyleBucketSymbol &properties;
|
||||
bool sdfIcons = false;
|
||||
|
||||
private:
|
||||
Collision &collision;
|
||||
|
||||
@@ -10,7 +10,7 @@ class SDFShader : public Shader {
|
||||
public:
|
||||
SDFShader();
|
||||
|
||||
void bind(char *offset);
|
||||
virtual void bind(char *offset) = 0;
|
||||
|
||||
UniformMatrix<4> u_matrix = {"u_matrix", *this};
|
||||
UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this};
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
Uniform<float> u_maxfadezoom = {"u_maxfadezoom", *this};
|
||||
Uniform<float> u_fadezoom = {"u_fadezoom", *this};
|
||||
|
||||
private:
|
||||
protected:
|
||||
int32_t a_pos = -1;
|
||||
int32_t a_offset = -1;
|
||||
int32_t a_tex = -1;
|
||||
@@ -37,6 +37,17 @@ private:
|
||||
int32_t a_rangestart = -1;
|
||||
int32_t a_labelminzoom = -1;
|
||||
};
|
||||
|
||||
class SDFGlyphShader : public SDFShader {
|
||||
public:
|
||||
void bind(char *offset);
|
||||
};
|
||||
|
||||
class SDFIconShader : public SDFShader {
|
||||
public:
|
||||
void bind(char *offset);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user