demos working

master
Benjamin Hansen 2 weeks ago
parent 5eacaf4e9c
commit 3d27fca202

3
Cargo.lock generated

@ -1671,6 +1671,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]

@ -38,6 +38,7 @@ web-sys = { version = "0.3", features = [
"Element",
"Location",
]}
instant = { version = "0.1", features = [ "wasm-bindgen" ] }
[build-dependencies]
anyhow = "1.0"

@ -37,6 +37,7 @@ web-sys = { version = "0.3", features = [
"Element",
"Location",
]}
instant = { version = "0.1", features = [ "wasm-bindgen" ] }
[build-dependencies]
anyhow = "1.0"

@ -284,17 +284,32 @@ impl HdrLoader {
dst_size: u32,
label: Option<&str>,
) -> anyhow::Result<texture::CubeTexture> {
log::info!("creating decoder");
let hdr_decoder = HdrDecoder::new(Cursor::new(data))?;
let meta = hdr_decoder.metadata();
let mut pixels = vec![[0.0, 0.0, 0.0, 0.0]; meta.width as usize * meta.height as usize];
hdr_decoder.read_image_transform(
|pix| {
log::info!("reading image");
#[cfg(not(target_arch="wasm32"))]
let pixels = {
let mut pixels = vec![[0.0, 0.0, 0.0, 0.0]; meta.width as usize * meta.height as usize];
hdr_decoder.read_image_transform(
|pix| {
let rgb = pix.to_hdr();
[rgb.0[0], rgb.0[1], rgb.0[2], 1.0f32]
},
&mut pixels[..],
)?;
pixels
};
#[cfg(target_arch="wasm32")]
let pixels = hdr_decoder.read_image_native()?
.into_iter()
.map(|pix| {
let rgb = pix.to_hdr();
[rgb.0[0], rgb.0[1], rgb.0[2], 1.0f32]
},
&mut pixels[..],
)?;
})
.collect::<Vec<_>>();
log::info!("creating texture");
let src = texture::Texture::create_2d_texture(
device,
meta.width,
@ -305,6 +320,7 @@ impl HdrLoader {
None,
);
log::info!("writing texture");
queue.write_texture(
wgpu::ImageCopyTexture {
texture: &src.texture,

@ -27,7 +27,12 @@ const SAFE_FRAC_PI_2: f32 = FRAC_PI_2 - 0.0001;
`std::time::Instant` panics on WASM, so we'll use the [instant crate](https://docs.rs/instant). You'll want to include it in your `Cargo.toml`:
```toml
[dependencies]
# ...
instant = "0.1"
[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { version = "0.1", features = [ "wasm-bindgen" ] }
```
</div>

Loading…
Cancel
Save