Skip to content

StandardMaterial doesn't support primitive restart #17794

@Lege19

Description

@Lege19

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(())
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions