Skip to main content

GpuRenderer

Struct GpuRenderer 

Source
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

Source

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.

Source

pub fn capacity(&self) -> usize

Instances the GPU buffer holds; more are clipped by GpuRenderer::prepare.

Source

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.

Source

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.

Source

pub fn atlas_size(&self) -> (u32, u32)

Current glyph atlas size in texels, (width, height).

Source

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.

Source

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.

Source

pub fn render( &self, encoder: &mut CommandEncoder, target: &TextureView, clear: Color, count: u32, )

Clears target to clear and draws the first count prepared instances.

Trait Implementations§

Source§

impl Debug for GpuRenderer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

Source§

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.

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

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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