This commit is contained in:
parent
6dae0339db
commit
2c3392c3ea
3 changed files with 1201 additions and 17 deletions
1158
Cargo.lock
generated
1158
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -13,11 +13,11 @@ winit = { version = "0.30", features = ["rwh_06"] }
|
|||
vulkano = "0.35"
|
||||
vulkano-shaders = "0.35"
|
||||
vulkano-util = "0.35"
|
||||
egui_winit_vulkano = { version = "0.28" }
|
||||
|
||||
# Math
|
||||
glam = { version = "0.30" }
|
||||
|
||||
|
||||
# Log and tracing
|
||||
log = "0.4"
|
||||
env_logger = "0.11"
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::render::scene::Scene;
|
||||
use egui_winit_vulkano::{Gui, GuiConfig, egui};
|
||||
use vulkano::command_buffer::{
|
||||
AutoCommandBufferBuilder, CommandBufferUsage, RenderingAttachmentInfo, RenderingInfo,
|
||||
};
|
||||
|
@ -18,7 +21,9 @@ use super::vulkan_context::VulkanContext;
|
|||
pub struct App {
|
||||
vulkan_context: VulkanContext,
|
||||
vulkano_windows: VulkanoWindows,
|
||||
gui: HashMap<WindowId, Gui>,
|
||||
scene: Option<Scene>,
|
||||
clear_color: [f32; 3],
|
||||
}
|
||||
|
||||
impl From<VulkanoContext> for App {
|
||||
|
@ -26,14 +31,16 @@ impl From<VulkanoContext> for App {
|
|||
Self {
|
||||
vulkan_context: VulkanContext::new(vulkano_context),
|
||||
vulkano_windows: VulkanoWindows::default(),
|
||||
gui: HashMap::new(),
|
||||
scene: None,
|
||||
clear_color: [0.0, 0.0, 0.0],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler for App {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
self.vulkano_windows.create_window(
|
||||
let window_id = self.vulkano_windows.create_window(
|
||||
event_loop,
|
||||
self.vulkan_context.vulkano_context(),
|
||||
&WindowDescriptor {
|
||||
|
@ -46,6 +53,21 @@ impl ApplicationHandler for App {
|
|||
|_| {},
|
||||
);
|
||||
|
||||
let gui = {
|
||||
let renderer = self.vulkano_windows.get_renderer_mut(window_id).unwrap();
|
||||
Gui::new(
|
||||
event_loop,
|
||||
renderer.surface(),
|
||||
renderer.graphics_queue(),
|
||||
renderer.swapchain_format(),
|
||||
GuiConfig {
|
||||
is_overlay: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
};
|
||||
self.gui.insert(window_id, gui);
|
||||
|
||||
self.scene = Some(
|
||||
Scene::load(
|
||||
&self.vulkan_context,
|
||||
|
@ -55,14 +77,23 @@ impl ApplicationHandler for App {
|
|||
);
|
||||
}
|
||||
|
||||
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
||||
fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
|
||||
let renderer = self.vulkano_windows.get_renderer_mut(id).unwrap();
|
||||
let gui = self.gui.get_mut(&id).unwrap();
|
||||
gui.update(&event);
|
||||
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
log::debug!("The close button was pressed; stopping");
|
||||
event_loop.exit();
|
||||
}
|
||||
WindowEvent::Resized(_) => {
|
||||
renderer.resize();
|
||||
}
|
||||
WindowEvent::ScaleFactorChanged { .. } => {
|
||||
renderer.resize();
|
||||
}
|
||||
WindowEvent::RedrawRequested => {
|
||||
let renderer = self.vulkano_windows.get_primary_renderer_mut().unwrap();
|
||||
let acquire_future = renderer.acquire(None, |_| {}).unwrap();
|
||||
|
||||
let mut builder = AutoCommandBufferBuilder::primary(
|
||||
|
@ -87,7 +118,7 @@ impl ApplicationHandler for App {
|
|||
color_attachments: vec![Some(RenderingAttachmentInfo {
|
||||
load_op: AttachmentLoadOp::Clear,
|
||||
store_op: AttachmentStoreOp::Store,
|
||||
clear_value: Some([0.0, 0.0, 0.0, 1.0].into()),
|
||||
clear_value: Some(self.clear_color.into()),
|
||||
..RenderingAttachmentInfo::image_view(
|
||||
renderer.swapchain_image_view().clone(),
|
||||
)
|
||||
|
@ -109,7 +140,7 @@ impl ApplicationHandler for App {
|
|||
|
||||
let command_buffer = builder.build().unwrap();
|
||||
|
||||
let future = acquire_future
|
||||
let render_future = acquire_future
|
||||
.then_execute(
|
||||
self.vulkan_context
|
||||
.vulkano_context()
|
||||
|
@ -119,7 +150,22 @@ impl ApplicationHandler for App {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
renderer.present(future.boxed(), true);
|
||||
gui.immediate_ui(|gui| {
|
||||
let ctx = gui.context();
|
||||
|
||||
egui::Window::new("Informations")
|
||||
.vscroll(true)
|
||||
.show(&ctx, |ui| {
|
||||
ui.label(format!("Format: {:?}", renderer.swapchain_format()));
|
||||
ui.label(format!("Resolution: {:?}", renderer.resolution()));
|
||||
ui.color_edit_button_rgb(&mut self.clear_color);
|
||||
});
|
||||
});
|
||||
|
||||
let render_future =
|
||||
gui.draw_on_image(render_future, renderer.swapchain_image_view());
|
||||
|
||||
renderer.present(render_future.boxed(), true);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue