Skip to content

Commit 908c40d

Browse files
committed
Implement Clone for all pipeline types (#6653)
# Objective Pipelines can be customized by wrapping an existing pipeline in a newtype and adding custom logic to its implementation of `SpecializedMeshPipeline::specialize`. To make that easier, the wrapped pipeline type needs to implement `Clone`. For example, the current non-cloneable pipelines require wrapper pipelines to pull apart the wrapped pipeline like this: ```rust impl FromWorld for Wireframe2dPipeline { fn from_world(world: &mut World) -> Self { let p = &world.resource::<Material2dPipeline<ColorMaterial>>(); Self { mesh2d_pipeline: p.mesh2d_pipeline.clone(), material2d_layout: p.material2d_layout.clone(), vertex_shader: p.vertex_shader.clone(), fragment_shader: p.fragment_shader.clone(), } } } ``` ## Solution Derive or implement `Clone` on all built-in pipeline types. This is easy to do since they mostly just contain cheaply clonable reference-counted types. --- ## Changelog Implement `Clone` for all pipeline types.
1 parent d9265db commit 908c40d

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

crates/bevy_pbr/src/material.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ pub struct MaterialPipeline<M: Material> {
232232
marker: PhantomData<M>,
233233
}
234234

235+
impl<M: Material> Clone for MaterialPipeline<M> {
236+
fn clone(&self) -> Self {
237+
Self {
238+
mesh_pipeline: self.mesh_pipeline.clone(),
239+
material_layout: self.material_layout.clone(),
240+
vertex_shader: self.vertex_shader.clone(),
241+
fragment_shader: self.fragment_shader.clone(),
242+
marker: PhantomData,
243+
}
244+
}
245+
}
246+
235247
impl<M: Material> SpecializedMeshPipeline for MaterialPipeline<M>
236248
where
237249
M::Data: PartialEq + Eq + Hash + Clone,

crates/bevy_pbr/src/render/light.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub const MAX_UNIFORM_BUFFER_POINT_LIGHTS: usize = 256;
213213
pub const MAX_DIRECTIONAL_LIGHTS: usize = 10;
214214
pub const SHADOW_FORMAT: TextureFormat = TextureFormat::Depth32Float;
215215

216-
#[derive(Resource)]
216+
#[derive(Resource, Clone)]
217217
pub struct ShadowPipeline {
218218
pub view_layout: BindGroupLayout,
219219
pub mesh_layout: BindGroupLayout,

crates/bevy_pbr/src/wireframe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct WireframeConfig {
7070
pub global: bool,
7171
}
7272

73-
#[derive(Resource)]
73+
#[derive(Resource, Clone)]
7474
pub struct WireframePipeline {
7575
mesh_pipeline: MeshPipeline,
7676
shader: Handle<Shader>,

crates/bevy_sprite/src/mesh2d/material.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ where
218218
}
219219
}
220220

221+
impl<M: Material2d> Clone for Material2dPipeline<M> {
222+
fn clone(&self) -> Self {
223+
Self {
224+
mesh2d_pipeline: self.mesh2d_pipeline.clone(),
225+
material2d_layout: self.material2d_layout.clone(),
226+
vertex_shader: self.vertex_shader.clone(),
227+
fragment_shader: self.fragment_shader.clone(),
228+
marker: PhantomData,
229+
}
230+
}
231+
}
232+
221233
impl<M: Material2d> SpecializedMeshPipeline for Material2dPipeline<M>
222234
where
223235
M::Data: PartialEq + Eq + Hash + Clone,

0 commit comments

Comments
 (0)