From bb9a466adbfe087a8e7700109a6e54fee33129d2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 3 Sep 2014 17:04:38 -0700 Subject: Revert "Avoid zero size array warning" This reverts commit d4fd57aae976f36a4f235e1e8358f6c5c1ad6d98. --- include/mbgl/platform/event.hpp | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/mbgl/platform/event.hpp b/include/mbgl/platform/event.hpp index 1befd0af3b..1676f40d2c 100644 --- a/include/mbgl/platform/event.hpp +++ b/include/mbgl/platform/event.hpp @@ -59,7 +59,6 @@ constexpr EventSeverity disabledEventSeverities[] = { #if !DEBUG EventSeverity::Debug, #endif - EventSeverity(-1) // Avoid zero size array }; -- cgit v1.2.1 From c1280f0b380bfb21ce9e811b87bcf7d8ab380f25 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 2 Sep 2014 15:18:52 -0700 Subject: Revert "coalesce texture uploads at the beginning of a frame" This reverts commit 8c2c7f769fffcd217698824719b0a0ba45fbef13. See #454 Conflicts: src/geometry/glyph_atlas.cpp src/geometry/sprite_atlas.cpp --- include/mbgl/geometry/glyph_atlas.hpp | 1 - include/mbgl/geometry/sprite_atlas.hpp | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/mbgl/geometry/glyph_atlas.hpp b/include/mbgl/geometry/glyph_atlas.hpp index 8df9fd0f73..336c4af284 100644 --- a/include/mbgl/geometry/glyph_atlas.hpp +++ b/include/mbgl/geometry/glyph_atlas.hpp @@ -33,7 +33,6 @@ public: const SDFGlyph& glyph); void removeGlyphs(uint64_t tile_id); void bind(); - void upload(); public: const uint16_t width = 0; diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp index 36f0f338ea..5044e4d3e6 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -42,12 +42,10 @@ public: // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. Rect waitForImage(const std::string &name, const Sprite &sprite); - // Binds the image buffer of this sprite atlas to the GPU. + // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out + // of date. void bind(bool linear = false); - // Uploads the image buffer to the GPU if it is out of date. - void upload(); - inline float getWidth() const { return width; } inline float getHeight() const { return height; } inline float getTextureWidth() const { return width * pixelRatio; } -- cgit v1.2.1 From 71c31cee2499d44fcd590136d15c5da7fbfb65ec Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Fri, 25 Jul 2014 18:17:37 -0700 Subject: linepattern in progress --- include/mbgl/renderer/line_bucket.hpp | 4 +- include/mbgl/renderer/painter.hpp | 2 + include/mbgl/shader/linepattern_shader.hpp | 59 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 include/mbgl/shader/linepattern_shader.hpp (limited to 'include') diff --git a/include/mbgl/renderer/line_bucket.hpp b/include/mbgl/renderer/line_bucket.hpp index c7e375a0a1..8babb734ed 100644 --- a/include/mbgl/renderer/line_bucket.hpp +++ b/include/mbgl/renderer/line_bucket.hpp @@ -17,10 +17,11 @@ class LineVertexBuffer; class TriangleElementsBuffer; class LineShader; class LinejoinShader; +class LinepatternShader; struct pbf; class LineBucket : public Bucket { - typedef ElementGroup<1> triangle_group_type; + typedef ElementGroup<2> triangle_group_type; typedef ElementGroup<1> point_group_type; public: @@ -38,6 +39,7 @@ public: bool hasPoints() const; void drawLines(LineShader& shader); + void drawLinePatterns(LinepatternShader& shader); void drawPoints(LinejoinShader& shader); public: diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index a8fe62b550..534323dd5d 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -169,6 +170,7 @@ public: std::unique_ptr outlineShader; std::unique_ptr lineShader; std::unique_ptr linejoinShader; + std::unique_ptr linepatternShader; std::unique_ptr patternShader; std::unique_ptr iconShader; std::unique_ptr rasterShader; diff --git a/include/mbgl/shader/linepattern_shader.hpp b/include/mbgl/shader/linepattern_shader.hpp new file mode 100644 index 0000000000..7d98b295a8 --- /dev/null +++ b/include/mbgl/shader/linepattern_shader.hpp @@ -0,0 +1,59 @@ +#ifndef MBGL_SHADER_SHADER_LINEPATTERN +#define MBGL_SHADER_SHADER_LINEPATTERN + +#include + +namespace mbgl { + +class LinepatternShader : public Shader { +public: + LinepatternShader(); + + void bind(char *offset); + + void setExtrudeMatrix(const std::array& exmatrix); + void setLineWidth(const std::array& linewidth); + void setRatio(float ratio); + void setDebug(float debug); + void setPatternSize(const std::array& new_pattern_size); + void setPatternTopLeft(const std::array& new_pattern_tl); + void setPatternBottomRight(const std::array& new_pattern_br); + void setOffset(const std::array& offset); + void setGamma(float new_gamma); + void setFade(float new_fade); + +private: + int32_t a_pos = -1; + int32_t a_extrude = -1; + int32_t a_linesofar = -1; + + std::array exmatrix = {{}}; + int32_t u_exmatrix = -1; + + std::array linewidth = {{}}; + int32_t u_linewidth = -1; + + float ratio = 0; + int32_t u_ratio = -1; + + std::array pattern_size = {{}}; + int32_t u_pattern_size = -1; + + std::array pattern_tl = {{}}; + int32_t u_pattern_tl = -1; + + std::array pattern_br = {{}}; + int32_t u_pattern_br = -1; + + std::array offset = {{}}; + int32_t u_offset = -1; + + float gamma = 0.0f; + int32_t u_gamma = -1; + + float fade = 0; + int32_t u_fade = -1; +}; +} + +#endif -- cgit v1.2.1 From 586cb9144af29e1a384de1c3d5162e916954098e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 29 Aug 2014 15:31:02 -0700 Subject: Make renderLine more similar to JS --- include/mbgl/shader/linepattern_shader.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/mbgl/shader/linepattern_shader.hpp b/include/mbgl/shader/linepattern_shader.hpp index 7d98b295a8..f8d50b2376 100644 --- a/include/mbgl/shader/linepattern_shader.hpp +++ b/include/mbgl/shader/linepattern_shader.hpp @@ -14,12 +14,11 @@ public: void setExtrudeMatrix(const std::array& exmatrix); void setLineWidth(const std::array& linewidth); void setRatio(float ratio); - void setDebug(float debug); void setPatternSize(const std::array& new_pattern_size); void setPatternTopLeft(const std::array& new_pattern_tl); void setPatternBottomRight(const std::array& new_pattern_br); - void setOffset(const std::array& offset); - void setGamma(float new_gamma); + void setPoint(float new_point); + void setBlur(float new_blur); void setFade(float new_fade); private: @@ -45,11 +44,11 @@ private: std::array pattern_br = {{}}; int32_t u_pattern_br = -1; - std::array offset = {{}}; - int32_t u_offset = -1; + float point = 0.0f; + int32_t u_point = -1; - float gamma = 0.0f; - int32_t u_gamma = -1; + float blur = 0.0f; + int32_t u_blur = -1; float fade = 0; int32_t u_fade = -1; -- cgit v1.2.1 From 4694aa40ada7d33732806f7fbb50b9abb2c412da Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 2 Sep 2014 11:33:45 -0700 Subject: Add SpriteAtlas::getPosition() --- include/mbgl/geometry/sprite_atlas.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp index 5044e4d3e6..0946f0fc48 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -9,12 +9,19 @@ #include #include #include +#include namespace mbgl { class Sprite; class SpritePosition; +struct SpriteAtlasPosition { + std::array size; + std::array tl; + std::array br; +}; + class SpriteAtlas : public util::noncopyable { public: typedef uint16_t dimension; @@ -42,6 +49,8 @@ public: // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. Rect waitForImage(const std::string &name, const Sprite &sprite); + SpriteAtlasPosition getPosition(const std::string &name, const Sprite &sprite, bool repeating = false); + // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out // of date. void bind(bool linear = false); -- cgit v1.2.1 From c14ae3c477617d284d50daff668ab5716ff9a771 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 4 Sep 2014 15:38:14 -0700 Subject: Fix text/icon-translate-anchor These are style properties, not render properties. --- include/mbgl/renderer/painter.hpp | 2 +- include/mbgl/style/style_bucket.hpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'include') diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 534323dd5d..52536e0a75 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -120,7 +120,7 @@ public: bool needsAnimation() const; private: void setupShaders(); - mat4 translatedMatrix(const mat4& matrix, const std::array &translation, const Tile::ID &id, TranslateAnchorType anchor = TranslateAnchorType::Map); + mat4 translatedMatrix(const mat4& matrix, const std::array &translation, const Tile::ID &id, TranslateAnchorType anchor); void prepareTile(const Tile& tile); diff --git a/include/mbgl/style/style_bucket.hpp b/include/mbgl/style/style_bucket.hpp index 67c3142059..c2cde52aa5 100644 --- a/include/mbgl/style/style_bucket.hpp +++ b/include/mbgl/style/style_bucket.hpp @@ -53,7 +53,6 @@ public: float padding = 2.0f; bool keep_upright = false; vec2 offset = {0, 0}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Map; } icon; struct { @@ -74,7 +73,6 @@ public: bool keep_upright = true; TextTransformType transform = TextTransformType::None; vec2 offset = {0, 0}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Map; bool allow_overlap = false; bool ignore_placement = false; bool optional = false; -- cgit v1.2.1 From 1fedf0918aa5c529207ba8f2f1312d403a8ba7fc Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 4 Sep 2014 13:55:03 -0700 Subject: Less shader boilerplate --- include/mbgl/renderer/painter.hpp | 2 + include/mbgl/shader/dot_shader.hpp | 29 +++++-------- include/mbgl/shader/gaussian_shader.hpp | 12 ++---- include/mbgl/shader/icon_shader.hpp | 52 ++++++------------------ include/mbgl/shader/line_shader.hpp | 33 ++++----------- include/mbgl/shader/linejoin_shader.hpp | 22 +++------- include/mbgl/shader/linepattern_shader.hpp | 47 +++++---------------- include/mbgl/shader/outline_shader.hpp | 12 ++---- include/mbgl/shader/pattern_shader.hpp | 32 ++++----------- include/mbgl/shader/plain_shader.hpp | 8 ++-- include/mbgl/shader/raster_shader.hpp | 42 +++++-------------- include/mbgl/shader/shader.hpp | 6 --- include/mbgl/shader/text_shader.hpp | 65 +++++++----------------------- include/mbgl/shader/uniform.hpp | 53 ++++++++++++++++++++++++ 14 files changed, 147 insertions(+), 268 deletions(-) create mode 100644 include/mbgl/shader/uniform.hpp (limited to 'include') diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 52536e0a75..7a245a58da 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -88,6 +88,8 @@ public: void renderRaster(RasterBucket& bucket, std::shared_ptr layer_desc, const Tile::ID& id, const mat4 &matrix); void renderBackground(std::shared_ptr layer_desc); + float saturationFactor(float saturation); + float contrastFactor(float contrast); std::array spinWeights(float spin_value); void preparePrerender(RasterBucket &bucket); diff --git a/include/mbgl/shader/dot_shader.hpp b/include/mbgl/shader/dot_shader.hpp index d8d649db9c..2c4176f364 100644 --- a/include/mbgl/shader/dot_shader.hpp +++ b/include/mbgl/shader/dot_shader.hpp @@ -2,30 +2,23 @@ #define MBGL_SHADER_SHADER_DOT #include +#include namespace mbgl { - class DotShader : public Shader { - public: - DotShader(); +class DotShader : public Shader { +public: + DotShader(); - void bind(char *offset); + void bind(char *offset); - void setColor(const std::array& color); - void setSize(float size); - void setBlur(float blur); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform u_size = {"u_size", *this}; + Uniform u_blur = {"u_blur", *this}; - private: - int32_t a_pos = -1; - - std::array color = {{}}; - int32_t u_color = -1; - - float size = 0; - int32_t u_size = -1; - - float blur = 0; - int32_t u_blur = -1; +private: + int32_t a_pos = -1; }; } diff --git a/include/mbgl/shader/gaussian_shader.hpp b/include/mbgl/shader/gaussian_shader.hpp index a4b9d09f3a..0f494f5c7e 100644 --- a/include/mbgl/shader/gaussian_shader.hpp +++ b/include/mbgl/shader/gaussian_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_RENDERER_SHADER_GAUSSIAN #include +#include namespace mbgl { @@ -11,17 +12,12 @@ public: void bind(char *offset); - void setImage(int32_t image); - void setOffset(const std::array& offset); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_offset = {"u_offset", *this}; + Uniform u_image = {"u_image", *this}; private: int32_t a_pos = -1; - - int32_t image = 0; - int32_t u_image = -1; - - std::array offset = {{}}; - int32_t u_offset = -1; }; } diff --git a/include/mbgl/shader/icon_shader.hpp b/include/mbgl/shader/icon_shader.hpp index 54869fe48d..645d7e21b6 100644 --- a/include/mbgl/shader/icon_shader.hpp +++ b/include/mbgl/shader/icon_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_SHADER_SHADER_ICON #include +#include namespace mbgl { @@ -11,16 +12,17 @@ public: void bind(char *offset); - void setExtrudeMatrix(const std::array& exmatrix); - void setAngle(float angle); - void setZoom(float zoom); - void setFlip(float flip); - void setFadeDist(float fadedist); - void setMinFadeZoom(float minfadezoom); - void setMaxFadeZoom(float maxfadezoom); - void setFadeZoom(float fadezoom); - void setOpacity(float opacity); - void setTextureSize(const std::array &texsize); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform u_angle = {"u_angle", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_flip = {"u_flip", *this}; + Uniform u_fadedist = {"u_fadedist", *this}; + Uniform u_minfadezoom = {"u_minfadezoom", *this}; + Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform u_fadezoom = {"u_fadezoom", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform> u_texsize = {"u_texsize", *this}; private: int32_t a_pos = -1; @@ -32,36 +34,6 @@ private: int32_t a_rangeend = -1; int32_t a_rangestart = -1; int32_t a_labelminzoom = -1; - - std::array exmatrix = {{}}; - int32_t u_exmatrix = -1; - - float angle = 0; - int32_t u_angle = -1; - - float zoom = 0; - int32_t u_zoom = -1; - - float flip = 0; - int32_t u_flip = -1; - - float fadedist = 0; - int32_t u_fadedist = -1; - - float minfadezoom = 0; - int32_t u_minfadezoom = -1; - - float maxfadezoom = 0; - int32_t u_maxfadezoom = -1; - - float fadezoom = 0; - int32_t u_fadezoom = -1; - - float opacity = 0; - int32_t u_opacity = -1; - - std::array texsize = {{}}; - int32_t u_texsize = -1; }; } diff --git a/include/mbgl/shader/line_shader.hpp b/include/mbgl/shader/line_shader.hpp index c476b5c4c6..b789330882 100644 --- a/include/mbgl/shader/line_shader.hpp +++ b/include/mbgl/shader/line_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_SHADER_SHADER_LINE #include +#include namespace mbgl { @@ -11,36 +12,18 @@ public: void bind(char *offset); - void setExtrudeMatrix(const std::array& exmatrix); - void setColor(const std::array& color); - void setLineWidth(const std::array& linewidth); - void setRatio(float ratio); - void setDashArray(const std::array& dasharray); - void setBlur(float blur); - void setDebug(float debug); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform> u_dasharray = {"u_dasharray", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_blur = {"u_blur", *this}; private: int32_t a_pos = -1; int32_t a_extrude = -1; int32_t a_linesofar = -1; - - std::array exmatrix = {{}}; - int32_t u_exmatrix = -1; - - std::array color = {{}}; - int32_t u_color = -1; - - std::array linewidth = {{}}; - int32_t u_linewidth = -1; - - float ratio = 0; - int32_t u_ratio = -1; - - std::array dasharray = {{}}; - int32_t u_dasharray = -1; - - float blur = 0.0f; - int32_t u_blur = -1; }; diff --git a/include/mbgl/shader/linejoin_shader.hpp b/include/mbgl/shader/linejoin_shader.hpp index 5a5c97e921..61406fd45c 100644 --- a/include/mbgl/shader/linejoin_shader.hpp +++ b/include/mbgl/shader/linejoin_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_SHADER_SHADER_LINEJOIN #include +#include namespace mbgl { @@ -11,25 +12,14 @@ public: void bind(char *offset); - void setColor(const std::array& color); - void setWorld(const std::array& world); - void setLineWidth(const std::array& linewidth); - void setSize(float size); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_world = {"u_world", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform u_size = {"u_size", *this}; private: int32_t a_pos = -1; - - std::array color = {{}}; - int32_t u_color = -1; - - std::array world = {{}}; - int32_t u_world = -1; - - std::array linewidth = {{}}; - int32_t u_linewidth = -1; - - float size = 0; - int32_t u_size = -1; }; } diff --git a/include/mbgl/shader/linepattern_shader.hpp b/include/mbgl/shader/linepattern_shader.hpp index f8d50b2376..bd22c99a19 100644 --- a/include/mbgl/shader/linepattern_shader.hpp +++ b/include/mbgl/shader/linepattern_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_SHADER_SHADER_LINEPATTERN #include +#include namespace mbgl { @@ -11,47 +12,21 @@ public: void bind(char *offset); - void setExtrudeMatrix(const std::array& exmatrix); - void setLineWidth(const std::array& linewidth); - void setRatio(float ratio); - void setPatternSize(const std::array& new_pattern_size); - void setPatternTopLeft(const std::array& new_pattern_tl); - void setPatternBottomRight(const std::array& new_pattern_br); - void setPoint(float new_point); - void setBlur(float new_blur); - void setFade(float new_fade); + UniformMatrix<4> u_matrix = {"u_posmatrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_linewidth = {"u_linewidth", *this}; + Uniform> u_pattern_size = {"u_pattern_size", *this}; + Uniform> u_pattern_tl = {"u_pattern_tl", *this}; + Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform u_ratio = {"u_ratio", *this}; + Uniform u_point = {"u_point", *this}; + Uniform u_blur = {"u_blur", *this}; + Uniform u_fade = {"u_fade", *this}; private: int32_t a_pos = -1; int32_t a_extrude = -1; int32_t a_linesofar = -1; - - std::array exmatrix = {{}}; - int32_t u_exmatrix = -1; - - std::array linewidth = {{}}; - int32_t u_linewidth = -1; - - float ratio = 0; - int32_t u_ratio = -1; - - std::array pattern_size = {{}}; - int32_t u_pattern_size = -1; - - std::array pattern_tl = {{}}; - int32_t u_pattern_tl = -1; - - std::array pattern_br = {{}}; - int32_t u_pattern_br = -1; - - float point = 0.0f; - int32_t u_point = -1; - - float blur = 0.0f; - int32_t u_blur = -1; - - float fade = 0; - int32_t u_fade = -1; }; } diff --git a/include/mbgl/shader/outline_shader.hpp b/include/mbgl/shader/outline_shader.hpp index 551e31ca57..f3e8175fd7 100644 --- a/include/mbgl/shader/outline_shader.hpp +++ b/include/mbgl/shader/outline_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_SHADER_SHADER_OUTLINE #include +#include namespace mbgl { @@ -11,17 +12,12 @@ public: void bind(char *offset); - void setColor(const std::array& color); - void setWorld(const std::array& world); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_world = {"u_world", *this}; private: int32_t a_pos = -1; - - std::array color = {{}}; - int32_t u_color = -1; - - std::array world = {{}}; - int32_t u_world = -1; }; } diff --git a/include/mbgl/shader/pattern_shader.hpp b/include/mbgl/shader/pattern_shader.hpp index e574b755dc..9fabd8e18a 100644 --- a/include/mbgl/shader/pattern_shader.hpp +++ b/include/mbgl/shader/pattern_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_SHADER_SHADER_PATTERN #include +#include namespace mbgl { @@ -11,33 +12,16 @@ public: void bind(char *offset); - void setPatternTopLeft(const std::array& pattern_tl); - void setPatternBottomRight(const std::array& pattern_br); - void setOpacity(float opacity); - void setImage(int image); - void setMix(float mix); - void setPatternMatrix(const std::array &patternmatrix); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_pattern_tl = {"u_pattern_tl", *this}; + Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_mix = {"u_mix", *this}; + Uniform u_image = {"u_image", *this}; + UniformMatrix<3> u_patternmatrix = {"u_patternmatrix", *this}; private: int32_t a_pos = -1; - - std::array pattern_tl = {{}}; - int32_t u_pattern_tl = -1; - - std::array pattern_br = {{}}; - int32_t u_pattern_br = -1; - - float opacity = 0; - int32_t u_opacity = -1; - - int image = 0; - int32_t u_image = -1; - - float mix = 0; - int32_t u_mix = -1; - - std::array patternmatrix = {{}}; - int32_t u_patternmatrix = -1; }; } diff --git a/include/mbgl/shader/plain_shader.hpp b/include/mbgl/shader/plain_shader.hpp index 277788431f..051501c3c9 100644 --- a/include/mbgl/shader/plain_shader.hpp +++ b/include/mbgl/shader/plain_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_SHADER_SHADER_PLAIN #include +#include namespace mbgl { @@ -11,14 +12,11 @@ public: void bind(char *offset); - void setColor(float r, float g, float b, float a); - void setColor(const std::array& color); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform> u_color = {"u_color", *this}; private: int32_t a_pos = -1; - - std::array color = {{}}; - int32_t u_color = -1; }; } diff --git a/include/mbgl/shader/raster_shader.hpp b/include/mbgl/shader/raster_shader.hpp index 11765413f4..8cf97055a2 100644 --- a/include/mbgl/shader/raster_shader.hpp +++ b/include/mbgl/shader/raster_shader.hpp @@ -2,6 +2,7 @@ #define MBGL_RENDERER_SHADER_RASTER #include +#include namespace mbgl { @@ -11,41 +12,18 @@ public: void bind(char *offset); - void setImage(int32_t image); - void setOpacity(float opacity); - void setBuffer(float buffer); - void setBrightness(float brightness_low, float brightness_high); - void setSaturation(float saturation_factor); - void setContrast(float contrast_factor); - void setSpin(std::array spin_weights); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform u_image = {"u_image", *this}; + Uniform u_opacity = {"u_opacity", *this}; + Uniform u_buffer = {"u_buffer", *this}; + Uniform u_brightness_low = {"u_brightness_low", *this}; + Uniform u_brightness_high = {"u_brightness_high", *this}; + Uniform u_saturation_factor = {"u_saturation_factor", *this}; + Uniform u_contrast_factor = {"u_contrast_factor", *this}; + Uniform> u_spin_weights = {"u_spin_weights", *this}; private: int32_t a_pos = -1; - - int32_t image = 0; - int32_t u_image = -1; - - float opacity = 0; - int32_t u_opacity = -1; - - float buffer = 0; - int32_t u_buffer = -1; - - float brightness_low = 0; - int32_t u_brightness_low = -1; - - float brightness_high = 0; - int32_t u_brightness_high = -1; - - float saturation_factor = 0; - int32_t u_saturation_factor = -1; - - float contrast_factor = 1; - int32_t u_contrast_factor = -1; - - std::array spin_weights = {{}}; - int32_t u_spin_weights = -1; - }; } diff --git a/include/mbgl/shader/shader.hpp b/include/mbgl/shader/shader.hpp index fa2d5a0a8e..27e831a510 100644 --- a/include/mbgl/shader/shader.hpp +++ b/include/mbgl/shader/shader.hpp @@ -15,18 +15,12 @@ public: bool valid; uint32_t program; - void setMatrix(const std::array& matrix); - inline uint32_t getID() const { return program; } private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); - -protected: - std::array matrix = {{}}; - int32_t u_matrix = -1; }; } diff --git a/include/mbgl/shader/text_shader.hpp b/include/mbgl/shader/text_shader.hpp index 554b890fb0..05360b9fcf 100644 --- a/include/mbgl/shader/text_shader.hpp +++ b/include/mbgl/shader/text_shader.hpp @@ -1,7 +1,8 @@ #ifndef MBGL_SHADER_TEXT_SHADER #define MBGL_SHADER_TEXT_SHADER -#include "shader.hpp" +#include +#include namespace mbgl { @@ -11,61 +12,25 @@ public: void bind(char *offset); - void setColor(float r, float g, float b, float a); - void setColor(const std::array &color); - void setBuffer(float buffer); - void setGamma(float gamma); - void setExtrudeMatrix(const std::array &exmatrix); - void setAngle(float angle); - void setZoom(float zoom); - void setFlip(float flip); - void setFadeDist(float fadedist); - void setMinFadeZoom(float minfadezoom); - void setMaxFadeZoom(float maxfadezoom); - void setFadeZoom(float fadezoom); - void setTextureSize(const std::array &texsize); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_texsize = {"u_texsize", *this}; + Uniform u_buffer = {"u_buffer", *this}; + Uniform u_gamma = {"u_gamma", *this}; + Uniform u_angle = {"u_angle", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_flip = {"u_flip", *this}; + Uniform u_fadedist = {"u_fadedist", *this}; + Uniform u_minfadezoom = {"u_minfadezoom", *this}; + Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform u_fadezoom = {"u_fadezoom", *this}; private: int32_t a_pos = -1; int32_t a_offset = -1; int32_t a_data1 = -1; int32_t a_data2 = -1; - - std::array color = {{}}; - int32_t u_color = -1; - - float buffer = 0.0f; - int32_t u_buffer = -1; - - float gamma = 0.0f; - int32_t u_gamma = -1; - - std::array exmatrix = {{}}; - int32_t u_exmatrix = -1; - - float angle = 0.0f; - int32_t u_angle = -1; - - float zoom = 0.0f; - int32_t u_zoom = -1; - - float flip = 0.0f; - int32_t u_flip = -1; - - float fadedist = 0.0f; - int32_t u_fadedist = -1; - - float minfadezoom = 0.0f; - int32_t u_minfadezoom = -1; - - float maxfadezoom = 0.0f; - int32_t u_maxfadezoom = -1; - - float fadezoom = 0.0f; - int32_t u_fadezoom = -1; - - std::array texsize = {{}}; - int32_t u_texsize = -1; }; } diff --git a/include/mbgl/shader/uniform.hpp b/include/mbgl/shader/uniform.hpp new file mode 100644 index 0000000000..a87bbd7aa3 --- /dev/null +++ b/include/mbgl/shader/uniform.hpp @@ -0,0 +1,53 @@ +#ifndef MBGL_SHADER_UNIFORM +#define MBGL_SHADER_UNIFORM + +#include +#include + +namespace mbgl { + +template +class Uniform { +public: + Uniform(const GLchar* name, const Shader& shader) + : location(glGetUniformLocation(shader.program, name)) {} + + void operator=(const T& t) { + if (current != t) { + current = t; + bind(t); + } + } + +private: + void bind(const T&); + + T current; + GLint location; +}; + +template +class UniformMatrix { +public: + typedef std::array T; + + UniformMatrix(const GLchar* name, const Shader& shader) + : location(glGetUniformLocation(shader.program, name)) {} + + void operator=(const T& t) { + if (current != t) { + current = t; + bind(t); + } + } + +private: + void bind(const T&); + + T current; + GLint location; +}; + +} + +#endif -- cgit v1.2.1 From f2391e25ea8162562a6b355a9df8473193be88c3 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 4 Sep 2014 15:53:18 -0700 Subject: =?UTF-8?q?TextShader=20=E2=87=A2=20SDFShader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/mbgl/renderer/painter.hpp | 4 ++-- include/mbgl/renderer/symbol_bucket.hpp | 4 ++-- include/mbgl/shader/sdf_shader.hpp | 37 +++++++++++++++++++++++++++++++++ include/mbgl/shader/text_shader.hpp | 37 --------------------------------- 4 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 include/mbgl/shader/sdf_shader.hpp delete mode 100644 include/mbgl/shader/text_shader.hpp (limited to 'include') diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 7a245a58da..af50a6b52a 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -176,7 +176,7 @@ public: std::unique_ptr patternShader; std::unique_ptr iconShader; std::unique_ptr rasterShader; - std::unique_ptr textShader; + std::unique_ptr sdfShader; 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 fb1678fc8b..23de5e6e5a 100644 --- a/include/mbgl/renderer/symbol_bucket.hpp +++ b/include/mbgl/renderer/symbol_bucket.hpp @@ -18,7 +18,7 @@ namespace mbgl { class Style; -class TextShader; +class SDFShader; class IconShader; class DotShader; class Collision; @@ -68,7 +68,7 @@ public: void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, PlacementRange placementRange, float zoom); - void drawGlyphs(TextShader &shader); + void drawGlyphs(SDFShader &shader); void drawIcons(IconShader& shader); private: diff --git a/include/mbgl/shader/sdf_shader.hpp b/include/mbgl/shader/sdf_shader.hpp new file mode 100644 index 0000000000..85104e2f96 --- /dev/null +++ b/include/mbgl/shader/sdf_shader.hpp @@ -0,0 +1,37 @@ +#ifndef MBGL_SHADER_SDF_SHADER +#define MBGL_SHADER_SDF_SHADER + +#include +#include + +namespace mbgl { + +class SDFShader : public Shader { +public: + SDFShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform> u_color = {"u_color", *this}; + Uniform> u_texsize = {"u_texsize", *this}; + Uniform u_buffer = {"u_buffer", *this}; + Uniform u_gamma = {"u_gamma", *this}; + Uniform u_angle = {"u_angle", *this}; + Uniform u_zoom = {"u_zoom", *this}; + Uniform u_flip = {"u_flip", *this}; + Uniform u_fadedist = {"u_fadedist", *this}; + Uniform u_minfadezoom = {"u_minfadezoom", *this}; + Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform u_fadezoom = {"u_fadezoom", *this}; + +private: + int32_t a_pos = -1; + int32_t a_offset = -1; + int32_t a_data1 = -1; + int32_t a_data2 = -1; +}; +} + +#endif diff --git a/include/mbgl/shader/text_shader.hpp b/include/mbgl/shader/text_shader.hpp deleted file mode 100644 index 05360b9fcf..0000000000 --- a/include/mbgl/shader/text_shader.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef MBGL_SHADER_TEXT_SHADER -#define MBGL_SHADER_TEXT_SHADER - -#include -#include - -namespace mbgl { - -class TextShader : public Shader { -public: - TextShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform> u_color = {"u_color", *this}; - Uniform> u_texsize = {"u_texsize", *this}; - Uniform u_buffer = {"u_buffer", *this}; - Uniform u_gamma = {"u_gamma", *this}; - Uniform u_angle = {"u_angle", *this}; - Uniform u_zoom = {"u_zoom", *this}; - Uniform u_flip = {"u_flip", *this}; - Uniform u_fadedist = {"u_fadedist", *this}; - Uniform u_minfadezoom = {"u_minfadezoom", *this}; - Uniform u_maxfadezoom = {"u_maxfadezoom", *this}; - Uniform u_fadezoom = {"u_fadezoom", *this}; - -private: - int32_t a_pos = -1; - int32_t a_offset = -1; - int32_t a_data1 = -1; - int32_t a_data2 = -1; -}; -} - -#endif -- cgit v1.2.1 From 9d5f02ccaa051a0f3459f6fc94df807338fa2552 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 Sep 2014 11:52:23 -0700 Subject: Match js shaders The only non-incidental change is to revert portions of d5b4c116 and 3a9a9043. See https://github.com/mapbox/mapbox-gl-native/commit/d5b4c1162dab706d6f56881e3f72baa003ad8ac7#commitcomment-7668050 --- include/mbgl/shader/linepattern_shader.hpp | 2 +- include/mbgl/shader/sdf_shader.hpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/mbgl/shader/linepattern_shader.hpp b/include/mbgl/shader/linepattern_shader.hpp index bd22c99a19..bf85940b8a 100644 --- a/include/mbgl/shader/linepattern_shader.hpp +++ b/include/mbgl/shader/linepattern_shader.hpp @@ -12,7 +12,7 @@ public: void bind(char *offset); - UniformMatrix<4> u_matrix = {"u_posmatrix", *this}; + UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; Uniform> u_linewidth = {"u_linewidth", *this}; Uniform> u_pattern_size = {"u_pattern_size", *this}; diff --git a/include/mbgl/shader/sdf_shader.hpp b/include/mbgl/shader/sdf_shader.hpp index 85104e2f96..ba1937d3c3 100644 --- a/include/mbgl/shader/sdf_shader.hpp +++ b/include/mbgl/shader/sdf_shader.hpp @@ -29,8 +29,13 @@ public: private: int32_t a_pos = -1; int32_t a_offset = -1; - int32_t a_data1 = -1; - int32_t a_data2 = -1; + int32_t a_tex = -1; + int32_t a_angle = -1; + int32_t a_minzoom = -1; + int32_t a_maxzoom = -1; + int32_t a_rangeend = -1; + int32_t a_rangestart = -1; + int32_t a_labelminzoom = -1; }; } -- cgit v1.2.1 From de720f351549ca4ff846c84899082320f6d30d5a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 Sep 2014 14:03:33 -0700 Subject: FrameHistory::getFadeProperties --- include/mbgl/renderer/frame_history.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/mbgl/renderer/frame_history.hpp b/include/mbgl/renderer/frame_history.hpp index a5dbe21bca..b1f0bcb597 100644 --- a/include/mbgl/renderer/frame_history.hpp +++ b/include/mbgl/renderer/frame_history.hpp @@ -16,12 +16,20 @@ struct FrameSnapshot { float z; }; +struct FadeProperties { + float fadedist; + float minfadezoom; + float maxfadezoom; + float bump; +}; + class FrameHistory { public: // Record frame history that will be used to calculate fading params void record(timestamp now, float zoom); bool needsAnimation(timestamp duration) const; + FadeProperties getFadeProperties(timestamp duration); public: std::deque history; -- cgit v1.2.1 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