1cd810653c
* Constify generated extension names * Constify hand-written extension names * Make ash-window list extensions as &[*const c_char] This alters enumerate_required_extensions() to return the same type that is expected by vk::InstanceCreateInfoBuilder::enabled_extension_names(), allowing simple Vulkan apps to omit the boilerplate of mapping to an intermediate Vec<*const c_char>. Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
50 lines
1.6 KiB
Rust
50 lines
1.6 KiB
Rust
//! Demonstrate interop with beryllium/SDL windows.
|
|
//!
|
|
//! Sample creates a surface from a window through the
|
|
//! platform agnostic window handle trait.
|
|
//!
|
|
//! On instance extensions platform specific extensions need to be enabled.
|
|
|
|
use ash::vk;
|
|
use std::error::Error;
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
let mut events_loop = winit::EventsLoop::new();
|
|
let window = winit::WindowBuilder::new()
|
|
.with_dimensions((800, 600).into())
|
|
.build(&events_loop)?;
|
|
|
|
unsafe {
|
|
let entry = ash::Entry::linked();
|
|
let surface_extensions = ash_window::enumerate_required_extensions(&window)?;
|
|
let app_desc = vk::ApplicationInfo::builder().api_version(vk::make_api_version(0, 1, 0, 0));
|
|
let instance_desc = vk::InstanceCreateInfo::builder()
|
|
.application_info(&app_desc)
|
|
.enabled_extension_names(surface_extensions);
|
|
|
|
let instance = entry.create_instance(&instance_desc, None)?;
|
|
|
|
// Create a surface from winit window.
|
|
let surface = ash_window::create_surface(&entry, &instance, &window, None)?;
|
|
let surface_fn = ash::extensions::khr::Surface::new(&entry, &instance);
|
|
println!("surface: {:?}", surface);
|
|
|
|
let mut running = true;
|
|
while running {
|
|
events_loop.poll_events(|event| {
|
|
if let winit::Event::WindowEvent {
|
|
event: winit::WindowEvent::CloseRequested,
|
|
..
|
|
} = event
|
|
{
|
|
running = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
surface_fn.destroy_surface(surface, None);
|
|
}
|
|
|
|
Ok(())
|
|
}
|