async fn new(window: &Window, sample_count: NonZeroU32) -> Self {
        let size = window.inner_size();
        // The instance is a handle to our GPU
        // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
        let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
        let surface = unsafe { instance.create_surface(window) };
        // need adapter to create the device and queue
        let adapter = instance
            .request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: wgpu::PowerPreference::default(),
                force_fallback_adapter: false,
                compatible_surface: Some(&surface),
            })
            .await
            .unwrap();
        let (device, queue) = adapter
            .request_device(
                &wgpu::DeviceDescriptor {
                    features: wgpu::Features::empty(), //The device you have limits the features you can use
                    limits: wgpu::Limits::default(), //The limits field describes the limit of certain types of resource we can create
                    label: None,
                },
                None,
            )
            .await
            .unwrap();
        let preferred_format = surface.get_preferred_format(&adapter).unwrap();
        let surface_configs = SurfaceConfiguration {
            usage: TextureUsages::RENDER_ATTACHMENT,
            format: preferred_format,
            width: size.width,
            height: size.height,
            present_mode: wgpu::PresentMode::Fifo,
        };
        surface.configure(&device, &surface_configs);
        let surface_view_desc = TextureViewDescriptor {
            label: Some("Render Texture View"),
            format: Some(surface_configs.format),
            dimension: Some(TextureViewDimension::D2),
            aspect: Default::default(),
            base_mip_level: 0,
            mip_level_count: None,
            base_array_layer: 0,
            array_layer_count: None,
        };
        // rendering configurations
        let camera = Camera {
            eye: (0.0, -2.5, 1.0).into(),
            center: (0.0, 0.0, 0.0).into(),
            up: cgmath::Vector3::unit_z(),
            aspect: (size.width as f32) / (size.height as f32),
            fovy: 45.0,
            znear: 0.1,
            zfar: 100.0,
        };
        // load volume into textures
        let ((x, y, z), data, _uint_data) = load_volume_data("./data/stagbeetle277x277x164.dat");
        let data_f16: Vec<f16> = data.par_iter().map(|x| f16::from_f32(*x)).collect();
        let extent = Extent3d {
            width: x as u32,
            height: y as u32,
            depth_or_array_layers: z as u32,
        };
        // prepare volume cube scaling for correct shape
        let mut dims = vec![x, y, z];
        dims.sort();
        let mid_val = *dims.get(1).unwrap() as f32;
        let volume_texture =
            Tex::create_3d_texture_red_f16(&extent, &data_f16, &device, &queue, "Volume");
        let cube_scaling = Matrix4::from_nonuniform_scale(
            x as f32 / mid_val,
            y as f32 / mid_val,
            z as f32 / mid_val,
        );

        // prepare front-face and back-face passes
        let face_buffer_format = TextureFormat::Rgba16Float; // filterable format with highest precision
        let front_face_render_buffer = Tex::create_render_buffer(
            (size.width, size.height),
            &device,
            Some("Front face render buffer texture"),
            NonZeroU32::new(State::FACE_RENDER_BUFFER_SAMPLE_COUNT).unwrap(),
            &face_buffer_format,
        );
        let front_face_pass = D3Pass::new(
            &device,
            size.width,
            size.height,
            &front_face_render_buffer.format,
            true,
            &camera,
            sample_count.clone(),
            cube_scaling.clone(),
        );
        let back_face_render_buffer = Tex::create_render_buffer(
            (size.width, size.height),
            &device,
            Some("Back face render buffer texture"),
            NonZeroU32::new(State::FACE_RENDER_BUFFER_SAMPLE_COUNT).unwrap(),
            &face_buffer_format,
        );
        let back_face_pass = D3Pass::new(
            &device,
            size.width,
            size.height,
            &back_face_render_buffer.format,
            false,
            &camera,
            sample_count.clone(),
            cube_scaling.clone(),
        );
        let canvas_pass = CanvasPass::new(
            &front_face_render_buffer,
            &back_face_render_buffer,
            &volume_texture,
            &device,
            &queue,
            (size.width, size.height),
            &preferred_format,
            sample_count,
        );
        Self {
            surface,
            surface_configs,
            surface_view_desc,
            device,
            queue,
            size,
            camera,
            camera_controller: CameraController::new(0.2),
            cube_scaling,
            front_face_pass,
            back_face_pass,
            front_face_render_buffer,
            back_face_render_buffer,
            canvas_pass,
        }
    }
