Skip to main content

bevy_material/
specialize.rs

1use bevy_ecs::world::World;
2use bevy_mesh::{MeshVertexBufferLayoutRef, MissingVertexAttributeError};
3use bevy_platform::sync::Arc;
4use core::any::Any;
5use thiserror::Error;
6
7use crate::{
8    descriptor::{CachedRenderPipelineId, RenderPipelineDescriptor},
9    key::ErasedMaterialPipelineKey,
10    MaterialProperties,
11};
12
13/// A type erased function pointer for specializing a material pipeline. The implementation is
14/// expected to:
15/// - Look up the appropriate specializer from the world
16/// - Downcast the erased key to the concrete key type
17/// - Call `SpecializedMeshPipelines::specialize` with the specializer and return the resulting pipeline id
18pub type BaseSpecializeFn = fn(
19    &mut World,
20    ErasedMaterialPipelineKey,
21    &MeshVertexBufferLayoutRef,
22    &Arc<MaterialProperties>,
23) -> Result<CachedRenderPipelineId, SpecializedMeshPipelineError>;
24
25/// A type erased function pointer for specializing a material prepass pipeline. The implementation is
26/// expected to:
27/// - Look up the appropriate specializer from the world
28/// - Downcast the erased key to the concrete key type
29/// - Call `SpecializedMeshPipelines::specialize` with the specializer and return the resulting pipeline id
30pub type PrepassSpecializeFn = fn(
31    &mut World,
32    ErasedMaterialPipelineKey,
33    &MeshVertexBufferLayoutRef,
34    &Arc<MaterialProperties>,
35) -> Result<CachedRenderPipelineId, SpecializedMeshPipelineError>;
36
37/// A type erased function pointer for specializing a material prepass pipeline. The implementation is
38/// expected to:
39/// - Look up the appropriate specializer from the world
40/// - Downcast the erased key to the concrete key type
41/// - Call `SpecializedMeshPipelines::specialize` with the specializer and return the resulting pipeline id
42pub type UserSpecializeFn = fn(
43    &dyn Any,
44    &mut RenderPipelineDescriptor,
45    &MeshVertexBufferLayoutRef,
46    ErasedMaterialPipelineKey,
47) -> Result<(), SpecializedMeshPipelineError>;
48
49#[derive(Error, Debug)]
50pub enum SpecializedMeshPipelineError {
51    #[error(transparent)]
52    MissingVertexAttribute(#[from] MissingVertexAttributeError),
53}