diff --git a/Makefile b/Makefile index bfb550aff..fb1c5b3ec 100644 --- a/Makefile +++ b/Makefile @@ -78,8 +78,10 @@ xproj: config.gypi macosx/mapboxgl-app.gyp clear_xcode_cache node open ./build/macosx/mapboxgl-app.xcodeproj # build iOS project for Xcode -iproj: config.gypi ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp clear_xcode_cache node +iproj-cli: config.gypi ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp clear_xcode_cache node deps/run_gyp ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp --depth=. --generator-output=./build -f xcode + +iproj: iproj-cli open ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj # build Linux project for Xcode (Runs on Mac OS X too, but without platform-specific code) diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp index 359c325f1..df7839ea9 100644 --- a/include/mbgl/map/transform.hpp +++ b/include/mbgl/map/transform.hpp @@ -96,7 +96,7 @@ private: const double max_scale = std::pow(2, 18); // cache values for spherical mercator math - double zc, Bc, Cc; + double Bc, Cc; std::forward_list> transitions; std::shared_ptr scale_timeout; diff --git a/include/mbgl/shader/line_shader.hpp b/include/mbgl/shader/line_shader.hpp index 38efe0b71..c476b5c4c 100644 --- a/include/mbgl/shader/line_shader.hpp +++ b/include/mbgl/shader/line_shader.hpp @@ -16,6 +16,7 @@ public: void setLineWidth(const std::array& linewidth); void setRatio(float ratio); void setDashArray(const std::array& dasharray); + void setBlur(float blur); void setDebug(float debug); private: @@ -37,6 +38,9 @@ private: std::array dasharray = {{}}; int32_t u_dasharray = -1; + + float blur = 0.0f; + int32_t u_blur = -1; }; diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp index f36da83e4..a11d9b19c 100644 --- a/include/mbgl/util/uv.hpp +++ b/include/mbgl/util/uv.hpp @@ -21,13 +21,18 @@ namespace uv { class loop { public: - inline loop() : l(uv_loop_new()) {} - inline ~loop() { uv_loop_delete(l); } + inline loop() { + if (uv_loop_init(&l) != 0) { + throw std::runtime_error("failed to initialize loop"); + } + } - inline uv_loop_t *operator*() { return l; } + inline ~loop() { uv_loop_close(&l); } + + inline uv_loop_t *operator*() { return &l; } private: - uv_loop_t *l; + uv_loop_t l; }; class mutex { diff --git a/src/map/transform.cpp b/src/map/transform.cpp index 251af30f9..6338df6a4 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -98,8 +98,8 @@ void Transform::setLonLat(const double lon, const double lat, const timestamp du uv::writelock lock(mtx); const double f = std::fmin(std::fmax(std::sin(D2R * lat), -0.9999), 0.9999); - double xn = -std::round(lon * Bc); - double yn = std::round(0.5 * Cc * std::log((1 + f) / (1 - f))); + double xn = -lon * Bc; + double yn = 0.5 * Cc * std::log((1 + f) / (1 - f)); _setScaleXY(current.scale, xn, yn, duration); } @@ -111,13 +111,12 @@ void Transform::setLonLatZoom(const double lon, const double lat, const double z double new_scale = std::pow(2.0, zoom); const double s = new_scale * util::tileSize; - zc = s / 2; Bc = s / 360; Cc = s / (2 * M_PI); const double f = std::fmin(std::fmax(std::sin(D2R * lat), -0.9999), 0.9999); - double xn = -std::round(lon * Bc); - double yn = std::round(0.5 * Cc * log((1 + f) / (1 - f))); + double xn = -lon * Bc; + double yn = 0.5 * Cc * log((1 + f) / (1 - f)); _setScaleXY(new_scale, xn, yn, duration); } @@ -309,7 +308,6 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl } const double s = final.scale * util::tileSize; - zc = s / 2; Bc = s / 360; Cc = s / (2 * M_PI); diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index 00b3a4847..dc09f5895 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -14,11 +14,13 @@ void Painter::renderLine(LineBucket& bucket, std::shared_ptr layer_d float width = properties.width; float offset = properties.offset / 2; + float antialiasing = 1 / map.getState().getPixelRatio(); + float blur = properties.blur + antialiasing; // These are the radii of the line. We are limiting it to 16, which will result // in a point size of 64 on retina. - float inset = std::fmin((std::fmax(-1, offset - width / 2 - 0.5) + 1), 16.0f); - float outset = std::fmin(offset + width / 2 + 0.5, 16.0f); + float inset = std::fmin((std::fmax(-1, offset - width / 2 - antialiasing / 2) + 1), 16.0f); + float outset = std::fmin(offset + width / 2 + antialiasing / 2, 16.0f); Color color = properties.color; color[0] *= properties.opacity; @@ -80,6 +82,7 @@ void Painter::renderLine(LineBucket& bucket, std::shared_ptr layer_d lineShader->setDashArray({{ dash_length, dash_gap }}); lineShader->setLineWidth({{ outset, inset }}); lineShader->setRatio(map.getState().getPixelRatio()); + lineShader->setBlur(blur); lineShader->setColor(color); bucket.drawLines(*lineShader); } diff --git a/src/shader/line.fragment.glsl b/src/shader/line.fragment.glsl index ca8fed9bb..f4ac1458b 100644 --- a/src/shader/line.fragment.glsl +++ b/src/shader/line.fragment.glsl @@ -1,5 +1,6 @@ uniform vec2 u_linewidth; uniform vec4 u_color; +uniform float u_blur; uniform vec2 u_dasharray; @@ -13,7 +14,7 @@ void main() { // Calculate the antialiasing fade factor. This is either when fading in // the line in case of an offset line (v_linewidth.t) or when fading out // (v_linewidth.s) - float alpha = clamp(min(dist - (u_linewidth.t - 1.0), u_linewidth.s - dist), 0.0, 1.0); + float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); // Calculate the antialiasing fade factor based on distance to the dash. // Only affects alpha when line is dashed @@ -21,4 +22,4 @@ void main() { alpha *= max(step(0.0, -u_dasharray.y), clamp(min(pos, u_dasharray.x - pos), 0.0, 1.0)); gl_FragColor = u_color * alpha; -} \ No newline at end of file +} diff --git a/src/shader/line_shader.cpp b/src/shader/line_shader.cpp index 133008989..529ab0d31 100644 --- a/src/shader/line_shader.cpp +++ b/src/shader/line_shader.cpp @@ -26,6 +26,7 @@ LineShader::LineShader() u_color = glGetUniformLocation(program, "u_color"); u_ratio = glGetUniformLocation(program, "u_ratio"); u_dasharray = glGetUniformLocation(program, "u_dasharray"); + u_blur = glGetUniformLocation(program, "u_blur"); // fprintf(stderr, "LineShader:\n"); // fprintf(stderr, " - u_matrix: %d\n", u_matrix); @@ -81,3 +82,10 @@ void LineShader::setDashArray(const std::array& new_dasharray) { dasharray = new_dasharray; } } + +void LineShader::setBlur(float new_blur) { + if (blur != new_blur) { + glUniform1f(u_blur, new_blur); + blur = new_blur; + } +}