Skip to content

Commit

Permalink
Don't use mod for unpacking flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Nov 15, 2019
1 parent a89e072 commit 992357a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 37 deletions.
8 changes: 3 additions & 5 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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
);
}
Expand Down
15 changes: 4 additions & 11 deletions src/shaders/symbol_icon.vertex.glsl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 3 additions & 10 deletions src/shaders/symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 5 additions & 10 deletions src/shaders/symbol_text_and_icon.vertex.glsl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/symbol/symbol_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 992357a

Please sign in to comment.