pub struct CaptureState {
pub texture: Texture,
/* private fields */
}
Expand description
A texture and a buffer for reading the rendered frame back to the cpu.
The texture is required since wgpu::TextureUsages::COPY_SRC
is not an allowed
flag for the surface texture on all platforms. This means that anytime we want to
capture the frame, we first render it to this texture, and then we can copy it to
both the surface texture (via a render pass) and the buffer (via a texture to buffer copy),
from where we can pull it back
to the cpu.
Fields§
§texture: Texture
Implementations§
Source§impl CaptureState
impl CaptureState
pub fn new(device: &Device, surface_texture: &Texture) -> Self
Sourcepub fn update(&mut self, device: &Device, texture: &Texture)
pub fn update(&mut self, device: &Device, texture: &Texture)
Updates the CaptureState
if the size of the surface texture has changed
Sourcepub fn copy_textures(
&mut self,
device: &Device,
output_frame: &SurfaceTexture,
encoder: &mut CommandEncoder,
) -> Buffer
pub fn copy_textures( &mut self, device: &Device, output_frame: &SurfaceTexture, encoder: &mut CommandEncoder, ) -> Buffer
Handles copying from the CaptureState
texture to the surface texture and the buffer.
Pass the returned buffer to CaptureState::read_screen_rgba
to read the data back to the cpu.
Sourcepub fn read_screen_rgba(
&self,
ctx: Context,
buffer: Buffer,
data: Vec<UserData>,
tx: CaptureSender,
viewport_id: ViewportId,
)
pub fn read_screen_rgba( &self, ctx: Context, buffer: Buffer, data: Vec<UserData>, tx: CaptureSender, viewport_id: ViewportId, )
Handles copying from the CaptureState
texture to the surface texture and the cpu
This function is non-blocking and will send the data to the given sender when it’s ready.
Pass in the buffer returned from CaptureState::copy_textures
.
Make sure to call this after the encoder has been submitted.