pub unsafe fn into_target(
        mut self,
        physical_device: &B::PhysicalDevice,
        device: &impl gfx_hal::Device<B>,
        image_count: u32,
        usage: gfx_hal::image::Usage,
    ) -> Result<Target<B>, failure::Error> {
        let (capabilities, formats, present_modes, _alpha) =
            gfx_hal::Surface::compatibility(&self.raw, physical_device);

        let present_mode = *present_modes
            .iter()
            .max_by_key(|mode| match mode {
                gfx_hal::PresentMode::Immediate => 0,
                gfx_hal::PresentMode::Mailbox => 3,
                gfx_hal::PresentMode::Fifo => 2,
                gfx_hal::PresentMode::Relaxed => 1,
            })
            .unwrap();

        log::info!(
            "Surface present modes: {:#?}. Pick {:#?}",
            present_modes,
            present_mode
        );

        let formats = formats.unwrap();

        let format = *formats
            .iter()
            .max_by_key(|format| {
                let base = format.base_format();
                let desc = base.0.desc();
                (
                    !desc.is_compressed(),
                    base.1 == gfx_hal::format::ChannelType::Srgb,
                    desc.bits,
                )
            })
            .unwrap();

        log::info!("Surface formats: {:#?}. Pick {:#?}", formats, format);

        let image_count = image_count
            .min(capabilities.image_count.end)
            .max(capabilities.image_count.start);

        log::info!(
            "Surface capabilities: {:#?}. Pick {} images",
            capabilities.image_count,
            image_count
        );
        assert!(
            capabilities.usage.contains(usage),
            "Surface supports {:?}, but {:?} was requested"
        );

        let extent = capabilities.current_extent.unwrap_or({
            let hidpi_factor = self.window.get_hidpi_factor();
            let start = capabilities.extents.start;
            let end = capabilities.extents.end;
            let (window_width, window_height) = self
                .window
                .get_inner_size()
                .unwrap()
                .to_physical(hidpi_factor)
                .into();
            gfx_hal::window::Extent2D {
                width: end.width.min(start.width.max(window_width)),
                height: end.height.min(start.height.max(window_height)),
            }
        });

        let (swapchain, backbuffer) = device.create_swapchain(
            &mut self.raw,
            gfx_hal::SwapchainConfig {
                present_mode,
                format,
                extent,
                image_count,
                image_layers: 1,
                image_usage: usage,
                composite_alpha: gfx_hal::window::CompositeAlpha::Inherit,
            },
            None,
        )?;

        let (backbuffer, terminal) = match backbuffer {
            gfx_hal::Backbuffer::Images(images) => {
                let terminal = Terminal::new();
                let backbuffer = Backbuffer::Images(
                    images
                        .into_iter()
                        .map(|image| {
                            Image::new(
                                Info {
                                    kind: gfx_hal::image::Kind::D2(
                                        extent.width,
                                        extent.height,
                                        1,
                                        1,
                                    ),
                                    levels: 1,
                                    format,
                                    tiling: gfx_hal::image::Tiling::Optimal,
                                    view_caps: gfx_hal::image::ViewCapabilities::empty(),
                                    usage,
                                },
                                image,
                                None,
                                &terminal,
                            )
                        })
                        .collect(),
                );
                (backbuffer, Some(terminal))
            }
            gfx_hal::Backbuffer::Framebuffer(raw) => {
                let backbuffer = Backbuffer::Framebuffer {
                    raw,
                    format,
                    extent,
                };
                (backbuffer, None)
            }
        };

        Ok(Target {
            relevant: relevant::Relevant,
            window: self.window,
            surface: self.raw,
            swapchain,
            backbuffer,
            terminal,
        })
    }
