Add VkInstance
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
This commit is contained in:
parent
433dc1afc8
commit
9223b89e4e
9 changed files with 237 additions and 122 deletions
51
src/display/app.rs
Normal file
51
src/display/app.rs
Normal 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();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue