res folder now copied to OUT_DIR

pull/68/head
Ben Hansen 4 years ago
parent 1a850cc1b1
commit 8eee289c41

9
Cargo.lock generated

@ -487,6 +487,11 @@ dependencies = [
"winit 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fs_extra"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
@ -1269,6 +1274,7 @@ dependencies = [
"bytemuck 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.23.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2009,7 +2015,7 @@ name = "twox-hash"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2466,6 +2472,7 @@ dependencies = [
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"

@ -21,6 +21,7 @@ features = ["swizzle"]
shaderc = "0.6"
glob = "0.3"
failure = "0.1"
fs_extra = "1.1"
[[bin]]

@ -1,9 +1,29 @@
use glob::glob;
use failure::bail;
use fs_extra::copy_items;
use fs_extra::dir::CopyOptions;
use std::env;
use std::fs::{read_to_string, write};
use std::path::{PathBuf};
fn main() {
copy_res();
compile_shaders();
}
fn copy_res() {
// This tells cargo to rerun this script if something in /res/ changes.
println!("cargo:rerun-if-changed=res/*");
let out_dir = env::var("OUT_DIR").unwrap();
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
let mut paths_to_copy = Vec::new();
paths_to_copy.push("res/");
copy_items(&paths_to_copy, out_dir, &copy_options).unwrap();
}
fn compile_shaders() {
// This tells cargo to rerun this script if something in /src/ changes.
println!("cargo:rerun-if-changed=src/*");

@ -5,6 +5,7 @@ use winit::{
window::Window,
};
use futures::executor::block_on;
use std::path::Path;
use std::time::{Duration, Instant};
mod pipeline;
@ -381,8 +382,12 @@ impl State {
label: None,
});
let (obj_model, cmds) =
model::Model::load(&device, &texture_bind_group_layout, "code/intermediate/tutorial10-lighting/src/res/cube.obj").unwrap();
let res_dir = Path::new(env!("OUT_DIR")).join("res");
let (obj_model, cmds) = model::Model::load(
&device,
&texture_bind_group_layout,
res_dir.join("cube.obj"),
).unwrap();
queue.submit(&cmds);

@ -1,3 +1,4 @@
use failure::bail;
use image::GenericImageView;
use std::path::Path;
@ -17,9 +18,11 @@ impl Texture {
path: P,
is_normal_map: bool,
) -> Result<(Self, wgpu::CommandBuffer), failure::Error> {
// Needed to appease the borrow checker
let path_copy = path.as_ref().to_path_buf();
let label = path_copy.to_str();
// The label currently can only be 64 characters, so we'll need
// to use just the file name for the label.
let label = path_copy.file_name().unwrap().to_str();
let img = image::open(path)?;
Self::from_image(device, &img, label, is_normal_map)
@ -81,14 +84,26 @@ impl Texture {
let rgba = img.to_rgba();
let dimensions = img.dimensions();
if dimensions.0 == 0 || dimensions.1 == 0 {
bail!(
"Image {} has invalid dimensions! {:?}",
label.unwrap_or("UNAMED_IMAGE"),
dimensions
)
}
let size = wgpu::Extent3d {
width: dimensions.0,
height: dimensions.1,
depth: 1,
};
// Ideally this number should be related to the size of
// the image, but let's keep things simple for now.
let mip_level_count = 4;
// Get the number of mip maps from the images width
let mip_level_count = if is_normal_map {
1
} else {
(size.width as f32).log2().round() as u32
};
let texture_desc = wgpu::TextureDescriptor {
label,
size,
@ -102,9 +117,9 @@ impl Texture {
wgpu::TextureFormat::Rgba8UnormSrgb
},
usage: wgpu::TextureUsage::SAMPLED
| wgpu::TextureUsage::COPY_DST
// Needed for to make the mip maps.
| wgpu::TextureUsage::OUTPUT_ATTACHMENT
| wgpu::TextureUsage::COPY_DST,
| wgpu::TextureUsage::OUTPUT_ATTACHMENT,
};
let texture = device.create_texture(&texture_desc);
@ -154,10 +169,10 @@ impl Texture {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
lod_min_clamp: -100.0,
lod_max_clamp: 100.0,
compare: wgpu::CompareFunction::Always,
mipmap_filter: wgpu::FilterMode::Linear,
lod_min_clamp: 0.0,
lod_max_clamp: 1000.0,
compare: wgpu::CompareFunction::LessEqual,
});
Ok((Self { texture, view, sampler }, cmd_buffer))

Loading…
Cancel
Save