-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
StandardMaterial doesn't support primitive restart #17794
Description
What problem does this solve or what need does it fill?
Triangle strip meshes require PrimitiveState::strip_index_format to be set for primitive restart to work. The current implementation of StandardMaterialdoesn't do this.
What solution would you like?
Add an extra field to StandardMaterial of type Option<IndexFormat> the value of which will be assigned to RenderPipelineDescriptor.primitive.strip_index_format in Material::specialize
OR
Add an extra field to StandardMaterial of type PrimitiveState (and remove redundancies this creates) the value of which will be assigned to RenderPipelineDescriptor.primitive in Material::specialize
OR
Just unconditionally set RenderPipelineDescriptor.primitive.strip_index_format = Some(IndexFormat::Uint32) in Material::specialize, this is less flexible but literally 1 line of code.
What alternative(s) have you considered?
This can already be achieved with a MaterialExtension:
#[derive(Copy, Clone, Hash, Eq, PartialEq)]
pub struct OverridePrimitiveKey(PrimitiveState);
impl From<&OverridePrimitive> for OverridePrimitiveKey {
fn from(value: &OverridePrimitive) -> Self {
Self(value.primitive)
}
}
#[derive(Clone, Asset, TypePath, AsBindGroup)]
#[bind_group_data(OverridePrimitiveKey)]
pub struct OverridePrimitive {
pub primitive: PrimitiveState,
}
impl MaterialExtension for OverridePrimitive {
fn specialize(
_pipeline: &MaterialExtensionPipeline,
descriptor: &mut RenderPipelineDescriptor,
_layout: &MeshVertexBufferLayoutRef,
key: MaterialExtensionKey<Self>,
) -> Result<(), SpecializedMeshPipelineError> {
descriptor.primitive = key.bind_group_data.0;
Ok(())
}
}