/// Cast surface into render target.
Cast surface into render target.
Cast surface into render target .
pub unsafe fn into_target(
        mut self,
        physical_device: &B::PhysicalDevice,
        device: &impl gfx_hal::Device<B>,
        image_count: u32,
        usage: gfx_hal::image::Usage,
    ) -> Result<Target<B>, failure::Error> {
        let (capabilities, formats, present_modes, _alpha) =
            gfx_hal::Surface::compatibility(&self.raw, physical_device);
        let present_mode = *present_modes
            .iter()
            .max_by_key(|mode| match mode {
                gfx_hal::PresentMode::Immediate => 0,
                gfx_hal::PresentMode::Mailbox => 3,
                gfx_hal::PresentMode::Fifo => 2,
                gfx_hal::PresentMode::Relaxed => 1,
            })
            .unwrap();
        log::info!(
            "Surface present modes: {:#?}. Pick {:#?}",
            present_modes,
            present_mode
        );
        let formats = formats.unwrap();
        let format = *formats
            .iter()
            .max_by_key(|format| {
                let base = format.base_format();
                let desc = base.0.desc();
                (
                    !desc.is_compressed(),
                    base.1 == gfx_hal::format::ChannelType::Srgb,
                    desc.bits,
                )
            })
            .unwrap();
        log::info!("Surface formats: {:#?}. Pick {:#?}", formats, format);
        let image_count = image_count
            .min(capabilities.image_count.end)
            .max(capabilities.image_count.start);
        log::info!(
            "Surface capabilities: {:#?}. Pick {} images",
            capabilities.image_count,
            image_count
        );
        assert!(
            capabilities.usage.contains(usage),
            "Surface supports {:?}, but {:?} was requested"
        );
        let extent = capabilities.current_extent.unwrap_or({
            let hidpi_factor = self.window.get_hidpi_factor();
            let start = capabilities.extents.start;
            let end = capabilities.extents.end;
            let (window_width, window_height) = self
                .window
                .get_inner_size()
                .unwrap()
                .to_physical(hidpi_factor)
                .into();
            gfx_hal::window::Extent2D {
                width: end.width.min(start.width.max(window_width)),
                height: end.height.min(start.height.max(window_height)),
            }
        });
        let (swapchain, backbuffer) = device.create_swapchain(
            &mut self.raw,
            gfx_hal::SwapchainConfig {
                present_mode,
                format,
                extent,
                image_count,
                image_layers: 1,
                image_usage: usage,
                composite_alpha: gfx_hal::window::CompositeAlpha::Inherit,
            },
            None,
        )?;
        let (backbuffer, terminal) = match backbuffer {
            gfx_hal::Backbuffer::Images(images) => {
                let terminal = Terminal::new();
                let backbuffer = Backbuffer::Images(
                    images
                        .into_iter()
                        .map(|image| {
                            Image::new(
                                Info {
                                    kind: gfx_hal::image::Kind::D2(
                                        extent.width,
                                        extent.height,
                                        1,
                                        1,
                                    ),
                                    levels: 1,
                                    format,
                                    tiling: gfx_hal::image::Tiling::Optimal,
                                    view_caps: gfx_hal::image::ViewCapabilities::empty(),
                                    usage,
                                },
                                image,
                                None,
                                &terminal,
                            )
                        })
                        .collect(),
                );
                (backbuffer, Some(terminal))
            }
            gfx_hal::Backbuffer::Framebuffer(raw) => {
                let backbuffer = Backbuffer::Framebuffer {
                    raw,
                    format,
                    extent,
                };
                (backbuffer, None)
            }
        };
        Ok(Target {
            relevant: relevant::Relevant,
            window: self.window,
            surface: self.raw,
            swapchain,
            backbuffer,
            terminal,
        })
    }
pub unsafe fn into_target ( mut self , physical_device : & B :: PhysicalDevice , device : & impl gfx_hal :: Device < B > , image_count : u32 , usage : gfx_hal :: image :: Usage , ) -> Result < Target < B > , failure :: Error > { let ( capabilities , formats , present_modes , _alpha ) = gfx_hal :: Surface :: compatibility ( & self . raw , physical_device ) ; let present_mode = * present_modes . iter ( ) . max_by_key ( | mode | match mode { gfx_hal :: PresentMode :: Immediate => 0 , gfx_hal :: PresentMode :: Mailbox => 3 , gfx_hal :: PresentMode :: Fifo => 2 , gfx_hal :: PresentMode :: Relaxed => 1 , } ) . unwrap ( ) ; log :: info ! ( " " present_modes present_mode ) ; let formats = formats . unwrap ( ) ; let format = * formats . iter ( ) . max_by_key ( | format | { let base = format . base_format ( ) ; let desc = base . 0 . desc ( ) ; ( ! desc . is_compressed ( ) , base . 1 == gfx_hal :: format :: ChannelType :: Srgb , desc . bits , ) } ) . unwrap ( ) ; log :: info ! ( " " formats format ) ; let image_count = image_count . min ( capabilities . image_count . end ) . max ( capabilities . image_count . start ) ; log :: info ! ( " " capabilities image_count image_count ) ; assert ! ( capabilities usage contains ( usage ) " " ) ; let extent = capabilities . current_extent . unwrap_or ( { let hidpi_factor = self . window . get_hidpi_factor ( ) ; let start = capabilities . extents . start ; let end = capabilities . extents . end ; let ( window_width , window_height ) = self . window . get_inner_size ( ) . unwrap ( ) . to_physical ( hidpi_factor ) . into ( ) ; gfx_hal :: window :: Extent2D { width : end . width . min ( start . width . max ( window_width ) ) , height : end . height . min ( start . height . max ( window_height ) ) , } } ) ; let ( swapchain , backbuffer ) = device . create_swapchain ( & mut self . raw , gfx_hal :: SwapchainConfig { present_mode , format , extent , image_count , image_layers : 1 , image_usage : usage , composite_alpha : gfx_hal :: window :: CompositeAlpha :: Inherit , } , None , ) ? ; let ( backbuffer , terminal ) = match backbuffer { gfx_hal :: Backbuffer :: Images ( images ) => { let terminal = Terminal :: new ( ) ; let backbuffer = Backbuffer :: Images ( images . into_iter ( ) . map ( | image | { Image :: new ( Info { kind : gfx_hal :: image :: Kind :: D2 ( extent . width , extent . height , 1 , 1 , ) , levels : 1 , format , tiling : gfx_hal :: image :: Tiling :: Optimal , view_caps : gfx_hal :: image :: ViewCapabilities :: empty ( ) , usage , } , image , None , & terminal , ) } ) . collect ( ) , ) ; ( backbuffer , Some ( terminal ) ) } gfx_hal :: Backbuffer :: Framebuffer ( raw ) => { let backbuffer = Backbuffer :: Framebuffer { raw , format , extent , } ; ( backbuffer , None ) } } ; Ok ( Target { relevant : relevant :: Relevant , window : self . window , surface : self . raw , swapchain , backbuffer , terminal , } ) }
Cast surface into render target.
Cast surface into render target .
mut self
physical_device
&B::PhysicalDevice
device
&impl gfx_hal::Device<B>
image_count
u32
usage
gfx_hal::image::Usage
mut self
physical_device
&B::PhysicalDevice
device
&impl gfx_hal::Device<B>
image_count
u32
usage
gfx_hal::image::Usage