|
|
@ -1,4 +1,6 @@
|
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
use std::iter::Chain;
|
|
|
|
|
|
|
|
use std::slice::Iter;
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use std::thread::current;
|
|
|
|
use std::thread::current;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::Duration;
|
|
|
@ -18,22 +20,25 @@ use legion::world::SubWorld;
|
|
|
|
use legion::*;
|
|
|
|
use legion::*;
|
|
|
|
use rapier3d::parry::motion::RigidMotionComposition;
|
|
|
|
use rapier3d::parry::motion::RigidMotionComposition;
|
|
|
|
use wgpu::util::DeviceExt;
|
|
|
|
use wgpu::util::DeviceExt;
|
|
|
|
use wgpu::{BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, Device, FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView, VertexState, CommandEncoder};
|
|
|
|
use wgpu::{
|
|
|
|
|
|
|
|
BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, CommandEncoder, Device,
|
|
|
|
|
|
|
|
FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame,
|
|
|
|
|
|
|
|
TextureView, VertexState,
|
|
|
|
|
|
|
|
};
|
|
|
|
use winit_24::dpi::PhysicalSize;
|
|
|
|
use winit_24::dpi::PhysicalSize;
|
|
|
|
use winit_24::platform::unix::x11::ffi::Time;
|
|
|
|
use winit_24::platform::unix::x11::ffi::Time;
|
|
|
|
use winit_24::window::Window;
|
|
|
|
use winit_24::window::Window;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
use crate::components::{Mesh, Position, RangeCopy, LoopState, ImguiWindow};
|
|
|
|
use crate::components::{ImguiWindow, LoopState, Mesh, Position, RangeCopy};
|
|
|
|
use crate::current_ui;
|
|
|
|
use crate::current_ui;
|
|
|
|
use crate::geometry::{load_obj, Vertex};
|
|
|
|
use crate::geometry::{load_obj, Vertex};
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::render::state::{RenderState};
|
|
|
|
use crate::render::state::RenderState;
|
|
|
|
use crate::render::{push_debug_group_checked, insert_debug_marker_checked, pop_debug_group_checked, EntityUniforms};
|
|
|
|
use crate::render::{
|
|
|
|
use std::iter::Chain;
|
|
|
|
insert_debug_marker_checked, pop_debug_group_checked, push_debug_group_checked, EntityUniforms,
|
|
|
|
use std::slice::Iter;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
#[system]
|
|
|
|
#[write_component(Camera)]
|
|
|
|
#[write_component(Camera)]
|
|
|
@ -55,9 +60,7 @@ pub fn imgui_prepare(
|
|
|
|
unsafe { crate::CURRENT_UI = Some(std::mem::transmute(imgui_context.frame())) }
|
|
|
|
unsafe { crate::CURRENT_UI = Some(std::mem::transmute(imgui_context.frame())) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn run_imgui_render_step<G: 'static + Sized + Send + Sync>(world: &mut SubWorld, ui: &Ui) {
|
|
|
|
fn run_imgui_render_step<G: 'static + Sized + Send + Sync>(world: &mut SubWorld, ui: &Ui) {
|
|
|
|
|
|
|
|
|
|
|
|
let mut component_query = <(&G)>::query();
|
|
|
|
let mut component_query = <(&G)>::query();
|
|
|
|
let mut window_query = <(&ImguiWindow<G>)>::query();
|
|
|
|
let mut window_query = <(&ImguiWindow<G>)>::query();
|
|
|
|
|
|
|
|
|
|
|
@ -73,7 +76,9 @@ fn run_imgui_render_step<G: 'static + Sized + Send + Sync>(world: &mut SubWorld,
|
|
|
|
for (component_state) in component_query.iter(world) {
|
|
|
|
for (component_state) in component_query.iter(world) {
|
|
|
|
v.push(component_state)
|
|
|
|
v.push(component_state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window_data.unwrap().build(&ui, || { (window_func.unwrap())(ui, v) });
|
|
|
|
window_data
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.build(&ui, || (window_func.unwrap())(ui, v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Go through each "global" window-data component and render it's data
|
|
|
|
/// Go through each "global" window-data component and render it's data
|
|
|
@ -83,7 +88,6 @@ fn run_imgui_render_step<G: 'static + Sized + Send + Sync>(world: &mut SubWorld,
|
|
|
|
#[write_component(ImguiWindow<ImguiGenericOutputLine>)]
|
|
|
|
#[write_component(ImguiWindow<ImguiGenericOutputLine>)]
|
|
|
|
#[write_component(ImguiGenericOutputLine)]
|
|
|
|
#[write_component(ImguiGenericOutputLine)]
|
|
|
|
pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
|
|
|
|
pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
|
|
|
|
|
|
|
|
|
|
|
|
let ui = unsafe { crate::current_ui().unwrap() };
|
|
|
|
let ui = unsafe { crate::current_ui().unwrap() };
|
|
|
|
|
|
|
|
|
|
|
|
// Pull out the window associated with this type, and render each of the components in the sytem
|
|
|
|
// Pull out the window associated with this type, and render each of the components in the sytem
|
|
|
@ -91,7 +95,6 @@ pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState
|
|
|
|
run_imgui_render_step::<ImguiPerformanceProfilerLine>(world, &ui);
|
|
|
|
run_imgui_render_step::<ImguiPerformanceProfilerLine>(world, &ui);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This would be the shared state for all imgui generic output things
|
|
|
|
// This would be the shared state for all imgui generic output things
|
|
|
|
pub struct ImguiGenericOutputLine {
|
|
|
|
pub struct ImguiGenericOutputLine {
|
|
|
|
pub label: String,
|
|
|
|
pub label: String,
|
|
|
@ -99,9 +102,7 @@ pub struct ImguiGenericOutputLine {
|
|
|
|
|
|
|
|
|
|
|
|
impl ImguiGenericOutputLine {
|
|
|
|
impl ImguiGenericOutputLine {
|
|
|
|
pub fn new(label: String) -> ImguiGenericOutputLine {
|
|
|
|
pub fn new(label: String) -> ImguiGenericOutputLine {
|
|
|
|
ImguiGenericOutputLine {
|
|
|
|
ImguiGenericOutputLine { label }
|
|
|
|
label
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -116,7 +117,6 @@ pub struct ImguiPerformanceProfilerLine {
|
|
|
|
|
|
|
|
|
|
|
|
impl ImguiPerformanceProfilerLine {
|
|
|
|
impl ImguiPerformanceProfilerLine {
|
|
|
|
fn add_sample(&mut self, sample: f32) {
|
|
|
|
fn add_sample(&mut self, sample: f32) {
|
|
|
|
|
|
|
|
|
|
|
|
self.list_of_fps[self.index] = sample;
|
|
|
|
self.list_of_fps[self.index] = sample;
|
|
|
|
|
|
|
|
|
|
|
|
if self.index >= 399 {
|
|
|
|
if self.index >= 399 {
|
|
|
@ -138,7 +138,16 @@ impl ImguiPerformanceProfilerLine {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn current_average_label(&self) -> (f32, String) {
|
|
|
|
pub fn current_average_label(&self) -> (f32, String) {
|
|
|
|
let (left, right) = self.list_of_fps.split_at(self.index);
|
|
|
|
let (left, right) = self.list_of_fps.split_at(self.index);
|
|
|
|
((left.iter().rev().chain(right.iter().rev()).take(50).sum::<f32>() / 50.0), "FPS".to_string())
|
|
|
|
(
|
|
|
|
|
|
|
|
(left
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.rev()
|
|
|
|
|
|
|
|
.chain(right.iter().rev())
|
|
|
|
|
|
|
|
.take(50)
|
|
|
|
|
|
|
|
.sum::<f32>()
|
|
|
|
|
|
|
|
/ 50.0),
|
|
|
|
|
|
|
|
"FPS".to_string(),
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn new(label: String) -> ImguiPerformanceProfilerLine {
|
|
|
|
pub fn new(label: String) -> ImguiPerformanceProfilerLine {
|
|
|
@ -147,11 +156,22 @@ impl ImguiPerformanceProfilerLine {
|
|
|
|
list_of_fps: [0.0; 400],
|
|
|
|
list_of_fps: [0.0; 400],
|
|
|
|
index: 0,
|
|
|
|
index: 0,
|
|
|
|
scale_min: 0.0,
|
|
|
|
scale_min: 0.0,
|
|
|
|
scale_max: 0.0
|
|
|
|
scale_max: 0.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
|
|
|
|
#[write_component(ImguiPerformanceProfilerLine)]
|
|
|
|
|
|
|
|
pub fn render_performance_flag(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
|
|
|
|
|
|
|
|
let delta_time = loop_state.delta_time.as_secs_f32();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut query = <(&mut ImguiPerformanceProfilerLine)>::query();
|
|
|
|
|
|
|
|
for (mut profiler) in query.iter_mut(world) {
|
|
|
|
|
|
|
|
profiler.add_sample(delta_time);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
#[system]
|
|
|
|
#[write_component(Camera)]
|
|
|
|
#[write_component(Camera)]
|
|
|
|
#[write_component(Position)]
|
|
|
|
#[write_component(Position)]
|
|
|
@ -161,17 +181,12 @@ impl ImguiPerformanceProfilerLine {
|
|
|
|
#[write_component(DirectionalLight)]
|
|
|
|
#[write_component(DirectionalLight)]
|
|
|
|
pub fn render_test(
|
|
|
|
pub fn render_test(
|
|
|
|
world: &mut SubWorld,
|
|
|
|
world: &mut SubWorld,
|
|
|
|
#[state] performance_profiler_line: &mut ImguiPerformanceProfilerLine,
|
|
|
|
|
|
|
|
#[resource] loop_state: &mut LoopState,
|
|
|
|
#[resource] loop_state: &mut LoopState,
|
|
|
|
#[resource] renderer: &mut RenderState,
|
|
|
|
#[resource] renderer: &mut RenderState,
|
|
|
|
#[resource] winit_window: &mut Window,
|
|
|
|
#[resource] winit_window: &mut Window,
|
|
|
|
#[resource] imgui_context: &mut Arc<Mutex<ImguiContext>>,
|
|
|
|
#[resource] imgui_context: &mut Arc<Mutex<ImguiContext>>,
|
|
|
|
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
|
|
|
|
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
let delta_time = loop_state.delta_time.as_secs_f32();
|
|
|
|
|
|
|
|
performance_profiler_line.add_sample(delta_time);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut encoder = renderer
|
|
|
|
let mut encoder = renderer
|
|
|
|
.device
|
|
|
|
.device
|
|
|
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
|
|
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
|
|
@ -237,8 +252,10 @@ pub fn render_test(
|
|
|
|
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
|
|
|
|
let mut query = <(&mut DirectionalLight, &mut Position)>::query();
|
|
|
|
|
|
|
|
|
|
|
|
for (i, (light, pos)) in query.iter_mut(world).enumerate() {
|
|
|
|
for (i, (light, pos)) in query.iter_mut(world).enumerate() {
|
|
|
|
insert_debug_marker_checked(&format!("shadow pass {} (light at position {:?})", i, pos), &mut encoder);
|
|
|
|
insert_debug_marker_checked(
|
|
|
|
|
|
|
|
&format!("shadow pass {} (light at position {:?})", i, pos),
|
|
|
|
|
|
|
|
&mut encoder,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// The light uniform buffer already has the projection,
|
|
|
|
// The light uniform buffer already has the projection,
|
|
|
|
// let's just copy it over to the shadow uniform buffer.
|
|
|
|
// let's just copy it over to the shadow uniform buffer.
|
|
|
@ -252,7 +269,6 @@ pub fn render_test(
|
|
|
|
|
|
|
|
|
|
|
|
insert_debug_marker_checked("render entities", &mut encoder);
|
|
|
|
insert_debug_marker_checked("render entities", &mut encoder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
|
|
|
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
|
|
|
label: Some("render pass"),
|
|
|
|
label: Some("render pass"),
|
|
|
|
color_attachments: &[],
|
|
|
|
color_attachments: &[],
|
|
|
@ -328,7 +344,6 @@ pub fn render_test(
|
|
|
|
|
|
|
|
|
|
|
|
let ui = unsafe { crate::current_ui().unwrap() };
|
|
|
|
let ui = unsafe { crate::current_ui().unwrap() };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ui.show_demo_window(&mut true);
|
|
|
|
// ui.show_demo_window(&mut true);
|
|
|
|
imgui_platform.prepare_render(&ui, &winit_window);
|
|
|
|
imgui_platform.prepare_render(&ui, &winit_window);
|
|
|
|
|
|
|
|
|
|
|
|