editor with imgui and sdl->28
This commit is contained in:
98
src/editor/inspector.rs
Normal file
98
src/editor/inspector.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
use dear_imgui_rs::{Condition, Context};
|
||||
use dear_imgui_wgpu::{WgpuInitInfo, WgpuRenderer};
|
||||
use sdl3_sys::events::SDL_Event;
|
||||
|
||||
pub struct FrameStats
|
||||
{
|
||||
pub fps: f32,
|
||||
pub frame_ms: f32,
|
||||
pub physics_budget_ms: f32,
|
||||
pub draw_call_count: usize,
|
||||
}
|
||||
|
||||
pub struct Inspector
|
||||
{
|
||||
imgui: Context,
|
||||
renderer: WgpuRenderer,
|
||||
}
|
||||
|
||||
impl Inspector
|
||||
{
|
||||
pub fn new(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
surface_format: wgpu::TextureFormat,
|
||||
) -> Self
|
||||
{
|
||||
let mut imgui = Context::create();
|
||||
let init_info = WgpuInitInfo::new(device.clone(), queue.clone(), surface_format);
|
||||
let renderer =
|
||||
WgpuRenderer::new(init_info, &mut imgui).expect("Failed to create imgui wgpu renderer");
|
||||
Self { imgui, renderer }
|
||||
}
|
||||
|
||||
pub fn init_platform(&mut self, window: &sdl3::video::Window)
|
||||
{
|
||||
dear_imgui_sdl3::init_for_other(&mut self.imgui, window)
|
||||
.expect("Failed to init imgui sdl3 platform");
|
||||
}
|
||||
|
||||
pub fn begin_frame(&mut self)
|
||||
{
|
||||
dear_imgui_sdl3::sdl3_new_frame(&mut self.imgui);
|
||||
}
|
||||
|
||||
pub fn process_event(&mut self, raw_event: &SDL_Event)
|
||||
{
|
||||
dear_imgui_sdl3::process_sys_event(raw_event);
|
||||
}
|
||||
|
||||
pub fn wants_keyboard(&self) -> bool
|
||||
{
|
||||
self.imgui.io().want_capture_keyboard()
|
||||
}
|
||||
|
||||
pub fn wants_mouse(&self) -> bool
|
||||
{
|
||||
self.imgui.io().want_capture_mouse()
|
||||
}
|
||||
|
||||
pub fn build_ui(&mut self, stats: &FrameStats)
|
||||
{
|
||||
let ui = self.imgui.frame();
|
||||
ui.window("Inspector")
|
||||
.position([10.0, 10.0], Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text(format!("FPS: {:.1}", stats.fps));
|
||||
ui.text(format!("Frame: {:.1} ms", stats.frame_ms));
|
||||
ui.text(format!("Physics: {:.1} ms", stats.physics_budget_ms));
|
||||
ui.text(format!("Draw calls: {}", stats.draw_call_count));
|
||||
});
|
||||
}
|
||||
|
||||
pub fn render(&mut self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView)
|
||||
{
|
||||
let draw_data = self.imgui.render();
|
||||
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("ImGui Render Pass"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Load,
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
depth_slice: None,
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
occlusion_query_set: None,
|
||||
timestamp_writes: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
self.renderer
|
||||
.render_draw_data(draw_data, &mut render_pass)
|
||||
.expect("Failed to render imgui");
|
||||
}
|
||||
}
|
||||
82
src/editor/mod.rs
Normal file
82
src/editor/mod.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
mod inspector;
|
||||
|
||||
use sdl3_sys::events::SDL_Event;
|
||||
|
||||
use crate::entity::EntityHandle;
|
||||
use crate::systems::camera_noclip_system;
|
||||
use crate::utility::input::InputState;
|
||||
use crate::world::World;
|
||||
|
||||
pub use inspector::FrameStats;
|
||||
use inspector::Inspector;
|
||||
|
||||
pub struct EditorState
|
||||
{
|
||||
pub active: bool,
|
||||
pub right_mouse_held: bool,
|
||||
pub selected_entity: Option<EntityHandle>,
|
||||
inspector: Inspector,
|
||||
}
|
||||
|
||||
impl EditorState
|
||||
{
|
||||
pub fn new(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
surface_format: wgpu::TextureFormat,
|
||||
) -> Self
|
||||
{
|
||||
Self {
|
||||
active: false,
|
||||
right_mouse_held: false,
|
||||
selected_entity: None,
|
||||
inspector: Inspector::new(device, queue, surface_format),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_platform(&mut self, window: &sdl3::video::Window)
|
||||
{
|
||||
self.inspector.init_platform(window);
|
||||
}
|
||||
|
||||
pub fn begin_frame(&mut self)
|
||||
{
|
||||
self.inspector.begin_frame();
|
||||
}
|
||||
|
||||
pub fn process_event(&mut self, raw_event: &SDL_Event) -> bool
|
||||
{
|
||||
self.inspector.process_event(raw_event);
|
||||
false
|
||||
}
|
||||
|
||||
pub fn wants_keyboard(&self) -> bool
|
||||
{
|
||||
self.inspector.wants_keyboard()
|
||||
}
|
||||
|
||||
pub fn wants_mouse(&self) -> bool
|
||||
{
|
||||
self.inspector.wants_mouse()
|
||||
}
|
||||
|
||||
pub fn render(&mut self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView)
|
||||
{
|
||||
self.inspector.render(encoder, view);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn editor_loop(
|
||||
editor: &mut EditorState,
|
||||
world: &mut World,
|
||||
input_state: &InputState,
|
||||
stats: &FrameStats,
|
||||
delta: f32,
|
||||
)
|
||||
{
|
||||
if editor.right_mouse_held
|
||||
{
|
||||
camera_noclip_system(world, input_state, delta);
|
||||
}
|
||||
editor.inspector.build_ui(stats);
|
||||
}
|
||||
143
src/main.rs
143
src/main.rs
@@ -1,7 +1,7 @@
|
||||
mod bundles;
|
||||
mod components;
|
||||
mod debug;
|
||||
mod draw;
|
||||
mod editor;
|
||||
mod entity;
|
||||
mod event;
|
||||
mod loaders;
|
||||
@@ -17,11 +17,15 @@ mod utility;
|
||||
mod world;
|
||||
|
||||
use crate::debug::{collider_debug, DebugMode};
|
||||
use crate::editor::{editor_loop, EditorState, FrameStats};
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use glam::Vec3;
|
||||
use render::Renderer;
|
||||
use sdl3::event::Event;
|
||||
use sdl3::keyboard::Keycode;
|
||||
use sdl3::mouse::MouseButton;
|
||||
use utility::input::InputState;
|
||||
use world::World;
|
||||
|
||||
@@ -34,11 +38,11 @@ use crate::loaders::scene::Space;
|
||||
use crate::physics::PhysicsManager;
|
||||
use crate::snow::{SnowConfig, SnowLayer};
|
||||
use crate::systems::{
|
||||
camera_follow_system, camera_input_system, camera_noclip_system, camera_view_matrix,
|
||||
noclip_toggle_system, physics_sync_system, player_input_system, render_system, rotate_system,
|
||||
snow_system, spotlight_sync_system, start_camera_following, state_machine_physics_system,
|
||||
state_machine_system,
|
||||
camera_follow_system, camera_input_system, camera_view_matrix, physics_sync_system,
|
||||
player_input_system, render_system, rotate_system, snow_system, spotlight_sync_system,
|
||||
start_camera_following, state_machine_physics_system, state_machine_system,
|
||||
};
|
||||
use crate::systems::camera::stop_camera_following;
|
||||
use crate::utility::time::Time;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
@@ -55,6 +59,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
let renderer = pollster::block_on(Renderer::new(&window, 2))?;
|
||||
render::init(renderer);
|
||||
|
||||
let mut editor = render::with_device(|device| {
|
||||
render::with_queue(|queue| {
|
||||
render::with_surface_format(|format| EditorState::new(device, queue, format))
|
||||
})
|
||||
});
|
||||
editor.init_platform(&window);
|
||||
|
||||
let space = Space::load_space("meshes/terrain.gltf")?;
|
||||
let terrain_config = TerrainConfig::default();
|
||||
|
||||
@@ -95,7 +106,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
|
||||
render::set_snow_depth(&snow_layer.depth_texture_view);
|
||||
|
||||
let mut noclip_mode = true;
|
||||
let mut debug_mode = DebugMode::default();
|
||||
|
||||
let camera_entity = CameraBundle {
|
||||
@@ -103,12 +113,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
}
|
||||
.spawn(&mut world)
|
||||
.unwrap();
|
||||
if !noclip_mode
|
||||
{
|
||||
start_camera_following(&mut world, camera_entity);
|
||||
}
|
||||
|
||||
let mut event_pump = sdl_context.event_pump()?;
|
||||
let _event_pump = sdl_context.event_pump()?;
|
||||
let mut input_state = InputState::new();
|
||||
|
||||
sdl_context.mouse().set_relative_mouse_mode(&window, true);
|
||||
@@ -121,6 +128,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
const FIXED_TIMESTEP: f32 = 1.0 / 60.0;
|
||||
let mut physics_accumulator = 0.0;
|
||||
|
||||
let mut stats = FrameStats {
|
||||
fps: 0.0,
|
||||
frame_ms: 0.0,
|
||||
physics_budget_ms: 0.0,
|
||||
draw_call_count: 0,
|
||||
};
|
||||
|
||||
'running: loop
|
||||
{
|
||||
let frame_start = Instant::now();
|
||||
@@ -128,11 +142,77 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
let delta = (frame_start - last_frame).as_secs_f32();
|
||||
last_frame = frame_start;
|
||||
|
||||
for event in event_pump.poll_iter()
|
||||
{
|
||||
let mouse_capture_changed = input_state.handle_event(&event);
|
||||
editor.begin_frame();
|
||||
|
||||
if mouse_capture_changed
|
||||
while let Some(raw_event) = dear_imgui_sdl3::sdl3_poll_event_ll()
|
||||
{
|
||||
editor.process_event(&raw_event);
|
||||
let event = Event::from_ll(raw_event);
|
||||
|
||||
match &event
|
||||
{
|
||||
Event::Quit { .. } =>
|
||||
{
|
||||
input_state.quit_requested = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
Event::KeyDown {
|
||||
keycode: Some(Keycode::I),
|
||||
repeat: false,
|
||||
..
|
||||
} =>
|
||||
{
|
||||
editor.active = !editor.active;
|
||||
if editor.active
|
||||
{
|
||||
sdl_context.mouse().set_relative_mouse_mode(&window, false);
|
||||
editor.right_mouse_held = false;
|
||||
input_state.mouse_captured = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
input_state.mouse_captured = true;
|
||||
sdl_context.mouse().set_relative_mouse_mode(&window, true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Event::MouseButtonDown {
|
||||
mouse_btn: MouseButton::Right,
|
||||
..
|
||||
} if editor.active =>
|
||||
{
|
||||
editor.right_mouse_held = true;
|
||||
input_state.mouse_captured = true;
|
||||
stop_camera_following(&mut world, camera_entity);
|
||||
sdl_context.mouse().set_relative_mouse_mode(&window, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
Event::MouseButtonUp {
|
||||
mouse_btn: MouseButton::Right,
|
||||
..
|
||||
} if editor.active =>
|
||||
{
|
||||
editor.right_mouse_held = false;
|
||||
input_state.mouse_captured = false;
|
||||
start_camera_following(&mut world, camera_entity);
|
||||
sdl_context.mouse().set_relative_mouse_mode(&window, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
_ =>
|
||||
{}
|
||||
}
|
||||
|
||||
if editor.active && (editor.wants_keyboard() || editor.wants_mouse())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let capture_changed = input_state.handle_event(&event);
|
||||
if capture_changed && !editor.active
|
||||
{
|
||||
sdl_context
|
||||
.mouse()
|
||||
@@ -145,10 +225,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
break 'running;
|
||||
}
|
||||
|
||||
input_state.process_post_events();
|
||||
|
||||
noclip_toggle_system(&mut world, &input_state, camera_entity, &mut noclip_mode);
|
||||
|
||||
if input_state.debug_cycle_just_pressed
|
||||
{
|
||||
debug_mode = debug_mode.cycle();
|
||||
@@ -157,9 +233,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
|
||||
camera_input_system(&mut world, &input_state);
|
||||
|
||||
if noclip_mode
|
||||
if editor.active
|
||||
{
|
||||
camera_noclip_system(&mut world, &input_state, delta);
|
||||
editor_loop(&mut editor, &mut world, &input_state, &stats, delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,6 +243,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
player_input_system(&mut world, &input_state);
|
||||
}
|
||||
|
||||
let physics_start = Instant::now();
|
||||
|
||||
physics_accumulator += delta;
|
||||
|
||||
while physics_accumulator >= FIXED_TIMESTEP
|
||||
@@ -180,6 +258,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
physics_accumulator -= FIXED_TIMESTEP;
|
||||
}
|
||||
|
||||
stats.physics_budget_ms = physics_start.elapsed().as_secs_f32() * 1000.0;
|
||||
|
||||
state_machine_system(&mut world, delta);
|
||||
|
||||
rotate_system(&mut world, delta);
|
||||
@@ -187,7 +267,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
let spotlights = spotlight_sync_system(&world);
|
||||
render::update_spotlights(spotlights);
|
||||
|
||||
snow_system(&world, &mut snow_layer, noclip_mode);
|
||||
snow_system(&world, &mut snow_layer, editor.active);
|
||||
|
||||
let mut draw_calls = render_system(&world);
|
||||
draw_calls.extend(snow_layer.get_draw_calls());
|
||||
@@ -207,7 +287,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
{
|
||||
let projection = camera_component.projection_matrix();
|
||||
|
||||
render::render(
|
||||
stats.draw_call_count = draw_calls.len();
|
||||
stats.fps = 1.0 / delta;
|
||||
stats.frame_ms = delta * 1000.0;
|
||||
|
||||
let frame = render::render(
|
||||
&view,
|
||||
&projection,
|
||||
camera_transform.position,
|
||||
@@ -217,6 +301,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
||||
delta,
|
||||
debug_mode,
|
||||
);
|
||||
|
||||
if editor.active
|
||||
{
|
||||
let screen_view =
|
||||
frame.texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let mut encoder = render::with_device(|d| {
|
||||
d.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("ImGui Encoder"),
|
||||
})
|
||||
});
|
||||
editor.render(&mut encoder, &screen_view);
|
||||
render::with_queue(|q| q.submit(std::iter::once(encoder.finish())));
|
||||
}
|
||||
|
||||
frame.present();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ impl LowResFramebuffer
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
@@ -157,7 +157,7 @@ pub fn create_blit_pipeline(
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Blit Pipeline Layout"),
|
||||
bind_group_layouts: &[bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
@@ -194,7 +194,7 @@ pub fn create_blit_pipeline(
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ impl DebugOverlay
|
||||
let shadow_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Shadow Debug Pipeline Layout"),
|
||||
bind_group_layouts: &[&shadow_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
let snow_light_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Snow Light Debug Pipeline Layout"),
|
||||
bind_group_layouts: &[&snow_light_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
let color_target = wgpu::ColorTargetState {
|
||||
@@ -98,7 +98,7 @@ impl DebugOverlay
|
||||
},
|
||||
depth_stencil: None,
|
||||
multisample: wgpu::MultisampleState::default(),
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
});
|
||||
|
||||
@@ -125,7 +125,7 @@ impl DebugOverlay
|
||||
},
|
||||
depth_stencil: None,
|
||||
multisample: wgpu::MultisampleState::default(),
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
});
|
||||
|
||||
@@ -171,6 +171,7 @@ impl DebugOverlay
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
pass.set_pipeline(&self.pipeline_shadow);
|
||||
@@ -221,6 +222,7 @@ impl DebugOverlay
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
pass.set_pipeline(&self.pipeline_snow_light);
|
||||
|
||||
@@ -248,7 +248,7 @@ impl Renderer
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Linear,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
|
||||
compare: Some(wgpu::CompareFunction::LessEqual),
|
||||
..Default::default()
|
||||
});
|
||||
@@ -546,7 +546,7 @@ impl Renderer
|
||||
time: f32,
|
||||
delta_time: f32,
|
||||
debug_mode: DebugMode,
|
||||
)
|
||||
) -> wgpu::SurfaceTexture
|
||||
{
|
||||
let light_view_projections = self.calculate_light_view_projections();
|
||||
|
||||
@@ -647,6 +647,7 @@ impl Renderer
|
||||
}),
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
let pipeline = match draw_call.pipeline
|
||||
@@ -737,6 +738,7 @@ impl Renderer
|
||||
),
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
wire_pass.set_pipeline(wireframe_pipeline);
|
||||
@@ -850,6 +852,7 @@ impl Renderer
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
blit_pass.set_pipeline(&self.blit_pipeline);
|
||||
@@ -860,7 +863,7 @@ impl Renderer
|
||||
}
|
||||
|
||||
self.queue.submit(std::iter::once(blit_encoder.finish()));
|
||||
frame.present();
|
||||
frame
|
||||
}
|
||||
|
||||
pub fn render_scale(&self) -> (u32, u32)
|
||||
@@ -1025,7 +1028,7 @@ pub fn render(
|
||||
time: f32,
|
||||
delta_time: f32,
|
||||
debug_mode: DebugMode,
|
||||
)
|
||||
) -> wgpu::SurfaceTexture
|
||||
{
|
||||
GLOBAL_RENDERER.with(|r| {
|
||||
let mut renderer = r.borrow_mut();
|
||||
@@ -1039,8 +1042,19 @@ pub fn render(
|
||||
time,
|
||||
delta_time,
|
||||
debug_mode,
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_surface_format<F, R>(f: F) -> R
|
||||
where
|
||||
F: FnOnce(wgpu::TextureFormat) -> R,
|
||||
{
|
||||
GLOBAL_RENDERER.with(|r| {
|
||||
let renderer = r.borrow();
|
||||
let renderer = renderer.as_ref().expect("Renderer not set");
|
||||
f(renderer.config.format)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_shadow_bias(bias: f32)
|
||||
|
||||
@@ -20,7 +20,7 @@ pub fn create_shadow_pipeline(
|
||||
let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Shadow Pipeline Layout"),
|
||||
bind_group_layouts: &[bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
@@ -57,7 +57,7 @@ pub fn create_shadow_pipeline(
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
})
|
||||
}
|
||||
@@ -85,7 +85,7 @@ pub fn create_main_pipeline(
|
||||
let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Main Pipeline Layout"),
|
||||
bind_group_layouts: &[bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
@@ -131,7 +131,7 @@ pub fn create_main_pipeline(
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
})
|
||||
}
|
||||
@@ -157,7 +157,7 @@ pub fn create_wireframe_pipeline(
|
||||
let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Wireframe Pipeline Layout"),
|
||||
bind_group_layouts: &[bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
@@ -203,7 +203,7 @@ pub fn create_wireframe_pipeline(
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
})
|
||||
}
|
||||
@@ -229,7 +229,7 @@ pub fn create_debug_lines_pipeline(
|
||||
let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Debug Lines Pipeline Layout"),
|
||||
bind_group_layouts: &[bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
@@ -275,7 +275,7 @@ pub fn create_debug_lines_pipeline(
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
})
|
||||
}
|
||||
@@ -340,7 +340,7 @@ pub fn create_snow_clipmap_pipeline(
|
||||
let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Snow Clipmap Pipeline Layout"),
|
||||
bind_group_layouts: &[main_bind_group_layout, &displacement_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
@@ -390,7 +390,7 @@ pub fn create_snow_clipmap_pipeline(
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ impl Renderer
|
||||
}),
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
shadow_pass.set_pipeline(
|
||||
|
||||
@@ -360,7 +360,7 @@ impl SnowLayer
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Snow Deform Pipeline Layout"),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use glam::{Vec2, Vec3};
|
||||
use glam::Vec2;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -185,7 +185,7 @@ impl SnowLightAccumulation
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Snow Light Accumulation Pipeline Layout"),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
@@ -222,7 +222,7 @@ impl SnowLightAccumulation
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
});
|
||||
|
||||
@@ -280,6 +280,7 @@ impl SnowLightAccumulation
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
@@ -296,6 +297,7 @@ impl SnowLightAccumulation
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -498,6 +500,7 @@ impl SnowLightAccumulation
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
render_pass.set_pipeline(&self.pipeline);
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
use crate::entity::EntityHandle;
|
||||
use crate::systems::camera::{start_camera_following, stop_camera_following};
|
||||
use crate::utility::input::InputState;
|
||||
use crate::world::World;
|
||||
|
||||
pub fn noclip_toggle_system(
|
||||
world: &mut World,
|
||||
input_state: &InputState,
|
||||
camera_entity: EntityHandle,
|
||||
noclip_mode: &mut bool,
|
||||
)
|
||||
{
|
||||
if input_state.noclip_just_pressed
|
||||
{
|
||||
*noclip_mode = !*noclip_mode;
|
||||
if *noclip_mode
|
||||
{
|
||||
stop_camera_following(world, camera_entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
start_camera_following(world, camera_entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ impl DitherTextures
|
||||
address_mode_w: wgpu::AddressMode::Repeat,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
@@ -226,7 +226,7 @@ impl FlowmapTexture
|
||||
address_mode_w: wgpu::AddressMode::Repeat,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
|
||||
@@ -11,12 +11,10 @@ pub struct InputState
|
||||
pub shift: bool,
|
||||
|
||||
pub space_just_pressed: bool,
|
||||
pub noclip_just_pressed: bool,
|
||||
pub debug_cycle_just_pressed: bool,
|
||||
|
||||
pub mouse_delta: (f32, f32),
|
||||
pub mouse_captured: bool,
|
||||
pub noclip_mode: bool,
|
||||
pub quit_requested: bool,
|
||||
}
|
||||
|
||||
@@ -32,11 +30,9 @@ impl InputState
|
||||
space: false,
|
||||
shift: false,
|
||||
space_just_pressed: false,
|
||||
noclip_just_pressed: false,
|
||||
debug_cycle_just_pressed: false,
|
||||
mouse_delta: (0.0, 0.0),
|
||||
mouse_captured: true,
|
||||
noclip_mode: false,
|
||||
quit_requested: false,
|
||||
}
|
||||
}
|
||||
@@ -66,12 +62,6 @@ impl InputState
|
||||
self.quit_requested = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if *key == Keycode::I
|
||||
{
|
||||
self.mouse_captured = !self.mouse_captured;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +101,6 @@ impl InputState
|
||||
self.space = true;
|
||||
}
|
||||
Keycode::LShift | Keycode::RShift => self.shift = true,
|
||||
Keycode::N => self.noclip_just_pressed = true,
|
||||
Keycode::F1 => self.debug_cycle_just_pressed = true,
|
||||
_ =>
|
||||
{}
|
||||
@@ -141,22 +130,9 @@ impl InputState
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_post_events(&mut self)
|
||||
{
|
||||
if self.noclip_just_pressed
|
||||
{
|
||||
self.noclip_mode = !self.noclip_mode;
|
||||
println!(
|
||||
"Noclip mode: {}",
|
||||
if self.noclip_mode { "ON" } else { "OFF" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear_just_pressed(&mut self)
|
||||
{
|
||||
self.space_just_pressed = false;
|
||||
self.noclip_just_pressed = false;
|
||||
self.debug_cycle_just_pressed = false;
|
||||
self.mouse_delta = (0.0, 0.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user