impl: add egui!!
This commit is contained in:
parent
b1c164dc6a
commit
6c70f7bc2e
2 changed files with 40 additions and 29 deletions
|
|
@ -294,6 +294,8 @@ impl Application {
|
|||
}
|
||||
|
||||
fn handle_event(&mut self, event: &WindowEvent, active_event_loop: &ActiveEventLoop) {
|
||||
let _ = self.egui_winit.on_window_event(&self.window, event);
|
||||
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
info!("Close requested. Exiting...");
|
||||
|
|
@ -340,6 +342,8 @@ impl Application {
|
|||
|
||||
let raw_input = self.egui_winit.take_egui_input(&self.window);
|
||||
|
||||
tracing::info!("{:?}", raw_input);
|
||||
|
||||
let egui::FullOutput {
|
||||
platform_output,
|
||||
textures_delta,
|
||||
|
|
@ -350,17 +354,18 @@ impl Application {
|
|||
self.egui_app.build_ui(ctx);
|
||||
});
|
||||
|
||||
self.renderer.update_textures(textures_delta).unwrap();
|
||||
|
||||
self.egui_winit
|
||||
.handle_platform_output(&self.window, platform_output);
|
||||
|
||||
let clipped_primitives = self.egui_ctx.tessellate(shapes, pixels_per_point);
|
||||
|
||||
// --- Render Frame ---
|
||||
match self.renderer.render_frame(
|
||||
pixels_per_point,
|
||||
textures_delta,
|
||||
&clipped_primitives,
|
||||
) {
|
||||
match self
|
||||
.renderer
|
||||
.render_frame(pixels_per_point, &clipped_primitives)
|
||||
{
|
||||
Ok(_) => {
|
||||
self.window.request_redraw();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,10 +183,30 @@ impl Renderer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_textures(&mut self, textures_delta: TexturesDelta) -> Result<(), RendererError> {
|
||||
tracing::trace!("Updating EGUI textures!");
|
||||
|
||||
if !textures_delta.free.is_empty() {
|
||||
self.frames_data[self.current_frame].textures_to_free =
|
||||
Some(textures_delta.free.clone());
|
||||
}
|
||||
|
||||
if !textures_delta.set.is_empty() {
|
||||
self.egui_renderer
|
||||
.set_textures(
|
||||
self.device.get_graphics_queue().handle(),
|
||||
self.frames_data[self.current_frame].command_pool,
|
||||
textures_delta.set.as_slice(),
|
||||
)
|
||||
.expect("Failed to update texture");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render_frame(
|
||||
&mut self,
|
||||
pixels_per_point: f32,
|
||||
textures_delta: TexturesDelta,
|
||||
clipped_primitives: &[ClippedPrimitive],
|
||||
) -> Result<(), RendererError> {
|
||||
// --- Handle Resize ---
|
||||
|
|
@ -253,29 +273,6 @@ impl Renderer {
|
|||
.begin_command_buffer(command_buffer, &cmd_begin_info)?;
|
||||
}
|
||||
|
||||
if !textures_delta.free.is_empty() {
|
||||
tracing::debug!("Setting textures to free");
|
||||
frame_data.textures_to_free = Some(textures_delta.free.clone());
|
||||
}
|
||||
|
||||
if !textures_delta.set.is_empty() {
|
||||
tracing::trace!("Setting EGUI textures");
|
||||
self.egui_renderer.set_textures(
|
||||
self.device.get_graphics_queue().handle(),
|
||||
frame_data.command_pool,
|
||||
textures_delta.set.as_slice(),
|
||||
)?;
|
||||
}
|
||||
|
||||
tracing::info!("Rendering EGUI");
|
||||
self.egui_renderer.cmd_draw(
|
||||
command_buffer,
|
||||
self.swapchain_extent,
|
||||
pixels_per_point,
|
||||
clipped_primitives,
|
||||
)?;
|
||||
tracing::debug!("Rendered EGUI");
|
||||
|
||||
let current_swapchain_image = swapchain_ref.images()[image_index as usize];
|
||||
|
||||
let initial_layout_transition_barrier = vk::ImageMemoryBarrier::default()
|
||||
|
|
@ -382,6 +379,15 @@ impl Renderer {
|
|||
self.device.raw().cmd_draw(command_buffer, 3, 1, 0, 0);
|
||||
}
|
||||
|
||||
tracing::trace!("Rendering EGUI");
|
||||
self.egui_renderer.cmd_draw(
|
||||
command_buffer,
|
||||
self.swapchain_extent,
|
||||
pixels_per_point,
|
||||
clipped_primitives,
|
||||
)?;
|
||||
tracing::trace!("Rendered EGUI");
|
||||
|
||||
// --- End Dynamic Rendering ---
|
||||
unsafe {
|
||||
// Need unsafe for Vulkan commands
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue