Skip to content

Commit

Permalink
Pack texture and layout data into single attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Mar 28, 2017
1 parent 2810146 commit 2d3b36a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
19 changes: 11 additions & 8 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const ArrayGroup = require('../array_group');
const BufferGroup = require('../buffer_group');
const createElementArrayType = require('../element_array_type');
const EXTENT = require('../extent');
const packUint8ToFloat = require('../../shaders/encode_attribute').packUint8ToFloat;
const Anchor = require('../../symbol/anchor');
const getAnchors = require('../../symbol/get_anchors');
const resolveTokens = require('../../util/token');
Expand Down Expand Up @@ -32,8 +33,7 @@ const elementArrayType = createElementArrayType();

const layoutAttributes = [
{name: 'a_pos_offset', components: 4, type: 'Int16'},
{name: 'a_texture_pos', components: 2, type: 'Uint16'},
{name: 'a_data', components: 4, type: 'Uint8'}
{name: 'a_data', components: 4, type: 'Uint16'}
];

const symbolInterfaces = {
Expand Down Expand Up @@ -77,15 +77,18 @@ function addVertex(array, x, y, ox, oy, tx, ty, sizeData, minzoom, maxzoom, labe
Math.round(ox * 64),
Math.round(oy * 64),

// a_texture_pos
// a_data
tx / 4, // x coordinate of symbol on glyph atlas texture
ty / 4, // y coordinate of symbol on glyph atlas texture
packUint8ToFloat(
(labelminzoom || 0) * 10, // labelminzoom
labelangle // labelangle
),
packUint8ToFloat(
(minzoom || 0) * 10, // minzoom
Math.min(maxzoom || 25, 25) * 10 // maxzoom
),

// a_data
(labelminzoom || 0) * 10, // labelminzoom
labelangle, // labelangle
(minzoom || 0) * 10, // minzoom
Math.min(maxzoom || 25, 25) * 10, // maxzoom
// a_size
sizeData ? sizeData[0] : undefined,
sizeData ? sizeData[1] : undefined,
Expand Down
8 changes: 4 additions & 4 deletions src/shaders/symbol_icon.vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

attribute vec4 a_pos_offset;
attribute vec2 a_texture_pos;
attribute vec4 a_data;

// icon-size data (see symbol_sdf.vertex.glsl for more)
Expand Down Expand Up @@ -32,9 +31,10 @@ 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];

Expand Down
12 changes: 6 additions & 6 deletions src/shaders/symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const float PI = 3.141592653589793;

attribute vec4 a_pos_offset;
attribute vec2 a_texture_pos;
attribute vec4 a_data;

// contents of a_size vary based on the type of property value
Expand Down Expand Up @@ -54,9 +53,10 @@ 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];

Expand Down Expand Up @@ -93,7 +93,7 @@ void main() {
// pitch-alignment: map
// rotation-alignment: map | viewport
if (u_pitch_with_map) {
lowp float angle = u_rotate_with_map ? (a_data[1] / 256.0 * 2.0 * PI) : u_bearing;
lowp float angle = u_rotate_with_map ? (label_data[1] / 256.0 * 2.0 * PI) : u_bearing;
lowp float asin = sin(angle);
lowp float acos = cos(angle);
mat2 RotationMatrix = mat2(acos, asin, -1.0 * asin, acos);
Expand All @@ -109,7 +109,7 @@ void main() {
// it goes from 0% foreshortening to up to around 70% foreshortening
lowp float pitchfactor = 1.0 - cos(u_pitch * sin(u_pitch * 0.75));

lowp float lineangle = a_data[1] / 256.0 * 2.0 * PI;
lowp float lineangle = label_data[1] / 256.0 * 2.0 * PI;

// use the lineangle to position points a,b along the line
// project the points and calculate the label angle in projected space
Expand Down

0 comments on commit 2d3b36a

Please sign in to comment.