summaryrefslogtreecommitdiff
path: root/src/texture.rs
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2022-10-02 13:49:47 -0400
committerMicha White <botahamec@outlook.com>2022-10-02 13:49:47 -0400
commit511d3873f5f567c97eecd69d186bb4f93f927d58 (patch)
treeb99779ade2b150d51d800b7275a0c310a7591439 /src/texture.rs
parent39e36dd10cd7a335897e66e0f613d0191e7f9eba (diff)
Hacked in textures
Diffstat (limited to 'src/texture.rs')
-rw-r--r--src/texture.rs59
1 files changed, 54 insertions, 5 deletions
diff --git a/src/texture.rs b/src/texture.rs
index 8a36334..9184304 100644
--- a/src/texture.rs
+++ b/src/texture.rs
@@ -12,9 +12,10 @@ use thiserror::Error;
static NEXT_TEXTURE_ID: AtomicUsize = AtomicUsize::new(0);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-struct TextureId(usize);
+pub struct TextureId(usize);
impl TextureId {
+ #[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(NEXT_TEXTURE_ID.fetch_add(1, Ordering::Relaxed))
}
@@ -58,15 +59,16 @@ impl From<ImageError> for TextureError {
}
}
-struct TextureAtlases<'a> {
+// TODO make this Debug
+pub struct TextureAtlases<'a> {
packer: MultiTexturePacker<'a, image::RgbaImage, TextureId>,
+ width: u32,
+ height: u32,
}
impl<'a> Default for TextureAtlases<'a> {
fn default() -> Self {
- Self {
- packer: MultiTexturePacker::new_skyline(TexturePackerConfig::default()),
- }
+ Self::new(1024, 1024)
}
}
@@ -78,8 +80,11 @@ impl<'a> TextureAtlases<'a> {
packer: MultiTexturePacker::new_skyline(TexturePackerConfig {
max_width: width,
max_height: height,
+ //trim: false,
..Default::default()
}),
+ width,
+ height,
}
}
@@ -98,6 +103,50 @@ impl<'a> TextureAtlases<'a> {
Ok(id)
}
+ fn texture_frame(&self, id: TextureId) -> Option<&texture_packer::Frame<TextureId>> {
+ self.packer
+ .get_pages()
+ .iter()
+ .map(|a| a.get_frame(&id))
+ .next()?
+ }
+
+ pub fn texture_width(&self, id: TextureId) -> Option<u32> {
+ let frame = self.texture_frame(id)?;
+ Some(frame.frame.w)
+ }
+
+ pub fn texture_height(&self, id: TextureId) -> Option<u32> {
+ let frame = self.texture_frame(id)?;
+ Some(frame.frame.h)
+ }
+
+ pub fn texture_x(&self, id: TextureId) -> Option<u32> {
+ let frame = self.texture_frame(id)?;
+ Some(frame.frame.x)
+ }
+
+ pub fn texture_y(&self, id: TextureId) -> Option<u32> {
+ let frame = self.texture_frame(id)?;
+ Some(frame.frame.y)
+ }
+
+ pub(crate) const fn bytes_per_row(&self) -> u32 {
+ self.width * 4
+ }
+
+ pub(crate) const fn height(&self) -> u32 {
+ self.height
+ }
+
+ pub(crate) const fn extent_3d(&self) -> wgpu::Extent3d {
+ wgpu::Extent3d {
+ width: self.width,
+ height: self.height,
+ depth_or_array_layers: 1,
+ }
+ }
+
pub(crate) fn atlases(&self) -> ExportResult<Box<[DynamicImage]>> {
self.packer
.get_pages()