summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-07-02 21:38:45 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-07-19 07:51:22 +0300
commitf8186e9d5279a7fa6b38e984101e49bfbf9867a2 (patch)
tree86fe34771651e82691dde91a19252735542ed137
parentef42ed2e24781c34c8e3fcf016562997c88438a3 (diff)
downloadqtlocation-mapboxgl-f8186e9d5279a7fa6b38e984101e49bfbf9867a2.tar.gz
[core] Do not downcast values in TransformStateupstream/padded-angle-correction
-rw-r--r--src/mbgl/map/transform_state.cpp19
-rw-r--r--src/mbgl/map/transform_state.hpp12
-rw-r--r--src/mbgl/programs/symbol_program.cpp10
-rw-r--r--src/mbgl/renderer/layers/render_circle_layer.cpp3
-rw-r--r--src/mbgl/renderer/layers/render_symbol_layer.cpp9
-rw-r--r--src/mbgl/renderer/tile_pyramid.cpp8
-rw-r--r--src/mbgl/renderer/tile_pyramid.hpp4
-rw-r--r--src/mbgl/tile/tile_id_io.cpp4
-rw-r--r--src/mbgl/util/tile_cover.cpp10
9 files changed, 42 insertions, 37 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index afa6b81820..a7cc8fc961 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -44,8 +44,7 @@ void TransformState::getProjMatrix(mat4& projMatrix, uint16_t nearZ, bool aligne
// Calculate z distance of the farthest fragment that should be rendered.
const double furthestDistance = std::cos(M_PI / 2 - getPitch()) * topHalfSurfaceDistance + cameraToCenterDistance;
- // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
- const double farZ = furthestDistance * 1.01;
+ const double farZ = furthestDistance;
const double aspect = double(size.width) / size.height;
matrix::perspective(projMatrix, getFieldOfView(), aspect, nearZ, farZ);
@@ -275,7 +274,7 @@ double TransformState::getMaxPitch() const {
#pragma mark - Rotation
-float TransformState::getBearing() const {
+double TransformState::getBearing() const {
return bearing;
}
@@ -283,15 +282,15 @@ void TransformState::setBearing(double bearing_) {
bearing = bearing_;
}
-float TransformState::getFieldOfView() const {
+double TransformState::getFieldOfView() const {
return fov;
}
-float TransformState::getCameraToCenterDistance() const {
+double TransformState::getCameraToCenterDistance() const {
return 0.5 * size.height / std::tan(fov / 2.0);
}
-float TransformState::getPitch() const {
+double TransformState::getPitch() const {
return pitch;
}
@@ -389,7 +388,7 @@ LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, L
mat4 TransformState::coordinatePointMatrix(double z) const {
mat4 proj;
getProjMatrix(proj);
- float s = Projection::worldSize(scale) / std::pow(2, z);
+ double s = Projection::worldSize(scale) / zoomScale(z);
matrix::scale(proj, proj, s, s, 1);
matrix::multiply(proj, getPixelMatrix(), proj);
return proj;
@@ -465,7 +464,7 @@ void TransformState::setLatLngZoom(const LatLng& latLng, const EdgeInsets &paddi
constrainToViewport();
}
-float TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) const {
+double TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) const {
mat4 projectionMatrix;
getProjMatrix(projectionMatrix);
mat4 tileProjectionMatrix;
@@ -477,11 +476,11 @@ float TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) con
return projectedCenter[3];
}
-float TransformState::maxPitchScaleFactor() const {
+double TransformState::maxPitchScaleFactor() const {
if (size.isEmpty()) {
return {};
}
- auto latLng = screenCoordinateToLatLng({ 0, static_cast<float>(getSize().height) });
+ auto latLng = screenCoordinateToLatLng({ 0, static_cast<double>(getSize().height) });
mat4 mat = coordinatePointMatrix(getZoom());
Point<double> pt = Projection::project(latLng, scale) / util::tileSize;
vec4 p = {{ pt.x, pt.y, 0, 1 }};
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 17850ac0bc..adcd88f4ea 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -73,15 +73,15 @@ public:
double getMaxPitch() const;
// Rotation
- float getBearing() const;
+ double getBearing() const;
void setBearing(double bearing);
// Camera
- float getFieldOfView() const;
- float getCameraToCenterDistance() const;
+ double getFieldOfView() const;
+ double getCameraToCenterDistance() const;
// Tilt
- float getPitch() const;
+ double getPitch() const;
void setPitch(double pitch);
// State
@@ -104,8 +104,8 @@ public:
return !size.isEmpty() && (scale >= min_scale && scale <= max_scale);
}
- float getCameraToTileDistance(const UnwrappedTileID&) const;
- float maxPitchScaleFactor() const;
+ double getCameraToTileDistance(const UnwrappedTileID&) const;
+ double maxPitchScaleFactor() const;
/** Recenter the map so that the given coordinate is located at the given
point on screen. */
diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp
index 84a7a53f1d..3ae11110f8 100644
--- a/src/mbgl/programs/symbol_program.cpp
+++ b/src/mbgl/programs/symbol_program.cpp
@@ -40,13 +40,15 @@ Values makeValues(const bool isText,
const float symbolFadeChange,
Args&&... args) {
std::array<float, 2> extrudeScale;
+ const float cameraToCenterDistance = state.getCameraToCenterDistance();
+ const float pitch = state.getPitch();
if (values.pitchAlignment == AlignmentType::Map) {
extrudeScale.fill(tile.id.pixelsToTileUnits(1, state.getZoom()));
} else {
extrudeScale = {{
- pixelsToGLUnits[0] * state.getCameraToCenterDistance(),
- pixelsToGLUnits[1] * state.getCameraToCenterDistance()
+ pixelsToGLUnits[0] * cameraToCenterDistance,
+ pixelsToGLUnits[1] * cameraToCenterDistance
}};
}
@@ -85,8 +87,8 @@ Values makeValues(const bool isText,
uniforms::u_texture::Value{ 0 },
uniforms::u_fade_change::Value{ symbolFadeChange },
uniforms::u_is_text::Value{ isText },
- uniforms::u_camera_to_center_distance::Value{ state.getCameraToCenterDistance() },
- uniforms::u_pitch::Value{ state.getPitch() },
+ uniforms::u_camera_to_center_distance::Value{ cameraToCenterDistance },
+ uniforms::u_pitch::Value{ pitch },
uniforms::u_pitch_with_map::Value{ pitchWithMap },
uniforms::u_max_camera_distance::Value{ values.maxCameraDistance },
uniforms::u_rotate_symbol::Value{ rotateInShader },
diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp
index e1a4bee6cd..a4585cbcab 100644
--- a/src/mbgl/renderer/layers/render_circle_layer.cpp
+++ b/src/mbgl/renderer/layers/render_circle_layer.cpp
@@ -54,6 +54,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) {
const bool scaleWithMap = evaluated.get<CirclePitchScale>() == CirclePitchScaleType::Map;
const bool pitchWithMap = evaluated.get<CirclePitchAlignment>() == AlignmentType::Map;
+ const float cameraToCenterDistance = parameters.state.getCameraToCenterDistance();
for (const RenderTile& tile : renderTiles) {
assert(dynamic_cast<CircleBucket*>(tile.tile.getBucket(*baseImpl)));
@@ -76,7 +77,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) {
tile.id.pixelsToTileUnits(1, parameters.state.getZoom()),
tile.id.pixelsToTileUnits(1, parameters.state.getZoom()) }}
: parameters.pixelsToGLUnits },
- uniforms::u_camera_to_center_distance::Value{ parameters.state.getCameraToCenterDistance() },
+ uniforms::u_camera_to_center_distance::Value{ cameraToCenterDistance },
uniforms::u_pitch_with_map::Value{ pitchWithMap }
},
paintPropertyBinders,
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp
index 3a3545122e..4cfbe4ae55 100644
--- a/src/mbgl/renderer/layers/render_symbol_layer.cpp
+++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp
@@ -229,6 +229,9 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
}
}
+ const float cameraToCenterDistance = parameters.state.getCameraToCenterDistance();
+ const float overscaleFactor = tile.tile.id.overscaleFactor();
+
if (bucket.hasCollisionBoxData()) {
static const style::Properties<>::PossiblyEvaluated properties {};
static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0);
@@ -250,7 +253,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
CollisionBoxProgram::UniformValues {
uniforms::u_matrix::Value{ tile.matrix },
uniforms::u_extrude_scale::Value{ extrudeScale },
- uniforms::u_camera_to_center_distance::Value{ parameters.state.getCameraToCenterDistance() }
+ uniforms::u_camera_to_center_distance::Value{ cameraToCenterDistance }
},
*bucket.collisionBox.vertexBuffer,
*bucket.collisionBox.dynamicVertexBuffer,
@@ -284,8 +287,8 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
CollisionCircleProgram::UniformValues {
uniforms::u_matrix::Value{ tile.matrix },
uniforms::u_extrude_scale::Value{ extrudeScale },
- uniforms::u_overscale_factor::Value{ float(tile.tile.id.overscaleFactor()) },
- uniforms::u_camera_to_center_distance::Value{ parameters.state.getCameraToCenterDistance() }
+ uniforms::u_overscale_factor::Value{ overscaleFactor },
+ uniforms::u_camera_to_center_distance::Value{ cameraToCenterDistance }
},
*bucket.collisionCircle.vertexBuffer,
*bucket.collisionCircle.dynamicVertexBuffer,
diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp
index 3fb5cab35c..10c0e69a8e 100644
--- a/src/mbgl/renderer/tile_pyramid.cpp
+++ b/src/mbgl/renderer/tile_pyramid.cpp
@@ -251,7 +251,7 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
}
}
-void TilePyramid::handleWrapJump(float lng) {
+void TilePyramid::handleWrapJump(double lng) {
// On top of the regular z/x/y values, TileIDs have a `wrap` value that specify
// which cppy of the world the tile belongs to. For example, at `lng: 10` you
// might render z/x/y/0 while at `lng: 370` you would render z/x/y/1.
@@ -268,9 +268,9 @@ void TilePyramid::handleWrapJump(float lng) {
//
// This enables us to reuse the tiles at more ideal locations and prevent flickering.
- const float lngDifference = lng - prevLng;
- const float worldDifference = lngDifference / 360;
- const int wrapDelta = ::round(worldDifference);
+ const double lngDifference = lng - prevLng;
+ const double worldDifference = lngDifference / 360;
+ const int16_t wrapDelta = ::round(worldDifference);
prevLng = lng;
if (wrapDelta) {
diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp
index 4e5f50fd52..c9d14af449 100644
--- a/src/mbgl/renderer/tile_pyramid.hpp
+++ b/src/mbgl/renderer/tile_pyramid.hpp
@@ -49,7 +49,7 @@ public:
std::vector<std::reference_wrapper<RenderTile>> getRenderTiles();
Tile* getTile(const OverscaledTileID&);
- void handleWrapJump(float lng);
+ void handleWrapJump(double lng);
std::unordered_map<std::string, std::vector<Feature>>
queryRenderedFeatures(const ScreenLineString& geometry,
@@ -75,7 +75,7 @@ public:
TileObserver* observer = nullptr;
- float prevLng = 0;
+ double prevLng = 0;
};
} // namespace mbgl
diff --git a/src/mbgl/tile/tile_id_io.cpp b/src/mbgl/tile/tile_id_io.cpp
index d8be6b93d6..360de131eb 100644
--- a/src/mbgl/tile/tile_id_io.cpp
+++ b/src/mbgl/tile/tile_id_io.cpp
@@ -18,12 +18,12 @@ std::string toString(const CanonicalTileID& rhs) {
} // namespace util
::std::ostream& operator<<(::std::ostream& os, const OverscaledTileID& rhs) {
- return os << rhs.canonical << "=>" << uint32_t(rhs.overscaledZ);
+ return os << rhs.canonical << "=>" << uint32_t(rhs.overscaledZ) << (rhs.wrap >= 0 ? "+" : "") << rhs.wrap;
}
namespace util {
std::string toString(const OverscaledTileID& rhs) {
- return util::toString(rhs.canonical) + "=>" + util::toString(rhs.overscaledZ);
+ return util::toString(rhs.canonical) + "=>" + util::toString(rhs.overscaledZ) + (rhs.wrap >= 0 ? "+" : "") + util::toString(rhs.wrap);
}
} // namespace util
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index 3eb200bcc1..cfad59a313 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -36,8 +36,8 @@ struct edge {
// scan-line conversion
static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine scanLine) {
- double y0 = ::fmax(ymin, std::floor(e1.y0));
- double y1 = ::fmin(ymax, std::ceil(e1.y1));
+ double y0 = util::max(double(ymin), std::floor(e1.y0));
+ double y1 = util::min(double(ymax), std::ceil(e1.y1));
// sort edges by x-coordinate
if ((e0.x0 == e1.x0 && e0.y0 == e1.y0) ?
@@ -52,8 +52,8 @@ static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine sca
double d0 = e0.dx > 0; // use y + 1 to compute x0
double d1 = e1.dx < 0; // use y + 1 to compute x1
for (int32_t y = y0; y < y1; y++) {
- double x0 = m0 * ::fmax(0, ::fmin(e0.dy, y + d0 - e0.y0)) + e0.x0;
- double x1 = m1 * ::fmax(0, ::fmin(e1.dy, y + d1 - e1.y0)) + e1.x0;
+ double x0 = m0 * util::max(0.0, util::min(e0.dy, y + d0 - e0.y0)) + e0.x0;
+ double x1 = m1 * util::max(0.0, util::min(e1.dy, y + d1 - e1.y0)) + e1.x0;
scanLine(std::floor(x1), std::ceil(x0), y);
}
}
@@ -203,7 +203,7 @@ std::vector<UnwrappedTileID> tileCover(const TransformState& state, uint8_t z, T
TileCoordinate::fromScreenCoordinate(state, z, { w, 0 }).p,
TileCoordinate::fromScreenCoordinate(state, z, { w, h }).p,
TileCoordinate::fromScreenCoordinate(state, z, { 0, h }).p,
- TileCoordinate::fromScreenCoordinate(state, z, { w/2, h/2 }).p,
+ TileCoordinate::fromScreenCoordinate(state, z, { w / 2.0, h / 2.0 }).p,
z, mode, state.getBearing());
}