stuff..... building & rebuilding swapchain
This commit is contained in:
parent
b7ac53ddca
commit
052fdc4e3e
|
@ -18,6 +18,7 @@ tracing-subscriber = "0.3.18"
|
||||||
vk-mem = "0.4.0"
|
vk-mem = "0.4.0"
|
||||||
vk-sync = "0.1.6"
|
vk-sync = "0.1.6"
|
||||||
winit = "0.30.5"
|
winit = "0.30.5"
|
||||||
|
tinyvec = "1.8"
|
||||||
|
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
smol = "2.0"
|
smol = "2.0"
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use renderer::Renderer;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use winit::{
|
use winit::{
|
||||||
application::ApplicationHandler,
|
application::ApplicationHandler,
|
||||||
dpi::{LogicalSize, PhysicalSize},
|
dpi::{LogicalSize, PhysicalSize},
|
||||||
event_loop::EventLoop,
|
event_loop::EventLoop,
|
||||||
raw_window_handle::HasDisplayHandle,
|
raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle},
|
||||||
window::{Window, WindowAttributes, WindowId},
|
window::{Window, WindowAttributes, WindowId},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,10 +14,11 @@ struct WindowState {
|
||||||
last_resize_events: BTreeMap<WindowId, PhysicalSize<u32>>,
|
last_resize_events: BTreeMap<WindowId, PhysicalSize<u32>>,
|
||||||
window_attrs: WindowAttributes,
|
window_attrs: WindowAttributes,
|
||||||
window: Option<Window>,
|
window: Option<Window>,
|
||||||
|
renderer: Renderer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowState {
|
impl WindowState {
|
||||||
fn new(window_title: String) -> WindowState {
|
fn new(window_title: String, display: DisplayHandle) -> WindowState {
|
||||||
Self {
|
Self {
|
||||||
window: None,
|
window: None,
|
||||||
last_resize_events: BTreeMap::new(),
|
last_resize_events: BTreeMap::new(),
|
||||||
|
@ -24,30 +26,66 @@ impl WindowState {
|
||||||
.with_title(window_title)
|
.with_title(window_title)
|
||||||
.with_resizable(true)
|
.with_resizable(true)
|
||||||
.with_inner_size(LogicalSize::new(800, 600)),
|
.with_inner_size(LogicalSize::new(800, 600)),
|
||||||
|
// TODO: pass down this error and add some kind of error handling UI or dump
|
||||||
|
renderer: Renderer::new(display).expect("renderer"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_final_resize(&mut self, window_id: WindowId, new_size: PhysicalSize<u32>) {
|
fn handle_final_resize(
|
||||||
|
&mut self,
|
||||||
|
window_id: WindowId,
|
||||||
|
new_size: PhysicalSize<u32>,
|
||||||
|
) {
|
||||||
_ = (window_id, new_size);
|
_ = (window_id, new_size);
|
||||||
info!("TODO: implement resize events");
|
info!("TODO: implement resize events");
|
||||||
|
if let Some(ctx) = self.renderer.window_contexts.get_mut(&window_id) {
|
||||||
|
ctx.recreate_swapchain(renderer::Extent2D {
|
||||||
|
width: new_size.width,
|
||||||
|
height: new_size.height,
|
||||||
|
})
|
||||||
|
.expect("swapchain recreation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_draw_request(&mut self, window_id: WindowId) {
|
fn handle_draw_request(&mut self, window_id: WindowId) {
|
||||||
_ = (window_id);
|
_ = window_id;
|
||||||
|
info!("TODO: implement draw request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicationHandler for WindowState {
|
impl ApplicationHandler for WindowState {
|
||||||
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||||
tracing::debug!("winit::resumed");
|
tracing::debug!("winit::resumed");
|
||||||
self.window = Some(event_loop.create_window(self.window_attrs.clone()).unwrap());
|
self.window =
|
||||||
tracing::info!(
|
Some(event_loop.create_window(self.window_attrs.clone()).unwrap());
|
||||||
window = u64::from(self.window.as_ref().unwrap().id()),
|
let window_id = self.window.as_ref().unwrap().id();
|
||||||
"created new window"
|
tracing::info!(window = u64::from(window_id), "created new window");
|
||||||
|
|
||||||
|
let size = self
|
||||||
|
.window_attrs
|
||||||
|
.inner_size
|
||||||
|
.map(|size| size.to_physical(1.0))
|
||||||
|
.unwrap_or(PhysicalSize::new(0, 0));
|
||||||
|
let extent = renderer::Extent2D {
|
||||||
|
width: size.width,
|
||||||
|
height: size.height,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.renderer.new_window_context(
|
||||||
|
extent,
|
||||||
|
window_id,
|
||||||
|
self.window
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.window_handle()
|
||||||
|
.expect("window handle"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn about_to_wait(&mut self, _event_loop: &winit::event_loop::ActiveEventLoop) {
|
fn about_to_wait(
|
||||||
|
&mut self,
|
||||||
|
_event_loop: &winit::event_loop::ActiveEventLoop,
|
||||||
|
) {
|
||||||
for (&window, &resize) in self.last_resize_events.clone().iter() {
|
for (&window, &resize) in self.last_resize_events.clone().iter() {
|
||||||
self.handle_final_resize(window, resize);
|
self.handle_final_resize(window, resize);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +108,10 @@ impl ApplicationHandler for WindowState {
|
||||||
_ = self.last_resize_events.insert(window_id, physical_size);
|
_ = self.last_resize_events.insert(window_id, physical_size);
|
||||||
}
|
}
|
||||||
winit::event::WindowEvent::CloseRequested => {
|
winit::event::WindowEvent::CloseRequested => {
|
||||||
tracing::info!(window = u64::from(window_id), "window close requested");
|
tracing::info!(
|
||||||
|
window = u64::from(window_id),
|
||||||
|
"window close requested"
|
||||||
|
);
|
||||||
event_loop.exit();
|
event_loop.exit();
|
||||||
}
|
}
|
||||||
winit::event::WindowEvent::KeyboardInput {
|
winit::event::WindowEvent::KeyboardInput {
|
||||||
|
@ -108,7 +149,7 @@ fn main() {
|
||||||
tracing_subscriber::fmt().init();
|
tracing_subscriber::fmt().init();
|
||||||
let ev = EventLoop::new().unwrap();
|
let ev = EventLoop::new().unwrap();
|
||||||
|
|
||||||
let display = ev.owned_display_handle().display_handle();
|
let display = ev.display_handle().expect("display handle");
|
||||||
let mut game = WindowState::new("Vidya".to_owned());
|
let mut game = WindowState::new("Vidya".to_owned(), display);
|
||||||
ev.run_app(&mut game).unwrap();
|
ev.run_app(&mut game).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
tinyvec = {workspace = true}
|
||||||
dyn-clone = "1"
|
dyn-clone = "1"
|
||||||
anyhow = "1.0.89"
|
anyhow = "1.0.89"
|
||||||
ash = "0.38.0"
|
ash = "0.38.0"
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue