Pausing rendering, warnings cleanup, more statistics
This commit is contained in:
+16
-16
@@ -1,3 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use wgpu_glyph::{GlyphBrush, ab_glyph::FontArc, GlyphBrushBuilder, Section, Text};
|
||||
use wgpu::util::StagingBelt;
|
||||
use futures::executor::LocalPool;
|
||||
@@ -11,7 +12,7 @@ pub struct UserInterface {
|
||||
local_pool: LocalPool,
|
||||
brush: GlyphBrush<()>,
|
||||
// Texts
|
||||
fps_text: String
|
||||
texts: HashMap<u32, String>
|
||||
}
|
||||
|
||||
impl UserInterface {
|
||||
@@ -22,27 +23,26 @@ impl UserInterface {
|
||||
staging_belt: StagingBelt::new(1024),
|
||||
local_pool: LocalPool::new(),
|
||||
brush: GlyphBrushBuilder::using_font(font).build(device, render_format),
|
||||
fps_text: "-".to_string()
|
||||
texts: HashMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn print(&mut self, x: u32, y: u32, msg: &str) {
|
||||
let text = Text::new(msg).with_color(WHITE);
|
||||
self.brush.queue(Section {
|
||||
screen_position: (x as f32, y as f32),
|
||||
bounds: (text.scale.x * text.text.len() as f32, text.scale.y),
|
||||
text: vec![text],
|
||||
..Section::default()
|
||||
});
|
||||
}
|
||||
|
||||
pub fn set_fps(&mut self, fps: f32) {
|
||||
self.fps_text = format!("FPS: {}", fps);
|
||||
pub fn set_text(&mut self, index: u32, text: String) {
|
||||
self.texts.insert(index, text);
|
||||
}
|
||||
|
||||
pub fn render(&mut self, device: &wgpu::Device, encoder: &mut wgpu::CommandEncoder, target: &wgpu::TextureView, width: u32, height: u32) {
|
||||
// Print texts
|
||||
self.print(5, 5, &self.fps_text.clone());
|
||||
for (id, text) in self.texts.iter() {
|
||||
|
||||
let text = Text::new(text).with_color(WHITE);
|
||||
self.brush.queue(Section {
|
||||
screen_position: (5 as f32, (5 + id*15) as f32),
|
||||
bounds: (text.scale.x * text.text.len() as f32, text.scale.y),
|
||||
text: vec![text],
|
||||
..Section::default()
|
||||
});
|
||||
}
|
||||
|
||||
// Draw
|
||||
self.brush.draw_queued(&device, &mut self.staging_belt, encoder, target, width, height).expect("Draw queued");
|
||||
self.staging_belt.finish();
|
||||
|
||||
Reference in New Issue
Block a user