Merge pull request #480 from sotrh/0.16

0.16
This commit is contained in:
Ben Hansen 2023-06-10 17:26:48 -06:00 committed by GitHub
commit 588a5442c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
111 changed files with 1749 additions and 945 deletions

1515
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -16,5 +16,5 @@ members = [
]
exclude = [
"code/showcase/imgui-demo",
"code/showcase/pong",
#"code/showcase/pong",
]

View File

@ -13,17 +13,17 @@ path = "src/main.rs"
[dependencies]
cfg-if = "1"
winit = "0.27"
winit = "0.28"
env_logger = "0.10"
log = "0.4"
wgpu = "0.15"
pollster = "0.2"
wgpu = "0.16"
pollster = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.15", features = ["webgl"]}
wasm-bindgen = "=0.2.84"
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "=0.2.86"
wasm-bindgen-futures = "0.4.30"
web-sys = { version = "0.3.53", features = [
"Document",

View File

@ -4,10 +4,10 @@ use winit::{
window::WindowBuilder,
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -19,9 +19,7 @@ pub fn run() {
}
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.build(&event_loop)
.unwrap();
let window = WindowBuilder::new().build(&event_loop).unwrap();
#[cfg(target_arch = "wasm32")]
{
@ -29,7 +27,7 @@ pub fn run() {
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())

View File

@ -2,4 +2,4 @@ use tutorial1_window::run;
fn main() {
run();
}
}

View File

@ -9,16 +9,16 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
cfg-if = "1"
winit = "0.27"
winit = "0.28"
env_logger = "0.10"
log = "0.4"
wgpu = "0.15"
pollster = "0.2"
wgpu = "0.16"
pollster = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -30,7 +30,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -68,9 +68,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -208,7 +210,9 @@ async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -34,7 +34,7 @@ impl State {
// The surface needs to live as long as the window that created it.
// State owns the window so this should be safe.
let surface = unsafe { instance.create_surface(&window) }.unwrap();
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(),
@ -67,9 +67,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -222,10 +224,12 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
Err(wgpu::SurfaceError::Timeout) => log::warn!("Surface timeout"),
}
}

View File

@ -2,4 +2,4 @@ use tutorial2_surface::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -9,16 +9,16 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
cfg-if = "1"
winit = "0.27"
winit = "0.28"
env_logger = "0.10"
log = "0.4"
wgpu = "0.15"
pollster = "0.2"
wgpu = "0.16"
pollster = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -28,7 +28,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -66,9 +66,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -320,7 +322,9 @@ async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -6,7 +6,7 @@ use winit::{
window::{Window, WindowBuilder},
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
struct State {
@ -30,7 +30,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -68,9 +68,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -212,7 +214,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -232,7 +234,7 @@ pub async fn run() {
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -244,7 +246,7 @@ pub async fn run() {
})
.expect("Couldn't append canvas to document body.");
}
// State::new uses async code, so we're going to wait for it to finish
let mut state = State::new(window).await;
@ -282,7 +284,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial3_pipeline::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -10,18 +10,18 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
cfg-if = "1"
winit = "0.27"
wgpu = "0.15"
winit = "0.28"
wgpu = "0.16"
env_logger = "0.10"
log = "0.4"
pollster = "0.2"
pollster = "0.3"
# NEW!
bytemuck = { version = "1.12", features = [ "derive" ] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -91,7 +91,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -129,9 +129,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -397,7 +399,9 @@ async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -7,7 +7,7 @@ use winit::{
window::{Window, WindowBuilder},
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[repr(C)]
@ -87,7 +87,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -125,9 +125,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -286,7 +288,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -306,7 +308,7 @@ pub async fn run() {
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -356,7 +358,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial4_buffer::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -13,9 +13,9 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
env_logger = "0.10"
log = "0.4"
pollster = "0.2"
wgpu = "0.15"
winit = "0.27"
pollster = "0.3"
wgpu = "0.16"
winit = "0.28"
[dependencies.image]
version = "0.24"
@ -24,8 +24,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -93,7 +93,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -130,9 +130,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -424,7 +426,9 @@ async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -7,7 +7,7 @@ use winit::{
window::{Window, WindowBuilder},
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
mod texture;
@ -93,7 +93,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -130,9 +130,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -336,7 +338,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -356,7 +358,7 @@ pub async fn run() {
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -368,7 +370,7 @@ pub async fn run() {
})
.expect("Couldn't append canvas to document body.");
}
// State::new uses async code, so we're going to wait for it to finish
let mut state = State::new(window).await;
@ -406,7 +408,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial5_textures::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -56,8 +56,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -14,9 +14,9 @@ bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
log = "0.4"
pollster = "0.2"
wgpu = "0.15"
winit = "0.27"
pollster = "0.3"
wgpu = "0.16"
winit = "0.28"
[dependencies.image]
version = "0.24"
@ -25,8 +25,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -243,7 +243,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -280,9 +280,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -595,7 +597,9 @@ async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -7,7 +7,7 @@ use winit::{
window::{Window, WindowBuilder},
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
mod texture;
@ -243,7 +243,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -280,9 +280,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -545,7 +547,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -565,7 +567,7 @@ pub async fn run() {
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -615,7 +617,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial6_uniforms::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -56,8 +56,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -14,9 +14,9 @@ bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
log = "0.4"
pollster = "0.2"
wgpu = "0.15"
winit = "0.27"
pollster = "0.3"
wgpu = "0.16"
winit = "0.28"
[dependencies.image]
version = "0.24"
@ -25,8 +25,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -297,7 +297,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -334,9 +334,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -696,7 +698,9 @@ async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -8,7 +8,7 @@ use winit::{
window::{Window, WindowBuilder},
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
mod texture;
@ -304,7 +304,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -341,9 +341,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -663,7 +665,7 @@ pub async fn run() {
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -713,7 +715,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial7_instancing::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -56,8 +56,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -13,10 +13,10 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
wgpu = "0.15"
winit = "0.27"
wgpu = "0.16"
winit = "0.28"
[dependencies.image]
version = "0.24"
@ -25,8 +25,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -1,7 +1,7 @@
use std::iter;
use cgmath::prelude::*;
use wgpu::{include_spirv_raw};
use wgpu::include_spirv_raw;
use wgpu::util::DeviceExt;
use winit::{
event::*,
@ -296,7 +296,11 @@ struct DepthPass {
impl DepthPass {
fn new(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) -> Self {
let texture = texture::Texture::create_depth_texture_non_comparison_sampler(device, config, "depth_texture");
let texture = texture::Texture::create_depth_texture_non_comparison_sampler(
device,
config,
"depth_texture",
);
let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Depth Pass Layout"),
@ -413,7 +417,11 @@ impl DepthPass {
}
fn resize(&mut self, device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) {
self.texture = texture::Texture::create_depth_texture_non_comparison_sampler(device, config, "depth_texture");
self.texture = texture::Texture::create_depth_texture_non_comparison_sampler(
device,
config,
"depth_texture",
);
self.bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &self.layout,
entries: &[
@ -486,7 +494,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -523,9 +531,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -893,7 +903,9 @@ async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -8,7 +8,7 @@ use winit::{
window::{Window, WindowBuilder},
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
mod texture;
@ -314,7 +314,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -351,9 +351,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -670,7 +672,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -690,7 +692,7 @@ pub async fn run() {
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -702,7 +704,7 @@ pub async fn run() {
})
.expect("Couldn't append canvas to document body.");
}
// State::new uses async code, so we're going to wait for it to finish
let mut state = State::new(window).await;
@ -740,7 +742,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial8_depth::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -142,8 +142,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -13,11 +13,11 @@ bytemuck = { version = "1.12", features = [ "derive" ] }
cfg-if = "1"
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = "0.15"
winit = "0.27"
wgpu = "0.16"
winit = "0.28"
[dependencies.image]
version = "0.24"
@ -27,8 +27,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -8,12 +8,12 @@ use winit::{
window::Window,
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
mod model;
mod texture;
mod resources;
mod texture;
use model::{DrawModel, Vertex};
@ -254,7 +254,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -294,9 +294,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -408,12 +410,10 @@ impl State {
});
log::warn!("Load model");
let obj_model = resources::load_model(
"cube.obj",
&device,
&queue,
&texture_bind_group_layout,
).await.unwrap();
let obj_model =
resources::load_model("cube.obj", &device, &queue, &texture_bind_group_layout)
.await
.unwrap();
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("shader.wgsl"),
@ -583,7 +583,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -601,14 +601,13 @@ pub async fn run() {
.build(&event_loop)
.unwrap();
#[cfg(target_arch = "wasm32")]
{
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -659,7 +658,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial9_models::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -100,8 +100,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -13,11 +13,11 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.15"}
winit = "0.27"
wgpu = { version = "0.16"}
winit = "0.28"
[dependencies.image]
version = "0.24"
@ -27,8 +27,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -8,7 +8,7 @@ use winit::{
window::Window,
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
mod model;
@ -349,7 +349,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -386,9 +386,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -500,12 +502,10 @@ impl State {
label: Some("camera_bind_group"),
});
let obj_model = resources::load_model(
"cube.obj",
&device,
&queue,
&texture_bind_group_layout,
).await.unwrap();
let obj_model =
resources::load_model("cube.obj", &device, &queue, &texture_bind_group_layout)
.await
.unwrap();
let light_uniform = LightUniform {
position: [2.0, 2.0, 2.0],
@ -720,7 +720,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -738,14 +738,13 @@ pub async fn run() {
.build(&event_loop)
.unwrap();
#[cfg(target_arch = "wasm32")]
{
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -799,7 +798,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial10_lighting::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -140,7 +140,13 @@ where
) {
for mesh in &model.meshes {
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}
@ -218,7 +224,12 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
self.draw_light_mesh_instanced(
mesh,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}

View File

@ -100,8 +100,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -13,11 +13,11 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.15"}
winit = "0.27"
wgpu = { version = "0.16"}
winit = "0.28"
[dependencies.image]
version = "0.24"
@ -27,8 +27,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -8,7 +8,7 @@ use winit::{
window::Window,
};
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
mod model;
@ -349,7 +349,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -386,9 +386,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -517,12 +519,10 @@ impl State {
label: Some("camera_bind_group"),
});
let obj_model = resources::load_model(
"cube.obj",
&device,
&queue,
&texture_bind_group_layout,
).await.unwrap();
let obj_model =
resources::load_model("cube.obj", &device, &queue, &texture_bind_group_layout)
.await
.unwrap();
let light_uniform = LightUniform {
position: [2.0, 2.0, 2.0],
@ -771,7 +771,7 @@ impl State {
}
}
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub async fn run() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -789,14 +789,13 @@ pub async fn run() {
.build(&event_loop)
.unwrap();
#[cfg(target_arch = "wasm32")]
{
// Winit prevents sizing with CSS, so we have to set
// the size manually when on web.
use winit::dpi::PhysicalSize;
window.set_inner_size(PhysicalSize::new(450, 400));
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.and_then(|win| win.document())
@ -847,7 +846,9 @@ pub async fn run() {
match state.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
state.resize(state.size)
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
// We're ignoring timeouts

View File

@ -2,4 +2,4 @@ use tutorial11_normals::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -203,7 +203,13 @@ where
) {
for mesh in &model.meshes {
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
@ -216,7 +222,13 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}
@ -294,7 +306,12 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
self.draw_light_mesh_instanced(
mesh,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}

View File

@ -105,8 +105,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -13,11 +13,11 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.15"}
winit = "0.27"
wgpu = { version = "0.16"}
winit = "0.28"
instant = "0.1"
[dependencies.image]
@ -28,8 +28,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -229,7 +229,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -266,9 +266,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,

View File

@ -2,4 +2,4 @@ use tutorial12_camera::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -202,7 +202,13 @@ where
) {
for mesh in &model.meshes {
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
@ -215,7 +221,13 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}
@ -293,7 +305,12 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
self.draw_light_mesh_instanced(
mesh,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}

View File

@ -106,8 +106,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -13,11 +13,11 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = { version = "0.18", features = [ "swizzle" ] }
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.15"}
winit = "0.27"
wgpu = { version = "0.16"}
winit = "0.28"
instant = "0.1"
[dependencies.image]
@ -28,8 +28,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -14,8 +14,8 @@ use wasm_bindgen::prelude::*;
mod camera;
mod model;
mod resources;
mod texture;
mod terrain;
mod texture;
use model::{DrawLight, DrawModel, Vertex};
@ -231,7 +231,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -268,9 +268,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -540,9 +542,24 @@ impl State {
let mut terrain = terrain::Terrain::new(chunk_size, min_max_height);
terrain.gen_chunk(&device, &queue, &terrain_pipeline, cgmath::Vector3::zero());
terrain.gen_chunk(&device, &queue, &terrain_pipeline, (0.0, 0.0, -(chunk_size.y as f32)).into());
terrain.gen_chunk(&device, &queue, &terrain_pipeline, (-(chunk_size.x as f32), 0.0, -(chunk_size.y as f32)).into());
terrain.gen_chunk(&device, &queue, &terrain_pipeline, (-(chunk_size.x as f32), 0.0, 0.0).into());
terrain.gen_chunk(
&device,
&queue,
&terrain_pipeline,
(0.0, 0.0, -(chunk_size.y as f32)).into(),
);
terrain.gen_chunk(
&device,
&queue,
&terrain_pipeline,
(-(chunk_size.x as f32), 0.0, -(chunk_size.y as f32)).into(),
);
terrain.gen_chunk(
&device,
&queue,
&terrain_pipeline,
(-(chunk_size.x as f32), 0.0, 0.0).into(),
);
Self {
window,
@ -699,7 +716,12 @@ impl State {
// &self.light_bind_group,
// );
self.terrain_pipeline.render(&mut render_pass, &self.terrain, &self.camera_bind_group, &self.light_bind_group);
self.terrain_pipeline.render(
&mut render_pass,
&self.terrain,
&self.camera_bind_group,
&self.light_bind_group,
);
}
self.queue.submit(iter::once(encoder.finish()));
output.present();

View File

@ -2,4 +2,4 @@ use tutorial13_terrain::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -203,7 +203,13 @@ where
) {
for mesh in &model.meshes {
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
@ -216,7 +222,13 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}
@ -294,7 +306,12 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
self.draw_light_mesh_instanced(
mesh,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}

View File

@ -256,7 +256,7 @@ pub async fn load_model(
// println!("data.len(): {}", data.len());
// let data_t: &[T] = bytemuck::cast_slice(&data[..]);
// output.extend(data_t.iter().map(f));
// });
// device.poll(wgpu::Maintain::Wait);
@ -264,4 +264,4 @@ pub async fn load_model(
// }
// buffer.unmap();
// output
// }
// }

View File

@ -568,8 +568,8 @@ impl GenerateChunk for TerrainHackPipeline {
buffer: &chunk.mesh.vertex_buffer,
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: std::num::NonZeroU32::new(std::mem::size_of::<u32>() as u32 * self.texture_size),
rows_per_image: std::num::NonZeroU32::new(self.texture_size),
bytes_per_row: Some(std::mem::size_of::<u32>() as u32 * self.texture_size),
rows_per_image: Some(self.texture_size),
},
},
wgpu::Extent3d {
@ -589,8 +589,8 @@ impl GenerateChunk for TerrainHackPipeline {
buffer: &chunk.mesh.index_buffer,
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: std::num::NonZeroU32::new(std::mem::size_of::<u32>() as u32 * self.texture_size),
rows_per_image: std::num::NonZeroU32::new(self.texture_size),
bytes_per_row: Some(std::mem::size_of::<u32>() as u32 * self.texture_size),
rows_per_image: Some(self.texture_size),
},
},
wgpu::Extent3d {
@ -613,15 +613,28 @@ impl GenerateChunk for TerrainHackPipeline {
let data = bs.get_mapped_range();
let indices: &[u32] = bytemuck::cast_slice(&data);
let mut f = std::fs::File::create(format!("Chunk ({}, {}) Indices.txt", chunk.corner.x, chunk.corner.y)).unwrap();
let mut f = std::fs::File::create(format!(
"Chunk ({}, {}) Indices.txt",
chunk.corner.x, chunk.corner.y
))
.unwrap();
use std::io::Write;
for quad in indices.chunks(6) {
writeln!(f, "{:?}", quad);
}
drop(f);
let img = image::ImageBuffer::<image::Rgba<u8>, _>::from_raw(self.texture_size, self.texture_size, data).unwrap();
img.save(format!("Chunk ({}, {}) Vertex Data.png", chunk.corner.x, chunk.corner.y)).unwrap();
let img = image::ImageBuffer::<image::Rgba<u8>, _>::from_raw(
self.texture_size,
self.texture_size,
data,
)
.unwrap();
img.save(format!(
"Chunk ({}, {}) Vertex Data.png",
chunk.corner.x, chunk.corner.y
))
.unwrap();
}
chunk.mesh.index_buffer.unmap();

View File

@ -106,8 +106,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);
@ -129,4 +129,4 @@ impl Texture {
sampler,
})
}
}
}

View File

@ -0,0 +1,11 @@
[package]
name = "md-builder"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
markdown = "0.3.0"
rayon = "1.7.0"
thiserror = "1.0.40"

View File

@ -0,0 +1,28 @@
use std::path::Path;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Error processing file: {0}")]
Io(#[from] std::io::Error),
}
fn main() -> Result<(), Error> {
let dir_path = match std::env::args().skip(1).next() {
Some(s) => s,
None => {
println!("Usage: md-builder 'directory with markdown'");
std::process::exit(1);
}
};
let dir = std::fs::read_dir(dir_path)?;
Ok(())
}
fn process_file<P: AsRef<Path>>(path: P) -> Result<(), Error> {
let path = path.as_ref();
Ok(())
}

View File

@ -9,13 +9,13 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = ["derive"]}
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
image = "0.24"
log = "0.4"
rayon = "1.4"
tobj = "2.0"
wgpu = "0.15"
winit = "0.27"
wgpu = "0.16"
winit = "0.28"
[build-dependencies]
anyhow = "1.0"

View File

@ -7,8 +7,8 @@ use naga::front::glsl::Options;
use naga::front::glsl::Parser;
use rayon::prelude::*;
use std::env;
use std::{fs::read_to_string, path::PathBuf};
use std::result::Result::Ok;
use std::{fs::read_to_string, path::PathBuf};
pub fn load_shader(src_path: PathBuf) -> Result<()> {
let extension = src_path
@ -48,7 +48,6 @@ pub fn load_shader(src_path: PathBuf) -> Result<()> {
let flags = wgsl::WriterFlags::empty();
std::fs::write(wgsl_path, wgsl::write_string(&module, &info, flags)?)?;
Ok(())
}

View File

@ -168,7 +168,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -205,9 +205,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,

View File

@ -472,7 +472,13 @@ where
) {
for mesh in &model.meshes {
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
@ -485,7 +491,13 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}
@ -563,7 +575,12 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
self.draw_light_mesh_instanced(
mesh,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}

View File

@ -120,8 +120,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -10,13 +10,13 @@ thiserror = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
image = "0.24.2"
log = "0.4"
tobj = "2.0"
wgpu = "0.15"
wgpu = "0.16"
wgpu-subscriber = "0.1"
winit = "0.27"
winit = "0.28"
[build-dependencies]
anyhow = "1.0"

View File

@ -1,10 +1,10 @@
use anyhow::Context;
use glob::glob;
use naga::back::wgsl;
use naga::front::glsl::Options;
use naga::front::glsl::Parser;
use rayon::prelude::*;
use std::{fs::read_to_string, path::PathBuf};
use anyhow::Context;
pub fn load_shader(src_path: PathBuf) -> anyhow::Result<()> {
let extension = src_path

View File

@ -68,9 +68,11 @@ impl Display {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,

View File

@ -331,7 +331,13 @@ where
) {
for mesh in &model.meshes {
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
@ -344,7 +350,13 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}
@ -422,7 +434,12 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
self.draw_light_mesh_instanced(
mesh,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}

View File

@ -107,7 +107,6 @@ pub struct ShaderCanvasBuilder<'a> {
impl<'a> ShaderCanvasBuilder<'a> {
pub fn new() -> Self {
Self {
canvas_size: [256.0; 2],
clear_color: [0.0, 0.0, 0.0, 1.0],

View File

@ -105,8 +105,8 @@ impl<'a> Texture<'a> {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -10,12 +10,12 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
image = "0.24.2"
log = "0.4"
tobj = "3.1"
wgpu = "0.15"
winit = "0.27"
wgpu = "0.16"
winit = "0.28"
gif = "0.11.4"
futures-intrusive = "0.4"

View File

@ -5,9 +5,9 @@ use std::{iter, mem, num::NonZeroU32};
async fn run() {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions::default())
.await
@ -18,12 +18,12 @@ async fn run() {
label: Some("Device"),
features: wgpu::Features::empty(),
// WebGL doesn't support all of wgpu's features, so if
// we're building for the web we'll have to disable some.
limits: if cfg!(target_arch = "wasm32") {
wgpu::Limits::downlevel_webgl2_defaults()
} else {
wgpu::Limits::default()
},
// we're building for the web we'll have to disable some.
limits: if cfg!(target_arch = "wasm32") {
wgpu::Limits::downlevel_webgl2_defaults()
} else {
wgpu::Limits::default()
},
},
None, // Trace path
)
@ -122,8 +122,8 @@ async fn run() {
buffer: &output_buffer,
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(padded_bytes_per_row),
rows_per_image: NonZeroU32::new(texture_size),
bytes_per_row: Some(padded_bytes_per_row),
rows_per_image: Some(texture_size),
},
},
render_target.desc.size,

View File

@ -8,8 +8,8 @@ edition = "2018"
[dependencies]
anyhow = "1.0"
wgpu = "0.15"
pollster = "0.2"
wgpu = "0.16"
pollster = "0.3"
imgui = "0.7"
imgui-wgpu = "0.17"
imgui-winit-support = "0.7"

View File

@ -7,6 +7,6 @@ edition = "2021"
[dependencies]
anyhow = "1"
wgpu = "0.15"
winit = "0.27"
pollster = "0.2"
wgpu = "0.16"
winit = "0.28"
pollster = "0.3"

View File

@ -13,11 +13,11 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.15"}
winit = "0.27"
wgpu = { version = "0.16"}
winit = "0.28"
instant = "0.1"
[dependencies.image]
@ -28,8 +28,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -234,7 +234,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -271,9 +271,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -621,7 +623,12 @@ impl State {
self.mouse_ray = Ray::with_start_end(mouse_world_pos, self.camera.position.to_vec());
self.selected_mesh = None;
if self.obj_model.bounding_box.intersect(&self.mouse_ray).is_some() {
if self
.obj_model
.bounding_box
.intersect(&self.mouse_ray)
.is_some()
{
let mut t = f32::NEG_INFINITY;
for (i, mesh) in self.obj_model.meshes.iter().enumerate() {
if let Some((_, ti)) = mesh.bounding_box.intersect(&self.mouse_ray) {

View File

@ -2,4 +2,4 @@ use mouse_picking::run;
fn main() {
pollster::block_on(run());
}
}

View File

@ -1,11 +1,7 @@
use cgmath::InnerSpace;
fn vmul(a: cgmath::Vector3<f32>, b: cgmath::Vector3<f32>) -> cgmath::Vector3<f32> {
cgmath::Vector3::new(
a.x * b.x,
a.y * b.y,
a.z * b.z,
)
cgmath::Vector3::new(a.x * b.x, a.y * b.y, a.z * b.z)
}
pub struct BoundingBox {
@ -79,11 +75,7 @@ pub struct Ray {
impl Ray {
pub fn new(dir: cgmath::Vector3<f32>, orig: cgmath::Vector3<f32>) -> Self {
let invdir = 1.0 / dir;
Self {
dir,
orig,
invdir,
}
Self { dir, orig, invdir }
}
pub fn with_start_end(start: cgmath::Vector3<f32>, end: cgmath::Vector3<f32>) -> Self {
@ -97,14 +89,22 @@ mod tests {
use super::*;
fn vec3(x: f32, y: f32, z: f32) -> cgmath::Vector3<f32> {
return cgmath::Vector3 { x, y, z }
return cgmath::Vector3 { x, y, z };
}
#[test]
fn box_ray_intersect() {
let b = BoundingBox {
min: cgmath::Vector3 { x: -1.0, y: -1.0, z: -1.0 },
max: cgmath::Vector3 { x: 1.0, y: 1.0, z: 1.0 },
min: cgmath::Vector3 {
x: -1.0,
y: -1.0,
z: -1.0,
},
max: cgmath::Vector3 {
x: 1.0,
y: 1.0,
z: 1.0,
},
};
let test_data = [
@ -116,4 +116,4 @@ mod tests {
assert_eq!(b.intersect(&r).is_some(), expected);
}
}
}
}

View File

@ -206,7 +206,13 @@ where
) {
for mesh in &model.meshes {
let material = &model.materials[mesh.material];
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
@ -219,7 +225,13 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
self.draw_mesh_instanced(
mesh,
material,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}
@ -297,7 +309,12 @@ where
light_bind_group: &'b wgpu::BindGroup,
) {
for mesh in &model.meshes {
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
self.draw_light_mesh_instanced(
mesh,
instances.clone(),
camera_bind_group,
light_bind_group,
);
}
}
}

View File

@ -106,8 +106,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -10,13 +10,13 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
cfg-if = "1"
env_logger = "0.10"
winit = "0.27"
winit = "0.28"
anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
pollster = "0.2"
wgpu = { version = "0.15", features = ["spirv"]}
wgpu_glyph = "0.18"
pollster = "0.3"
wgpu = { version = "0.16", features = ["spirv"]}
wgpu_glyph = "0.20"
rand = "0.8"
rodio = { version = "0.16", default-features = false, features = ["wav"] }
log = "0.4"
@ -24,17 +24,17 @@ instant = "0.1"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
console_log = "1.0"
getrandom = { version = "0.2", features = ["js"] }
rodio = { version = "0.16", default-features = false, features = ["wasm-bindgen", "wav"] }
wasm-bindgen-futures = "0.4.20"
wasm-bindgen = "=0.2.84"
wasm-bindgen = "=0.2.86"
web-sys = { version = "0.3.53", features = [
"Document",
"Window",
"Element",
]}
wgpu = { version = "0.15", features = ["spirv", "webgl"]}
wgpu = { version = "0.16", features = ["spirv", "webgl"]}
[build-dependencies]
anyhow = "1.0"

View File

@ -1,4 +1,4 @@
use anyhow::{Context, bail, Result};
use anyhow::{bail, Context, Result};
use fs_extra::copy_items;
use fs_extra::dir::CopyOptions;
use glob::glob;
@ -40,12 +40,12 @@ pub fn load_shader(src_path: PathBuf) -> anyhow::Result<()> {
};
let flags = naga::valid::ValidationFlags::all();
let info = naga::valid::Validator::new(
flags,
naga::valid::Capabilities::empty(),
)
.validate(&module)?;
std::fs::write(wgsl_path, wgsl::write_string(&module, &info, wgsl::WriterFlags::all())?)?;
let info =
naga::valid::Validator::new(flags, naga::valid::Capabilities::empty()).validate(&module)?;
std::fs::write(
wgsl_path,
wgsl::write_string(&module, &info, wgsl::WriterFlags::all())?,
)?;
Ok(())
}

View File

@ -8,7 +8,7 @@ mod util;
use input::Input;
use system::System;
#[cfg(target_arch="wasm32")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
use winit::dpi::PhysicalSize;
@ -16,7 +16,7 @@ use winit::event::*;
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Fullscreen, WindowBuilder};
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub fn start() {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
@ -30,7 +30,9 @@ pub fn start() {
let event_loop = EventLoop::new();
let monitor = event_loop.primary_monitor().unwrap();
let video_mode = monitor.video_modes().next();
let size = video_mode.clone().map_or(PhysicalSize::new(800, 600), |vm| vm.size());
let size = video_mode
.clone()
.map_or(PhysicalSize::new(800, 600), |vm| vm.size());
let window = WindowBuilder::new()
.with_visible(false)
.with_title("Pong")
@ -56,8 +58,8 @@ pub fn start() {
// Request fullscreen, if denied, continue as normal
match canvas.request_fullscreen() {
Ok(_) => {},
Err(_) => ()
Ok(_) => {}
Err(_) => (),
}
Some(())
@ -193,11 +195,15 @@ pub fn start() {
}
}
Event::WindowEvent {
event: WindowEvent::Resized(size), ..
event: WindowEvent::Resized(size),
..
} => {
render.resize(size);
events.push(state::Event::Resize(size.width as f32, size.height as f32));
}
Event::RedrawEventsCleared => {
window.request_redraw();
}
Event::RedrawRequested(window_id) if window_id == window.id() => {
for event in &events {
match event {

View File

@ -1,3 +1,3 @@
fn main() {
pong::start();
}
}

View File

@ -107,11 +107,20 @@ pub struct StagingBuffer {
}
impl StagingBuffer {
pub fn new<T: bytemuck::Pod + Sized>(device: &wgpu::Device, data: &[T], is_index_buffer: bool) -> StagingBuffer {
pub fn new<T: bytemuck::Pod + Sized>(
device: &wgpu::Device,
data: &[T],
is_index_buffer: bool,
) -> StagingBuffer {
StagingBuffer {
buffer: device.create_buffer_init(&BufferInitDescriptor {
contents: bytemuck::cast_slice(data),
usage: wgpu::BufferUsages::COPY_SRC | if is_index_buffer { wgpu::BufferUsages::INDEX } else { wgpu::BufferUsages::empty() },
usage: wgpu::BufferUsages::COPY_SRC
| if is_index_buffer {
wgpu::BufferUsages::INDEX
} else {
wgpu::BufferUsages::empty()
},
label: Some("Staging Buffer"),
}),
size: size_of_slice(data) as wgpu::BufferAddress,

View File

@ -44,7 +44,7 @@ impl Render {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -75,9 +75,11 @@ impl Render {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -218,7 +220,6 @@ impl Render {
self.staging_belt.finish();
self.queue.submit(iter::once(encoder.finish()));
frame.present();
}
Err(wgpu::SurfaceError::Outdated) => {
log::info!("Outdated surface texture");

View File

@ -17,8 +17,13 @@ impl SoundSystem {
let sink = rodio::Sink::try_new(&stream_handle).unwrap();
sink.set_volume(0.5);
let spatial_sink =
rodio::SpatialSink::try_new(&stream_handle, [0.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]).unwrap();
let spatial_sink = rodio::SpatialSink::try_new(
&stream_handle,
[0.0, 0.0, 0.0],
[-1.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
)
.unwrap();
Self {
stream,

View File

@ -1,31 +1,19 @@
use anyhow::{Result, Error};
use anyhow::{Error, Result};
struct Snow {
}
struct Snow {}
impl framework::Demo for Snow {
fn init(display: &framework::Display) -> Result<Self, Error> {
Ok(Self {
})
Ok(Self {})
}
fn process_mouse(&mut self, dx: f64, dy: f64) {
}
fn process_mouse(&mut self, dx: f64, dy: f64) {}
fn resize(&mut self, display: &framework::Display) {
}
fn resize(&mut self, display: &framework::Display) {}
fn update(&mut self, display: &framework::Display, dt: std::time::Duration) {
}
fn update(&mut self, display: &framework::Display, dt: std::time::Duration) {}
fn render(&mut self, display: &mut framework::Display) {
}
fn render(&mut self, display: &mut framework::Display) {}
}
fn main() {

View File

@ -13,12 +13,12 @@ anyhow = "1.0"
bytemuck = { version = "1.12", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.10"
pollster = "0.2"
pollster = "0.3"
log = "0.4"
rayon = "1.4" # NEW!
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.15"}
winit = "0.27"
wgpu = { version = "0.16"}
winit = "0.28"
instant = "0.1"
async-std = "1"
@ -30,8 +30,8 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.15", features = ["webgl"]}
console_log = "1.0"
wgpu = { version = "0.16", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

View File

@ -228,7 +228,7 @@ impl State {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
// # Safety
//
// The surface needs to live as long as the window that created it.
@ -265,9 +265,11 @@ impl State {
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
// one will result all the colors comming out darker. If you want to support non
// Srgb surfaces, you'll need to account for that when drawing to the frame.
let surface_format = surface_caps.formats.iter()
let surface_format = surface_caps
.formats
.iter()
.copied()
.find(|f| f.describe().srgb)
.find(|f| f.is_srgb())
.unwrap_or(surface_caps.formats[0]);
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,

View File

@ -2,4 +2,4 @@ use threading::run;
fn main() {
async_std::task::block_on(run());
}
}

View File

@ -106,8 +106,8 @@ impl Texture {
&rgba,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * dimensions.0),
rows_per_image: NonZeroU32::new(dimensions.1),
bytes_per_row: Some(4 * dimensions.0),
rows_per_image: Some(dimensions.1),
},
size,
);

View File

@ -9,8 +9,8 @@ edition = "2018"
[dependencies]
image = "0.24"
shaderc = "0.8"
wgpu = { version = "0.15", features = ["spirv"] }
pollster = "0.2"
wgpu = { version = "0.16", features = ["spirv"] }
pollster = "0.3"
futures-intrusive = "0.4"
[[bin]]

View File

@ -2,9 +2,9 @@ use std::num::NonZeroU32;
async fn run() {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
backends: wgpu::Backends::all(),
dx12_shader_compiler: Default::default(),
});
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(),
@ -169,8 +169,8 @@ async fn run() {
buffer: &output_buffer,
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(u32_size * texture_size),
rows_per_image: NonZeroU32::new(texture_size),
bytes_per_row: Some(u32_size * texture_size),
rows_per_image: Some(texture_size),
},
},
texture_desc.size,
@ -198,10 +198,8 @@ async fn run() {
let buffer =
ImageBuffer::<Rgba<u8>, _>::from_raw(texture_size, texture_size, data).unwrap();
buffer.save("image.png").unwrap();
}
output_buffer.unmap();
}
fn main() {

Some files were not shown because too many files have changed in this diff Show More