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 <[email protected]>
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
|
||||
/// — so the raster is drawn only inside its clip boundary.
|
||||
pub verts: Vec<ImageQuadVertex>,
|
||||
/// Magnified pixels stay square (raster images); otherwise they blend
|
||||
/// (PDF pages, OLE pictures).
|
||||
pub pixelated: bool,
|
||||
}
|
||||
|
||||
impl ImageModel {
|
||||
@@ -179,6 +182,7 @@ impl ImageModel {
|
||||
corners_low,
|
||||
draw_depth: 0.0,
|
||||
verts,
|
||||
pixelated: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -283,6 +287,7 @@ impl ImageModel {
|
||||
corners_low,
|
||||
draw_depth: 0.0,
|
||||
verts,
|
||||
pixelated: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -363,6 +368,7 @@ impl ImageModel {
|
||||
corners_low,
|
||||
draw_depth: 0.0,
|
||||
verts,
|
||||
pixelated: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Group 1 bindings per image:
|
||||
// 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)
|
||||
|
||||
use crate::scene::model::image_model::ImageModel;
|
||||
@@ -118,19 +118,27 @@ impl ImageGpu {
|
||||
});
|
||||
groups[slot].push(model);
|
||||
}
|
||||
let sampler = Arc::new(device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
label: Some("image.sampler"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Linear,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
|
||||
..Default::default()
|
||||
}));
|
||||
let sampler = |mag_filter| {
|
||||
Arc::new(device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
label: Some("image.sampler"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
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
|
||||
.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()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user