mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Get capture mostly working
`File::create` isn't available on wasm, so we can't actually write the output image anywhere unless we target something else as the file system (e.g. local storage)
This commit is contained in:
committed by
Josh Groves
parent
76d5855fdc
commit
a6473b52b9
@@ -96,7 +96,12 @@ async fn run() {
|
||||
// be called in an event loop or on another thread.
|
||||
device.poll(wgpu::Maintain::Wait);
|
||||
|
||||
// Write the buffer as a PNG
|
||||
// If a file system is available, write the buffer as a PNG
|
||||
let has_file_system_available = cfg!(not(target_arch = "wasm32"));
|
||||
if !has_file_system_available {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Ok(mapping) = buffer_future.await {
|
||||
let mut png_encoder = png::Encoder::new(File::create("red.png").unwrap(), size, size);
|
||||
png_encoder.set_depth(png::BitDepth::Eight);
|
||||
@@ -109,8 +114,19 @@ async fn run() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))]
|
||||
pub fn wasm_main() {
|
||||
console_log::init().expect("could not initialize log");
|
||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
wasm_bindgen_futures::spawn_local(run());
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn main() {}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
futures::executor::block_on(run());
|
||||
}
|
||||
|
||||
@@ -431,6 +431,20 @@ pub(crate) fn command_encoder_copy_buffer_to_texture(
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn command_encoder_copy_texture_to_buffer(
|
||||
command_encoder: &CommandEncoderId,
|
||||
source: crate::TextureCopyView,
|
||||
destination: crate::BufferCopyView,
|
||||
copy_size: wgt::Extent3d,
|
||||
) {
|
||||
wgn::wgpu_command_encoder_copy_texture_to_buffer(
|
||||
*command_encoder,
|
||||
&map_texture_copy_view(source),
|
||||
&map_buffer_copy_view(destination),
|
||||
copy_size,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn begin_compute_pass(command_encoder: &CommandEncoderId) -> ComputePassId {
|
||||
unsafe { wgn::wgpu_command_encoder_begin_compute_pass(*command_encoder, None) }
|
||||
}
|
||||
|
||||
@@ -746,6 +746,19 @@ pub(crate) fn command_encoder_copy_buffer_to_texture(
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn command_encoder_copy_texture_to_buffer(
|
||||
command_encoder: &CommandEncoderId,
|
||||
source: crate::TextureCopyView,
|
||||
destination: crate::BufferCopyView,
|
||||
copy_size: wgt::Extent3d,
|
||||
) {
|
||||
command_encoder.copy_texture_to_buffer_with_gpu_extent_3d_dict(
|
||||
&map_texture_copy_view(source),
|
||||
&map_buffer_copy_view(destination),
|
||||
&map_extent_3d(copy_size),
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn begin_compute_pass(command_encoder: &CommandEncoderId) -> ComputePassId {
|
||||
let mapped_desc = web_sys::GpuComputePassDescriptor::new();
|
||||
command_encoder.begin_compute_pass_with_descriptor(&mapped_desc)
|
||||
|
||||
@@ -923,7 +923,6 @@ impl CommandEncoder {
|
||||
backend::command_encoder_copy_buffer_to_texture(&self.id, source, destination, copy_size);
|
||||
}
|
||||
|
||||
/*
|
||||
/// Copy data from a texture to a buffer.
|
||||
pub fn copy_texture_to_buffer(
|
||||
&mut self,
|
||||
@@ -931,14 +930,10 @@ impl CommandEncoder {
|
||||
destination: BufferCopyView,
|
||||
copy_size: Extent3d,
|
||||
) {
|
||||
wgn::wgpu_command_encoder_copy_texture_to_buffer(
|
||||
self.id,
|
||||
&source.into_native(),
|
||||
&destination.into_native(),
|
||||
copy_size,
|
||||
);
|
||||
backend::command_encoder_copy_texture_to_buffer(&self.id, source, destination, copy_size);
|
||||
}
|
||||
|
||||
/*
|
||||
/// Copy data from one texture to another.
|
||||
pub fn copy_texture_to_texture(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user