Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images loaded in RenderApp ignores ImageSettings #5744

Open
TanTanDev opened this issue Aug 19, 2022 · 3 comments
Open

Images loaded in RenderApp ignores ImageSettings #5744

TanTanDev opened this issue Aug 19, 2022 · 3 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@TanTanDev
Copy link

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();
            }
        }
    }
}
@TanTanDev TanTanDev added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 19, 2022
@afonsolage
Copy link
Contributor

I'm pretty sure it has to be inserted before DefaultPlugins

Maybe we should clarify it on the docs.

@Weibye Weibye added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Aug 19, 2022
@robng
Copy link

robng commented Sep 11, 2022

Please make this obvious in the docs. I was about to open an issue ;)

@tylerkayser
Copy link

The following works in v0.10 since ImageSettings no longer exists:

.add_plugins(
  DefaultPlugins.set(ImagePlugin::default_nearest())
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

5 participants