ui: ui.render draws on the window's GPU

The app keeps a capturer on its own device; ui.render draws with the
viewport's pipelines there, on the CPU with the reason otherwise, and
the reply names the renderer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
jyvikoandClaude Opus 5.5 authored and Irakli Kourtis committed 2026-10-16 08:27:21 -04:00
1 parent b655af305a
commit 6136770c1c
2 files changed
+87 -15

No files matched your search

+4 -3
View File
@@ -631,12 +631,12 @@ pub fn handle(app: &mut ModelApp, ctx: &egui::Context, req: &ControlRequest) ->
Ok(s) => s,
Err(e) => return err(e),
};
let png = match app.render_png(w, h, f64::from(scale)) {
Ok(png) => png,
let (png, renderer) = match app.render_png(w, h, f64::from(scale)) {
Ok(drawn) => drawn,
Err(e) => return err(e),
};
match std::fs::write(path, &png) {
Ok(()) => ok(json!({"path": path, "width": w, "height": h, "scale": scale, "bytes": png.len()})),
Ok(()) => ok(json!({"path": path, "width": w, "height": h, "scale": scale, "bytes": png.len(), "renderer": renderer.report()})),
Err(e) => err(format!("{path}: {e}")),
}
}
@@ -996,6 +996,7 @@ mod tests {
let path = std::env::temp_dir().join(format!("fieldcraft-render-{}.png", std::process::id()));
let r = call(&mut app, "ui.render", json!({"path": path.to_string_lossy(), "width": 120, "height": 80}));
assert_eq!(r["ok"], true, "{r}");
assert_eq!(r["result"]["renderer"]["kind"], "cpu", "{r}");
let bytes = std::fs::read(&path).unwrap();
assert!(bytes.starts_with(&[0x89, b'P', b'N', b'G']));
let _ = std::fs::remove_file(&path);