summaryrefslogtreecommitdiff
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
parent511d3873f5f567c97eecd69d186bb4f93f927d58 (diff)
Small optimization
-rw-r--r--examples/black.rs4
-rw-r--r--examples/bmp.rs6
-rw-r--r--examples/square.rs2
-rw-r--r--src/renderer.rs21
-rw-r--r--src/texture.rs3
5 files changed, 21 insertions, 15 deletions
diff --git a/examples/black.rs b/examples/black.rs
index 291fafb..a4237a4 100644
--- a/examples/black.rs
+++ b/examples/black.rs
@@ -7,8 +7,8 @@ fn main() {
let start = std::time::Instant::now();
// configure the render window
let config = RenderWindowConfig {
- //vsync: false,
- //mode: alligator_render::config::WindowMode::BorderlessFullscreen,
+ vsync: false,
+ mode: alligator_render::config::WindowMode::BorderlessFullscreen,
title: "Black Screen.exe",
..Default::default()
};
diff --git a/examples/bmp.rs b/examples/bmp.rs
index b1c2117..b527377 100644
--- a/examples/bmp.rs
+++ b/examples/bmp.rs
@@ -2,7 +2,7 @@
use std::num::NonZeroU32;
-use alligator_render::{config::WindowMode, ImageFormat, Instance, RenderWindowConfig, Renderer};
+use alligator_render::{ImageFormat, Instance, RenderWindowConfig, Renderer};
use winit::event_loop::EventLoop;
fn main() {
@@ -12,8 +12,8 @@ fn main() {
instance_capacity: 1,
default_width: NonZeroU32::new(1280).unwrap(),
default_height: NonZeroU32::new(720).unwrap(),
- mode: WindowMode::BorderlessFullscreen,
- vsync: false,
+ //mode: alligator_render::config::WindowMode::BorderlessFullscreen,
+ //vsync: false,
..Default::default()
};
diff --git a/examples/square.rs b/examples/square.rs
index f95bd00..7941fe1 100644
--- a/examples/square.rs
+++ b/examples/square.rs
@@ -8,6 +8,8 @@ fn main() {
let config = RenderWindowConfig {
title: "Pokemon: Black and White (New Edition)",
instance_capacity: 1,
+ //vsync: false,
+ //mode: alligator_render::config::WindowMode::BorderlessFullscreen,
..Default::default()
};
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)
}