From 7f7ed299688486c1184963485db37f295902c829 Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 4 Dec 2020 23:41:03 -0500 Subject: [PATCH] Render the UIs --- voxygen/src/hud/mod.rs | 6 ++--- voxygen/src/menu/main/mod.rs | 2 +- voxygen/src/render/renderer/binding.rs | 1 - voxygen/src/scene/mod.rs | 32 +++++++++++++++++--------- voxygen/src/scene/terrain.rs | 4 ++-- voxygen/src/session.rs | 12 +++++++++- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 2d14e19527..178508b956 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -51,7 +51,7 @@ use crate::{ ecs::{comp as vcomp, comp::HpFloaterList}, hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent}, i18n::{LanguageMetadata, Localization}, - render::{Consts, Globals, RenderMode, Renderer}, + render::{Consts, Globals, RenderMode, UiDrawer}, scene::camera::{self, Camera}, settings::Fps, ui::{ @@ -2978,11 +2978,11 @@ impl Hud { events } - pub fn render(&self, renderer: &mut Renderer, globals: &Consts) { + pub fn render<'a>(&'a self, drawer: &mut UiDrawer<'_, 'a>) { span!(_guard, "render", "Hud::render"); // Don't show anything if the UI is toggled off. if self.show.ui { - //self.ui.render(renderer, Some(globals)); + self.ui.render(drawer); } } diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 7207c41753..c19363f784 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -327,7 +327,7 @@ impl PlayState for MainMenuState { .unwrap() { Some(d) => d, - // Couldn't get swap chain texture this fime + // Couldn't get swap chain texture this frame None => return, }; diff --git a/voxygen/src/render/renderer/binding.rs b/voxygen/src/render/renderer/binding.rs index 5ecfda32cf..691d9660a7 100644 --- a/voxygen/src/render/renderer/binding.rs +++ b/voxygen/src/render/renderer/binding.rs @@ -8,7 +8,6 @@ use super::{ }; impl Renderer { - // TODO: rework this to use the Bound type? pub fn bind_globals( &self, global_model: &GlobalModel, diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index c7a4cf7ec0..a2a64d1d80 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -17,8 +17,8 @@ use crate::{ audio::{ambient::AmbientMgr, music::MusicMgr, sfx::SfxMgr, AudioFrontend}, render::{ create_clouds_mesh, create_pp_mesh, create_skybox_mesh, CloudsLocals, CloudsVertex, Consts, - GlobalModel, Globals, Light, Model, PostProcessLocals, PostProcessVertex, Renderer, Shadow, - ShadowLocals, SkyboxVertex, + GlobalModel, Globals, GlobalsBindGroup, Light, Model, PostProcessLocals, PostProcessVertex, + Renderer, Shadow, ShadowLocals, SkyboxVertex, }, settings::Settings, window::{AnalogGameInput, Event}, @@ -42,7 +42,7 @@ use vek::*; // TODO: Don't hard-code this. const CURSOR_PAN_SCALE: f32 = 0.005; -const MAX_LIGHT_COUNT: usize = 31; +const MAX_LIGHT_COUNT: usize = 20; // 31 (total shadow_mats is limited to 128 with default max_uniform_buffer_binding_size) const MAX_SHADOW_COUNT: usize = 24; const NUM_DIRECTED_LIGHTS: usize = 1; const LIGHT_DIST_RADIUS: f32 = 64.0; // The distance beyond which lights may not emit light from their origin @@ -83,6 +83,7 @@ struct PostProcess { pub struct Scene { data: GlobalModel, + globals_bind_group: GlobalsBindGroup, camera: Camera, camera_input_state: Vec2, event_lights: Vec, @@ -270,14 +271,21 @@ impl Scene { pub fn new(renderer: &mut Renderer, client: &Client, settings: &Settings) -> Self { let resolution = renderer.resolution().map(|e| e as f32); + let data = GlobalModel { + globals: renderer.create_consts(&[Globals::default()]), + lights: renderer.create_consts(&[Light::default(); MAX_LIGHT_COUNT]), + shadows: renderer.create_consts(&[Shadow::default(); MAX_SHADOW_COUNT]), + shadow_mats: renderer + .create_consts(&[ShadowLocals::default(); MAX_LIGHT_COUNT * 6 + 6]), + }; + + let lod = Lod::new(renderer, client, settings); + + let globals_bind_group = renderer.bind_globals(&data, lod.get_data()); + Self { - data: GlobalModel { - globals: renderer.create_consts(&[Globals::default()]), - lights: renderer.create_consts(&[Light::default(); MAX_LIGHT_COUNT]), - shadows: renderer.create_consts(&[Shadow::default(); MAX_SHADOW_COUNT]), - shadow_mats: renderer - .create_consts(&[ShadowLocals::default(); MAX_LIGHT_COUNT * 6 + 6]), - }, + data, + globals_bind_group, camera: Camera::new(resolution.x / resolution.y, CameraMode::ThirdPerson), camera_input_state: Vec2::zero(), event_lights: Vec::new(), @@ -294,7 +302,7 @@ impl Scene { locals: renderer.create_consts(&[PostProcessLocals::default()]), }, terrain: Terrain::new(renderer), - lod: Lod::new(renderer, client, settings), + lod, loaded_distance: 0.0, map_bounds: Vec2::new( client.world_data().min_chunk_alt(), @@ -992,6 +1000,8 @@ impl Scene { .maintain(audio, scene_data.state, client, &self.camera); } + pub fn global_bind_group(&self) -> &GlobalsBindGroup { &self.globals_bind_group } + /// Render the scene using the provided `Renderer`. pub fn render( &mut self, diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index ed2e7240bd..c65d2bc66f 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -444,14 +444,14 @@ impl Terrain { }, mip_level_count: 1, sample_count: 1, - dimension: wgpu::TextureDimension::D1, + dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsage::COPY_DST | wgpu::TextureUsage::SAMPLED, }, &wgpu::TextureViewDescriptor { label: Some("Atlas texture view"), format: Some(wgpu::TextureFormat::Rgba8UnormSrgb), - dimension: Some(wgpu::TextureViewDimension::D1), + dimension: Some(wgpu::TextureViewDimension::D2), aspect: wgpu::TextureAspect::All, base_mip_level: 0, level_count: None, diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 2c9b052c1e..8687832502 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -1393,8 +1393,18 @@ impl PlayState for SessionState { &scene_data, ); } + + let mut drawer = match renderer + .start_recording_frame(self.scene.global_bind_group()) + .unwrap() + { + Some(d) => d, + // Couldn't get swap chain texture this frame + None => return, + }; + // Draw the UI to the screen - self.hud.render(renderer, self.scene.globals()); + self.hud.render(&mut drawer.third_pass().draw_ui()); } }