Crate frenderer

source ·
Expand description

A friendly renderer built with WGPU.

Frenderer currently manages a wgpu::Instance and associated types, initializing a custom SpriteRenderer based on storage buffers (for native) and instance buffers (for WebGL).

It also provides a convenience type input::Input for processing user input and a utility function for loading a texture (from disk or from a relative URL).

Except for the WGPU initialization, frenderer is fully modular; in particular, it does not take control of the event loop. Typical usage will call frenderer::with_default_runtime() to install frenderer inside a winit::window::Window, call sprites::SpriteRenderer::add_sprite_group() on the resulting frenderer::Renderer value, and eventually call frenderer::Renderer::process_window_event(), sprites::SpriteRenderer::upload_sprites(), and frenderer::Renderer::render or frenderer::Renderer::render_into to draw.

In the future, more types of renderers including 3D renderers will also be provided.

Re-exports

Modules

  • Renderer is the main user-facing type of this crate. You can make one using with_default_runtime() or provide your own super::Runtime implementor via Renderer::with_runtime().
  • A wrapper for a current and previous input button/mouse state.
  • Similar to sprite groups and individual sprites, in frenderer there are mesh groups and individual meshes. Each individual mesh has some submeshes that are all grouped together (this is kind of a quirk of the glTF format but it means different submeshes can use different materials in principle); meshes can have some number of instances (you set an estimate for the number of instances of each mesh when you’re adding the mesh group; it can grow at runtime but it might be costly so try to minimize the amount of growth), and the setting of instance data and uploading of instance data to the GPU are separated like they are for sprites. The only instance data is a 3D transform (translation, rotation, and a uniform scaling factor (so it fits neatly into 8 floats). Rotations are defined as quaternions.

Structs

  • Camera2D is a transform for a sprite layer, defining a scale followed by a translation.
  • A runtime using pollster for native builds
  • A SheetRegion defines the visual appearance of a sprite: which spritesheet (of an array of spritesheets), its pixel region within the spritesheet, and its visual depth (larger meaning further away).
  • SpriteRenderer hosts a number of sprite groups. Each group has a specified spritesheet texture array, parallel vectors of Transforms and SheetRegions, and a Camera2D to define its transform. Currently, all groups render into the same depth buffer so their outputs are interleaved.
  • A Transform describes a location, an extent, and a rotation in 2D space. Width and height are crammed into 4 bytes meaning the maximum width and height are u16::MAX and fractional widths and heights are not supported. The location (x,y) is typically interpreted as the center of the object after translation. Rotations are in radians, counterclockwise about the center point.
  • A wrapper for a WGPU instance, surface, adapter, device, queue, and surface configuration.

Traits

  • A runtime for frenderer; mainly wraps an async runtime, but also sets up logging, etc. In the future it might be responsible for setting up WGPU/providing a rendering context as well.

Type Aliases