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.
This commit is contained in:
parent
d9265db344
commit
908c40dd88
@ -232,6 +232,18 @@ pub struct MaterialPipeline<M: Material> {
|
||||
marker: PhantomData<M>,
|
||||
}
|
||||
|
||||
impl<M: Material> Clone for MaterialPipeline<M> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
mesh_pipeline: self.mesh_pipeline.clone(),
|
||||
material_layout: self.material_layout.clone(),
|
||||
vertex_shader: self.vertex_shader.clone(),
|
||||
fragment_shader: self.fragment_shader.clone(),
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Material> SpecializedMeshPipeline for MaterialPipeline<M>
|
||||
where
|
||||
M::Data: PartialEq + Eq + Hash + Clone,
|
||||
|
@ -213,7 +213,7 @@ pub const MAX_UNIFORM_BUFFER_POINT_LIGHTS: usize = 256;
|
||||
pub const MAX_DIRECTIONAL_LIGHTS: usize = 10;
|
||||
pub const SHADOW_FORMAT: TextureFormat = TextureFormat::Depth32Float;
|
||||
|
||||
#[derive(Resource)]
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct ShadowPipeline {
|
||||
pub view_layout: BindGroupLayout,
|
||||
pub mesh_layout: BindGroupLayout,
|
||||
|
@ -70,7 +70,7 @@ pub struct WireframeConfig {
|
||||
pub global: bool,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct WireframePipeline {
|
||||
mesh_pipeline: MeshPipeline,
|
||||
shader: Handle<Shader>,
|
||||
|
@ -218,6 +218,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Material2d> Clone for Material2dPipeline<M> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
mesh2d_pipeline: self.mesh2d_pipeline.clone(),
|
||||
material2d_layout: self.material2d_layout.clone(),
|
||||
vertex_shader: self.vertex_shader.clone(),
|
||||
fragment_shader: self.fragment_shader.clone(),
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Material2d> SpecializedMeshPipeline for Material2dPipeline<M>
|
||||
where
|
||||
M::Data: PartialEq + Eq + Hash + Clone,
|
||||
|
Loading…
Reference in New Issue
Block a user