summaryrefslogtreecommitdiff
path: root/src/renderer.rs
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2022-10-04 09:59:44 -0400
committerMicha White <botahamec@outlook.com>2022-10-04 09:59:44 -0400
commit1169cf72ec435a495e1449bdf222bc0ccfd6f62a (patch)
tree3e080b1731de16e3c9bb0c7e8844d21341258dc9 /src/renderer.rs
parent511d3873f5f567c97eecd69d186bb4f93f927d58 (diff)
Small optimization
Diffstat (limited to 'src/renderer.rs')
-rw-r--r--src/renderer.rs21
1 files changed, 11 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),