From eb4f53cbed1953d4016975d14424fb2bc6bbf3d3 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 Sep 2014 14:43:52 -0700 Subject: SDF icon support (fixes #404) --- include/mbgl/map/sprite.hpp | 3 ++- include/mbgl/renderer/painter.hpp | 15 ++++++++++++++- include/mbgl/renderer/symbol_bucket.hpp | 6 ++++-- include/mbgl/shader/sdf_shader.hpp | 15 +++++++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp index 7bc6665570..6461a5e33d 100644 --- a/include/mbgl/map/sprite.hpp +++ b/include/mbgl/map/sprite.hpp @@ -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, private util::noncopyable { diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index af50a6b52a..75529d1136 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -120,12 +120,24 @@ public: void discardFramebuffers(); bool needsAnimation() const; + private: void setupShaders(); mat4 translatedMatrix(const mat4& matrix, const std::array &translation, const Tile::ID &id, TranslateAnchorType anchor); void prepareTile(const Tile& tile); + template + void renderSDF(SymbolBucket &bucket, + const Tile::ID &id, + const mat4 &matrixSymbol, + const BucketProperties& bucketProperties, + const StyleProperties& styleProperties, + float scaleDivisor, + std::array 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; std::unique_ptr iconShader; std::unique_ptr rasterShader; - std::unique_ptr sdfShader; + std::unique_ptr sdfGlyphShader; + std::unique_ptr sdfIconShader; std::unique_ptr dotShader; std::unique_ptr gaussianShader; diff --git a/include/mbgl/renderer/symbol_bucket.hpp b/include/mbgl/renderer/symbol_bucket.hpp index 23de5e6e5a..c71d276456 100644 --- a/include/mbgl/renderer/symbol_bucket.hpp +++ b/include/mbgl/renderer/symbol_bucket.hpp @@ -51,7 +51,7 @@ typedef std::vector 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; diff --git a/include/mbgl/shader/sdf_shader.hpp b/include/mbgl/shader/sdf_shader.hpp index ba1937d3c3..0737c25ee1 100644 --- a/include/mbgl/shader/sdf_shader.hpp +++ b/include/mbgl/shader/sdf_shader.hpp @@ -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 u_maxfadezoom = {"u_maxfadezoom", *this}; Uniform 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 -- cgit v1.2.1