Skip to content

Images loaded in RenderApp ignores ImageSettings #5744

@TanTanDev

Description

@TanTanDev

Bevy version 0.8
There's a texture I want to have FilterMode::Nearest.
I've tried to insert_resource(ImageSettings::default_nearest()) but I believe due to the circumstance when it get's loaded, the ImageSettings seems to be ignored.
the sampler get's set to FilterMode::Linear despite the ImageSetting.

The code:

pub struct ChunkTexture(pub Handle<Image>);

impl FromWorld for ChunkTexture {
    fn from_world(world: &mut World) -> Self {
        let asset_server = world.resource_mut::<AssetServer>();
        ChunkTexture(asset_server.load("textures/block_atlas.png"))
    }
}

loading occurs here:

// no effect
app.insert_resource(ImageSettings::default_nearest())

app.sub_app_mut(RenderApp)
     // no effect
    .insert_resource(ImageSettings::default_nearest())
    .init_resource::<ChunkTexture>()

I'm currently getting around this by hacking together this (added the "core/main" app):
Which has the side effect of forcing all images to be nearest.

fn set_texture_filters_to_nearest(
    mut texture_events: EventReader<AssetEvent<Image>>,
    mut textures: ResMut<Assets<Image>>,
) {
    for event in texture_events.iter() {
        if let AssetEvent::Created { handle } = event {
            if let Some(mut texture) = textures.get_mut(handle) {
                texture.sampler_descriptor = ImageSampler::nearest();
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions