Skip to main content

RenderContext

Struct RenderContext 

Source
pub struct RenderContext { /* private fields */ }
Expand description

Owns the wgpu instance, surface, device, and queue for one output window.

surface is None for a headless context (Plan 0013): a device+queue with no swapchain, drawing into offscreen capture textures. The on-surface present path always has Some; config still carries the render size and format for both paths.

Implementations§

Source§

impl RenderContext

Source

pub fn new( target: impl Into<SurfaceTarget<'static>>, width: u32, height: u32, adapter: &AdapterChoice, ) -> Result<Self, RenderError>

Create a context rendering into target (any window-handle provider — the core never sees the windowing library behind it).

Source

pub unsafe fn new_unsafe( target: SurfaceTargetUnsafe, width: u32, height: u32, adapter: &AdapterChoice, ) -> Result<Self, RenderError>

Context from raw display/window handles — the C ABI path, where the host (e.g. the foobar2000 shim) owns the window.

§Safety

The handles must be valid and the window must outlive this context.

Source

pub fn new_headless( width: u32, height: u32, prefer_software: bool, ) -> Result<Self, RenderError>

Build a surface-less context for headless capture (Plan 0013): a device and queue with no swapchain, drawing into offscreen textures. No window, no present, no added dependency. prefer_software forces a fallback adapter (WARP on DX12) so tests rasterize identically on any machine.

The synthesized [wgpu::SurfaceConfiguration] carries only the render size and the offscreen format (HEADLESS_FORMAT); its present-related fields are inert with no surface to configure.

Source

pub fn new_headless_on( width: u32, height: u32, choice: &AdapterChoice, ) -> Result<Self, RenderError>

A headless context on a named adapter (ADR-0146).

The one real constructor of the two; new_headless delegates here. It exists because a live video-out has to render on a GPU the operator can name - on a hybrid machine Windows hands a console process the power-saving one - while every capture path wants exactly the adapter it already asks for.

Source

pub fn resize(&mut self, width: u32, height: u32)

Reconfigure the surface for a new size (a zero dimension is ignored).

Source

pub fn surface_format(&self) -> TextureFormat

The texture format the surface is configured with.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,