pub async fn new<
        F0: Fn(&wgpu::Device, &wgpu::Queue) -> Vec<(wgpu::BindGroupLayout, wgpu::BindGroup)>,
        F1: Fn(&wgpu::Device, wgpu::TextureFormat) -> P,
    >(
        window: &Window,
        bind_group_builder: F0,
        pipeline_builder: F1,
    ) -> Self {
        let size = window.inner_size();

        // Instance is our GPU handle
        // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
        let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
        let surface = unsafe { instance.create_surface(window) };
        let adapter = instance
            .request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: wgpu::PowerPreference::HighPerformance,
                compatible_surface: Some(&surface),
            })
            .await
            .unwrap();

        let (device, queue) = adapter
            .request_device(
                &wgpu::DeviceDescriptor {
                    label: Some("Main Device"),
                    features: wgpu::Features::empty(),
                    limits: wgpu::Limits::default(),
                },
                None,
            )
            .await
            .unwrap();

        let swap_descriptor = wgpu::SwapChainDescriptor {
            usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
            format: wgpu::TextureFormat::Bgra8UnormSrgb,
            width: size.width,
            height: size.height,
            present_mode: wgpu::PresentMode::Mailbox,
        };
        let swap_chain = SwapChain::new(&device, &surface, swap_descriptor);

        // Pipeline
        let mut pipeline = pipeline_builder(&device, swap_chain.descriptor.format);
        pipeline.initialize(&device, &queue, bind_group_builder);
        pipeline.resize(&device, &queue, size.width, size.height);

        Self {
            surface,
            device,
            queue,
            swap_chain,
            pipeline,

            width: size.width,
            height: size.height,
        }
    }
// Creating some of the wgpu types requires async code
Creating some of the wgpu types requires async code
Creating some of the wgpu types requires async code
pub async fn new<
        F0: Fn(&wgpu::Device, &wgpu::Queue) -> Vec<(wgpu::BindGroupLayout, wgpu::BindGroup)>,
        F1: Fn(&wgpu::Device, wgpu::TextureFormat) -> P,
    >(
        window: &Window,
        bind_group_builder: F0,
        pipeline_builder: F1,
    ) -> Self {
        let size = window.inner_size();
        // Instance is our GPU handle
        // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
        let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
        let surface = unsafe { instance.create_surface(window) };
        let adapter = instance
            .request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: wgpu::PowerPreference::HighPerformance,
                compatible_surface: Some(&surface),
            })
            .await
            .unwrap();
        let (device, queue) = adapter
            .request_device(
                &wgpu::DeviceDescriptor {
                    label: Some("Main Device"),
                    features: wgpu::Features::empty(),
                    limits: wgpu::Limits::default(),
                },
                None,
            )
            .await
            .unwrap();
        let swap_descriptor = wgpu::SwapChainDescriptor {
            usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
            format: wgpu::TextureFormat::Bgra8UnormSrgb,
            width: size.width,
            height: size.height,
            present_mode: wgpu::PresentMode::Mailbox,
        };
        let swap_chain = SwapChain::new(&device, &surface, swap_descriptor);
        // Pipeline
        let mut pipeline = pipeline_builder(&device, swap_chain.descriptor.format);
        pipeline.initialize(&device, &queue, bind_group_builder);
        pipeline.resize(&device, &queue, size.width, size.height);
        Self {
            surface,
            device,
            queue,
            swap_chain,
            pipeline,
            width: size.width,
            height: size.height,
        }
    }
pub async fn new < F0 : Fn ( & wgpu :: Device , & wgpu :: Queue ) -> Vec < ( wgpu :: BindGroupLayout , wgpu :: BindGroup ) > , F1 : Fn ( & wgpu :: Device , wgpu :: TextureFormat ) -> P , > ( window : & Window , bind_group_builder : F0 , pipeline_builder : F1 , ) -> Self { let size = window . inner_size ( ) ; // Instance is our GPU handle // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu :: Instance :: new ( wgpu :: BackendBit :: PRIMARY ) ; let surface = unsafe { instance . create_surface ( window ) } ; let adapter = instance . request_adapter ( & wgpu :: RequestAdapterOptions { power_preference : wgpu :: PowerPreference :: HighPerformance , compatible_surface : Some ( & surface ) , } ) . await . unwrap ( ) ; let ( device , queue ) = adapter . request_device ( & wgpu :: DeviceDescriptor { label : Some ( " " ) , features : wgpu :: Features :: empty ( ) , limits : wgpu :: Limits :: default ( ) , } , None , ) . await . unwrap ( ) ; let swap_descriptor = wgpu :: SwapChainDescriptor { usage : wgpu :: TextureUsage :: RENDER_ATTACHMENT , format : wgpu :: TextureFormat :: Bgra8UnormSrgb , width : size . width , height : size . height , present_mode : wgpu :: PresentMode :: Mailbox , } ; let swap_chain = SwapChain :: new ( & device , & surface , swap_descriptor ) ; // Pipeline let mut pipeline = pipeline_builder ( & device , swap_chain . descriptor . format ) ; pipeline . initialize ( & device , & queue , bind_group_builder ) ; pipeline . resize ( & device , & queue , size . width , size . height ) ; Self { surface , device , queue , swap_chain , pipeline , width : size . width , height : size . height , } }
Creating some of the wgpu types requires async code
Creating some of the wgpu types requires async code
window
&Window
bind_group_builder
F0
pipeline_builder
F1