From 935f35455ac2e3547cdd21cd4596538958a7217e Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 26 Nov 2023 13:36:16 +0100 Subject: feat(engine): make textures clonable --- engine/src/texture.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'engine/src/texture.rs') diff --git a/engine/src/texture.rs b/engine/src/texture.rs index bde3cd2..f32bc0a 100644 --- a/engine/src/texture.rs +++ b/engine/src/texture.rs @@ -17,6 +17,8 @@ pub use reexports::*; pub struct Texture { inner: InnerTexture, + pixel_data_format: PixelDataFormat, + dimensions: Vec2, } impl Texture @@ -45,16 +47,18 @@ impl Texture let inner = InnerTexture::new(); + let dimensions = Vec2 { x: image.width(), y: image.height() }; + inner.bind(|texture_curr_bound| { InnerTexture::generate( &texture_curr_bound, - &Vec2 { x: image.width(), y: image.height() }, + &dimensions, image.as_bytes(), pixel_data_format, ); }); - let me = Self { inner }; + let me = Self { inner, pixel_data_format, dimensions }; me.set_wrap(Wrapping::Repeat); me.set_magnifying_filter(Filtering::Linear); @@ -90,6 +94,25 @@ impl Texture } } +impl Clone for Texture +{ + fn clone(&self) -> Self + { + let inner = self.inner.copy( + &self.dimensions, + self.pixel_data_format, + &Vec2::ZERO, + &Vec2::ZERO, + ); + + Self { + inner, + pixel_data_format: self.pixel_data_format, + dimensions: self.dimensions.clone(), + } + } +} + /// Texture error. #[derive(Debug, thiserror::Error)] pub enum Error -- cgit v1.2.3-18-g5258