[core] Avoid precompute overscaling for TileID
Plus type change for zoom and removed redundant inlines.
This commit is contained in:
@@ -22,6 +22,11 @@ inline std::string toString(int8_t num) {
|
||||
return boost::lexical_cast<std::string>(int(num));
|
||||
}
|
||||
|
||||
// boost::lexical_cast() treats this as a character, but we are using it as number types.
|
||||
inline std::string toString(uint8_t num) {
|
||||
return boost::lexical_cast<std::string>(unsigned(num));
|
||||
}
|
||||
|
||||
inline std::string toString(std::exception_ptr error) {
|
||||
try {
|
||||
std::rethrow_exception(error);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user