diff --git a/examples/paint_callback.rs b/examples/paint_callback.rs index 00da9d58..a0c57c67 100644 --- a/examples/paint_callback.rs +++ b/examples/paint_callback.rs @@ -101,6 +101,7 @@ impl EguiBevyPaintCallbackImpl for CustomPaintCallback { .and_then(|cache| cache.get_render_pipeline(comp.pipeline_id)) }) else { + warn!("Could not find pipeline."); return; }; diff --git a/examples/two_windows.rs b/examples/two_windows.rs index ba6174af..6bd22110 100644 --- a/examples/two_windows.rs +++ b/examples/two_windows.rs @@ -70,6 +70,7 @@ fn ui_first_window_system( ) { let bevy_texture_id = egui_user_textures.add_image(images.bevy_icon.clone_weak()); let Ok(mut ctx) = egui_ctx.get_single_mut() else { + warn!("Could not find ctx."); return; }; egui::Window::new("First Window") @@ -100,6 +101,7 @@ fn ui_second_window_system( ) { let bevy_texture_id = egui_user_textures.add_image(images.bevy_icon.clone_weak()); let Ok(mut ctx) = egui_ctx.get_single_mut() else { + warn!("Could not find ctx(2)."); return; }; egui::Window::new("Second Window") diff --git a/src/egui_node.rs b/src/egui_node.rs index 2a02ec4e..92b0e099 100644 --- a/src/egui_node.rs +++ b/src/egui_node.rs @@ -6,7 +6,8 @@ use crate::{ }; use bevy::{ ecs::world::{FromWorld, World}, - prelude::{Entity, Handle, Resource}, + log::{info, warn}, + prelude::{Handle, Resource}, render::{ render_asset::RenderAssetUsages, render_graph::{Node, NodeRunError, RenderGraphContext}, @@ -227,11 +228,13 @@ impl EguiNode { impl Node for EguiNode { fn update(&mut self, world: &mut World) { + info!("drawing"); let Some(key) = world .get_resource::() .and_then(|windows| windows.windows.get(&self.window_entity_main.id())) .and_then(EguiPipelineKey::from_extracted_window) else { + warn!("Could not make EguiPipelineKey."); return; }; @@ -241,6 +244,7 @@ impl Node for EguiNode { let Ok((egui_settings, window_size, mut render_output)) = render_target_query.get_mut(world, self.window_entity_render.id()) else { + warn!("Could not find settings."); return; }; let window_size = *window_size; @@ -248,6 +252,8 @@ impl Node for EguiNode { self.pixels_per_point = window_size.scale_factor * egui_settings.scale_factor; if window_size.physical_width == 0.0 || window_size.physical_height == 0.0 { + warn!("small window"); + return; } @@ -285,6 +291,7 @@ impl Node for EguiNode { )) .is_empty() { + warn!("empty clip"); continue; } @@ -327,9 +334,7 @@ impl Node for EguiNode { index_offset += mesh.vertices.len() as u32; let texture_handle = match mesh.texture_id { - egui::TextureId::Managed(id) => { - EguiTextureId::Managed(self.window_entity_render.id(), id) - } + egui::TextureId::Managed(id) => EguiTextureId::Managed(self.window_entity_main, id), egui::TextureId::User(id) => EguiTextureId::User(id), }; @@ -399,7 +404,11 @@ impl Node for EguiNode { let extracted_window = extracted_windows.get(&self.window_entity_main.id()); let swap_chain_texture_view = match extracted_window.and_then(|v| v.swap_chain_texture_view.as_ref()) { - None => return Ok(()), + None => { + warn!("no extracted_window for eguinode"); + + return Ok(()); + } Some(window) => window, }; @@ -407,7 +416,10 @@ impl Node for EguiNode { let (vertex_buffer, index_buffer) = match (&self.vertex_buffer, &self.index_buffer) { (Some(vertex), Some(index)) => (vertex, index), - _ => return Ok(()), + _ => { + warn!("no vertex or index buffer for eguinode"); + return Ok(()); + } }; render_queue.write_buffer(vertex_buffer, 0, &self.vertex_data); @@ -422,6 +434,8 @@ impl Node for EguiNode { None => unreachable!(), }; let Some(key) = pipeline_key else { + warn!("no pipeline KEY for eguinode"); + return Ok(()); }; @@ -474,6 +488,7 @@ impl Node for EguiNode { let pipeline_id = egui_pipelines.get(&self.window_entity_main).unwrap(); let Some(pipeline) = pipeline_cache.get_render_pipeline(*pipeline_id) else { + warn!("no pipeline for eguinode"); return Ok(()); }; @@ -521,6 +536,7 @@ impl Node for EguiNode { physical_height, )); if scrissor_rect.is_empty() { + warn!("too small scissor"); continue; } diff --git a/src/egui_render_to_texture_node.rs b/src/egui_render_to_texture_node.rs index 9a21873e..b83fb8d0 100644 --- a/src/egui_render_to_texture_node.rs +++ b/src/egui_render_to_texture_node.rs @@ -8,7 +8,6 @@ use crate::{ }; use bevy::{ ecs::world::World, - prelude::Entity, render::{ render_asset::RenderAssets, render_graph::{Node, NodeRunError, RenderGraphContext, RenderLabel}, @@ -177,7 +176,7 @@ impl Node for EguiRenderToTextureNode { let texture_handle = match mesh.texture_id { egui::TextureId::Managed(id) => { - EguiTextureId::Managed(self.render_to_texture_target_render.id(), id) + EguiTextureId::Managed(self.render_to_texture_target_main, id) } egui::TextureId::User(id) => EguiTextureId::User(id), }; diff --git a/src/render_systems.rs b/src/render_systems.rs index a325d4d6..10fe58ab 100644 --- a/src/render_systems.rs +++ b/src/render_systems.rs @@ -43,7 +43,7 @@ impl ExtractResource for ExtractedEguiManagedTextures { #[derive(Debug, PartialEq, Eq, Hash)] pub enum EguiTextureId { /// Textures allocated via Egui. - Managed(Entity, u64), + Managed(MainEntity, u64), /// Textures allocated via Bevy. User(u64), } @@ -73,7 +73,10 @@ impl ExtractedEguiTextures<'_> { .0 .iter() .map(|(&(window, texture_id), managed_tex)| { - (EguiTextureId::Managed(window, texture_id), managed_tex.id()) + ( + EguiTextureId::Managed(MainEntity::from(window), texture_id), + managed_tex.id(), + ) }) .chain( self.user_textures @@ -91,8 +94,8 @@ pub fn setup_new_windows_render_system( ) { for (window, render_window) in windows.iter() { let egui_pass = EguiPass { - entity_index: window.index(), - entity_generation: window.generation(), + entity_index: render_window.index(), + entity_generation: render_window.generation(), }; dbg!("setup_new_windows_render_system"); let new_node = EguiNode::new(MainEntity::from(window), *render_window); @@ -166,11 +169,12 @@ impl EguiTransform { /// Prepares Egui transforms. pub fn prepare_egui_transforms_system( mut egui_transforms: ResMut, - render_targets: Query<(&MainEntity, &EguiSettings, &RenderTargetSize)>, + render_targets: Query<(Option<&MainEntity>, &EguiSettings, &RenderTargetSize)>, render_device: Res, render_queue: Res, egui_pipeline: Res, ) { + info!("prepare_egui_transforms_system"); egui_transforms.buffer.clear(); egui_transforms.offsets.clear(); @@ -181,7 +185,10 @@ pub fn prepare_egui_transforms_system( *size, egui_settings.scale_factor, )); - egui_transforms.offsets.insert(*window_main, offset); + info!(offset); + if let Some(window_main) = window_main { + egui_transforms.offsets.insert(*window_main, offset); + } } egui_transforms @@ -192,6 +199,7 @@ pub fn prepare_egui_transforms_system( match egui_transforms.bind_group { Some((id, _)) if buffer.id() == id => {} _ => { + info!("{:?}", buffer.id()); let transform_bind_group = render_device.create_bind_group( Some("egui transform bind group"), &egui_pipeline.transform_bind_group_layout, @@ -261,8 +269,6 @@ pub fn queue_pipelines_system( let mut pipelines: HashMap = windows .iter() .filter_map(|(window_id, window)| { - dbg!("pipeline"); - //let window_id = render_entity.get(*window_id).ok()?.id(); dbg!("pipeline contd"); let key = EguiPipelineKey::from_extracted_window(window)?; let pipeline_id = @@ -275,6 +281,7 @@ pub fn queue_pipelines_system( render_to_texture .iter() .filter_map(|(main_entity, handle)| { + dbg!("pipeline rtt"); let img = images.get(&handle.0)?; let key = EguiPipelineKey::from_gpu_image(img); let pipeline_id =