diff options
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/programs/symbol_program.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_circle_layer.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_symbol_layer.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/renderer/tile_pyramid.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/renderer/tile_pyramid.hpp | 4 |
7 files changed, 37 insertions, 29 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index c740e6e87d..0cda016efa 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -44,11 +44,13 @@ 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 aspect = double(size.width) / size.height; - matrix::perspective(projMatrix, getFieldOfView(), aspect, nearZ, farZ); + // Double FOV breaks here: https://github.com/mapbox/mapbox-gl-native/issues/12506 + matrix::perspective(projMatrix, static_cast<float>(getFieldOfView()), aspect, nearZ, farZ); const bool flippedY = viewportMode == ViewportMode::FlippedY; matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1); @@ -260,7 +262,7 @@ double TransformState::getMaxPitch() const { #pragma mark - Rotation -float TransformState::getBearing() const { +double TransformState::getBearing() const { return bearing; } @@ -268,15 +270,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; } @@ -374,7 +376,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; @@ -449,7 +451,7 @@ void TransformState::setLatLngZoom(const LatLng& latLng, double zoom) { constrainToViewport(); } -float TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) const { +double TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) const { mat4 projectionMatrix; getProjMatrix(projectionMatrix); mat4 tileProjectionMatrix; @@ -461,11 +463,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 f30e551a97..84be8f955b 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 07d07ff0dd..3b5473955c 100644 --- a/src/mbgl/programs/symbol_program.cpp +++ b/src/mbgl/programs/symbol_program.cpp @@ -46,13 +46,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 }}; } @@ -91,8 +93,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_rotate_symbol::Value{ rotateInShader }, uniforms::u_aspect_ratio::Value{ state.getSize().aspectRatio() }, diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index de4e5720bf..a877cb30a1 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) { auto bucket_ = tile.tile.getBucket<CircleBucket>(*baseImpl); @@ -79,7 +80,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 63fcb6cfd5..615df577d2 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -232,6 +232,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); @@ -253,7 +256,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, @@ -287,8 +290,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 fd4356ca02..3fcdabd98f 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -240,7 +240,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. @@ -257,9 +257,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 |