summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/renderer.rs21
-rw-r--r--src/texture.rs3
2 files changed, 14 insertions, 10 deletions
diff --git a/src/renderer.rs b/src/renderer.rs
index 14a7b6a..516b1b1 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -64,6 +64,7 @@ pub struct Renderer {
texture_size: wgpu::Extent3d,
diffuse_texture: wgpu::Texture,
diffuse_bind_group: wgpu::BindGroup,
+ image: image::RgbaImage,
window: Window,
}
@@ -299,6 +300,13 @@ impl Renderer {
},
],
});
+ // TODO make this all resizable
+ let image = image::RgbaImage::from_vec(
+ texture_size.width,
+ texture_size.height,
+ vec![0; 4 * texture_size.width as usize * texture_size.height as usize],
+ )
+ .unwrap();
let render_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
@@ -330,6 +338,7 @@ impl Renderer {
texture_size,
diffuse_texture,
diffuse_bind_group,
+ image,
window,
})
}
@@ -468,18 +477,10 @@ impl Renderer {
// TODO optimize this
fn fill_textures(&mut self) {
- // create a base image
- let mut image = image::RgbaImage::from_vec(
- self.texture_size.width,
- self.texture_size.height,
- vec![0; 4 * self.texture_size.width as usize * self.texture_size.height as usize],
- )
- .unwrap();
-
// put the packed texture into the base image
let Ok(atlases) = self.textures.atlases() else { return };
let Some(atlas) = atlases.first() else { return };
- image.copy_from(atlas, 0, 0).unwrap();
+ self.image.copy_from(atlas, 0, 0).unwrap();
// copy that to the gpu
self.queue.write_texture(
@@ -489,7 +490,7 @@ impl Renderer {
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
},
- image.as_bytes(),
+ self.image.as_bytes(),
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(self.texture_size.width * 4),
diff --git a/src/texture.rs b/src/texture.rs
index 9184304..f5d1c34 100644
--- a/src/texture.rs
+++ b/src/texture.rs
@@ -64,6 +64,7 @@ pub struct TextureAtlases<'a> {
packer: MultiTexturePacker<'a, image::RgbaImage, TextureId>,
width: u32,
height: u32,
+ changed: bool,
}
impl<'a> Default for TextureAtlases<'a> {
@@ -85,6 +86,7 @@ impl<'a> TextureAtlases<'a> {
}),
width,
height,
+ changed: false,
}
}
@@ -99,6 +101,7 @@ impl<'a> TextureAtlases<'a> {
self.packer
.pack_own(id, img)
.map_err(TextureError::TextureTooLarge)?;
+ self.changed = true;
Ok(id)
}