diff options
author | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-05-16 15:20:39 +0200 |
---|---|---|
committer | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-05-16 15:20:39 +0200 |
commit | ef8c75b9dc47142527fc1741d75cf34c66c3ac9d (patch) | |
tree | 836e541b516717f9c00d06e659d4cc7b238193b2 /src/gfx/font.rs | |
parent | 0fc89aa3ec523d3d06546220bae5393232274e13 (diff) | |
download | mt_client-ef8c75b9dc47142527fc1741d75cf34c66c3ac9d.tar.xz |
Split state.rs and add debug menu
Diffstat (limited to 'src/gfx/font.rs')
-rw-r--r-- | src/gfx/font.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gfx/font.rs b/src/gfx/font.rs new file mode 100644 index 0000000..6875a3b --- /dev/null +++ b/src/gfx/font.rs @@ -0,0 +1,44 @@ +use super::gpu::{Frame, Gpu}; + +pub struct Font { + glyph_brush: wgpu_glyph::GlyphBrush<()>, + staging_belt: wgpu::util::StagingBelt, +} + +impl Font { + pub fn new(gpu: &Gpu) -> Self { + Self { + glyph_brush: wgpu_glyph::GlyphBrushBuilder::using_font( + wgpu_glyph::ab_glyph::FontArc::try_from_slice(include_bytes!( + "../../assets/font/regular.otf" + )) + .unwrap(), + ) + .build(&gpu.device, gpu.config.format), + staging_belt: wgpu::util::StagingBelt::new(1024), + } + } + + pub fn add(&mut self, section: wgpu_glyph::Section) { + self.glyph_brush.queue(section); + } + + pub fn submit(&mut self, frame: &mut Frame) { + self.glyph_brush + .draw_queued( + &frame.gpu.device, + &mut self.staging_belt, + &mut frame.encoder, + &frame.view, + frame.gpu.config.width, + frame.gpu.config.height, + ) + .unwrap(); + + self.staging_belt.finish(); + } + + pub fn cleanup(&mut self) { + self.staging_belt.recall(); + } +} |