@@ -3,10 +3,7 @@ use std::ops::Range;
33use bevy:: prelude:: * ;
44use bevy:: render:: camera:: { ExtractedCamera , Viewport } ;
55use bevy:: render:: mesh:: allocator:: MeshAllocator ;
6- use bevy:: render:: mesh:: RenderMesh ;
7- use bevy:: render:: render_asset:: RenderAssets ;
86use bevy:: render:: render_phase:: { DrawFunctions , PhaseItemExtraIndex , ViewSortedRenderPhases } ;
9- use bevy:: render:: render_resource:: { PipelineCache , SpecializedMeshPipelines } ;
107use bevy:: render:: sync_world:: MainEntity ;
118use bevy:: render:: view:: { ExtractedView , RenderLayers } ;
129use bevy:: render:: {
@@ -19,15 +16,13 @@ use bevy::render::{
1916} ;
2017use wgpu_types:: ImageSubresourceRange ;
2118
22- use crate :: queue:: OutlineRangefinder ;
19+ use crate :: queue:: { OutlineCache , OutlineCacheEntry , OutlineRangefinder } ;
2320use crate :: uniforms:: ExtractedOutline ;
2421use crate :: view_uniforms:: OutlineQueueStatus ;
2522
2623use super :: bounds:: FloodMeshBounds ;
2724use super :: node:: FloodOutline ;
28- use super :: {
29- DepthMode , DrawMode , DrawOutline , OutlinePipeline , OutlineViewUniform , PassType , PipelineKey ,
30- } ;
25+ use super :: { DrawMode , DrawOutline , OutlineViewUniform } ;
3126
3227pub ( crate ) fn prepare_flood_phases (
3328 query : Query < & ExtractedView , With < OutlineViewUniform > > ,
@@ -41,11 +36,8 @@ pub(crate) fn prepare_flood_phases(
4136#[ allow( clippy:: too_many_arguments) ]
4237pub ( crate ) fn queue_flood_meshes (
4338 flood_draw_functions : Res < DrawFunctions < FloodOutline > > ,
44- outline_pipeline : Res < OutlinePipeline > ,
45- mut pipelines : ResMut < SpecializedMeshPipelines < OutlinePipeline > > ,
46- pipeline_cache : Res < PipelineCache > ,
47- render_meshes : Res < RenderAssets < RenderMesh > > ,
4839 mesh_allocator : Res < MeshAllocator > ,
40+ outline_cache : Res < OutlineCache > ,
4941 material_meshes : Query < ( Entity , & MainEntity , & ExtractedOutline , & FloodMeshBounds ) > ,
5042 mut flood_phases : ResMut < ViewSortedRenderPhases < FloodOutline > > ,
5143 mut views : Query < (
@@ -78,6 +70,11 @@ pub(crate) fn queue_flood_meshes(
7870
7971 let rangefinder = OutlineRangefinder :: new ( view) ;
8072
73+ let outline_view_cache = outline_cache
74+ . view_map
75+ . get ( & view. retained_view_entity )
76+ . unwrap ( ) ;
77+
8178 for ( entity, main_entity, outline, mesh_bounds) in material_meshes. iter ( ) {
8279 if !outline. volume {
8380 continue ;
@@ -91,10 +88,6 @@ pub(crate) fn queue_flood_meshes(
9188 continue ;
9289 }
9390
94- let Some ( mesh) = render_meshes. get ( outline. mesh_id ) else {
95- continue ;
96- } ;
97-
9891 // Calculate screen-space bounds of outline
9992 let border = ( view_uniform. scale_physical_from_logical
10093 * outline. instance_data . volume_offset )
@@ -107,36 +100,30 @@ pub(crate) fn queue_flood_meshes(
107100
108101 let ( _vertex_slab, index_slab) = mesh_allocator. mesh_slabs ( & outline. mesh_id ) ;
109102
110- let flood_key = PipelineKey :: new ( )
111- . with_primitive_topology ( mesh. primitive_topology ( ) )
112- . with_depth_mode ( DepthMode :: Flat )
113- . with_morph_targets ( mesh. morph_targets . is_some ( ) )
114- . with_vertex_offset_zero ( true )
115- . with_plane_offset_zero ( true )
116- . with_pass_type ( PassType :: FloodInit )
117- . with_double_sided ( outline. double_sided )
118- . with_alpha_mask_texture ( outline. alpha_mask_id . is_some ( ) )
119- . with_alpha_mask_channel ( outline. alpha_mask_channel ) ;
103+ let Some ( OutlineCacheEntry {
104+ changed_tick : _,
105+ stencil_pipeline_id : _,
106+ volume_pipeline_id,
107+ } ) = outline_view_cache. entity_map . get ( main_entity)
108+ else {
109+ continue ;
110+ } ;
120111
121112 queue_status. has_volume = true ;
122113
123- if let Ok ( pipeline) =
124- pipelines. specialize ( & pipeline_cache, & outline_pipeline, flood_key, & mesh. layout )
125- {
126- flood_phase. add ( FloodOutline {
127- distance : rangefinder. distance_of ( outline) ,
128- entity,
129- main_entity : * main_entity,
130- pipeline,
131- draw_function : draw_flood,
132- batch_range : 0 ..0 ,
133- extra_index : PhaseItemExtraIndex :: None ,
134- indexed : index_slab. is_some ( ) ,
135- volume_offset : outline. instance_data . volume_offset ,
136- volume_colour : outline. instance_data . volume_colour ,
137- screen_space_bounds,
138- } ) ;
139- }
114+ flood_phase. add ( FloodOutline {
115+ distance : rangefinder. distance_of ( outline) ,
116+ entity,
117+ main_entity : * main_entity,
118+ pipeline : * volume_pipeline_id,
119+ draw_function : draw_flood,
120+ batch_range : 0 ..0 ,
121+ extra_index : PhaseItemExtraIndex :: None ,
122+ indexed : index_slab. is_some ( ) ,
123+ volume_offset : outline. instance_data . volume_offset ,
124+ volume_colour : outline. instance_data . volume_colour ,
125+ screen_space_bounds,
126+ } ) ;
140127 }
141128 }
142129}
0 commit comments