mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-30 01:53:54 +01:00
Fix 4K preview texture refresh in 2D view (#122)
Users switching to 4K previews saw stale low-resolution textures in the 2D view. Include image dimensions in the texture cache key so a size change reloads the texture at the new resolution. Test: four_k_preview_refreshes_texture_after_size_change failed before the change and passes after. Co-authored-by: eliets2 <287273517+eliets2@users.noreply.github.com> Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
This commit is contained in:
2 files changed
+32
No files matched your search
@@ -95,6 +95,8 @@ pub fn show(app: &mut MaterialCraftApp, ui: &mut Ui) {
|
||||
let texture_limit = ctx.input(|i| i.max_texture_side).max(1);
|
||||
let key = app.session.cooked.nodes.get(&id).map_or(0, |r| r.key)
|
||||
^ (texture_limit as u64).rotate_left(32)
|
||||
^ (img.w as u64).rotate_left(16)
|
||||
^ img.h as u64
|
||||
^ (app.session.view2d.port as u64).wrapping_mul(0x9e37)
|
||||
^ (app.session.view2d.channel.len() as u64 * 31)
|
||||
^ app.session.view2d.channel.bytes().next().unwrap_or(0) as u64;
|
||||
|
||||
@@ -48,6 +48,36 @@ fn selecting_4k_cooks_and_displays_4k_material_maps() {
|
||||
assert_eq!(h.state().view2d.shown.as_ref().map(|(w, h, _)| (*w, *h)), Some((4096, 4096)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn four_k_preview_refreshes_texture_after_size_change() {
|
||||
let mut h = Harness::builder().with_context_setup(materialcraft_ui_egui::theme::install).with_size(vec2(1200.0, 800.0)).build_ui_state(
|
||||
|ui, app: &mut MaterialCraftApp| {
|
||||
app.apply_prefs();
|
||||
view2d::show(app, ui);
|
||||
},
|
||||
app(),
|
||||
);
|
||||
h.input_mut().max_texture_side = Some(4096);
|
||||
// The cooked key alone does not name the input size, so changing size must still refresh.
|
||||
let node = h.state().session.view2d.node.unwrap();
|
||||
h.state_mut().session.preview_size = Some(4096);
|
||||
h.state_mut().session.cook();
|
||||
h.state_mut().session.cooked.nodes.get_mut(&node).unwrap().key = 0;
|
||||
h.state_mut().ui.prefs.preview_size = 4096;
|
||||
h.step();
|
||||
let (_, image) = h.state().session.view2d_image().unwrap();
|
||||
assert_eq!((image.w, image.h), (4096, 4096));
|
||||
assert_eq!(h.state().view2d.shown.as_ref().map(|(w, h, _)| (*w, *h)), Some((4096, 4096)));
|
||||
h.state_mut().session.preview_size = Some(256);
|
||||
h.state_mut().session.cook();
|
||||
h.state_mut().session.cooked.nodes.get_mut(&node).unwrap().key = 0;
|
||||
h.state_mut().ui.prefs.preview_size = 256;
|
||||
h.step();
|
||||
let (_, image) = h.state().session.view2d_image().unwrap();
|
||||
assert_eq!((image.w, image.h), (256, 256));
|
||||
assert_eq!(h.state().view2d.shown.as_ref().map(|(w, h, _)| (*w, *h)), Some((256, 256)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_resolution_survives_preferences_and_invalid_requests() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in new issue
Block a user