3131use std:: any:: TypeId ;
3232
3333use bevy:: asset:: load_internal_asset;
34+ use bevy:: asset:: AssetEvents ;
3435use bevy:: core_pipeline:: core_3d:: graph:: { Core3d , Node3d } ;
3536use bevy:: pbr:: { MeshInputUniform , MeshUniform } ;
3637use bevy:: prelude:: * ;
3738use bevy:: render:: batching:: gpu_preprocessing:: { self , GpuPreprocessingSupport } ;
3839use bevy:: render:: batching:: no_gpu_preprocessing:: {
3940 clear_batched_cpu_instance_buffers, write_batched_instance_buffer, BatchedInstanceBuffer ,
4041} ;
41- use bevy:: render:: extract_component:: { ExtractComponentPlugin , UniformComponentPlugin } ;
42+ use bevy:: render:: extract_component:: UniformComponentPlugin ;
4243use bevy:: render:: mesh:: MeshVertexAttribute ;
4344use bevy:: render:: render_graph:: { EmptyNode , RenderGraphApp , RenderLabel , ViewNodeRunner } ;
4445use bevy:: render:: render_phase:: {
@@ -47,17 +48,24 @@ use bevy::render::render_phase::{
4748} ;
4849use bevy:: render:: render_resource:: { SpecializedMeshPipelines , VertexFormat } ;
4950use bevy:: render:: renderer:: RenderDevice ;
51+ use bevy:: render:: sync_component:: SyncComponentPlugin ;
5052use bevy:: render:: view:: { RenderLayers , VisibilitySystems } ;
5153use bevy:: render:: { Render , RenderApp , RenderDebugFlags , RenderSet } ;
5254use bevy:: transform:: TransformSystem ;
53- use uniforms:: { prepare_render_outlines, AlphaMaskBindGroups , RenderOutlines } ;
55+ use uniforms:: extract_outlines;
56+ use uniforms:: AlphaMaskBindGroups ;
57+ use uniforms:: RenderOutlineInstances ;
5458
5559use crate :: msaa:: MsaaExtraWritebackNode ;
5660use crate :: node:: { OpaqueOutline , OutlineNode , StencilOutline , TransparentOutline } ;
5761use crate :: pipeline:: {
5862 OutlinePipeline , COMMON_SHADER_HANDLE , FRAGMENT_SHADER_HANDLE , OUTLINE_SHADER_HANDLE ,
5963} ;
60- use crate :: queue:: queue_outline_mesh;
64+ use crate :: queue:: {
65+ check_outline_entities_needing_specialisation, extract_outline_entities_needing_specialisation,
66+ queue_outline_mesh, specialise_outlines, OutlineEntitiesNeedingSpecialisation ,
67+ OutlineEntitySpecialisationTicks , OutlinePipelineCache ,
68+ } ;
6169use crate :: render:: DrawOutline ;
6270use crate :: uniforms:: set_outline_visibility;
6371use crate :: uniforms:: {
@@ -342,7 +350,7 @@ impl Plugin for OutlinePlugin {
342350 ) ;
343351
344352 app. add_plugins ( (
345- ExtractComponentPlugin :: < ComputedOutline > :: default ( ) ,
353+ SyncComponentPlugin :: < ComputedOutline > :: default ( ) ,
346354 UniformComponentPlugin :: < OutlineViewUniform > :: default ( ) ,
347355 BinnedRenderPhasePlugin :: < StencilOutline , OutlinePipeline > :: new (
348356 RenderDebugFlags :: empty ( ) ,
@@ -357,6 +365,11 @@ impl Plugin for OutlinePlugin {
357365 . register_required_components :: < OutlineStencil , ComputedOutline > ( )
358366 . register_required_components :: < OutlineVolume , ComputedOutline > ( )
359367 . register_required_components :: < InheritOutline , ComputedOutline > ( )
368+ . init_resource :: < OutlineEntitiesNeedingSpecialisation > ( )
369+ . add_systems (
370+ PostUpdate ,
371+ check_outline_entities_needing_specialisation. after ( AssetEvents ) ,
372+ )
360373 . add_systems (
361374 PostUpdate ,
362375 (
@@ -374,7 +387,14 @@ impl Plugin for OutlinePlugin {
374387 . add_render_command :: < StencilOutline , DrawOutline > ( )
375388 . add_render_command :: < OpaqueOutline , DrawOutline > ( )
376389 . add_render_command :: < TransparentOutline , DrawOutline > ( )
377- . add_systems ( ExtractSchedule , extract_outline_view_uniforms)
390+ . add_systems (
391+ ExtractSchedule ,
392+ (
393+ extract_outline_view_uniforms,
394+ extract_outlines,
395+ extract_outline_entities_needing_specialisation,
396+ ) ,
397+ )
378398 . add_systems (
379399 Render ,
380400 msaa:: prepare_msaa_extra_writeback_pipelines. in_set ( RenderSet :: Prepare ) ,
@@ -388,10 +408,7 @@ impl Plugin for OutlinePlugin {
388408 )
389409 . in_set ( RenderSet :: PrepareBindGroups ) ,
390410 )
391- . add_systems (
392- Render ,
393- prepare_render_outlines. in_set ( RenderSet :: PrepareMeshes ) ,
394- )
411+ . add_systems ( Render , specialise_outlines. in_set ( RenderSet :: PrepareMeshes ) )
395412 . add_systems ( Render , queue_outline_mesh. in_set ( RenderSet :: QueueMeshes ) )
396413 . add_systems (
397414 Render ,
@@ -442,7 +459,9 @@ impl Plugin for OutlinePlugin {
442459 fn finish ( & self , app : & mut App ) {
443460 let render_app = app. sub_app_mut ( RenderApp ) ;
444461 render_app
445- . init_resource :: < RenderOutlines > ( )
462+ . init_resource :: < RenderOutlineInstances > ( )
463+ . init_resource :: < OutlineEntitySpecialisationTicks > ( )
464+ . init_resource :: < OutlinePipelineCache > ( )
446465 . init_resource :: < OutlinePipeline > ( )
447466 . init_resource :: < AlphaMaskBindGroups > ( ) ;
448467
0 commit comments