pub struct NativeHost { /* private fields */ }Expand description
A window-owning wgpu host and the players drawing into it.
Implementations§
Source§impl NativeHost
impl NativeHost
Sourcepub unsafe fn new(
target: SurfaceTargetUnsafe,
config: &NativeHostConfig,
) -> Result<Self, String>
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.
Sourcepub fn create_player(&mut self) -> PlayerId
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.
Sourcepub fn destroy_player(&mut self, id: PlayerId) -> bool
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.
Sourcepub fn player_mut(&mut self, id: PlayerId) -> Option<&mut SSPlayer>
pub fn player_mut(&mut self, id: PlayerId) -> Option<&mut SSPlayer>
The player id names, or None if it has been destroyed.
Sourcepub fn player_count(&self) -> usize
pub fn player_count(&self) -> usize
How many players this window currently holds.
Sourcepub fn stats(&self) -> SceneStats
pub fn stats(&self) -> SceneStats
What the last frame cost.
Sourcepub fn texture_extent_error(&self, width: u32, height: u32) -> Option<String>
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.
Sourcepub fn upload_texture(
&mut self,
hash: u32,
rgba: &[u8],
width: u32,
height: u32,
)
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.
Sourcepub fn upload_texture_encoded(
&mut self,
hash: u32,
encoded: &[u8],
) -> Result<(), String>
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.
Sourcepub fn update(&mut self, delta_secs: f32)
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.
Sourcepub fn render(&mut self) -> Result<(), String>
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.
Sourcepub fn set_group_alpha(&mut self, on: bool)
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.
Sourcepub fn group_alpha(&self) -> bool
pub fn group_alpha(&self) -> bool
Whether players fade as one layer each.
Sourcepub fn resize(&mut self, width: u32, height: u32)
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.
Sourcepub fn is_device_lost(&self) -> bool
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.
Sourcepub fn restore_device(&mut self) -> Result<(), String>
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.