Skip to main content

NativeHost

Struct NativeHost 

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

A window-owning wgpu host and the players drawing into it.

Implementations§

Source§

impl NativeHost

Source

pub unsafe fn new( target: SurfaceTargetUnsafe, config: &NativeHostConfig, ) -> Result<Self, String>

Build the wgpu stack for target and a player matched to its surface.

§Safety

target must describe a live window, view or layer that outlives the returned host. On macOS this must be called from the main thread.

Source

pub fn create_player(&mut self) -> PlayerId

Add a player to this window and return its id.

Players are cheap — no GPU resource of their own — so a window holding a dozen characters costs one device, one renderer and one scene.

Source

pub fn destroy_player(&mut self, id: PlayerId) -> bool

Remove a player. Returns whether id named a live one; a stale id is a no-op rather than a mistake made silently.

Source

pub fn player_mut(&mut self, id: PlayerId) -> Option<&mut SSPlayer>

The player id names, or None if it has been destroyed.

Source

pub fn player_count(&self) -> usize

How many players this window currently holds.

Source

pub fn stats(&self) -> SceneStats

What the last frame cost.

Source

pub fn texture_extent_error(&self, width: u32, height: u32) -> Option<String>

Why this window’s device cannot hold a width x height texture, or None when it can: empty, or past its max_texture_dimension_2d.

What the C face asks before it hands a host’s pixels over, so a texture too large for the device comes back as an error code instead of one NativeHost::upload_texture can only report on stderr.

Source

pub fn upload_texture( &mut self, hash: u32, rgba: &[u8], width: u32, height: u32, )

Register a texture for a reference-mode pack, lending the renderer this host’s device+queue. Shared by every player in the window.

One the device cannot hold is not uploaded; see SSRenderer::upload_texture.

Source

pub fn upload_texture_encoded( &mut self, hash: u32, encoded: &[u8], ) -> Result<(), String>

Register a texture from encoded image bytes (PNG), for hosts that have no image decoder of their own — the C face’s reference-mode path.

The library already carries a PNG decoder for embedded packs, so lending it out costs nothing and saves every C viewer from bringing ImageIO / WIC / libpng along just to show a reference-mode .ssab. The host still does the reading: nothing here opens a file.

Source

pub fn update(&mut self, delta_secs: f32)

Advance every player and build this frame’s GPU buffers. Players are drawn in ascending order, whatever order the slots happen to be in.

Source

pub fn render(&mut self) -> Result<(), String>

Acquire the swapchain image, draw the prepared frame, and present.

A lost/outdated/timed-out surface is absorbed by reconfiguring, and an occluded one by waiting, skipping one frame either way; that is reported as success.

Source

pub fn set_group_alpha(&mut self, on: bool)

Fade each player as one layer rather than part by part; see SSScene::set_group_alpha. Kept across a device restore.

Source

pub fn group_alpha(&self) -> bool

Whether players fade as one layer each.

Source

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

Resize the swapchain, the depth/stencil buffer and the projection to a new drawable size in pixels. Zero in either dimension is ignored, and a size past the device’s max_texture_dimension_2d draws at that limit.

While the device is lost only the size is recorded, and restore_device applies it.

Source

pub fn is_device_lost(&self) -> bool

Whether the driver has taken the device away. While this is true update / render / resize keep off the GPU.

Source

pub fn restore_device(&mut self) -> Result<(), String>

Rebuild the wgpu stack after a device loss and restore everything drawing through it, resuming playback where it was interrupted.

Errors if the GPU is gone for good, or if the replacement adapter cannot present this window’s format — the scene’s pipelines are baked against it, so that case is a rebuild from NativeHost::new.

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

§

fn downcast(&self) -> &T

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.

§

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

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,