migrated tutorial10

pull/90/head
Ben Hansen 4 years ago
parent a92dd32106
commit 03b1b64e55

@ -22,7 +22,7 @@ impl Texture {
let label = path_copy.to_str();
let img = image::open(path)?;
Self::from_image(device, queue, img, label)
Self::from_image(device, queue, &img, label)
}
pub fn create_depth_texture(device: &wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor, label: &str) -> Self {
@ -69,17 +69,17 @@ impl Texture {
label: &str
) -> Result<Self> {
let img = image::load_from_memory(bytes)?;
Self::from_image(device, queue, img, Some(label))
Self::from_image(device, queue, &img, Some(label))
}
pub fn from_image(
device: &wgpu::Device,
queue: &wgpu::Queue,
img: image::DynamicImage,
img: &image::DynamicImage,
label: Option<&str>
) -> Result<Self> {
let dimensions = img.dimensions();
let rgba = img.into_rgba();
let rgba = img.to_rgba();
let size = wgpu::Extent3d {
width: dimensions.0,

@ -64,7 +64,7 @@ With all that in place we need a model to render. If you have one already that's
## Accessing files in the res folder
When cargo builds and runs our program it sets what's known as the current working directory. This directory is usually the folder containing your projects root `Cargo.toml`. The path to our res folder may differ depending on the structure of the project. In the `res` folder for the example code for this section tutorial is at `code/beginner/tutorial9-models/res/`. When loading our model we could use this path, and just append `cube.obj`, but our program will break if we try to run the executable generated by cargo directly. This is because the running executable is in charge of setting the current working directory.
When cargo builds and runs our program it sets what's known as the current working directory. This directory is usually the folder containing your projects root `Cargo.toml`. The path to our res folder may differ depending on the structure of the project. In the `res` folder for the example code for this section tutorial is at `code/beginner/tutorial9-models/res/`. When loading our model we could use this path, and just append `cube.obj`. This is fine, but if we change our projects structure, our code will break.
We're going to fix that by modifying our build script to copy our `res` folder to where cargo creates our executable, and we'll reference it from there. Add the following lines to `build.rs` after you compile the shaders.

@ -418,8 +418,8 @@ where
uniforms: &'b wgpu::BindGroup,
light: &'b wgpu::BindGroup,
) {
self.set_vertex_buffer(0, &mesh.vertex_buffer, 0, 0);
self.set_index_buffer(&mesh.index_buffer, 0, 0);
self.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
self.set_index_buffer(mesh.index_buffer.slice(..));
self.set_bind_group(0, uniforms, &[]);
self.set_bind_group(1, light, &[]);
self.draw_indexed(0..mesh.num_elements, 0, instances);

Loading…
Cancel
Save