mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Render the UIs
This commit is contained in:
parent
7b86b0d236
commit
c34afaa258
@ -52,7 +52,7 @@ use crate::{
|
|||||||
ecs::{comp as vcomp, comp::HpFloaterList},
|
ecs::{comp as vcomp, comp::HpFloaterList},
|
||||||
hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent},
|
hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent},
|
||||||
i18n::Localization,
|
i18n::Localization,
|
||||||
render::{Consts, Globals, Renderer},
|
render::{Consts, Globals, UiDrawer},
|
||||||
scene::camera::{self, Camera},
|
scene::camera::{self, Camera},
|
||||||
session::{
|
session::{
|
||||||
settings_change::{Interface as InterfaceChange, SettingsChange},
|
settings_change::{Interface as InterfaceChange, SettingsChange},
|
||||||
@ -3405,11 +3405,11 @@ impl Hud {
|
|||||||
events
|
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");
|
span!(_guard, "render", "Hud::render");
|
||||||
// Don't show anything if the UI is toggled off.
|
// Don't show anything if the UI is toggled off.
|
||||||
if self.show.ui {
|
if self.show.ui {
|
||||||
//self.ui.render(renderer, Some(globals));
|
self.ui.render(drawer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ impl PlayState for MainMenuState {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
Some(d) => d,
|
Some(d) => d,
|
||||||
// Couldn't get swap chain texture this fime
|
// Couldn't get swap chain texture this frame
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
// TODO: rework this to use the Bound type?
|
|
||||||
pub fn bind_globals(
|
pub fn bind_globals(
|
||||||
&self,
|
&self,
|
||||||
global_model: &GlobalModel,
|
global_model: &GlobalModel,
|
||||||
|
@ -17,8 +17,8 @@ use crate::{
|
|||||||
audio::{ambient::AmbientMgr, music::MusicMgr, sfx::SfxMgr, AudioFrontend},
|
audio::{ambient::AmbientMgr, music::MusicMgr, sfx::SfxMgr, AudioFrontend},
|
||||||
render::{
|
render::{
|
||||||
create_clouds_mesh, create_pp_mesh, create_skybox_mesh, CloudsLocals, CloudsVertex, Consts,
|
create_clouds_mesh, create_pp_mesh, create_skybox_mesh, CloudsLocals, CloudsVertex, Consts,
|
||||||
GlobalModel, Globals, Light, Model, PostProcessLocals, PostProcessVertex, Renderer, Shadow,
|
GlobalModel, Globals, GlobalsBindGroup, Light, Model, PostProcessLocals, PostProcessVertex,
|
||||||
ShadowLocals, SkyboxVertex,
|
Renderer, Shadow, ShadowLocals, SkyboxVertex,
|
||||||
},
|
},
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
window::{AnalogGameInput, Event},
|
window::{AnalogGameInput, Event},
|
||||||
@ -41,7 +41,7 @@ use vek::*;
|
|||||||
// TODO: Don't hard-code this.
|
// TODO: Don't hard-code this.
|
||||||
const CURSOR_PAN_SCALE: f32 = 0.005;
|
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 MAX_SHADOW_COUNT: usize = 24;
|
||||||
const NUM_DIRECTED_LIGHTS: usize = 1;
|
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
|
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 {
|
pub struct Scene {
|
||||||
data: GlobalModel,
|
data: GlobalModel,
|
||||||
|
globals_bind_group: GlobalsBindGroup,
|
||||||
camera: Camera,
|
camera: Camera,
|
||||||
camera_input_state: Vec2<f32>,
|
camera_input_state: Vec2<f32>,
|
||||||
event_lights: Vec<EventLight>,
|
event_lights: Vec<EventLight>,
|
||||||
@ -275,14 +276,21 @@ impl Scene {
|
|||||||
let resolution = renderer.resolution().map(|e| e as f32);
|
let resolution = renderer.resolution().map(|e| e as f32);
|
||||||
let sprite_render_context = lazy_init(renderer);
|
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 {
|
Self {
|
||||||
data: GlobalModel {
|
data,
|
||||||
globals: renderer.create_consts(&[Globals::default()]),
|
globals_bind_group,
|
||||||
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]),
|
|
||||||
},
|
|
||||||
camera: Camera::new(resolution.x / resolution.y, CameraMode::ThirdPerson),
|
camera: Camera::new(resolution.x / resolution.y, CameraMode::ThirdPerson),
|
||||||
camera_input_state: Vec2::zero(),
|
camera_input_state: Vec2::zero(),
|
||||||
event_lights: Vec::new(),
|
event_lights: Vec::new(),
|
||||||
@ -299,7 +307,7 @@ impl Scene {
|
|||||||
locals: renderer.create_consts(&[PostProcessLocals::default()]),
|
locals: renderer.create_consts(&[PostProcessLocals::default()]),
|
||||||
},
|
},
|
||||||
terrain: Terrain::new(renderer, sprite_render_context),
|
terrain: Terrain::new(renderer, sprite_render_context),
|
||||||
lod: Lod::new(renderer, client, settings),
|
lod,
|
||||||
loaded_distance: 0.0,
|
loaded_distance: 0.0,
|
||||||
map_bounds: Vec2::new(
|
map_bounds: Vec2::new(
|
||||||
client.world_data().min_chunk_alt(),
|
client.world_data().min_chunk_alt(),
|
||||||
@ -992,6 +1000,8 @@ impl Scene {
|
|||||||
.maintain(audio, scene_data.state, client, &self.camera);
|
.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`.
|
/// Render the scene using the provided `Renderer`.
|
||||||
pub fn render(
|
pub fn render(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -566,14 +566,14 @@ impl<V: RectRasterableVol> Terrain<V> {
|
|||||||
},
|
},
|
||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D1,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||||
usage: wgpu::TextureUsage::COPY_DST | wgpu::TextureUsage::SAMPLED,
|
usage: wgpu::TextureUsage::COPY_DST | wgpu::TextureUsage::SAMPLED,
|
||||||
},
|
},
|
||||||
&wgpu::TextureViewDescriptor {
|
&wgpu::TextureViewDescriptor {
|
||||||
label: Some("Atlas texture view"),
|
label: Some("Atlas texture view"),
|
||||||
format: Some(wgpu::TextureFormat::Rgba8UnormSrgb),
|
format: Some(wgpu::TextureFormat::Rgba8UnormSrgb),
|
||||||
dimension: Some(wgpu::TextureViewDimension::D1),
|
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||||
aspect: wgpu::TextureAspect::All,
|
aspect: wgpu::TextureAspect::All,
|
||||||
base_mip_level: 0,
|
base_mip_level: 0,
|
||||||
level_count: None,
|
level_count: None,
|
||||||
|
@ -1317,8 +1317,18 @@ impl PlayState for SessionState {
|
|||||||
&scene_data,
|
&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
|
// Draw the UI to the screen
|
||||||
self.hud.render(renderer, self.scene.globals());
|
self.hud.render(&mut drawer.third_pass().draw_ui());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user