diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 2add574..39bc9cf 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -104,7 +104,7 @@ fn create_surface(instance: &Instance, -> Result { use winit::os::windows::WindowExt; let hwnd = window.get_hwnd() as *mut winapi::windef::HWND__; - let hinstance = unsafe {user32::GetWindow(hwnd, 0) as *const ()}; + let hinstance = unsafe { user32::GetWindow(hwnd, 0) as *const () }; let win32_create_info = vk::Win32SurfaceCreateInfoKHR { s_type: vk::StructureType::Win32SurfaceCreateInfoKhr, p_next: ptr::null(), @@ -118,17 +118,21 @@ fn create_surface(instance: &Instance, } #[cfg(all(unix, not(target_os = "android")))] -fn extension_names() -> Vec { - vec![CString::new("VK_KHR_surface").unwrap(), - CString::new("VK_KHR_xlib_surface").unwrap(), - CString::new("VK_EXT_debug_report").unwrap()] +fn extension_names() -> Vec<*const i8> { + vec![ + Surface::name().as_ptr(), + XlibSurface::name().as_ptr(), + DebugReport::name().as_ptr() + ] } #[cfg(all(windows))] -fn extension_names() -> Vec { - vec![CString::new("VK_KHR_surface").unwrap(), - CString::new("VK_KHR_win32_surface").unwrap(), - CString::new("VK_EXT_debug_report").unwrap()] +fn extension_names() -> Vec<*const i8> { + vec![ + Surface::name().as_ptr(), + Win32Surface::name().as_ptr(), + DebugReport::name().as_ptr() + ] } unsafe extern "system" fn vulkan_debug_callback(_: vk::DebugReportFlagsEXT, @@ -225,10 +229,7 @@ impl ExampleBase { let layers_names_raw: Vec<*const i8> = layer_names.iter() .map(|raw_name| raw_name.as_ptr()) .collect(); - let extension_names = extension_names(); - let extension_names_raw: Vec<*const i8> = extension_names.iter() - .map(|raw_name| raw_name.as_ptr()) - .collect(); + let extension_names_raw = extension_names(); let appinfo = vk::ApplicationInfo { p_application_name: raw_name, s_type: vk::StructureType::ApplicationInfo, @@ -288,10 +289,7 @@ impl ExampleBase { .nth(0) .expect("Couldn't find suitable device."); let queue_family_index = queue_family_index as u32; - let device_extension_names = [CString::new("VK_KHR_swapchain").unwrap()]; - let device_extension_names_raw: Vec<*const i8> = device_extension_names.iter() - .map(|raw_name| raw_name.as_ptr()) - .collect(); + let device_extension_names_raw = [Swapchain::name().as_ptr()]; let features = vk::PhysicalDeviceFeatures { shader_clip_distance: 1, ..Default::default() }; let priorities = [1.0]; diff --git a/src/extensions/debug_report.rs b/src/extensions/debug_report.rs index 28aee4f..0162eaa 100644 --- a/src/extensions/debug_report.rs +++ b/src/extensions/debug_report.rs @@ -4,6 +4,7 @@ use std::mem; use instance::Instance; use entry::Entry; use vk; +use std::ffi::CStr; pub struct DebugReport { handle: vk::Instance, @@ -23,6 +24,10 @@ impl DebugReport { }) } + pub fn name() -> &'static CStr{ + CStr::from_bytes_with_nul(b"VK_EXT_debug_report\0").expect("Wrong extension string") + } + pub unsafe fn destroy_debug_report_callback_ext(&self, debug: vk::DebugReportCallbackEXT) { self.debug_report_fn.destroy_debug_report_callback_ext(self.handle, debug, ptr::null()); } diff --git a/src/extensions/surface.rs b/src/extensions/surface.rs index 938afc1..468579c 100644 --- a/src/extensions/surface.rs +++ b/src/extensions/surface.rs @@ -4,6 +4,7 @@ use std::mem; use instance::Instance; use entry::Entry; use vk; +use std::ffi::CStr; pub struct Surface { pub handle: vk::Instance, @@ -23,6 +24,10 @@ impl Surface { }) } + pub fn name() -> &'static CStr{ + CStr::from_bytes_with_nul(b"VK_KHR_surface\0").expect("Wrong extension string") + } + pub fn get_physical_device_surface_support_khr(&self, physical_device: vk::PhysicalDevice, queue_index: vk::uint32_t, diff --git a/src/extensions/swapchain.rs b/src/extensions/swapchain.rs index 7c8d2e1..08ac2c4 100644 --- a/src/extensions/swapchain.rs +++ b/src/extensions/swapchain.rs @@ -4,6 +4,7 @@ use std::mem; use instance::Instance; use device::Device; use vk; +use std::ffi::CStr; pub struct Swapchain { handle: vk::Device, @@ -21,6 +22,10 @@ impl Swapchain { }) } + pub fn name() -> &'static CStr{ + CStr::from_bytes_with_nul(b"VK_KHR_swapchain\0").expect("Wrong extension string") + } + pub unsafe fn destroy_swapchain_khr(&self, swapchain: vk::SwapchainKHR) { self.swapchain_fn.destroy_swapchain_khr(self.handle, swapchain, ptr::null()); } diff --git a/src/extensions/win32_surface.rs b/src/extensions/win32_surface.rs index 376987c..212fb99 100644 --- a/src/extensions/win32_surface.rs +++ b/src/extensions/win32_surface.rs @@ -4,6 +4,7 @@ use std::mem; use instance::Instance; use entry::Entry; use vk; +use std::ffi::CStr; pub struct Win32Surface { pub handle: vk::Instance, @@ -23,6 +24,10 @@ impl Win32Surface { }) } + pub fn name() -> &'static CStr{ + CStr::from_bytes_with_nul(b"VK_KHR_win32_surface\0").expect("Wrong extension string") + } + pub fn create_win32_surface_khr(&self, create_info: &vk::Win32SurfaceCreateInfoKHR) -> VkResult { diff --git a/src/extensions/xlibsurface.rs b/src/extensions/xlibsurface.rs index 400125d..c419c10 100644 --- a/src/extensions/xlibsurface.rs +++ b/src/extensions/xlibsurface.rs @@ -4,6 +4,7 @@ use std::mem; use instance::Instance; use entry::Entry; use vk; +use std::ffi::CStr; pub struct XlibSurface { pub handle: vk::Instance, @@ -23,6 +24,10 @@ impl XlibSurface { }) } + pub fn name() -> &'static CStr{ + CStr::from_bytes_with_nul(b"VK_KHR_xlib_surface\0").expect("Wrong extension string") + } + pub fn create_xlib_surface_khr(&self, create_info: &vk::XlibSurfaceCreateInfoKHR) -> VkResult { diff --git a/src/vk.rs b/src/vk.rs index 86a283d..da9765d 100644 --- a/src/vk.rs +++ b/src/vk.rs @@ -3224,13 +3224,6 @@ pub mod types { } } } - - impl ::std::ops::Deref for $name{ - type Target = *mut u8; - fn deref(&self) -> &Self::Target{ - &self.ptr - } - } } }