From 992357afa7a75d1d6d844189bb06ea425334d3c3 Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Thu, 14 Nov 2019 23:26:01 +0200 Subject: [PATCH] Don't use mod for unpacking flag --- src/data/bucket/symbol_bucket.js | 8 +++----- src/shaders/symbol_icon.vertex.glsl | 15 ++++----------- src/shaders/symbol_sdf.vertex.glsl | 13 +++---------- src/shaders/symbol_text_and_icon.vertex.glsl | 15 +++++---------- src/symbol/symbol_layout.js | 2 +- 5 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/data/bucket/symbol_bucket.js b/src/data/bucket/symbol_bucket.js index 6bb310aa014..925e8e70499 100644 --- a/src/data/bucket/symbol_bucket.js +++ b/src/data/bucket/symbol_bucket.js @@ -32,8 +32,8 @@ import mvt from '@mapbox/vector-tile'; const vectorTileFeatureTypes = mvt.VectorTileFeature.types; import {verticalizedCharacterMap} from '../../util/verticalize_punctuation'; import Anchor from '../../symbol/anchor'; -import {SIZE_PACK_FACTOR, getSizeData} from '../../symbol/symbol_size'; -import {MAX_GLYPH_ICON_SIZE, MAX_PACKED_SIZE} from '../../symbol/symbol_layout'; +import {getSizeData} from '../../symbol/symbol_size'; +import {MAX_PACKED_SIZE} from '../../symbol/symbol_layout'; import {register} from '../../util/web_worker_transfer'; import EvaluationParameters from '../../style/evaluation_parameters'; import Formatted from '../../style-spec/expression/types/formatted'; @@ -102,8 +102,6 @@ const shaderOpacityAttributes = [ {name: 'a_fade_opacity', components: 1, type: 'Uint8', offset: 0} ]; -const SDF_FLAG = (MAX_GLYPH_ICON_SIZE + 1) * SIZE_PACK_FACTOR; - function addVertex(array, anchorX, anchorY, ox, oy, tx, ty, sizeVertex, isSDF: boolean) { const aSizeX = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[0])) : 0; const aSizeY = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[1])) : 0; @@ -117,7 +115,7 @@ function addVertex(array, anchorX, anchorY, ox, oy, tx, ty, sizeVertex, isSDF: b // a_data tx, // x coordinate of symbol on glyph atlas texture ty, // y coordinate of symbol on glyph atlas texture - isSDF ? aSizeX | SDF_FLAG : aSizeX, + (aSizeX << 1) + (isSDF ? 1 : 0), aSizeY ); } diff --git a/src/shaders/symbol_icon.vertex.glsl b/src/shaders/symbol_icon.vertex.glsl index 3370815b1fd..056ce24e4d2 100644 --- a/src/shaders/symbol_icon.vertex.glsl +++ b/src/shaders/symbol_icon.vertex.glsl @@ -1,8 +1,5 @@ const float PI = 3.141592653589793; -// Should be same as SDF_FLAG used when vertex is added. -const float SDF_FLAG = 256.0 * 128.0; - attribute vec4 a_pos_offset; attribute vec4 a_data; attribute vec3 a_projected_pos; @@ -41,18 +38,14 @@ void main() { vec2 a_tex = a_data.xy; vec2 a_size = a_data.zw; - bool is_sdf = mod(a_size[0], 2.0 * SDF_FLAG) >= SDF_FLAG; - if (is_sdf) { - a_size[0] -= SDF_FLAG; - } - + float a_size_min = floor(a_size[0] * 0.5); highp float segment_angle = -a_projected_pos[2]; - float size; + if (!u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = mix(a_size[0], a_size[1], u_size_t) / 128.0; + size = mix(a_size_min, a_size[1], u_size_t) / 128.0; } else if (u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = a_size[0] / 128.0; + size = a_size_min / 128.0; } else { size = u_size; } diff --git a/src/shaders/symbol_sdf.vertex.glsl b/src/shaders/symbol_sdf.vertex.glsl index 57236845f6b..6c9ef11f833 100644 --- a/src/shaders/symbol_sdf.vertex.glsl +++ b/src/shaders/symbol_sdf.vertex.glsl @@ -1,8 +1,5 @@ const float PI = 3.141592653589793; -// Should be same as SDF_FLAG used when vertex is added. -const float SDF_FLAG = 256.0 * 128.0; - attribute vec4 a_pos_offset; attribute vec4 a_data; attribute vec3 a_projected_pos; @@ -53,18 +50,14 @@ void main() { vec2 a_tex = a_data.xy; vec2 a_size = a_data.zw; - bool is_sdf = mod(a_size[0], 2.0 * SDF_FLAG) >= SDF_FLAG; - if (is_sdf) { - a_size[0] -= SDF_FLAG; - } - + float a_size_min = floor(a_size[0] * 0.5); highp float segment_angle = -a_projected_pos[2]; float size; if (!u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = mix(a_size[0], a_size[1], u_size_t) / 128.0; + size = mix(a_size_min, a_size[1], u_size_t) / 128.0; } else if (u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = a_size[0] / 128.0; + size = a_size_min / 128.0; } else { size = u_size; } diff --git a/src/shaders/symbol_text_and_icon.vertex.glsl b/src/shaders/symbol_text_and_icon.vertex.glsl index 47027e05f57..9abcff39200 100644 --- a/src/shaders/symbol_text_and_icon.vertex.glsl +++ b/src/shaders/symbol_text_and_icon.vertex.glsl @@ -1,8 +1,5 @@ const float PI = 3.141592653589793; -// Should be same as SDF_FLAG used when vertex is added. -const float SDF_FLAG = 256.0 * 128.0; - attribute vec4 a_pos_offset; attribute vec4 a_data; attribute vec3 a_projected_pos; @@ -53,18 +50,16 @@ void main() { vec2 a_tex = a_data.xy; vec2 a_size = a_data.zw; - bool is_sdf = mod(a_size[0], 2.0 * SDF_FLAG) >= SDF_FLAG; - if (is_sdf) { - a_size[0] -= SDF_FLAG; - } + float a_size_min = floor(a_size[0] * 0.5); + float is_sdf = a_size[0] - 2.0 * a_size_min; highp float segment_angle = -a_projected_pos[2]; float size; if (!u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = mix(a_size[0], a_size[1], u_size_t) / 128.0; + size = mix(a_size_min, a_size[1], u_size_t) / 128.0; } else if (u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = a_size[0] / 128.0; + size = a_size_min / 128.0; } else { size = u_size; } @@ -116,5 +111,5 @@ void main() { v_data0.xy = a_tex / u_texsize; v_data0.zw = a_tex / u_texsize_icon; - v_data1 = vec4(gamma_scale, size, interpolated_fade_opacity, float(is_sdf)); + v_data1 = vec4(gamma_scale, size, interpolated_fade_opacity, is_sdf); } diff --git a/src/symbol/symbol_layout.js b/src/symbol/symbol_layout.js index e841b1f34d7..5c0dcd9ffae 100644 --- a/src/symbol/symbol_layout.js +++ b/src/symbol/symbol_layout.js @@ -467,7 +467,7 @@ function addFeature(bucket: SymbolBucket, const MAX_GLYPH_ICON_SIZE = 255; const MAX_PACKED_SIZE = MAX_GLYPH_ICON_SIZE * SIZE_PACK_FACTOR; -export {MAX_GLYPH_ICON_SIZE, MAX_PACKED_SIZE}; +export {MAX_PACKED_SIZE}; function addTextVertices(bucket: SymbolBucket, anchor: Point,