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
impl RenderContext
Sourcepub fn new(
target: impl Into<SurfaceTarget<'static>>,
width: u32,
height: u32,
adapter: &AdapterChoice,
) -> Result<Self, RenderError>
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).
Sourcepub unsafe fn new_unsafe(
target: SurfaceTargetUnsafe,
width: u32,
height: u32,
adapter: &AdapterChoice,
) -> Result<Self, RenderError>
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.
Sourcepub fn new_headless(
width: u32,
height: u32,
prefer_software: bool,
) -> Result<Self, RenderError>
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.
Sourcepub fn new_headless_on(
width: u32,
height: u32,
choice: &AdapterChoice,
) -> Result<Self, RenderError>
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.
Sourcepub fn resize(&mut self, width: u32, height: u32)
pub fn resize(&mut self, width: u32, height: u32)
Reconfigure the surface for a new size (a zero dimension is ignored).
Sourcepub fn surface_format(&self) -> TextureFormat
pub fn surface_format(&self) -> TextureFormat
The texture format the surface is configured with.