pulled swapchain out of shaderkernels
This commit is contained in:
@@ -49,8 +49,8 @@ struct EntryPoint<'a> {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ShaderKernels {
|
||||
pub swapchain : Arc<Swapchain<Window>>,
|
||||
pub swapchain_images: Vec<Arc<SwapchainImage<Window>>>, // Surface which is drawn to
|
||||
// pub swapchain : Arc<Swapchain<Window>>,
|
||||
// pub swapchain_images: Vec<Arc<SwapchainImage<Window>>>, // Surface which is drawn to
|
||||
|
||||
pub render_pass: Arc<RenderPassAbstract + Send + Sync>,
|
||||
pub graphics_pipeline: Option<Arc<GraphicsPipelineAbstract + Sync + Send>>,
|
||||
@@ -93,26 +93,26 @@ impl ShaderKernels {
|
||||
}
|
||||
|
||||
// On resizes we have to recreate the swapchain
|
||||
pub fn recreate_swapchain(mut self, surface: &Arc<Surface<Window>>) -> Self {
|
||||
let dimensions = if let Some(dimensions) = surface.window().get_inner_size() {
|
||||
let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into();
|
||||
[dimensions.0, dimensions.1]
|
||||
} else {
|
||||
return self;
|
||||
};
|
||||
|
||||
let (new_swapchain, new_images) = match self.swapchain.clone().recreate_with_dimension(dimensions) {
|
||||
Ok(r) => r,
|
||||
// This error tends to happen when the user is manually resizing the window.
|
||||
// Simply restarting the loop is the easiest way to fix this issue.
|
||||
Err(SwapchainCreationError::UnsupportedDimensions) => panic!("Uh oh"),
|
||||
Err(err) => panic!("{:?}", err)
|
||||
};
|
||||
|
||||
self.swapchain = new_swapchain;
|
||||
self.swapchain_images = new_images;
|
||||
self
|
||||
}
|
||||
// pub fn recreate_swapchain(mut self, surface: &Arc<Surface<Window>>) -> Self {
|
||||
// let dimensions = if let Some(dimensions) = surface.window().get_inner_size() {
|
||||
// let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into();
|
||||
// [dimensions.0, dimensions.1]
|
||||
// } else {
|
||||
// return self;
|
||||
// };
|
||||
//
|
||||
// let (new_swapchain, new_images) = match self.swapchain.clone().recreate_with_dimension(dimensions) {
|
||||
// Ok(r) => r,
|
||||
// // This error tends to happen when the user is manually resizing the window.
|
||||
// // Simply restarting the loop is the easiest way to fix this issue.
|
||||
// Err(SwapchainCreationError::UnsupportedDimensions) => panic!("Uh oh"),
|
||||
// Err(err) => panic!("{:?}", err)
|
||||
// };
|
||||
//
|
||||
// self.swapchain = new_swapchain;
|
||||
// self.swapchain_images = new_images;
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn new(filename: String,
|
||||
surface: &Arc<Surface<Window>>,
|
||||
@@ -120,35 +120,38 @@ impl ShaderKernels {
|
||||
physical: PhysicalDevice,
|
||||
device: Arc<Device>) -> ShaderKernels {
|
||||
|
||||
let (mut swapchain, images) = {
|
||||
let capabilities = surface.capabilities(physical).unwrap();
|
||||
let usage = capabilities.supported_usage_flags;
|
||||
let alpha = capabilities.supported_composite_alpha.iter().next().unwrap();
|
||||
// Choosing the internal format that the images will have.
|
||||
let format = capabilities.supported_formats[0].0;
|
||||
// let (mut swapchain, images) = {
|
||||
// let capabilities = surface.capabilities(physical).unwrap();
|
||||
// let usage = capabilities.supported_usage_flags;
|
||||
// let alpha = capabilities.supported_composite_alpha.iter().next().unwrap();
|
||||
// // Choosing the internal format that the images will have.
|
||||
// let format = capabilities.supported_formats[0].0;
|
||||
//
|
||||
// // Set the swapchains window dimensions
|
||||
// let initial_dimensions = if let Some(dimensions) = surface.window().get_inner_size() {
|
||||
// // convert to physical pixels
|
||||
// let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into();
|
||||
// [dimensions.0, dimensions.1]
|
||||
// } else {
|
||||
// // The window no longer exists so exit the application.
|
||||
// panic!("window closed");
|
||||
// };
|
||||
//
|
||||
// Swapchain::new(device.clone(),
|
||||
// surface.clone(),
|
||||
// capabilities.min_image_count,
|
||||
// format,
|
||||
// initial_dimensions,
|
||||
// 1, // Layers
|
||||
// usage,
|
||||
// &queue,
|
||||
// SurfaceTransform::Identity,
|
||||
// alpha,
|
||||
// PresentMode::Fifo, true, None).unwrap()
|
||||
// };
|
||||
|
||||
// Set the swapchains window dimensions
|
||||
let initial_dimensions = if let Some(dimensions) = surface.window().get_inner_size() {
|
||||
// convert to physical pixels
|
||||
let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into();
|
||||
[dimensions.0, dimensions.1]
|
||||
} else {
|
||||
// The window no longer exists so exit the application.
|
||||
panic!("window closed");
|
||||
};
|
||||
|
||||
Swapchain::new(device.clone(),
|
||||
surface.clone(),
|
||||
capabilities.min_image_count,
|
||||
format,
|
||||
initial_dimensions,
|
||||
1, // Layers
|
||||
usage,
|
||||
&queue,
|
||||
SurfaceTransform::Identity,
|
||||
alpha,
|
||||
PresentMode::Fifo, true, None).unwrap()
|
||||
};
|
||||
let capabilities = surface.capabilities(physical).unwrap();
|
||||
let format = capabilities.supported_formats[0].0;
|
||||
|
||||
let filenames = ShaderKernels::get_path(filename.clone());
|
||||
|
||||
@@ -208,7 +211,7 @@ impl ShaderKernels {
|
||||
// be one of the types of the `vulkano::format` module (or alternatively one
|
||||
// of your structs that implements the `FormatDesc` trait). Here we use the
|
||||
// same format as the swapchain.
|
||||
format: swapchain.clone().format(),
|
||||
format: format,
|
||||
// TODO:
|
||||
samples: 1,
|
||||
}
|
||||
@@ -224,8 +227,8 @@ impl ShaderKernels {
|
||||
|
||||
|
||||
ShaderKernels {
|
||||
swapchain: swapchain,
|
||||
swapchain_images: images,
|
||||
// swapchain: swapchain,
|
||||
// swapchain_images: images,
|
||||
//physical: physical,
|
||||
//options: CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user