summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-12-14 15:48:04 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-12-21 15:46:36 -0800
commit2cf238f74eef021b5dd097822ceafc6da83cf4d3 (patch)
treec66ea401428b2c8f222473f12087e8468d7004e3
parent29099399a91a330c5fdde2e0acaf4c58687574d6 (diff)
downloadqtlocation-mapboxgl-2cf238f74eef021b5dd097822ceafc6da83cf4d3.tar.gz
[core] fix matrix z range and remove hack
ported from -js: 0b5520fa5ab2a4659d80dcffa8b035a0d84fe1ca This should fix the issue behind #2270 and remove the need for the hack added in #3740.
-rw-r--r--src/mbgl/map/transform_state.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 51ecf52e40..f7419fa5b4 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -36,10 +36,13 @@ void TransformState::getProjMatrix(mat4& projMatrix) const {
const double groundAngle = M_PI / 2.0 + getPitch();
const double topHalfSurfaceDistance = std::sin(halfFov) * getCameraToCenterDistance() / std::sin(M_PI - groundAngle - halfFov);
- // Calculate z value of the farthest fragment that should be rendered.
- const double farZ = std::cos(M_PI / 2.0 - getPitch()) * topHalfSurfaceDistance + getCameraToCenterDistance();
- matrix::perspective(projMatrix, getFieldOfView(), double(size.width) / size.height, 0.1, farZ);
+ // Calculate z distance of the farthest fragment that should be rendered.
+ const double furthestDistance = std::cos(M_PI / 2 - getPitch()) * topHalfSurfaceDistance + getCameraToCenterDistance();
+ // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
+ const double farZ = furthestDistance * 1.01;
+
+ matrix::perspective(projMatrix, getFieldOfView(), double(size.width) / size.height, 1, farZ);
const bool flippedY = viewportMode == ViewportMode::FlippedY;
matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1);