Add a lot of thing
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
This commit is contained in:
parent
09e109d6ef
commit
fb4ac29c07
6 changed files with 255 additions and 43 deletions
|
@ -1,27 +1,26 @@
|
|||
use crate::vulkan::{VkSurface, LOG_TARGET};
|
||||
use ash::prelude::VkResult;
|
||||
use ash::vk;
|
||||
use ash::vk::{Extent2D, PresentModeKHR, SurfaceFormatKHR, SurfaceTransformFlagsKHR, SwapchainCreateInfoKHR, SwapchainKHR};
|
||||
|
||||
pub struct VkSwapchain {
|
||||
swapchain_loader: ash::khr::swapchain::Device,
|
||||
pub(super) swapchain_loader: ash::khr::swapchain::Device,
|
||||
swapchain: Option<vk::SwapchainKHR>,
|
||||
|
||||
desired_image_count: u32,
|
||||
surface_format: SurfaceFormatKHR,
|
||||
surface_resolution: Extent2D,
|
||||
present_mode: PresentModeKHR,
|
||||
pre_transform: SurfaceTransformFlagsKHR,
|
||||
pub(super) desired_image_count: u32,
|
||||
pub(super) surface_format: vk::SurfaceFormatKHR,
|
||||
pub(super) surface_resolution: vk::Extent2D,
|
||||
pub(super) present_mode: vk::PresentModeKHR,
|
||||
pub(super) pre_transform: vk::SurfaceTransformFlagsKHR,
|
||||
}
|
||||
|
||||
impl VkSwapchain {
|
||||
pub fn new(
|
||||
pub(super) fn new(
|
||||
swapchain_loader: ash::khr::swapchain::Device,
|
||||
desired_image_count: u32,
|
||||
surface_format: SurfaceFormatKHR,
|
||||
surface_resolution: Extent2D,
|
||||
present_mode: PresentModeKHR,
|
||||
pre_transform: SurfaceTransformFlagsKHR,
|
||||
surface_format: vk::SurfaceFormatKHR,
|
||||
surface_resolution: vk::Extent2D,
|
||||
present_mode: vk::PresentModeKHR,
|
||||
pre_transform: vk::SurfaceTransformFlagsKHR,
|
||||
) -> Self {
|
||||
Self {
|
||||
swapchain_loader,
|
||||
|
@ -34,7 +33,7 @@ impl VkSwapchain {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_swapchain(&mut self, surface: &VkSurface) -> VkResult<()> {
|
||||
pub(super) fn create_swapchain(&mut self, surface: &VkSurface) -> VkResult<()> {
|
||||
let mut swapchain_create_info = self.create_swapchain_info(surface);
|
||||
|
||||
if let Some(old_swapchain) = self.swapchain {
|
||||
|
@ -44,15 +43,40 @@ impl VkSwapchain {
|
|||
let swapchain = unsafe {
|
||||
self.swapchain_loader.create_swapchain(&swapchain_create_info, None)?
|
||||
};
|
||||
log::debug!(target: LOG_TARGET, "Swapchain created : {swapchain_create_info:#?}");
|
||||
|
||||
match self.swapchain {
|
||||
Some(_) => log::debug!(target: LOG_TARGET, "Swapchain created : {swapchain_create_info:#?}"),
|
||||
None => log::debug!(target: LOG_TARGET, "Swapchain updated : {swapchain_create_info:#?}")
|
||||
}
|
||||
|
||||
self.swapchain = Some(swapchain);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_swapchain_info(&self, surface: &VkSurface) -> SwapchainCreateInfoKHR {
|
||||
SwapchainCreateInfoKHR::default()
|
||||
pub(super) fn update_resolution(&mut self, surface: &VkSurface, width: u32, height: u32) -> VkResult<()> {
|
||||
log::debug!(target: LOG_TARGET, "New resolution requested for swapchain {width}x{height}");
|
||||
self.surface_resolution = vk::Extent2D {
|
||||
width,
|
||||
height,
|
||||
};
|
||||
|
||||
self.create_swapchain(surface)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn get_swapchain_images(&self) -> anyhow::Result<Vec<vk::Image>> {
|
||||
let swapchain = self.swapchain
|
||||
.ok_or_else(|| anyhow::anyhow!("Can't get swapchain images : Swapchain is not set"))?;
|
||||
|
||||
let images = unsafe { self.swapchain_loader.get_swapchain_images(swapchain)? };
|
||||
|
||||
Ok(images)
|
||||
}
|
||||
|
||||
fn create_swapchain_info(&self, surface: &VkSurface) -> vk::SwapchainCreateInfoKHR {
|
||||
vk::SwapchainCreateInfoKHR::default()
|
||||
.surface(surface.surface)
|
||||
.min_image_count(self.desired_image_count)
|
||||
.image_color_space(self.surface_format.color_space)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue