diff --git a/src/instance.rs b/src/instance.rs index 3be02ec..c010df1 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -19,10 +19,32 @@ pub struct Instance { pub instance_fn: vk::InstanceFn, } +pub struct XlibSurface { + pub handle: vk::Instance, + pub xlib_surface_fn: vk::XlibSurfaceFn, +} + +impl XlibSurface { + pub fn create_xlib_surface_khr(&self, + create_info: &vk::XlibSurfaceCreateInfoKHR) + -> VkResult { + unsafe { + let mut surface = mem::uninitialized(); + let err_code = self.xlib_surface_fn + .create_xlib_surface_khr(self.handle, create_info, ptr::null(), &mut surface); + match err_code { + vk::Result::Success => Ok(surface), + _ => Err(err_code), + } + } + } +} + pub struct Surface { pub handle: vk::Instance, pub surface_fn: vk::SurfaceFn, } + impl Surface { pub fn get_physical_device_surface_support_khr(&self, physical_device: vk::PhysicalDevice, @@ -112,6 +134,19 @@ impl Surface { } impl Instance { + pub fn load_xlib_surface(&self, entry: &Entry) -> XlibSurface { + let surface_fn = vk::XlibSurfaceFn::load(|name| { + unsafe { + mem::transmute(entry.static_fn + .get_instance_proc_addr(self.handle, name.as_ptr())) + } + }) + .unwrap(); + XlibSurface { + handle: self.handle, + xlib_surface_fn: surface_fn, + } + } pub fn load_surface(&self, entry: &Entry) -> Surface { let surface_fn = vk::SurfaceFn::load(|name| { unsafe { @@ -201,22 +236,6 @@ impl Instance { } } - pub fn create_xlib_surface_khr(&self, - create_info: &vk::XlibSurfaceCreateInfoKHR) - -> VkResult { - unsafe { - let mut surface = mem::uninitialized(); - let err_code = self.instance_fn - .create_xlib_surface_khr(self.handle, create_info, ptr::null(), &mut surface); - match err_code { - vk::Result::Success => Ok(surface), - _ => Err(err_code), - } - } - - } - - pub fn get_physical_device_queue_family_properties(&self, physical_device: vk::PhysicalDevice) -> Vec { diff --git a/src/vk.rs b/src/vk.rs index 653ae93..fbc514e 100644 --- a/src/vk.rs +++ b/src/vk.rs @@ -3839,13 +3839,6 @@ vk_functions!{ visual_id: VisualID, ) -> Bool32; - "vkCreateXlibSurfaceKHR", create_xlib_surface_khr( - instance: Instance, - p_create_info: *const XlibSurfaceCreateInfoKHR, - p_allocator: *const AllocationCallbacks, - p_surface: *mut SurfaceKHR, - ) -> Result; - "vkCreateXcbSurfaceKHR", create_xcb_surface_khr( instance: Instance, p_create_info: *const XcbSurfaceCreateInfoKHR, @@ -4890,4 +4883,13 @@ vk_functions!{ p_present_modes: *mut PresentModeKHR, ) -> Result; } +vk_functions!{ + XlibSurfaceFn, + "vkCreateXlibSurfaceKHR", create_xlib_surface_khr( + instance: Instance, + p_create_info: *const XlibSurfaceCreateInfoKHR, + p_allocator: *const AllocationCallbacks, + p_surface: *mut SurfaceKHR, + ) -> Result; +} }