Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
29 changes: 25 additions & 4 deletions apps/lightcraft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,38 @@ struct WindowTextures {
renderer: std::sync::Arc<egui::mutex::RwLock<eframe::egui_wgpu::Renderer>>,
}

/// The window sampler for a GPU-resident view: the filters the renderer chose for the slot (nearest
/// magnification for a native-resolution photo past 100 %, #2643), edges clamped as for egui's own
/// textures.
fn view_sampler(options: egui::TextureOptions) -> eframe::wgpu::SamplerDescriptor<'static> {
let filter = |f: egui::TextureFilter| match f {
egui::TextureFilter::Nearest => eframe::wgpu::FilterMode::Nearest,
egui::TextureFilter::Linear => eframe::wgpu::FilterMode::Linear,
};
eframe::wgpu::SamplerDescriptor {
label: Some("lightcraft view"),
mag_filter: filter(options.magnification),
min_filter: filter(options.minification),
..Default::default()
}
}

impl lightcraft_ui_egui::render::ScreenTextures for WindowTextures {
fn show(&mut self, frame: &lightcraft_engine::media::ScreenFrame, id: Option<egui::TextureId>) -> Option<egui::TextureId> {
fn show(
&mut self,
frame: &lightcraft_engine::media::ScreenFrame,
id: Option<egui::TextureId>,
options: egui::TextureOptions,
) -> Option<egui::TextureId> {
let view = frame.texture.create_view(&Default::default());
let mut r = self.renderer.write();
let filter = eframe::wgpu::FilterMode::Linear;
let sampler = view_sampler(options);
Some(match id {
Some(id) => {
r.update_egui_texture_from_wgpu_texture(&self.device, &view, filter, id);
r.update_egui_texture_from_wgpu_texture_with_sampler_options(&self.device, &view, sampler, id);
id
}
None => r.register_native_texture(&self.device, &view, filter),
None => r.register_native_texture_with_sampler_options(&self.device, &view, sampler),
})
}

Expand Down
13 changes: 13 additions & 0 deletions apps/lightcraft/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
use super::*;

/// #2643: a GPU-resident view is registered with the sampler the renderer chose: nearest
/// magnification and linear minification for a native-resolution photo past 100 %, linear
/// otherwise (before, the window used one linear sampler for every view).
#[test]
fn gpu_views_use_the_sampler_the_renderer_chose() {
let nearest = egui::TextureOptions { magnification: egui::TextureFilter::Nearest, ..egui::TextureOptions::LINEAR };
let s = view_sampler(nearest);
assert_eq!((s.mag_filter, s.min_filter), (eframe::wgpu::FilterMode::Nearest, eframe::wgpu::FilterMode::Linear));
let s = view_sampler(egui::TextureOptions::LINEAR);
assert_eq!((s.mag_filter, s.min_filter), (eframe::wgpu::FilterMode::Linear, eframe::wgpu::FilterMode::Linear));
assert_eq!(s.address_mode_u, eframe::wgpu::AddressMode::ClampToEdge);
}

#[test]
fn desktop_clear_color_stays_opaque_with_a_modal_open() {
let mut app = App(
Expand Down
2 changes: 2 additions & 0 deletions crates/ui-egui/examples/thumb_request_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ fn micro(points: usize, pending: bool) {
histogram: None,
ms: 0.0,
quick: None,
full_res: false,
first_pixel: Some(egui::Color32::GRAY),
pixels: None,
native: None,
slide_photo: None,
Expand Down
11 changes: 11 additions & 0 deletions crates/ui-egui/src/panels/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ fn request_thumb(app: &mut LightcraftApp, id: PhotoId) {
}
}

/// Survey always fits; interactive panes use the mode after this frame's zoom gesture.
fn tile_texture_zoom(app: &mut LightcraftApp, slot: Slot, zoom: Zoom) -> Zoom {
let zoom = if matches!(app.ui.view, ViewMode::Compare | ViewMode::Reference) { app.ui.zoom } else { zoom };
app.renderer.set_texture_zoom(slot, zoom);
if let Slot::Compare(i) = slot {
app.renderer.set_texture_zoom(Slot::CompareRegion(i), zoom);
}
zoom
}

/// The photo's frame as shown: cropped, rotated and lens-corrected.
fn frame_of(photo: &lightcraft_catalog::Photo) -> lightcraft_pipeline::geometry::Frame {
lightcraft_pipeline::geometry::Frame::with_lens(
Expand Down Expand Up @@ -258,6 +268,7 @@ fn photo_tile(
super::detail::pan_image(app, img_area, img, resp.drag_delta());
}
}
let zoom = tile_texture_zoom(app, slot, zoom);
let texture_side = super::detail::texture_side(ui.ctx());
let want =
(img.width().max(img.height()).min(img_area.width().max(img_area.height()) * 4.0) * ppp).min(2560.0_f32.min(texture_side as f32)) as usize;
Expand Down
10 changes: 6 additions & 4 deletions crates/ui-egui/src/panels/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub use geometry::CanvasMap;
#[cfg(test)]
pub(crate) use geometry::focus_box;
use geometry::{animated_rect, middle_pan};
pub(crate) use geometry::{fit_rect, fit_texture_rect, focus_pan, navigate_gesture, output_px, pan_image, snap_fit_rect, texture_side};
pub(crate) use geometry::{fit_rect, fit_texture_rect, focus_pan, navigate_gesture, output_px, pan_image, render_size, snap_fit_rect, texture_side};
#[cfg(test)]
use info::RENDERING_AFTER_SECS;
use info::camera_preview_badge;
Expand Down Expand Up @@ -248,12 +248,11 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
// The short side is rounded, not truncated: a truncated box (2560 x 1706 for a 2560 x 1707
// source) made the render a slightly anisotropic resample of its source, a 2-tap blur along
// one axis only. A box that matches the source to rounding is rendered at exactly its size.
let short = |e: usize, a: f32| ((e as f32 / a).round() as usize).max(1);
let (rw, rh) = if aspect >= 1.0 { (want, short(want, aspect)) } else { (short(want, 1.0 / aspect), want) };
let (rw, rh) = render_size(want, aspect);
note_loupe_edge(app, sizes.canvas_long, !interacting && !split && !split_view);
// hover and before renders are stand-ins: the preview size is plenty and keeps them cheap
let se = app.ui.settings.stand_in_edge(want, texture_side);
let (sw, sh) = if aspect >= 1.0 { (se, short(se, aspect)) } else { (short(se, 1.0 / aspect), se) };
let (sw, sh) = render_size(se, aspect);
let ask = LoupeAsk { id, with_crop: !crop_tool, interacting, fit_px, overlay };
let settling = request_main_or_settle(app, ui, &ask, [rw, rh], plan.window_edge.is_none(), now);
// hovering a preset or profile: the photo with that look, shown instead of the loupe render
Expand Down Expand Up @@ -299,6 +298,9 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
Vec::new()
};
let windows = request_windows(app, &window_ctx, window_views);
for slot in [Slot::Main, Slot::Before, Slot::Region, Slot::RegionBefore, Slot::Hover] {
app.renderer.set_texture_zoom(slot, app.ui.zoom);
}
let single = hover_key.is_none() && !split && !show_before && !split_view && !interacting;
let camera_full = request_camera_full(app, &photo, single && !windows.is_empty(), native_long.min(texture_side));
let p = ui.painter_at(canvas);
Expand Down
3 changes: 2 additions & 1 deletion crates/ui-egui/src/panels/detail/filmstrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ pub(super) fn navigator(app: &mut LightcraftApp, ui: &mut egui::Ui, canvas: Rect
if !app.ui.navigator || !zoomed || app.ui.fullscreen {
return None;
}
let tex = app.renderer.thumb(id).or_else(|| app.renderer.textures.get(&Slot::Main).filter(|t| t.photo == id));
let aspect = img.width() / img.height().max(1.0);
let (w, h) = if aspect >= 1.0 { (NAV_W, NAV_W / aspect) } else { (NAV_W * aspect, NAV_W) };
let ppp = ui.ctx().pixels_per_point();
let tex = app.renderer.thumb(id).or_else(|| app.renderer.main_for_fit(id, [w * ppp, h * ppp]));
let frame = Rect::from_min_size(pos2(canvas.right() - w - 16.0, canvas.bottom() - h - 16.0), vec2(w, h));
let p = ui.painter_at(canvas);
p.rect_filled(frame.expand(5.0), 4.0, Color32::from_black_alpha(190));
Expand Down
6 changes: 6 additions & 0 deletions crates/ui-egui/src/panels/detail/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ pub(crate) fn output_px(frame: &Frame) -> [usize; 2] {
[px(w), px(h)]
}

/// Render dimensions at a rounded long edge, preserving the frame's aspect to rounding.
pub(crate) fn render_size(edge: usize, aspect: f32) -> (usize, usize) {
let short = |a: f32| ((edge as f32 / a).round() as usize).max(1);
if aspect >= 1.0 { (edge, short(aspect)) } else { (short(1.0 / aspect), edge) }
}

/// The camera's focus point of `photo` in the displayed frame (its crop, rotation and flips), as the
/// normalized box over the drawn image: `None` when the photo has none or it is cropped away.
pub(crate) fn focus_box(photo: &lightcraft_catalog::Photo) -> Option<lightcraft_geom::Rect> {
Expand Down
5 changes: 4 additions & 1 deletion crates/ui-egui/src/panels/second.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ fn body(app: &mut LightcraftApp, ui: &mut egui::Ui) {
app.renderer.request(Slot::Second, job, 95);
}
let mine = |s: Slot| app.renderer.textures.get(&s).filter(|t| t.photo == id);
let tex = mine(Slot::Second).or_else(|| mine(Slot::Main)).or_else(|| app.renderer.thumb(id));
// Main can be explicitly zoomed while this automatic Fit view is open. Do not borrow
// its nearest sampler: use the smooth thumbnail until this window's render is ready.
let tex =
mine(Slot::Second).or_else(|| app.renderer.main_for_fit(id, [area.width() * ppp, area.height() * ppp])).or_else(|| app.renderer.thumb(id));
if let Some(t) = tex {
// (the frame's size: a GPU-resident render's `tex` is only a placeholder)
let [tw, th] = t.size.map(|n| n.max(1));
Expand Down
11 changes: 6 additions & 5 deletions crates/ui-egui/src/panels/slideshow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ fn wanted(play: &Playback, now: f64) -> Vec<(Item, u32)> {
/// The texture to draw for slide `item`: its own render, else (a photo) the loupe's or a
/// thumbnail (a slide stepped to with ←/→ shows at once, sharp when its render lands). A title
/// screen has nothing to stand in for it: the black canvas shows until it lands.
fn texture(app: &LightcraftApp, item: Item) -> Option<&crate::render::Tex> {
fn texture(app: &LightcraftApp, item: Item, physical_bounds: [f32; 2]) -> Option<&crate::render::Tex> {
let Item::Photo(id) = item else { return app.renderer.textures.get(&Slot::Slide(item)) };
slide_texture(app, id).or_else(|| app.renderer.textures.get(&Slot::Main).filter(|t| t.photo == id)).or_else(|| app.renderer.thumb(id))
slide_texture(app, id).or_else(|| app.renderer.main_for_fit(id, physical_bounds)).or_else(|| app.renderer.thumb(id))
}

/// Photo `id`'s own slide render.
Expand Down Expand Up @@ -384,6 +384,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
app.renderer.release_slides(&keep);
let p = ui.painter_at(canvas);
p.rect_filled(canvas, 0.0, Color32::BLACK);
let physical_bounds = [canvas.width() * ui.ctx().pixels_per_point(), canvas.height() * ui.ctx().pixels_per_point()];
let rect_of = |t: &crate::render::Tex| super::detail::fit_texture_rect(canvas, t.size);
let view_of = |id: Item| {
if id == frame.current {
Expand All @@ -395,7 +396,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
}
};
let draw_on = |p: &egui::Painter, id: Item, alpha: f32| -> Option<Rect> {
let t = texture(app, id)?;
let t = texture(app, id, physical_bounds)?;
let r = rect_of(t);
paint(p, t, r, moving_part(app, id, t), view_of(id), Color32::WHITE.gamma_multiply(alpha.clamp(0.0, 1.0)));
Some(r)
Expand All @@ -417,8 +418,8 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) {
// crossfade: where the slides overlap the new one goes over the old at `k`; where only
// the old one is, it fades to the backdrop
(Some(from), None) => {
let new_rect = texture(app, frame.current).map(rect_of);
if let Some(r) = texture(app, from).map(rect_of) {
let new_rect = texture(app, frame.current, physical_bounds).map(rect_of);
if let Some(r) = texture(app, from, physical_bounds).map(rect_of) {
match new_rect {
Some(n) => {
draw_on(&p.with_clip_rect(n.intersect(canvas)), from, 1.0);
Expand Down
Loading
Loading