rename renderer to vulkan
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 20m44s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 20m44s
This commit is contained in:
parent
6bc3dbd53d
commit
f32db72101
8 changed files with 11 additions and 11 deletions
|
@ -1,102 +0,0 @@
|
|||
use std::sync::Arc;
|
||||
use vulkano::device::Device;
|
||||
use vulkano::image::view::ImageView;
|
||||
use vulkano::image::{Image, ImageUsage};
|
||||
use vulkano::pipeline::graphics::viewport::Viewport;
|
||||
use vulkano::swapchain::{Surface, Swapchain, SwapchainCreateInfo};
|
||||
use vulkano::sync::GpuFuture;
|
||||
use vulkano::{sync, Validated, VulkanError};
|
||||
use winit::window::Window;
|
||||
|
||||
pub struct RenderContext {
|
||||
pub(super) window: Arc<Window>,
|
||||
pub(super) swapchain: Arc<Swapchain>,
|
||||
pub(super) attachment_image_views: Vec<Arc<ImageView>>,
|
||||
pub(super) viewport: Viewport,
|
||||
pub(super) recreate_swapchain: bool,
|
||||
pub(super) previous_frame_end: Option<Box<dyn GpuFuture>>,
|
||||
}
|
||||
|
||||
impl RenderContext {
|
||||
pub fn new(window: Arc<Window>, surface: Arc<Surface>, device: &Arc<Device>) -> Self {
|
||||
let window_size = window.inner_size();
|
||||
|
||||
let (swapchain, images) = {
|
||||
let surface_capabilities = device
|
||||
.physical_device()
|
||||
.surface_capabilities(&surface, Default::default())
|
||||
.unwrap();
|
||||
|
||||
let (image_format, _) = device
|
||||
.physical_device()
|
||||
.surface_formats(&surface, Default::default())
|
||||
.unwrap()[0];
|
||||
|
||||
Swapchain::new(
|
||||
device.clone(),
|
||||
surface,
|
||||
SwapchainCreateInfo {
|
||||
// 2 because with some graphics driver, it crash on fullscreen because fullscreen need to min image to works.
|
||||
min_image_count: surface_capabilities.min_image_count.max(2),
|
||||
image_format,
|
||||
image_extent: window_size.into(),
|
||||
image_usage: ImageUsage::COLOR_ATTACHMENT,
|
||||
composite_alpha: surface_capabilities
|
||||
.supported_composite_alpha
|
||||
.into_iter()
|
||||
.next()
|
||||
.unwrap(),
|
||||
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let attachment_image_views = window_size_dependent_setup(&images);
|
||||
|
||||
let viewport = Viewport {
|
||||
offset: [0.0, 0.0],
|
||||
extent: window_size.into(),
|
||||
depth_range: 0.0..=1.0,
|
||||
};
|
||||
|
||||
let recreate_swapchain = false;
|
||||
let previous_frame_end = Some(sync::now(device.clone()).boxed());
|
||||
|
||||
Self {
|
||||
window,
|
||||
swapchain,
|
||||
attachment_image_views,
|
||||
viewport,
|
||||
recreate_swapchain,
|
||||
previous_frame_end,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_swapchain(&mut self) -> Result<(), Validated<VulkanError>> {
|
||||
if !self.recreate_swapchain {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let window_size = self.window.inner_size();
|
||||
let (new_swapchain, new_images) = self.swapchain.recreate(SwapchainCreateInfo {
|
||||
image_extent: window_size.into(),
|
||||
..self.swapchain.create_info()
|
||||
})?;
|
||||
|
||||
self.swapchain = new_swapchain;
|
||||
self.attachment_image_views = window_size_dependent_setup(&new_images);
|
||||
self.viewport.extent = window_size.into();
|
||||
self.recreate_swapchain = false;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn window_size_dependent_setup(images: &[Arc<Image>]) -> Vec<Arc<ImageView>> {
|
||||
images
|
||||
.iter()
|
||||
.map(|image| ImageView::new_default(image.clone()).unwrap())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue