summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2015-01-09 09:30:52 +1100
committerLeith Bade <leith@mapbox.com>2015-01-09 09:30:52 +1100
commit5ed8d4544f2e0cb5f78a6960a6378d7ed4eb7620 (patch)
treeb8d882c4ea4264bce5fcb9557397c37130a4c833 /src
parent3127301976bfa66e2782905100382fe906e721c6 (diff)
parent166a3e21fac8632cdf5afdf4d38bf429e45dc699 (diff)
downloadqtlocation-mapboxgl-5ed8d4544f2e0cb5f78a6960a6378d7ed4eb7620.tar.gz
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/geometry/icon_buffer.cpp16
-rw-r--r--src/mbgl/geometry/icon_buffer.hpp2
-rw-r--r--src/mbgl/geometry/line_buffer.cpp4
-rw-r--r--src/mbgl/geometry/sprite_atlas.cpp37
-rw-r--r--src/mbgl/geometry/sprite_atlas.hpp4
-rw-r--r--src/mbgl/geometry/text_buffer.cpp34
-rw-r--r--src/mbgl/renderer/painter.cpp2
-rw-r--r--src/mbgl/renderer/painter_line.cpp23
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp9
-rw-r--r--src/mbgl/shader/icon.vertex.glsl18
-rw-r--r--src/mbgl/shader/icon_shader.cpp34
-rw-r--r--src/mbgl/shader/icon_shader.hpp9
-rw-r--r--src/mbgl/shader/line.vertex.glsl6
-rw-r--r--src/mbgl/shader/line_shader.cpp10
-rw-r--r--src/mbgl/shader/line_shader.hpp3
-rw-r--r--src/mbgl/shader/linepattern.vertex.glsl11
-rw-r--r--src/mbgl/shader/linepattern_shader.cpp11
-rw-r--r--src/mbgl/shader/linepattern_shader.hpp3
-rw-r--r--src/mbgl/shader/sdf.vertex.glsl18
-rw-r--r--src/mbgl/shader/sdf_shader.cpp57
-rw-r--r--src/mbgl/shader/sdf_shader.hpp9
21 files changed, 144 insertions, 176 deletions
diff --git a/src/mbgl/geometry/icon_buffer.cpp b/src/mbgl/geometry/icon_buffer.cpp
index c571dfa69e..5e7b76fde2 100644
--- a/src/mbgl/geometry/icon_buffer.cpp
+++ b/src/mbgl/geometry/icon_buffer.cpp
@@ -19,15 +19,17 @@ size_t IconVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, int16_t t
shorts[3] /* offset */ = std::round(oy * 64);
uint8_t *ubytes = static_cast<uint8_t *>(data);
- ubytes[8] /* labelminzoom */ = labelminzoom * 10;
- ubytes[9] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160.
- ubytes[10] /* maxzoom */ = std::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
+ // a_data1
+ ubytes[8] /* tex */ = tx / 4;
+ ubytes[9] /* tex */ = ty / 4;
+ ubytes[10] /* labelminzoom */ = labelminzoom * 10;
ubytes[11] /* angle */ = (int16_t)std::round(angle * angleFactor) % 256;
- ubytes[12] /* rangeend */ = util::max((int16_t)std::round(range[0] * angleFactor), (int16_t)0) % 256;
- ubytes[13] /* rangestart */ = util::min((int16_t)std::round(range[1] * angleFactor), (int16_t)255) % 256;
- shorts[8] /* tex */ = tx;
- shorts[9] /* tex */ = ty;
+ // a_data2
+ ubytes[12] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160.
+ ubytes[13] /* maxzoom */ = std::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
+ ubytes[14] /* rangeend */ = util::max((int16_t)std::round(range[0] * angleFactor), (int16_t)0) % 256;
+ ubytes[15] /* rangestart */ = util::min((int16_t)std::round(range[1] * angleFactor), (int16_t)255) % 256;
return idx;
}
diff --git a/src/mbgl/geometry/icon_buffer.hpp b/src/mbgl/geometry/icon_buffer.hpp
index 08c9687004..90ce19b1ed 100644
--- a/src/mbgl/geometry/icon_buffer.hpp
+++ b/src/mbgl/geometry/icon_buffer.hpp
@@ -8,7 +8,7 @@
namespace mbgl {
class IconVertexBuffer : public Buffer<
- 20
+ 16
> {
public:
static const double angleFactor;
diff --git a/src/mbgl/geometry/line_buffer.cpp b/src/mbgl/geometry/line_buffer.cpp
index 50a6e66b93..7704838483 100644
--- a/src/mbgl/geometry/line_buffer.cpp
+++ b/src/mbgl/geometry/line_buffer.cpp
@@ -16,8 +16,8 @@ size_t LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, i
int8_t *extrude = static_cast<int8_t *>(data);
extrude[4] = std::round(extrudeScale * ex);
extrude[5] = std::round(extrudeScale * ey);
-
- coords[3] = linesofar;
+ extrude[6] = static_cast<int8_t>(linesofar / 128);
+ extrude[7] = static_cast<int8_t>(linesofar % 128);
return idx;
}
diff --git a/src/mbgl/geometry/sprite_atlas.cpp b/src/mbgl/geometry/sprite_atlas.cpp
index 0f39de74ba..2d6a8a7835 100644
--- a/src/mbgl/geometry/sprite_atlas.cpp
+++ b/src/mbgl/geometry/sprite_atlas.cpp
@@ -77,18 +77,22 @@ void copy_bitmap(const uint32_t *src, const int src_stride, const int src_x, con
}
}
-Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(size_t pixel_width, size_t pixel_height) {
+Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(const size_t pixel_width, const size_t pixel_height) {
+ // Increase to next number divisible by 4, but at least 1.
+ // This is so we can scale down the texture coordinates and pack them
+ // into 2 bytes rather than 4 bytes.
+ const uint16_t pack_width = pixel_width + (4 - pixel_width % 4);
+ const uint16_t pack_height = pixel_height + (4 - pixel_width % 4);
+
// We have to allocate a new area in the bin, and store an empty image in it.
// Add a 1px border around every image.
- Rect<dimension> rect = bin.allocate(pixel_width + 2 * buffer, pixel_height + 2 * buffer);
+ Rect<dimension> rect = bin.allocate(pack_width, pack_height);
if (rect.w == 0) {
return rect;
}
rect.x += buffer;
rect.y += buffer;
- rect.w -= 2 * buffer;
- rect.h -= 2 * buffer;
return rect;
}
@@ -123,15 +127,24 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::getImage(const std::string& name) {
SpriteAtlasPosition SpriteAtlas::getPosition(const std::string& name, bool repeating) {
std::lock_guard<std::recursive_mutex> lock(mtx);
- // `repeating` indicates that the image will be used in a repeating pattern
- // repeating pattern images are assumed to have a 1px padding that mirrors the opposite edge
- // positions for repeating images are adjusted to exclude the edge
+
Rect<dimension> rect = getImage(name);
- const int r = repeating ? 1 : 0;
+ if (repeating) {
+ // When the image is repeating, get the correct position of the image, rather than the
+ // one rounded up to 4 pixels.
+ const SpritePosition &pos = sprite->getSpritePosition(name);
+ if (!pos.width || !pos.height) {
+ return SpriteAtlasPosition {};
+ }
+
+ rect.w = pos.width / pos.pixelRatio;
+ rect.h = pos.height / pos.pixelRatio;
+ }
+
return SpriteAtlasPosition {
- {{ float(rect.w) / pixelRatio, float(rect.h) / pixelRatio }},
- {{ float(rect.x + r) / width, float(rect.y + r) / height }},
- {{ float(rect.x + rect.w - 2*r) / width, float(rect.y + rect.h - 2*r) / height }}
+ {{ float(rect.w), float(rect.h) }},
+ {{ float(rect.x) / width, float(rect.y) / height }},
+ {{ float(rect.x + rect.w) / width, float(rect.y + rect.h) / height }}
};
}
@@ -249,6 +262,8 @@ void SpriteAtlas::bind(bool linear) {
}
dirty = false;
+
+ // platform::show_color_debug_image("Sprite Atlas", reinterpret_cast<const char *>(data), width, height, width * pixelRatio, height * pixelRatio);
}
};
diff --git a/src/mbgl/geometry/sprite_atlas.hpp b/src/mbgl/geometry/sprite_atlas.hpp
index 9e0fe995bb..ebfd69edf5 100644
--- a/src/mbgl/geometry/sprite_atlas.hpp
+++ b/src/mbgl/geometry/sprite_atlas.hpp
@@ -19,6 +19,10 @@ class Sprite;
class SpritePosition;
struct SpriteAtlasPosition {
+ inline SpriteAtlasPosition(const std::array<float, 2> size_ = {{0, 0}},
+ const std::array<float, 2> tl_ = {{0, 0}},
+ const std::array<float, 2> br_ = {{0, 0}})
+ : size(size_), tl(tl_), br(br_) {}
std::array<float, 2> size;
std::array<float, 2> tl;
std::array<float, 2> br;
diff --git a/src/mbgl/geometry/text_buffer.cpp b/src/mbgl/geometry/text_buffer.cpp
index 295ff02efa..e9bfc503be 100644
--- a/src/mbgl/geometry/text_buffer.cpp
+++ b/src/mbgl/geometry/text_buffer.cpp
@@ -4,30 +4,34 @@
#include <cmath>
-using namespace mbgl;
+namespace mbgl {
const double TextVertexBuffer::angleFactor = 128.0 / M_PI;
size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float angle, float minzoom, std::array<float, 2> range, float maxzoom, float labelminzoom) {
- size_t idx = index();
+ const size_t idx = index();
void *data = addElement();
int16_t *shorts = static_cast<int16_t *>(data);
- shorts[0] = x;
- shorts[1] = y;
- shorts[2] = std::round(ox * 64); // use 1/64 pixels for placement
- shorts[3] = std::round(oy * 64);
+ shorts[0] /* pos */ = x;
+ shorts[1] /* pos */ = y;
+ shorts[2] /* offset */ = std::round(ox * 64); // use 1/64 pixels for placement
+ shorts[3] /* offset */ = std::round(oy * 64);
uint8_t *ubytes = static_cast<uint8_t *>(data);
- ubytes[8] = labelminzoom * 10;
- ubytes[9] = minzoom * 10; // 1/10 zoom levels: z16 == 160.
- ubytes[10] = fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
- ubytes[11] = (int16_t)round(angle * angleFactor) % 256;
- ubytes[12] = util::max((int16_t)std::round(range[0] * angleFactor), (int16_t)0) % 256;
- ubytes[13] = util::min((int16_t)std::round(range[1] * angleFactor), (int16_t)255) % 256;
-
- ubytes[14] = tx / 4;
- ubytes[15] = ty / 4;
+ // a_data1
+ ubytes[8] /* tex */ = tx / 4;
+ ubytes[9] /* tex */ = ty / 4;
+ ubytes[10] /* labelminzoom */ = labelminzoom * 10;
+ ubytes[11] /* angle */ = (int16_t)std::round(angle * angleFactor) % 256;
+
+ // a_data2
+ ubytes[12] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160.
+ ubytes[13] /* maxzoom */ = std::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
+ ubytes[14] /* rangeend */ = util::max((int16_t)std::round(range[0] * angleFactor), (int16_t)0) % 256;
+ ubytes[15] /* rangestart */ = util::min((int16_t)std::round(range[1] * angleFactor), (int16_t)255) % 256;
return idx;
}
+
+}
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index 67d3c9afe2..1af33c4130 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -244,8 +244,6 @@ void Painter::render(const Style& style, const std::set<util::ptr<StyleSource>>&
for (const util::ptr<StyleSource> &source : sources) {
source->source->finishRender(*this);
}
-
- MBGL_CHECK_ERROR(glFlush());
}
void Painter::renderLayers(util::ptr<StyleLayerGroup> group) {
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index c46bc23439..71364f40c4 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -15,13 +15,25 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
const LineProperties &properties = layer_desc->getProperties<LineProperties>();
+ // the distance over which the line edge fades out.
+ // Retina devices need a smaller distance to avoid aliasing.
float antialiasing = 1 / state.getPixelRatio();
- float width = properties.width;
- float offset = properties.gap_width == 0 ? 0 : (properties.gap_width + width) / 2;
+
float blur = properties.blur + antialiasing;
+ float edgeWidth = properties.width / 2.0;
+ float inset = -1;
+ float offset = 0;
+ float shift = 0;
+
+ if (properties.gap_width != 0) {
+ inset = properties.gap_width / 2.0 + antialiasing * 0.5;
+ edgeWidth = properties.width;
+
+ // shift outer lines half a pixel towards the middle to eliminate the crack
+ offset = inset - antialiasing / 2.0;
+ }
- float inset = std::fmin((std::fmax(-1, offset - width / 2 - antialiasing / 2) + 1), 16.0f);
- float outset = std::fmin(offset + width / 2 + antialiasing / 2, 16.0f);
+ float outset = offset + edgeWidth + antialiasing / 2.0 + shift;
Color color = properties.color;
color[0] *= properties.opacity;
@@ -61,7 +73,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
}
if (properties.image.size()) {
- SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image);
+ SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image, true);
float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z);
float fade = std::fmod(state.getZoom(), 1.0);
@@ -79,6 +91,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
linepatternShader->u_pattern_br = imagePos.br;
linepatternShader->u_fade = fade;
+ MBGL_CHECK_ERROR(glActiveTexture(GL_TEXTURE0));
spriteAtlas.bind(true);
MBGL_CHECK_ERROR(glDepthRange(strata + strata_epsilon, 1.0f)); // may or may not matter
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index f5320b4be7..d9e4a58c23 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -134,11 +134,6 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr<StyleLayer> layer_des
spriteAtlas.bind(state.isChanging() || bucket.properties.placement == PlacementType::Line || angleOffset != 0 || fontScale != 1 || sdf);
- std::array<float, 2> texsize = {{
- float(spriteAtlas.getWidth()),
- float(spriteAtlas.getHeight())
- }};
-
if (sdf) {
renderSDF(bucket,
id,
@@ -146,7 +141,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr<StyleLayer> layer_des
bucket.properties.icon,
properties.icon,
1.0f,
- texsize,
+ {{ float(spriteAtlas.getWidth()) / 4.0f, float(spriteAtlas.getHeight()) / 4.0f }},
*sdfIconShader,
&SymbolBucket::drawIcons);
} else {
@@ -164,7 +159,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr<StyleLayer> layer_des
useProgram(iconShader->program);
iconShader->u_matrix = vtxMatrix;
iconShader->u_exmatrix = exMatrix;
- iconShader->u_texsize = texsize;
+ iconShader->u_texsize = {{ float(spriteAtlas.getWidth()) / 4.0f, float(spriteAtlas.getHeight()) / 4.0f }};
// Convert the -pi..pi to an int8 range.
const float angle = std::round(state.getAngle() / M_PI * 128);
diff --git a/src/mbgl/shader/icon.vertex.glsl b/src/mbgl/shader/icon.vertex.glsl
index 8c69c40410..fd7afd5b7d 100644
--- a/src/mbgl/shader/icon.vertex.glsl
+++ b/src/mbgl/shader/icon.vertex.glsl
@@ -1,12 +1,7 @@
attribute vec2 a_pos;
attribute vec2 a_offset;
-attribute vec2 a_tex;
-attribute float a_angle;
-attribute float a_minzoom;
-attribute float a_maxzoom;
-attribute float a_rangeend;
-attribute float a_rangestart;
-attribute float a_labelminzoom;
+attribute vec4 a_data1;
+attribute vec4 a_data2;
// matrix is for the vertex position, exmatrix is for rotating and projecting
@@ -28,6 +23,15 @@ varying vec2 v_tex;
varying float v_alpha;
void main() {
+ vec2 a_tex = a_data1.xy;
+ float a_labelminzoom = a_data1[2];
+ float a_angle = a_data1[3];
+ vec2 a_zoom = a_data2.st;
+ float a_minzoom = a_zoom[0];
+ float a_maxzoom = a_zoom[1];
+ vec2 a_range = a_data2.pq;
+ float a_rangeend = a_range[0];
+ float a_rangestart = a_range[1];
float a_fadedist = 10.0;
float rev = 0.0;
diff --git a/src/mbgl/shader/icon_shader.cpp b/src/mbgl/shader/icon_shader.cpp
index fa397fb274..0dfd67e25b 100644
--- a/src/mbgl/shader/icon_shader.cpp
+++ b/src/mbgl/shader/icon_shader.cpp
@@ -19,17 +19,12 @@ IconShader::IconShader()
a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos"));
a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset"));
- a_tex = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_tex"));
- a_angle = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_angle"));
- a_minzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_minzoom"));
- a_maxzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom"));
- a_rangeend = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangeend"));
- a_rangestart = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangestart"));
- a_labelminzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom"));
+ a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1"));
+ a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2"));
}
void IconShader::bind(char *offset) {
- const int stride = 20;
+ const int stride = 16;
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0));
@@ -37,24 +32,9 @@ void IconShader::bind(char *offset) {
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset));
MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12));
}
diff --git a/src/mbgl/shader/icon_shader.hpp b/src/mbgl/shader/icon_shader.hpp
index 645d7e21b6..155b9addca 100644
--- a/src/mbgl/shader/icon_shader.hpp
+++ b/src/mbgl/shader/icon_shader.hpp
@@ -27,13 +27,8 @@ public:
private:
int32_t a_pos = -1;
int32_t a_offset = -1;
- int32_t a_tex = -1;
- int32_t a_angle = -1;
- int32_t a_minzoom = -1;
- int32_t a_maxzoom = -1;
- int32_t a_rangeend = -1;
- int32_t a_rangestart = -1;
- int32_t a_labelminzoom = -1;
+ int32_t a_data1 = -1;
+ int32_t a_data2 = -1;
};
}
diff --git a/src/mbgl/shader/line.vertex.glsl b/src/mbgl/shader/line.vertex.glsl
index 1d8e687c95..bf0b537e83 100644
--- a/src/mbgl/shader/line.vertex.glsl
+++ b/src/mbgl/shader/line.vertex.glsl
@@ -7,8 +7,7 @@
#define scale 0.015873016
attribute vec2 a_pos;
-attribute vec2 a_extrude;
-attribute float a_linesofar;
+attribute vec4 a_data;
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
@@ -24,6 +23,9 @@ varying vec2 v_normal;
varying float v_linesofar;
void main() {
+ vec2 a_extrude = a_data.xy;
+ float a_linesofar = a_data.z * 128.0 + a_data.w;
+
// We store the texture normals in the most insignificant bit
// transform y so that 0 => -1 and 1 => 1
// In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap
diff --git a/src/mbgl/shader/line_shader.cpp b/src/mbgl/shader/line_shader.cpp
index 5ad257eabd..432a64f695 100644
--- a/src/mbgl/shader/line_shader.cpp
+++ b/src/mbgl/shader/line_shader.cpp
@@ -18,17 +18,13 @@ LineShader::LineShader()
}
a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos"));
- a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude"));
- a_linesofar = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_linesofar"));
+ a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data"));
}
void LineShader::bind(char *offset) {
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_linesofar));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4));
}
diff --git a/src/mbgl/shader/line_shader.hpp b/src/mbgl/shader/line_shader.hpp
index b789330882..c6adc0ff8d 100644
--- a/src/mbgl/shader/line_shader.hpp
+++ b/src/mbgl/shader/line_shader.hpp
@@ -22,8 +22,7 @@ public:
private:
int32_t a_pos = -1;
- int32_t a_extrude = -1;
- int32_t a_linesofar = -1;
+ int32_t a_data = -1;
};
diff --git a/src/mbgl/shader/linepattern.vertex.glsl b/src/mbgl/shader/linepattern.vertex.glsl
index 4600ebf65b..ada384a3d1 100644
--- a/src/mbgl/shader/linepattern.vertex.glsl
+++ b/src/mbgl/shader/linepattern.vertex.glsl
@@ -3,11 +3,11 @@
// stored in a byte (-128..127). we scale regular normals up to length 63, but
// there are also "special" normals that have a bigger length (of up to 126 in
// this case).
-#define scale 63.0
+// #define scale 63.0
+#define scale 0.015873016
attribute vec2 a_pos;
-attribute vec2 a_extrude;
-attribute float a_linesofar;
+attribute vec4 a_data;
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
@@ -24,6 +24,9 @@ varying vec2 v_normal;
varying float v_linesofar;
void main() {
+ vec2 a_extrude = a_data.xy;
+ float a_linesofar = a_data.z * 128.0 + a_data.w;
+
// We store the texture normals in the most insignificant bit
// transform y so that 0 => -1 and 1 => 1
// In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap
@@ -34,7 +37,7 @@ void main() {
// Scale the extrusion vector down to a normal and then up by the line width
// of this vertex.
- vec2 extrude = a_extrude / scale;
+ vec2 extrude = a_extrude * scale;
vec2 dist = u_linewidth.s * extrude * (1.0 - u_point);
// If the x coordinate is the maximum integer, we move the z coordinates out
diff --git a/src/mbgl/shader/linepattern_shader.cpp b/src/mbgl/shader/linepattern_shader.cpp
index 492a8f2a85..c45378378d 100644
--- a/src/mbgl/shader/linepattern_shader.cpp
+++ b/src/mbgl/shader/linepattern_shader.cpp
@@ -1,7 +1,6 @@
#include <mbgl/shader/linepattern_shader.hpp>
#include <mbgl/shader/shaders.hpp>
#include <mbgl/platform/gl.hpp>
-#include <iostream>
#include <cstdio>
@@ -19,17 +18,13 @@ LinepatternShader::LinepatternShader()
}
a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos"));
- a_extrude = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_extrude"));
- a_linesofar = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_linesofar"));
+ a_data = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data"));
}
void LinepatternShader::bind(char *offset) {
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_extrude));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_extrude, 2, GL_BYTE, false, 8, offset + 4));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_linesofar));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_linesofar, 1, GL_SHORT, false, 8, offset + 6));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4));
}
diff --git a/src/mbgl/shader/linepattern_shader.hpp b/src/mbgl/shader/linepattern_shader.hpp
index bf85940b8a..ace8198aed 100644
--- a/src/mbgl/shader/linepattern_shader.hpp
+++ b/src/mbgl/shader/linepattern_shader.hpp
@@ -25,8 +25,7 @@ public:
private:
int32_t a_pos = -1;
- int32_t a_extrude = -1;
- int32_t a_linesofar = -1;
+ int32_t a_data = -1;
};
}
diff --git a/src/mbgl/shader/sdf.vertex.glsl b/src/mbgl/shader/sdf.vertex.glsl
index c5166ae46f..bbfc44919e 100644
--- a/src/mbgl/shader/sdf.vertex.glsl
+++ b/src/mbgl/shader/sdf.vertex.glsl
@@ -1,12 +1,7 @@
attribute vec2 a_pos;
attribute vec2 a_offset;
-attribute vec2 a_tex;
-attribute float a_angle;
-attribute float a_minzoom;
-attribute float a_maxzoom;
-attribute float a_rangeend;
-attribute float a_rangestart;
-attribute float a_labelminzoom;
+attribute vec4 a_data1;
+attribute vec4 a_data2;
// matrix is for the vertex position, exmatrix is for rotating and projecting
@@ -27,6 +22,15 @@ varying vec2 v_tex;
varying float v_alpha;
void main() {
+ vec2 a_tex = a_data1.xy;
+ float a_labelminzoom = a_data1[2];
+ float a_angle = a_data1[3];
+ vec2 a_zoom = a_data2.st;
+ float a_minzoom = a_zoom[0];
+ float a_maxzoom = a_zoom[1];
+ vec2 a_range = a_data2.pq;
+ float a_rangeend = a_range[0];
+ float a_rangestart = a_range[1];
float rev = 0.0;
diff --git a/src/mbgl/shader/sdf_shader.cpp b/src/mbgl/shader/sdf_shader.cpp
index 25b226ee23..757884f39c 100644
--- a/src/mbgl/shader/sdf_shader.cpp
+++ b/src/mbgl/shader/sdf_shader.cpp
@@ -19,13 +19,8 @@ SDFShader::SDFShader()
a_pos = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_pos"));
a_offset = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_offset"));
- a_tex = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_tex"));
- a_angle = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_angle"));
- a_minzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_minzoom"));
- a_maxzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_maxzoom"));
- a_rangeend = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangeend"));
- a_rangestart = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_rangestart"));
- a_labelminzoom = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_labelminzoom"));
+ a_data1 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data1"));
+ a_data2 = MBGL_CHECK_ERROR(glGetAttribLocation(program, "a_data2"));
}
void SDFGlyphShader::bind(char *offset) {
@@ -37,30 +32,15 @@ void SDFGlyphShader::bind(char *offset) {
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset));
MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, stride, offset + 14));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12));
}
void SDFIconShader::bind(char *offset) {
- const int stride = 20;
+ const int stride = 16;
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, stride, offset + 0));
@@ -68,24 +48,9 @@ void SDFIconShader::bind(char *offset) {
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_offset));
MBGL_CHECK_ERROR(glVertexAttribPointer(a_offset, 2, GL_SHORT, false, stride, offset + 4));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_labelminzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 8));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_minzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 9));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_maxzoom));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, stride, offset + 10));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_angle));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, stride, offset + 11));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangeend));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, stride, offset + 12));
-
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_rangestart));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, stride, offset + 13));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data1));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, stride, offset + 8));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_tex));
- MBGL_CHECK_ERROR(glVertexAttribPointer(a_tex, 2, GL_SHORT, false, stride, offset + 16));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2));
+ MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12));
}
diff --git a/src/mbgl/shader/sdf_shader.hpp b/src/mbgl/shader/sdf_shader.hpp
index 0737c25ee1..08f3053b7d 100644
--- a/src/mbgl/shader/sdf_shader.hpp
+++ b/src/mbgl/shader/sdf_shader.hpp
@@ -29,13 +29,8 @@ public:
protected:
int32_t a_pos = -1;
int32_t a_offset = -1;
- int32_t a_tex = -1;
- int32_t a_angle = -1;
- int32_t a_minzoom = -1;
- int32_t a_maxzoom = -1;
- int32_t a_rangeend = -1;
- int32_t a_rangestart = -1;
- int32_t a_labelminzoom = -1;
+ int32_t a_data1 = -1;
+ int32_t a_data2 = -1;
};
class SDFGlyphShader : public SDFShader {