Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Nov 11, 2023
1 parent fd01dac commit 536471c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
61 changes: 31 additions & 30 deletions flare3d/examples/dummy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ fn main() {
let window = WindowBuilder::new().build(&event_loop).unwrap();
let mut state = futures_executor::block_on(State::new(&window));

event_loop.run(move |event, target| {
target.set_control_flow(ControlFlow::Wait);
event_loop
.run(move |event, target| {
target.set_control_flow(ControlFlow::Wait);

match event {
Event::WindowEvent { window_id, event } if window_id == window.id() => match event {
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
event:
KeyEvent {
state: ElementState::Pressed,
logical_key: Key::Named(NamedKey::Escape),
match event {
Event::WindowEvent { window_id, event } if window_id == window.id() => {
match event {
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
event:
KeyEvent {
state: ElementState::Pressed,
logical_key: Key::Named(NamedKey::Escape),
..
},
..
},
..
} => target.exit(),
WindowEvent::Resized(physical_size) => {
state.resize(physical_size);
}
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
state.resize(*new_inner_size);
}
WindowEvent::RedrawRequested => {
state.update();
match state.render() {
Ok(_) => {}
Err(wgpu::SurfaceError::Lost) => state.resize(state.size),
Err(wgpu::SurfaceError::OutOfMemory) => target.exit(),
Err(e) => eprintln!("{:?}", e),
} => target.exit(),
WindowEvent::Resized(physical_size) => {
state.resize(physical_size);
}
WindowEvent::RedrawRequested => {
state.update();
match state.render() {
Ok(_) => {}
Err(wgpu::SurfaceError::Lost) => state.resize(state.size),
Err(wgpu::SurfaceError::OutOfMemory) => target.exit(),
Err(e) => eprintln!("{:?}", e),
}
}
_ => (),
}
}
_ => (),
},
_ => (),
}
});
}
})
.unwrap();
}
25 changes: 13 additions & 12 deletions flare3d/src/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
struct CameraUniform {
view_proj: mat4x4<f32>;
view_proj: mat4x4f,
};
[[group(1), binding(0)]] // 1.

@group(1) @binding(0) // 1.
var<uniform> camera: CameraUniform;

struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
@location(0) position: vec3f,
@location(1) tex_coords: vec2f,
};

struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
@builtin(position) clip_position: vec4f,
@location(0) tex_coords: vec2f,
};

[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coords = model.tex_coords;
out.clip_position = camera.view_proj * vec4<f32>(model.position, 1.0); // 2.
out.clip_position = camera.view_proj * vec4f(model.position, 1.0); // 2.
return out;
}

[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0) @binding(1)
var s_diffuse: sampler;

[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4f {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}

0 comments on commit 536471c

Please sign in to comment.