Snap icon sprites to pixel grid

This should resolve some rendering artifacts potentially caused by
floating point errors when sampling the texture. It should also lead
to crisper images when icons are rendered midway through a pixel.
This commit is contained in:
Antonio Scandurra 2022-03-28 11:52:13 +02:00
parent 3ae5fc74c9
commit f69bd0e327

View file

@ -561,9 +561,10 @@ impl Renderer {
} }
for icon in icons { for icon in icons {
let origin = icon.bounds.origin() * scale_factor; // Snap sprite to pixel grid.
let target_size = icon.bounds.size() * scale_factor; let origin = (icon.bounds.origin() * scale_factor).floor();
let source_size = (target_size * 2.).ceil().to_i32(); let target_size = (icon.bounds.size() * scale_factor).ceil();
let source_size = (target_size * 2.).to_i32();
let sprite = let sprite =
self.sprite_cache self.sprite_cache