Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 21 additions & 49 deletions crates/bevy_gizmos_render/src/pipeline_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Plugin for LineGizmo2dPlugin {
)
.add_systems(
Render,
(queue_line_gizmos_2d, queue_line_joint_gizmos_2d)
queue_line_and_joint_gizmos_2d
.in_set(GizmoRenderSystems::QueueLineGizmos2d)
.after(prepare_assets::<GpuLineGizmo>),
);
Expand Down Expand Up @@ -287,21 +287,27 @@ type DrawLineJointGizmo2d = (
DrawLineJointGizmo,
);

fn queue_line_gizmos_2d(
fn queue_line_and_joint_gizmos_2d(
draw_functions: Res<DrawFunctions<Transparent2d>>,
pipeline: Res<LineGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<LineGizmoPipeline>>,
line_gizmo_pipeline: Res<LineGizmoPipeline>,
line_joint_gizmo_pipeline: Res<LineJointGizmoPipeline>,
mut line_gizmo_pipelines: ResMut<SpecializedRenderPipelines<LineGizmoPipeline>>,
mut line_joint_gizmo_pipelines: ResMut<SpecializedRenderPipelines<LineJointGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
line_gizmos: Query<(Entity, &MainEntity, &GizmoMeshConfig)>,
line_gizmo_assets: Res<RenderAssets<GpuLineGizmo>>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent2d>>,
mut views: Query<(&ExtractedView, &Msaa, Option<&RenderLayers>)>,
) {
let draw_function = draw_functions.read().get_id::<DrawLineGizmo2d>().unwrap();
let draw_function_strip = draw_functions
let draw_line_function_strip = draw_functions
.read()
.get_id::<DrawLineGizmo2dStrip>()
.unwrap();
let draw_line_joint_function = draw_functions
.read()
.get_id::<DrawLineJointGizmo2d>()
.unwrap();

for (view, msaa, render_layers) in &mut views {
let Some(transparent_phase) = transparent_render_phases.get_mut(&view.retained_view_entity)
Expand All @@ -322,10 +328,11 @@ fn queue_line_gizmos_2d(
continue;
};

// Draw lines
if line_gizmo.list_vertex_count > 0 {
let pipeline = pipelines.specialize(
let pipeline = line_gizmo_pipelines.specialize(
&pipeline_cache,
&pipeline,
&line_gizmo_pipeline,
LineGizmoPipelineKey {
mesh_key,
strip: false,
Expand All @@ -345,9 +352,9 @@ fn queue_line_gizmos_2d(
}

if line_gizmo.strip_vertex_count >= 2 {
let pipeline = pipelines.specialize(
let pipeline = line_gizmo_pipelines.specialize(
&pipeline_cache,
&pipeline,
&line_gizmo_pipeline,
LineGizmoPipelineKey {
mesh_key,
strip: true,
Expand All @@ -356,7 +363,7 @@ fn queue_line_gizmos_2d(
);
transparent_phase.add(Transparent2d {
entity: (entity, *main_entity),
draw_function: draw_function_strip,
draw_function: draw_line_function_strip,
pipeline,
sort_key: FloatOrd(f32::INFINITY),
batch_range: 0..1,
Expand All @@ -365,58 +372,23 @@ fn queue_line_gizmos_2d(
indexed: false,
});
}
}
}
}
fn queue_line_joint_gizmos_2d(
draw_functions: Res<DrawFunctions<Transparent2d>>,
pipeline: Res<LineJointGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<LineJointGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
line_gizmos: Query<(Entity, &MainEntity, &GizmoMeshConfig)>,
line_gizmo_assets: Res<RenderAssets<GpuLineGizmo>>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent2d>>,
mut views: Query<(&ExtractedView, &Msaa, Option<&RenderLayers>)>,
) {
let draw_function = draw_functions
.read()
.get_id::<DrawLineJointGizmo2d>()
.unwrap();

for (view, msaa, render_layers) in &mut views {
let Some(transparent_phase) = transparent_render_phases.get_mut(&view.retained_view_entity)
else {
continue;
};

let mesh_key = Mesh2dPipelineKey::from_msaa_samples(msaa.samples())
| Mesh2dPipelineKey::from_hdr(view.hdr);

let render_layers = render_layers.unwrap_or_default();
for (entity, main_entity, config) in &line_gizmos {
if !config.render_layers.intersects(render_layers) {
continue;
}

let Some(line_gizmo) = line_gizmo_assets.get(&config.handle) else {
continue;
};

// Draw line joints
if line_gizmo.strip_vertex_count < 3 || config.line_joints == GizmoLineJoint::None {
continue;
}

let pipeline = pipelines.specialize(
let pipeline = line_joint_gizmo_pipelines.specialize(
&pipeline_cache,
&pipeline,
&line_joint_gizmo_pipeline,
LineJointGizmoPipelineKey {
mesh_key,
joints: config.line_joints,
},
);
transparent_phase.add(Transparent2d {
entity: (entity, *main_entity),
draw_function,
draw_function: draw_line_joint_function,
pipeline,
sort_key: FloatOrd(f32::INFINITY),
batch_range: 0..1,
Expand Down