prepare for reswapchain
parent
dfef4de4d8
commit
ac4b0ca497
|
@ -20,7 +20,7 @@ impl <WT> Binding<WT> {
|
||||||
vi::PhysicalDevice::from_index(&self.instance, self.physical_device_ix).unwrap()
|
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_ix = Self::pick_physical_device(instance, &surface);
|
||||||
let physical_device = vi::PhysicalDevice::from_index(instance, physical_device_ix).unwrap();
|
let physical_device = vi::PhysicalDevice::from_index(instance, physical_device_ix).unwrap();
|
||||||
let indices = super::qfi::QueueFamilyIndices::find(&surface, &physical_device).unwrap();
|
let indices = super::qfi::QueueFamilyIndices::find(&surface, &physical_device).unwrap();
|
||||||
|
|
|
@ -25,6 +25,7 @@ pub struct Instance<WT> {
|
||||||
debug_callback: vi::debug::DebugCallback,
|
debug_callback: vi::debug::DebugCallback,
|
||||||
vulkan: Arc<vi::Instance>,
|
vulkan: Arc<vi::Instance>,
|
||||||
|
|
||||||
|
surface: Option<Arc<vs::Surface<WT>>>,
|
||||||
binding: Option<binding::Binding<WT>>,
|
binding: Option<binding::Binding<WT>>,
|
||||||
swapchains: Option<swapchains::Swapchains<WT>>,
|
swapchains: Option<swapchains::Swapchains<WT>>,
|
||||||
render_pass: Option<Arc<dyn vf::RenderPassAbstract + Send + Sync>>,
|
render_pass: Option<Arc<dyn vf::RenderPassAbstract + Send + Sync>>,
|
||||||
|
@ -51,6 +52,7 @@ impl<WT: 'static + Send + Sync> Instance<WT> {
|
||||||
debug_callback,
|
debug_callback,
|
||||||
vulkan,
|
vulkan,
|
||||||
|
|
||||||
|
surface: None,
|
||||||
binding: None,
|
binding: None,
|
||||||
swapchains: None,
|
swapchains: None,
|
||||||
render_pass: 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>>) {
|
pub fn use_surface(&mut self, surface: &Arc<vs::Surface<WT>>) {
|
||||||
self.binding = Some(binding::Binding::new(&self.vulkan, &surface));
|
self.surface = Some(surface.clone());
|
||||||
self.swapchains = Some(swapchains::Swapchains::new(self.binding.as_ref().unwrap()));
|
self.arm();
|
||||||
|
|
||||||
log::info!("Bound to Vulkan Device: {}", self.binding.as_ref().unwrap().physical_device().name());
|
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 device = self.binding.as_ref().unwrap().device.clone();
|
||||||
let chain = self.get_swapchain();
|
let chain = self.get_swapchain();
|
||||||
|
|
||||||
self.create_render_pass(chain.format());
|
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();
|
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);
|
self.create_command_buffers(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct Swapchains<WT> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<WT> 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 physical_device = binding.physical_device();
|
||||||
let capabilities = binding.surface.capabilities(physical_device).expect("could not get capabilities");
|
let capabilities = binding.surface.capabilities(physical_device).expect("could not get capabilities");
|
||||||
|
|
||||||
|
@ -38,6 +38,11 @@ impl<WT> Swapchains<WT> {
|
||||||
(&binding.graphics_queue).into()
|
(&binding.graphics_queue).into()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let prev = match previous {
|
||||||
|
None => None,
|
||||||
|
Some(p) => Some(p.chain.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
let (chain, images) = vs::Swapchain::new(
|
let (chain, images) = vs::Swapchain::new(
|
||||||
binding.device.clone(),
|
binding.device.clone(),
|
||||||
binding.surface.clone(),
|
binding.surface.clone(),
|
||||||
|
@ -51,7 +56,7 @@ impl<WT> Swapchains<WT> {
|
||||||
vs::CompositeAlpha::Opaque,
|
vs::CompositeAlpha::Opaque,
|
||||||
present_mode,
|
present_mode,
|
||||||
true,
|
true,
|
||||||
None,
|
prev.as_ref(),
|
||||||
).expect("could not create swap chain");
|
).expect("could not create swap chain");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|
Loading…
Reference in New Issue