Code cleanup
This commit is contained in:
parent
b291e7f82e
commit
30e7134415
|
@ -1,4 +1,4 @@
|
||||||
use glam::{Mat4, Quat, Vec2, Vec3};
|
use glam::{Mat4, Quat, Vec3};
|
||||||
use std::f32::consts::LN_2;
|
use std::f32::consts::LN_2;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use winit::event::{ElementState, VirtualKeyCode};
|
use winit::event::{ElementState, VirtualKeyCode};
|
||||||
|
@ -130,7 +130,7 @@ impl Flycam {
|
||||||
self.update_kinematic(dt);
|
self.update_kinematic(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_orientation(&mut self, dt: f32) {
|
fn update_orientation(&mut self, _dt: f32) {
|
||||||
let t = self.turn_sensitivity;
|
let t = self.turn_sensitivity;
|
||||||
|
|
||||||
self.euler_x -= t * self.mouse_dy; // mouse +y = 2D plane down = look down = 3d space -x
|
self.euler_x -= t * self.mouse_dy; // mouse +y = 2D plane down = look down = 3d space -x
|
||||||
|
|
|
@ -484,7 +484,7 @@ impl MeshPool {
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: keep track of loaded/unloaded meshes
|
// TODO: keep track of loaded/unloaded meshes
|
||||||
let on_complete = |target| {};
|
let on_complete = |_target| {};
|
||||||
|
|
||||||
self.staging.flush(commands, get_dst, on_complete);
|
self.staging.flush(commands, get_dst, on_complete);
|
||||||
}
|
}
|
||||||
|
|
19
src/pass.rs
19
src/pass.rs
|
@ -52,16 +52,21 @@ pub trait RenderPass: Send + Sync {
|
||||||
/// data to the GPU.
|
/// data to the GPU.
|
||||||
fn begin_frame(&self, data: &mut Self::FrameData, phases: &mut Vec<Phase>, queue: &wgpu::Queue);
|
fn begin_frame(&self, data: &mut Self::FrameData, phases: &mut Vec<Phase>, queue: &wgpu::Queue);
|
||||||
|
|
||||||
fn record_commands(&self, data: PhaseData<&Self::FrameData>, cmds: &mut wgpu::CommandEncoder) {}
|
fn record_commands(
|
||||||
|
&self,
|
||||||
fn record_compute<'a>(
|
_data: PhaseData<&Self::FrameData>,
|
||||||
&'a self,
|
_cmds: &mut wgpu::CommandEncoder,
|
||||||
data: PhaseData<&'a Self::FrameData>,
|
|
||||||
cmds: &mut wgpu::ComputePass<'a>,
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_render(&self, data: PhaseData<&Self::FrameData>) -> Option<wgpu::RenderBundle> {
|
fn record_compute<'a>(
|
||||||
|
&'a self,
|
||||||
|
_data: PhaseData<&'a Self::FrameData>,
|
||||||
|
_cmds: &mut wgpu::ComputePass<'a>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn record_render(&self, _data: PhaseData<&Self::FrameData>) -> Option<wgpu::RenderBundle> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::gpu::GpuVec;
|
||||||
use crate::viewport::ViewportInfo;
|
use crate::viewport::ViewportInfo;
|
||||||
use crate::RenderLayouts;
|
use crate::RenderLayouts;
|
||||||
|
|
||||||
|
@ -25,11 +26,8 @@ impl Vertex {
|
||||||
pub type Index = u32;
|
pub type Index = u32;
|
||||||
|
|
||||||
pub struct FrameData {
|
pub struct FrameData {
|
||||||
vertex_capacity: usize,
|
vertices: GpuVec<Vertex>,
|
||||||
vertices: wgpu::Buffer,
|
indices: GpuVec<Index>,
|
||||||
index_capacity: usize,
|
|
||||||
indices: wgpu::Buffer,
|
|
||||||
index_num: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DebugPass {
|
pub struct DebugPass {
|
||||||
|
@ -106,37 +104,31 @@ impl RenderPass for DebugPass {
|
||||||
type FrameData = FrameData;
|
type FrameData = FrameData;
|
||||||
|
|
||||||
fn create_frame_data(&self) -> FrameData {
|
fn create_frame_data(&self) -> FrameData {
|
||||||
let vertex_capacity = 1024 * 1024; // TODO resizable buffers
|
|
||||||
let vertices = self.device.create_buffer(&wgpu::BufferDescriptor {
|
|
||||||
label: Some("DebugPass Vertex Buffer"),
|
|
||||||
size: (vertex_capacity * std::mem::size_of::<Vertex>()) as wgpu::BufferAddress,
|
|
||||||
mapped_at_creation: false,
|
|
||||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
|
||||||
});
|
|
||||||
|
|
||||||
let index_capacity = 1024 * 1024; // TODO resizable buffers
|
|
||||||
let indices = self.device.create_buffer(&wgpu::BufferDescriptor {
|
|
||||||
label: Some("DebugPass Index Buffer"),
|
|
||||||
size: (index_capacity * std::mem::size_of::<Index>()) as wgpu::BufferAddress,
|
|
||||||
mapped_at_creation: false,
|
|
||||||
usage: wgpu::BufferUsages::INDEX | wgpu::BufferUsages::COPY_DST,
|
|
||||||
});
|
|
||||||
|
|
||||||
let index_num = 0;
|
|
||||||
|
|
||||||
FrameData {
|
FrameData {
|
||||||
vertex_capacity,
|
vertices: GpuVec::new(
|
||||||
vertices,
|
self.device.clone(),
|
||||||
index_capacity,
|
wgpu::BufferUsages::VERTEX,
|
||||||
indices,
|
1024 * 1024,
|
||||||
index_num,
|
Some("Debug Vertex Buffer".to_string()),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
indices: GpuVec::new(
|
||||||
|
self.device.clone(),
|
||||||
|
wgpu::BufferUsages::INDEX,
|
||||||
|
1024 * 1024,
|
||||||
|
Some("Debug Index Buffer".to_string()),
|
||||||
|
false,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn begin_frame(&self, data: &mut FrameData, phases: &mut Vec<Phase>, queue: &wgpu::Queue) {
|
fn begin_frame(&self, data: &mut FrameData, phases: &mut Vec<Phase>, queue: &wgpu::Queue) {
|
||||||
phases.push(Phase::Overlay);
|
phases.push(Phase::Overlay);
|
||||||
|
|
||||||
let vertices = &[
|
data.vertices.clear();
|
||||||
|
data.indices.clear();
|
||||||
|
|
||||||
|
data.vertices.extend_from_slice(&[
|
||||||
Vertex {
|
Vertex {
|
||||||
position: [0.0, 0.0, -1.0],
|
position: [0.0, 0.0, -1.0],
|
||||||
color: [1.0, 0.0, 0.0],
|
color: [1.0, 0.0, 0.0],
|
||||||
|
@ -145,13 +137,12 @@ impl RenderPass for DebugPass {
|
||||||
position: [0.0, 0.0, 1.0],
|
position: [0.0, 0.0, 1.0],
|
||||||
color: [0.0, 0.0, 1.0],
|
color: [0.0, 0.0, 1.0],
|
||||||
},
|
},
|
||||||
];
|
]);
|
||||||
queue.write_buffer(&data.vertices, 0, bytemuck::cast_slice(vertices));
|
|
||||||
|
|
||||||
let indices = &[0u32, 1u32];
|
data.indices.extend_from_slice(&[0u32, 1u32]);
|
||||||
queue.write_buffer(&data.indices, 0, bytemuck::cast_slice(indices));
|
|
||||||
|
|
||||||
data.index_num = 2;
|
data.vertices.write(queue);
|
||||||
|
data.indices.write(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_render(&self, data: PhaseData<&FrameData>) -> Option<wgpu::RenderBundle> {
|
fn record_render(&self, data: PhaseData<&FrameData>) -> Option<wgpu::RenderBundle> {
|
||||||
|
@ -171,12 +162,15 @@ impl RenderPass for DebugPass {
|
||||||
multiview: None,
|
multiview: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let vertices = &data.frame_data.vertices;
|
||||||
|
let indices = &data.frame_data.indices;
|
||||||
|
|
||||||
cmds.set_pipeline(&self.pipeline);
|
cmds.set_pipeline(&self.pipeline);
|
||||||
cmds.set_bind_group(0, data.bind_viewport, &[]);
|
cmds.set_bind_group(0, data.bind_viewport, &[]);
|
||||||
cmds.set_vertex_buffer(0, data.frame_data.vertices.slice(..));
|
cmds.set_vertex_buffer(0, vertices.as_ref().slice(..));
|
||||||
cmds.set_index_buffer(data.frame_data.indices.slice(..), wgpu::IndexFormat::Uint32);
|
cmds.set_index_buffer(indices.as_ref().slice(..), wgpu::IndexFormat::Uint32);
|
||||||
|
|
||||||
let index_range = 0..(data.frame_data.index_num as u32);
|
let index_range = 0..(indices.len() as u32);
|
||||||
cmds.draw_indexed(index_range, 0, 0..1);
|
cmds.draw_indexed(index_range, 0, 0..1);
|
||||||
|
|
||||||
Some(cmds.finish(&wgpu::RenderBundleDescriptor::default()))
|
Some(cmds.finish(&wgpu::RenderBundleDescriptor::default()))
|
||||||
|
|
|
@ -103,8 +103,8 @@ impl ShaderStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ShaderInfo {
|
pub struct ShaderInfo {
|
||||||
handle: ShaderHandle,
|
pub handle: ShaderHandle,
|
||||||
dependencies: BTreeSet<PathBuf>,
|
pub dependencies: BTreeSet<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ShaderLoader<'a> {
|
pub struct ShaderLoader<'a> {
|
||||||
|
|
Loading…
Reference in New Issue