Scharf statt verpixelt: SVG-Overlay waehrend Pan/Zoom ueber echten viewBox statt CSS-Bitmap-Transform, Griffe skalieren mit, native Flaeche mit 8x MSAA (falls GPU es kann)

This commit is contained in:
karim committed 2026-10-20 00:13:34 +02:00
1 parent b92d6dfed6
commit 3cc3e0c976
4 files changed
+29 -21

No files matched your search

+8 -5
View File
@@ -19,7 +19,6 @@ use wgpu::util::DeviceExt;
use crate::shaders::FILL_WGSL;
const SAMPLE_COUNT: u32 = 4;
/// Graustufe fuer gedimmte Linien (== GREY_RGB in glPlanCompile.ts).
const GREY: f32 = 0.549;
/// Viewbox-Einheiten je Meter (== PX_PER_M).
@@ -205,6 +204,7 @@ pub struct ChunkRenderer {
layout: Vec<ChunkGeom>,
msaa: Option<(wgpu::Texture, (u32, u32))>,
format: wgpu::TextureFormat,
samples: u32,
pub clear: [f64; 3],
// --- Vektor-Text ---
text_pipeline: wgpu::RenderPipeline,
@@ -250,7 +250,9 @@ fn projection(b: (f64, f64, f64, f64), origin: [f64; 2]) -> [f32; 16] {
}
impl ChunkRenderer {
pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self {
/// `samples`: MSAA-Stufe (4 oder 8, je nach GPU-Unterstuetzung) — Kantenglaettung
/// fuer ALLE Geometrie (Flaechen, Linien, Text).
pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat, samples: u32) -> Self {
let fill_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("chunks.fill"),
source: wgpu::ShaderSource::Wgsl(FILL_WGSL.into()),
@@ -305,7 +307,7 @@ impl ChunkRenderer {
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: SAMPLE_COUNT,
count: samples,
mask: !0,
alpha_to_coverage_enabled: false,
},
@@ -367,7 +369,7 @@ impl ChunkRenderer {
..Default::default()
},
depth_stencil: None,
multisample: wgpu::MultisampleState { count: SAMPLE_COUNT, mask: !0, alpha_to_coverage_enabled: false },
multisample: wgpu::MultisampleState { count: samples, mask: !0, alpha_to_coverage_enabled: false },
multiview_mask: None,
cache: None,
});
@@ -386,6 +388,7 @@ impl ChunkRenderer {
layout: Vec::new(),
msaa: None,
format,
samples,
clear: [0.941, 0.941, 0.941],
}
}
@@ -634,7 +637,7 @@ impl ChunkRenderer {
label: Some("chunks.msaa"),
size: wgpu::Extent3d { width: viewport.0, height: viewport.1, depth_or_array_layers: 1 },
mip_level_count: 1,
sample_count: SAMPLE_COUNT,
sample_count: self.samples,
dimension: wgpu::TextureDimension::D2,
format: self.format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
+9 -4
View File
@@ -84,8 +84,12 @@ pub fn set_rect(app: &AppHandle, x: f64, y: f64, w: f64, h: f64) {
// Unter alle vorhandenen Geschwister (= unter die Webview).
parent.addSubview_positioned_relativeTo(&view, NSWindowOrderingMode::Below, None);
make_webview_transparent(&app2);
let (surface, device, queue, config) = create_surface(&view, w * scale, h * scale);
let renderer = ChunkRenderer::new(&device, config.format);
let (surface, device, queue, config, adapter_flags) = create_surface(&view, w * scale, h * scale);
let samples = [8u32, 4]
.into_iter()
.find(|s| adapter_flags.sample_count_supported(*s))
.unwrap_or(4);
let renderer = ChunkRenderer::new(&device, config.format, samples);
let mut e = Embedded {
ns_view: view,
surface,
@@ -135,7 +139,7 @@ fn create_surface(
view: &NSView,
pw: f64,
ph: f64,
) -> (wgpu::Surface<'static>, wgpu::Device, wgpu::Queue, wgpu::SurfaceConfiguration) {
) -> (wgpu::Surface<'static>, wgpu::Device, wgpu::Queue, wgpu::SurfaceConfiguration, wgpu::TextureFormatFeatureFlags) {
let instance = wgpu::Instance::default();
let surface = unsafe {
instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::RawHandle {
@@ -174,7 +178,8 @@ fn create_surface(
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);
(surface, device, queue, config)
let flags = adapter.get_texture_format_features(format).flags;
(surface, device, queue, config, flags)
}
/// Roh-Bytes eines Puffers ablegen (Vertex-/Indexdaten eines Chunks).
+12 -4
View File
@@ -1950,6 +1950,8 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
// + echtes viewBox werden erst beim Loslassen abgeglichen → in WebKit KEIN
// SVG-Re-Raster je Frame mehr.
const panPending = useRef<ViewBox | null>(null);
// true, wenn das SVG-Overlay zu schwer fürs Neu-Rastern je Frame ist (s. applySvgTransform).
const overlayHeavyRef = useRef(false);
const panStartView = useRef<ViewBox | null>(null); // viewBox bei Gestenbeginn (V0)
const panRaf = useRef<number | null>(null);
@@ -1971,6 +1973,15 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
const lbY = (rect.height - v0.h * m) / 2;
const cx = m * A * (v0.x - v.x) + (1 - A) * lbX;
const cy = m * A * (v0.y - v.y) + (1 - A) * lbY;
if (!overlayHeavyRef.current) {
// Leichtes Overlay: den echten viewBox setzen — der Vektor wird in jedem
// Frame SCHARF neu gerastert (ein CSS-Transform würde die Ebene als Bitmap
// strecken → verpixelt). Bildschirmkonstante Griffe skalieren dabei mit.
svg.style.transform = "";
svg.setAttribute("viewBox", `${v.x} ${v.y} ${v.w} ${v.h}`);
return;
}
// Schweres Overlay (z. B. riesiger Auswahlpfad): GPU-komponierter CSS-Transform.
svg.style.transformOrigin = "0 0";
svg.style.transform = `translate(${cx}px, ${cy}px) scale(${A})`;
};
@@ -1999,7 +2010,6 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
if (panPending.current) {
// SVG-Transform lösen; setView setzt das echte viewBox (ein einziger Re-Raster).
if (svgRef.current) svgRef.current.style.transform = "";
svgRef.current?.classList.remove("plan-zooming");
setView(panPending.current);
panPending.current = null;
}
@@ -2626,9 +2636,6 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
y: base.y + (e.clientY - rect.top - offY) / scale,
};
}
// Bildschirmkonstante Overlays (Griffe) würden vom CSS-Transform der Geste
// mitskaliert → bis zum Festschreiben ausblenden (kein React-Render nötig).
svgRef.current?.classList.add("plan-zooming");
enqueuePan(zoomedView(base, e.clientX, e.clientY, e.deltaY, anchor));
if (wheelCommitTimer.current !== null) clearTimeout(wheelCommitTimer.current);
wheelCommitTimer.current = setTimeout(() => {
@@ -2791,6 +2798,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
return parts.join("");
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [highlightDrawPrims]);
overlayHeavyRef.current = highlightDrawPath.length > 300_000;
const highlightTextPath = useMemo(() => {
const parts: string[] = [];
for (const p of highlightTextFrames) {
-8
View File
@@ -2300,14 +2300,6 @@ body {
shape-rendering: geometricPrecision;
}
/* Während einer Zoom-Geste (CSS-Transform des SVG) würden bildschirmkonstante
Griffe mitskalieren und kurz riesig wirken — bis zum Festschreiben ausblenden. */
.plan-svg.plan-zooming .plan-grip,
.plan-svg.plan-zooming .plan-edge-grip,
.plan-svg.plan-zooming .plan-grip-line {
visibility: hidden;
}
/* Bezier-Hilfslinien (Anker → Kontrollpunkt-Griff): dünn, gestrichelt, deutlich
zurückhaltender als der Kurven-Umriss selbst — reine Steuerungshilfe. */
.plan-svg .plan-grip-line {