Fix errors with new versions
This commit is contained in:
parent
010921f4fa
commit
881de4e3b9
|
@ -296,7 +296,7 @@ fn grid_cast_ray(orig_ray_pos: vec3<f32>, ray_dir: vec3<f32>) -> HitInfo {
|
||||||
|
|
||||||
@compute @workgroup_size(8, 8, 1)
|
@compute @workgroup_size(8, 8, 1)
|
||||||
fn compute(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
fn compute(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
||||||
let img_coord = vec2<i32>(global_id.xy);
|
let img_coord = global_id.xy;
|
||||||
let img_dims = textureDimensions(output);
|
let img_dims = textureDimensions(output);
|
||||||
|
|
||||||
// This discards the extra pixels in cases where the image size isn't perfectly divisible by the kernel.xy
|
// This discards the extra pixels in cases where the image size isn't perfectly divisible by the kernel.xy
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
use std::time::Instant;
|
use std::{sync::Arc, time::Instant};
|
||||||
use winit::{dpi::PhysicalSize, event::Event, event_loop::EventLoop};
|
use winit::{
|
||||||
|
dpi::PhysicalSize,
|
||||||
|
event::{Event, WindowEvent},
|
||||||
|
event_loop::EventLoop,
|
||||||
|
};
|
||||||
|
|
||||||
use super::camera;
|
use super::camera;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -7,22 +11,24 @@ use crate::{
|
||||||
voxel,
|
voxel,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App<'window> {
|
||||||
title: String,
|
title: String,
|
||||||
event_loop: EventLoop<()>,
|
event_loop: EventLoop<()>,
|
||||||
render_ctx: gfx::Context,
|
render_ctx: gfx::Context<'window>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl<'window> App<'window> {
|
||||||
pub async fn new(width: u32, height: u32, title: &str) -> Self {
|
pub async fn new(width: u32, height: u32, title: &str) -> Self {
|
||||||
log::info!("Initialising window...");
|
log::info!("Initialising window...");
|
||||||
let size = PhysicalSize::new(width, height);
|
let size = PhysicalSize::new(width, height);
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new().unwrap();
|
||||||
let window = winit::window::WindowBuilder::new()
|
let window = Arc::new(
|
||||||
.with_title(title)
|
winit::window::WindowBuilder::new()
|
||||||
.with_inner_size(size)
|
.with_title(title)
|
||||||
.build(&event_loop)
|
.with_inner_size(size)
|
||||||
.unwrap();
|
.build(&event_loop)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
let render_ctx = gfx::Context::new(
|
let render_ctx = gfx::Context::new(
|
||||||
window,
|
window,
|
||||||
|
@ -80,16 +86,20 @@ impl App {
|
||||||
let mut cumulative_dt = 0.0;
|
let mut cumulative_dt = 0.0;
|
||||||
let mut frames_accumulated = 0.0;
|
let mut frames_accumulated = 0.0;
|
||||||
let mut last_render_time = Instant::now();
|
let mut last_render_time = Instant::now();
|
||||||
self.event_loop.run(move |event, _, control_flow| {
|
self.event_loop.run(|event, elwt| {
|
||||||
if !self.render_ctx.handle_window_event(&event, control_flow) {
|
match event {
|
||||||
match event {
|
Event::WindowEvent { window_id, event }
|
||||||
Event::WindowEvent {
|
if window_id == self.render_ctx.window.id() =>
|
||||||
ref event,
|
{
|
||||||
window_id,
|
if self.render_ctx.handle_window_event(&event, elwt) {
|
||||||
} if window_id == self.render_ctx.window.id() => {
|
return;
|
||||||
camera_controller.process_events(event);
|
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
|
if camera_controller.process_events(&event) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let WindowEvent::RedrawRequested = event {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let dt = now - last_render_time;
|
let dt = now - last_render_time;
|
||||||
last_render_time = now;
|
last_render_time = now;
|
||||||
|
@ -114,10 +124,50 @@ impl App {
|
||||||
cumulative_dt = 0.0;
|
cumulative_dt = 0.0;
|
||||||
frames_accumulated = 0.0;
|
frames_accumulated = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.render_ctx.window.request_redraw();
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if !self.render_ctx.handle_window_event(&event, control_flow) {
|
||||||
|
// match event {
|
||||||
|
// Event::WindowEvent {
|
||||||
|
// ref event,
|
||||||
|
// window_id,
|
||||||
|
// } if window_id == self.render_ctx.window.id() => {
|
||||||
|
// camera_controller.process_events(event);
|
||||||
|
// }
|
||||||
|
// Event::RedrawRequested(_) => {
|
||||||
|
// let now = Instant::now();
|
||||||
|
// let dt = now - last_render_time;
|
||||||
|
// last_render_time = now;
|
||||||
|
// camera_controller.update(dt);
|
||||||
|
// camera_controller.update_buffer(&self.render_ctx);
|
||||||
|
// renderer.render(&self.render_ctx);
|
||||||
|
// renderer.update(&dt, &self.render_ctx);
|
||||||
|
// renderer.update_brickmap(&self.render_ctx, &mut world);
|
||||||
|
|
||||||
|
// // Simple framerate tracking
|
||||||
|
// self.render_ctx.window.set_title(&format!(
|
||||||
|
// "{}: {} fps",
|
||||||
|
// self.title,
|
||||||
|
// (1.0 / dt.as_secs_f32()).floor()
|
||||||
|
// ));
|
||||||
|
// cumulative_dt += dt.as_secs_f32();
|
||||||
|
// frames_accumulated += 1.0;
|
||||||
|
// if cumulative_dt >= 1.0 {
|
||||||
|
// let fps = frames_accumulated * 1.0 / cumulative_dt;
|
||||||
|
// let frame_time = cumulative_dt * 1000.0 / frames_accumulated;
|
||||||
|
// log::info!("FPS: {}, Frame Time: {}", fps.floor(), frame_time);
|
||||||
|
// cumulative_dt = 0.0;
|
||||||
|
// frames_accumulated = 0.0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// _ => {}
|
||||||
|
// }
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
use winit::event::{ElementState, KeyboardInput, VirtualKeyCode, WindowEvent};
|
use winit::{
|
||||||
|
event::{ElementState, KeyEvent, WindowEvent},
|
||||||
|
keyboard::{KeyCode, PhysicalKey},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::gfx::Context;
|
use crate::gfx::Context;
|
||||||
|
|
||||||
|
@ -143,17 +146,17 @@ impl CameraController {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_events(&mut self, event: &WindowEvent) -> bool {
|
pub fn process_events(&mut self, event: &WindowEvent) -> bool {
|
||||||
|
let mut handled = true;
|
||||||
match event {
|
match event {
|
||||||
WindowEvent::Resized(physical_size) => {
|
WindowEvent::Resized(physical_size) => {
|
||||||
self.projection
|
self.projection
|
||||||
.resize(physical_size.width, physical_size.height);
|
.resize(physical_size.width, physical_size.height);
|
||||||
true
|
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
KeyboardInput {
|
KeyEvent {
|
||||||
state,
|
state,
|
||||||
virtual_keycode: Some(keycode),
|
physical_key: PhysicalKey::Code(keycode),
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
|
@ -164,51 +167,43 @@ impl CameraController {
|
||||||
};
|
};
|
||||||
|
|
||||||
match keycode {
|
match keycode {
|
||||||
VirtualKeyCode::W => {
|
KeyCode::KeyW => {
|
||||||
self.move_dirs_pressed.z = val;
|
self.move_dirs_pressed.z = val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::S => {
|
KeyCode::KeyS => {
|
||||||
self.move_dirs_pressed.z = -val;
|
self.move_dirs_pressed.z = -val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::A => {
|
KeyCode::KeyA => {
|
||||||
self.move_dirs_pressed.x = -val;
|
self.move_dirs_pressed.x = -val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::D => {
|
KeyCode::KeyD => {
|
||||||
self.move_dirs_pressed.x = val;
|
self.move_dirs_pressed.x = val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Q => {
|
KeyCode::KeyQ => {
|
||||||
self.move_dirs_pressed.y = val;
|
self.move_dirs_pressed.y = val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::E => {
|
KeyCode::KeyE => {
|
||||||
self.move_dirs_pressed.y = -val;
|
self.move_dirs_pressed.y = -val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Up => {
|
KeyCode::ArrowUp => {
|
||||||
self.rot_dirs_pressed.y = val;
|
self.rot_dirs_pressed.y = val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Down => {
|
KeyCode::ArrowDown => {
|
||||||
self.rot_dirs_pressed.y = -val;
|
self.rot_dirs_pressed.y = -val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Left => {
|
KeyCode::ArrowLeft => {
|
||||||
self.rot_dirs_pressed.x = -val;
|
self.rot_dirs_pressed.x = -val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Right => {
|
KeyCode::ArrowRight => {
|
||||||
self.rot_dirs_pressed.x = val;
|
self.rot_dirs_pressed.x = val;
|
||||||
true
|
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => handled = false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => handled = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handled
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, dt: Duration) {
|
pub fn update(&mut self, dt: Duration) {
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
dpi::PhysicalSize,
|
dpi::PhysicalSize,
|
||||||
event::{Event, WindowEvent},
|
event::{Event, WindowEvent},
|
||||||
event_loop::ControlFlow,
|
event_loop::{ControlFlow, EventLoopWindowTarget},
|
||||||
window::Window,
|
window::Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context<'window> {
|
||||||
pub window: Window,
|
pub window: Arc<Window>,
|
||||||
pub instance: wgpu::Instance,
|
pub instance: wgpu::Instance,
|
||||||
pub size: PhysicalSize<u32>,
|
pub size: PhysicalSize<u32>,
|
||||||
pub surface: wgpu::Surface,
|
pub surface: wgpu::Surface<'window>,
|
||||||
pub surface_config: wgpu::SurfaceConfiguration,
|
pub surface_config: wgpu::SurfaceConfiguration,
|
||||||
pub adapter: wgpu::Adapter,
|
pub adapter: wgpu::Adapter,
|
||||||
pub device: wgpu::Device,
|
pub device: wgpu::Device,
|
||||||
pub queue: wgpu::Queue,
|
pub queue: wgpu::Queue,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl<'window> Context<'window> {
|
||||||
pub async fn new(window: Window, limits: wgpu::Limits) -> Self {
|
pub async fn new(window: Arc<Window>, limits: wgpu::Limits) -> Self {
|
||||||
log::info!("Initialising WGPU context...");
|
log::info!("Initialising WGPU context...");
|
||||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
backends: wgpu::Backends::VULKAN,
|
backends: wgpu::Backends::VULKAN,
|
||||||
dx12_shader_compiler: Default::default(),
|
dx12_shader_compiler: Default::default(),
|
||||||
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
// To be able to start drawing we need a few things:
|
// To be able to start drawing we need a few things:
|
||||||
|
@ -29,7 +32,7 @@ impl Context {
|
||||||
// - A GPU device to draw to the surface
|
// - A GPU device to draw to the surface
|
||||||
// - A draw command queue
|
// - A draw command queue
|
||||||
log::info!("Initialising window surface...");
|
log::info!("Initialising window surface...");
|
||||||
let surface = unsafe { instance.create_surface(&window) }.unwrap();
|
let surface = unsafe { instance.create_surface(window.clone()) }.unwrap();
|
||||||
|
|
||||||
log::info!("Requesting GPU adapter...");
|
log::info!("Requesting GPU adapter...");
|
||||||
let adapter = instance
|
let adapter = instance
|
||||||
|
@ -47,8 +50,8 @@ impl Context {
|
||||||
.request_device(
|
.request_device(
|
||||||
&wgpu::DeviceDescriptor {
|
&wgpu::DeviceDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
features: wgpu::Features::empty(),
|
required_features: wgpu::Features::empty(),
|
||||||
limits,
|
required_limits: limits,
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -74,7 +77,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize(&mut self, new_size: PhysicalSize<u32>) {
|
pub fn resize_surface(&mut self, new_size: PhysicalSize<u32>) {
|
||||||
if new_size.width > 0 && new_size.height > 0 {
|
if new_size.width > 0 && new_size.height > 0 {
|
||||||
self.size = new_size;
|
self.size = new_size;
|
||||||
self.surface_config.width = new_size.width;
|
self.surface_config.width = new_size.width;
|
||||||
|
@ -85,33 +88,24 @@ impl Context {
|
||||||
|
|
||||||
pub fn handle_window_event(
|
pub fn handle_window_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
event: &Event<()>,
|
event: &WindowEvent,
|
||||||
control_flow: &mut ControlFlow,
|
elwt: &EventLoopWindowTarget<()>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
let mut handled = true;
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
WindowEvent::CloseRequested => {
|
||||||
ref event,
|
elwt.exit();
|
||||||
window_id,
|
|
||||||
} if *window_id == self.window.id() => match event {
|
|
||||||
WindowEvent::CloseRequested => {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
true
|
|
||||||
}
|
|
||||||
WindowEvent::Resized(physical_size) => {
|
|
||||||
self.resize(*physical_size);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
|
|
||||||
self.resize(**new_inner_size);
|
|
||||||
true
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
Event::MainEventsCleared => {
|
|
||||||
self.window.request_redraw();
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
_ => false,
|
WindowEvent::Resized(physical_size) => {
|
||||||
|
self.resize_surface(*physical_size);
|
||||||
|
}
|
||||||
|
WindowEvent::ScaleFactorChanged { .. } => {
|
||||||
|
self.resize_surface(self.window.inner_size());
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => handled = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,8 +187,8 @@ impl Texture {
|
||||||
let size = self.attributes.size;
|
let size = self.attributes.size;
|
||||||
let image_layout = wgpu::ImageDataLayout {
|
let image_layout = wgpu::ImageDataLayout {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
bytes_per_row: std::num::NonZeroU32::new(4 * size.width),
|
bytes_per_row: Some(4 * size.width),
|
||||||
rows_per_image: std::num::NonZeroU32::new(size.height),
|
rows_per_image: Some(size.height),
|
||||||
};
|
};
|
||||||
|
|
||||||
context
|
context
|
||||||
|
|
|
@ -209,10 +209,11 @@ impl gfx::Renderer for VoxelRenderer {
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
ops: wgpu::Operations {
|
ops: wgpu::Operations {
|
||||||
load: wgpu::LoadOp::Clear(self.clear_color),
|
load: wgpu::LoadOp::Clear(self.clear_color),
|
||||||
store: true,
|
store: wgpu::StoreOp::Store,
|
||||||
},
|
},
|
||||||
})],
|
})],
|
||||||
depth_stencil_attachment: None,
|
depth_stencil_attachment: None,
|
||||||
|
..Default::default()
|
||||||
});
|
});
|
||||||
render_pass.set_pipeline(&self.render_pipeline);
|
render_pass.set_pipeline(&self.render_pipeline);
|
||||||
render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]);
|
render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]);
|
||||||
|
|
Loading…
Reference in New Issue