prepare for reswapchain

ecs
q3k 2020-01-19 23:21:27 +01:00
parent dfef4de4d8
commit ac4b0ca497
3 changed files with 19 additions and 8 deletions

View File

@ -20,7 +20,7 @@ impl <WT> Binding<WT> {
vi::PhysicalDevice::from_index(&self.instance, self.physical_device_ix).unwrap()
}
pub fn new(instance: &Arc<vi::Instance>, surface: &Arc<vs::Surface<WT>>) -> Self {
pub fn new(instance: &Arc<vi::Instance>, surface: Arc<vs::Surface<WT>>) -> Self {
let physical_device_ix = Self::pick_physical_device(instance, &surface);
let physical_device = vi::PhysicalDevice::from_index(instance, physical_device_ix).unwrap();
let indices = super::qfi::QueueFamilyIndices::find(&surface, &physical_device).unwrap();

View File

@ -25,6 +25,7 @@ pub struct Instance<WT> {
debug_callback: vi::debug::DebugCallback,
vulkan: Arc<vi::Instance>,
surface: Option<Arc<vs::Surface<WT>>>,
binding: Option<binding::Binding<WT>>,
swapchains: Option<swapchains::Swapchains<WT>>,
render_pass: Option<Arc<dyn vf::RenderPassAbstract + Send + Sync>>,
@ -51,6 +52,7 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
debug_callback,
vulkan,
surface: None,
binding: None,
swapchains: None,
render_pass: None,
@ -68,20 +70,24 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
}
pub fn use_surface(&mut self, surface: &Arc<vs::Surface<WT>>) {
self.binding = Some(binding::Binding::new(&self.vulkan, &surface));
self.swapchains = Some(swapchains::Swapchains::new(self.binding.as_ref().unwrap()));
self.surface = Some(surface.clone());
self.arm();
log::info!("Bound to Vulkan Device: {}", self.binding.as_ref().unwrap().physical_device().name());
}
fn arm(&mut self) {
self.binding = Some(binding::Binding::new(&self.vulkan, self.surface.as_ref().unwrap().clone()));
self.swapchains = Some(swapchains::Swapchains::new(self.binding.as_ref().unwrap(), None));
let device = self.binding.as_ref().unwrap().device.clone();
let chain = self.get_swapchain();
self.create_render_pass(chain.format());
let render_pass = self.render_pass.as_ref().unwrap().clone();
let pipeline = shaders::pipeline_triangle(device, chain.dimensions(), render_pass);
self.create_framebuffers();
let render_pass = self.render_pass.as_ref().unwrap().clone();
let pipeline = shaders::pipeline_triangle(device, chain.dimensions(), render_pass);
self.create_command_buffers(pipeline);
}

View File

@ -11,7 +11,7 @@ pub struct Swapchains<WT> {
}
impl<WT> Swapchains<WT> {
pub fn new(binding: &super::binding::Binding<WT>) -> Self {
pub fn new(binding: &super::binding::Binding<WT>, previous: Option<&Swapchains<WT>>) -> Self {
let physical_device = binding.physical_device();
let capabilities = binding.surface.capabilities(physical_device).expect("could not get capabilities");
@ -38,6 +38,11 @@ impl<WT> Swapchains<WT> {
(&binding.graphics_queue).into()
};
let prev = match previous {
None => None,
Some(p) => Some(p.chain.clone()),
};
let (chain, images) = vs::Swapchain::new(
binding.device.clone(),
binding.surface.clone(),
@ -51,7 +56,7 @@ impl<WT> Swapchains<WT> {
vs::CompositeAlpha::Opaque,
present_mode,
true,
None,
prev.as_ref(),
).expect("could not create swap chain");
Self {