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
impl WgpuBackendBuilder
Sourcepub const fn new() -> Self
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).
Sourcepub const fn scale(self, scale: u16) -> Self
pub const fn scale(self, scale: u16) -> Self
Sets the integer pixel scale (each glyph pixel becomes scalexscale physical pixels).
Sourcepub fn font(self, fonts: impl Into<FontChain<'static>>) -> Self
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");Sourcepub fn tileset(self, opts: TilesetOptions) -> Self
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.
Sourcepub fn build(self) -> Result<WgpuRenderer, WgpuBackendError>
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
impl Clone for WgpuBackendBuilder
Source§fn clone(&self) -> WgpuBackendBuilder
fn clone(&self) -> WgpuBackendBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WgpuBackendBuilder
impl Debug for WgpuBackendBuilder
Auto Trait Implementations§
impl Freeze for WgpuBackendBuilder
impl RefUnwindSafe for WgpuBackendBuilder
impl Send for WgpuBackendBuilder
impl Sync for WgpuBackendBuilder
impl Unpin for WgpuBackendBuilder
impl UnsafeUnpin for WgpuBackendBuilder
impl UnwindSafe for WgpuBackendBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.