Skip to content

Commit

Permalink
Reverting TextureCollection padding change
Browse files Browse the repository at this point in the history
After doing a review of the text rendering code trying to figure out if
anything had changed that could account for glyphs looking different
than they did in v0.10, I realized the texture collection code to deal
with padding for MSAA was a red herring -- the texture is explicitly
created without multisampling. The artifacting was caused by glyphs
sometimes being rendered at subpixel offsets.

The only other change didn't visually affect layout as far as I could
tell, but it's technically more correct -- instead of Kludgine rounding
the run origin, the rounding happens by cosmic_text's physical glyph
function. In theory this might account for slight shifts of individual
runs, but in the limited test I was performing nothing changed.
  • Loading branch information
ecton committed Jan 9, 2025
1 parent 2d8bb23 commit 8087081
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
the underlying render pass.
- `Text::align` allows specifying a `cosmic_text::Align` setting and a width to
perform the alignment within.
- `TextureCollection` now automatically adds padding when multisampling is
enabled to ensure that multisampling does not sample neighboring pixels of
other textures in the collection.
- `Drawing::draw_measured_text` now uses the correct offset when using
`TextOrigin::FirstBaseline`.
- `Graphics::kludgine` and `Graphics::kludgine_mut()` provide access to the
Expand Down
18 changes: 4 additions & 14 deletions src/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::sync::{Arc, PoisonError, RwLock};

use alot::{LotId, Lots};
use etagere::{Allocation, BucketedAtlasAllocator};
use figures::units::{Px, UPx};
use figures::{IntoSigned, IntoUnsigned, Point, Px2D, Rect, Size, UPx2D, Zero};
use figures::units::UPx;
use figures::{IntoSigned, IntoUnsigned, Point, Px2D, Rect, Size, UPx2D};

use crate::pipeline::{PreparedGraphic, Vertex};
use crate::{sealed, CanRenderTo, Graphics, Kludgine, KludgineGraphics, Texture, TextureSource};
Expand Down Expand Up @@ -38,7 +38,6 @@ struct Data {
rects: BucketedAtlasAllocator,
texture: Texture,
textures: Lots<Allocation>,
padding: Px,
}

impl TextureCollection {
Expand All @@ -57,12 +56,6 @@ impl TextureCollection {
filter_mode,
);

let padding = if graphics.multisample_state().count > 1 {
Px::new(1)
} else {
Px::ZERO
};

let initial_size = initial_size.into_signed();
Self {
format,
Expand All @@ -74,7 +67,6 @@ impl TextureCollection {
)),
texture,
textures: Lots::new(),
padding,
})),
}
}
Expand Down Expand Up @@ -115,7 +107,7 @@ impl TextureCollection {
graphics: &impl KludgineGraphics,
) -> CollectedTexture {
let mut this = self.data.write().unwrap_or_else(PoisonError::into_inner);
let allocation_size = size.into_signed() + Size::squared(this.padding * 2);
let allocation_size = size.into_signed();
let allocation = loop {
if let Some(allocation) = this.rects.allocate(etagere::euclid::Size2D::new(
allocation_size.width.get(),
Expand Down Expand Up @@ -151,9 +143,7 @@ impl TextureCollection {
};

let region = Rect::new(
(Point::px(allocation.rectangle.min.x, allocation.rectangle.min.y)
+ Point::squared(this.padding))
.into_unsigned(),
Point::px(allocation.rectangle.min.x, allocation.rectangle.min.y).into_unsigned(),
size,
);

Expand Down
4 changes: 2 additions & 2 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub(crate) fn map_each_glyph(

let buffer = buffer.unwrap_or_else(|| kludgine.text.scratch.as_ref().expect("no buffer"));
for run in buffer.layout_runs() {
let run_origin = (Point::new(Px::ZERO, Px::from(run.line_y)) - relative_to).round();
let run_origin = Point::new(Px::ZERO, Px::from(run.line_y)) - relative_to;
for glyph in run.glyphs {
let physical =
glyph.physical((run_origin.x.into_float(), run_origin.y.into_float()), 1.);
Expand Down Expand Up @@ -547,7 +547,7 @@ pub(crate) fn map_each_glyph(
}
};
map(
blit,
dbg!(blit),
glyph,
(run.line_top / metrics.line_height).round().cast::<usize>(),
Px::from(run.line_y),
Expand Down

0 comments on commit 8087081

Please sign in to comment.