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;
|
2022-09-23 20:40:12 +10:00
|
|
|
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
2020-07-04 23:21:39 +10:00
|
|
|
use std::error::Error;
|
2022-07-30 03:42:10 +10:00
|
|
|
use winit::{
|
|
|
|
dpi::PhysicalSize,
|
|
|
|
event::{Event, VirtualKeyCode, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::WindowBuilder,
|
|
|
|
};
|
2020-07-04 23:21:39 +10:00
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
2022-07-30 03:42:10 +10:00
|
|
|
let event_loop = EventLoop::new();
|
2020-07-04 23:21:39 +10:00
|
|
|
|
|
|
|
unsafe {
|
2021-12-27 21:49:40 +11:00
|
|
|
let entry = ash::Entry::linked();
|
2022-09-23 20:40:12 +10:00
|
|
|
let surface_extensions =
|
|
|
|
ash_window::enumerate_required_extensions(event_loop.raw_display_handle())?;
|
2022-03-30 04:15:14 +11:00
|
|
|
let app_desc = vk::ApplicationInfo::default().api_version(vk::make_api_version(0, 1, 0, 0));
|
|
|
|
let instance_desc = vk::InstanceCreateInfo::default()
|
2020-07-04 23:21:39 +10:00
|
|
|
.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)?;
|
|
|
|
|
2022-09-23 20:40:12 +10:00
|
|
|
let window = WindowBuilder::new()
|
|
|
|
.with_inner_size(PhysicalSize::<u32>::from((800, 600)))
|
|
|
|
.build(&event_loop)?;
|
|
|
|
|
2020-07-04 23:21:39 +10:00
|
|
|
// Create a surface from winit window.
|
2022-09-23 20:40:12 +10:00
|
|
|
let surface = ash_window::create_surface(
|
|
|
|
&entry,
|
|
|
|
&instance,
|
|
|
|
window.raw_display_handle(),
|
|
|
|
window.raw_window_handle(),
|
|
|
|
None,
|
|
|
|
)?;
|
2020-07-04 23:21:39 +10:00
|
|
|
let surface_fn = ash::extensions::khr::Surface::new(&entry, &instance);
|
2023-02-18 04:11:44 +11:00
|
|
|
println!("surface: {surface:?}");
|
2020-07-04 23:21:39 +10:00
|
|
|
|
2022-07-30 03:42:10 +10:00
|
|
|
event_loop.run(move |event, _, control_flow| match event {
|
|
|
|
winit::event::Event::WindowEvent {
|
|
|
|
event:
|
|
|
|
WindowEvent::CloseRequested
|
|
|
|
| WindowEvent::KeyboardInput {
|
|
|
|
input:
|
|
|
|
winit::event::KeyboardInput {
|
|
|
|
virtual_keycode: Some(VirtualKeyCode::Escape),
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
},
|
|
|
|
window_id: _,
|
|
|
|
} => {
|
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
|
|
|
Event::LoopDestroyed => {
|
|
|
|
surface_fn.destroy_surface(surface, None);
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
})
|
2020-07-04 23:21:39 +10:00
|
|
|
}
|
|
|
|
}
|