// need async because we need to await some struct creation here
need async because we need to await some struct creation here
need async because we need to await some struct creation here
async fn new(window: &Window, sample_count: NonZeroU32) -> Self {
        let size = window.inner_size();
        // The instance is a handle to our GPU
        // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
        let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
        let surface = unsafe { instance.create_surface(window) };
        // need adapter to create the device and queue
        let adapter = instance
            .request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: wgpu::PowerPreference::default(),
                force_fallback_adapter: false,
                compatible_surface: Some(&surface),
            })
            .await
            .unwrap();
        let (device, queue) = adapter
            .request_device(
                &wgpu::DeviceDescriptor {
                    features: wgpu::Features::empty(), //The device you have limits the features you can use
                    limits: wgpu::Limits::default(), //The limits field describes the limit of certain types of resource we can create
                    label: None,
                },
                None,
            )
            .await
            .unwrap();
        let preferred_format = surface.get_preferred_format(&adapter).unwrap();
        let surface_configs = SurfaceConfiguration {
            usage: TextureUsages::RENDER_ATTACHMENT,
            format: preferred_format,
            width: size.width,
            height: size.height,
            present_mode: wgpu::PresentMode::Fifo,
        };
        surface.configure(&device, &surface_configs);
        let surface_view_desc = TextureViewDescriptor {
            label: Some("Render Texture View"),
            format: Some(surface_configs.format),
            dimension: Some(TextureViewDimension::D2),
            aspect: Default::default(),
            base_mip_level: 0,
            mip_level_count: None,
            base_array_layer: 0,
            array_layer_count: None,
        };
        // rendering configurations
        let camera = Camera {
            eye: (0.0, -2.5, 1.0).into(),
            center: (0.0, 0.0, 0.0).into(),
            up: cgmath::Vector3::unit_z(),
            aspect: (size.width as f32) / (size.height as f32),
            fovy: 45.0,
            znear: 0.1,
            zfar: 100.0,
        };
        // load volume into textures
        let ((x, y, z), data, _uint_data) = load_volume_data("./data/stagbeetle277x277x164.dat");
        let data_f16: Vec<f16> = data.par_iter().map(|x| f16::from_f32(*x)).collect();
        let extent = Extent3d {
            width: x as u32,
            height: y as u32,
            depth_or_array_layers: z as u32,
        };
        // prepare volume cube scaling for correct shape
        let mut dims = vec![x, y, z];
        dims.sort();
        let mid_val = *dims.get(1).unwrap() as f32;
        let volume_texture =
            Tex::create_3d_texture_red_f16(&extent, &data_f16, &device, &queue, "Volume");
        let cube_scaling = Matrix4::from_nonuniform_scale(
            x as f32 / mid_val,
            y as f32 / mid_val,
            z as f32 / mid_val,
        );
        // prepare front-face and back-face passes
        let face_buffer_format = TextureFormat::Rgba16Float; // filterable format with highest precision
        let front_face_render_buffer = Tex::create_render_buffer(
            (size.width, size.height),
            &device,
            Some("Front face render buffer texture"),
            NonZeroU32::new(State::FACE_RENDER_BUFFER_SAMPLE_COUNT).unwrap(),
            &face_buffer_format,
        );
        let front_face_pass = D3Pass::new(
            &device,
            size.width,
            size.height,
            &front_face_render_buffer.format,
            true,
            &camera,
            sample_count.clone(),
            cube_scaling.clone(),
        );
        let back_face_render_buffer = Tex::create_render_buffer(
            (size.width, size.height),
            &device,
            Some("Back face render buffer texture"),
            NonZeroU32::new(State::FACE_RENDER_BUFFER_SAMPLE_COUNT).unwrap(),
            &face_buffer_format,
        );
        let back_face_pass = D3Pass::new(
            &device,
            size.width,
            size.height,
            &back_face_render_buffer.format,
            false,
            &camera,
            sample_count.clone(),
            cube_scaling.clone(),
        );
        let canvas_pass = CanvasPass::new(
            &front_face_render_buffer,
            &back_face_render_buffer,
            &volume_texture,
            &device,
            &queue,
            (size.width, size.height),
            &preferred_format,
            sample_count,
        );
        Self {
            surface,
            surface_configs,
            surface_view_desc,
            device,
            queue,
            size,
            camera,
            camera_controller: CameraController::new(0.2),
            cube_scaling,
            front_face_pass,
            back_face_pass,
            front_face_render_buffer,
            back_face_render_buffer,
            canvas_pass,
        }
    }
