pub struct WgpuWindowRenderer { /* private fields */ }Expand description
面向桌面(winit)与移动端(ANativeWindow / CAMetalLayer / OHNativeWindow)的统一轻量级
wgpu Swapchain 窗口渲染器。
直接渲染至 Swapchain 纹理,无中间全屏纹理与 Blit 开销。
Implementations§
Source§impl WgpuWindowRenderer
impl WgpuWindowRenderer
Sourcepub fn from_prepared<T>(
prepared: PreparedWgpuContext,
target: T,
width: u32,
height: u32,
) -> Option<Self>where
T: Into<SurfaceTarget<'static>>,
pub fn from_prepared<T>(
prepared: PreparedWgpuContext,
target: T,
width: u32,
height: u32,
) -> Option<Self>where
T: Into<SurfaceTarget<'static>>,
将后台线程预热完毕的 PreparedWgpuContext 在主线程快速绑定至目标窗口 target(仅耗时 ~10ms)。
Sourcepub fn new<T>(target: T, width: u32, height: u32) -> Option<Self>
pub fn new<T>(target: T, width: u32, height: u32) -> Option<Self>
初始化窗口 GPU 渲染表面;若宿主无可用硬件 GPU 或创建失败则返回 None 以便优雅回退至软件光栅。
Sourcepub fn adapter_name(&self) -> &str
pub fn adapter_name(&self) -> &str
返回当前选中的显卡适配器名称。
Sourcepub const fn backend_name(&self) -> &'static str
pub const fn backend_name(&self) -> &'static str
返回当前激活的图形 API 后端名称("DX12" / "Vulkan" / "Metal" 等)。
Sourcepub fn last_primitive_count(&self) -> usize
pub fn last_primitive_count(&self) -> usize
返回最近一帧合批渲染的图元总数。
Sourcepub const fn atlas_sizes(&self) -> (u32, u32)
pub const fn atlas_sizes(&self) -> (u32, u32)
返回当前字形图集与精灵图集的物理像素边长 (glyph_size, sprite_size)。
Sourcepub fn renderer(&self) -> &WgpuRenderer
pub fn renderer(&self) -> &WgpuRenderer
返回内部 WgpuRenderer 只读引用。
Sourcepub fn renderer_mut(&mut self) -> &mut WgpuRenderer
pub fn renderer_mut(&mut self) -> &mut WgpuRenderer
返回内部 WgpuRenderer 可变引用。
Sourcepub fn register_external_texture(
&mut self,
view: TextureView,
sampler: Option<Sampler>,
) -> ExternalTextureId
pub fn register_external_texture( &mut self, view: TextureView, sampler: Option<Sampler>, ) -> ExternalTextureId
向窗口渲染器注册外部零拷贝 GPU 纹理(如海图/视频/3D 视口),返回句柄 ID。
Sourcepub fn update_external_texture(
&mut self,
id: ExternalTextureId,
view: TextureView,
) -> bool
pub fn update_external_texture( &mut self, id: ExternalTextureId, view: TextureView, ) -> bool
原地更新已注册外部零拷贝纹理的 TextureView(如外部引擎 Swap/Resize 后切换目标)。
Sourcepub fn unregister_external_texture(&mut self, id: ExternalTextureId) -> bool
pub fn unregister_external_texture(&mut self, id: ExternalTextureId) -> bool
注销外部零拷贝纹理槽位。
Sourcepub fn render(
&mut self,
ops: &[DrawOp<'_>],
viewport: Region,
dpi_scale: i16,
) -> bool
pub fn render( &mut self, ops: &[DrawOp<'_>], viewport: Region, dpi_scale: i16, ) -> bool
直接在 Swapchain 上执行单 Pass 2D SDF 渲染并提交显示(整数 DPI 兼容入口)。
Sourcepub fn render_scaled(
&mut self,
ops: &[DrawOp<'_>],
viewport: Region,
scale_factor: f32,
) -> bool
pub fn render_scaled( &mut self, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, ) -> bool
直接在 Swapchain 上执行单 Pass 2D SDF 渲染并提交显示(原生支持分数 DPI scale_factor 与 Pixel Snapping)。
Sourcepub fn render_scaled_with_clear(
&mut self,
ops: &[DrawOp<'_>],
viewport: Region,
scale_factor: f32,
clear: Color,
) -> bool
pub fn render_scaled_with_clear( &mut self, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, clear: Color, ) -> bool
直接在 Swapchain 上以指定背景清屏色 clear 执行单 Pass 2D SDF 渲染并提交显示。
Sourcepub fn flush_and_wait(&self)
pub fn flush_and_wait(&self)
等待已提交至 GPU 队列的渲染指令完成(用于首帧隐身提交后、显窗前的零白屏同步栅栏)。
Auto Trait Implementations§
impl !Freeze for WgpuWindowRenderer
impl !RefUnwindSafe for WgpuWindowRenderer
impl !UnwindSafe for WgpuWindowRenderer
impl Forget for WgpuWindowRenderer
impl Move for WgpuWindowRenderer
impl Send for WgpuWindowRenderer
impl Sync for WgpuWindowRenderer
impl Unpin for WgpuWindowRenderer
impl UnsafeUnpin for WgpuWindowRenderer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。