Add VkInstance
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

This commit is contained in:
Florian RICHER 2024-11-06 22:13:46 +01:00
parent 433dc1afc8
commit 9223b89e4e
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
9 changed files with 237 additions and 122 deletions

51
src/display/app.rs Normal file
View file

@ -0,0 +1,51 @@
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)));
}
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();
}
_ => (),
}
}
}

2
src/display/mod.rs Normal file
View file

@ -0,0 +1,2 @@
mod app;
pub use app::App;