Skip to content

Commit

Permalink
Make CI happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jan 27, 2024
1 parent b76ae84 commit fefb91f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 58 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions code/beginner/tutorial1-window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use wasm_bindgen::prelude::*;

fn start_event_loop() {
let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let _window = WindowBuilder::new().build(&event_loop).unwrap();

#[cfg(target_arch = "wasm32")]
{
Expand All @@ -21,7 +21,7 @@ fn start_event_loop() {
web_sys::window()
.and_then(|win| win.document())
.map(|doc| {
let canvas = window.canvas().unwrap();
let canvas = _window.canvas().unwrap();
let mut web_width = 800.0f32;
match doc.get_element_by_id("wasm-example") {
Some(dst) => {
Expand All @@ -37,8 +37,11 @@ fn start_event_loop() {
}
};
// winit 0.29 开始,通过 request_inner_size, canvas.set_width 都无法设置 canvas 的大小
let canvas = window.canvas().unwrap();
let canvas = _window.canvas().unwrap();
let web_height = web_width;
let scale_factor = _window.scale_factor() as f32;
canvas.set_width((web_width * scale_factor) as u32);
canvas.set_height((web_height * scale_factor) as u32);
canvas.style().set_css_text(
&(canvas.style().css_text()
+ &format!("width: {}px; height: {}px", web_width, web_height)),
Expand Down
3 changes: 1 addition & 2 deletions code/intermediate/hdr/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ fn main() -> Result<()> {
let out_dir = env::var("OUT_DIR")?;
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
let mut paths_to_copy = Vec::new();
paths_to_copy.push("res/");
let paths_to_copy = vec!["res/"];
copy_items(&paths_to_copy, out_dir, &copy_options)?;

Ok(())
Expand Down
14 changes: 7 additions & 7 deletions code/intermediate/tutorial13-terrain/src/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct TerrainPipeline {
min_max_height: glam::Vec2,
gen_layout: wgpu::BindGroupLayout,
gen_pipeline: wgpu::ComputePipeline,
render_pipeline: wgpu::RenderPipeline,
_render_pipeline: wgpu::RenderPipeline,
}

impl TerrainPipeline {
Expand Down Expand Up @@ -165,18 +165,18 @@ impl TerrainPipeline {
min_max_height,
gen_layout,
gen_pipeline,
render_pipeline,
_render_pipeline: render_pipeline,
}
}

pub fn render<'a, 'b>(
pub fn render<'a>(
&'a self,
render_pass: &'b mut wgpu::RenderPass<'a>,
render_pass: &mut wgpu::RenderPass<'a>,
terrain: &'a Terrain,
camera_bind_group: &'a wgpu::BindGroup,
light_bind_group: &'a wgpu::BindGroup,
) {
render_pass.set_pipeline(&self.render_pipeline);
render_pass.set_pipeline(&self._render_pipeline);
render_pass.set_bind_group(0, camera_bind_group, &[]);
render_pass.set_bind_group(1, light_bind_group, &[]);
for chunk in &terrain.chunks {
Expand Down Expand Up @@ -414,9 +414,9 @@ impl TerrainHackPipeline {
}
}

pub fn render<'a, 'b>(
pub fn render<'a>(
&'a self,
render_pass: &'b mut wgpu::RenderPass<'a>,
render_pass: &mut wgpu::RenderPass<'a>,
terrain: &'a Terrain,
camera_bind_group: &'a wgpu::BindGroup,
light_bind_group: &'a wgpu::BindGroup,
Expand Down
8 changes: 5 additions & 3 deletions code/showcase/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition.workspace = true
[dependencies]
anyhow = "1.0"
thiserror = "1.0"
bytemuck = { version = "1.14", features = [ "derive" ] }
bytemuck = { version = "1.14", features = ["derive"] }
glam.workspace = true
env_logger = "0.10"
pollster = "0.3"
Expand All @@ -16,10 +16,12 @@ log = "0.4"
tobj = "2.0"
wgpu.workspace = true
winit.workspace = true
cfg-if.workspace = true
instant.workspace = true

[build-dependencies]
anyhow.workspace = true
fs_extra.workspace = true
glob = "0.3"
naga = { version = "0.9", features = ["glsl-in", "spv-out", "wgsl-out"]}
rayon.workspace = true
naga = { version = "0.9", features = ["glsl-in", "spv-out", "wgsl-out"] }
rayon.workspace = true
74 changes: 31 additions & 43 deletions code/showcase/framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use texture::*;

use anyhow::*;
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::time::Duration;
use wgpu::util::{BufferInitDescriptor, DeviceExt};
use winit::event::*;
use winit::window::{Window, WindowBuilder};
Expand Down Expand Up @@ -211,17 +211,14 @@ pub trait Demo: 'static + Sized {
fn render(&mut self, display: &mut Display);
}

pub async fn run<D: Demo>() -> Result<(), Error> {
pub async fn run<D: Demo>() -> Result<(), anyhow::Error> {
let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new()
.with_title(env!("CARGO_PKG_NAME"))
.build(&event_loop)?;
let mut display = Display::new(Arc::new(window)).await?;
let mut demo = D::init(&display)?;
let mut last_update = Instant::now();
let mut is_resumed = true;
let mut is_focused = true;
let mut is_redraw_requested = true;
let mut last_render_time = instant::Instant::now();
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
use winit::platform::web::EventLoopExtWebSys;
Expand All @@ -237,48 +234,39 @@ pub async fn run<D: Demo>() -> Result<(), Error> {
demo.start();
}
if let Event::WindowEvent { event, .. } = event {
if !demo.input(&event) {
match event {
WindowEvent::KeyboardInput {
event:
KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
..
},
..
}
| WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::Resized(physical_size) => {
if physical_size.width == 0 || physical_size.height == 0 {
// 处理最小化窗口的事件
println!("Window minimized!");
} else {
display.resize(physical_size.width, physical_size.height);
demo.resize(&display);
}
match event {
WindowEvent::KeyboardInput {
event:
KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
..
},
..
}
| WindowEvent::CloseRequested => elwt.exit(),
WindowEvent::Resized(physical_size) => {
if physical_size.width == 0 || physical_size.height == 0 {
// 处理最小化窗口的事件
println!("Window minimized!");
} else {
display.resize(physical_size.width, physical_size.height);
demo.resize(&display);
}
WindowEvent::RedrawRequested => {
let now = instant::Instant::now();
let _dt = now - last_render_time;
last_render_time = now;
demo.update(&display, dt);

match demo.render(&mut display) {
Ok(_) => {}
// 当展示平面的上下文丢失,就需重新配置
Err(wgpu::SurfaceError::Lost) => eprintln!("Surface is lost"),
// 所有其他错误(过期、超时等)应在下一帧解决
Err(e) => eprintln!("SurfaceError: {e:?}"),
}
is_redraw_requested = false;
}
WindowEvent::RedrawRequested => {
let now = instant::Instant::now();
let dt = now - last_render_time;
last_render_time = now;
demo.update(&display, dt);
demo.render(&mut display);

// 除非我们手动请求,RedrawRequested 将只会触发一次。
display.window().request_redraw();
}
_ => {}
// 除非我们手动请求,RedrawRequested 将只会触发一次。
display.window().request_redraw();
}
_ => {}
}
}
},
);
Ok(())
}

0 comments on commit fefb91f

Please sign in to comment.