1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
use acute_ecs::prelude::*; use acute_window::window::Window; use std::ops::Deref; pub struct Renderer { pub adapter: wgpu::Adapter, pub device: wgpu::Device, pub queue: wgpu::Queue, pub surface: wgpu::Surface, pub swap_chain: wgpu::SwapChain, pub window: Window, } impl Renderer { pub async fn new( resources: &mut Resources, window: Window, ) -> Self { let size = window.inner_size(); let surface = wgpu::Surface::create(&window); let adapter = wgpu::Adapter::request( &wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::Default, compatible_surface: Some(&surface), }, wgpu::BackendBit::PRIMARY, ) .await .unwrap(); let (device, queue) = adapter .request_device(&wgpu::DeviceDescriptor { extensions: wgpu::Extensions { anisotropic_filtering: false, }, limits: wgpu::Limits::default(), }) .await; let sc_desc = wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; let swap_chain = device.create_swap_chain(&surface, &sc_desc); resources.insert(sc_desc); Self { adapter, device, queue, surface, swap_chain, window } } }