not-fl3/egui-miniquad

Does TextureOptions::NEAREST work?

yds12 opened this issue · 3 comments

yds12 commented

I'm trying to use the NEAREST filter for enlarged images, which I show in an ImageButton. The code I use to load the texture is the following:

ui.ctx().load_texture("tex", image, egui::TextureOptions::NEAREST)

I would expect this to give the "pixelized" effect, but it looks like it's using the LINEAR filter instead (blurry).

Could it be this line? It seems that Linear is always used:

filter: miniquad::FilterMode::Linear,

I checked the loaded texture options, and at least according to TextureManager, it seems to be set correctly:

let meta = ui.ctx().tex_manager().read().meta(tex.id()).unwrap().options;
dbg!(meta);

// output:
// meta = TextureOptions {
//     magnification: Nearest,
//     minification: Nearest,
// }

I'm not sure also if this is the correct place to report this, or if I should open the issue in egui. I use egui-miniquad as backend (with egui-macroquad on top of it, but that's only a few lines of code).

I'm having the same issue, thanks to you I was able to fix it by editing painter.rs and setting filter based on what delta.options.magnification is set to, so you can effectively specify either TextureOptions::NEAREST or TextureOptions::LINEAR, but you wouldn't be able to set different behaviour for minification:

let filter = match delta.options.magnification {
    TextureFilter::Nearest => FilterMode::Nearest,
    TextureFilter::Linear => FilterMode::Linear,
};

I don't know enough about this to say for sure, but it looks like the problem lies with egui providing a texture with separate options for magnification and minification, whereas there's no such distinction with miniquad's FilterMode.

yds12 commented

Hi @Karta775, thanks for the info. I'll try to do it locally for now. Would you consider maybe opening a PR with it? I'd be very interested in it.

Edit: ah I see your point, because they are different it's not obvious to decide which value to assign. For now it's always Linear, I'd say at least in the case where both values are set to Nearest, it would make sense to set it to that value, and if they are different then any default value (here Linear) would be fine.

yds12 commented

Thanks for the PR! I made the change locally here as well and it works.