Skip to main content

WgpuRenderer

Struct WgpuRenderer 

Source
pub struct WgpuRenderer { /* private fields */ }

Implementations§

Source§

impl WgpuRenderer

Source

pub fn new<W>( gpu_context: GpuContext, window: &W, config: WgpuSurfaceConfig, compositor_gpu: Option<CompositorGpuHint>, ) -> Result<Self>
where W: HasWindowHandle + HasDisplayHandle + Debug + Send + Sync + Clone + 'static,

从原始窗口句柄创建新的 WgpuRenderer。

gpu_context 是一个共享引用,用于在多个窗口之间协调 GPU 上下文。 第一个创建渲染器的窗口将初始化上下文;后续窗口将共享它。

§安全性

调用者必须确保窗口句柄在返回的渲染器的生命周期内保持有效。

Source

pub fn update_drawable_size(&mut self, size: Size<DevicePixels>)

Source

pub fn set_subpixel_layout(&mut self, is_bgr: bool)

Source

pub fn update_transparency(&mut self, transparent: bool)

Source

pub fn viewport_size(&self) -> Size<DevicePixels>

Source

pub fn sprite_atlas(&self) -> &Arc<WgpuAtlas>

Source

pub fn supports_dual_source_blending(&self) -> bool

Source

pub fn gpu_specs(&self) -> GpuSpecs

Source

pub fn max_texture_size(&self) -> u32

Source

pub fn draw(&mut self, scene: &Scene) -> bool

Source

pub fn unconfigure_surface(&mut self)

将表面标记为未配置,以便在通过 replace_surface 提供新表面之前跳过渲染。

不会丢弃渲染器 —— 设备、队列、图集和 管线保持活动状态。当原生窗口被销毁时使用此方法 (例如 Android TerminateWindow),但你打算稍后重新创建 表面而不丢失缓存的图集纹理。

Source

pub fn replace_surface<W: HasWindowHandle>( &mut self, window: &W, config: WgpuSurfaceConfig, instance: &Instance, ) -> Result<()>

用新表面替换 wgpu 表面(例如在 Android 销毁并 重新创建原生窗口之后)。保持设备、队列、图集和 所有管线完好无损,以便缓存的 AtlasTextureId 保持有效。

instance 必须 是用于创建适配器和设备的 同一个 wgpu::Instance(即来自 WgpuContext)。使用 不同的实例将导致 “Device does not exist” panic,因为 wgpu 设备绑定到其原始实例。

Source

pub fn destroy(&mut self)

Source

pub fn device_lost(&self) -> bool

返回 GPU 设备是否丢失以及是否需要恢复。

Source

pub fn needs_redraw(&mut self) -> bool

返回是否需要重绘,因为 GPU 状态已被清除。 调用此方法将清除标志。

Source

pub fn recover<W>(&mut self, window: &W) -> Result<()>
where W: HasWindowHandle + HasDisplayHandle + Debug + Send + Sync + Clone + 'static,

从丢失的 GPU 设备恢复,通过使用新上下文重新创建渲染器。

在检测到 device_lost() 返回 true 后调用此方法。

此方法协调多个窗口之间的恢复:

  • 第一个调用此方法的窗口将重新创建共享上下文
  • 后续窗口将采用已恢复的上下文

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

Source§

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

Source§

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