@@ -1,10 +1,15 @@
|
||||
#include <mbgl/map/tile_id.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
float TileID::pixelsToTileUnits(float pixelValue, float zoom) const {
|
||||
return pixelValue * (util::EXTENT / (util::tileSize * overscaleFactor() * std::pow(2, zoom - z)));
|
||||
}
|
||||
|
||||
TileID TileID::parent(uint8_t parent_z, uint8_t sourceMaxZoom) const {
|
||||
assert(parent_z < z);
|
||||
auto newX = x;
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
return y < rhs.y;
|
||||
}
|
||||
|
||||
float pixelsToTileUnits(float pixelValue, float zoom) const;
|
||||
TileID parent(uint8_t z, uint8_t sourceMaxZoom) const;
|
||||
TileID normalized() const;
|
||||
std::forward_list<TileID>
|
||||
|
||||
@@ -260,20 +260,19 @@ mat4 Painter::translatedMatrix(const mat4& matrix, const std::array<float, 2> &t
|
||||
if (translation[0] == 0 && translation[1] == 0) {
|
||||
return matrix;
|
||||
} else {
|
||||
const double factor = double(1ll << id.sourceZ) * util::EXTENT / util::tileSize / state.getScale();
|
||||
|
||||
mat4 vtxMatrix;
|
||||
if (anchor == TranslateAnchorType::Viewport) {
|
||||
const double sin_a = std::sin(-state.getAngle());
|
||||
const double cos_a = std::cos(-state.getAngle());
|
||||
matrix::translate(vtxMatrix, matrix,
|
||||
factor * (translation[0] * cos_a - translation[1] * sin_a),
|
||||
factor * (translation[0] * sin_a + translation[1] * cos_a),
|
||||
id.pixelsToTileUnits(translation[0] * cos_a - translation[1] * sin_a, state.getZoom()),
|
||||
id.pixelsToTileUnits(translation[0] * sin_a + translation[1] * cos_a, state.getZoom()),
|
||||
0);
|
||||
} else {
|
||||
matrix::translate(vtxMatrix, matrix,
|
||||
factor * translation[0],
|
||||
factor * translation[1],
|
||||
id.pixelsToTileUnits(translation[0], state.getZoom()),
|
||||
id.pixelsToTileUnits(translation[1], state.getZoom()),
|
||||
0);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
|
||||
|
||||
if (isPatterned) {
|
||||
patternShader->u_matrix = vtxMatrix;
|
||||
const float factor = util::EXTENT / util::tileSize;
|
||||
|
||||
std::array<int, 2> imageSizeScaledA = {{
|
||||
(int)((*imagePosA).size[0] * properties.pattern.value.fromScale),
|
||||
@@ -75,12 +74,12 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
|
||||
}};
|
||||
|
||||
patternShader->u_patternscale_a = {{
|
||||
1.0f / (factor * imageSizeScaledA[0]),
|
||||
1.0f / (factor * imageSizeScaledA[1])
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledA[0], state.getIntegerZoom()),
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledA[1], state.getIntegerZoom())
|
||||
}};
|
||||
patternShader->u_patternscale_b = {{
|
||||
1.0f / (factor * imageSizeScaledB[0]),
|
||||
1.0f / (factor * imageSizeScaledB[1])
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledB[0], state.getIntegerZoom()),
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledB[1], state.getIntegerZoom())
|
||||
}};
|
||||
|
||||
float offsetAx = (std::fmod(util::tileSize, imageSizeScaledA[0]) * id.x) / (float)imageSizeScaledA[0];
|
||||
|
||||
@@ -64,8 +64,6 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
|
||||
|
||||
// Image fill.
|
||||
if (pass == RenderPass::Translucent && posA && posB) {
|
||||
const float factor =
|
||||
(util::EXTENT / util::tileSize / std::pow(2, state.getIntegerZoom() - id.sourceZ));
|
||||
|
||||
config.program = patternShader->getID();
|
||||
patternShader->u_matrix = vtxMatrix;
|
||||
@@ -87,12 +85,12 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
|
||||
}};
|
||||
|
||||
patternShader->u_patternscale_a = {{
|
||||
1.0f / (factor * imageSizeScaledA[0]),
|
||||
1.0f / (factor * imageSizeScaledA[1])
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledA[0], state.getIntegerZoom()),
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledB[1], state.getIntegerZoom())
|
||||
}};
|
||||
patternShader->u_patternscale_b = {{
|
||||
1.0f / (factor * imageSizeScaledB[0]),
|
||||
1.0f / (factor * imageSizeScaledB[1])
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledB[0], state.getIntegerZoom()),
|
||||
1.0f / id.pixelsToTileUnits(imageSizeScaledB[1], state.getIntegerZoom())
|
||||
}};
|
||||
|
||||
float offsetAx = (std::fmod(util::tileSize, imageSizeScaledA[0]) * id.x) / (float)imageSizeScaledA[0];
|
||||
|
||||
@@ -51,7 +51,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
|
||||
color[2] *= properties.opacity;
|
||||
color[3] *= properties.opacity;
|
||||
|
||||
const float ratio = state.getScale() / (1ll << id.sourceZ) * util::tileSize / util::EXTENT;
|
||||
const float ratio = 1.0 / id.pixelsToTileUnits(1.0, state.getZoom());
|
||||
|
||||
mat2 antialiasingMatrix;
|
||||
matrix::identity(antialiasingMatrix);
|
||||
@@ -83,15 +83,12 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
|
||||
LinePatternPos posB = lineAtlas->getDashPosition(properties.dasharray.value.to, layout.cap == CapType::Round, glObjectStore);
|
||||
lineAtlas->bind(glObjectStore);
|
||||
|
||||
const float widthA = posA.width * properties.dasharray.value.fromScale;
|
||||
const float widthB = posB.width * properties.dasharray.value.toScale;
|
||||
const float widthA = posA.width * properties.dasharray.value.fromScale * properties.dashLineWidth;
|
||||
const float widthB = posB.width * properties.dasharray.value.toScale * properties.dashLineWidth;
|
||||
|
||||
const float patternratio =
|
||||
std::pow(2.0, state.getIntegerZoom() - id.sourceZ) * util::tileSize / util::EXTENT;
|
||||
|
||||
float scaleXA = patternratio / widthA / properties.dashLineWidth;
|
||||
float scaleXA = 1.0 / id.pixelsToTileUnits(widthA, state.getIntegerZoom());
|
||||
float scaleYA = -posA.height / 2.0;
|
||||
float scaleXB = patternratio / widthB / properties.dashLineWidth;
|
||||
float scaleXB = 1.0 / id.pixelsToTileUnits(widthB, state.getIntegerZoom());
|
||||
float scaleYB = -posB.height / 2.0;
|
||||
|
||||
linesdfShader->u_patternscale_a = {{ scaleXA, scaleYA }};
|
||||
@@ -99,7 +96,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
|
||||
linesdfShader->u_patternscale_b = {{ scaleXB, scaleYB }};
|
||||
linesdfShader->u_tex_y_b = posB.y;
|
||||
linesdfShader->u_image = 0;
|
||||
linesdfShader->u_sdfgamma = lineAtlas->width / (properties.dashLineWidth * std::min(widthA, widthB) * 256.0 * data.pixelRatio) / 2;
|
||||
linesdfShader->u_sdfgamma = lineAtlas->width / (std::min(widthA, widthB) * 256.0 * data.pixelRatio) / 2;
|
||||
linesdfShader->u_mix = properties.dasharray.value.t;
|
||||
linesdfShader->u_extra = extra;
|
||||
linesdfShader->u_offset = -properties.offset;
|
||||
@@ -114,8 +111,6 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
|
||||
if (!imagePosA || !imagePosB)
|
||||
return;
|
||||
|
||||
const float factor = util::EXTENT / util::tileSize / std::pow(2.0f, state.getIntegerZoom() - id.sourceZ);
|
||||
|
||||
config.program = linepatternShader->getID();
|
||||
|
||||
linepatternShader->u_matrix = vtxMatrix;
|
||||
@@ -124,12 +119,20 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
|
||||
linepatternShader->u_ratio = ratio;
|
||||
linepatternShader->u_blur = blur;
|
||||
|
||||
linepatternShader->u_pattern_size_a = {{(*imagePosA).size[0] * factor * properties.pattern.value.fromScale, (*imagePosA).size[1]}};
|
||||
linepatternShader->u_pattern_size_a = {{
|
||||
id.pixelsToTileUnits((*imagePosA).size[0] * properties.pattern.value.fromScale, state.getIntegerZoom()),
|
||||
(*imagePosA).size[1]
|
||||
}};
|
||||
linepatternShader->u_pattern_tl_a = (*imagePosA).tl;
|
||||
linepatternShader->u_pattern_br_a = (*imagePosA).br;
|
||||
linepatternShader->u_pattern_size_b = {{(*imagePosB).size[0] * factor * properties.pattern.value.toScale, (*imagePosB).size[1]}};
|
||||
|
||||
linepatternShader->u_pattern_size_b = {{
|
||||
id.pixelsToTileUnits((*imagePosB).size[0] * properties.pattern.value.toScale, state.getIntegerZoom()),
|
||||
(*imagePosB).size[1]
|
||||
}};
|
||||
linepatternShader->u_pattern_tl_b = (*imagePosB).tl;
|
||||
linepatternShader->u_pattern_br_b = (*imagePosB).br;
|
||||
|
||||
linepatternShader->u_fade = properties.pattern.value.t;
|
||||
linepatternShader->u_opacity = properties.opacity;
|
||||
linepatternShader->u_extra = extra;
|
||||
|
||||
@@ -34,7 +34,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
|
||||
|
||||
if (skewed) {
|
||||
matrix::identity(exMatrix);
|
||||
s = util::EXTENT / util::tileSize / std::pow(2, state.getZoom() - id.sourceZ);
|
||||
s = id.pixelsToTileUnits(1, state.getZoom());
|
||||
gammaScale = 1.0f / std::cos(state.getPitch());
|
||||
} else {
|
||||
exMatrix = extrudeMatrix;
|
||||
@@ -195,7 +195,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const
|
||||
|
||||
if (skewed) {
|
||||
matrix::identity(exMatrix);
|
||||
s = util::EXTENT / util::tileSize / std::pow(2, state.getZoom() - id.sourceZ);
|
||||
s = id.pixelsToTileUnits(1, state.getZoom());
|
||||
} else {
|
||||
exMatrix = extrudeMatrix;
|
||||
matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle());
|
||||
|
||||
Reference in New Issue
Block a user