pub struct Surface<'window> { /* private fields */ }
Expand description
Handle to a presentable surface.
A Surface
represents a platform-specific surface (e.g. a window) onto which rendered images may
be presented. A Surface
may be created with the function Instance::create_surface
.
This type is unique to the Rust API of wgpu
. In the WebGPU specification,
GPUCanvasContext
serves a similar role.
Implementations§
source§impl Surface<'_>
impl Surface<'_>
sourcepub fn get_capabilities(&self, adapter: &Adapter) -> SurfaceCapabilities
pub fn get_capabilities(&self, adapter: &Adapter) -> SurfaceCapabilities
Returns the capabilities of the surface when used with the given adapter.
Returns specified values (see SurfaceCapabilities
) if surface is incompatible with the adapter.
sourcepub fn get_default_config(
&self,
adapter: &Adapter,
width: u32,
height: u32
) -> Option<SurfaceConfiguration>
pub fn get_default_config( &self, adapter: &Adapter, width: u32, height: u32 ) -> Option<SurfaceConfiguration>
Return a default SurfaceConfiguration
from width and height to use for the Surface
with this adapter.
Returns None if the surface isn’t supported by this adapter
sourcepub fn configure(&self, device: &Device, config: &SurfaceConfiguration)
pub fn configure(&self, device: &Device, config: &SurfaceConfiguration)
Initializes Surface
for presentation.
Panics
- A old
SurfaceTexture
is still alive referencing an old surface. - Texture format requested is unsupported on the surface.
config.width
orconfig.height
is zero.
sourcepub fn get_current_texture(&self) -> Result<SurfaceTexture, SurfaceError>
pub fn get_current_texture(&self) -> Result<SurfaceTexture, SurfaceError>
Returns the next texture to be presented by the swapchain for drawing.
In order to present the SurfaceTexture
returned by this method,
first a Queue::submit
needs to be done with some work rendering to this texture.
Then SurfaceTexture::present
needs to be called.
If a SurfaceTexture referencing this surface is alive when the swapchain is recreated, recreating the swapchain will panic.
sourcepub unsafe fn as_hal<A: HalApi, F: FnOnce(Option<&A::Surface>) -> R, R>(
&self,
hal_surface_callback: F
) -> R
Available on wgpu_core
only.
pub unsafe fn as_hal<A: HalApi, F: FnOnce(Option<&A::Surface>) -> R, R>( &self, hal_surface_callback: F ) -> R
wgpu_core
only.Returns the inner hal Surface using a callback. The hal surface will be None
if the
backend type argument does not match with this wgpu Surface
Safety
- The raw handle obtained from the hal Surface must not be manually destroyed
Trait Implementations§
source§impl Ord for Surface<'_>
impl Ord for Surface<'_>
source§impl PartialEq for Surface<'_>
impl PartialEq for Surface<'_>
source§impl PartialOrd for Surface<'_>
impl PartialOrd for Surface<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Surface<'_>
Auto Trait Implementations§
impl<'window> !RefUnwindSafe for Surface<'window>
impl<'window> Send for Surface<'window>
impl<'window> Sync for Surface<'window>
impl<'window> Unpin for Surface<'window>
impl<'window> !UnwindSafe for Surface<'window>
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
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.