return refs to avoid matrix allocation/deallocation for untranslated layers
refs #189
This commit is contained in:
@@ -89,7 +89,7 @@ public:
|
||||
bool needsAnimation() const;
|
||||
private:
|
||||
void setupShaders();
|
||||
mat4 translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor = TranslateAnchor::Map);
|
||||
const mat4 &translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor = TranslateAnchor::Map);
|
||||
|
||||
void prepareTile(const Tile& tile);
|
||||
void useProgram(uint32_t program);
|
||||
@@ -98,6 +98,7 @@ private:
|
||||
|
||||
public:
|
||||
mat4 matrix;
|
||||
mat4 vtxMatrix;
|
||||
mat4 projMatrix;
|
||||
mat4 nativeMatrix;
|
||||
mat4 extrudeMatrix;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
|
||||
stroke_color = fill_color;
|
||||
}
|
||||
|
||||
const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
|
||||
// Because we're drawing top-to-bottom, and we update the stencil mask
|
||||
// below, we have to draw the outline first (!)
|
||||
|
||||
@@ -33,7 +33,7 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons
|
||||
float dash_length = properties.dash_array[0];
|
||||
float dash_gap = properties.dash_array[1];
|
||||
|
||||
const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
|
||||
glDepthRange(strata, 1.0f);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co
|
||||
imagePos = sprite->getPosition(sized_image, false);
|
||||
}
|
||||
|
||||
const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
|
||||
if (!imagePos.size) {
|
||||
useProgram(dotShader->program);
|
||||
|
||||
@@ -31,7 +31,7 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
|
||||
float fontSize = std::fmin(properties.size, bucket.geom_desc.font_size);
|
||||
matrix::scale(exMatrix, exMatrix, fontSize / 24.0f, fontSize / 24.0f, 1.0f);
|
||||
|
||||
const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
const mat4 &vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
|
||||
|
||||
useProgram(textShader->program);
|
||||
textShader->setMatrix(vtxMatrix);
|
||||
|
||||
Reference in New Issue
Block a user