Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Fix style.cpp skipping duplicated child symbol tiles + rebased shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Mar 20, 2017
1 parent 5888ee9 commit f9c6cec
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 236 deletions.
71 changes: 0 additions & 71 deletions src/mbgl/shaders/extrusion_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,6 @@ namespace shaders {

const char* extrusion_texture::name = "extrusion_texture";
const char* extrusion_texture::vertexSource = R"MBGL_SHADER(
#ifdef GL_ES
precision highp float;
#else
#if !defined(lowp)
#define lowp
#endif
#if !defined(mediump)
#define mediump
#endif
#if !defined(highp)
#define highp
#endif
#endif
float evaluate_zoom_function_1(const vec4 values, const float t) {
if (t < 1.0) {
return mix(values[0], values[1], t);
} else if (t < 2.0) {
return mix(values[1], values[2], t - 1.0);
} else {
return mix(values[2], values[3], t - 2.0);
}
}
vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) {
if (t < 1.0) {
return mix(value0, value1, t);
} else if (t < 2.0) {
return mix(value1, value2, t - 1.0);
} else {
return mix(value2, value3, t - 2.0);
}
}
// The offset depends on how many pixels are between the world origin and the edge of the tile:
// vec2 offset = mod(pixel_coord, size)
//
// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile.
// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that.
//
// The pixel_coord is passed in as two 16 bit values:
// pixel_coord_upper = floor(pixel_coord / 2^16)
// pixel_coord_lower = mod(pixel_coord, 2^16)
//
// The offset is calculated in a series of steps that should preserve this precision:
vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) {
vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
return (tile_units_to_pixels * pos + offset) / pattern_size;
}
uniform mat4 u_matrix;
uniform vec2 u_world;
attribute vec2 a_pos;
Expand All @@ -75,23 +21,6 @@ void main() {
)MBGL_SHADER";
const char* extrusion_texture::fragmentSource = R"MBGL_SHADER(
#ifdef GL_ES
precision mediump float;
#else
#if !defined(lowp)
#define lowp
#endif
#if !defined(mediump)
#define mediump
#endif
#if !defined(highp)
#define highp
#endif
#endif
uniform sampler2D u_image;
uniform float u_opacity;
varying vec2 v_pos;
Expand Down
86 changes: 6 additions & 80 deletions src/mbgl/shaders/fill_extrusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,6 @@ namespace shaders {

const char* fill_extrusion::name = "fill_extrusion";
const char* fill_extrusion::vertexSource = R"MBGL_SHADER(
#ifdef GL_ES
precision highp float;
#else
#if !defined(lowp)
#define lowp
#endif
#if !defined(mediump)
#define mediump
#endif
#if !defined(highp)
#define highp
#endif
#endif
float evaluate_zoom_function_1(const vec4 values, const float t) {
if (t < 1.0) {
return mix(values[0], values[1], t);
} else if (t < 2.0) {
return mix(values[1], values[2], t - 1.0);
} else {
return mix(values[2], values[3], t - 2.0);
}
}
vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) {
if (t < 1.0) {
return mix(value0, value1, t);
} else if (t < 2.0) {
return mix(value1, value2, t - 1.0);
} else {
return mix(value2, value3, t - 2.0);
}
}
// The offset depends on how many pixels are between the world origin and the edge of the tile:
// vec2 offset = mod(pixel_coord, size)
//
// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile.
// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that.
//
// The pixel_coord is passed in as two 16 bit values:
// pixel_coord_upper = floor(pixel_coord / 2^16)
// pixel_coord_lower = mod(pixel_coord, 2^16)
//
// The offset is calculated in a series of steps that should preserve this precision:
vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) {
vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
return (tile_units_to_pixels * pos + offset) / pattern_size;
}
uniform mat4 u_matrix;
uniform vec3 u_lightcolor;
uniform lowp vec3 u_lightpos;
Expand All @@ -73,23 +19,20 @@ attribute float a_edgedistance;
varying vec4 v_color;
uniform lowp float a_base_t;
attribute lowp float a_base_min;
attribute lowp float a_base_max;
attribute lowp vec2 a_base;
varying lowp float base;
uniform lowp float a_height_t;
attribute lowp float a_height_min;
attribute lowp float a_height_max;
attribute lowp vec2 a_height;
varying lowp float height;
uniform lowp float a_color_t;
attribute lowp vec4 a_color_min;
attribute lowp vec4 a_color_max;
attribute lowp vec4 a_color;
varying lowp vec4 color;
void main() {
base = mix(a_base_min, a_base_max, a_base_t);
height = mix(a_height_min, a_height_max, a_height_t);
color = mix(a_color_min, a_color_max, a_color_t);
base = unpack_mix_vec2(a_base, a_base_t);
height = unpack_mix_vec2(a_height, a_height_t);
color = unpack_mix_vec4(a_color, a_color_t);
float ed = a_edgedistance; // use each attrib in order to not trip a VAO assert
float t = mod(a_normal.x, 2.0);
Expand Down Expand Up @@ -129,23 +72,6 @@ void main() {
)MBGL_SHADER";
const char* fill_extrusion::fragmentSource = R"MBGL_SHADER(
#ifdef GL_ES
precision mediump float;
#else
#if !defined(lowp)
#define lowp
#endif
#if !defined(mediump)
#define mediump
#endif
#if !defined(highp)
#define highp
#endif
#endif
varying vec4 v_color;
varying lowp float base;
varying lowp float height;
Expand Down
81 changes: 4 additions & 77 deletions src/mbgl/shaders/fill_extrusion_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,6 @@ namespace shaders {

const char* fill_extrusion_pattern::name = "fill_extrusion_pattern";
const char* fill_extrusion_pattern::vertexSource = R"MBGL_SHADER(
#ifdef GL_ES
precision highp float;
#else
#if !defined(lowp)
#define lowp
#endif
#if !defined(mediump)
#define mediump
#endif
#if !defined(highp)
#define highp
#endif
#endif
float evaluate_zoom_function_1(const vec4 values, const float t) {
if (t < 1.0) {
return mix(values[0], values[1], t);
} else if (t < 2.0) {
return mix(values[1], values[2], t - 1.0);
} else {
return mix(values[2], values[3], t - 2.0);
}
}
vec4 evaluate_zoom_function_4(const vec4 value0, const vec4 value1, const vec4 value2, const vec4 value3, const float t) {
if (t < 1.0) {
return mix(value0, value1, t);
} else if (t < 2.0) {
return mix(value1, value2, t - 1.0);
} else {
return mix(value2, value3, t - 2.0);
}
}
// The offset depends on how many pixels are between the world origin and the edge of the tile:
// vec2 offset = mod(pixel_coord, size)
//
// At high zoom levels there are a ton of pixels between the world origin and the edge of the tile.
// The glsl spec only guarantees 16 bits of precision for highp floats. We need more than that.
//
// The pixel_coord is passed in as two 16 bit values:
// pixel_coord_upper = floor(pixel_coord / 2^16)
// pixel_coord_lower = mod(pixel_coord, 2^16)
//
// The offset is calculated in a series of steps that should preserve this precision:
vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower,
const vec2 pattern_size, const float tile_units_to_pixels, const vec2 pos) {
vec2 offset = mod(mod(mod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size);
return (tile_units_to_pixels * pos + offset) / pattern_size;
}
uniform mat4 u_matrix;
uniform vec2 u_pattern_size_a;
uniform vec2 u_pattern_size_b;
Expand All @@ -85,17 +31,15 @@ varying vec4 v_lighting;
varying float v_directional;
uniform lowp float a_base_t;
attribute lowp float a_base_min;
attribute lowp float a_base_max;
attribute lowp vec2 a_base;
varying lowp float base;
uniform lowp float a_height_t;
attribute lowp float a_height_min;
attribute lowp float a_height_max;
attribute lowp vec2 a_height;
varying lowp float height;
void main() {
base = mix(a_base_min, a_base_max, a_base_t);
height = mix(a_height_min, a_height_max, a_height_t);
base = unpack_mix_vec2(a_base, a_base_t);
height = unpack_mix_vec2(a_height, a_height_t);
float t = mod(a_normal.x, 2.0);
float z = t > 0.0 ? height : base;
Expand All @@ -122,23 +66,6 @@ void main() {
)MBGL_SHADER";
const char* fill_extrusion_pattern::fragmentSource = R"MBGL_SHADER(
#ifdef GL_ES
precision mediump float;
#else
#if !defined(lowp)
#define lowp
#endif
#if !defined(mediump)
#define mediump
#endif
#if !defined(highp)
#define highp
#endif
#endif
uniform vec2 u_pattern_tl_a;
uniform vec2 u_pattern_br_a;
uniform vec2 u_pattern_tl_b;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/shaders/symbol_sdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void main() {
lowp vec4 color = fill_color;
lowp float gamma = EDGE_GAMMA / u_gamma_scale;
highp float gamma = EDGE_GAMMA / u_gamma_scale;
lowp float buff = (256.0 - 64.0) / 256.0;
if (u_is_halo) {
color = halo_color;
Expand Down
14 changes: 7 additions & 7 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const
});
}

std::vector<std::reference_wrapper<RenderTile>> sortedTilesForInsertion;
for (auto tileIt = sortedTiles.begin(); tileIt != sortedTiles.end(); ++tileIt) {
// for (auto tileIt : sortedTiles) {
auto& tile = tileIt->get();
if (!tile.tile.isRenderable()) {
sortedTiles.erase(tileIt);
Expand All @@ -484,22 +484,22 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const
// Look back through the buckets we decided to render to find out whether there is
// already a bucket from this layer that is a parent of this tile. Tiles are ordered
// by zoom level when we obtain them from getTiles().
for (auto it = sortedTiles.rbegin() + (sortedTiles.end() - tileIt); it != sortedTiles.rend(); ++it) {
for (auto it = sortedTilesForInsertion.rbegin(); it != sortedTilesForInsertion.rend(); ++it) {
if (tile.tile.id.isChildOf(it->get().tile.id)) {
skip = true;
// sortedTiles.erase(--(it.base()));
// TODO commenting this out as a temporary stopgap fix for EXC_BAD_ACCESS error; revisit to fix tile loading
break;
}
}
if (skip) {
continue;
if (!skip) {
sortedTilesForInsertion.emplace_back(tile);
}
} else {
sortedTilesForInsertion.emplace_back(tile);
}

}

result.order.emplace_back(*layer, std::move(sortedTiles));
result.order.emplace_back(*layer, std::move(sortedTilesForInsertion));
}

return result;
Expand Down

0 comments on commit f9c6cec

Please sign in to comment.