Skip to main content

SurfaceWindow

Struct SurfaceWindow 

Source
pub struct SurfaceWindow { /* private fields */ }
Available on crate features winit only.
Expand description

Implementations§

Source§

impl SurfaceWindow

Source

pub fn new( event_loop: &ActiveEventLoop, attributes: WindowAttributes, config_opts: SurfaceConfigOptions, ) -> Result<Self, OsError>

Create a new window under an winit::ActiveEventLoop.

Also requires a winit::window::WindowAttributes (though Default should work fine for most cases) and a SurfaceConfigOptions (Default should be fine here too).

Source

pub fn try_get_config(&self) -> Option<SurfaceConfiguration>

Try to get the wgpu::SurfaceConfiguration, if the surface has been created.

Source

pub fn window(&self) -> &Window

Get a reference to the window.

Source

pub fn init_surface( &self, instance: &Instance, adapter: &Adapter, device: &Device, ) -> Result<ActiveSurfaceWindow<'_>, ConfigSurfaceError>

Opaquely create, configure, and get the wgpu::SurfaceTexture & wgpu::TextureView of the underlying winit::window::Window.

If the window’s wgpu::Surface hasn’t been created yet, it will do so now. If needed it’ll make a new wgpu::SurfaceConfiguration using either the window’s inner size or a manually provided one from the last Self::resize.

Next, it’ll try getting its wgpu::SurfaceTexture with wgpu::Surface::get_current_texture. This may fail if the surface was old and needed to be refreshed, in which case it’ll need to fully recreate the surface. If getting the surface texture fails a 2nd time, the error will be raised to the caller.

Only one ActiveSurfaceWindow is allowed at any one time, this is enforced during runtime.

Source

pub fn init_with_context( &self, context: &RenderContext, ) -> Result<ActiveSurfaceWindow<'_>, ConfigSurfaceError>

Get a usable ActiveSurfaceWindow, which guarantees that the window surface exists & is configured.

See Self::init_surface for more details.

Source

pub fn try_drop_surface(&self) -> Result<(), BorrowMutError>

Try to drop the surface.

Source

pub fn drop_surface(&mut self)

Drop the surface now.

Source

pub fn resize(&self, size: Option<PhysicalSize<u32>>)

Set the target window size and trigger a reconfiguration.

If you pass None, the size will be queried from the window, or you can specify it from a winit resize event. The surface will be reconfigured when it’s next initialized.

Source

pub fn reconfigure(&self)

Mark the surface to be reconfigured when it’s next initialized.

Source

pub fn get_size(&self) -> PhysicalSize<u32>

Convenience function to get the window’s inner size.

Trait Implementations§

Source§

impl Debug for SurfaceWindow

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

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