return refs to avoid matrix allocation/deallocation for untranslated layers

refs #189
This commit is contained in:
Konstantin Käfer
2014-05-14 17:21:12 +02:00
parent a27f8798ff
commit a9d559fe51
6 changed files with 11 additions and 10 deletions

View File

@@ -171,28 +171,28 @@ void Painter::renderTileLayer(const Tile& tile, const LayerDescription &layer_de
}
}
mat4 Painter::translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor) {
const mat4 &Painter::translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor) {
if (translation[0] == 0 && translation[1] == 0) {
return matrix;
} else {
// TODO: Get rid of the 8 (scaling from 4096 to tile size)
const double factor = ((double)(1 << id.z)) / map.getState().getScale() * (4096.0 / util::tileSize);
mat4 result;
if (anchor == TranslateAnchor::Viewport) {
const double sin_a = std::sin(-map.getState().getAngle());
const double cos_a = std::cos(-map.getState().getAngle());
matrix::translate(result, matrix,
matrix::translate(vtxMatrix, matrix,
factor * (translation[0] * cos_a - translation[1] * sin_a),
factor * (translation[0] * sin_a + translation[1] * cos_a),
0);
} else {
matrix::translate(result, matrix,
matrix::translate(vtxMatrix, matrix,
factor * translation[0],
factor * translation[1],
0);
}
return result;
return vtxMatrix;
}
}