Move DisplaySwapchain into a new extension

This commit is contained in:
maik klein 2017-01-20 17:13:04 +01:00
parent a5f78297d1
commit b7842db292
3 changed files with 59 additions and 1 deletions

View file

@ -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<I: InstanceV1_0, D: DeviceV1_0>(instance: &I,
device: &D)
-> Result<DisplaySwapchain, Vec<&'static str>> {
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<Vec<vk::SwapchainKHR>>{
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),
}
}
}

View file

@ -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;

View file

@ -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(