1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Add support for mipmap textures. (#5146)

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

* [x] I have followed the instructions in the PR template

Adds support for mipmaps in the `glow` backend.

Should be possible to implement for `wgpu` in the future as well, but
requires a custom compute kernel.
This commit is contained in:
Christofer Nolander
2024-09-22 19:16:16 +02:00
committed by GitHub
parent 07ccf41bf9
commit 6f7b9b9b87
2 changed files with 39 additions and 7 deletions

View File

@@ -22,14 +22,18 @@ const VERT_SRC: &str = include_str!("shader/vertex.glsl");
const FRAG_SRC: &str = include_str!("shader/fragment.glsl");
trait TextureFilterExt {
fn glow_code(&self) -> u32;
fn glow_code(&self, mipmap: Option<egui::TextureFilter>) -> u32;
}
impl TextureFilterExt for egui::TextureFilter {
fn glow_code(&self) -> u32 {
match self {
Self::Linear => glow::LINEAR,
Self::Nearest => glow::NEAREST,
fn glow_code(&self, mipmap: Option<egui::TextureFilter>) -> u32 {
match (self, mipmap) {
(Self::Linear, None) => glow::LINEAR,
(Self::Nearest, None) => glow::NEAREST,
(Self::Linear, Some(Self::Linear)) => glow::LINEAR_MIPMAP_LINEAR,
(Self::Nearest, Some(Self::Linear)) => glow::NEAREST_MIPMAP_LINEAR,
(Self::Linear, Some(Self::Nearest)) => glow::LINEAR_MIPMAP_NEAREST,
(Self::Nearest, Some(Self::Nearest)) => glow::NEAREST_MIPMAP_NEAREST,
}
}
}
@@ -569,12 +573,12 @@ impl Painter {
self.gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MAG_FILTER,
options.magnification.glow_code() as i32,
options.magnification.glow_code(None) as i32,
);
self.gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MIN_FILTER,
options.minification.glow_code() as i32,
options.minification.glow_code(options.mipmap_mode) as i32,
);
self.gl.tex_parameter_i32(
@@ -635,6 +639,11 @@ impl Painter {
);
check_for_gl_error!(&self.gl, "tex_image_2d");
}
if options.mipmap_mode.is_some() {
self.gl.generate_mipmap(glow::TEXTURE_2D);
check_for_gl_error!(&self.gl, "generate_mipmap");
}
}
}