Add basic window
This commit is contained in:
parent
623deead9e
commit
7787a8b69e
|
@ -6,3 +6,8 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.82"
|
||||||
|
crawl = { path = "../crawl" }
|
||||||
|
env_logger = "0.11.3"
|
||||||
|
log = "0.4.21"
|
||||||
|
pollster = "0.3.0"
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use crawl::{
|
||||||
|
wgpu,
|
||||||
|
winit::{
|
||||||
|
self,
|
||||||
|
dpi::PhysicalSize,
|
||||||
|
event::{Event, WindowEvent},
|
||||||
|
event_loop::EventLoop,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct App<'window> {
|
||||||
|
title: String,
|
||||||
|
event_loop: EventLoop<()>,
|
||||||
|
render_ctx: crawl::Context<'window>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'window> App<'window> {
|
||||||
|
pub async fn new(width: u32, height: u32, title: &str) -> Result<Self> {
|
||||||
|
log::info!("Initialising window...");
|
||||||
|
let size = PhysicalSize::new(width, height);
|
||||||
|
let event_loop = EventLoop::new()?;
|
||||||
|
let window = Arc::new(
|
||||||
|
winit::window::WindowBuilder::new()
|
||||||
|
.with_title(title)
|
||||||
|
.with_inner_size(size)
|
||||||
|
.build(&event_loop)?,
|
||||||
|
);
|
||||||
|
|
||||||
|
let render_ctx = crawl::Context::new(
|
||||||
|
window,
|
||||||
|
wgpu::Limits {
|
||||||
|
max_storage_buffer_binding_size: 1 << 30,
|
||||||
|
max_buffer_size: 1 << 30,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
title: title.to_owned(),
|
||||||
|
event_loop,
|
||||||
|
render_ctx,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(mut self) -> Result<()> {
|
||||||
|
self.event_loop.run(|event, elwt| match event {
|
||||||
|
Event::WindowEvent { window_id, event } if window_id == self.render_ctx.window.id() => {
|
||||||
|
if self.render_ctx.handle_window_event(&event, elwt) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let WindowEvent::RedrawRequested = event {
|
||||||
|
self.render_ctx.window.request_redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
11
src/main.rs
11
src/main.rs
|
@ -1,3 +1,10 @@
|
||||||
fn main() {
|
mod app;
|
||||||
println!("Hello, world!");
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use app::App;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
env_logger::init();
|
||||||
|
pollster::block_on(App::new(1280, 720, "Epic"))?.run()?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue