Merge pull request #43 from kvark/entry

Nicer Entry implementation
This commit is contained in:
Maik Klein 2018-01-31 19:48:49 +01:00 committed by GitHub
commit a9dd6df8fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -93,10 +93,10 @@ pub trait EntryV1_0 {
return Err(InstanceError::VkError(err_code)); return Err(InstanceError::VkError(err_code));
} }
let instance_fp = let instance_fp =
<<Self as EntryV1_0>::Fp as FunctionPointers>::InstanceFp::load( <Self::Fp as FunctionPointers>::InstanceFp::load(
&self.static_fn(), &self.static_fn(),
instance, instance,
).map_err(|err| InstanceError::LoadError(err))?; ).map_err(InstanceError::LoadError)?;
Ok(Instance::from_raw(instance, instance_fp)) Ok(Instance::from_raw(instance, instance_fp))
} }
@ -159,28 +159,23 @@ impl EntryV1_0 for Entry<V1_0> {
} }
impl<V: FunctionPointers> Entry<V> { impl<V: FunctionPointers> Entry<V> {
pub fn new() -> Result<Entry<V>, LoadingError> { pub fn new() -> Result<Self, LoadingError> {
let static_fn = match *VK_LIB { let lib = VK_LIB
Ok(ref lib) => { .as_ref()
let static_fn = .map_err(|err| LoadingError::LibraryLoadError(err.clone()))?;
vk::StaticFn::load(|name| unsafe {
let name = name.to_str().unwrap(); let static_fn = vk::StaticFn::load(|name| unsafe {
let f = match lib.symbol(name) { lib.symbol(name.to_str().unwrap())
Ok(s) => s, .unwrap_or(ptr::null_mut())
Err(_) => ptr::null(), }).map_err(LoadingError::StaticLoadError)?;
};
f
}).map_err(|err| LoadingError::StaticLoadError(err))?;
Ok(static_fn)
}
Err(ref err) => Err(LoadingError::LibraryLoadError(err.clone())),
}?;
let entry_fn = unsafe { let entry_fn = unsafe {
V::EntryFp::load(&static_fn).map_err(|err| LoadingError::EntryLoadError(err))? V::EntryFp::load(&static_fn)
}; }.map_err(LoadingError::EntryLoadError)?;
Ok(Entry { Ok(Entry {
static_fn: static_fn, static_fn,
entry_fn: entry_fn, entry_fn,
}) })
} }
} }