Skip to main content

WgpuBackendBuilder

Struct WgpuBackendBuilder 

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

Builder for the wgpu backend.

§Examples

use retroglyph_core::color::Style;
use retroglyph_wgpu::WgpuBackendBuilder;
use retroglyph_window::winit::{WindowConfig, run_windowed};

let renderer = WgpuBackendBuilder::new()
    .grid_size(80, 25)
    .scale(2)
    .build()
    .expect("wgpu backend init failed");
let config = WindowConfig::fit(&renderer, "My Game", None, true);
run_windowed(config, renderer, move |term| {
    term.draw(|s| s.print((0, 0), "Hello from retroglyph-wgpu!", Style::default()))
        .ok();
})
.expect("event loop failed");

Implementations§

Source§

impl WgpuBackendBuilder

Source

pub const fn new() -> Self

A new builder with an 80x25 grid at scale 1 and no font yet (the default-font feature supplies one at build time if none is set).

Source

pub const fn grid_size(self, cols: u16, rows: u16) -> Self

Sets the grid size in cells.

Source

pub const fn scale(self, scale: u16) -> Self

Sets the integer pixel scale (each glyph pixel becomes scalexscale physical pixels).

Source

pub fn font(self, fonts: impl Into<FontChain<'static>>) -> Self

Sets the fonts glyphs are resolved through, overriding the default-font embedded font.

Takes either a single BitmapFont or a whole FontChain, since a lone font is a chain of one. A chain is how a grid draws characters CP437 has no mapping for (quadrants, sextants, braille): the extra coverage comes from a fallback font built with BitmapFont::with_charset, every font in the chain is packed into the same glyph atlas, and the glyph is drawn from that atlas, so it takes the cell’s foreground color like any other glyph (unlike a tileset sprite, which carries its own colors).

Every font in a chain must agree on its glyph size, since that is the grid’s cell size, and the chain’s glyphs must fit the atlas’s 16-bit slot space; otherwise build fails.

§Examples
use retroglyph_wgpu::WgpuBackendBuilder;
use retroglyph_window::font::{BitmapFont, FontChain, unscii16};

// A fallback font declaring the quadrant glyphs CP437 has no mapping for.
static QUADRANTS: [u8; 3 * 16] = [0; 3 * 16];
const CHARSET: [(char, u8); 3] = [('▘', 0), ('▝', 1), ('▖', 2)];
static FALLBACKS: [BitmapFont; 1] =
    [BitmapFont::with_charset(&QUADRANTS, 8, 16, 3, &CHARSET)];

let renderer = WgpuBackendBuilder::new()
    .font(FontChain::new(unscii16::FONT, &FALLBACKS))
    .build()
    .expect("wgpu backend init failed");
Source

pub fn tileset(self, opts: TilesetOptions) -> Self

Registers a PNG sprite tileset. Glyphs a tileset maps override the bitmap font for those codepoints; register multiple and later ones win on codepoint collision. Build the options with TilesetOptions::builder.

Available only with the tilesets feature.

Source

pub fn build(self) -> Result<WgpuRenderer, WgpuBackendError>

Builds the WgpuRenderer.

The renderer holds no GPU device yet; the device and surface are created when the windowing loop calls Presenter::init_surface.

§Errors

Returns WgpuBackendError::NoFont if no font was set and the default-font feature is disabled, WgpuBackendError::MixedGlyphSizes if the configured chain’s fonts disagree on their glyph size, WgpuBackendError::FontChainTooLarge if the chain’s glyphs overflow the atlas’s slot space, WgpuBackendError::ZeroScale if scale is 0, WgpuBackendError::ZeroGrid if either grid dimension is 0, or WgpuBackendError::SurfaceTooLarge if cols/rows/scale combine to a surface wider or taller than u32::MAX physical pixels.

Trait Implementations§

Source§

impl Clone for WgpuBackendBuilder

Source§

fn clone(&self) -> WgpuBackendBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WgpuBackendBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WgpuBackendBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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