fn ensure_render_state_for_surface(&mut self, surface: &Surface) {
        self.adapter.get_or_insert_with(|| {
            pollster::block_on(self.instance.request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: self.power_preference,
                compatible_surface: Some(surface),
                force_fallback_adapter: false,
            }))
            .unwrap()
        });

        if self.render_state.is_none() {
            let adapter = self.adapter.as_ref().unwrap();
            let swapchain_format = surface.get_preferred_format(adapter).unwrap();

            let rs = pollster::block_on(self.init_render_state(adapter, swapchain_format));
            self.render_state = Some(rs);
        }
    }
// We want to defer the initialization of our render state until we have a surface
// so we can take its format into account.
//
// After we've initialized our render state once though we expect all future surfaces
// will have the same format and so this render state will remain valid.
We want to defer the initialization of our render state until we have a surface
so we can take its format into account.

After we've initialized our render state once though we expect all future surfaces
will have the same format and so this render state will remain valid.
We want to defer the initialization of our render state until we have a surface so we can take its format into account . After we ' ve initialized our render state once though we expect all future surfaces will have the same format and so this render state will remain valid .
fn ensure_render_state_for_surface(&mut self, surface: &Surface) {
        self.adapter.get_or_insert_with(|| {
            pollster::block_on(self.instance.request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: self.power_preference,
                compatible_surface: Some(surface),
                force_fallback_adapter: false,
            }))
            .unwrap()
        });
        if self.render_state.is_none() {
            let adapter = self.adapter.as_ref().unwrap();
            let swapchain_format = surface.get_preferred_format(adapter).unwrap();
            let rs = pollster::block_on(self.init_render_state(adapter, swapchain_format));
            self.render_state = Some(rs);
        }
    }
fn ensure_render_state_for_surface ( & mut self , surface : & Surface ) { self . adapter . get_or_insert_with ( | | { pollster :: block_on ( self . instance . request_adapter ( & wgpu :: RequestAdapterOptions { power_preference : self . power_preference , compatible_surface : Some ( surface ) , force_fallback_adapter : false , } ) ) . unwrap ( ) } ) ; if self . render_state . is_none ( ) { let adapter = self . adapter . as_ref ( ) . unwrap ( ) ; let swapchain_format = surface . get_preferred_format ( adapter ) . unwrap ( ) ; let rs = pollster :: block_on ( self . init_render_state ( adapter , swapchain_format ) ) ; self . render_state = Some ( rs ) ; } }
We want to defer the initialization of our render state until we have a surface
so we can take its format into account.
We want to defer the initialization of our render state until we have a surface so we can take its format into account .
&mut self
surface
&Surface
&mut self
surface
&Surface