πŸ¦…πŸ¦ Fast, simple 2D text renderer for wgpu

Overview

πŸ¦… glyphon 🦁

Fast, simple 2D text rendering for wgpu

crates.io docs.rs Minimum Rust Version Build Status

What is this?

This crate provides a simple way to render 2D text with wgpu by:

  • rasterizing glyphs (with fontdue)
  • packing the glyphs into texture atlas (with etagere)
  • calculate layout for text (with fontdue)
  • sampling from the texture atlas to render text (with wgpu)

To avoid extra render passes, rendering uses existing render passes (following the middleware pattern described in wgpu's Encapsulating Graphics Work wiki page.

License

This project is licensed under either Apache License, Version 2.0, zlib License, or MIT License, at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache 2.0 license, shall be triple licensed as above, without any additional terms or conditions.

Comments
  • Handle text overflow

    Handle text overflow

    Cull glyphs fully outside the bounds, and clip glyphs intersecting the bounds. This is all done on the CPU for now.

    Fixes #2

    We'll wait on a new version of fontdue to be published before merging.

    opened by grovesNL 6
  • Split Files and Error Handling.

    Split Files and Error Handling.

    I have Separated the Source into files which should improve source Readability. I have Removed and Replaced the Error Enums with a single Enum using ThisError to also allow handling WGPU and such Error for later usage if you expand to more features that needs wgpu error handling.

    opened by genusistimelord 4
  • Share atlas between text renderers

    Share atlas between text renderers

    This allows the glyph cache to be shared between renderers.

    Fixes #6

    For now, we also reuse some other fields where possible (e.g. params, bind groups). We could change this later if we'd any of these to vary between renderers.

    This doesn't change the storage, so a single 2D texture is still used for now.

    Some other ideas:

    • We could empty the cache easily if we had an Arc per glyph to know if it needs to remain in the cache. This would probably be really heavyweight and we'd need to change the refcount per glyph every time prepare is called, so I avoided this approach.
    • Pass layouts into render and verify the glyphs exist instead of storing them in a Vec on TextRenderer. I didn't do it this way because layouts can change between prepare and render, although maybe we could require that it's not allowed (e.g. through documentation or lifetimes).
    • We could generate an atlas internally if we don't want to require the atlas to be passed in explicitly in all new functions (e.g. builders or Default). This would make the shared atlas opt-in but it seems like we'd probably want the opt-in behavior by default.
    • We could accept &mut TextAtlas where we need to use the atlas instead of internally storing Arc<RwLock<InnerAtlas>>. This avoids Arc and RwLock to be replaced by something else (e.g. Rc when running single-threaded). Doing it internally seems to have better ergonomics because we don't have to pass in &mut TextAtlas all the time, but there's a good argument for keeping this external too.
    opened by grovesNL 2
  • Allow borrowed layouts for `prepare`

    Allow borrowed layouts for `prepare`

    Allows either &[layout, overflow] or &[&layout, overflow]

    Discussed in https://github.com/grovesNL/glyphon/issues/1#issuecomment-1286428829

    opened by grovesNL 1
  • Some Source Suggestions.

    Some Source Suggestions.

    So in small or large projects it does tend to be a good Idea to split structure and data types into their own parts. This makes certain things Easier to find and can improve readability and Adaptability. Keeping most of everything in a Single file generally is a huge turn off to programmers who are willing to help as it makes it harder to find Certain things. This is just a Suggestion not really a Must do.

    TextAtlas and Text Renderer can be split into their own files. The major Data structures at the top Could either Stay since they are small or be moved into a single separate file to remove code form the lib.rs. Some internal Changes Could also be split into Functions as well and just made inlined, which can make Code easier to read if the function names Make sense for what it does.

    Splitting up the Code can also help later on with new Feature Additions to this library. Anyways What do you think?

    opened by genusistimelord 1
  • wgpu 13 support

    wgpu 13 support

    Hey, I like that this is using the latest shader format. You might want to add this to Cargo.toml or make mention of it:

    [patch.crates-io]
    wgpu = { git = "https://github.com/gfx-rs/wgpu" }
    
    opened by SetheenDev 1
  • Sharing atlas between multiple text renderers

    Sharing atlas between multiple text renderers

    Ideally we could have an easy way to have multiple text renderers that share the same atlas to avoid extra texture allocations and share glyphs when possible.

    We could do this by passing the atlas to prepare, sharing internally, etc. Alternatively we could share a text renderer between all layers, and the text renderer could model layers directly somehow.

    opened by grovesNL 1
  • Pad to improve WebGL support

    Pad to improve WebGL support

    Better support WebGL by padding uniform block to 16-byte alignment, which will usually cause the block size to match UNIFORM_BLOCK_DATA_SIZE on WebGL.

    We might be able to remove this or handle it differently eventually depending on how it's supported upstream.

    (see https://github.com/gfx-rs/wgpu/issues/2072#issuecomment-1147599245 for more context)

    opened by grovesNL 0
  • Accept atlas in `prepare` and `render`

    Accept atlas in `prepare` and `render`

    Removes the internal RwLock in favor of accepting &mut TextAtlas (follow-up from https://github.com/grovesNL/glyphon/pull/9#issuecomment-1137501663)

    opened by grovesNL 0
  • Handle text overflow

    Handle text overflow

    Handle text overflow outside of layouts through culling and clipping.

    Culling:

    • We could cull on the CPU, e.g. if all or any glyph's vertex is outside the layout then we could skip it
      • We could also clip on the CPU at this point if we want, see note below

    Clipping:

    • When one layout is used per render, clipping with scissor could be handled outside of glyphon or by glyphon setting the scissor
    • When multiple layouts are used, we'd probably need to handle clipping through shader discard or clip on the CPU (e.g. clip the vertices and sample the glyph from the remaining area)
    opened by grovesNL 0
  • Consider handling transformations

    Consider handling transformations

    Consider handling scale, shear, rotation, etc., at least for typical 2D use cases

    Also related to #3 because pixel snapping wouldn't work well depending on the transformation.

    opened by grovesNL 0
  • Subpixel positioning and antialiasing

    Subpixel positioning and antialiasing

    Currently we snap to the nearest pixel so kind of avoid this.

    We probably want to have a strategy for handling subpixel positioning and AA generally. This can be difficult with glyphs because we might need to generate multiple glyphs for various subpixel positions.

    opened by grovesNL 1
  • Improve API ergonomics

    Improve API ergonomics

    It's a bit difficult to organize fonts/layouts and pass them to renderer.

    Consider some other way to handle fonts, layouts, etc., possibly wrapping all of fontdue to remove fontdue from the public API.

    opened by grovesNL 31
Owner
Josh Groves
πŸ‡¨πŸ‡¦
Josh Groves
Simple profiler scopes for wgpu using timer queries

wgpu-profiler Simple profiler scopes for wgpu using timer queries Features Easy to use profiler scopes Allows nesting! Can be disabled by runtime flag

null 41 Dec 5, 2022
Rustcraft is a simple Minecraft engine written in rust using wgpu.

Rustcraft is a simple Minecraft engine written in rust using wgpu.

Raphael Van Hoffelen 110 Dec 22, 2022
πŸ–A WGPU graphics pipeline, along with simple types used to marshal data to the GPU

renderling ?? This library is a collection of WGPU render pipelines. Shaders are written in GLSL. shaderc is used to compile shaders to SPIR-V. Defini

Schell Carl Scivally 5 Dec 20, 2022
A modern 3D/2D game engine that uses wgpu.

Harmony A modern 3D/2D game engine that uses wgpu and is designed to work out of the box with minimal effort. It uses legion for handling game/renderi

John 152 Dec 24, 2022
A curated list of wgpu code and resources.

Awesome wgpu A curated list of wgpu code and resources. PRs welcome. About wgpu https://github.com/gfx-rs/wgpu-rs matrix chat https://matrix.to/#/#wgp

Roman FroΕ‚ow 283 Jan 3, 2023
Scion is a tiny 2D game library built on top of wgpu, winit and legion.

Scion is a 2D game library made in rust. Please note that this project is in its first milestones and is subject to change according to convience need

JΓ©rΓ©my Thulliez 143 Dec 25, 2022
Self Study on developing a game engine using wgpu as the rendering API. Learning as I go.

Fabled Engine Any issues, enhancement, features, or bugs report are always welcome in Issues. The obj branch is where frequent development and up to d

Khalid 20 Jan 5, 2023
Tic-Tac-Toe on the GPU, as an example application for wgpu

Tic-Tac-GPU A simple (cough cough) example on a tic-tac-toe game with wgpu. Why? Because I didn't find that many small applications which use wgpu as

multisn8 2 Oct 7, 2022
Guide for using gfx-rs's wgpu library.

Introduction What is wgpu? Wgpu is a Rust implementation of the WebGPU API spec. WebGPU is a specification published by the GPU for the Web Community

sotrh 1k Dec 29, 2022
game engine built in rust, using wgpu and probably other stuff too

horizon game engine engine for devpty games, made in 99.9% rust and 0.1% shell. this is our main project currently. the engine will be used for most i

DEVPTY 2 Apr 12, 2022
A barebones example of how to integrate OpenXR with wgpu (Vulkan-only)

wgpu-openxr-example a barebones example of how to integrate OpenXR with wgpu (Vulkan-only) It has four modes: cargo run --no-default-features: desktop

Philpax 21 Dec 15, 2022
3d Cellular Automata using WGPU in Rust (for the web and using compute shaders)

3D-Cellular-Automata-WGPU 3d Cellular Automata using WGPU in Rust (for the web and using compute shaders) The branches are very messy... I recommend y

null 18 Dec 18, 2022
Rust-based replacement for the default Minecraft renderer

wgpu-mc ?? A blazing fast alternative renderer for Minecraft Intro WebGPU is a new web specification designed to provide modern graphics and compute c

Birb 1 Jun 28, 2022
Pixel-Perfect, 2D Renderer for Bevy that Seamlessly Targets Desktop and Web

bevy_retro ( Screenshot of Bounty Bros. game made with Bevy Retro and Skip'n Go ) Bevy Retro is a 2D, pixel-perfect renderer for Bevy that can target

Katharos Technology 224 Dec 23, 2022
A high-performance renderer to render glTF models that use the `KHR_materials_transmission` and `KHR_materials_volume` extensions.

This is a high-performance renderer designed among other things to render glTF models that use the KHR_materials_transmission and KHR_materials_volume

Ashley 21 Dec 5, 2022
A plugin to use the kajiya renderer with bevy

??️ ?? bevy-kajiya A plugin that enables use of the kajiya renderer in bevy WARNING: This plugin is barebones and supports a limited set of features.

Sebastian Hamel 79 Jan 5, 2023
Sdf 2d shape renderer for Bevy

bevy_smud Sdf 2d shape rendering for Bevy. Bevy smud is a way to conveniently construct and render sdf shapes with Bevy. Given a shape function/expres

Johan Klokkhammer Helsing 85 Jan 2, 2023
Renderer-agnostic toolkit for Indie Game Developers

Indie Toolkit Renderer-agnostic toolkit for Indie Game Developers Features Not yet implemented: app_kit debug_kit input_kit asset_kit audio_kit Implem

null 2 May 25, 2022
Bevy plugin for a simple single-line text input widget.

bevy_simple_text_input An unambitious single-line text input widget for bevy_ui. Usage See examples/basic.rs. Alternatives If you need more features,

Rob Parrett 9 Oct 3, 2023