#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum WuiCaptureFormat {
Rgba8Unorm = 0,
Rgba16Float = 1,
}
#[must_use]
pub fn capture_buffer_format(format: wgpu::TextureFormat) -> WuiCaptureFormat {
match format {
wgpu::TextureFormat::Rgba8Unorm | wgpu::TextureFormat::Rgba8UnormSrgb => {
WuiCaptureFormat::Rgba8Unorm
}
wgpu::TextureFormat::Rgba16Float => WuiCaptureFormat::Rgba16Float,
other => panic!(
"Android view capture cannot fill a {other:?} texture: no AHardwareBuffer layout \
matches it"
),
}
}
#[must_use]
pub const fn effect_input_texture_format(format: WuiCaptureFormat) -> wgpu::TextureFormat {
match format {
WuiCaptureFormat::Rgba8Unorm => wgpu::TextureFormat::Rgba8UnormSrgb,
WuiCaptureFormat::Rgba16Float => wgpu::TextureFormat::Rgba16Float,
}
}
#[must_use]
pub fn create_effect_input_texture(
device: &wgpu::Device,
queue: &wgpu::Queue,
format: wgpu::TextureFormat,
width: u32,
height: u32,
) -> wgpu::Texture {
let texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("ViewEffect Capture Texture"),
size: wgpu::Extent3d {
width,
height,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("ViewEffect Capture Texture Init"),
});
drop(encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("ViewEffect Capture Texture Init"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
depth_slice: None,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
multiview_mask: None,
}));
queue.submit([encoder.finish()]);
texture
}