Expose public api for handle

This commit is contained in:
maik klein 2016-12-24 05:57:44 +01:00
parent 7bfe4d9531
commit 5ad765d2e1
8 changed files with 24 additions and 19 deletions

View file

@ -9,11 +9,15 @@ unsafe impl Sync for Device {}
unsafe impl Send for Device {} unsafe impl Send for Device {}
pub struct Device { pub struct Device {
pub handle: vk::Device, handle: vk::Device,
pub device_fn: vk::DeviceFn, device_fn: vk::DeviceFn,
} }
impl Device { impl Device {
pub fn handle(&self) -> vk::Device{
self.handle
}
pub unsafe fn from_raw(handle: vk::Device, device_fn: vk::DeviceFn) -> Self { pub unsafe fn from_raw(handle: vk::Device, device_fn: vk::DeviceFn) -> Self {
Device { Device {
handle: handle, handle: handle,

View file

@ -26,8 +26,8 @@ lazy_static!{
} }
pub struct Entry { pub struct Entry {
pub static_fn: vk::StaticFn, static_fn: vk::StaticFn,
pub entry_fn: vk::EntryFn, entry_fn: vk::EntryFn,
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -7,20 +7,19 @@ use vk;
pub struct DebugReport { pub struct DebugReport {
pub handle: vk::Instance, handle: vk::Instance,
pub debug_report_fn: vk::DebugReportFn, debug_report_fn: vk::DebugReportFn,
} }
impl DebugReport { impl DebugReport {
pub fn new(entry: &Entry, instance: &Instance) -> Result<DebugReport, String> { pub fn new(entry: &Entry, instance: &Instance) -> Result<DebugReport, String> {
let debug_report_fn = vk::DebugReportFn::load(|name| { let debug_report_fn = vk::DebugReportFn::load(|name| {
unsafe { unsafe {
mem::transmute(entry.static_fn mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
.get_instance_proc_addr(instance.handle, name.as_ptr()))
} }
})?; })?;
Ok(DebugReport { Ok(DebugReport {
handle: instance.handle, handle: instance.handle(),
debug_report_fn: debug_report_fn, debug_report_fn: debug_report_fn,
}) })
} }

View file

@ -13,10 +13,10 @@ pub struct Surface {
impl Surface { impl Surface {
pub fn new(entry: &Entry, instance: &Instance) -> Result<Surface, String> { pub fn new(entry: &Entry, instance: &Instance) -> Result<Surface, String> {
let surface_fn = vk::SurfaceFn::load(|name| { let surface_fn = vk::SurfaceFn::load(|name| {
unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle, name.as_ptr())) } unsafe { mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) }
})?; })?;
Ok(Surface { Ok(Surface {
handle: instance.handle, handle: instance.handle(),
surface_fn: surface_fn, surface_fn: surface_fn,
}) })
} }

View file

@ -14,11 +14,11 @@ impl Swapchain {
pub fn new(instance: &Instance, device: &Device) -> Result<Swapchain, String> { pub fn new(instance: &Instance, device: &Device) -> Result<Swapchain, String> {
let swapchain_fn = vk::SwapchainFn::load(|name| { let swapchain_fn = vk::SwapchainFn::load(|name| {
unsafe { unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle, name.as_ptr())) mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
} }
})?; })?;
Ok(Swapchain { Ok(Swapchain {
handle: device.handle, handle: device.handle(),
swapchain_fn: swapchain_fn, swapchain_fn: swapchain_fn,
}) })
} }

View file

@ -14,12 +14,11 @@ impl XlibSurface {
pub fn new(entry: &Entry, instance: &Instance) -> Result<XlibSurface, String> { pub fn new(entry: &Entry, instance: &Instance) -> Result<XlibSurface, String> {
let surface_fn = vk::XlibSurfaceFn::load(|name| { let surface_fn = vk::XlibSurfaceFn::load(|name| {
unsafe { unsafe {
mem::transmute(entry.static_fn mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
.get_instance_proc_addr(instance.handle, name.as_ptr()))
} }
})?; })?;
Ok(XlibSurface { Ok(XlibSurface {
handle: instance.handle, handle: instance.handle(),
xlib_surface_fn: surface_fn, xlib_surface_fn: surface_fn,
}) })
} }

View file

@ -15,11 +15,14 @@ pub enum DeviceError {
#[derive(Debug)] #[derive(Debug)]
pub struct Instance { pub struct Instance {
pub handle: vk::Instance, handle: vk::Instance,
pub instance_fn: vk::InstanceFn, instance_fn: vk::InstanceFn,
} }
impl Instance { impl Instance {
pub fn handle(&self) -> vk::Instance{
self.handle
}
pub unsafe fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self { pub unsafe fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self {
Instance { Instance {
handle: handle, handle: handle,

View file

@ -3234,13 +3234,13 @@ pub mod types {
pub type Queue = *mut Queue_T; pub type Queue = *mut Queue_T;
handle_nondispatchable!(Semaphore);
#[repr(C)] #[repr(C)]
#[doc(hidden)] #[doc(hidden)]
pub struct CommandBuffer_T(u8); pub struct CommandBuffer_T(u8);
pub type CommandBuffer = *mut CommandBuffer_T; pub type CommandBuffer = *mut CommandBuffer_T;
handle_nondispatchable!(Semaphore);
handle_nondispatchable!(Fence); handle_nondispatchable!(Fence);
handle_nondispatchable!(DeviceMemory); handle_nondispatchable!(DeviceMemory);
handle_nondispatchable!(Buffer); handle_nondispatchable!(Buffer);