async fn new ( window : & Window , sample_count : NonZeroU32 ) -> Self { let size = window . inner_size ( ) ; // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu :: Instance :: new ( wgpu :: Backends :: PRIMARY ) ; let surface = unsafe { instance . create_surface ( window ) } ; // need adapter to create the device and queue let adapter = instance . request_adapter ( & wgpu :: RequestAdapterOptions { power_preference : wgpu :: PowerPreference :: default ( ) , force_fallback_adapter : false , compatible_surface : Some ( & surface ) , } ) . await . unwrap ( ) ; let ( device , queue ) = adapter . request_device ( & wgpu :: DeviceDescriptor { features : wgpu :: Features :: empty ( ) , //The device you have limits the features you can use limits : wgpu :: Limits :: default ( ) , //The limits field describes the limit of certain types of resource we can create label : None , } , None , ) . await . unwrap ( ) ; let preferred_format = surface . get_preferred_format ( & adapter ) . unwrap ( ) ; let surface_configs = SurfaceConfiguration { usage : TextureUsages :: RENDER_ATTACHMENT , format : preferred_format , width : size . width , height : size . height , present_mode : wgpu :: PresentMode :: Fifo , } ; surface . configure ( & device , & surface_configs ) ; let surface_view_desc = TextureViewDescriptor { label : Some ( " " ) , format : Some ( surface_configs . format ) , dimension : Some ( TextureViewDimension :: D2 ) , aspect : Default :: default ( ) , base_mip_level : 0 , mip_level_count : None , base_array_layer : 0 , array_layer_count : None , } ; // rendering configurations let camera = Camera { eye : ( 0.0 , - 2.5 , 1.0 ) . into ( ) , center : ( 0.0 , 0.0 , 0.0 ) . into ( ) , up : cgmath :: Vector3 :: unit_z ( ) , aspect : ( size . width as f32 ) / ( size . height as f32 ) , fovy : 45.0 , znear : 0.1 , zfar : 100.0 , } ; // load volume into textures let ( ( x , y , z ) , data , _uint_data ) = load_volume_data ( " " ) ; let data_f16 : Vec < f16 > = data . par_iter ( ) . map ( | x | f16 :: from_f32 ( * x ) ) . collect ( ) ; let extent = Extent3d { width : x as u32 , height : y as u32 , depth_or_array_layers : z as u32 , } ; // prepare volume cube scaling for correct shape let mut dims = vec ! [ x y z ] ; dims . sort ( ) ; let mid_val = * dims . get ( 1 ) . unwrap ( ) as f32 ; let volume_texture = Tex :: create_3d_texture_red_f16 ( & extent , & data_f16 , & device , & queue , " " ) ; let cube_scaling = Matrix4 :: from_nonuniform_scale ( x as f32 / mid_val , y as f32 / mid_val , z as f32 / mid_val , ) ; // prepare front-face and back-face passes let face_buffer_format = TextureFormat :: Rgba16Float ; // filterable format with highest precision let front_face_render_buffer = Tex :: create_render_buffer ( ( size . width , size . height ) , & device , Some ( " " ) , NonZeroU32 :: new ( State :: FACE_RENDER_BUFFER_SAMPLE_COUNT ) . unwrap ( ) , & face_buffer_format , ) ; let front_face_pass = D3Pass :: new ( & device , size . width , size . height , & front_face_render_buffer . format , true , & camera , sample_count . clone ( ) , cube_scaling . clone ( ) , ) ; let back_face_render_buffer = Tex :: create_render_buffer ( ( size . width , size . height ) , & device , Some ( " " ) , NonZeroU32 :: new ( State :: FACE_RENDER_BUFFER_SAMPLE_COUNT ) . unwrap ( ) , & face_buffer_format , ) ; let back_face_pass = D3Pass :: new ( & device , size . width , size . height , & back_face_render_buffer . format , false , & camera , sample_count . clone ( ) , cube_scaling . clone ( ) , ) ; let canvas_pass = CanvasPass :: new ( & front_face_render_buffer , & back_face_render_buffer , & volume_texture , & device , & queue , ( size . width , size . height ) , & preferred_format , sample_count , ) ; Self { surface , surface_configs , surface_view_desc , device , queue , size , camera , camera_controller : CameraController :: new ( 0.2 ) , cube_scaling , front_face_pass , back_face_pass , front_face_render_buffer , back_face_render_buffer , canvas_pass , } }
need async because we need to await some struct creation here
need async because we need to await some struct creation here
window
&Window
sample_count
NonZeroU32
window
&Window
sample_count
NonZeroU32