#![cfg(feature = "vulkan")]
extern crate glfw;
extern crate vk_sys;
use std::os::raw::c_void;
use std::mem;
use std::ptr;
use vk_sys::{
self as vk,
EntryPoints,
InstancePointers,
InstanceCreateInfo,
Instance as VkInstance,
Result as VkResult
};
use glfw::Context;
fn main() {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
glfw.window_hint(glfw::WindowHint::Visible(true));
let (mut window, _) = glfw.create_window(640, 480, "Defaults", glfw::WindowMode::Windowed)
.expect("Failed to create GLFW window.");
window.make_current();
assert!(glfw.vulkan_supported());
let required_extensions = glfw.get_required_instance_extensions().unwrap_or(vec![]);
assert!(required_extensions.contains(&"VK_KHR_surface".to_string()));
println!("Vulkan required extensions: {:?}", required_extensions);
let mut entry_points: EntryPoints = EntryPoints::load(|func| {
window.get_instance_proc_address(0, func.to_str().unwrap()) as *const c_void
});
let instance: VkInstance = unsafe { create_instance(&mut entry_points) };
let mut instance_ptrs: InstancePointers = InstancePointers::load(|func| {
window.get_instance_proc_address(instance, func.to_str().unwrap()) as *const c_void
});
unsafe {
destroy_instance(instance, &mut instance_ptrs);
}
println!("Vulkan instance successfully created and destroyed.");
}
unsafe fn create_instance(entry_points: &mut EntryPoints) -> VkInstance {
let mut instance: VkInstance = mem::uninitialized();
let info: InstanceCreateInfo = InstanceCreateInfo {
sType: vk::STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
pNext: ptr::null(),
flags: 0,
pApplicationInfo: ptr::null(),
enabledLayerCount: 0,
ppEnabledLayerNames: ptr::null(),
enabledExtensionCount: 0,
ppEnabledExtensionNames: ptr::null()
};
let res: VkResult = entry_points.CreateInstance(&info as *const InstanceCreateInfo,
ptr::null(),
&mut instance as *mut VkInstance);
assert_eq!(res, vk::SUCCESS);
instance
}
unsafe fn destroy_instance(instance: VkInstance, instance_ptrs: &mut InstancePointers) {
instance_ptrs.DestroyInstance(instance, ptr::null());
}