add window icon
This commit is contained in:
parent
d8e6baebf1
commit
841ff739dd
13 changed files with 659 additions and 113 deletions
|
@ -13,8 +13,9 @@ use wgpu_text::glyph_brush::ab_glyph::FontRef;
|
|||
use wgpu_text::glyph_brush::{HorizontalAlign, Layout, OwnedSection, OwnedText, VerticalAlign};
|
||||
use wgpu_text::{BrushBuilder, TextBrush};
|
||||
use winit::window::Window;
|
||||
use crate::error::{ZenyxError, ZenyxErrorKind};
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::error::{ZenyxError, ZenyxErrorKind};
|
||||
|
||||
const SHADER_SRC: &str = include_str!("shader.wgsl");
|
||||
|
||||
|
@ -130,7 +131,7 @@ struct Model {
|
|||
bind_group: wgpu::BindGroup,
|
||||
index_count: u32,
|
||||
transform: Matrix4<f32>,
|
||||
version: u32,
|
||||
version: u32,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
|
@ -174,7 +175,7 @@ impl Model {
|
|||
bind_group,
|
||||
index_count: indices.len() as u32,
|
||||
transform: Matrix4::identity(),
|
||||
version: 1
|
||||
version: 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +191,6 @@ impl Model {
|
|||
self.version += 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct Renderer<'window> {
|
||||
|
@ -211,7 +211,7 @@ pub struct Renderer<'window> {
|
|||
frame_count: u32,
|
||||
fps: f32,
|
||||
font_state: FontState,
|
||||
model_versions: Vec<u32>,
|
||||
model_versions: Vec<u32>,
|
||||
}
|
||||
|
||||
struct FontState {
|
||||
|
@ -370,6 +370,8 @@ impl<'window> Renderer<'window> {
|
|||
surface.configure(&device, &surface_config);
|
||||
let (depth_texture, depth_texture_view) =
|
||||
create_depth_texture(&device, surface_config.width, surface_config.height);
|
||||
let (depth_texture, depth_texture_view) =
|
||||
create_depth_texture(&device, surface_config.width, surface_config.height);
|
||||
|
||||
let font_bytes = include_bytes!("DejaVuSans.ttf");
|
||||
let font = FontRef::try_from_slice(font_bytes).map_err(|e| {
|
||||
|
@ -385,8 +387,6 @@ impl<'window> Renderer<'window> {
|
|||
let scale = base_scale * (surface_config.width as f32 / base_width as f32).clamp(0.5, 2.0);
|
||||
let color = wgpu::Color::WHITE;
|
||||
|
||||
|
||||
|
||||
let section = OwnedSection::default()
|
||||
.add_text(OwnedText::new("FPS: 0.00").with_scale(scale).with_color([
|
||||
color.r as f32,
|
||||
|
@ -430,7 +430,7 @@ impl<'window> Renderer<'window> {
|
|||
scale,
|
||||
color,
|
||||
},
|
||||
model_versions: vec![]
|
||||
model_versions: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -475,16 +475,16 @@ impl<'window> Renderer<'window> {
|
|||
for (i, model) in self.models.iter_mut().enumerate() {
|
||||
let angle = Rad(elapsed * 0.8 + i as f32 * 0.3);
|
||||
if i % 2 == 0 {
|
||||
model.set_transform(Matrix4::from_angle_y(angle));
|
||||
model.set_transform(Matrix4::from_angle_y(angle));
|
||||
} else {
|
||||
model.set_transform(Matrix4::from_angle_x(angle) * Matrix4::from_angle_y(angle));
|
||||
model.set_transform(Matrix4::from_angle_x(angle) * Matrix4::from_angle_y(angle));
|
||||
}
|
||||
}
|
||||
for (i, model) in self.models.iter().enumerate() {
|
||||
if model.version > self.model_versions[i] {
|
||||
model.update(&self.queue);
|
||||
#[cfg(debug_assertions)]
|
||||
trace!("Updating model: {:#?}",model);
|
||||
trace!("Updating model: {:#?}", model);
|
||||
self.model_versions[i] = model.version;
|
||||
}
|
||||
}
|
||||
|
@ -604,9 +604,11 @@ impl<'window> Renderer<'window> {
|
|||
pub fn bg_color(&self) -> &wgpu::Color {
|
||||
&self.bg_color
|
||||
}
|
||||
|
||||
pub fn text_color(&self) -> &wgpu::Color {
|
||||
&self.font_state.color
|
||||
}
|
||||
|
||||
pub fn set_text_color(&mut self, color: wgpu::Color) {
|
||||
self.font_state.color = color;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue