pub struct CaptureState {
padding: BufferPadding,
pub texture: Texture,
pipeline: RenderPipeline,
bind_group: BindGroup,
}
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§
§padding: BufferPadding
§texture: Texture
§pipeline: RenderPipeline
§bind_group: BindGroup
Implementations§
§impl CaptureState
impl CaptureState
pub fn new(device: &Device, surface_texture: &Texture) -> CaptureState
pub 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
pub 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.
pub fn read_screen_rgba(
&self,
ctx: Context,
buffer: Buffer,
data: Vec<UserData>,
tx: Sender<(ViewportId, Vec<UserData>, ColorImage)>,
viewport_id: ViewportId,
)
pub fn read_screen_rgba( &self, ctx: Context, buffer: Buffer, data: Vec<UserData>, tx: Sender<(ViewportId, Vec<UserData>, ColorImage)>, 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.
Auto Trait Implementations§
impl Freeze for CaptureState
impl !RefUnwindSafe for CaptureState
impl Send for CaptureState
impl Sync for CaptureState
impl Unpin for CaptureState
impl !UnwindSafe for CaptureState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request