diff --git a/src/extensions/display_swapchain.rs b/src/extensions/display_swapchain.rs new file mode 100644 index 0000000..1aab0c0 --- /dev/null +++ b/src/extensions/display_swapchain.rs @@ -0,0 +1,51 @@ +#![allow(dead_code)] +use prelude::*; +use std::ptr; +use std::mem; +use vk; +use std::ffi::CStr; +use ::RawPtr; +use version::{InstanceV1_0, DeviceV1_0}; + +#[derive(Clone)] +pub struct DisplaySwapchain { + handle: vk::Device, + swapchain_fn: vk::DisplaySwapchainFn, +} + +impl DisplaySwapchain { + pub fn new(instance: &I, + device: &D) + -> Result> { + let swapchain_fn = vk::DisplaySwapchainFn::load(|name| { + unsafe { mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) } + })?; + Ok(DisplaySwapchain { + handle: device.handle(), + swapchain_fn: swapchain_fn, + }) + } + + pub fn name() -> &'static CStr { + CStr::from_bytes_with_nul(b"VK_KHR_display_swapchain\0").expect("Wrong extension string") + } + + pub unsafe fn create_shared_swapchains_khr( + &self, + create_infos: &[vk::SwapchainCreateInfoKHR], + allocation_callbacks: Option<&vk::AllocationCallbacks>, + ) -> VkResult>{ + let mut swapchains = Vec::with_capacity(create_infos.len()); + let err_code = self.swapchain_fn + .create_shared_swapchains_khr(self.handle, + create_infos.len() as u32, + create_infos.as_ptr(), + allocation_callbacks.as_raw_ptr(), + swapchains.as_mut_ptr()); + swapchains.set_len(create_infos.len()); + match err_code { + vk::Result::Success => Ok(swapchains), + _ => Err(err_code), + } + } +} diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index d0c71b0..761b363 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -1,4 +1,5 @@ pub use self::swapchain::Swapchain; +pub use self::display_swapchain::DisplaySwapchain; pub use self::surface::Surface; pub use self::xlib_surface::XlibSurface; pub use self::debug_report::DebugReport; @@ -9,6 +10,7 @@ pub use self::wayland_surface::WaylandSurface; pub use self::android_surface::AndroidSurface; mod swapchain; +mod display_swapchain; mod surface; mod xlib_surface; mod win32_surface; diff --git a/src/vk.rs b/src/vk.rs index a38db7b..41d75ad 100644 --- a/src/vk.rs +++ b/src/vk.rs @@ -4649,8 +4649,9 @@ vk_functions!{ p_command_buffers: *const CommandBuffer, ) -> (); } + vk_functions!{ - SwapchainFn, + DisplaySwapchainFn, "vkCreateSharedSwapchainsKHR", create_shared_swapchains_khr( device: Device, swapchain_count: uint32_t, @@ -4658,7 +4659,10 @@ vk_functions!{ p_allocator: *const AllocationCallbacks, p_swapchains: *mut SwapchainKHR, ) -> Result; +} +vk_functions!{ + SwapchainFn, "vkCreateSwapchainKHR", create_swapchain_khr( device: Device, p_create_info: *const SwapchainCreateInfoKHR, @@ -4693,6 +4697,7 @@ vk_functions!{ p_present_info: *const PresentInfoKHR, ) -> Result; } + vk_functions!{ SurfaceFn, "vkDestroySurfaceKHR", destroy_surface_khr(