Surface loader
This commit is contained in:
parent
b5bb9329f4
commit
601f5573cf
|
@ -17,6 +17,7 @@ pub struct Swapchain {
|
|||
handle: vk::Device,
|
||||
swapchain_fn: vk::SwapchainFn,
|
||||
}
|
||||
|
||||
impl Swapchain {
|
||||
pub fn destroy_swapchain_khr(&self, swapchain: vk::SwapchainKHR) {
|
||||
unsafe {
|
||||
|
@ -59,6 +60,7 @@ impl Swapchain {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_swapchain_images_khr(&self,
|
||||
swapchain: vk::SwapchainKHR)
|
||||
-> VkResult<Vec<vk::Image>> {
|
||||
|
@ -93,6 +95,7 @@ impl Device {
|
|||
swapchain_fn: swapchain_fn,
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn from_raw(handle: vk::Device, device_fn: vk::DeviceFn) -> Self {
|
||||
Device {
|
||||
handle: handle,
|
||||
|
|
|
@ -23,8 +23,8 @@ fn get_path() -> &'static Path {
|
|||
|
||||
pub struct Entry {
|
||||
lib: DynamicLibrary,
|
||||
static_fn: vk::StaticFn,
|
||||
entry_fn: vk::EntryFn,
|
||||
pub static_fn: vk::StaticFn,
|
||||
pub entry_fn: vk::EntryFn,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
192
src/instance.rs
192
src/instance.rs
|
@ -4,6 +4,7 @@ use std::ptr;
|
|||
use std::mem;
|
||||
use vk;
|
||||
use device::Device;
|
||||
use entry::Entry;
|
||||
use shared_library::dynamic_library::DynamicLibrary;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -18,7 +19,112 @@ pub struct Instance {
|
|||
pub instance_fn: vk::InstanceFn,
|
||||
}
|
||||
|
||||
pub struct Surface {
|
||||
pub handle: vk::Instance,
|
||||
pub surface_fn: vk::SurfaceFn,
|
||||
}
|
||||
impl Surface {
|
||||
pub fn get_physical_device_surface_support_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
queue_index: vk::uint32_t,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> bool {
|
||||
unsafe {
|
||||
let mut b = mem::uninitialized();
|
||||
self.surface_fn
|
||||
.get_physical_device_surface_support_khr(physical_device,
|
||||
queue_index,
|
||||
surface,
|
||||
&mut b);
|
||||
b > 0
|
||||
}
|
||||
}
|
||||
pub fn get_physical_device_surface_present_modes_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> VkResult<Vec<vk::PresentModeKHR>> {
|
||||
unsafe {
|
||||
let mut count = 0;
|
||||
self.surface_fn.get_physical_device_surface_present_modes_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
ptr::null_mut());
|
||||
let mut v = Vec::with_capacity(count as usize);
|
||||
let err_code = self.surface_fn
|
||||
.get_physical_device_surface_present_modes_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
v.as_mut_ptr());
|
||||
v.set_len(count as usize);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(v),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_surface_capabilities_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> VkResult<vk::SurfaceCapabilitiesKHR> {
|
||||
unsafe {
|
||||
let mut surface_capabilities = mem::uninitialized();
|
||||
let err_code = self.surface_fn
|
||||
.get_physical_device_surface_capabilities_khr(physical_device,
|
||||
surface,
|
||||
&mut surface_capabilities);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(surface_capabilities),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_surface_formats_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> VkResult<Vec<vk::SurfaceFormatKHR>> {
|
||||
unsafe {
|
||||
let mut count = 0;
|
||||
self.surface_fn.get_physical_device_surface_formats_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
ptr::null_mut());
|
||||
let mut v = Vec::with_capacity(count as usize);
|
||||
let err_code = self.surface_fn
|
||||
.get_physical_device_surface_formats_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
v.as_mut_ptr());
|
||||
v.set_len(count as usize);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(v),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy_surface_khr(&self, surface: vk::SurfaceKHR) {
|
||||
unsafe {
|
||||
self.surface_fn.destroy_surface_khr(self.handle, surface, ptr::null());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
pub fn load_surface(&self, entry: &Entry) -> Surface {
|
||||
let surface_fn = vk::SurfaceFn::load(|name| {
|
||||
unsafe {
|
||||
mem::transmute(entry.static_fn
|
||||
.get_instance_proc_addr(self.handle, name.as_ptr()))
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
Surface {
|
||||
handle: self.handle,
|
||||
surface_fn: surface_fn,
|
||||
}
|
||||
}
|
||||
pub unsafe fn from_raw(handle: vk::Instance, instance_fn: vk::InstanceFn) -> Self {
|
||||
Instance {
|
||||
handle: handle,
|
||||
|
@ -95,77 +201,6 @@ impl Instance {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_surface_present_modes_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> VkResult<Vec<vk::PresentModeKHR>> {
|
||||
unsafe {
|
||||
let mut count = 0;
|
||||
self.instance_fn.get_physical_device_surface_present_modes_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
ptr::null_mut());
|
||||
let mut v = Vec::with_capacity(count as usize);
|
||||
let err_code = self.instance_fn
|
||||
.get_physical_device_surface_present_modes_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
v.as_mut_ptr());
|
||||
v.set_len(count as usize);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(v),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_surface_capabilities_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> VkResult<vk::SurfaceCapabilitiesKHR> {
|
||||
unsafe {
|
||||
let mut surface_capabilities = mem::uninitialized();
|
||||
let err_code = self.instance_fn
|
||||
.get_physical_device_surface_capabilities_khr(physical_device,
|
||||
surface,
|
||||
&mut surface_capabilities);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(surface_capabilities),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_surface_formats_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> VkResult<Vec<vk::SurfaceFormatKHR>> {
|
||||
unsafe {
|
||||
let mut count = 0;
|
||||
self.instance_fn.get_physical_device_surface_formats_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
ptr::null_mut());
|
||||
let mut v = Vec::with_capacity(count as usize);
|
||||
let err_code = self.instance_fn
|
||||
.get_physical_device_surface_formats_khr(physical_device,
|
||||
surface,
|
||||
&mut count,
|
||||
v.as_mut_ptr());
|
||||
v.set_len(count as usize);
|
||||
match err_code {
|
||||
vk::Result::Success => Ok(v),
|
||||
_ => Err(err_code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy_surface_khr(&self, surface: vk::SurfaceKHR) {
|
||||
unsafe {
|
||||
self.instance_fn.destroy_surface_khr(self.handle, surface, ptr::null());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_xlib_surface_khr(&self,
|
||||
create_info: &vk::XlibSurfaceCreateInfoKHR)
|
||||
-> VkResult<vk::SurfaceKHR> {
|
||||
|
@ -181,21 +216,6 @@ impl Instance {
|
|||
|
||||
}
|
||||
|
||||
pub fn get_physical_device_surface_support_khr(&self,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
queue_index: vk::uint32_t,
|
||||
surface: vk::SurfaceKHR)
|
||||
-> bool {
|
||||
unsafe {
|
||||
let mut b = mem::uninitialized();
|
||||
self.instance_fn
|
||||
.get_physical_device_surface_support_khr(physical_device,
|
||||
queue_index,
|
||||
surface,
|
||||
&mut b);
|
||||
b > 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_queue_family_properties(&self,
|
||||
physical_device: vk::PhysicalDevice)
|
||||
|
|
67
src/vk.rs
67
src/vk.rs
|
@ -3831,38 +3831,6 @@ vk_functions!{
|
|||
p_properties: *mut SparseImageFormatProperties,
|
||||
) -> ();
|
||||
|
||||
"vkDestroySurfaceKHR", destroy_surface_khr(
|
||||
instance: Instance,
|
||||
surface: SurfaceKHR,
|
||||
p_allocator: *const AllocationCallbacks,
|
||||
) -> ();
|
||||
|
||||
"vkGetPhysicalDeviceSurfaceSupportKHR", get_physical_device_surface_support_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
queue_family_index: uint32_t,
|
||||
surface: SurfaceKHR,
|
||||
p_supported: *mut Bool32,
|
||||
) -> Result;
|
||||
|
||||
"vkGetPhysicalDeviceSurfaceCapabilitiesKHR", get_physical_device_surface_capabilities_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
surface: SurfaceKHR,
|
||||
p_surface_capabilities: *mut SurfaceCapabilitiesKHR,
|
||||
) -> Result;
|
||||
|
||||
"vkGetPhysicalDeviceSurfaceFormatsKHR", get_physical_device_surface_formats_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
surface: SurfaceKHR,
|
||||
p_surface_format_count: *mut uint32_t,
|
||||
p_surface_formats: *mut SurfaceFormatKHR,
|
||||
) -> Result;
|
||||
|
||||
"vkGetPhysicalDeviceSurfacePresentModesKHR", get_physical_device_surface_present_modes_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
surface: SurfaceKHR,
|
||||
p_present_mode_count: *mut uint32_t,
|
||||
p_present_modes: *mut PresentModeKHR,
|
||||
) -> Result;
|
||||
|
||||
"vkGetPhysicalDeviceXlibPresentationSupportKHR", get_physical_device_xlib_presentation_support_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
|
@ -4887,4 +4855,39 @@ vk_functions!{
|
|||
p_image_index: *mut uint32_t,
|
||||
) -> Result;
|
||||
}
|
||||
vk_functions!{
|
||||
SurfaceFn,
|
||||
"vkDestroySurfaceKHR", destroy_surface_khr(
|
||||
instance: Instance,
|
||||
surface: SurfaceKHR,
|
||||
p_allocator: *const AllocationCallbacks,
|
||||
) -> ();
|
||||
|
||||
"vkGetPhysicalDeviceSurfaceSupportKHR", get_physical_device_surface_support_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
queue_family_index: uint32_t,
|
||||
surface: SurfaceKHR,
|
||||
p_supported: *mut Bool32,
|
||||
) -> Result;
|
||||
|
||||
"vkGetPhysicalDeviceSurfaceCapabilitiesKHR", get_physical_device_surface_capabilities_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
surface: SurfaceKHR,
|
||||
p_surface_capabilities: *mut SurfaceCapabilitiesKHR,
|
||||
) -> Result;
|
||||
|
||||
"vkGetPhysicalDeviceSurfaceFormatsKHR", get_physical_device_surface_formats_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
surface: SurfaceKHR,
|
||||
p_surface_format_count: *mut uint32_t,
|
||||
p_surface_formats: *mut SurfaceFormatKHR,
|
||||
) -> Result;
|
||||
|
||||
"vkGetPhysicalDeviceSurfacePresentModesKHR", get_physical_device_surface_present_modes_khr(
|
||||
physical_device: PhysicalDevice,
|
||||
surface: SurfaceKHR,
|
||||
p_present_mode_count: *mut uint32_t,
|
||||
p_present_modes: *mut PresentModeKHR,
|
||||
) -> Result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue