Render the UIs

This commit is contained in:
Imbris 2020-12-04 23:41:03 -05:00
parent 7b86b0d236
commit c34afaa258
6 changed files with 38 additions and 19 deletions

View File

@ -52,7 +52,7 @@ use crate::{
ecs::{comp as vcomp, comp::HpFloaterList},
hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent},
i18n::Localization,
render::{Consts, Globals, Renderer},
render::{Consts, Globals, UiDrawer},
scene::camera::{self, Camera},
session::{
settings_change::{Interface as InterfaceChange, SettingsChange},
@ -3405,11 +3405,11 @@ impl Hud {
events
}
pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) {
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);
}
}

View File

@ -340,7 +340,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,
};

View File

@ -8,7 +8,6 @@ use super::{
};
impl Renderer {
// TODO: rework this to use the Bound type?
pub fn bind_globals(
&self,
global_model: &GlobalModel,

View File

@ -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},
@ -41,7 +41,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
@ -82,6 +82,7 @@ struct PostProcess {
pub struct Scene {
data: GlobalModel,
globals_bind_group: GlobalsBindGroup,
camera: Camera,
camera_input_state: Vec2<f32>,
event_lights: Vec<EventLight>,
@ -275,14 +276,21 @@ impl Scene {
let resolution = renderer.resolution().map(|e| e as f32);
let sprite_render_context = lazy_init(renderer);
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(),
@ -299,7 +307,7 @@ impl Scene {
locals: renderer.create_consts(&[PostProcessLocals::default()]),
},
terrain: Terrain::new(renderer, sprite_render_context),
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,

View File

@ -566,14 +566,14 @@ impl<V: RectRasterableVol> Terrain<V> {
},
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,

View File

@ -1317,8 +1317,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());
}
}