pub struct SurfaceContext {
pub device: Device,
pub queue: Queue,
pub surface: Surface<'static>,
pub surface_format: TextureFormat,
/* private fields */
}Expand description
A windowed GPU context: device, queue, surface, and swap-chain config.
Unlike crate::GpuContext (headless), SurfaceContext presents frames
to an OS window via a wgpu swap-chain.
Fields§
§device: DeviceThe logical GPU device.
queue: QueueThe command queue for the device.
surface: Surface<'static>The wgpu surface attached to the OS window.
surface_format: TextureFormatThe texture format selected for the swap-chain.
Implementations§
Source§impl SurfaceContext
impl SurfaceContext
Sourcepub unsafe fn from_raw_handles(
window_handle: RawWindowHandle,
display_handle: RawDisplayHandle,
config: SurfaceConfig,
) -> Result<Self, UiError>
pub unsafe fn from_raw_handles( window_handle: RawWindowHandle, display_handle: RawDisplayHandle, config: SurfaceConfig, ) -> Result<Self, UiError>
Create a windowed surface context from raw OS window/display handles.
§Safety
The caller must ensure that both window_handle and display_handle
refer to valid OS objects and remain valid for the entire lifetime
of the returned SurfaceContext. Dropping the underlying window while
a SurfaceContext is live is undefined behaviour.
Sourcepub fn resize(&mut self, width: u32, height: u32)
pub fn resize(&mut self, width: u32, height: u32)
Resize the swap-chain to new dimensions.
Dimensions are clamped to a minimum of 1×1 to avoid a wgpu validation error.
Sourcepub fn acquire_frame(&self) -> Option<SurfaceTexture>
pub fn acquire_frame(&self) -> Option<SurfaceTexture>
Acquire the next swap-chain frame.
Returns None on surface timeout, occlusion, or any other transient
condition — the caller should skip the frame and try again next tick.
Permanent errors (surface lost / outdated) are logged to stderr; the
caller can recreate the SurfaceContext if needed.
Sourcepub fn present_frame(&self, frame: SurfaceTexture)
pub fn present_frame(&self, frame: SurfaceTexture)
Present a previously acquired frame to the display.
Sourcepub fn format(&self) -> TextureFormat
pub fn format(&self) -> TextureFormat
The texture format used by the swap-chain.
Auto Trait Implementations§
impl !Freeze for SurfaceContext
impl !RefUnwindSafe for SurfaceContext
impl !UnwindSafe for SurfaceContext
impl Send for SurfaceContext
impl Sync for SurfaceContext
impl Unpin for SurfaceContext
impl UnsafeUnpin for SurfaceContext
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more