From 67635a5fad8b69e74b4c6be17c54def7108dddc3 Mon Sep 17 00:00:00 2001 From: Renato Caldas Date: Fri, 15 Jan 2021 18:23:49 +0000 Subject: [PATCH 1/3] Fix typos in beginner tutorial 4 --- docs/beginner/tutorial4-buffer/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/beginner/tutorial4-buffer/README.md b/docs/beginner/tutorial4-buffer/README.md index b372f89e..4f5eafd1 100644 --- a/docs/beginner/tutorial4-buffer/README.md +++ b/docs/beginner/tutorial4-buffer/README.md @@ -89,7 +89,7 @@ struct Vertex {
-If you're struct includes types that don't implement `Pod` and `Zeroable`, you'll need to implement these traits manually. These traits don't require us to implement any methods, so we just need to use the following to get our code to work. +If your struct includes types that don't implement `Pod` and `Zeroable`, you'll need to implement these traits manually. These traits don't require us to implement any methods, so we just need to use the following to get our code to work. ```rust unsafe impl bytemuck::Pod for Vertex {} @@ -138,8 +138,8 @@ wgpu::VertexBufferDescriptor { ``` 1. The `stride` defines how wide a vertex is. When the shader goes to read the next vertex, it will skip over `stride` number of bytes. In our case, stride will probably be 24 bytes. -2. `step_mode` tells the pipeline how often it should move to the next vertex. This seems redundant in our case, but we can specify `wgpu::InputStepMode::Instance` if we only want the change vertices when we start drawing a new instance. We'll cover instancing in a later tutorial. -3. Vertex attributes describe the individual parts of the vertex. Generally this is a 1:1 mapping with a structs fields which it is in our case. +2. `step_mode` tells the pipeline how often it should move to the next vertex. This seems redundant in our case, but we can specify `wgpu::InputStepMode::Instance` if we only want to change vertices when we start drawing a new instance. We'll cover instancing in a later tutorial. +3. Vertex attributes describe the individual parts of the vertex. Generally this is a 1:1 mapping with a struct's fields, which it is in our case. 4. This defines the `offset` in bytes that this attribute starts. The first attribute is usually zero, and any future attributes are the collective `size_of` the previous attributes data. 5. This tells the shader what location to store this attribute at. For example `layout(location=0) in vec3 x` in the vertex shader would correspond to the position field of the struct, while `layout(location=1) in vec3 x` would be the color field. 6. `format` tells the shader the shape of the attribute. `Float3` corresponds to `vec3` in shader code. The max value we can store in an attribute is `Float4` (`Uint4`, and `Int4` work as well). We'll keep this in mind for when we have to store things that are bigger than `Float4`. @@ -176,7 +176,7 @@ impl Vertex {
-Specifying the attributes as we are now is quite verbose. We could use the `vertex_attr_array` macro provided by wgpu to clean things up a bit. With it our `VertexBufferDescriptor` becomes +Specifying the attributes as we did now is quite verbose. We could use the `vertex_attr_array` macro provided by wgpu to clean things up a bit. With it our `VertexBufferDescriptor` becomes ```rust wgpu::VertexBufferDescriptor { From e61b939889f013f6f064326c63fc99193f119e80 Mon Sep 17 00:00:00 2001 From: Renato Caldas Date: Fri, 15 Jan 2021 19:12:44 +0000 Subject: [PATCH 2/3] Remove stray field 'colour' from State --- docs/beginner/tutorial5-textures/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/beginner/tutorial5-textures/README.md b/docs/beginner/tutorial5-textures/README.md index 4fe48c42..6535f867 100644 --- a/docs/beginner/tutorial5-textures/README.md +++ b/docs/beginner/tutorial5-textures/README.md @@ -225,7 +225,6 @@ struct State { sc_desc: wgpu::SwapChainDescriptor, swap_chain: wgpu::SwapChain, size: winit::dpi::PhysicalSize, - colour: wgpu::Color, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, From d44f216b14c3316f18f723f003a0c1d9b66a4998 Mon Sep 17 00:00:00 2001 From: Renato Caldas Date: Fri, 15 Jan 2021 19:19:43 +0000 Subject: [PATCH 3/3] Fix inconsistent position of the 'size' field in the beginner tutorials --- code/beginner/tutorial4-buffer/src/main.rs | 4 ++-- code/beginner/tutorial5-textures/src/main.rs | 4 ++-- code/beginner/tutorial6-uniforms/src/main.rs | 4 ++-- code/beginner/tutorial7-instancing/src/main.rs | 2 +- code/beginner/tutorial8-depth/src/main.rs | 2 +- code/beginner/tutorial9-models/src/main.rs | 4 ++-- docs/beginner/tutorial3-pipeline/README.md | 2 +- docs/beginner/tutorial4-buffer/README.md | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/code/beginner/tutorial4-buffer/src/main.rs b/code/beginner/tutorial4-buffer/src/main.rs index 34144f5b..ff8e0ae9 100644 --- a/code/beginner/tutorial4-buffer/src/main.rs +++ b/code/beginner/tutorial4-buffer/src/main.rs @@ -66,8 +66,8 @@ struct State { queue: wgpu::Queue, sc_desc: wgpu::SwapChainDescriptor, swap_chain: wgpu::SwapChain, - render_pipeline: wgpu::RenderPipeline, size: winit::dpi::PhysicalSize, + render_pipeline: wgpu::RenderPipeline, // NEW! vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, @@ -175,11 +175,11 @@ impl State { queue, sc_desc, swap_chain, + size, render_pipeline, vertex_buffer, index_buffer, num_indices, - size, } } diff --git a/code/beginner/tutorial5-textures/src/main.rs b/code/beginner/tutorial5-textures/src/main.rs index d7416e67..83eef00b 100644 --- a/code/beginner/tutorial5-textures/src/main.rs +++ b/code/beginner/tutorial5-textures/src/main.rs @@ -69,8 +69,8 @@ struct State { queue: wgpu::Queue, sc_desc: wgpu::SwapChainDescriptor, swap_chain: wgpu::SwapChain, - render_pipeline: wgpu::RenderPipeline, size: winit::dpi::PhysicalSize, + render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, num_indices: u32, @@ -222,13 +222,13 @@ impl State { queue, sc_desc, swap_chain, + size, render_pipeline, vertex_buffer, index_buffer, num_indices, diffuse_texture, diffuse_bind_group, - size, } } diff --git a/code/beginner/tutorial6-uniforms/src/main.rs b/code/beginner/tutorial6-uniforms/src/main.rs index 6139721e..fec489c8 100644 --- a/code/beginner/tutorial6-uniforms/src/main.rs +++ b/code/beginner/tutorial6-uniforms/src/main.rs @@ -214,8 +214,8 @@ struct State { queue: wgpu::Queue, sc_desc: wgpu::SwapChainDescriptor, swap_chain: wgpu::SwapChain, - render_pipeline: wgpu::RenderPipeline, size: winit::dpi::PhysicalSize, + render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, num_indices: u32, @@ -415,6 +415,7 @@ impl State { queue, sc_desc, swap_chain, + size, render_pipeline, vertex_buffer, index_buffer, @@ -426,7 +427,6 @@ impl State { uniform_buffer, uniform_bind_group, uniforms, - size, } } diff --git a/code/beginner/tutorial7-instancing/src/main.rs b/code/beginner/tutorial7-instancing/src/main.rs index 4e2cb5d1..857cc8a5 100644 --- a/code/beginner/tutorial7-instancing/src/main.rs +++ b/code/beginner/tutorial7-instancing/src/main.rs @@ -512,6 +512,7 @@ impl State { queue, sc_desc, swap_chain, + size, render_pipeline, vertex_buffer, index_buffer, @@ -523,7 +524,6 @@ impl State { uniform_buffer, uniform_bind_group, uniforms, - size, // NEW! instances, instance_buffer, diff --git a/code/beginner/tutorial8-depth/src/main.rs b/code/beginner/tutorial8-depth/src/main.rs index 88bd14bf..2395003c 100644 --- a/code/beginner/tutorial8-depth/src/main.rs +++ b/code/beginner/tutorial8-depth/src/main.rs @@ -529,6 +529,7 @@ impl State { queue, sc_desc, swap_chain, + size, render_pipeline, vertex_buffer, index_buffer, @@ -540,7 +541,6 @@ impl State { uniform_buffer, uniform_bind_group, uniforms, - size, instances, instance_buffer, depth_texture, diff --git a/code/beginner/tutorial9-models/src/main.rs b/code/beginner/tutorial9-models/src/main.rs index 267f018f..d01bf6f2 100644 --- a/code/beginner/tutorial9-models/src/main.rs +++ b/code/beginner/tutorial9-models/src/main.rs @@ -225,6 +225,7 @@ struct State { queue: wgpu::Queue, sc_desc: wgpu::SwapChainDescriptor, swap_chain: wgpu::SwapChain, + size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, obj_model: model::Model, camera: Camera, @@ -236,7 +237,6 @@ struct State { #[allow(dead_code)] instance_buffer: wgpu::Buffer, depth_texture: texture::Texture, - size: winit::dpi::PhysicalSize, } impl State { @@ -444,6 +444,7 @@ impl State { queue, sc_desc, swap_chain, + size, render_pipeline, obj_model, camera, @@ -454,7 +455,6 @@ impl State { instances, instance_buffer, depth_texture, - size, } } diff --git a/docs/beginner/tutorial3-pipeline/README.md b/docs/beginner/tutorial3-pipeline/README.md index d1cf9802..c76fab18 100644 --- a/docs/beginner/tutorial3-pipeline/README.md +++ b/docs/beginner/tutorial3-pipeline/README.md @@ -209,9 +209,9 @@ Self { surface, device, queue, - size, sc_desc, swap_chain, + size, // NEW! render_pipeline, } diff --git a/docs/beginner/tutorial4-buffer/README.md b/docs/beginner/tutorial4-buffer/README.md index 4f5eafd1..0ec349fb 100644 --- a/docs/beginner/tutorial4-buffer/README.md +++ b/docs/beginner/tutorial4-buffer/README.md @@ -107,9 +107,9 @@ Self { queue, sc_desc, swap_chain, + size, render_pipeline, vertex_buffer, - size, } ``` @@ -388,8 +388,8 @@ Self { queue, sc_desc, swap_chain, - render_pipeline, size, + render_pipeline, vertex_buffer, // NEW! index_buffer,