diff options
author | Mike Morris <michael.patrick.morris@gmail.com> | 2014-09-09 17:06:22 -0400 |
---|---|---|
committer | Mike Morris <michael.patrick.morris@gmail.com> | 2014-09-09 17:06:22 -0400 |
commit | c32bb852484420647502a58e880bf8251c13416a (patch) | |
tree | 649090d7941e47d772017843fd0d339945f1fb6e /include | |
parent | 74c4f976d1437e81e9bd57ee98fde05fba8c6e80 (diff) | |
parent | 2a50fccd24e762d0de5a53bac358e5ddfea8d213 (diff) | |
download | qtlocation-mapboxgl-c32bb852484420647502a58e880bf8251c13416a.tar.gz |
Merge branch 'master' into libuv010
Diffstat (limited to 'include')
23 files changed, 254 insertions, 270 deletions
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..0946f0fc48 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -9,12 +9,19 @@ #include <mutex> #include <atomic> #include <set> +#include <array> namespace mbgl { class Sprite; class SpritePosition; +struct SpriteAtlasPosition { + std::array<float, 2> size; + std::array<float, 2> tl; + std::array<float, 2> br; +}; + class SpriteAtlas : public util::noncopyable { public: typedef uint16_t dimension; @@ -42,11 +49,11 @@ public: // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. Rect<dimension> waitForImage(const std::string &name, const Sprite &sprite); - // Binds the image buffer of this sprite atlas to the GPU. - void bind(bool linear = false); + SpriteAtlasPosition getPosition(const std::string &name, const Sprite &sprite, bool repeating = false); - // Uploads the image buffer to the GPU if it is out of date. - void upload(); + // 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); inline float getWidth() const { return width; } inline float getHeight() const { return height; } 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<Sprite>, private util::noncopyable { 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 }; 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<FrameSnapshot> history; 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..75529d1136 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -14,9 +14,10 @@ #include <mbgl/shader/pattern_shader.hpp> #include <mbgl/shader/line_shader.hpp> #include <mbgl/shader/linejoin_shader.hpp> +#include <mbgl/shader/linepattern_shader.hpp> #include <mbgl/shader/icon_shader.hpp> #include <mbgl/shader/raster_shader.hpp> -#include <mbgl/shader/text_shader.hpp> +#include <mbgl/shader/sdf_shader.hpp> #include <mbgl/shader/dot_shader.hpp> #include <mbgl/shader/gaussian_shader.hpp> @@ -87,6 +88,8 @@ public: void renderRaster(RasterBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); void renderBackground(std::shared_ptr<StyleLayer> layer_desc); + float saturationFactor(float saturation); + float contrastFactor(float contrast); std::array<float, 3> spinWeights(float spin_value); void preparePrerender(RasterBucket &bucket); @@ -117,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 = TranslateAnchorType::Map); + 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); @@ -169,10 +184,12 @@ public: std::unique_ptr<OutlineShader> outlineShader; std::unique_ptr<LineShader> lineShader; std::unique_ptr<LinejoinShader> linejoinShader; + std::unique_ptr<LinepatternShader> linepatternShader; std::unique_ptr<PatternShader> patternShader; std::unique_ptr<IconShader> iconShader; std::unique_ptr<RasterShader> rasterShader; - std::unique_ptr<TextShader> textShader; + std::unique_ptr<SDFGlyphShader> sdfGlyphShader; + std::unique_ptr<SDFIconShader> sdfIconShader; std::unique_ptr<DotShader> dotShader; std::unique_ptr<GaussianShader> gaussianShader; diff --git a/include/mbgl/renderer/symbol_bucket.hpp b/include/mbgl/renderer/symbol_bucket.hpp index fb1678fc8b..c71d276456 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; @@ -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(TextShader &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/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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> 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<float, 4>& color); - void setSize(float size); - void setBlur(float blur); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<float, 4>> u_color = {"u_color", *this}; + Uniform<float> u_size = {"u_size", *this}; + Uniform<float> u_blur = {"u_blur", *this}; - private: - int32_t a_pos = -1; - - std::array<float, 4> 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> namespace mbgl { @@ -11,17 +12,12 @@ public: void bind(char *offset); - void setImage(int32_t image); - void setOffset(const std::array<float, 2>& offset); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<float, 2>> u_offset = {"u_offset", *this}; + Uniform<int32_t> u_image = {"u_image", *this}; private: int32_t a_pos = -1; - - int32_t image = 0; - int32_t u_image = -1; - - std::array<float, 2> 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> namespace mbgl { @@ -11,16 +12,17 @@ public: void bind(char *offset); - void setExtrudeMatrix(const std::array<float, 16>& 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<float, 2> &texsize); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform<float> u_angle = {"u_angle", *this}; + Uniform<float> u_zoom = {"u_zoom", *this}; + Uniform<float> u_flip = {"u_flip", *this}; + Uniform<float> u_fadedist = {"u_fadedist", *this}; + Uniform<float> u_minfadezoom = {"u_minfadezoom", *this}; + Uniform<float> u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform<float> u_fadezoom = {"u_fadezoom", *this}; + Uniform<float> u_opacity = {"u_opacity", *this}; + Uniform<std::array<float, 2>> 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<float, 16> 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<float, 2> 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> namespace mbgl { @@ -11,36 +12,18 @@ public: void bind(char *offset); - void setExtrudeMatrix(const std::array<float, 16>& exmatrix); - void setColor(const std::array<float, 4>& color); - void setLineWidth(const std::array<float, 2>& linewidth); - void setRatio(float ratio); - void setDashArray(const std::array<float, 2>& dasharray); - void setBlur(float blur); - void setDebug(float debug); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform<std::array<float, 4>> u_color = {"u_color", *this}; + Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this}; + Uniform<std::array<float, 2>> u_dasharray = {"u_dasharray", *this}; + Uniform<float> u_ratio = {"u_ratio", *this}; + Uniform<float> u_blur = {"u_blur", *this}; private: int32_t a_pos = -1; int32_t a_extrude = -1; int32_t a_linesofar = -1; - - std::array<float, 16> exmatrix = {{}}; - int32_t u_exmatrix = -1; - - std::array<float, 4> color = {{}}; - int32_t u_color = -1; - - std::array<float, 2> linewidth = {{}}; - int32_t u_linewidth = -1; - - float ratio = 0; - int32_t u_ratio = -1; - - std::array<float, 2> 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> namespace mbgl { @@ -11,25 +12,14 @@ public: void bind(char *offset); - void setColor(const std::array<float, 4>& color); - void setWorld(const std::array<float, 2>& world); - void setLineWidth(const std::array<float, 2>& linewidth); - void setSize(float size); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<float, 4>> u_color = {"u_color", *this}; + Uniform<std::array<float, 2>> u_world = {"u_world", *this}; + Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this}; + Uniform<float> u_size = {"u_size", *this}; private: int32_t a_pos = -1; - - std::array<float, 4> color = {{}}; - int32_t u_color = -1; - - std::array<float, 2> world = {{}}; - int32_t u_world = -1; - - std::array<float, 2> 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 new file mode 100644 index 0000000000..bf85940b8a --- /dev/null +++ b/include/mbgl/shader/linepattern_shader.hpp @@ -0,0 +1,33 @@ +#ifndef MBGL_SHADER_SHADER_LINEPATTERN +#define MBGL_SHADER_SHADER_LINEPATTERN + +#include <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> + +namespace mbgl { + +class LinepatternShader : public Shader { +public: + LinepatternShader(); + + void bind(char *offset); + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this}; + Uniform<std::array<float, 2>> u_pattern_size = {"u_pattern_size", *this}; + Uniform<std::array<float, 2>> u_pattern_tl = {"u_pattern_tl", *this}; + Uniform<std::array<float, 2>> u_pattern_br = {"u_pattern_br", *this}; + Uniform<float> u_ratio = {"u_ratio", *this}; + Uniform<float> u_point = {"u_point", *this}; + Uniform<float> u_blur = {"u_blur", *this}; + Uniform<float> u_fade = {"u_fade", *this}; + +private: + int32_t a_pos = -1; + int32_t a_extrude = -1; + int32_t a_linesofar = -1; +}; +} + +#endif 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> namespace mbgl { @@ -11,17 +12,12 @@ public: void bind(char *offset); - void setColor(const std::array<float, 4>& color); - void setWorld(const std::array<float, 2>& world); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<float, 4>> u_color = {"u_color", *this}; + Uniform<std::array<float, 2>> u_world = {"u_world", *this}; private: int32_t a_pos = -1; - - std::array<float, 4> color = {{}}; - int32_t u_color = -1; - - std::array<float, 2> 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> namespace mbgl { @@ -11,33 +12,16 @@ public: void bind(char *offset); - void setPatternTopLeft(const std::array<float, 2>& pattern_tl); - void setPatternBottomRight(const std::array<float, 2>& pattern_br); - void setOpacity(float opacity); - void setImage(int image); - void setMix(float mix); - void setPatternMatrix(const std::array<float, 9> &patternmatrix); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<float, 2>> u_pattern_tl = {"u_pattern_tl", *this}; + Uniform<std::array<float, 2>> u_pattern_br = {"u_pattern_br", *this}; + Uniform<float> u_opacity = {"u_opacity", *this}; + Uniform<float> u_mix = {"u_mix", *this}; + Uniform<int32_t> u_image = {"u_image", *this}; + UniformMatrix<3> u_patternmatrix = {"u_patternmatrix", *this}; private: int32_t a_pos = -1; - - std::array<float, 2> pattern_tl = {{}}; - int32_t u_pattern_tl = -1; - - std::array<float, 2> 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<float, 9> 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> 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<float, 4>& color); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<float, 4>> u_color = {"u_color", *this}; private: int32_t a_pos = -1; - - std::array<float, 4> 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 <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> 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<float, 3> spin_weights); + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<int32_t> u_image = {"u_image", *this}; + Uniform<float> u_opacity = {"u_opacity", *this}; + Uniform<float> u_buffer = {"u_buffer", *this}; + Uniform<float> u_brightness_low = {"u_brightness_low", *this}; + Uniform<float> u_brightness_high = {"u_brightness_high", *this}; + Uniform<float> u_saturation_factor = {"u_saturation_factor", *this}; + Uniform<float> u_contrast_factor = {"u_contrast_factor", *this}; + Uniform<std::array<float, 3>> 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<float, 3> spin_weights = {{}}; - int32_t u_spin_weights = -1; - }; } diff --git a/include/mbgl/shader/sdf_shader.hpp b/include/mbgl/shader/sdf_shader.hpp new file mode 100644 index 0000000000..0737c25ee1 --- /dev/null +++ b/include/mbgl/shader/sdf_shader.hpp @@ -0,0 +1,53 @@ +#ifndef MBGL_SHADER_SDF_SHADER +#define MBGL_SHADER_SDF_SHADER + +#include <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> + +namespace mbgl { + +class SDFShader : public Shader { +public: + SDFShader(); + + virtual void bind(char *offset) = 0; + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; + Uniform<std::array<float, 4>> u_color = {"u_color", *this}; + Uniform<std::array<float, 2>> u_texsize = {"u_texsize", *this}; + Uniform<float> u_buffer = {"u_buffer", *this}; + Uniform<float> u_gamma = {"u_gamma", *this}; + Uniform<float> u_angle = {"u_angle", *this}; + Uniform<float> u_zoom = {"u_zoom", *this}; + Uniform<float> u_flip = {"u_flip", *this}; + Uniform<float> u_fadedist = {"u_fadedist", *this}; + Uniform<float> u_minfadezoom = {"u_minfadezoom", *this}; + Uniform<float> u_maxfadezoom = {"u_maxfadezoom", *this}; + Uniform<float> u_fadezoom = {"u_fadezoom", *this}; + +protected: + int32_t a_pos = -1; + int32_t a_offset = -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; +}; + +class SDFGlyphShader : public SDFShader { +public: + void bind(char *offset); +}; + +class SDFIconShader : public SDFShader { +public: + void bind(char *offset); +}; + +} + +#endif 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<float, 16>& matrix); - inline uint32_t getID() const { return program; } private: bool compileShader(uint32_t *shader, uint32_t type, const char *source); - -protected: - std::array<float, 16> matrix = {{}}; - int32_t u_matrix = -1; }; } diff --git a/include/mbgl/shader/text_shader.hpp b/include/mbgl/shader/text_shader.hpp deleted file mode 100644 index 554b890fb0..0000000000 --- a/include/mbgl/shader/text_shader.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef MBGL_SHADER_TEXT_SHADER -#define MBGL_SHADER_TEXT_SHADER - -#include "shader.hpp" - -namespace mbgl { - -class TextShader : public Shader { -public: - TextShader(); - - void bind(char *offset); - - void setColor(float r, float g, float b, float a); - void setColor(const std::array<float, 4> &color); - void setBuffer(float buffer); - void setGamma(float gamma); - void setExtrudeMatrix(const std::array<float, 16> &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<float, 2> &texsize); - -private: - int32_t a_pos = -1; - int32_t a_offset = -1; - int32_t a_data1 = -1; - int32_t a_data2 = -1; - - std::array<float, 4> 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<float, 16> 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<float, 2> texsize = {{}}; - int32_t u_texsize = -1; -}; -} - -#endif 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 <mbgl/shader/shader.hpp> +#include <mbgl/platform/gl.hpp> + +namespace mbgl { + +template <typename T> +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 <size_t C, size_t R = C> +class UniformMatrix { +public: + typedef std::array<float, C*R> 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 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<float> offset = {0, 0}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Map; } icon; struct { @@ -74,7 +73,6 @@ public: bool keep_upright = true; TextTransformType transform = TextTransformType::None; vec2<float> offset = {0, 0}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Map; bool allow_overlap = false; bool ignore_placement = false; bool optional = false; |