Merge branch 'master' into symbols

Conflicts:
	src/renderer/painter_text.cpp
This commit is contained in:
Konstantin Käfer
2014-08-06 15:32:48 +02:00
8 changed files with 37 additions and 16 deletions

View File

@@ -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)

View File

@@ -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<std::shared_ptr<util::transition>> transitions;
std::shared_ptr<util::transition> scale_timeout;

View File

@@ -16,6 +16,7 @@ public:
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);
private:
@@ -37,6 +38,9 @@ private:
std::array<float, 2> dasharray = {{}};
int32_t u_dasharray = -1;
float blur = 0.0f;
int32_t u_blur = -1;
};

View File

@@ -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 {

View File

@@ -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);

View File

@@ -14,11 +14,13 @@ void Painter::renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> 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<StyleLayer> 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);
}

View File

@@ -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;
}
}

View File

@@ -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<float, 2>& new_dasharray) {
dasharray = new_dasharray;
}
}
void LineShader::setBlur(float new_blur) {
if (blur != new_blur) {
glUniform1f(u_blur, new_blur);
blur = new_blur;
}
}