use embedded_graphics_core::pixelcolor::Rgb565;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum TextureMapping {
PerspectiveCorrect,
Affine,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TextureLodConfig {
pub near_distance: f32,
pub far_distance: f32,
pub fallback_color: Rgb565,
}
impl TextureLodConfig {
#[must_use]
pub const fn new(near_distance: f32, far_distance: f32, fallback_color: Rgb565) -> Self {
Self {
near_distance,
far_distance,
fallback_color,
}
}
#[must_use]
#[inline]
pub fn should_drop_texture(&self, z: f32) -> bool {
z >= self.far_distance
}
#[must_use]
#[inline]
pub fn is_in_transition(&self, z: f32) -> bool {
z >= self.near_distance && z < self.far_distance
}
#[must_use]
#[inline]
pub fn flat_blend_factor(&self, z: f32) -> f32 {
if z <= self.near_distance {
0.0
} else if z >= self.far_distance {
1.0
} else {
(z - self.near_distance) / (self.far_distance - self.near_distance)
}
}
}