bevy
bevy copied to clipboard
Images loaded in RenderApp ignores ImageSettings
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();
}
}
}
}
I'm pretty sure it has to be inserted before DefaultPlugins
Maybe we should clarify it on the docs.
Please make this obvious in the docs. I was about to open an issue ;)
The following works in v0.10 since ImageSettings
no longer exists:
.add_plugins(
DefaultPlugins.set(ImagePlugin::default_nearest())
)