Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
60 lines
1.9 KiB
Rust
60 lines
1.9 KiB
Rust
use winit::{
|
|
application::ApplicationHandler, event::WindowEvent, event_loop::ActiveEventLoop, raw_window_handle::{HasDisplayHandle, DisplayHandle, HandleError}, window::{Window, WindowId}
|
|
};
|
|
use crate::vulkan::VkInstance;
|
|
|
|
#[derive(Default)]
|
|
pub struct App {
|
|
window: Option<Window>,
|
|
instance: Option<VkInstance>,
|
|
}
|
|
|
|
impl HasDisplayHandle for App {
|
|
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
|
|
self.window.as_ref()
|
|
.ok_or_else(|| HandleError::Unavailable)?
|
|
.display_handle()
|
|
}
|
|
}
|
|
|
|
impl ApplicationHandler for App {
|
|
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
|
let window_attributes = Window::default_attributes()
|
|
.with_title("Rust ASH Test")
|
|
.with_visible(true)
|
|
.with_inner_size(winit::dpi::LogicalSize::new(
|
|
f64::from(800),
|
|
f64::from(600),
|
|
));
|
|
|
|
self.window = event_loop
|
|
.create_window(window_attributes)
|
|
.ok();
|
|
|
|
self.instance = self.window
|
|
.as_ref()
|
|
.and_then(|w| Some(VkInstance::new(w)));
|
|
|
|
if let Some(instance) = self.instance.as_ref() {
|
|
let physical_devices = instance.get_physical_devices();
|
|
|
|
println!("Physical Devices:");
|
|
for physical_device in physical_devices {
|
|
println!("\tNom: {:?}, Priorité: {}", physical_device.properties.device_name_as_c_str().unwrap_or_default(), physical_device.priority())
|
|
}
|
|
}
|
|
}
|
|
|
|
fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
|
|
match event {
|
|
WindowEvent::CloseRequested => {
|
|
println!("The close button was pressed; stopping");
|
|
event_loop.exit();
|
|
}
|
|
WindowEvent::RedrawRequested => {
|
|
self.window.as_ref().unwrap().request_redraw();
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|