Skip to content

Commit ee04648

Browse files
committed
Revert "extract node 2d to core_pipeline"
This reverts commit 1230d2b.
1 parent 2512479 commit ee04648

File tree

6 files changed

+87
-123
lines changed

6 files changed

+87
-123
lines changed

crates/bevy_core_pipeline/src/core_2d/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub mod graph {
1111
pub const BLOOM: &str = "bloom";
1212
pub const TONEMAPPING: &str = "tonemapping";
1313
pub const FXAA: &str = "fxaa";
14-
pub const GIZMO: &str = "gizmo";
1514
pub const UPSCALING: &str = "upscaling";
1615
pub const END_MAIN_PASS_POST_PROCESSING: &str = "end_main_pass_post_processing";
1716
}

crates/bevy_core_pipeline/src/gizmo_2d/mod.rs

Lines changed: 0 additions & 104 deletions
This file was deleted.

crates/bevy_core_pipeline/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod core_2d;
44
pub mod core_3d;
55
pub mod fullscreen_vertex_shader;
66
pub mod fxaa;
7-
pub mod gizmo_2d;
87
pub mod prepass;
98
pub mod tonemapping;
109
pub mod upscaling;

crates/bevy_gizmos/src/lib.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use std::mem;
22

33
use bevy_app::{CoreSet, IntoSystemAppConfig, Plugin};
44
use bevy_asset::{load_internal_asset, Assets, Handle, HandleUntyped};
5-
use bevy_core_pipeline::{
6-
core_3d,
7-
gizmo_2d::{Gizmo2dPlugin, GizmoLine2d},
8-
};
5+
use bevy_core_pipeline::{core_2d, core_3d};
96
use bevy_ecs::{
107
prelude::{Component, DetectChanges},
118
schedule::IntoSystemConfig,
@@ -29,14 +26,15 @@ use bevy_sprite::{Mesh2dHandle, Mesh2dUniform};
2926

3027
pub mod gizmos;
3128

29+
mod node_2d;
3230
mod node_3d;
3331

3432
#[cfg(feature = "bevy_sprite")]
3533
mod pipeline_2d;
3634
#[cfg(feature = "bevy_pbr")]
3735
mod pipeline_3d;
3836

39-
use crate::{gizmos::GizmoStorage, node_3d::GizmoNode3d};
37+
use crate::{gizmos::GizmoStorage, node_2d::GizmoNode2d, node_3d::GizmoNode3d};
4038

4139
/// The `bevy_gizmos` prelude.
4240
pub mod prelude {
@@ -58,9 +56,6 @@ impl Plugin for GizmoPlugin {
5856
.init_resource::<GizmoStorage>()
5957
.add_system(update_gizmo_meshes.in_base_set(CoreSet::Last));
6058

61-
#[cfg(feature = "bevy_sprite")]
62-
app.add_plugin(Gizmo2dPlugin);
63-
6459
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return; };
6560

6661
render_app.add_system(extract_gizmo_data.in_schedule(ExtractSchedule));
@@ -72,8 +67,28 @@ impl Plugin for GizmoPlugin {
7267
render_app
7368
.init_resource::<GizmoPipeline2d>()
7469
.init_resource::<SpecializedMeshPipelines<GizmoPipeline2d>>()
70+
.init_resource::<DrawFunctions<GizmoLine2d>>()
7571
.add_render_command::<GizmoLine2d, DrawGizmoLines>()
72+
.add_system(sort_phase_system::<GizmoLine2d>)
73+
.add_system_to_schedule(ExtractSchedule, extract_gizmo_line_2d_camera_phase)
7674
.add_system(queue_gizmos_2d.in_set(RenderSet::Queue));
75+
76+
let gizmo_node = GizmoNode2d::new(&mut render_app.world);
77+
let mut binding = render_app.world.resource_mut::<RenderGraph>();
78+
let graph = binding.get_sub_graph_mut(core_2d::graph::NAME).unwrap();
79+
80+
graph.add_node(GizmoNode2d::NAME, gizmo_node);
81+
graph.add_slot_edge(
82+
graph.input_node().id,
83+
core_2d::graph::input::VIEW_ENTITY,
84+
GizmoNode2d::NAME,
85+
GizmoNode2d::IN_VIEW,
86+
);
87+
graph.add_node_edge(
88+
core_2d::graph::node::END_MAIN_PASS_POST_PROCESSING,
89+
GizmoNode2d::NAME,
90+
);
91+
graph.add_node_edge(GizmoNode2d::NAME, core_2d::graph::node::UPSCALING);
7792
}
7893

7994
#[cfg(feature = "bevy_pbr")]

crates/bevy_core_pipeline/src/gizmo_2d/node.rs renamed to crates/bevy_gizmos/src/node_2d.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ use bevy_render::{
66
renderer::RenderContext,
77
view::{ExtractedView, ViewTarget},
88
};
9-
#[cfg(feature = "trace")]
10-
use bevy_utils::tracing::info_span;
119

12-
use super::GizmoLine2d;
10+
use crate::pipeline_2d::GizmoLine2d;
1311

14-
pub struct Gizmo2dNode {
12+
pub struct GizmoNode2d {
1513
view_query:
1614
QueryState<(&'static ViewTarget, &'static RenderPhase<GizmoLine2d>), With<ExtractedView>>,
1715
}
1816

19-
impl Gizmo2dNode {
17+
impl GizmoNode2d {
2018
pub const IN_VIEW: &'static str = "view";
19+
pub const NAME: &'static str = "gizmo_node_2d";
2120

2221
pub fn new(world: &mut World) -> Self {
2322
Self {
@@ -26,7 +25,7 @@ impl Gizmo2dNode {
2625
}
2726
}
2827

29-
impl Node for Gizmo2dNode {
28+
impl Node for GizmoNode2d {
3029
fn input(&self) -> Vec<SlotInfo> {
3130
vec![SlotInfo::new(Self::IN_VIEW, SlotType::Entity)]
3231
}

crates/bevy_gizmos/src/pipeline_2d.rs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
use bevy_asset::Handle;
2-
use bevy_core_pipeline::gizmo_2d::GizmoLine2d;
2+
use bevy_core_pipeline::prelude::Camera2d;
33
use bevy_ecs::{
44
prelude::Entity,
55
query::With,
6-
system::{Query, Res, ResMut, Resource},
6+
system::{Commands, Query, Res, ResMut, Resource},
77
world::{FromWorld, World},
88
};
99
use bevy_render::{
1010
mesh::{Mesh, MeshVertexBufferLayout},
11+
prelude::Camera,
1112
render_asset::RenderAssets,
12-
render_phase::{DrawFunctions, RenderPhase, SetItemPipeline},
13+
render_phase::{
14+
CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, PhaseItem, RenderPhase,
15+
SetItemPipeline,
16+
},
1317
render_resource::*,
1418
texture::BevyDefault,
1519
view::Msaa,
20+
Extract,
1621
};
1722
use bevy_sprite::*;
1823
use bevy_utils::FloatOrd;
@@ -88,6 +93,57 @@ pub(crate) type DrawGizmoLines = (
8893
DrawMesh2d,
8994
);
9095

96+
pub struct GizmoLine2d {
97+
pub sort_key: FloatOrd,
98+
pub pipeline: CachedRenderPipelineId,
99+
pub entity: Entity,
100+
pub draw_function: DrawFunctionId,
101+
}
102+
103+
impl PhaseItem for GizmoLine2d {
104+
type SortKey = FloatOrd;
105+
106+
#[inline]
107+
fn entity(&self) -> Entity {
108+
self.entity
109+
}
110+
111+
#[inline]
112+
fn sort_key(&self) -> Self::SortKey {
113+
self.sort_key
114+
}
115+
116+
#[inline]
117+
fn draw_function(&self) -> DrawFunctionId {
118+
self.draw_function
119+
}
120+
121+
#[inline]
122+
fn sort(items: &mut [Self]) {
123+
items.sort_by_key(|item| item.sort_key());
124+
}
125+
}
126+
127+
impl CachedRenderPipelinePhaseItem for GizmoLine2d {
128+
#[inline]
129+
fn cached_pipeline(&self) -> CachedRenderPipelineId {
130+
self.pipeline
131+
}
132+
}
133+
134+
pub fn extract_gizmo_line_2d_camera_phase(
135+
mut commands: Commands,
136+
cameras_2d: Extract<Query<(Entity, &Camera), With<Camera2d>>>,
137+
) {
138+
for (entity, camera) in &cameras_2d {
139+
if camera.is_active {
140+
commands
141+
.get_or_spawn(entity)
142+
.insert(RenderPhase::<GizmoLine2d>::default());
143+
}
144+
}
145+
}
146+
91147
#[allow(clippy::too_many_arguments)]
92148
pub(crate) fn queue_gizmos_2d(
93149
draw_functions: Res<DrawFunctions<GizmoLine2d>>,

0 commit comments

Comments
 (0)