Merge pull request #1202 from hannobraun/ui

Remove old UI
This commit is contained in:
Hanno Braun 2022-10-11 14:05:27 +02:00 committed by GitHub
commit e51a3fcebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 175 deletions

View File

@ -1,147 +0,0 @@
use std::collections::HashMap;
use fj_math::Aabb;
use wgpu::util::StagingBelt;
use wgpu_glyph::{
ab_glyph::{FontArc, InvalidFont},
GlyphBrush, GlyphBrushBuilder, Section, Text,
};
use super::draw_config::DrawConfig;
pub struct ConfigUi {
glyph_brush: GlyphBrush<()>,
texts: HashMap<(Element, bool), String>,
staging_belt: StagingBelt,
}
impl std::fmt::Debug for ConfigUi {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ConfigUi")
.field("glyph_brush", &self.glyph_brush)
.field("texts", &self.texts)
.finish()
}
}
impl ConfigUi {
pub fn new(
device: &wgpu::Device,
color_format: wgpu::TextureFormat,
) -> Result<Self, InvalidFont> {
let font =
FontArc::try_from_slice(include_bytes!("fonts/B612-Bold.ttf"))?;
let glyph_brush = GlyphBrushBuilder::using_font(font)
.initial_cache_size((512, 512))
.build(device, color_format);
let mut texts = HashMap::new();
for element in Element::elements() {
let (name, key) = element.name_key();
for (enabled, word) in [(false, "disabled"), (true, "enabled")] {
texts.insert(
(element, enabled),
format!(
"{} rendering is {} (toggle with {})\n",
name, word, key
),
);
}
}
// I haven't put any thought into the staging belt's buffer size.
// 1024 just seemed like a good number, and so far it hasn't caused
// any problems.
//
// - @hannobraun
let staging_belt = StagingBelt::new(1024);
Ok(Self {
glyph_brush,
texts,
staging_belt,
})
}
pub fn draw(
&mut self,
device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder,
view: &wgpu::TextureView,
surface_config: &wgpu::SurfaceConfiguration,
aabb: &Aabb<3>,
draw_config: &DrawConfig,
) -> Result<(), String> {
let mut section = Section::new().with_screen_position((50.0, 50.0));
for element in Element::elements() {
let enabled = element.is_enabled(draw_config);
let text = &self.texts[&(element, enabled)];
let alpha = if enabled { 1.0 } else { 0.75 };
let text = Text::new(text)
.with_color([0.0, 0.0, 0.0, alpha])
.with_scale(50.0);
section = section.add_text(text);
}
/* Render size of model bounding box */
let bbsize = aabb.size().components;
let info = format!(
"Model bounding box size: {:0.1} {:0.1} {:0.1}",
bbsize[0].into_f32(),
bbsize[1].into_f32(),
bbsize[2].into_f32()
);
let text = Text::new(&info)
.with_color([0.0, 0.0, 0.0, 1.0])
.with_scale(50.0);
section = section.add_text(text);
self.glyph_brush.queue(section);
self.glyph_brush.draw_queued(
device,
&mut self.staging_belt,
encoder,
view,
surface_config.width,
surface_config.height,
)?;
self.staging_belt.finish();
Ok(())
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
enum Element {
Model,
Mesh,
Debug,
}
impl Element {
fn elements() -> [Self; 3] {
[Self::Model, Self::Mesh, Self::Debug]
}
fn name_key(&self) -> (&'static str, &'static str) {
match self {
Self::Model => ("model", "1"),
Self::Mesh => ("mesh", "2"),
Self::Debug => ("debug info", "3"),
}
}
fn is_enabled(&self, config: &DrawConfig) -> bool {
match self {
Self::Model => config.draw_model,
Self::Mesh => config.draw_mesh,
Self::Debug => config.draw_debug,
}
}
}

View File

@ -1,6 +1,5 @@
//! Rendering primitives, routines, and structures. //! Rendering primitives, routines, and structures.
mod config_ui;
mod draw_config; mod draw_config;
mod drawables; mod drawables;
mod geometries; mod geometries;

View File

@ -14,9 +14,9 @@ use crate::{
}; };
use super::{ use super::{
config_ui::ConfigUi, draw_config::DrawConfig, drawables::Drawables, draw_config::DrawConfig, drawables::Drawables, geometries::Geometries,
geometries::Geometries, pipelines::Pipelines, transform::Transform, pipelines::Pipelines, transform::Transform, uniforms::Uniforms,
uniforms::Uniforms, vertices::Vertices, DEPTH_FORMAT, vertices::Vertices, DEPTH_FORMAT,
}; };
#[derive(Default)] #[derive(Default)]
@ -24,7 +24,6 @@ struct EguiOptionsState {
show_trace: bool, show_trace: bool,
show_layout_debug_on_hover: bool, show_layout_debug_on_hover: bool,
show_debug_text_example: bool, show_debug_text_example: bool,
show_original_ui: bool,
show_settings_ui: bool, show_settings_ui: bool,
show_inspection_ui: bool, show_inspection_ui: bool,
} }
@ -59,8 +58,6 @@ pub struct Renderer {
geometries: Geometries, geometries: Geometries,
pipelines: Pipelines, pipelines: Pipelines,
config_ui: ConfigUi,
/// State required for integration with `egui`. /// State required for integration with `egui`.
pub egui: EguiState, pub egui: EguiState,
} }
@ -232,8 +229,6 @@ impl Renderer {
let pipelines = let pipelines =
Pipelines::new(&device, &bind_group_layout, color_format); Pipelines::new(&device, &bind_group_layout, color_format);
let config_ui = ConfigUi::new(&device, color_format)?;
// //
// Note: We need to hold on to this otherwise (from my memory) // Note: We need to hold on to this otherwise (from my memory)
// it causes the egui font texture to get dropped after // it causes the egui font texture to get dropped after
@ -267,8 +262,6 @@ impl Renderer {
geometries, geometries,
pipelines, pipelines,
config_ui,
egui: EguiState { egui: EguiState {
context: egui_context, context: egui_context,
winit_state: egui_winit_state, winit_state: egui_winit_state,
@ -380,19 +373,6 @@ impl Renderer {
} }
} }
if self.egui.options.show_original_ui {
self.config_ui
.draw(
&self.device,
&mut encoder,
&color_view,
&self.surface_config,
&self.geometries.aabb,
config,
)
.map_err(DrawError::Text)?;
}
// //
// NOTE: The following comment was written for the original // NOTE: The following comment was written for the original
// proof-of-concept which targeted older versions of // proof-of-concept which targeted older versions of
@ -461,10 +441,6 @@ impl Renderer {
.on_disabled_hover_text( .on_disabled_hover_text(
"Rendering device does not have line rendering feature support" "Rendering device does not have line rendering feature support"
); );
ui.checkbox(
&mut self.egui.options.show_original_ui,
"Render original UI",
);
ui.add_space(16.0); ui.add_space(16.0);
ui.strong(get_bbox_size_text(&self.geometries.aabb)); ui.strong(get_bbox_size_text(&self.geometries.aabb));
}); });