use winit::{ event::*, event_loop::{ControlFlow, EventLoop}, window::{WindowBuilder, Window}, }; struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, } impl State { // Creating some of the wgpu types requires async code async fn new(window: &Window) -> Self { let size = window.inner_size(); // The instance is a handle to our GPU // Backends::all => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance.request_adapter( &wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::default(), compatible_surface: Some(&surface), force_fallback_adapter: false, }, ).await.unwrap(); } fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { todo!() } fn input(&mut self, event: &WindowEvent) -> bool { todo!() } fn update(&mut self) { todo!() } fn render(&mut self) -> Result<(), wgpu::SurfaceError> { todo!() } } pub fn run() { env_logger::init(); let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { ref event, window_id, } if window_id == window.id() => match event { WindowEvent::CloseRequested | WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, virtual_keycode: Some(VirtualKeyCode::Escape), .. }, .. } => *control_flow = ControlFlow::Exit, _ => {} }, _ => {} }); }