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

[core] Transform{,State} cleanups #6790

Merged
merged 5 commits into from
Oct 31, 2016
Merged

Conversation

brunoabinader
Copy link
Member

Reuse TransformState::{zoomScale,scaleZoom,getZoomFraction} and util::log2 whenever possible.

@brunoabinader brunoabinader added the Core The cross-platform C++ core, aka mbgl label Oct 21, 2016
@mention-bot
Copy link

@brunoabinader, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jfirebaugh, @kkaefer and @ansis to be potential reviewers.

@@ -256,8 +256,7 @@ void Painter::renderSymbol(PaintParameters& parameters,
auto& collisionBoxShader = shaders->collisionBox;
context.program = collisionBoxShader.getID();
collisionBoxShader.u_matrix = tile.matrix;
// TODO: This was the overscaled z instead of the canonical z.
collisionBoxShader.u_scale = std::pow(2, state.getZoom() - tile.id.canonical.z);
collisionBoxShader.u_scale = state.zoomScale(state.getZoomFraction());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct in the case of overzoomed tiles?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question - I'm not sure. I'll revert this particular change.

@@ -139,7 +139,7 @@ void GeometryTile::queryRenderedFeatures(
queryGeometry,
transformState.getAngle(),
util::tileSize * id.overscaleFactor(),
std::pow(2, transformState.getZoom() - id.overscaledZ),
transformState.zoomScale(transformState.getZoomFraction()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same question here BTW.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess I didn't account for overscaled zoom on my tests. We can revisit it again with proper unit tests to verify later.

@brunoabinader brunoabinader force-pushed the transformstate-helpers branch 3 times, most recently from 6f3a220 to acbb073 Compare October 24, 2016 06:33
@brunoabinader brunoabinader changed the title [core] Reuse TransformState helpers [core] Transform{,State} cleanups Oct 29, 2016
@brunoabinader brunoabinader force-pushed the transformstate-helpers branch 2 times, most recently from cbee3dc to 689c8b1 Compare October 30, 2016 09:01
@brunoabinader
Copy link
Member Author

Took liberty to include a few other refactors and bug fixes related. Rebased after #6468 (/cc @jfirebaugh).


const float placementZoom = ::fmax(std::log(scale) / std::log(2) + zoom, 0);
static const uint16_t vertexLength = 4;
const float placementZoom = util::max(std::log2(scale) + zoom, 0.0f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using util::log2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops - forgot to update these, thanks!

const auto &anchorPoint = symbol.anchorPoint;

// drop upside down versions of glyphs
const float a = std::fmod(symbol.anchorAngle + placementAngle + M_PI, M_PI * 2);
if (keepUpright && placement == style::SymbolPlacementType::Line &&
(a <= M_PI / 2 || a > M_PI * 3 / 2)) {
(a <= M_PI_2 || a > M_PI_2 * 3)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this makes sense for readability. The compiler almost certainly optimizes this anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough 👍 From reading http://stackoverflow.com/posts/1610346/revisions it seems that using M_PI_2 actually decreases a bit of precision in favor of pre computation.

#endif
}
template <> float log2(float x);
template <> double log2(double x);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these needed? The implementation is all in the header anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accounts for explicit instantiation, which from my understanding instantiates these template specializations to be reused by each compilation unit without duplications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but they are only needed when you want to force certain instances to exist even if they're not used, or when the template definition is in an implementation file.

buffer.segments.emplace_back(buffer.vertices.size(), buffer.triangles.size());
}

// We're generating triangle fans, so we always start with the first
// coordinate in this polygon.
auto& segment = buffer.segments.back();
size_t index = segment.vertexLength;
uint16_t index = uint16_t(segment.vertexLength);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert here that it's <= 65535?

@@ -418,6 +418,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)

template <typename Buffer>
void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const style::SymbolPlacementType placement, const float placementAngle) {
static const uint16_t vertexLength = 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be constexpr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - btw this accounts for the longest type declaration in our codebase: static constexpr const uint16_t 😄

- Added util::{MIN,MAX}_ZOOM_F to avoid consecutive conversions from
double to float
- Move util::log2 to its own header (part of mbgl/math)
@brunoabinader brunoabinader merged commit 7b3e24d into master Oct 31, 2016
@brunoabinader brunoabinader deleted the transformstate-helpers branch October 31, 2016 14:53
@jfirebaugh
Copy link
Contributor

Can you please revert the GL_LINEAR change? Enabling GL_LINEAR during pan-only operations was the intended behavior -- it prevents icons from "wiggling" during the pan.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants