pub struct Frame<'swap_chain> { /* private fields */ }
Expand description
A Frame to which the user can draw graphics before it is presented to the display.
Frames are delivered to the user for drawing via the user’s view function.
See the RawFrame docs for more details on how the implementation works under the hood. The Frame type differs in that rather than drawing directly to the swapchain image the user may draw to an intermediary linear sRGBA image. There are several advantages of drawing to an intermediary image.
Implementations§
source§impl<'swap_chain> Frame<'swap_chain>
impl<'swap_chain> Frame<'swap_chain>
sourcepub const DEFAULT_MSAA_SAMPLES: u32 = 4u32
pub const DEFAULT_MSAA_SAMPLES: u32 = 4u32
The default number of multisample anti-aliasing samples used if the window with which the
Frame
is associated supports it.
sourcepub const TEXTURE_FORMAT: TextureFormat = wgpu::RenderPipelineBuilder::DEFAULT_COLOR_FORMAT
pub const TEXTURE_FORMAT: TextureFormat = wgpu::RenderPipelineBuilder::DEFAULT_COLOR_FORMAT
The texture format used by the intermediary linear sRGBA image.
We use a high bit depth format in order to retain as much information as possible when converting from the linear representation to the swapchain format (normally a non-linear representation).
sourcepub fn texture(&self) -> &Texture
pub fn texture(&self) -> &Texture
The texture to which all graphics should be drawn this frame.
This is not the swapchain texture, but rather an intermediary linear sRGBA image. This intermediary image is used in order to:
- Ensure consistent MSAA resolve behaviour across platforms.
- Avoid the need for multiple implicit conversions to and from linear sRGBA for each graphics pipeline render pass that is used.
- Allow for the user’s rendered image to persist between frames.
The exact format of the texture is equal to Frame::TEXTURE_FORMAT
.
If the number of MSAA samples specified is greater than 1
(which it is by default if
supported by the platform), this will be a multisampled texture. After the view
function returns, this texture will be resolved to a non-multisampled linear sRGBA texture.
After the texture has been resolved if necessary, it will then be used as a shader input
within a graphics pipeline used to draw the swapchain texture.
sourcepub fn texture_view(&self) -> &TextureView
pub fn texture_view(&self) -> &TextureView
A full view into the frame’s texture.
See texture
for details.
sourcepub fn resolve_target(&self) -> Option<&TextureView>
pub fn resolve_target(&self) -> Option<&TextureView>
Returns the resolve target texture in the case that MSAA is enabled.
sourcepub fn texture_format(&self) -> TextureFormat
pub fn texture_format(&self) -> TextureFormat
The color format of the Frame
’s intermediary linear sRGBA texture (equal to
Frame::TEXTURE_FORMAT
).
sourcepub fn texture_msaa_samples(&self) -> u32
pub fn texture_msaa_samples(&self) -> u32
The number of MSAA samples of the Frame
’s intermediary linear sRGBA texture.
sourcepub fn texture_size(&self) -> [u32; 2]
pub fn texture_size(&self) -> [u32; 2]
The size of the frame’s texture in pixels.
sourcepub fn color_attachment_descriptor(&self) -> RenderPassColorAttachment<'_>
pub fn color_attachment_descriptor(&self) -> RenderPassColorAttachment<'_>
Short-hand for constructing a wgpu::RenderPassColorAttachment
for use within a
render pass that targets this frame’s texture. The returned descriptor’s attachment
will
the same wgpu::TextureView
returned by the Frame::texture
method.
Note that this method will not perform any resolving. In the case that msaa_samples
is
greater than 1
, a render pass will be automatically added after the view
completes and
before the texture is drawn to the swapchain.
sourcepub fn clear<C>(&self, color: C)where
C: IntoLinSrgba<f32>,
pub fn clear<C>(&self, color: C)where
C: IntoLinSrgba<f32>,
Clear the texture with the given color.
sourcepub fn submit(self)
pub fn submit(self)
Submit the frame to the GPU!
Note that you do not need to call this manually as submission will occur automatically when the Frame is dropped.
Before submission, the frame does the following:
- If the frame’s intermediary linear sRGBA texture is multisampled, resolve it.
- Write the intermediary linear sRGBA image to the swap chain texture.
It can sometimes be useful to submit the Frame before view
completes in order to read
the frame’s texture back to the CPU (e.g. for screen shots, recordings, etc).
Methods from Deref<Target = RawFrame<'swap_chain>>§
sourcepub fn command_encoder(&self) -> RefMut<'_, CommandEncoder>
pub fn command_encoder(&self) -> RefMut<'_, CommandEncoder>
Access the command encoder in order to encode commands that will be submitted to the swap chain queue at the end of the call to view.
sourcepub fn window_id(&self) -> Id
pub fn window_id(&self) -> Id
The Id
of the window whose wgpu surface is associated with this frame.
sourcepub fn rect(&self) -> Rect
pub fn rect(&self) -> Rect
A Rect representing the full surface of the frame.
The returned Rect is equivalent to the result of calling Window::rect on the window associated with this Frame.
sourcepub fn nth(&self) -> u64
pub fn nth(&self) -> u64
The nth
frame for the associated window since the application started.
E.g. the first frame yielded will return 0
, the second will return 1
, and so on.
sourcepub fn swap_chain_texture(&self) -> &TextureViewHandle
pub fn swap_chain_texture(&self) -> &TextureViewHandle
The swap chain texture that will be the target for drawing this frame.
sourcepub fn texture_format(&self) -> TextureFormat
pub fn texture_format(&self) -> TextureFormat
The texture format of the frame’s swap chain texture.
sourcepub fn device_queue_pair(&self) -> &Arc<DeviceQueuePair>
pub fn device_queue_pair(&self) -> &Arc<DeviceQueuePair>
The device and queue on which the swap chain was created and which will be used to submit the RawFrame’s encoded commands.
This refers to the same DeviceQueuePair as held by the window associated with this frame.
sourcepub fn clear(&self, texture_view: &TextureView, color: Color)
pub fn clear(&self, texture_view: &TextureView, color: Color)
Clear the texture with the given color.
Trait Implementations§
Auto Trait Implementations§
impl<'swap_chain> !RefUnwindSafe for Frame<'swap_chain>
impl<'swap_chain> Send for Frame<'swap_chain>
impl<'swap_chain> !Sync for Frame<'swap_chain>
impl<'swap_chain> Unpin for Frame<'swap_chain>
impl<'swap_chain> !UnwindSafe for Frame<'swap_chain>
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
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, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
source§fn convert_into(self) -> U
fn convert_into(self) -> U
source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains the unclamped color. Read more