Merge pull request #11 from adamnemecek/master

whitespace
pull/15/head
sotrh 4 years ago committed by GitHub
commit dabca840e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,7 +9,7 @@ fn main() {
let window = WindowBuilder::new()
.build(&event_loop)
.unwrap();
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -35,4 +35,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -122,7 +122,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -130,7 +130,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -165,4 +165,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -106,7 +106,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -114,7 +114,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -149,4 +149,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -231,7 +231,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -239,7 +239,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -274,4 +274,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -159,7 +159,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -167,7 +167,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -202,4 +202,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -168,7 +168,7 @@ impl State {
]
}
}).collect::<Vec<_>>();
let num_triangles = num_vertices - 2;
let challenge_indices = (1u16..num_triangles+1).into_iter().flat_map(|i| {
vec![i + 1, i, 0]
@ -261,8 +261,8 @@ impl State {
let data = if self.use_complex {
(
&self.challenge_vertex_buffer,
&self.challenge_index_buffer,
&self.challenge_vertex_buffer,
&self.challenge_index_buffer,
self.num_challenge_indices
)
} else {
@ -291,7 +291,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -299,7 +299,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -334,4 +334,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -221,7 +221,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -229,7 +229,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -264,4 +264,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -57,8 +57,8 @@ pub struct Texture {
impl Texture {
pub fn from_bytes(
device: &wgpu::Device,
queue: &mut wgpu::Queue,
device: &wgpu::Device,
queue: &mut wgpu::Queue,
layout: &wgpu::BindGroupLayout,
data: &[u8],
) -> Self {
@ -97,13 +97,13 @@ impl Texture {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -135,7 +135,7 @@ impl Texture {
}
],
});
Self {
texture,
view,
@ -381,7 +381,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -389,7 +389,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -424,4 +424,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -142,13 +142,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -336,7 +336,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -344,7 +344,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -379,4 +379,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -283,13 +283,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -546,7 +546,7 @@ fn main() {
let mut old_time = std::time::Instant::now();
const MSPT: std::time::Duration = std::time::Duration::from_millis(20);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -554,7 +554,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
()
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -597,4 +597,4 @@ fn main() {
_ => (),
}
});
}
}

@ -269,13 +269,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -527,7 +527,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -535,7 +535,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -570,4 +570,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -281,13 +281,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -449,7 +449,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -562,7 +562,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -570,7 +570,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -605,4 +605,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -283,13 +283,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -454,7 +454,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -589,7 +589,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -597,7 +597,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -632,4 +632,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -287,13 +287,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -373,7 +373,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -586,7 +586,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -594,7 +594,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -629,4 +629,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -288,13 +288,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -372,7 +372,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -420,13 +420,13 @@ impl State {
offset: 0,
row_pitch: std::mem::size_of::<f32>() as u32 * 4,
image_height: instance_data.len() as u32 * 4,
},
},
wgpu::TextureCopyView {
texture: &instance_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
instance_extent,
);
@ -639,7 +639,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -647,7 +647,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -682,4 +682,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -232,7 +232,7 @@ struct Instance {
impl Instance {
fn to_raw(&self) -> InstanceRaw {
let model = cgmath::Matrix4::from_translation(self.position)
let model = cgmath::Matrix4::from_translation(self.position)
* cgmath::Matrix4::from(self.rotation);
InstanceRaw { model }
}
@ -330,13 +330,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -416,7 +416,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -613,7 +613,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -621,7 +621,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -656,4 +656,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -246,7 +246,7 @@ fn quat_mul(q: cgmath::Quaternion<f32>, r: cgmath::Quaternion<f32>) -> cgmath::Q
// t1=(r0 q1 + r1 q0 r2 q3 + r3 q2)
// t2=(r0 q2 + r1 q3 + r2 q0 r3 q1)
// t3=(r0 q3 r1 q2 + r2 q1 + r3 q0
let w = r.s * q.s - r.v.x * q.v.x - r.v.y * q.v.y - r.v.z * q.v.z;
let xi = r.s * q.v.x + r.v.x * q.s - r.v.y * q.v.z + r.v.z * q.v.y;
@ -318,13 +318,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -404,7 +404,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -632,7 +632,7 @@ fn main() {
let mut old_time = std::time::Instant::now();
const MSPT: std::time::Duration = std::time::Duration::from_millis(20);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -640,7 +640,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
()
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -683,4 +683,4 @@ fn main() {
_ => (),
}
});
}
}

@ -232,7 +232,7 @@ struct Instance {
impl Instance {
fn to_raw(&self) -> InstanceRaw {
let model = cgmath::Matrix4::from_translation(self.position)
let model = cgmath::Matrix4::from_translation(self.position)
* cgmath::Matrix4::from(self.rotation);
InstanceRaw { model }
}
@ -330,13 +330,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -416,7 +416,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -613,7 +613,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -621,7 +621,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -656,4 +656,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -248,7 +248,7 @@ impl DepthPass {
}
],
});
let vertex_buffer = device
.create_buffer_mapped(DEPTH_VERTICES.len(), wgpu::BufferUsage::VERTEX)
.fill_from_slice(DEPTH_VERTICES);
@ -304,7 +304,7 @@ impl DepthPass {
sample_mask: !0,
alpha_to_coverage_enabled: false,
});
Self {
texture, view, sampler, bind_group,
vertex_buffer, index_buffer,
@ -371,7 +371,7 @@ const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
fn create_depth_texture(device: &wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor) -> wgpu::Texture {
let desc = wgpu::TextureDescriptor {
format: DEPTH_FORMAT,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT
| wgpu::TextureUsage::SAMPLED
| wgpu::TextureUsage::COPY_SRC,
..sc_desc.to_texture_desc()
@ -434,13 +434,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -520,7 +520,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -782,13 +782,13 @@ impl State {
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
wgpu::BufferCopyView {
buffer: &buffer,
offset: 0,
row_pitch: U32_SIZE * self.sc_desc.width,
image_height: self.sc_desc.height,
},
},
wgpu::Extent3d {
width: self.sc_desc.width,
height: self.sc_desc.height,
@ -816,7 +816,7 @@ impl State {
buffer.map_read_async(0, buffer_size, move |result: wgpu::BufferMapAsyncResult<&[f32]>| {
let mapping = result.unwrap();
let data = mapping.data;
use image::{ImageBuffer, Rgba, Pixel};
let mut buffer = ImageBuffer::<Rgba<u8>, _>::new(
width,
@ -829,7 +829,7 @@ impl State {
let z = pixel * 2.0 - 1.0;
let r = (2.0 * near * far) / (far + near - z * (far - near));
let p = (r.floor() * 255.0 / far) as u8;
buffer.put_pixel(x, y, Pixel::from_channels(
p, p, p, 255,
));
@ -840,7 +840,7 @@ impl State {
y += 1;
}
}
buffer.save("image.png").unwrap();
});
}
@ -854,7 +854,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -862,7 +862,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -897,4 +897,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -293,13 +293,13 @@ impl State {
offset: 0,
row_pitch: 4 * dimensions.0,
image_height: dimensions.1,
},
},
wgpu::TextureCopyView {
texture: &diffuse_texture,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
size3d,
);
@ -379,7 +379,7 @@ impl State {
} else {
cgmath::Quaternion::from_axis_angle(position.clone().normalize(), cgmath::Deg(45.0))
};
Instance {
position, rotation,
}
@ -616,7 +616,7 @@ fn main() {
.unwrap();
let mut state = State::new(&window);
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
@ -624,7 +624,7 @@ fn main() {
window_id,
} if window_id == window.id() => if state.input(event) {
*control_flow = ControlFlow::Wait;
} else {
} else {
match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
@ -659,4 +659,4 @@ fn main() {
_ => *control_flow = ControlFlow::Wait,
}
});
}
}

@ -16,7 +16,7 @@ fn main() {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsage::COPY_SRC
usage: wgpu::TextureUsage::COPY_SRC
| wgpu::TextureUsage::OUTPUT_ATTACHMENT
,
};
@ -27,7 +27,7 @@ fn main() {
let output_buffer_size = (u32_size * texture_size * texture_size) as wgpu::BufferAddress;
let output_buffer_desc = wgpu::BufferDescriptor {
size: output_buffer_size,
usage: wgpu::BufferUsage::COPY_DST
usage: wgpu::BufferUsage::COPY_DST
| wgpu::BufferUsage::MAP_READ
,
};
@ -114,13 +114,13 @@ fn main() {
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d::ZERO,
},
},
wgpu::BufferCopyView {
buffer: &output_buffer,
offset: 0,
row_pitch: u32_size * texture_size,
image_height: texture_size,
},
},
texture_desc.size,
);
@ -139,4 +139,4 @@ fn main() {
buffer.save("image.png").unwrap();
});
}
}

@ -95,6 +95,7 @@ At the end of the method, we simply return the resulting struct.
```rust
Self {
surface,
adapter,
device,
queue,
sc_desc,

Loading…
Cancel
Save