#[allow(unused_imports)] use log::{debug, error, info, trace, warn}; use std::{ mem::ManuallyDrop, }; mod gpu; use gpu::Gpu; mod swap_system; use swap_system::SwapSystem; pub mod output; use output::Output; //mod pipeline; //use pipeline::Pipeline; //--Renderer implementation------------------------------------------------------------------------- #[derive(Debug)] pub struct Renderer { instance: ManuallyDrop, gpu: ManuallyDrop>, //pipelines: Vec>, swap_systems: Vec>, } impl Drop for Renderer where B: gfx_hal::Backend, { fn drop(&mut self) { use gfx_hal::device::Device; debug!("Waiting for device to idle..."); let _ = self.gpu .device() .wait_idle(); info!("Dropping Renderer..."); for mut swap_system in self.swap_systems.drain(..) { swap_system.drop(&mut self.gpu, &self.instance); } // for mut pipeline in self.pipelines.drain(..) { // // } unsafe { ManuallyDrop::drop(&mut self.gpu); ManuallyDrop::drop(&mut self.instance); } trace!("Renderer dropped !"); } } impl Renderer where B: gfx_hal::Backend, { pub fn new<'a, H, T: 'a, I>(outputs: I) -> Result, &'static str> where H: raw_window_handle::HasRawWindowHandle, T: Output, I: IntoIterator, { use gfx_hal::Instance; info!("Creating renderer..."); let instance = B::Instance::create("IV", 1) .map_err(|_| "Could not create instance")?; let (mut gpu, mut surfaces) = Gpu::new(&instance, outputs) .map_err(|err| err)?; let swap_systems = { surfaces .drain(..) .map(|surface| SwapSystem::new(&mut gpu, surface)) .collect::, &str>>()? }; debug!("Renderer created !"); Ok( Renderer { instance: ManuallyDrop::new(instance), gpu: ManuallyDrop::new(gpu), swap_systems, }) } pub fn draw_clear_frame(&mut self, output: &mut O, _color: [f32; 4]) -> Result<(), &'static str> where T: raw_window_handle::HasRawWindowHandle, O: Output { let swap_index = output.get_id(); let frame = self.swap_systems[swap_index].acquire_frame(); frame.sync_gpu(&self.gpu); Ok(()) } }