Skip to main content

WgpuRenderer

Struct WgpuRenderer 

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

自研轻量级 wgpu 2D SDF 渲染管线核心(绑定任意目标 TextureView 即可渲染)。

Implementations§

Source§

impl WgpuRenderer

Source

pub fn new(device: &Device, target_format: TextureFormat) -> Self

基于已有 wgpu::Device 与目标表面像素格式创建 2D SDF 渲染管线。

Source

pub fn last_primitive_count(&self) -> usize

返回最近一帧合批提交的 GpuPrimitive 实例数量。

Source

pub const fn atlas_sizes(&self) -> (u32, u32)

返回当前字形图集与精灵图集的物理像素边长 (glyph_size, sprite_size)。

Source

pub const fn sprite_cache_hits(&self) -> u64

返回静态精灵跨帧驻留缓存累计命中次数。

Source

pub const fn text_layout_cache_hits(&self) -> u64

返回跨帧文本行排版缓存(TextLayoutCache)累计命中次数。

Source

pub fn text_layout_cache_len(&self) -> usize

返回跨帧文本行排版缓存当前驻留条目数。

Source

pub fn register_external_texture( &mut self, view: TextureView, sampler: Option<Sampler>, ) -> ExternalTextureId

注册一张外部零拷贝 GPU 纹理(如海图、雷达、视频解码器或 3D 视口产出的 wgpu::TextureView), 返回可供 div().external_texture(id) 或 SurfaceCanvas 引用的句柄 ID。

Source

pub fn register_external_texture_with_id( &mut self, id: ExternalTextureId, view: TextureView, sampler: Option<Sampler>, )

按显式 ID 注册或替换外部零拷贝 GPU 纹理(便于固定槽位号与跨语言 FFI 绑定)。

Source

pub fn update_external_texture( &mut self, id: ExternalTextureId, view: TextureView, ) -> bool

原地更新已注册外部纹理的 wgpu::TextureView(如外部引擎 Resize 或双缓冲翻页时调用)。

Source

pub fn unregister_external_texture(&mut self, id: ExternalTextureId) -> bool

注销外部零拷贝纹理槽位并释放 TextureView 引用。

Source

pub fn external_texture_count(&self) -> usize

返回当前已注册的外部零拷贝 GPU 纹理数量。

Source

pub fn render_to_view( &mut self, device: &Device, queue: &Queue, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, target_view: &TextureView, phys_width: u32, phys_height: u32, clear_color: Color, )

将当前帧 ops 直接渲染至目标 target_view:

  • 无图层/混合模式时走单 RenderPass / 单 Draw Call 直出快路径(0 离屏拷贝);
  • 含 PushLayer / 混合 / 毛玻璃 / 滤镜时自动通过 GpuEffectsEngine 在单 CommandEncoder 内完成多 Pass 离屏合成。
Source

pub fn render_to_view_dirty( &mut self, device: &Device, queue: &Queue, ops: &[DrawOp<'_>], viewport: Region, scale_factor: f32, target_view: &TextureView, phys_width: u32, phys_height: u32, dirty_regions: &[Region], clear_color: Color, )

面向持久离屏画布的 GPU 硬件脏区 Scissor 局部增量渲染(仅重绘 dirty_regions 覆盖的物理像素,保留未脏区域以压低 4K 功耗)。

若本帧包含复杂离屏图层/毛玻璃或 dirty_regions 为空,自动无缝回退至标准整帧 render_to_view。

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

Source§

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

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
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.

Source§

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

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,