summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-01 16:05:23 +0000
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-01 21:39:36 +0000
commit9346a6d038ee24b6cfd0bd39e311b5e00673c06e (patch)
tree6599a21846bcdf37342f70f955f6a67596705951 /src
parentc6757b9a9b004c566c9ff0b0715d336e668e1410 (diff)
downloadqtlocation-mapboxgl-9346a6d038ee24b6cfd0bd39e311b5e00673c06e.tar.gz
[core] Avoid precompute overscaling for TileID
Plus type change for zoom and removed redundant inlines.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/layer/line_layer.cpp2
-rw-r--r--src/mbgl/layer/symbol_layer.cpp2
-rw-r--r--src/mbgl/map/tile_id.cpp4
-rw-r--r--src/mbgl/map/tile_id.hpp28
-rw-r--r--src/mbgl/renderer/painter.cpp2
-rw-r--r--src/mbgl/renderer/painter_fill.cpp2
-rw-r--r--src/mbgl/renderer/painter_line.cpp6
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp4
-rw-r--r--src/mbgl/source/source.cpp2
-rw-r--r--src/mbgl/source/source_info.hpp4
-rw-r--r--src/mbgl/style/style_parser.cpp4
11 files changed, 32 insertions, 28 deletions
diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp
index edf128fd35..c6ddaee37d 100644
--- a/src/mbgl/layer/line_layer.cpp
+++ b/src/mbgl/layer/line_layer.cpp
@@ -69,7 +69,7 @@ bool LineLayer::recalculate(const StyleCalculationParameters& parameters) {
}
std::unique_ptr<Bucket> LineLayer::createBucket(StyleBucketParameters& parameters) const {
- auto bucket = std::make_unique<LineBucket>(parameters.tileID.overscaling);
+ auto bucket = std::make_unique<LineBucket>(parameters.tileID.overscaling());
bucket->layout = layout;
diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp
index 77254d6f2b..f8a21a4782 100644
--- a/src/mbgl/layer/symbol_layer.cpp
+++ b/src/mbgl/layer/symbol_layer.cpp
@@ -113,7 +113,7 @@ bool SymbolLayer::recalculate(const StyleCalculationParameters& parameters) {
}
std::unique_ptr<Bucket> SymbolLayer::createBucket(StyleBucketParameters& parameters) const {
- auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling,
+ auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling(),
parameters.tileID.z,
parameters.mode);
diff --git a/src/mbgl/map/tile_id.cpp b/src/mbgl/map/tile_id.cpp
index 3058125a20..fe6f2b8eb7 100644
--- a/src/mbgl/map/tile_id.cpp
+++ b/src/mbgl/map/tile_id.cpp
@@ -5,7 +5,7 @@
namespace mbgl {
-TileID TileID::parent(int8_t parent_z, int8_t sourceMaxZoom) const {
+TileID TileID::parent(uint8_t parent_z, uint8_t sourceMaxZoom) const {
assert(parent_z < z);
auto newX = x;
auto newY = y;
@@ -22,7 +22,7 @@ TileID TileID::parent(int8_t parent_z, int8_t sourceMaxZoom) const {
return TileID{parent_z, newX, newY, parent_z > sourceMaxZoom ? sourceMaxZoom : parent_z};
}
-std::forward_list<TileID> TileID::children(int8_t sourceMaxZoom) const {
+std::forward_list<TileID> TileID::children(uint8_t sourceMaxZoom) const {
auto childZ = z + 1;
std::forward_list<TileID> child_ids;
diff --git a/src/mbgl/map/tile_id.hpp b/src/mbgl/map/tile_id.hpp
index a193b63392..5fa5e45433 100644
--- a/src/mbgl/map/tile_id.hpp
+++ b/src/mbgl/map/tile_id.hpp
@@ -13,38 +13,42 @@ namespace mbgl {
class TileID {
public:
const int16_t w = 0;
- const int8_t z = 0;
- const int32_t x = 0, y = 0;
- const int8_t sourceZ;
- const float overscaling;
+ const uint8_t z;
+ const int32_t x;
+ const int32_t y;
+ const uint8_t sourceZ;
- inline explicit TileID(int8_t z_, int32_t x_, int32_t y_, int8_t sourceZ_)
+ explicit TileID(uint8_t z_, int32_t x_, int32_t y_, uint8_t sourceZ_)
: w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_),
- sourceZ(sourceZ_), overscaling(std::pow(2, z_ - sourceZ_)) {}
+ sourceZ(sourceZ_) {}
- inline uint64_t to_uint64() const {
+ uint64_t to_uint64() const {
return ((std::pow(2, z) * y + x) * 32) + z;
}
- inline bool operator==(const TileID& rhs) const {
+ float overscaling() const {
+ return std::pow(2, z - sourceZ);
+ }
+
+ bool operator==(const TileID& rhs) const {
return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y;
}
- inline bool operator!=(const TileID& rhs) const {
+ bool operator!=(const TileID& rhs) const {
return !operator==(rhs);
}
- inline bool operator<(const TileID& rhs) const {
+ bool operator<(const TileID& rhs) const {
if (w != rhs.w) return w < rhs.w;
if (z != rhs.z) return z < rhs.z;
if (x != rhs.x) return x < rhs.x;
return y < rhs.y;
}
- TileID parent(int8_t z, int8_t sourceMaxZoom) const;
+ TileID parent(uint8_t z, uint8_t sourceMaxZoom) const;
TileID normalized() const;
std::forward_list<TileID>
- children(int8_t sourceMaxZoom = std::numeric_limits<int8_t>::max()) const;
+ children(uint8_t sourceMaxZoom = std::numeric_limits<uint8_t>::max()) const;
bool isChildOf(const TileID&) const;
operator std::string() const;
};
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index f1210364a3..6cf2afc228 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -344,7 +344,7 @@ 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)(1 << id.z)) / state.getScale() * (util::EXTENT / util::tileSize / id.overscaling);
+ const double factor = ((double)(1 << id.z)) / state.getScale() * (util::EXTENT / util::tileSize / id.overscaling());
mat4 vtxMatrix;
if (anchor == TranslateAnchorType::Viewport) {
diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp
index cd54645c2b..7f632f1961 100644
--- a/src/mbgl/renderer/painter_fill.cpp
+++ b/src/mbgl/renderer/painter_fill.cpp
@@ -65,7 +65,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI
// Image fill.
if (pass == RenderPass::Translucent && posA && posB) {
- float factor = (util::EXTENT / util::tileSize / std::pow(2, state.getIntegerZoom() - id.z)) / id.overscaling;
+ float factor = (util::EXTENT / util::tileSize / std::pow(2, state.getIntegerZoom() - id.z)) / id.overscaling();
mat3 patternMatrixA;
matrix::identity(patternMatrixA);
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index 5fc5ee0221..e18206b1f7 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -51,7 +51,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
color[2] *= properties.opacity;
color[3] *= properties.opacity;
- float ratio = state.getScale() / std::pow(2, id.z) / (util::EXTENT / (512.0 * id.overscaling));
+ float ratio = state.getScale() / std::pow(2, id.z) / (util::EXTENT / (512.0 * id.overscaling()));
mat2 antialiasingMatrix;
matrix::identity(antialiasingMatrix);
@@ -85,7 +85,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
const float widthA = posA.width * properties.dasharray.value.fromScale;
const float widthB = posB.width * properties.dasharray.value.toScale;
- float patternratio = std::pow(2.0, std::floor(::log2(state.getScale())) - id.z) / (util::EXTENT / util::tileSize) * id.overscaling;
+ float patternratio = std::pow(2.0, std::floor(::log2(state.getScale())) - id.z) / (util::EXTENT / util::tileSize) * id.overscaling();
float scaleXA = patternratio / widthA / properties.dashLineWidth;
float scaleYA = -posA.height / 2.0;
float scaleXB = patternratio / widthB / properties.dashLineWidth;
@@ -111,7 +111,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI
if (!imagePosA || !imagePosB)
return;
- float factor = util::EXTENT / (512 * id.overscaling) / std::pow(2, state.getIntegerZoom() - id.z);
+ float factor = util::EXTENT / (512 * id.overscaling()) / std::pow(2, state.getIntegerZoom() - id.z);
config.program = linepatternShader->getID();
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index 5f59d6a8a6..a460af400b 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -34,7 +34,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
if (skewed) {
matrix::identity(exMatrix);
- s = util::EXTENT / util::tileSize / id.overscaling / std::pow(2, state.getZoom() - id.z);
+ s = util::EXTENT / util::tileSize / id.overscaling() / std::pow(2, state.getZoom() - id.z);
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 / id.overscaling / std::pow(2, state.getZoom() - id.z);
+ s = util::EXTENT / util::tileSize / id.overscaling() / std::pow(2, state.getZoom() - id.z);
} else {
exMatrix = extrudeMatrix;
matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle());
diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp
index 8947e4f988..967a829ee9 100644
--- a/src/mbgl/source/source.cpp
+++ b/src/mbgl/source/source.cpp
@@ -160,7 +160,7 @@ void Source::load(FileSource& fileSource) {
void Source::updateMatrices(const mat4 &projMatrix, const TransformState &transform) {
for (const auto& pair : tiles) {
Tile &tile = *pair.second;
- transform.matrixFor(tile.matrix, tile.id, std::min(static_cast<int8_t>(info->maxZoom), tile.id.z));
+ transform.matrixFor(tile.matrix, tile.id, std::min(static_cast<uint8_t>(info->maxZoom), tile.id.z));
matrix::multiply(tile.matrix, projMatrix, tile.matrix);
}
}
diff --git a/src/mbgl/source/source_info.hpp b/src/mbgl/source/source_info.hpp
index db584d9e33..ceae8ef8a3 100644
--- a/src/mbgl/source/source_info.hpp
+++ b/src/mbgl/source/source_info.hpp
@@ -17,8 +17,8 @@ class TileID;
class SourceInfo {
public:
std::vector<std::string> tiles;
- uint16_t minZoom = 0;
- uint16_t maxZoom = 22;
+ uint8_t minZoom = 0;
+ uint8_t maxZoom = 22;
std::string attribution;
LatLng center;
double zoom = 0;
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index 797f20adeb..ca0fe94056 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -59,7 +59,7 @@ void parseTileJSONMember(const JSValue& value, std::string& target, const char*
target = { property.GetString(), property.GetStringLength() };
}
-void parseTileJSONMember(const JSValue& value, uint16_t& target, const char* name) {
+void parseTileJSONMember(const JSValue& value, uint8_t& target, const char* name) {
if (!value.HasMember(name)) {
return;
}
@@ -70,7 +70,7 @@ void parseTileJSONMember(const JSValue& value, uint16_t& target, const char* nam
}
unsigned int uint = property.GetUint();
- if (uint > std::numeric_limits<uint16_t>::max()) {
+ if (uint > std::numeric_limits<uint8_t>::max()) {
return;
}