2020-07-04 23:21:39 +10:00
|
|
|
//! 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.
|
|
|
|
|
2021-05-01 01:13:23 +10:00
|
|
|
use ash::vk;
|
2020-07-04 23:21:39 +10:00
|
|
|
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 {
|
2021-12-27 21:49:40 +11:00
|
|
|
let entry = ash::Entry::linked();
|
2020-07-04 23:21:39 +10:00
|
|
|
let surface_extensions = ash_window::enumerate_required_extensions(&window)?;
|
2021-06-06 19:00:29 +10:00
|
|
|
let app_desc = vk::ApplicationInfo::builder().api_version(vk::make_api_version(0, 1, 0, 0));
|
2020-07-04 23:21:39 +10:00
|
|
|
let instance_desc = vk::InstanceCreateInfo::builder()
|
|
|
|
.application_info(&app_desc)
|
2022-03-23 09:47:26 +11:00
|
|
|
.enabled_extension_names(surface_extensions);
|
2020-07-04 23:21:39 +10:00
|
|
|
|
|
|
|
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 {
|
2020-09-02 04:26:39 +10:00
|
|
|
events_loop.poll_events(|event| {
|
|
|
|
if let winit::Event::WindowEvent {
|
2020-07-04 23:21:39 +10:00
|
|
|
event: winit::WindowEvent::CloseRequested,
|
|
|
|
..
|
2020-09-02 04:26:39 +10:00
|
|
|
} = event
|
|
|
|
{
|
|
|
|
running = false;
|
|
|
|
}
|
2020-07-04 23:21:39 +10:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_fn.destroy_surface(surface, None);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|