Skip to content

Commit

Permalink
Use the right sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Dec 10, 2023
1 parent d936aa0 commit cab18ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bitflags::Flags;
use wgpu::util::DeviceExt;
use winit::window::Window;
use crate::gpu::{SCREEN_H, SCREEN_W};

// Code here is mostly derived from https://sotrh.github.io/learn-wgpu/beginner/tutorial1-window/

Expand Down Expand Up @@ -122,8 +123,8 @@ impl Context {
let texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("Texture"),
size: wgpu::Extent3d {
width: 100,
height: 100,
width: SCREEN_W as u32,
height: SCREEN_H as u32,
depth_or_array_layers: 1,
},
mip_level_count: 1,
Expand Down Expand Up @@ -273,23 +274,23 @@ impl Context {
self.window.request_redraw();
}

pub fn update(&mut self, rgb: Vec<u8>) {
pub fn update(&mut self, rgba: [u8; 92160]) {
self.queue.write_texture(
wgpu::ImageCopyTexture {
aspect: wgpu::TextureAspect::All,
texture: &self.texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
},
&rgb,
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: Some(4 * 100),
rows_per_image: Some(100),
bytes_per_row: Some(4 * SCREEN_W as u32),
rows_per_image: Some(SCREEN_H as u32),
},
wgpu::Extent3d {
width: 100,
height: 100,
width: SCREEN_W as u32,
height: SCREEN_H as u32,
depth_or_array_layers: 1,
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async fn main() -> Result<(), impl std::error::Error> {
if let Event::WindowEvent { event, window_id } = event {
match event {
WindowEvent::RedrawRequested if window_id == context.window().id() => {
context.update([0xFF; 92160]);
match context.render() {
Ok(_) => {}
Err(SurfaceError::Lost) => context.resize(context.size),
Expand All @@ -81,7 +82,6 @@ async fn main() -> Result<(), impl std::error::Error> {
}
}
WindowEvent::Resized(physical_size) => {
context.update(vec![0xFF; 40000]);
context.resize(physical_size);
}
WindowEvent::ModifiersChanged(new) => {
Expand Down

0 comments on commit cab18ef

Please sign in to comment.