forked from 1b-agent/opencadstudio-upstream
Raster images show square pixels when magnified
Raster image textures use nearest magnification; PDF pages and OLE pictures keep bilinear filtering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
857f2f2e58
commit
46fa08a041
2 files changed
+26
-12
No files matched your search
@@ -109,6 +109,9 @@ pub struct ImageModel {
|
|||||||
/// (when the entity carries a clip boundary) the triangulated clip polygon
|
/// (when the entity carries a clip boundary) the triangulated clip polygon
|
||||||
/// — so the raster is drawn only inside its clip boundary.
|
/// — so the raster is drawn only inside its clip boundary.
|
||||||
pub verts: Vec<ImageQuadVertex>,
|
pub verts: Vec<ImageQuadVertex>,
|
||||||
|
/// Magnified pixels stay square (raster images); otherwise they blend
|
||||||
|
/// (PDF pages, OLE pictures).
|
||||||
|
pub pixelated: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageModel {
|
impl ImageModel {
|
||||||
@@ -179,6 +182,7 @@ impl ImageModel {
|
|||||||
corners_low,
|
corners_low,
|
||||||
draw_depth: 0.0,
|
draw_depth: 0.0,
|
||||||
verts,
|
verts,
|
||||||
|
pixelated: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,6 +287,7 @@ impl ImageModel {
|
|||||||
corners_low,
|
corners_low,
|
||||||
draw_depth: 0.0,
|
draw_depth: 0.0,
|
||||||
verts,
|
verts,
|
||||||
|
pixelated: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -363,6 +368,7 @@ impl ImageModel {
|
|||||||
corners_low,
|
corners_low,
|
||||||
draw_depth: 0.0,
|
draw_depth: 0.0,
|
||||||
verts,
|
verts,
|
||||||
|
pixelated: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// Group 1 bindings per image:
|
// Group 1 bindings per image:
|
||||||
// binding 0 — texture_2d<f32> (RGBA image texture)
|
// binding 0 — texture_2d<f32> (RGBA image texture)
|
||||||
// binding 1 — sampler (bilinear filtering)
|
// binding 1 — sampler (bilinear; nearest magnification for raster images)
|
||||||
// binding 2 — ImageParams (opacity uniform, 16 bytes)
|
// binding 2 — ImageParams (opacity uniform, 16 bytes)
|
||||||
|
|
||||||
use crate::scene::model::image_model::ImageModel;
|
use crate::scene::model::image_model::ImageModel;
|
||||||
@@ -118,19 +118,27 @@ impl ImageGpu {
|
|||||||
});
|
});
|
||||||
groups[slot].push(model);
|
groups[slot].push(model);
|
||||||
}
|
}
|
||||||
let sampler = Arc::new(device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = |mag_filter| {
|
||||||
label: Some("image.sampler"),
|
Arc::new(device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
label: Some("image.sampler"),
|
||||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||||
mag_filter: wgpu::FilterMode::Linear,
|
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||||
min_filter: wgpu::FilterMode::Linear,
|
mag_filter,
|
||||||
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
|
min_filter: wgpu::FilterMode::Linear,
|
||||||
..Default::default()
|
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
|
||||||
}));
|
..Default::default()
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
// Raster images show square pixels when magnified.
|
||||||
|
let smooth = sampler(wgpu::FilterMode::Linear);
|
||||||
|
let pixelated = sampler(wgpu::FilterMode::Nearest);
|
||||||
groups
|
groups
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|group| Self::new(device, queue, &group, bgl1, &sampler))
|
.flat_map(|group| {
|
||||||
|
let sampler = if group.first().is_some_and(|m| m.pixelated) { &pixelated } else { &smooth };
|
||||||
|
Self::new(device, queue, &group, bgl1, sampler)
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user