From 29ab08a36c36ea0d43b6b484d37e1aa1d0d70bf5 Mon Sep 17 00:00:00 2001 From: maik klein Date: Thu, 29 Dec 2016 04:41:41 +0100 Subject: [PATCH] Add all surface extensions --- src/extensions/android_surface.rs | 47 +++++++++++++++++++++++++++++++ src/extensions/mod.rs | 8 ++++++ src/extensions/wayland_surface.rs | 46 ++++++++++++++++++++++++++++++ src/extensions/xcb_surface.rs | 46 ++++++++++++++++++++++++++++++ src/vk.rs | 1 - 5 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/extensions/android_surface.rs create mode 100644 src/extensions/wayland_surface.rs create mode 100644 src/extensions/xcb_surface.rs diff --git a/src/extensions/android_surface.rs b/src/extensions/android_surface.rs new file mode 100644 index 0000000..09548b3 --- /dev/null +++ b/src/extensions/android_surface.rs @@ -0,0 +1,47 @@ + +use prelude::*; +use std::mem; +use instance::Instance; +use entry::Entry; +use vk; +use std::ffi::CStr; +use ::RawPtr; + +pub struct AndroidSurface { + handle: vk::Instance, + android_surface_fn: vk::AndroidSurfaceFn, +} + +impl AndroidSurface { + pub fn new(entry: &Entry, instance: &Instance) -> Result { + let surface_fn = vk::AndroidSurfaceFn::load(|name| { + unsafe { + mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + } + })?; + Ok(AndroidSurface { + handle: instance.handle(), + android_surface_fn: surface_fn, + }) + } + + pub fn name() -> &'static CStr { + CStr::from_bytes_with_nul(b"VK_KHR_android_surface\0").expect("Wrong extension string") + } + + pub unsafe fn create_android_surface_khr(&self, + create_info: &vk::AndroidSurfaceCreateInfoKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { + let mut surface = mem::uninitialized(); + let err_code = self.android_surface_fn + .create_android_surface_khr(self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut surface); + match err_code { + vk::Result::Success => Ok(surface), + _ => Err(err_code), + } + } +} diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index ec0c13e..b782dbc 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -3,9 +3,17 @@ pub use self::surface::Surface; pub use self::xlibsurface::XlibSurface; pub use self::debug_report::DebugReport; pub use self::win32_surface::Win32Surface; +pub use self::mir_surface::MirSurface; +pub use self::xcb_surface::XcbSurface; +pub use self::wayland_surface::WaylandSurface; +pub use self::android_surface::AndroidSurface; mod swapchain; mod surface; mod xlibsurface; mod debug_report; mod win32_surface; +mod mir_surface; +mod android_surface; +mod wayland_surface; +mod xcb_surface; diff --git a/src/extensions/wayland_surface.rs b/src/extensions/wayland_surface.rs new file mode 100644 index 0000000..8f59120 --- /dev/null +++ b/src/extensions/wayland_surface.rs @@ -0,0 +1,46 @@ +use prelude::*; +use std::mem; +use instance::Instance; +use entry::Entry; +use vk; +use std::ffi::CStr; +use ::RawPtr; + +pub struct WaylandSurface { + handle: vk::Instance, + wayland_surface_fn: vk::WaylandSurfaceFn, +} + +impl WaylandSurface { + pub fn new(entry: &Entry, instance: &Instance) -> Result { + let surface_fn = vk::WaylandSurfaceFn::load(|name| { + unsafe { + mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + } + })?; + Ok(WaylandSurface { + handle: instance.handle(), + wayland_surface_fn: surface_fn, + }) + } + + pub fn name() -> &'static CStr { + CStr::from_bytes_with_nul(b"VK_KHR_wayland_surface\0").expect("Wrong extension string") + } + + pub unsafe fn create_wayland_surface_khr(&self, + create_info: &vk::WaylandSurfaceCreateInfoKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { + let mut surface = mem::uninitialized(); + let err_code = self.wayland_surface_fn + .create_wayland_surface_khr(self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut surface); + match err_code { + vk::Result::Success => Ok(surface), + _ => Err(err_code), + } + } +} diff --git a/src/extensions/xcb_surface.rs b/src/extensions/xcb_surface.rs new file mode 100644 index 0000000..fd8ecee --- /dev/null +++ b/src/extensions/xcb_surface.rs @@ -0,0 +1,46 @@ +use prelude::*; +use std::mem; +use instance::Instance; +use entry::Entry; +use vk; +use std::ffi::CStr; +use ::RawPtr; + +pub struct XcbSurface { + handle: vk::Instance, + xcb_surface_fn: vk::XcbSurfaceFn, +} + +impl XcbSurface { + pub fn new(entry: &Entry, instance: &Instance) -> Result { + let surface_fn = vk::XcbSurfaceFn::load(|name| { + unsafe { + mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + } + })?; + Ok(XcbSurface { + handle: instance.handle(), + xcb_surface_fn: surface_fn, + }) + } + + pub fn name() -> &'static CStr { + CStr::from_bytes_with_nul(b"VK_KHR_xcb_surface\0").expect("Wrong extension string") + } + + pub unsafe fn create_xcb_surface_khr(&self, + create_info: &vk::XcbSurfaceCreateInfoKHR, + allocation_callbacks: Option<&vk::AllocationCallbacks>) + -> VkResult { + let mut surface = mem::uninitialized(); + let err_code = self.xcb_surface_fn + .create_xcb_surface_khr(self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut surface); + match err_code { + vk::Result::Success => Ok(surface), + _ => Err(err_code), + } + } +} diff --git a/src/vk.rs b/src/vk.rs index 91a4130..39f0057 100644 --- a/src/vk.rs +++ b/src/vk.rs @@ -3824,7 +3824,6 @@ vk_functions!{ p_property_count: *mut uint32_t, p_properties: *mut SparseImageFormatProperties, ) -> (); - } vk_functions!{