summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders/symbol_icon.cpp
diff options
context:
space:
mode:
authorAnand Thakker <anandthakker@users.noreply.github.com>2017-04-06 15:29:59 -0400
committerGitHub <noreply@github.com>2017-04-06 15:29:59 -0400
commit693c9f3641b3189b4cd439049904c95a516ae609 (patch)
tree8341a16f57ff184a2fe9e085c490e8762eb206ce /src/mbgl/shaders/symbol_icon.cpp
parentf9cc044357d60dd5cf15ba951384529f88802089 (diff)
downloadqtlocation-mapboxgl-693c9f3641b3189b4cd439049904c95a516ae609.tar.gz
[core] Add DDS support for {text,icon}-size (#8593)
* Update gl-js and generate style code * Factor out packUint8Pair() helper function * Draft implementation of DDS for {text,icon}-size Ports https://github.com/mapbox/mapbox-gl-js/pull/4455 * Fix text-size/composite-function-line-placement test * Refactor to PaintPropertyBinders-like strategy * Dedupe gl::Program construction * Use exponential function base for interpolation * Dedupe coveringZoomStops method * Fixup tests * Fix CI errors (hidden within #if block)
Diffstat (limited to 'src/mbgl/shaders/symbol_icon.cpp')
-rw-r--r--src/mbgl/shaders/symbol_icon.cpp51
1 files changed, 44 insertions, 7 deletions
diff --git a/src/mbgl/shaders/symbol_icon.cpp b/src/mbgl/shaders/symbol_icon.cpp
index 9adda0ba16..b6fbed428e 100644
--- a/src/mbgl/shaders/symbol_icon.cpp
+++ b/src/mbgl/shaders/symbol_icon.cpp
@@ -9,9 +9,16 @@ const char* symbol_icon::name = "symbol_icon";
const char* symbol_icon::vertexSource = R"MBGL_SHADER(
attribute vec4 a_pos_offset;
-attribute vec2 a_texture_pos;
attribute vec4 a_data;
+// icon-size data (see symbol_sdf.vertex.glsl for more)
+attribute vec3 a_size;
+uniform bool u_is_size_zoom_constant;
+uniform bool u_is_size_feature_constant;
+uniform mediump float u_size_t; // used to interpolate between zoom stops when size is a composite function
+uniform mediump float u_size; // used when size is both zoom and feature constant
+uniform mediump float u_layout_size; // used when size is feature constant
+
uniform lowp float a_opacity_t;
attribute lowp vec2 a_opacity;
varying lowp float opacity;
@@ -19,6 +26,7 @@ varying lowp float opacity;
// matrix is for the vertex position.
uniform mat4 u_matrix;
+uniform bool u_is_text;
uniform mediump float u_zoom;
uniform bool u_rotate_with_map;
uniform vec2 u_extrude_scale;
@@ -34,16 +42,45 @@ void main() {
vec2 a_pos = a_pos_offset.xy;
vec2 a_offset = a_pos_offset.zw;
- vec2 a_tex = a_texture_pos.xy;
- mediump float a_labelminzoom = a_data[0];
- mediump vec2 a_zoom = a_data.pq;
+ vec2 a_tex = a_data.xy;
+ mediump vec2 label_data = unpack_float(a_data[2]);
+ mediump float a_labelminzoom = label_data[0];
+ mediump vec2 a_zoom = unpack_float(a_data[3]);
mediump float a_minzoom = a_zoom[0];
mediump float a_maxzoom = a_zoom[1];
- // u_zoom is the current zoom level adjusted for the change in font size
- mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom));
+ float size;
+ // In order to accommodate placing labels around corners in
+ // symbol-placement: line, each glyph in a label could have multiple
+ // "quad"s only one of which should be shown at a given zoom level.
+ // The min/max zoom assigned to each quad is based on the font size at
+ // the vector tile's zoom level, which might be different than at the
+ // currently rendered zoom level if text-size is zoom-dependent.
+ // Thus, we compensate for this difference by calculating an adjustment
+ // based on the scale of rendered text size relative to layout text size.
+ mediump float layoutSize;
+ if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
+ size = mix(a_size[0], a_size[1], u_size_t) / 10.0;
+ layoutSize = a_size[2] / 10.0;
+ } else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
+ size = a_size[0] / 10.0;
+ layoutSize = size;
+ } else if (!u_is_size_zoom_constant && u_is_size_feature_constant) {
+ size = u_size;
+ layoutSize = u_layout_size;
+ } else {
+ size = u_size;
+ layoutSize = u_size;
+ }
+
+ float fontScale = u_is_text ? size / 24.0 : size;
+
+ mediump float zoomAdjust = log2(size / layoutSize);
+ mediump float adjustedZoom = (u_zoom - zoomAdjust) * 10.0;
+ // result: z = 0 if a_minzoom <= adjustedZoom < a_maxzoom, and 1 otherwise
+ mediump float z = 2.0 - step(a_minzoom, adjustedZoom) - (1.0 - step(a_maxzoom, adjustedZoom));
- vec2 extrude = u_extrude_scale * (a_offset / 64.0);
+ vec2 extrude = fontScale * u_extrude_scale * (a_offset / 64.0);
if (u_rotate_with_map) {
gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1);
gl_Position.z += z * gl_Position.w;