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:
committed by
GitHub
parent
07ccf41bf9
commit
6f7b9b9b87
@@ -159,6 +159,16 @@ pub struct TextureOptions {
|
||||
|
||||
/// How to wrap the texture when the texture coordinates are outside the [0, 1] range.
|
||||
pub wrap_mode: TextureWrapMode,
|
||||
|
||||
/// How to filter between texture mipmaps.
|
||||
///
|
||||
/// Mipmaps ensures textures look smooth even when the texture is very small and pixels are much
|
||||
/// larger than individual texels.
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// - This may not be available on all backends (currently only `egui_glow`).
|
||||
pub mipmap_mode: Option<TextureFilter>,
|
||||
}
|
||||
|
||||
impl TextureOptions {
|
||||
@@ -167,6 +177,7 @@ impl TextureOptions {
|
||||
magnification: TextureFilter::Linear,
|
||||
minification: TextureFilter::Linear,
|
||||
wrap_mode: TextureWrapMode::ClampToEdge,
|
||||
mipmap_mode: None,
|
||||
};
|
||||
|
||||
/// Nearest magnification and minification.
|
||||
@@ -174,6 +185,7 @@ impl TextureOptions {
|
||||
magnification: TextureFilter::Nearest,
|
||||
minification: TextureFilter::Nearest,
|
||||
wrap_mode: TextureWrapMode::ClampToEdge,
|
||||
mipmap_mode: None,
|
||||
};
|
||||
|
||||
/// Linear magnification and minification, but with the texture repeated.
|
||||
@@ -181,6 +193,7 @@ impl TextureOptions {
|
||||
magnification: TextureFilter::Linear,
|
||||
minification: TextureFilter::Linear,
|
||||
wrap_mode: TextureWrapMode::Repeat,
|
||||
mipmap_mode: None,
|
||||
};
|
||||
|
||||
/// Linear magnification and minification, but with the texture mirrored and repeated.
|
||||
@@ -188,6 +201,7 @@ impl TextureOptions {
|
||||
magnification: TextureFilter::Linear,
|
||||
minification: TextureFilter::Linear,
|
||||
wrap_mode: TextureWrapMode::MirroredRepeat,
|
||||
mipmap_mode: None,
|
||||
};
|
||||
|
||||
/// Nearest magnification and minification, but with the texture repeated.
|
||||
@@ -195,6 +209,7 @@ impl TextureOptions {
|
||||
magnification: TextureFilter::Nearest,
|
||||
minification: TextureFilter::Nearest,
|
||||
wrap_mode: TextureWrapMode::Repeat,
|
||||
mipmap_mode: None,
|
||||
};
|
||||
|
||||
/// Nearest magnification and minification, but with the texture mirrored and repeated.
|
||||
@@ -202,7 +217,15 @@ impl TextureOptions {
|
||||
magnification: TextureFilter::Nearest,
|
||||
minification: TextureFilter::Nearest,
|
||||
wrap_mode: TextureWrapMode::MirroredRepeat,
|
||||
mipmap_mode: None,
|
||||
};
|
||||
|
||||
pub const fn with_mipmap_mode(self, mipmap_mode: Option<TextureFilter>) -> Self {
|
||||
Self {
|
||||
mipmap_mode,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TextureOptions {
|
||||
|
||||
Reference in New Issue
Block a user