/// This example shows how to render headlessly by: /// /// 1. Rendering a triangle to an MtlDrawable /// /// 2. Waiting for the render to complete and the color texture to be synchronized with the CPU /// by using a blit command encoder /// /// 3. Reading the texture bytes from the MtlTexture /// /// 4. Saving the texture to a PNG file fn main() { let device = Device::system_default().expect("No device found");
let texture = create_texture(&device);
let library_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("examples/window/shaders.metallib");
let library = device.new_library_with_file(library_path).unwrap();
let pipeline_state = prepare_pipeline_state(&device, &library);
let command_queue = device.new_command_queue();
let vertex_buffer = create_vertex_buffer(&device);
let render_pass_descriptor = RenderPassDescriptor::new();
initialize_color_attachment(&render_pass_descriptor, &texture);
let command_buffer = command_queue.new_command_buffer(); let rc_encoder = command_buffer.new_render_command_encoder(&render_pass_descriptor);
rc_encoder.set_render_pipeline_state(&pipeline_state);
rc_encoder.set_vertex_buffer(0, Some(&vertex_buffer), 0);
rc_encoder.draw_primitives(MTLPrimitiveType::Triangle, 0, 3);
rc_encoder.end_encoding();
let out_file =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/headless-render/out.png"); let file = File::create(&out_file).unwrap(); letrefmut w = BufWriter::new(file);
letmut encoder = png::Encoder::new(w, VIEW_WIDTH as u32, VIEW_HEIGHT as u32);
encoder.set_color(ColorType::Rgba);
encoder.set_depth(png::BitDepth::Eight); letmut writer = encoder.write_header().unwrap();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.