Typesafe handles, e.g Instance, Device, Queue etc

This commit is contained in:
maik klein 2016-12-28 03:54:30 +01:00
parent e8d679c84f
commit ac14f440a7
3 changed files with 29 additions and 29 deletions

View file

@ -60,7 +60,7 @@ impl Entry {
Err(ref err) => Err(LoadingError::LibraryLoadFailure(err.clone())),
}?;
let entry_fn = vk::EntryFn::load(|name| unsafe {
mem::transmute(static_fn.get_instance_proc_addr(ptr::null_mut(), name.as_ptr()))
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
}).map_err(|err| LoadingError::EntryLoadError(err))?;
Ok(Entry {
static_fn: static_fn,

View file

@ -34,7 +34,7 @@ impl Instance {
create_info: &vk::DeviceCreateInfo)
-> Result<Device, DeviceError> {
unsafe {
let mut device = mem::uninitialized();
let mut device: vk::Device = mem::uninitialized();
let err_code = self.instance_fn
.create_device(physical_device, create_info, ptr::null(), &mut device);
if err_code != vk::Result::Success {

View file

@ -3209,36 +3209,36 @@ pub mod types {
CallbackRef = 1,
}
macro_rules! vk_define_handle{
($name: ident) => {
#[derive(Clone, Copy, Debug)]
#[repr(C)]
#[doc(hidden)]
pub struct Instance_T(u8);
pub type Instance = *mut Instance_T;
pub struct $name{
ptr: *mut u8
}
impl $name{
pub unsafe fn null() -> Self{
$name{
ptr: ::std::ptr::null_mut()
}
}
}
#[repr(C)]
#[doc(hidden)]
pub struct PhysicalDevice_T(u8);
pub type PhysicalDevice = *mut PhysicalDevice_T;
#[repr(C)]
#[doc(hidden)]
pub struct Device_T(u8);
pub type Device = *mut Device_T;
#[repr(C)]
#[doc(hidden)]
pub struct Queue_T(u8);
pub type Queue = *mut Queue_T;
#[repr(C)]
#[doc(hidden)]
pub struct CommandBuffer_T(u8);
pub type CommandBuffer = *mut CommandBuffer_T;
impl ::std::ops::Deref for $name{
type Target = *mut u8;
fn deref(&self) -> &Self::Target{
&self.ptr
}
}
}
}
vk_define_handle!(Instance);
vk_define_handle!(Device);
vk_define_handle!(PhysicalDevice);
vk_define_handle!(Queue);
vk_define_handle!(CommandBuffer);
handle_nondispatchable!(Semaphore);
handle_nondispatchable!(Fence);