Render sprited icons at 2x resolution since we don't align to pixel grid

This provides the sampler with a bit more data when positioning sprites at subpixel positions.

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo
2021-04-28 09:32:38 -06:00
co-authored by Antonio Scandurra
parent 69cc2b0483
commit 8c51bb253d
2 changed files with 14 additions and 29 deletions
+1 -18
View File
@@ -137,30 +137,13 @@ impl SpriteCache {
pub fn render_icon(
&mut self,
size: Vector2F,
size: Vector2I,
path: Cow<'static, str>,
svg: usvg::Tree,
target_position: Vector2F,
scale_factor: f32,
) -> IconSprite {
const SUBPIXEL_VARIANTS: u8 = 4;
let target_position = target_position * scale_factor;
let subpixel_variant = (
(target_position.x().fract() * SUBPIXEL_VARIANTS as f32).round() as u8
% SUBPIXEL_VARIANTS,
(target_position.y().fract() * SUBPIXEL_VARIANTS as f32).round() as u8
% SUBPIXEL_VARIANTS,
);
let subpixel_shift = vec2f(
subpixel_variant.0 as f32 / SUBPIXEL_VARIANTS as f32,
subpixel_variant.1 as f32 / SUBPIXEL_VARIANTS as f32,
);
let atlases = &mut self.atlases;
let atlas_size = self.atlas_size;
let device = &self.device;
let size = (size * scale_factor).round().to_i32();
assert!(size.x() < atlas_size.x());
assert!(size.y() < atlas_size.y());
self.icons