diff --git a/src/io/gltf.rs b/src/io/gltf.rs index a9700c4..e5286b5 100644 --- a/src/io/gltf.rs +++ b/src/io/gltf.rs @@ -390,22 +390,38 @@ fn parse_texture<'a>( Some(::gltf::texture::MagFilter::Linear) => Interpolation::Linear, None => tex.mag_filter, }; - (tex.min_filter, tex.mip_map_filter) = match sampler.min_filter() { + (tex.min_filter, tex.mipmap) = match sampler.min_filter() { Some(::gltf::texture::MinFilter::Nearest) => (Interpolation::Nearest, None), Some(::gltf::texture::MinFilter::Linear) => (Interpolation::Linear, None), - Some(::gltf::texture::MinFilter::NearestMipmapNearest) => { - (Interpolation::Nearest, Some(Interpolation::Nearest)) - } - Some(::gltf::texture::MinFilter::LinearMipmapNearest) => { - (Interpolation::Linear, Some(Interpolation::Nearest)) - } - Some(::gltf::texture::MinFilter::NearestMipmapLinear) => { - (Interpolation::Nearest, Some(Interpolation::Linear)) - } - Some(::gltf::texture::MinFilter::LinearMipmapLinear) => { - (Interpolation::Linear, Some(Interpolation::Linear)) - } - None => (tex.min_filter, tex.mip_map_filter), + Some(::gltf::texture::MinFilter::NearestMipmapNearest) => ( + Interpolation::Nearest, + Some(Mipmap { + filter: Interpolation::Nearest, + ..Default::default() + }), + ), + Some(::gltf::texture::MinFilter::LinearMipmapNearest) => ( + Interpolation::Linear, + Some(Mipmap { + filter: Interpolation::Nearest, + ..Default::default() + }), + ), + Some(::gltf::texture::MinFilter::NearestMipmapLinear) => ( + Interpolation::Nearest, + Some(Mipmap { + filter: Interpolation::Linear, + ..Default::default() + }), + ), + Some(::gltf::texture::MinFilter::LinearMipmapLinear) => ( + Interpolation::Linear, + Some(Mipmap { + filter: Interpolation::Linear, + ..Default::default() + }), + ), + None => (tex.min_filter, tex.mipmap), }; tex.wrap_s = sampler.wrap_s().into(); tex.wrap_t = sampler.wrap_t().into(); diff --git a/src/texture.rs b/src/texture.rs index 73b58cc..a1a49af 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -29,6 +29,30 @@ impl Default for Interpolation { } } +/// Mipmap settings for a texture. +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct Mipmap { + /// Specifies what type of interpolation to use between the two closest mipmaps. + pub filter: Interpolation, + /// Specifies the maximum number of mipmap levels that should be created for the texture. + /// If this is 1, no mip maps will be created. + pub max_levels: u32, + /// Specifies the maximum ratio of anisotropy to be used when creating mipmaps for the texture. + /// If this is 1, only isotropic mipmaps will be created. + pub max_ratio: u32, +} + +impl Default for Mipmap { + fn default() -> Self { + Self { + filter: Interpolation::Linear, + max_levels: u32::MAX, + max_ratio: 1, + } + } +} + /// /// Possible wrapping modes for a texture which determines how the texture is applied outside of the /// [0..1] uv coordinate range. diff --git a/src/texture/texture2d.rs b/src/texture/texture2d.rs index ee73352..9c5590e 100644 --- a/src/texture/texture2d.rs +++ b/src/texture/texture2d.rs @@ -1,5 +1,5 @@ #[doc(inline)] -pub use crate::texture::{Interpolation, TextureData, Wrapping}; +pub use super::{Interpolation, Mipmap, TextureData, Wrapping}; /// /// A CPU-side version of a 2D texture. @@ -19,8 +19,8 @@ pub struct Texture2D { pub min_filter: Interpolation, /// The way the pixel data is interpolated when the texture is close pub mag_filter: Interpolation, - /// Specifies whether mipmaps should be created for this texture and what type of interpolation to use between the two closest mipmaps. - pub mip_map_filter: Option, + /// Specifies the [Mipmap] settings for this texture. If this is `None`, no mipmaps are created. + pub mipmap: Option, /// Determines how the texture is sampled outside the [0..1] s coordinate range (the first value of the uv coordinates). pub wrap_s: Wrapping, /// Determines how the texture is sampled outside the [0..1] t coordinate range (the second value of the uv coordinates). @@ -36,7 +36,7 @@ impl Default for Texture2D { height: 1, min_filter: Interpolation::Linear, mag_filter: Interpolation::Linear, - mip_map_filter: Some(Interpolation::Linear), + mipmap: Some(Mipmap::default()), wrap_s: Wrapping::Repeat, wrap_t: Wrapping::Repeat, } diff --git a/src/texture/texture3d.rs b/src/texture/texture3d.rs index 853df2a..9b61057 100644 --- a/src/texture/texture3d.rs +++ b/src/texture/texture3d.rs @@ -1,5 +1,5 @@ #[doc(inline)] -pub use crate::texture::{Interpolation, TextureData, Wrapping}; +pub use super::{Interpolation, Mipmap, TextureData, Wrapping}; /// /// A CPU-side version of a 3D texture. @@ -21,8 +21,8 @@ pub struct Texture3D { pub min_filter: Interpolation, /// The way the pixel data is interpolated when the texture is close pub mag_filter: Interpolation, - /// Specifies whether mipmaps should be created for this texture and what type of interpolation to use between the two closest mipmaps. - pub mip_map_filter: Option, + /// Specifies the [Mipmap] settings for this texture. If this is `None`, no mipmaps are created. + pub mipmap: Option, /// Determines how the texture is sampled outside the [0..1] s coordinate range (the first value of the uvw coordinates). pub wrap_s: Wrapping, /// Determines how the texture is sampled outside the [0..1] t coordinate range (the second value of the uvw coordinates). @@ -41,7 +41,7 @@ impl Default for Texture3D { depth: 1, min_filter: Interpolation::Linear, mag_filter: Interpolation::Linear, - mip_map_filter: Some(Interpolation::Linear), + mipmap: None, wrap_s: Wrapping::Repeat, wrap_t: Wrapping::Repeat, wrap_r: Wrapping::Repeat,