abrasion/engine/src/render/mod.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

2019-05-06 23:24:55 +00:00
use std::sync::Arc;
2019-05-05 14:52:27 +00:00
use winit::{
dpi::LogicalSize,
2019-05-06 23:24:55 +00:00
Window,
2019-05-05 14:52:27 +00:00
WindowEvent,
WindowBuilder,
EventsLoop,
Event,
};
2019-05-06 23:24:55 +00:00
use vulkano_win::VkSurfaceBuild;
use vulkano::instance as vi;
use vulkano::swapchain as vs;
2019-05-05 14:52:27 +00:00
mod vulkan;
const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
pub struct Renderer {
2019-05-06 23:24:55 +00:00
instance: vulkan::Instance<winit::Window>,
2019-05-05 14:52:27 +00:00
events_loop: EventsLoop,
}
impl Renderer {
pub fn initialize() -> Self {
2020-01-18 23:27:11 +00:00
let mut instance = vulkan::Instance::new("abrasion".to_string());
2019-05-06 23:24:55 +00:00
let (events_loop, surface) = Self::init_window(instance.get_vulkan());
2020-01-18 20:03:31 +00:00
instance.use_surface(&surface);
2019-05-05 14:52:27 +00:00
Self {
instance,
events_loop,
}
}
2019-05-06 23:24:55 +00:00
fn init_window(instance: Arc<vi::Instance>) -> (EventsLoop, Arc<vs::Surface<Window>>) {
2019-05-05 14:52:27 +00:00
let events_loop = EventsLoop::new();
2019-05-06 23:24:55 +00:00
let surface = WindowBuilder::new()
2020-01-18 23:27:11 +00:00
.with_title("abrasion")
2019-05-05 14:52:27 +00:00
.with_dimensions(LogicalSize::new(f64::from(WIDTH), f64::from(HEIGHT)))
2019-05-06 23:24:55 +00:00
.build_vk_surface(&events_loop, instance.clone())
.expect("could not create surface");
(events_loop, surface)
2019-05-05 14:52:27 +00:00
}
pub fn main_loop(&mut self) {
loop {
let mut done = false;
self.events_loop.poll_events(|ev| {
if let Event::WindowEvent { event: WindowEvent::CloseRequested, .. } = ev {
done = true
}
});
if done {
return;
}
}
}
}