From a33d334169679ff3786c08aa91736aeb7d9d74be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 19 May 2014 16:19:51 +0200 Subject: [PATCH] incorporate the color and draw circle dots if we don't have an icon Conflicts: bin/style.js --- bin/style.js | 4 ++-- include/llmr/style/properties.hpp | 4 ++-- include/llmr/style/sprite.hpp | 4 ++++ src/geometry/sprite_atlas.cpp | 8 ++++++-- src/renderer/icon_bucket.cpp | 18 ++++++++++++------ src/shader/icon.fragment.glsl | 2 +- src/shader/shaders_gl.cpp | 2 +- src/shader/shaders_gles2.cpp | 2 +- 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/bin/style.js b/bin/style.js index 558c64242..ad2f57e2d 100644 --- a/bin/style.js +++ b/bin/style.js @@ -373,7 +373,8 @@ module.exports = { "layer": "place_label", "field": "type", "value": "city", - "type": "point" + "type": "point", + "size": 4 }, "place_label_city": { "source": "mapbox streets", @@ -1878,7 +1879,6 @@ module.exports = { ], }, "poi": { - "color": "maki", }, "satellite": { "type": "raster", diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp index a9bd89909..90cd6e688 100644 --- a/include/llmr/style/properties.hpp +++ b/include/llmr/style/properties.hpp @@ -65,7 +65,7 @@ struct IconClass { std::array translate = {{ 0, 0 }}; TranslateAnchor translateAnchor = TranslateAnchor::Map; FunctionProperty size; - Color color = {{ 0, 0, 0, 1 }}; + Color color = {{ 1, 1, 1, 1 }}; FunctionProperty opacity = 1; std::string image; FunctionProperty radius = 0; @@ -77,7 +77,7 @@ struct IconProperties { std::array translate = {{ 0, 0 }}; TranslateAnchor translateAnchor = TranslateAnchor::Map; float size = 0; - Color color = {{ 0, 0, 0, 1 }}; + Color color = {{ 1, 1, 1, 1 }}; float opacity = 1.0; std::string image; float radius = 0; diff --git a/include/llmr/style/sprite.hpp b/include/llmr/style/sprite.hpp index 60a61c033..4f902d77a 100644 --- a/include/llmr/style/sprite.hpp +++ b/include/llmr/style/sprite.hpp @@ -19,6 +19,10 @@ public: explicit SpritePosition() {} explicit SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t pixelRatio = 1); + operator bool() const { + return !(width == 0 && height == 0 && x == 0 && y == 0); + } + uint16_t x = 0, y = 0; uint16_t width = 0, height = 0; uint8_t pixelRatio = 1; diff --git a/src/geometry/sprite_atlas.cpp b/src/geometry/sprite_atlas.cpp index fbdf5b348..431aad973 100644 --- a/src/geometry/sprite_atlas.cpp +++ b/src/geometry/sprite_atlas.cpp @@ -161,8 +161,6 @@ Rect SpriteAtlas::getImage(const std::string &name, cons copy(rect, pos, sprite); - dirty = true; - return rect; } @@ -192,6 +190,8 @@ void SpriteAtlas::copy(const Rect &dst, const SpritePosition &src, co /* icon dimension */ src.width, /* icon dimension */ src.height ); + + dirty = true; } @@ -202,6 +202,10 @@ void SpriteAtlas::update(const Sprite &sprite) { std::erase_if(uninitialized, [&sprite, &atlas](const std::string &name) { Rect dst = atlas.getImage(name, sprite); const SpritePosition &src = sprite.getSpritePosition(name); + if (!src) { + return true; + } + if (src.width == dst.w * atlas.pixelRatio && src.height == dst.h * atlas.pixelRatio && src.pixelRatio == atlas.pixelRatio) { atlas.copy(dst, src, sprite); return true; diff --git a/src/renderer/icon_bucket.cpp b/src/renderer/icon_bucket.cpp index 9d1505c03..76404f7f8 100644 --- a/src/renderer/icon_bucket.cpp +++ b/src/renderer/icon_bucket.cpp @@ -24,13 +24,19 @@ IconBucket::IconBucket(IconVertexBuffer& vertexBuffer, } void IconBucket::addFeature(const VectorTileFeature &feature, SpriteAtlas &sprite_atlas) { - auto field_it = feature.properties.find(geometry.field); - if (field_it == feature.properties.end()) { - // fprintf(stderr, "feature doesn't contain field '%s'\n", geometry.field.c_str()); - return; - } + std::string field; - std::string field = toString(field_it->second); + if (geometry.field.size()) { + auto field_it = feature.properties.find(geometry.field); + if (field_it == feature.properties.end()) { + fprintf(stderr, "feature doesn't contain field '%s'\n", geometry.field.c_str()); + return; + } + + field = toString(field_it->second); + } else { + field = ""; + } const Rect rect = sprite_atlas.getIcon(geometry.size, field); const uint16_t tx = rect.x + rect.w / 2; diff --git a/src/shader/icon.fragment.glsl b/src/shader/icon.fragment.glsl index a3191b3a8..52c9e65aa 100644 --- a/src/shader/icon.fragment.glsl +++ b/src/shader/icon.fragment.glsl @@ -7,5 +7,5 @@ varying vec2 v_tex; void main() { vec2 pos = (v_tex + (gl_PointCoord - 0.5) * u_size) / u_dimension; - gl_FragColor = texture2D(u_image, pos); + gl_FragColor = u_color * texture2D(u_image, pos); } diff --git a/src/shader/shaders_gl.cpp b/src/shader/shaders_gl.cpp index 29cbc0ead..5c5532eb5 100644 --- a/src/shader/shaders_gl.cpp +++ b/src/shader/shaders_gl.cpp @@ -12,7 +12,7 @@ const shader_source llmr::shaders[SHADER_COUNT] = { }, { "#version 120\nattribute vec2 a_pos;\nattribute vec2 a_tex;\nuniform mat4 u_matrix;\nuniform float u_size;\nuniform float u_ratio;\nvarying vec2 v_tex;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n v_tex = (a_tex * u_ratio);\n}\n\n", - "#version 120\nuniform sampler2D u_image;\nuniform vec2 u_dimension;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n gl_FragColor = texture2D (u_image, ((v_tex + (\n (gl_PointCoord - 0.5)\n * u_size)) / u_dimension));\n}\n\n", + "#version 120\nuniform sampler2D u_image;\nuniform vec2 u_dimension;\nuniform vec4 u_color;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n gl_FragColor = (u_color * texture2D (u_image, ((v_tex + \n ((gl_PointCoord - 0.5) * u_size)\n ) / u_dimension)));\n}\n\n", }, { "#version 120\nattribute vec2 a_pos;\nattribute vec2 a_extrude;\nattribute float a_linesofar;\nuniform mat4 u_matrix;\nuniform mat4 u_exmatrix;\nuniform float u_ratio;\nuniform vec2 u_linewidth;\nvarying vec2 v_normal;\nvarying float v_linesofar;\nvoid main ()\n{\n vec2 normal_1;\n vec2 tmpvar_2;\n tmpvar_2 = (vec2(mod (a_pos, 2.0)));\n normal_1.x = tmpvar_2.x;\n normal_1.y = sign((tmpvar_2.y - 0.5));\n v_normal = normal_1;\n vec4 tmpvar_3;\n tmpvar_3.zw = vec2(0.0, 0.0);\n tmpvar_3.xy = ((u_linewidth.x * a_extrude) * 0.015873);\n vec4 tmpvar_4;\n tmpvar_4.zw = vec2(0.0, 1.0);\n tmpvar_4.xy = floor((a_pos * 0.5));\n gl_Position = ((u_matrix * tmpvar_4) + (u_exmatrix * tmpvar_3));\n v_linesofar = (a_linesofar * u_ratio);\n}\n\n", diff --git a/src/shader/shaders_gles2.cpp b/src/shader/shaders_gles2.cpp index f19edf540..ac90eff85 100644 --- a/src/shader/shaders_gles2.cpp +++ b/src/shader/shaders_gles2.cpp @@ -12,7 +12,7 @@ const shader_source llmr::shaders[SHADER_COUNT] = { }, { "precision highp float;\nattribute vec2 a_pos;\nattribute vec2 a_tex;\nuniform mat4 u_matrix;\nuniform float u_size;\nuniform float u_ratio;\nvarying vec2 v_tex;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n v_tex = (a_tex * u_ratio);\n}\n\n", - "precision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_dimension;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n mediump vec2 tmpvar_1;\n tmpvar_1 = ((v_tex + (\n (gl_PointCoord - 0.5)\n * u_size)) / u_dimension);\n lowp vec4 tmpvar_2;\n tmpvar_2 = texture2D (u_image, tmpvar_1);\n gl_FragColor = tmpvar_2;\n}\n\n", + "precision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_dimension;\nuniform vec4 u_color;\nuniform float u_size;\nvarying vec2 v_tex;\nvoid main ()\n{\n mediump vec2 tmpvar_1;\n tmpvar_1 = ((v_tex + (\n (gl_PointCoord - 0.5)\n * u_size)) / u_dimension);\n lowp vec4 tmpvar_2;\n tmpvar_2 = (u_color * texture2D (u_image, tmpvar_1));\n gl_FragColor = tmpvar_2;\n}\n\n", }, { "precision highp float;\nattribute vec2 a_pos;\nattribute vec2 a_extrude;\nattribute float a_linesofar;\nuniform mat4 u_matrix;\nuniform mat4 u_exmatrix;\nuniform float u_ratio;\nuniform vec2 u_linewidth;\nvarying vec2 v_normal;\nvarying float v_linesofar;\nvoid main ()\n{\n vec2 normal_1;\n vec2 tmpvar_2;\n tmpvar_2 = (vec2(mod (a_pos, 2.0)));\n normal_1.x = tmpvar_2.x;\n normal_1.y = sign((tmpvar_2.y - 0.5));\n v_normal = normal_1;\n vec4 tmpvar_3;\n tmpvar_3.zw = vec2(0.0, 0.0);\n tmpvar_3.xy = ((u_linewidth.x * a_extrude) * 0.015873);\n vec4 tmpvar_4;\n tmpvar_4.zw = vec2(0.0, 1.0);\n tmpvar_4.xy = floor((a_pos * 0.5));\n gl_Position = ((u_matrix * tmpvar_4) + (u_exmatrix * tmpvar_3));\n v_linesofar = (a_linesofar * u_ratio);\n}\n\n",