Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions impeller/entity/entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Matrix Entity::GetShaderTransform(const RenderPass& pass) const {
Matrix Entity::GetShaderTransform(Scalar shader_clip_depth,
const RenderPass& pass,
const Matrix& transform) {
return Matrix::MakeTranslation({0, 0, shader_clip_depth}) *
Matrix::MakeScale({1, 1, Entity::kDepthEpsilon}) *
return Matrix::MakeTranslateScale({1, 1, Entity::kDepthEpsilon},
{0, 0, shader_clip_depth}) *
pass.GetOrthographicTransform() * transform;
}

Expand Down
10 changes: 10 additions & 0 deletions impeller/geometry/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ struct Matrix {
// clang-format on
}

static constexpr Matrix MakeTranslateScale(const Vector3& s,
const Vector3& t) {
// clang-format off
return Matrix(s.x, 0.0f, 0.0f, 0.0f,
0.0f, s.y, 0.0f, 0.0f,
0.0f, 0.0f, s.z, 0.0f,
t.x , t.y, t.z, 1.0f);
// clang-format on
}

static constexpr Matrix MakeScale(const Vector2& s) {
return MakeScale(Vector3(s.x, s.y, 1.0f));
}
Expand Down
15 changes: 15 additions & 0 deletions impeller/geometry/matrix_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,20 @@ TEST(MatrixTest, TranslateWithPerspective) {
0.0, 2.0, 0.0, 430.0)));
}

TEST(MatrixTest, MakeScaleTranslate) {
EXPECT_TRUE(MatrixNear(
Matrix::MakeTranslateScale({1, 1, 1.0 / 1024}, {10, 10, 1.0 / 1024}),
Matrix::MakeTranslation({10, 10, 1.0 / 1024}) *
Matrix::MakeScale({1, 1, 1.0 / 1024})));

EXPECT_TRUE(MatrixNear(
Matrix::MakeTranslateScale({2, 2, 2}, {10, 10, 0}),
Matrix::MakeTranslation({10, 10, 0}) * Matrix::MakeScale({2, 2, 2})));

EXPECT_TRUE(MatrixNear(
Matrix::MakeTranslateScale({0, 0, 0}, {0, 0, 0}),
Matrix::MakeTranslation({0, 0, 0}) * Matrix::MakeScale({0, 0, 0})));
}

} // namespace testing
} // namespace impeller