@@ -2,7 +2,7 @@ use crate::{
22 render_systems:: {
33 EguiPipelines , EguiTextureBindGroups , EguiTextureId , EguiTransform , EguiTransforms ,
44 } ,
5- EguiRenderOutput , EguiSettings , WindowSize ,
5+ EguiRenderOutput , EguiSettings , RenderTargetSize ,
66} ;
77use bevy:: {
88 ecs:: world:: { FromWorld , World } ,
@@ -22,7 +22,10 @@ use bevy::{
2222 VertexBufferLayout , VertexFormat , VertexState , VertexStepMode ,
2323 } ,
2424 renderer:: { RenderContext , RenderDevice , RenderQueue } ,
25- texture:: { Image , ImageAddressMode , ImageFilterMode , ImageSampler , ImageSamplerDescriptor } ,
25+ texture:: {
26+ GpuImage , Image , ImageAddressMode , ImageFilterMode , ImageSampler ,
27+ ImageSamplerDescriptor ,
28+ } ,
2629 view:: { ExtractedWindow , ExtractedWindows } ,
2730 } ,
2831} ;
@@ -96,12 +99,19 @@ pub struct EguiPipelineKey {
9699}
97100
98101impl EguiPipelineKey {
99- /// Extracts target texture format in egui renderpass
102+ /// Constructs a pipeline key from a window.
100103 pub fn from_extracted_window ( window : & ExtractedWindow ) -> Option < Self > {
101104 Some ( Self {
102105 texture_format : window. swap_chain_texture_format ?. add_srgb_suffix ( ) ,
103106 } )
104107 }
108+
109+ /// Constructs a pipeline key from a gpu image.
110+ pub fn from_gpu_image ( image : & GpuImage ) -> Self {
111+ EguiPipelineKey {
112+ texture_format : image. texture_format . add_srgb_suffix ( ) ,
113+ }
114+ }
105115}
106116
107117impl SpecializedRenderPipeline for EguiPipeline {
@@ -160,25 +170,24 @@ impl SpecializedRenderPipeline for EguiPipeline {
160170 }
161171}
162172
163- struct DrawCommand {
164- clip_rect : egui:: Rect ,
165- primitive : DrawPrimitive ,
173+ pub ( crate ) struct DrawCommand {
174+ pub ( crate ) clip_rect : egui:: Rect ,
175+ pub ( crate ) primitive : DrawPrimitive ,
166176}
167177
168- enum DrawPrimitive {
178+ pub ( crate ) enum DrawPrimitive {
169179 Egui ( EguiDraw ) ,
170180 PaintCallback ( PaintCallbackDraw ) ,
171181}
172182
173- struct PaintCallbackDraw {
174- callback : std:: sync:: Arc < EguiBevyPaintCallback > ,
175- rect : egui:: Rect ,
183+ pub ( crate ) struct PaintCallbackDraw {
184+ pub ( crate ) callback : std:: sync:: Arc < EguiBevyPaintCallback > ,
185+ pub ( crate ) rect : egui:: Rect ,
176186}
177187
178- #[ derive( Debug ) ]
179- struct EguiDraw {
180- vertices_count : usize ,
181- egui_texture : EguiTextureId ,
188+ pub ( crate ) struct EguiDraw {
189+ pub ( crate ) vertices_count : usize ,
190+ pub ( crate ) egui_texture : EguiTextureId ,
182191}
183192
184193/// Egui render node.
@@ -223,9 +232,10 @@ impl Node for EguiNode {
223232 return ;
224233 } ;
225234
226- let mut window_sizes = world. query :: < ( & WindowSize , & mut EguiRenderOutput ) > ( ) ;
235+ let mut render_target_size = world. query :: < ( & RenderTargetSize , & mut EguiRenderOutput ) > ( ) ;
227236
228- let Ok ( ( window_size, mut render_output) ) = window_sizes. get_mut ( world, self . window_entity )
237+ let Ok ( ( window_size, mut render_output) ) =
238+ render_target_size. get_mut ( world, self . window_entity )
229239 else {
230240 return ;
231241 } ;
@@ -382,21 +392,13 @@ impl Node for EguiNode {
382392 let pipeline_cache = world. get_resource :: < PipelineCache > ( ) . unwrap ( ) ;
383393
384394 let extracted_windows = & world. get_resource :: < ExtractedWindows > ( ) . unwrap ( ) . windows ;
385- let extracted_window =
386- if let Some ( extracted_window ) = extracted_windows . get ( & self . window_entity ) {
387- extracted_window
388- } else {
389- return Ok ( ( ) ) ; // No window
395+ let extracted_window = extracted_windows . get ( & self . window_entity ) ;
396+ let swap_chain_texture_view =
397+ match extracted_window . and_then ( |v| v . swap_chain_texture_view . as_ref ( ) ) {
398+ None => return Ok ( ( ) ) ,
399+ Some ( window ) => window,
390400 } ;
391401
392- let swap_chain_texture_view = if let Some ( swap_chain_texture_view) =
393- extracted_window. swap_chain_texture_view . as_ref ( )
394- {
395- swap_chain_texture_view
396- } else {
397- return Ok ( ( ) ) ; // No swapchain texture
398- } ;
399-
400402 let render_queue = world. get_resource :: < RenderQueue > ( ) . unwrap ( ) ;
401403
402404 let ( vertex_buffer, index_buffer) = match ( & self . vertex_buffer , & self . index_buffer ) {
@@ -432,13 +434,19 @@ impl Node for EguiNode {
432434 } ) ;
433435 let mut render_pass = TrackedRenderPass :: new ( device, render_pass) ;
434436
435- let Some ( key) = EguiPipelineKey :: from_extracted_window ( extracted_window) else {
436- return Ok ( ( ) ) ;
437+ let ( physical_width, physical_height, pipeline_key) = match extracted_window {
438+ Some ( window) => (
439+ window. physical_width ,
440+ window. physical_height ,
441+ EguiPipelineKey :: from_extracted_window ( window) ,
442+ ) ,
443+ None => unreachable ! ( ) ,
437444 } ;
438-
439- let Some ( pipeline_id) = egui_pipelines. get ( & extracted_window. entity ) else {
445+ let Some ( key) = pipeline_key else {
440446 return Ok ( ( ) ) ;
441447 } ;
448+
449+ let pipeline_id = egui_pipelines. get ( & self . window_entity ) . unwrap ( ) ;
442450 let Some ( pipeline) = pipeline_cache. get_render_pipeline ( * pipeline_id) else {
443451 return Ok ( ( ) ) ;
444452 } ;
@@ -454,8 +462,8 @@ impl Node for EguiNode {
454462 render_pass. set_viewport (
455463 0. ,
456464 0. ,
457- extracted_window . physical_width as f32 ,
458- extracted_window . physical_height as f32 ,
465+ physical_width as f32 ,
466+ physical_height as f32 ,
459467 0. ,
460468 1. ,
461469 ) ;
@@ -479,11 +487,12 @@ impl Node for EguiNode {
479487 y : ( draw_command. clip_rect . max . y * self . pixels_per_point ) . round ( ) as u32 ,
480488 } ,
481489 } ;
490+
482491 let scrissor_rect = clip_urect. intersect ( bevy:: math:: URect :: new (
483492 0 ,
484493 0 ,
485- extracted_window . physical_width ,
486- extracted_window . physical_width ,
494+ physical_width,
495+ physical_height ,
487496 ) ) ;
488497 if scrissor_rect. is_empty ( ) {
489498 continue ;
@@ -529,10 +538,7 @@ impl Node for EguiNode {
529538 viewport : command. rect ,
530539 clip_rect : draw_command. clip_rect ,
531540 pixels_per_point : self . pixels_per_point ,
532- screen_size_px : [
533- extracted_window. physical_width ,
534- extracted_window. physical_height ,
535- ] ,
541+ screen_size_px : [ physical_width, physical_height] ,
536542 } ;
537543
538544 let viewport = info. viewport_in_pixels ( ) ;
@@ -649,7 +655,7 @@ impl EguiBevyPaintCallback {
649655 }
650656 }
651657
652- fn cb ( & self ) -> & dyn EguiBevyPaintCallbackImpl {
658+ pub ( crate ) fn cb ( & self ) -> & dyn EguiBevyPaintCallbackImpl {
653659 self . 0 . as_ref ( )
654660 }
655661}
0 commit comments