Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement copyExternalImageToTexture #2781

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions wgpu/Cargo.toml
Expand Up @@ -215,7 +215,9 @@ web-sys = { version = "0.3.60", features = [
"GpuFragmentState",
"GpuFrontFace",
"GpuImageCopyBuffer",
"GpuImageCopyExternalImage",
"GpuImageCopyTexture",
"GpuImageCopyTextureTagged",
"GpuImageDataLayout",
"GpuIndexFormat",
"GpuLoadOp",
Expand Down Expand Up @@ -294,5 +296,12 @@ parking_lot = ">=0.11,<0.13"
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
console_error_panic_hook = "0.1.7"
console_log = "0.2"
# We need the Location feature in the framework examples
web-sys = { version = "0.3.60", features = ["Location"] }
# We need these features in the framework examples
web-sys = { version = "0.3.60", features = [
"Location",
"Blob",
"RequestInit",
"RequestMode",
"Request",
"Response"
] }
14 changes: 13 additions & 1 deletion wgpu/examples/framework.rs
Expand Up @@ -437,17 +437,29 @@ impl Spawner {

#[cfg(not(target_arch = "wasm32"))]
pub fn run<E: Example>(title: &str) {
run_with_setup::<E, _>(title, async {});
}

#[cfg(target_arch = "wasm32")]
pub fn run<E: Example>(title: &str) {
run_with_setup::<E, _>(title, async {});
}

#[cfg(not(target_arch = "wasm32"))]
pub fn run_with_setup<E: Example, F: Future + 'static>(title: &str, setup_block: F) {
let setup = pollster::block_on(setup::<E>(title));
let _example_setup = pollster::block_on(setup_block);
start::<E>(setup);
}

#[cfg(target_arch = "wasm32")]
pub fn run<E: Example>(title: &str) {
pub fn run_with_setup<E: Example, F: Future + 'static>(title: &str, setup_block: F) {
use wasm_bindgen::{prelude::*, JsCast};

let title = title.to_owned();
wasm_bindgen_futures::spawn_local(async move {
let setup = setup::<E>(&title).await;
let _example_setup = setup_block.await;
let start_closure = Closure::once_into_js(move || start::<E>(setup));

// make sure to handle JS exceptions thrown inside start.
Expand Down
13 changes: 13 additions & 0 deletions wgpu/examples/hello-copy-source/README.md
@@ -0,0 +1,13 @@
# hello-copy-source

This example copy image data from `ImageBitmap` to `wgpu::Texture`.

## To Run

```
cargo run-wasm --example hello-copy-source
```

## Screenshots

![Window](./screenshot.png)