use sdl2::render::{Canvas, Texture};
use sdl2::video::Window;
#[derive(Default)]
pub struct TextureStore {
store: Option<Texture>,
width: u32,
height: u32,
}
impl TextureStore {
pub fn get_mut_ref(&mut self) -> &mut Texture {
self.store.as_mut().unwrap()
}
pub fn get_optional_ref(&mut self) -> Option<&Texture> {
Some(self.store.as_ref().unwrap())
}
pub fn create_or_resize_texture(&mut self, c: &mut Canvas<Window>, width: u32, height: u32) {
if self.store.is_none() || self.width != width || self.height != height {
self.width = width;
self.height = height;
self.store = Some(c.create_texture_target(None, width, height).unwrap());
eprintln!("Created texture: size={}x{}", width, height);
}
}
}