Skip to content

Commit

Permalink
don't use bit in coordinates for up and round attributes
Browse files Browse the repository at this point in the history
this effectively reverts mapbox/mapbox-gl-js#8306
  • Loading branch information
candux authored and birkskyum committed Jun 1, 2023
1 parent ff65fb3 commit 8915acb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/data/bucket/line_attributes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createLayout} from '../../util/struct_array';

const lineLayoutAttributes = createLayout([
{name: 'a_pos_normal', components: 2, type: 'Int16'},
{name: 'a_pos_normal', components: 4, type: 'Int16'},
{name: 'a_data', components: 4, type: 'Uint8'}
], 4);

Expand Down
6 changes: 4 additions & 2 deletions src/data/bucket/line_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ class LineBucket implements Bucket {
this.layoutVertexArray.emplaceBack(
// a_pos_normal
// Encode round/up the least significant bits
(x << 1) + (round ? 1 : 0),
(y << 1) + (up ? 1 : 0),
x,
y,
round ? 1 : 0,
up ? 1 : -1,
// a_data
// add 128 to store a byte in an unsigned byte
Math.round(EXTRUDE_SCALE * extrudeX) + 128,
Expand Down
8 changes: 3 additions & 5 deletions src/shaders/line.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// #define scale 63.0
#define scale 0.015873016

in vec2 a_pos_normal;
in vec4 a_pos_normal;
in vec4 a_data;

uniform mat4 u_matrix;
Expand Down Expand Up @@ -43,13 +43,11 @@ void main() {

v_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * 2.0;

vec2 pos = floor(a_pos_normal * 0.5);
vec2 pos = a_pos_normal.xy;

// x is 1 if it's a round cap, 0 otherwise
// y is 1 if the normal points up, and -1 if it points down
// We store these in the least significant bit of a_pos_normal
mediump vec2 normal = a_pos_normal - 2.0 * pos;
normal.y = normal.y * 2.0 - 1.0;
mediump vec2 normal = a_pos_normal.zw;
v_normal = normal;

// these transformations used to be applied in the JS and native code bases.
Expand Down
8 changes: 3 additions & 5 deletions src/shaders/line_gradient.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// #define scale 63.0
#define scale 0.015873016

in vec2 a_pos_normal;
in vec4 a_pos_normal;
in vec4 a_data;
in float a_uv_x;
in float a_split_index;
Expand Down Expand Up @@ -46,13 +46,11 @@ void main() {
highp float half_texel_height = 0.5 * texel_height;
v_uv = vec2(a_uv_x, a_split_index * texel_height - half_texel_height);

vec2 pos = floor(a_pos_normal * 0.5);
vec2 pos = a_pos_normal.xy;

// x is 1 if it's a round cap, 0 otherwise
// y is 1 if the normal points up, and -1 if it points down
// We store these in the least significant bit of a_pos_normal
mediump vec2 normal = a_pos_normal - 2.0 * pos;
normal.y = normal.y * 2.0 - 1.0;
mediump vec2 normal = a_pos_normal.zw;
v_normal = normal;

// these transformations used to be applied in the JS and native code bases.
Expand Down
8 changes: 3 additions & 5 deletions src/shaders/line_pattern.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// long distances for long segments. Use this value to unscale the distance.
#define LINE_DISTANCE_SCALE 2.0

in vec2 a_pos_normal;
in vec4 a_pos_normal;
in vec4 a_data;

uniform mat4 u_matrix;
Expand Down Expand Up @@ -55,13 +55,11 @@ void main() {
float a_direction = mod(a_data.z, 4.0) - 1.0;
float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE;
// float tileRatio = u_scale.x;
vec2 pos = floor(a_pos_normal * 0.5);
vec2 pos = a_pos_normal.xy;

// x is 1 if it's a round cap, 0 otherwise
// y is 1 if the normal points up, and -1 if it points down
// We store these in the least significant bit of a_pos_normal
mediump vec2 normal = a_pos_normal - 2.0 * pos;
normal.y = normal.y * 2.0 - 1.0;
mediump vec2 normal = a_pos_normal.zw;
v_normal = normal;

// these transformations used to be applied in the JS and native code bases.
Expand Down
8 changes: 3 additions & 5 deletions src/shaders/line_sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// long distances for long segments. Use this value to unscale the distance.
#define LINE_DISTANCE_SCALE 2.0

in vec2 a_pos_normal;
in vec4 a_pos_normal;
in vec4 a_data;

uniform mat4 u_matrix;
Expand Down Expand Up @@ -53,13 +53,11 @@ void main() {
float a_direction = mod(a_data.z, 4.0) - 1.0;
float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE;

vec2 pos = floor(a_pos_normal * 0.5);
vec2 pos = a_pos_normal.xy;

// x is 1 if it's a round cap, 0 otherwise
// y is 1 if the normal points up, and -1 if it points down
// We store these in the least significant bit of a_pos_normal
mediump vec2 normal = a_pos_normal - 2.0 * pos;
normal.y = normal.y * 2.0 - 1.0;
mediump vec2 normal = a_pos_normal.zw;
v_normal = normal;

// these transformations used to be applied in the JS and native code bases.
Expand Down

0 comments on commit 8915acb

Please sign in to comment.