pub struct GpuRenderer { /* private fields */ }Expand description
GPU resources for drawing a frame of Instances in one draw call.
Everything is created up front; per frame only GpuRenderer::apply_atlas_updates (work
only when new glyphs appeared), GpuRenderer::prepare (two buffer writes) and
GpuRenderer::render (one pass, one draw) run.
Implementations§
Source§impl GpuRenderer
impl GpuRenderer
Sourcepub fn new(device: &Device, format: TextureFormat, capacity: usize) -> Self
pub fn new(device: &Device, format: TextureFormat, capacity: usize) -> Self
A renderer drawing up to capacity instances. Its glyph atlas starts empty and follows
the glyph cache through GpuRenderer::apply_atlas_updates.
format must match the color target render will draw into; use an sRGB format
(or an sRGB view of the surface) so linear shader colors display correctly.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Instances the GPU buffer holds; more are clipped by GpuRenderer::prepare.
Sourcepub fn max_atlas_side(device: &Device) -> u32
pub fn max_atlas_side(device: &Device) -> u32
The largest atlas side device supports; pass it to
GlyphCache::limit_side so the cache never outgrows the device.
Sourcepub fn atlas_error(&self) -> Option<AtlasError>
pub fn atlas_error(&self) -> Option<AtlasError>
The atlas failure latched by apply_atlas_updates, if
any: then the renderer draws nothing until it is recreated.
Sourcepub fn atlas_size(&self) -> (u32, u32)
pub fn atlas_size(&self) -> (u32, u32)
Current glyph atlas size in texels, (width, height).
Sourcepub fn apply_atlas_updates(
&mut self,
device: &Device,
queue: &Queue,
updates: impl IntoIterator<Item = AtlasUpdate>,
) -> Result<usize, AtlasError>
pub fn apply_atlas_updates( &mut self, device: &Device, queue: &Queue, updates: impl IntoIterator<Item = AtlasUpdate>, ) -> Result<usize, AtlasError>
Applies the glyph cache’s atlas changes in order (GlyphCache::drain_updates):
grows the texture, keeping its texels, and copies new glyphs in. Returns how many
glyph writes were applied.
§Errors
AtlasError if the texture can no longer mirror the cache (too large for the device,
or a malformed update). The error is latched: later updates are not applied, every
later call returns it, and prepare draws nothing, since glyphs
would sample the wrong texels. Recreate the renderer and the glyph cache to recover.
Sourcepub fn prepare(
&self,
queue: &Queue,
screen: (u32, u32),
instances: &[Instance],
) -> u32
pub fn prepare( &self, queue: &Queue, screen: (u32, u32), instances: &[Instance], ) -> u32
Uploads the frame’s instances for a screen of (width, height) physical pixels.
Returns how many will be drawn: clipped to capacity, and 0 after an atlas failure.
Sourcepub fn render(
&self,
encoder: &mut CommandEncoder,
target: &TextureView,
clear: Color,
count: u32,
)
pub fn render( &self, encoder: &mut CommandEncoder, target: &TextureView, clear: Color, count: u32, )
Clears target to clear and draws the first count prepared instances.