From f15dd26bb9f39e36417b09a16f40c4ad3d8f48d4 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 6 Aug 2021 16:09:29 +0300 Subject: [PATCH] Snap text vertices to pixels in ui painter --- libs/ui/source/painter_impl.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/ui/source/painter_impl.cpp b/libs/ui/source/painter_impl.cpp index e3f5d78b..148035bd 100644 --- a/libs/ui/source/painter_impl.cpp +++ b/libs/ui/source/painter_impl.cpp @@ -284,10 +284,17 @@ void main() std::uint32_t const depth = impl().depth++; std::uint32_t const base = batch.vertices.size(); - batch.vertices.push_back({rect.corner(0.f, 0.f), depth, color, tc(0.f, 0.f)}); - batch.vertices.push_back({rect.corner(1.f, 0.f), depth, color, tc(1.f, 0.f)}); - batch.vertices.push_back({rect.corner(0.f, 1.f), depth, color, tc(0.f, 1.f)}); - batch.vertices.push_back({rect.corner(1.f, 1.f), depth, color, tc(1.f, 1.f)}); + auto round = [](geom::point p) + { + p[0] = std::round(p[0]); + p[1] = std::round(p[1]); + return p; + }; + + batch.vertices.push_back({round(rect.corner(0.f, 0.f)), depth, color, tc(0.f, 0.f)}); + batch.vertices.push_back({round(rect.corner(1.f, 0.f)), depth, color, tc(1.f, 0.f)}); + batch.vertices.push_back({round(rect.corner(0.f, 1.f)), depth, color, tc(0.f, 1.f)}); + batch.vertices.push_back({round(rect.corner(1.f, 1.f)), depth, color, tc(1.f, 1.f)}); batch.indices.insert(batch.indices.end(), {base + 0, base + 1, base + 2, base + 2, base + 1, base + 3}); }