summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-05-17 21:40:57 -0700
committerAnsis Brammanis <brammanis@gmail.com>2017-07-11 09:10:23 -0700
commit8f5e0b66ab13cff7d35ed46afaddbdca9ab1993f (patch)
tree49b45a6327092a9affa9fd4fd1b3f2764df4b180
parent59df3a90f41461562a80688337ec53687e341124 (diff)
downloadqtlocation-mapboxgl-8f5e0b66ab13cff7d35ed46afaddbdca9ab1993f.tar.gz
[core] Pass pitch-scaling vertex attributes and uniforms to shaders.
-rw-r--r--src/mbgl/layout/symbol_layout.cpp23
-rw-r--r--src/mbgl/layout/symbol_layout.hpp3
-rw-r--r--src/mbgl/programs/attributes.hpp2
-rw-r--r--src/mbgl/programs/collision_box_program.cpp2
-rw-r--r--src/mbgl/programs/collision_box_program.hpp12
-rw-r--r--src/mbgl/programs/symbol_program.cpp6
-rw-r--r--src/mbgl/programs/symbol_program.hpp21
-rw-r--r--src/mbgl/programs/uniforms.hpp2
-rw-r--r--src/mbgl/renderer/painters/painter_symbol.cpp3
9 files changed, 53 insertions, 21 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index adc7eaaed8..a664957489 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -504,7 +504,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
for (const auto& symbol : symbolInstance.glyphQuads) {
addSymbol(
bucket->text, *bucket->textSizeBinder, symbol, feature, placementZoom,
- keepUpright, textPlacement, collisionTile.config.angle, symbolInstance.writingModes);
+ keepUpright, textPlacement, collisionTile.config.angle, symbolInstance.writingModes, symbolInstance.point);
}
}
}
@@ -515,7 +515,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
if (iconScale < collisionTile.maxScale && symbolInstance.iconQuad) {
addSymbol(
bucket->icon, *bucket->iconSizeBinder, *symbolInstance.iconQuad, feature, placementZoom,
- keepUpright, iconPlacement, collisionTile.config.angle, symbolInstance.writingModes);
+ keepUpright, iconPlacement, collisionTile.config.angle, symbolInstance.writingModes, symbolInstance.point);
}
}
@@ -541,7 +541,8 @@ void SymbolLayout::addSymbol(Buffer& buffer,
const bool keepUpright,
const style::SymbolPlacementType placement,
const float placementAngle,
- const WritingModeType writingModes) {
+ const WritingModeType writingModes,
+ const Point<float> labelAnchor) {
constexpr const uint16_t vertexLength = 4;
const auto &tl = symbol.tl;
@@ -590,13 +591,13 @@ void SymbolLayout::addSymbol(Buffer& buffer,
uint8_t glyphAngle = std::round((symbol.glyphAngle / (M_PI * 2)) * 256);
// coordinates (2 triangles)
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, tl, tex.x, tex.y,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, tl, labelAnchor, tex.x, tex.y,
minZoom, maxZoom, placementZoom, glyphAngle));
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, tr, tex.x + tex.w, tex.y,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, tr, labelAnchor, tex.x + tex.w, tex.y,
minZoom, maxZoom, placementZoom, glyphAngle));
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, bl, tex.x, tex.y + tex.h,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, bl, labelAnchor, tex.x, tex.y + tex.h,
minZoom, maxZoom, placementZoom, glyphAngle));
- buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, br, tex.x + tex.w, tex.y + tex.h,
+ buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, br, labelAnchor, tex.x + tex.w, tex.y + tex.h,
minZoom, maxZoom, placementZoom, glyphAngle));
sizeBinder.populateVertexVector(feature);
@@ -646,10 +647,10 @@ void SymbolLayout::addToDebugBuffers(CollisionTile& collisionTile, SymbolBucket&
auto& segment = collisionBox.segments.back();
uint16_t index = segment.vertexLength;
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, tl, maxZoom, placementZoom));
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, tr, maxZoom, placementZoom));
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, br, maxZoom, placementZoom));
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, bl, maxZoom, placementZoom));
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, symbolInstance.point, tl, maxZoom, placementZoom));
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, symbolInstance.point, tr, maxZoom, placementZoom));
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, symbolInstance.point, br, maxZoom, placementZoom));
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, symbolInstance.point, bl, maxZoom, placementZoom));
collisionBox.lines.emplace_back(index + 0, index + 1);
collisionBox.lines.emplace_back(index + 1, index + 2);
diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp
index 4ee52e843f..5dc0f3eb76 100644
--- a/src/mbgl/layout/symbol_layout.hpp
+++ b/src/mbgl/layout/symbol_layout.hpp
@@ -65,7 +65,8 @@ private:
const bool keepUpright,
const style::SymbolPlacementType,
const float placementAngle,
- WritingModeType writingModes);
+ WritingModeType writingModes,
+ const Point<float> labelAnchor);
// Stores the layer so that we can hold on to GeometryTileFeature instances in SymbolFeature,
// which may reference data from this object.
diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp
index 8f2751080f..f39af2deec 100644
--- a/src/mbgl/programs/attributes.hpp
+++ b/src/mbgl/programs/attributes.hpp
@@ -23,6 +23,8 @@ inline uint16_t packUint8Pair(T a, T b) {
MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_pos);
MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_extrude);
MBGL_DEFINE_ATTRIBUTE(int16_t, 4, a_pos_offset);
+MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_label_pos);
+MBGL_DEFINE_ATTRIBUTE(int16_t, 2, a_anchor_pos);
MBGL_DEFINE_ATTRIBUTE(uint16_t, 2, a_texture_pos);
MBGL_DEFINE_ATTRIBUTE(int16_t, 3, a_normal);
MBGL_DEFINE_ATTRIBUTE(uint16_t, 1, a_edgedistance);
diff --git a/src/mbgl/programs/collision_box_program.cpp b/src/mbgl/programs/collision_box_program.cpp
index a3dc01ebe4..57107db75d 100644
--- a/src/mbgl/programs/collision_box_program.cpp
+++ b/src/mbgl/programs/collision_box_program.cpp
@@ -2,6 +2,6 @@
namespace mbgl {
-static_assert(sizeof(CollisionBoxProgram::LayoutVertex) == 10, "expected CollisionBoxVertex size");
+static_assert(sizeof(CollisionBoxProgram::LayoutVertex) == 14, "expected CollisionBoxVertex size");
} // namespace mbgl
diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp
index 160fd42814..3b4260bb78 100644
--- a/src/mbgl/programs/collision_box_program.hpp
+++ b/src/mbgl/programs/collision_box_program.hpp
@@ -18,6 +18,7 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_maxzoom);
using CollisionBoxAttributes = gl::Attributes<
attributes::a_pos,
+ attributes::a_anchor_pos,
attributes::a_extrude,
attributes::a_data<uint8_t, 2>>;
@@ -29,19 +30,26 @@ class CollisionBoxProgram : public Program<
uniforms::u_matrix,
uniforms::u_scale,
uniforms::u_zoom,
- uniforms::u_maxzoom>,
+ uniforms::u_maxzoom,
+ uniforms::u_collision_y_stretch,
+ uniforms::u_camera_to_center_distance,
+ uniforms::u_pitch>,
style::Properties<>>
{
public:
using Program::Program;
- static LayoutVertex vertex(Point<float> a, Point<float> o, float maxzoom, float placementZoom) {
+ static LayoutVertex vertex(Point<float> a, Point<float> anchor, Point<float> o, float maxzoom, float placementZoom) {
return LayoutVertex {
{{
static_cast<int16_t>(a.x),
static_cast<int16_t>(a.y)
}},
{{
+ static_cast<int16_t>(anchor.x),
+ static_cast<int16_t>(anchor.y)
+ }},
+ {{
static_cast<int16_t>(::round(o.x)),
static_cast<int16_t>(::round(o.y))
}},
diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp
index 789eed0dd8..1b5a7d9bff 100644
--- a/src/mbgl/programs/symbol_program.cpp
+++ b/src/mbgl/programs/symbol_program.cpp
@@ -10,7 +10,7 @@ namespace mbgl {
using namespace style;
-static_assert(sizeof(SymbolLayoutVertex) == 16, "expected SymbolLayoutVertex size");
+static_assert(sizeof(SymbolLayoutVertex) == 20, "expected SymbolLayoutVertex size");
std::unique_ptr<SymbolSizeBinder> SymbolSizeBinder::create(const float tileZoom,
const style::DataDrivenPropertyValue<float>& sizeProperty,
@@ -59,6 +59,9 @@ Values makeValues(const bool isText,
uniforms::u_fadetexture::Value{ 1 },
uniforms::u_is_text::Value{ isText },
uniforms::u_collision_y_stretch::Value{ tile.tile.yStretch() },
+ uniforms::u_camera_to_center_distance::Value{ state.getCameraToCenterDistance() },
+ uniforms::u_pitch::Value{ state.getPitch() },
+ uniforms::u_max_camera_distance::Value{ 10.0f },
std::forward<Args>(args)...
};
}
@@ -103,7 +106,6 @@ typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<Paint
tile,
state,
uniforms::u_gamma_scale::Value{ gammaScale },
- uniforms::u_pitch::Value{ state.getPitch() },
uniforms::u_bearing::Value{ -1.0f * state.getAngle() },
uniforms::u_aspect_ratio::Value{ (state.getSize().width * 1.0f) / (state.getSize().height * 1.0f) },
uniforms::u_pitch_with_map::Value{ values.pitchAlignment == AlignmentType::Map },
diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp
index d1a6b4b994..c38ed04a1e 100644
--- a/src/mbgl/programs/symbol_program.hpp
+++ b/src/mbgl/programs/symbol_program.hpp
@@ -42,15 +42,17 @@ MBGL_DEFINE_UNIFORM_SCALAR(bool, u_is_size_feature_constant);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_size_t);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_size);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_layout_size);
-MBGL_DEFINE_UNIFORM_SCALAR(float, u_collision_y_stretch);
+MBGL_DEFINE_UNIFORM_SCALAR(float, u_max_camera_distance);
} // namespace uniforms
struct SymbolLayoutAttributes : gl::Attributes<
attributes::a_pos_offset,
+ attributes::a_label_pos,
attributes::a_data<uint16_t, 4>>
{
static Vertex vertex(Point<float> a,
Point<float> o,
+ Point<float> labelAnchor,
uint16_t tx,
uint16_t ty,
float minzoom,
@@ -66,6 +68,10 @@ struct SymbolLayoutAttributes : gl::Attributes<
static_cast<int16_t>(::round(o.y * 64))
}},
{{
+ static_cast<int16_t>(labelAnchor.x),
+ static_cast<int16_t>(labelAnchor.y)
+ }},
+ {{
tx,
ty,
mbgl::attributes::packUint8Pair(
@@ -391,7 +397,10 @@ class SymbolIconProgram : public SymbolProgram<
uniforms::u_texture,
uniforms::u_fadetexture,
uniforms::u_is_text,
- uniforms::u_collision_y_stretch>,
+ uniforms::u_collision_y_stretch,
+ uniforms::u_camera_to_center_distance,
+ uniforms::u_pitch,
+ uniforms::u_max_camera_distance>,
style::IconPaintProperties>
{
public:
@@ -425,8 +434,10 @@ class SymbolSDFProgram : public SymbolProgram<
uniforms::u_fadetexture,
uniforms::u_is_text,
uniforms::u_collision_y_stretch,
- uniforms::u_gamma_scale,
+ uniforms::u_camera_to_center_distance,
uniforms::u_pitch,
+ uniforms::u_max_camera_distance,
+ uniforms::u_gamma_scale,
uniforms::u_bearing,
uniforms::u_aspect_ratio,
uniforms::u_pitch_with_map,
@@ -447,8 +458,10 @@ public:
uniforms::u_fadetexture,
uniforms::u_is_text,
uniforms::u_collision_y_stretch,
- uniforms::u_gamma_scale,
+ uniforms::u_camera_to_center_distance,
uniforms::u_pitch,
+ uniforms::u_max_camera_distance,
+ uniforms::u_gamma_scale,
uniforms::u_bearing,
uniforms::u_aspect_ratio,
uniforms::u_pitch_with_map,
diff --git a/src/mbgl/programs/uniforms.hpp b/src/mbgl/programs/uniforms.hpp
index c8f8684ba1..8d606dcf08 100644
--- a/src/mbgl/programs/uniforms.hpp
+++ b/src/mbgl/programs/uniforms.hpp
@@ -14,6 +14,8 @@ MBGL_DEFINE_UNIFORM_SCALAR(Color, u_color);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_blur);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_zoom);
+MBGL_DEFINE_UNIFORM_SCALAR(float, u_collision_y_stretch);
+MBGL_DEFINE_UNIFORM_SCALAR(float, u_camera_to_center_distance);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_pitch);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_bearing);
MBGL_DEFINE_UNIFORM_SCALAR(float, u_radius);
diff --git a/src/mbgl/renderer/painters/painter_symbol.cpp b/src/mbgl/renderer/painters/painter_symbol.cpp
index d3a505aa3f..2d91ff41ad 100644
--- a/src/mbgl/renderer/painters/painter_symbol.cpp
+++ b/src/mbgl/renderer/painters/painter_symbol.cpp
@@ -152,6 +152,9 @@ void Painter::renderSymbol(PaintParameters& parameters,
uniforms::u_scale::Value{ std::pow(2.0f, float(state.getZoom() - tile.tile.id.overscaledZ)) },
uniforms::u_zoom::Value{ float(state.getZoom() * 10) },
uniforms::u_maxzoom::Value{ float((tile.id.canonical.z + 1) * 10) },
+ uniforms::u_collision_y_stretch::Value{ tile.tile.yStretch() },
+ uniforms::u_camera_to_center_distance::Value{ state.getCameraToCenterDistance() },
+ uniforms::u_pitch::Value{ state.getPitch() }
},
*bucket.collisionBox.vertexBuffer,
*bucket.collisionBox.indexBuffer,