summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-07-14 18:25:07 -0700
committerKonstantin Käfer <mail@kkaefer.com>2014-07-14 18:25:07 -0700
commit471dafc1d1e453efa09f6d0e213ee5f8601cd754 (patch)
treed5c83e6f04074a39d607d7b5613c386ad9b511ae
parent9213f8d8e01c265ede1ca742886fb6e5df1b6677 (diff)
downloadqtlocation-mapboxgl-471dafc1d1e453efa09f6d0e213ee5f8601cd754.tar.gz
change halo-width/blur units
refs mapbox/mapbox-gl-style-spec#66
-rw-r--r--src/renderer/painter_text.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/renderer/painter_text.cpp b/src/renderer/painter_text.cpp
index 233ba25b1f..3d064d9eef 100644
--- a/src/renderer/painter_text.cpp
+++ b/src/renderer/painter_text.cpp
@@ -89,23 +89,37 @@ void Painter::renderText(TextBucket& bucket, std::shared_ptr<StyleLayer> layer_d
textShader->setMaxFadeZoom(std::floor(highZ * 10));
textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10);
- // We're drawing in the translucent pass which is bottom-to-top, so we need
- // to draw the halo first.
- if (properties.halo_color[3] > 0.0f) {
- // TODO: Get rid of the 2.4 magic value. It is currently 24 / 10, with 24 being the font size
- // of the SDF glyphs.
+ // This defines the gamma around the SDF cutoff value.
+ const float sdfGamma = 0.75f / 10.0f;
- // Our signed distance fields are scaled so that 1 pixel is scaled to 32 pixels.
- // Our cutoff between positive and negative values is hard coded to 64 (== 2 pixels).
- // This means that our 6/8 of the value range lies outside the glyph outline.
- const float sdfOffset = (256.0f - 64.0f) / 32.0f;
+ // Our signed distance fields are scaled so that 1 pixel is scaled to 32 pixels.
+ // Our cutoff between positive and negative values is hard coded to 64 (== 2 pixels).
+ // This means that our 6/8 of the value range lies outside the glyph outline.
+ const float sdfOffset = (256.0f - 64.0f) / 32.0f;
- // Currently, all of our fonts are rendered with a font size of 24px.
- const float sdfFontSize = 24.0f;
+ // Currently, all of our fonts are rendered with a font size of 24px.
+ const float sdfFontSize = 24.0f;
+ // The default gamma value has to be adjust for the current pixelratio so that we're not drawing
+ // blurry font on retina screens.
+ const float gamma = sdfGamma * sdfFontSize / fontSize / map.getState().getPixelRatio();
+
+ // We're drawing in the translucent pass which is bottom-to-top, so we need
+ // to draw the halo first.
+ if (properties.halo_color[3] > 0.0f) {
const float haloWidth = util::clamp((sdfOffset - properties.halo_width / (fontSize / sdfFontSize)) / 8.0f, 0.0f, 1.0f);
- textShader->setGamma(properties.halo_blur * 2.4f / fontSize / map.getState().getPixelRatio());
+ if (properties.halo_blur != 0.0f) {
+ // We are converting the halo_blur value to current screen pixels.
+ // Then we're dividing it by two because the gamma value is added/subtracted into both
+ // directions in the shader, but the halo_blur describes the entire width of the blur.
+ // Note that this does *not* have to be adjusted for retina screens, because we want the
+ // same blur width when we explicitly specify one.
+ textShader->setGamma((properties.halo_blur / (fontSize / sdfFontSize)) / 8.0f / 2.0f);
+ } else {
+ textShader->setGamma(sdfGamma);
+ }
+
if (properties.opacity < 1.0f) {
Color color = properties.halo_color;
color[0] *= properties.opacity;
@@ -123,9 +137,7 @@ void Painter::renderText(TextBucket& bucket, std::shared_ptr<StyleLayer> layer_d
if (properties.color[3] > 0.0f) {
// Then, we draw the text over the halo
- // TODO: Get rid of the 2.4 magic value. It is currently 24 / 10, with 24 being the font size
- // of the SDF glyphs.
- textShader->setGamma(2.4f / fontSize / map.getState().getPixelRatio());
+ textShader->setGamma(gamma);
if (properties.opacity < 1.0f) {
Color color = properties.color;
color[0] *= properties.opacity;