diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-26 13:36:16 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-26 13:36:16 +0100 |
commit | 935f35455ac2e3547cdd21cd4596538958a7217e (patch) | |
tree | 98ed3752b1f4fbe5e95262185704544ba8be85ae /engine/src/texture.rs | |
parent | c4c599ae00e6a73126637bd73dce33522f5a9fef (diff) |
feat(engine): make textures clonable
Diffstat (limited to 'engine/src/texture.rs')
-rw-r--r-- | engine/src/texture.rs | 27 |
1 files changed, 25 insertions, 2 deletions
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<u32>, } 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 |