mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-20 06:20:50 +01:00
An open-source, clean-room implementation of a Substance 3D Painter-style texturing workflow, written in pure Rust with egui and wgpu. - Layer stack with 32 blend modes, masks, generators, content effects and anchor points - Painting, projection, smudge, clone, path, lasso fill, particle brush and quick mask - 43 procedural materials, 17 smart materials and 10 smart masks - Mesh map baking with high-poly, cage and match-by-name support - PBR viewport with HDR environments, TAA and a path-traced Rendering mode - glTF, FBX, COLLADA, OBJ, PLY and STL import; texture export presets; OBJ and GLB export - Dockable Painter-style UI, shortcut editor, web build, MCP server and CLI Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.4 KiB
Rust
31 lines
1.4 KiB
Rust
//! A windowless wgpu device for CLI renders, screenshots and GPU tests.
|
|
|
|
use crate::Renderer;
|
|
|
|
pub struct Headless {
|
|
pub device: wgpu::Device,
|
|
pub queue: wgpu::Queue,
|
|
pub renderer: Renderer,
|
|
pub adapter_name: String,
|
|
}
|
|
|
|
impl Headless {
|
|
/// Create a device on the default adapter. Errors when no GPU (or software) adapter exists.
|
|
pub fn new() -> Result<Headless, String> {
|
|
let instance = wgpu::Instance::default();
|
|
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default())).map_err(|e| format!("no GPU adapter: {e}"))?;
|
|
let adapter_name = adapter.get_info().name;
|
|
let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())).map_err(|e| format!("no GPU device: {e}"))?;
|
|
let renderer = Renderer::new(&device, &queue, wgpu::TextureFormat::Rgba8Unorm);
|
|
Ok(Headless { device, queue, renderer, adapter_name })
|
|
}
|
|
|
|
/// Render a frame and read it back as RGBA8 (sRGB-encoded).
|
|
pub fn render(&mut self, frame: &crate::Frame) -> Option<(u32, u32, Vec<u8>)> {
|
|
let mut enc = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("tc_headless") });
|
|
self.renderer.prepare(&self.device, &self.queue, &mut enc, frame);
|
|
self.queue.submit([enc.finish()]);
|
|
self.renderer.read_view(&self.device, &self.queue, frame.view_id)
|
|
}
|
|
}
|