use std::fmt;
use crate::model::loader::ParsedTexture;
use image::DynamicImage;
#[derive(Clone)]
pub struct Texture {
pub name: Option<String>,
pub image: DynamicImage,
pub transparent: bool,
pub wrap_mode_u: WrapMode,
pub wrap_mode_v: WrapMode,
}
impl Into<ParsedTexture> for Texture {
fn into(self) -> ParsedTexture {
let image = self.image.to_rgba();
let width = image.width();
let height = image.height();
let rgba_data = image.into_raw();
ParsedTexture {
width,
height,
rgba_data,
}
}
}
impl fmt::Debug for Texture {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use image::GenericImageView;
#[derive(Debug)]
struct ImageInfo {
width: u32,
height: u32,
color: image::ColorType,
}
f.debug_struct("Texture")
.field("name", &self.name)
.field(
"image",
&ImageInfo {
width: self.image.width(),
height: self.image.height(),
color: self.image.color(),
},
)
.field("transparent", &self.transparent)
.field("wrap_mode_u", &self.wrap_mode_u)
.field("wrap_mode_v", &self.wrap_mode_v)
.finish()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum WrapMode {
Repeat,
ClampToEdge,
}