Add traits and FP loading for Entry 1.1

This commit is contained in:
Gabriel Majeri 2018-08-22 10:49:41 +03:00
parent 67ea40b30c
commit ce6820f923
2 changed files with 44 additions and 2 deletions

View file

@ -6,7 +6,7 @@ use std::fmt;
use std::mem; use std::mem;
use std::path::Path; use std::path::Path;
use std::ptr; use std::ptr;
use version::{EntryLoader, FunctionPointers, InstanceLoader, V1_0}; use version::{EntryLoader, FunctionPointers, InstanceLoader, V1_0, V1_1};
use vk; use vk;
use RawPtr; use RawPtr;
@ -150,6 +150,22 @@ impl EntryV1_0 for Entry<V1_0> {
} }
} }
impl EntryV1_0 for Entry<V1_1> {
type Fp = V1_1;
fn fp_v1_0(&self) -> &vk::EntryFnV1_0 {
self.entry_fn.fp_v1_0()
}
fn static_fn(&self) -> &vk::StaticFn {
&self.static_fn
}
}
impl EntryV1_1 for Entry<V1_1> {
fn fp_v1_1(&self) -> &vk::EntryFnV1_1 {
&self.entry_fn.entry_fn_1_1
}
}
impl<V: FunctionPointers> Entry<V> { impl<V: FunctionPointers> Entry<V> {
pub fn new() -> Result<Self, LoadingError> { pub fn new() -> Result<Self, LoadingError> {
let lib = VK_LIB let lib = VK_LIB

View file

@ -15,7 +15,7 @@ pub struct V1_1;
impl FunctionPointers for V1_1 { impl FunctionPointers for V1_1 {
type InstanceFp = InstanceFpV1_1; type InstanceFp = InstanceFpV1_1;
type DeviceFp = DeviceFpV1_1; type DeviceFp = DeviceFpV1_1;
type EntryFp = EntryFpV1_0; type EntryFp = EntryFpV1_1;
} }
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
@ -50,6 +50,32 @@ pub trait EntryLoader: Sized {
unsafe fn load(static_fn: &vk::StaticFn) -> Result<Self, Vec<&'static str>>; unsafe fn load(static_fn: &vk::StaticFn) -> Result<Self, Vec<&'static str>>;
} }
#[allow(non_camel_case_types)]
#[derive(Clone)]
pub struct EntryFpV1_1 {
pub entry_fn_1_0: vk::EntryFnV1_0,
pub entry_fn_1_1: vk::EntryFnV1_1,
}
impl EntryLoader for EntryFpV1_1 {
fn fp_v1_0(&self) -> &vk::EntryFnV1_0 {
&self.entry_fn_1_0
}
unsafe fn load(static_fn: &vk::StaticFn) -> Result<Self, Vec<&'static str>> {
let entry_fn_1_0 = vk::EntryFnV1_0::load(|name| {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
})?;
let entry_fn_1_1 = vk::EntryFnV1_1::load(|name| {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
})?;
Ok(EntryFpV1_1 {
entry_fn_1_0,
entry_fn_1_1,
})
}
}
pub trait InstanceLoader: Sized { pub trait InstanceLoader: Sized {
unsafe fn load( unsafe fn load(
static_fn: &vk::StaticFn, static_fn: &vk::StaticFn,