summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-12-11 11:58:46 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-12-12 12:37:55 +0100
commitfebfb7ac0965852ee224744bd33a3e3e5461ba80 (patch)
tree91c78a7d130cbbd0526d1c8e1bf4190e94a350af /src
parentf8ba23377d4377a6047f8cb9b28c8ce94a00e8f5 (diff)
downloadqtlocation-mapboxgl-febfb7ac0965852ee224744bd33a3e3e5461ba80.tar.gz
fix rendering errors
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/geometry/sprite_atlas.cpp34
-rw-r--r--src/mbgl/renderer/painter_line.cpp3
-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
5 files changed, 32 insertions, 30 deletions
diff --git a/src/mbgl/geometry/sprite_atlas.cpp b/src/mbgl/geometry/sprite_atlas.cpp
index db75414c0b..d3771b4695 100644
--- a/src/mbgl/geometry/sprite_atlas.cpp
+++ b/src/mbgl/geometry/sprite_atlas.cpp
@@ -77,15 +77,12 @@ 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) {
- uint16_t pack_width = pixel_width + buffer * 2;
- uint16_t pack_height = pixel_height + buffer * 2;
-
+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.
- pack_width += (4 - pack_width % 4);
- pack_height += (4 - pack_height % 4);
+ 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.
@@ -96,8 +93,6 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(size_t pixel_width, size
rect.x += buffer;
rect.y += buffer;
- rect.w = pixel_width;
- rect.h = pixel_height;
return rect;
}
@@ -132,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;
+ rect.h = pos.height;
+ }
+
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) / pixelRatio, float(rect.h) / pixelRatio }},
+ {{ float(rect.x) / width, float(rect.y) / height }},
+ {{ float(rect.x + rect.w) / width, float(rect.y + rect.h) / height }}
};
}
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index c46bc23439..af5017b14c 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -61,7 +61,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 +79,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
linepatternShader->u_pattern_br = imagePos.br;
linepatternShader->u_fade = fade;
+ 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/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;
};
}